1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "../bfd/libhppa.h"
31 #include "../bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".hppa_unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
56 #define obj_version obj_elf_version
58 /* Use space aliases. */
61 /* Some local functions only used by ELF. */
62 static void pa_build_symextn_section
PARAMS ((void));
63 static void hppa_tc_make_symextn_section
PARAMS ((void));
67 /* Names of various debugging spaces/subspaces. */
68 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
69 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
70 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
71 #define UNWIND_SECTION_NAME "$UNWIND$"
73 /* Object file formats specify relocation types. */
74 typedef int reloc_type
;
77 #define obj_version obj_som_version
79 /* Do not use space aliases. */
82 /* How to generate a relocation. */
83 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
85 /* Object file formats specify BFD symbol types. */
86 typedef som_symbol_type obj_symbol_type
;
89 /* Various structures and types used internally in tc-hppa.c. */
91 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
95 unsigned int cannot_unwind
:1;
96 unsigned int millicode
:1;
97 unsigned int millicode_save_rest
:1;
98 unsigned int region_desc
:2;
99 unsigned int save_sr
:2;
100 unsigned int entry_fr
:4;
101 unsigned int entry_gr
:5;
102 unsigned int args_stored
:1;
103 unsigned int call_fr
:5;
104 unsigned int call_gr
:5;
105 unsigned int save_sp
:1;
106 unsigned int save_rp
:1;
107 unsigned int save_rp_in_frame
:1;
108 unsigned int extn_ptr_defined
:1;
109 unsigned int cleanup_defined
:1;
111 unsigned int hpe_interrupt_marker
:1;
112 unsigned int hpux_interrupt_marker
:1;
113 unsigned int reserved
:3;
114 unsigned int frame_size
:27;
119 /* Starting and ending offsets of the region described by
121 unsigned int start_offset
;
122 unsigned int end_offset
;
123 struct unwind_desc descriptor
;
126 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
127 control the entry and exit code they generate. It is also used in
128 creation of the correct stack unwind descriptors.
130 NOTE: GAS does not support .enter and .leave for the generation of
131 prologues and epilogues. FIXME.
133 The fields in structure roughly correspond to the arguments available on the
134 .callinfo pseudo-op. */
138 /* Size of the stack frame. */
141 /* Should sr3 be saved in the prologue? */
144 /* Does this function make calls? */
147 /* The unwind descriptor being built. */
148 struct unwind_table ci_unwind
;
150 /* Name of this function. */
151 symbolS
*start_symbol
;
153 /* (temporary) symbol used to mark the end of this function. */
156 /* frags associated with start and end of this function. */
160 /* frags for starting/ending offset of this descriptor. */
161 fragS
*start_offset_frag
;
162 fragS
*end_offset_frag
;
164 /* The location within {start,end}_offset_frag to find the
165 {start,end}_offset. */
166 int start_frag_where
;
169 /* Fixups (relocations) for start_offset and end_offset. */
173 /* Next entry in the chain. */
174 struct call_info
*ci_next
;
177 /* Operand formats for FP instructions. Note not all FP instructions
178 allow all four formats to be used (for example fmpysub only allows
182 SGL
, DBL
, ILLEGAL_FMT
, QUAD
186 /* This structure contains information needed to assemble
187 individual instructions. */
190 /* Holds the opcode after parsing by pa_ip. */
191 unsigned long opcode
;
193 /* Holds an expression associated with the current instruction. */
196 /* Does this instruction use PC-relative addressing. */
199 /* Floating point formats for operand1 and operand2. */
200 fp_operand_format fpof1
;
201 fp_operand_format fpof2
;
203 /* Holds the field selector for this instruction
204 (for example L%, LR%, etc). */
207 /* Holds any argument relocation bits associated with this
208 instruction. (instruction should be some sort of call). */
211 /* The format specification for this instruction. */
214 /* The relocation (if any) associated with this instruction. */
218 /* PA-89 floating point registers are arranged like this:
221 +--------------+--------------+
222 | 0 or 16L | 16 or 16R |
223 +--------------+--------------+
224 | 1 or 17L | 17 or 17R |
225 +--------------+--------------+
233 +--------------+--------------+
234 | 14 or 30L | 30 or 30R |
235 +--------------+--------------+
236 | 15 or 31L | 31 or 31R |
237 +--------------+--------------+
240 The following is a version of pa_parse_number that
241 handles the L/R notation and returns the correct
242 value to put into the instruction register field.
243 The correct value to put into the instruction is
244 encoded in the structure 'pa_89_fp_reg_struct'. */
246 struct pa_89_fp_reg_struct
248 /* The register number. */
255 /* Additional information needed to build argument relocation stubs. */
258 /* The argument relocation specification. */
259 unsigned int arg_reloc
;
261 /* Number of arguments. */
262 unsigned int arg_count
;
265 /* This structure defines an entry in the subspace dictionary
268 struct subspace_dictionary_chain
270 /* Index of containing space. */
271 unsigned long ssd_space_index
;
273 /* Which quadrant within the space this subspace should be loaded into. */
274 unsigned char ssd_quadrant
;
276 /* Alignment (in bytes) for this subspace. */
277 unsigned long ssd_alignment
;
279 /* Access control bits to determine read/write/execute permissions
280 as well as gateway privilege promotions. */
281 unsigned char ssd_access_control_bits
;
283 /* A sorting key so that it is possible to specify ordering of
284 subspaces within a space. */
285 unsigned char ssd_sort_key
;
287 /* Nonzero of this space should be zero filled. */
288 unsigned long ssd_zero
;
290 /* Nonzero if this is a common subspace. */
291 unsigned char ssd_common
;
293 /* Nonzero if this is a common subspace which allows symbols to be
295 unsigned char ssd_dup_common
;
297 /* Nonzero if this subspace is loadable. Note loadable subspaces
298 must be contained within loadable spaces; unloadable subspaces
299 must be contained in unloadable spaces. */
300 unsigned char ssd_loadable
;
302 /* Nonzero if this subspace contains only code. */
303 unsigned char ssd_code_only
;
305 /* Starting offset of this subspace. */
306 unsigned long ssd_subspace_start
;
308 /* Length of this subspace. */
309 unsigned long ssd_subspace_length
;
311 /* Name of this subspace. */
314 /* GAS segment and subsegment associated with this subspace. */
318 /* Index of this subspace within the subspace dictionary of the object
319 file. Not used until object file is written. */
320 int object_file_index
;
322 /* The size of the last alignment request for this subspace. */
325 /* Next space in the subspace dictionary chain. */
326 struct subspace_dictionary_chain
*ssd_next
;
329 typedef struct subspace_dictionary_chain ssd_chain_struct
;
331 /* This structure defines an entry in the subspace dictionary
334 struct space_dictionary_chain
337 /* Holds the index into the string table of the name of this
339 unsigned int sd_name_index
;
341 /* Nonzero if the space is loadable. */
342 unsigned int sd_loadable
;
344 /* Nonzero if this space has been defined by the user code or
345 as a default space. */
346 unsigned int sd_defined
;
348 /* Nonzero if this spaces has been defined by the user code. */
349 unsigned int sd_user_defined
;
351 /* Nonzero if this space is not sharable. */
352 unsigned int sd_private
;
354 /* The space number (or index). */
355 unsigned int sd_spnum
;
357 /* The sort key for this space. May be used to determine how to lay
358 out the spaces within the object file. */
359 unsigned char sd_sort_key
;
361 /* The name of this subspace. */
364 /* GAS segment to which this subspace corresponds. */
367 /* Current subsegment number being used. */
370 /* The chain of subspaces contained within this space. */
371 ssd_chain_struct
*sd_subspaces
;
373 /* The next entry in the space dictionary chain. */
374 struct space_dictionary_chain
*sd_next
;
377 typedef struct space_dictionary_chain sd_chain_struct
;
379 /* Structure for previous label tracking. Needed so that alignments,
380 callinfo declarations, etc can be easily attached to a particular
382 typedef struct label_symbol_struct
384 struct symbol
*lss_label
;
385 sd_chain_struct
*lss_space
;
386 struct label_symbol_struct
*lss_next
;
390 /* This structure defines attributes of the default subspace
391 dictionary entries. */
393 struct default_subspace_dict
395 /* Name of the subspace. */
398 /* FIXME. Is this still needed? */
401 /* Nonzero if this subspace is loadable. */
404 /* Nonzero if this subspace contains only code. */
407 /* Nonzero if this is a common subspace. */
410 /* Nonzero if this is a common subspace which allows symbols
411 to be multiply defined. */
414 /* Nonzero if this subspace should be zero filled. */
417 /* Sort key for this subspace. */
420 /* Access control bits for this subspace. Can represent RWX access
421 as well as privilege level changes for gateways. */
424 /* Index of containing space. */
427 /* Alignment (in bytes) of this subspace. */
430 /* Quadrant within space where this subspace should be loaded. */
433 /* An index into the default spaces array. */
436 /* An alias for this section (or NULL if no alias exists). */
439 /* Subsegment associated with this subspace. */
443 /* This structure defines attributes of the default space
444 dictionary entries. */
446 struct default_space_dict
448 /* Name of the space. */
451 /* Space number. It is possible to identify spaces within
452 assembly code numerically! */
455 /* Nonzero if this space is loadable. */
458 /* Nonzero if this space is "defined". FIXME is still needed */
461 /* Nonzero if this space can not be shared. */
464 /* Sort key for this space. */
467 /* Segment associated with this space. */
470 /* An alias for this section (or NULL if no alias exists). */
474 /* Extra information needed to perform fixups (relocations) on the PA. */
475 struct hppa_fix_struct
477 /* The field selector. */
483 /* Format of fixup. */
486 /* Argument relocation bits. */
489 /* The unwind descriptor associated with this fixup. */
493 /* Structure to hold information about predefined registers. */
501 /* This structure defines the mapping from a FP condition string
502 to a condition number which can be recorded in an instruction. */
509 /* This structure defines a mapping from a field selector
510 string to a field selector type. */
511 struct selector_entry
517 /* Prototypes for functions local to tc-hppa.c. */
519 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
520 static void pa_cons
PARAMS ((int));
521 static void pa_data
PARAMS ((int));
522 static void pa_desc
PARAMS ((int));
523 static void pa_float_cons
PARAMS ((int));
524 static void pa_fill
PARAMS ((int));
525 static void pa_lcomm
PARAMS ((int));
526 static void pa_lsym
PARAMS ((int));
527 static void pa_stringer
PARAMS ((int));
528 static void pa_text
PARAMS ((int));
529 static void pa_version
PARAMS ((int));
530 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
531 static int get_expression
PARAMS ((char *));
532 static int pa_get_absolute_expression
PARAMS ((char *));
533 static int evaluate_absolute
PARAMS ((expressionS
, int));
534 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
535 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
536 static int pa_parse_nullif
PARAMS ((char **));
537 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
538 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
539 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
540 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
541 static void pa_block
PARAMS ((int));
542 static void pa_call
PARAMS ((int));
543 static void pa_call_args
PARAMS ((struct call_desc
*));
544 static void pa_callinfo
PARAMS ((int));
545 static void pa_code
PARAMS ((int));
546 static void pa_comm
PARAMS ((int));
547 static void pa_copyright
PARAMS ((int));
548 static void pa_end
PARAMS ((int));
549 static void pa_enter
PARAMS ((int));
550 static void pa_entry
PARAMS ((int));
551 static void pa_equ
PARAMS ((int));
552 static void pa_exit
PARAMS ((int));
553 static void pa_export
PARAMS ((int));
554 static void pa_export_args
PARAMS ((symbolS
*));
555 static void pa_import
PARAMS ((int));
556 static void pa_label
PARAMS ((int));
557 static void pa_leave
PARAMS ((int));
558 static void pa_origin
PARAMS ((int));
559 static void pa_proc
PARAMS ((int));
560 static void pa_procend
PARAMS ((int));
561 static void pa_space
PARAMS ((int));
562 static void pa_spnum
PARAMS ((int));
563 static void pa_subspace
PARAMS ((int));
564 static void pa_param
PARAMS ((int));
565 static void pa_undefine_label
PARAMS ((void));
566 static int need_89_opcode
PARAMS ((struct pa_it
*,
567 struct pa_89_fp_reg_struct
*));
568 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
569 static label_symbol_struct
*pa_get_label
PARAMS ((void));
570 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, char,
573 static ssd_chain_struct
* create_new_subspace
PARAMS ((sd_chain_struct
*,
578 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
579 char *, char, char, char,
580 char, char, char, int,
581 int, int, int, subsegT
));
582 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
583 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *, subsegT
));
584 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
585 static ssd_chain_struct
* pa_subsegment_to_subspace
PARAMS ((asection
*,
587 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
588 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
589 static void pa_ip
PARAMS ((char *));
590 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
591 long, expressionS
*, int,
592 bfd_reloc_code_real_type
, long,
594 static void md_apply_fix_1
PARAMS ((fixS
*, long));
595 static int is_end_of_statement
PARAMS ((void));
596 static int reg_name_search
PARAMS ((char *));
597 static int pa_chk_field_selector
PARAMS ((char **));
598 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
599 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
600 static void process_exit
PARAMS ((void));
601 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
602 static void pa_align_subseg
PARAMS ((asection
*, subsegT
));
603 static int log2
PARAMS ((int));
604 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
605 static unsigned int pa_stringer_aux
PARAMS ((char *));
606 static void pa_spaces_begin
PARAMS ((void));
609 /* File and gloally scoped variable declarations. */
611 /* Root and final entry in the space chain. */
612 static sd_chain_struct
*space_dict_root
;
613 static sd_chain_struct
*space_dict_last
;
615 /* The current space and subspace. */
616 static sd_chain_struct
*current_space
;
617 static ssd_chain_struct
*current_subspace
;
619 /* Root of the call_info chain. */
620 static struct call_info
*call_info_root
;
622 /* The last call_info (for functions) structure
623 seen so it can be associated with fixups and
625 static struct call_info
*last_call_info
;
627 /* The last call description (for actual calls). */
628 static struct call_desc last_call_desc
;
630 /* Relaxation isn't supported for the PA yet. */
631 const relax_typeS md_relax_table
[] = {0};
633 /* Jumps are always the same size -- one instruction. */
634 int md_short_jump_size
= 4;
635 int md_long_jump_size
= 4;
637 /* handle of the OPCODE hash table */
638 static struct hash_control
*op_hash
= NULL
;
640 /* This array holds the chars that always start a comment. If the
641 pre-processor is disabled, these aren't very useful. */
642 const char comment_chars
[] = ";";
644 /* Table of pseudo ops for the PA. FIXME -- how many of these
645 are now redundant with the overall GAS and the object file
647 const pseudo_typeS md_pseudo_table
[] =
649 /* align pseudo-ops on the PA specify the actual alignment requested,
650 not the log2 of the requested alignment. */
651 {"align", s_align_bytes
, 8},
652 {"ALIGN", s_align_bytes
, 8},
653 {"block", pa_block
, 1},
654 {"BLOCK", pa_block
, 1},
655 {"blockz", pa_block
, 0},
656 {"BLOCKZ", pa_block
, 0},
657 {"byte", pa_cons
, 1},
658 {"BYTE", pa_cons
, 1},
659 {"call", pa_call
, 0},
660 {"CALL", pa_call
, 0},
661 {"callinfo", pa_callinfo
, 0},
662 {"CALLINFO", pa_callinfo
, 0},
663 {"code", pa_code
, 0},
664 {"CODE", pa_code
, 0},
665 {"comm", pa_comm
, 0},
666 {"COMM", pa_comm
, 0},
667 {"copyright", pa_copyright
, 0},
668 {"COPYRIGHT", pa_copyright
, 0},
669 {"data", pa_data
, 0},
670 {"DATA", pa_data
, 0},
671 {"desc", pa_desc
, 0},
672 {"DESC", pa_desc
, 0},
673 {"double", pa_float_cons
, 'd'},
674 {"DOUBLE", pa_float_cons
, 'd'},
677 {"enter", pa_enter
, 0},
678 {"ENTER", pa_enter
, 0},
679 {"entry", pa_entry
, 0},
680 {"ENTRY", pa_entry
, 0},
683 {"exit", pa_exit
, 0},
684 {"EXIT", pa_exit
, 0},
685 {"export", pa_export
, 0},
686 {"EXPORT", pa_export
, 0},
687 {"fill", pa_fill
, 0},
688 {"FILL", pa_fill
, 0},
689 {"float", pa_float_cons
, 'f'},
690 {"FLOAT", pa_float_cons
, 'f'},
691 {"half", pa_cons
, 2},
692 {"HALF", pa_cons
, 2},
693 {"import", pa_import
, 0},
694 {"IMPORT", pa_import
, 0},
697 {"label", pa_label
, 0},
698 {"LABEL", pa_label
, 0},
699 {"lcomm", pa_lcomm
, 0},
700 {"LCOMM", pa_lcomm
, 0},
701 {"leave", pa_leave
, 0},
702 {"LEAVE", pa_leave
, 0},
703 {"long", pa_cons
, 4},
704 {"LONG", pa_cons
, 4},
705 {"lsym", pa_lsym
, 0},
706 {"LSYM", pa_lsym
, 0},
707 {"octa", pa_cons
, 16},
708 {"OCTA", pa_cons
, 16},
709 {"org", pa_origin
, 0},
710 {"ORG", pa_origin
, 0},
711 {"origin", pa_origin
, 0},
712 {"ORIGIN", pa_origin
, 0},
713 {"param", pa_param
, 0},
714 {"PARAM", pa_param
, 0},
715 {"proc", pa_proc
, 0},
716 {"PROC", pa_proc
, 0},
717 {"procend", pa_procend
, 0},
718 {"PROCEND", pa_procend
, 0},
719 {"quad", pa_cons
, 8},
720 {"QUAD", pa_cons
, 8},
723 {"short", pa_cons
, 2},
724 {"SHORT", pa_cons
, 2},
725 {"single", pa_float_cons
, 'f'},
726 {"SINGLE", pa_float_cons
, 'f'},
727 {"space", pa_space
, 0},
728 {"SPACE", pa_space
, 0},
729 {"spnum", pa_spnum
, 0},
730 {"SPNUM", pa_spnum
, 0},
731 {"string", pa_stringer
, 0},
732 {"STRING", pa_stringer
, 0},
733 {"stringz", pa_stringer
, 1},
734 {"STRINGZ", pa_stringer
, 1},
735 {"subspa", pa_subspace
, 0},
736 {"SUBSPA", pa_subspace
, 0},
737 {"text", pa_text
, 0},
738 {"TEXT", pa_text
, 0},
739 {"version", pa_version
, 0},
740 {"VERSION", pa_version
, 0},
741 {"word", pa_cons
, 4},
742 {"WORD", pa_cons
, 4},
746 /* This array holds the chars that only start a comment at the beginning of
747 a line. If the line seems to have the form '# 123 filename'
748 .line and .file directives will appear in the pre-processed output.
750 Note that input_file.c hand checks for '#' at the beginning of the
751 first line of the input file. This is because the compiler outputs
752 #NO_APP at the beginning of its output.
754 Also note that '/*' will always start a comment. */
755 const char line_comment_chars
[] = "#";
757 /* This array holds the characters which act as line separators. */
758 const char line_separator_chars
[] = "!";
760 /* Chars that can be used to separate mant from exp in floating point nums. */
761 const char EXP_CHARS
[] = "eE";
763 /* Chars that mean this number is a floating point constant.
764 As in 0f12.456 or 0d1.2345e12.
766 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
767 changed in read.c. Ideally it shouldn't hae to know abou it at
768 all, but nothing is ideal around here. */
769 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
771 static struct pa_it the_insn
;
773 /* Points to the end of an expression just parsed by get_expressoin
774 and friends. FIXME. This shouldn't be handled with a file-global
776 static char *expr_end
;
778 /* Nonzero if a .callinfo appeared within the current procedure. */
779 static int callinfo_found
;
781 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
782 static int within_entry_exit
;
784 /* Nonzero if the assembler has completed exit processing for the
785 current procedure. */
786 static int exit_processing_complete
;
788 /* Nonzero if the assembler is currently within a procedure definition. */
789 static int within_procedure
;
791 /* Handle on strucutre which keep track of the last symbol
792 seen in each subspace. */
793 static label_symbol_struct
*label_symbols_rootp
= NULL
;
795 /* Holds the last field selector. */
796 static int hppa_field_selector
;
798 /* Nonzero if errors are to be printed. */
799 static int print_errors
= 1;
801 /* List of registers that are pre-defined:
803 Each general register has one predefined name of the form
804 %r<REGNUM> which has the value <REGNUM>.
806 Space and control registers are handled in a similar manner,
807 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
809 Likewise for the floating point registers, but of the form
810 %fr<REGNUM>. Floating point registers have additional predefined
811 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
812 again have the value <REGNUM>.
814 Many registers also have synonyms:
816 %r26 - %r23 have %arg0 - %arg3 as synonyms
817 %r28 - %r29 have %ret0 - %ret1 as synonyms
818 %r30 has %sp as a synonym
820 Almost every control register has a synonym; they are not listed
823 The table is sorted. Suitable for searching by a binary search. */
825 static const struct pd_reg pre_defined_registers
[] =
1035 /* This table is sorted by order of the length of the string. This is
1036 so we check for <> before we check for <. If we had a <> and checked
1037 for < first, we would get a false match. */
1038 static const struct fp_cond_map fp_cond_map
[] =
1074 static const struct selector_entry selector_table
[] =
1109 /* default space and subspace dictionaries */
1111 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1112 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1114 /* pre-defined subsegments (subspaces) for the HPPA. */
1115 #define SUBSEG_CODE 0
1116 #define SUBSEG_DATA 0
1117 #define SUBSEG_LIT 1
1118 #define SUBSEG_BSS 2
1119 #define SUBSEG_UNWIND 3
1120 #define SUBSEG_GDB_STRINGS 0
1121 #define SUBSEG_GDB_SYMBOLS 1
1123 static struct default_subspace_dict pa_def_subspaces
[] =
1125 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1126 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1127 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1128 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1129 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1130 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1133 static struct default_space_dict pa_def_spaces
[] =
1135 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1136 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1137 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1140 /* Misc local definitions used by the assembler. */
1142 /* Return nonzero if the string pointed to by S potentially represents
1143 a right or left half of a FP register */
1144 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1145 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1147 /* These macros are used to maintain spaces/subspaces. */
1148 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1149 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1150 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1151 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1152 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1153 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1154 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1155 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1157 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1158 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1159 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1160 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1161 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1162 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1163 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1164 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1165 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1166 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1167 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1168 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1169 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1171 #define is_DP_relative(exp) \
1172 ((exp).X_op == O_subtract \
1173 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1175 #define is_PC_relative(exp) \
1176 ((exp).X_op == O_subtract \
1177 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1179 #define is_complex(exp) \
1180 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1182 /* Actual functions to implement the PA specific code for the assembler. */
1184 /* Returns a pointer to the label_symbol_struct for the current space.
1185 or NULL if no label_symbol_struct exists for the current space. */
1187 static label_symbol_struct
*
1190 label_symbol_struct
*label_chain
;
1191 sd_chain_struct
*space_chain
= current_space
;
1193 for (label_chain
= label_symbols_rootp
;
1195 label_chain
= label_chain
->lss_next
)
1196 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1202 /* Defines a label for the current space. If one is already defined,
1203 this function will replace it with the new label. */
1206 pa_define_label (symbol
)
1209 label_symbol_struct
*label_chain
= pa_get_label ();
1210 sd_chain_struct
*space_chain
= current_space
;
1213 label_chain
->lss_label
= symbol
;
1216 /* Create a new label entry and add it to the head of the chain. */
1218 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1219 label_chain
->lss_label
= symbol
;
1220 label_chain
->lss_space
= space_chain
;
1221 label_chain
->lss_next
= NULL
;
1223 if (label_symbols_rootp
)
1224 label_chain
->lss_next
= label_symbols_rootp
;
1226 label_symbols_rootp
= label_chain
;
1230 /* Removes a label definition for the current space.
1231 If there is no label_symbol_struct entry, then no action is taken. */
1234 pa_undefine_label ()
1236 label_symbol_struct
*label_chain
;
1237 label_symbol_struct
*prev_label_chain
= NULL
;
1238 sd_chain_struct
*space_chain
= current_space
;
1240 for (label_chain
= label_symbols_rootp
;
1242 label_chain
= label_chain
->lss_next
)
1244 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1246 /* Remove the label from the chain and free its memory. */
1247 if (prev_label_chain
)
1248 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1250 label_symbols_rootp
= label_chain
->lss_next
;
1255 prev_label_chain
= label_chain
;
1260 /* An HPPA-specific version of fix_new. This is required because the HPPA
1261 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1262 results in the creation of an instance of an hppa_fix_struct. An
1263 hppa_fix_struct stores the extra information along with a pointer to the
1264 original fixS. This is attached to the original fixup via the
1265 tc_fix_data field. */
1268 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1269 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1273 symbolS
*add_symbol
;
1277 bfd_reloc_code_real_type r_type
;
1285 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1286 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1289 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1291 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1292 new_fix
->tc_fix_data
= hppa_fix
;
1293 hppa_fix
->fx_r_type
= r_type
;
1294 hppa_fix
->fx_r_field
= r_field
;
1295 hppa_fix
->fx_r_format
= r_format
;
1296 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1298 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1302 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1303 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1306 parse_cons_expression_hppa (exp
)
1309 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1313 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1314 hppa_field_selector is set by the parse_cons_expression_hppa. */
1317 cons_fix_new_hppa (frag
, where
, size
, exp
)
1323 unsigned int reloc_type
;
1325 if (is_DP_relative (*exp
))
1326 reloc_type
= R_HPPA_GOTOFF
;
1327 else if (is_complex (*exp
))
1328 reloc_type
= R_HPPA_COMPLEX
;
1330 reloc_type
= R_HPPA
;
1332 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1333 as_warn ("Invalid field selector. Assuming F%%.");
1335 fix_new_hppa (frag
, where
, size
,
1336 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1337 hppa_field_selector
, 32, 0, (char *) 0);
1340 /* This function is called once, at assembler startup time. It should
1341 set up all the tables, etc. that the MD part of the assembler will need. */
1346 char *retval
= NULL
;
1350 last_call_info
= NULL
;
1351 call_info_root
= NULL
;
1353 /* Folding of text and data segments fails miserably on the PA.
1354 Warn user and disable "-R" option. */
1357 as_warn ("-R option not supported on this target.");
1358 flag_readonly_data_in_text
= 0;
1364 op_hash
= hash_new ();
1365 if (op_hash
== NULL
)
1366 as_fatal ("Virtual memory exhausted");
1368 while (i
< NUMOPCODES
)
1370 const char *name
= pa_opcodes
[i
].name
;
1371 retval
= hash_insert (op_hash
, name
, &pa_opcodes
[i
]);
1372 if (retval
!= NULL
&& *retval
!= '\0')
1374 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1379 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1380 != pa_opcodes
[i
].match
)
1382 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1383 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1388 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1392 as_fatal ("Broken assembler. No assembly attempted.");
1394 /* SOM will change text_section. To make sure we never put
1395 anything into the old one switch to the new one now. */
1396 subseg_set (text_section
, 0);
1399 /* Called at the end of assembling a source file. Nothing to do
1400 at this point on the PA. */
1408 /* Assemble a single instruction storing it into a frag. */
1415 /* The had better be something to assemble. */
1418 /* Assemble the instruction. Results are saved into "the_insn". */
1421 /* Get somewhere to put the assembled instrution. */
1424 /* Output the opcode. */
1425 md_number_to_chars (to
, the_insn
.opcode
, 4);
1427 /* If necessary output more stuff. */
1428 if (the_insn
.reloc
!= R_HPPA_NONE
)
1429 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1430 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1431 the_insn
.reloc
, the_insn
.field_selector
,
1432 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1436 /* Do the real work for assembling a single instruction. Store results
1437 into the global "the_insn" variable.
1439 FIXME: Should define and use some functions/macros to handle
1440 various common insertions of information into the opcode. */
1446 char *error_message
= "";
1447 char *s
, c
, *argstart
, *name
, *save_s
;
1451 int reg
, s2
, s3
, m
, a
, uu
, cmpltr
, nullif
, flag
, sfu
, cond
;
1452 unsigned int im21
, im14
, im11
, im5
;
1453 unsigned long i
, opcode
;
1454 struct pa_opcode
*insn
;
1456 /* Skip to something interesting. */
1457 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1476 as_bad ("Unknown opcode: `%s'", str
);
1482 /* Convert everything into lower case. */
1485 if (isupper (*save_s
))
1486 *save_s
= tolower (*save_s
);
1490 /* Look up the opcode in the has table. */
1491 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1493 as_bad ("Unknown opcode: `%s'", str
);
1502 /* Mark the location where arguments for the instruction start, then
1503 start processing them. */
1507 /* Do some initialization. */
1508 opcode
= insn
->match
;
1509 bzero (&the_insn
, sizeof (the_insn
));
1511 the_insn
.reloc
= R_HPPA_NONE
;
1513 /* Build the opcode, checking as we go to make
1514 sure that the operands match. */
1515 for (args
= insn
->args
;; ++args
)
1520 /* End of arguments. */
1536 /* These must match exactly. */
1545 /* Handle a 5 bit register or control register field at 10. */
1548 reg
= pa_parse_number (&s
, 0);
1549 if (reg
< 32 && reg
>= 0)
1551 opcode
|= reg
<< 21;
1556 /* Handle a 5 bit register field at 15. */
1558 reg
= pa_parse_number (&s
, 0);
1559 if (reg
< 32 && reg
>= 0)
1561 opcode
|= reg
<< 16;
1566 /* Handle a 5 bit register field at 31. */
1569 reg
= pa_parse_number (&s
, 0);
1570 if (reg
< 32 && reg
>= 0)
1577 /* Handle a 5 bit field length at 31. */
1579 pa_get_absolute_expression (s
);
1580 if (the_insn
.exp
.X_op
== O_constant
)
1582 reg
= the_insn
.exp
.X_add_number
;
1583 if (reg
<= 32 && reg
> 0)
1592 /* Handle a 5 bit immediate at 15. */
1594 pa_get_absolute_expression (s
);
1595 if (the_insn
.exp
.X_add_number
> 15)
1597 as_bad ("5 bit immediate > 15. Set to 15");
1598 the_insn
.exp
.X_add_number
= 15;
1600 else if (the_insn
.exp
.X_add_number
< -16)
1602 as_bad ("5 bit immediate < -16. Set to -16");
1603 the_insn
.exp
.X_add_number
= -16;
1606 low_sign_unext (evaluate_absolute (the_insn
.exp
,
1607 the_insn
.field_selector
),
1609 opcode
|= (im5
<< 16);
1613 /* Handle a 2 bit space identifier at 17. */
1615 s2
= pa_parse_number (&s
, 0);
1616 if (s2
< 4 && s2
>= 0)
1623 /* Handle a 3 bit space identifier at 18. */
1625 s3
= pa_parse_number (&s
, 0);
1626 if (s3
< 8 && s3
>= 0)
1628 dis_assemble_3 (s3
, &s3
);
1634 /* Handle a completer for an indexing load or store. */
1639 while (*s
== ',' && i
< 2)
1642 if (strncasecmp (s
, "sm", 2) == 0)
1649 else if (strncasecmp (s
, "m", 1) == 0)
1651 else if (strncasecmp (s
, "s", 1) == 0)
1654 as_bad ("Invalid Indexed Load Completer.");
1659 as_bad ("Invalid Indexed Load Completer Syntax.");
1660 while (*s
== ' ' || *s
== '\t')
1667 /* Handle a short load/store completer. */
1674 if (strncasecmp (s
, "ma", 2) == 0)
1679 else if (strncasecmp (s
, "mb", 2) == 0)
1685 as_bad ("Invalid Short Load/Store Completer.");
1688 while (*s
== ' ' || *s
== '\t')
1694 /* Handle a stbys completer. */
1699 while (*s
== ',' && i
< 2)
1702 if (strncasecmp (s
, "m", 1) == 0)
1704 else if (strncasecmp (s
, "b", 1) == 0)
1706 else if (strncasecmp (s
, "e", 1) == 0)
1709 as_bad ("Invalid Store Bytes Short Completer");
1714 as_bad ("Invalid Store Bytes Short Completer");
1715 while (*s
== ' ' || *s
== '\t')
1721 /* Handle a non-negated compare/stubtract condition. */
1723 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1726 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1729 opcode
|= cmpltr
<< 13;
1732 /* Handle a negated or non-negated compare/subtract condition. */
1735 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1739 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1742 as_bad ("Invalid Compare/Subtract Condition.");
1747 /* Negated condition requires an opcode change. */
1751 opcode
|= cmpltr
<< 13;
1754 /* Handle a negated or non-negated add condition. */
1757 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1761 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1764 as_bad ("Invalid Compare/Subtract Condition");
1769 /* Negated condition requires an opcode change. */
1773 opcode
|= cmpltr
<< 13;
1776 /* Handle a compare/subtract condition. */
1783 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1788 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1791 as_bad ("Invalid Compare/Subtract Condition");
1795 opcode
|= cmpltr
<< 13;
1796 opcode
|= flag
<< 12;
1799 /* Handle a non-negated add condition. */
1808 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1812 if (strcmp (name
, "=") == 0)
1814 else if (strcmp (name
, "<") == 0)
1816 else if (strcmp (name
, "<=") == 0)
1818 else if (strcasecmp (name
, "nuv") == 0)
1820 else if (strcasecmp (name
, "znv") == 0)
1822 else if (strcasecmp (name
, "sv") == 0)
1824 else if (strcasecmp (name
, "od") == 0)
1826 else if (strcasecmp (name
, "n") == 0)
1828 else if (strcasecmp (name
, "tr") == 0)
1833 else if (strcasecmp (name
, "<>") == 0)
1838 else if (strcasecmp (name
, ">=") == 0)
1843 else if (strcasecmp (name
, ">") == 0)
1848 else if (strcasecmp (name
, "uv") == 0)
1853 else if (strcasecmp (name
, "vnz") == 0)
1858 else if (strcasecmp (name
, "nsv") == 0)
1863 else if (strcasecmp (name
, "ev") == 0)
1869 as_bad ("Invalid Add Condition: %s", name
);
1872 nullif
= pa_parse_nullif (&s
);
1873 opcode
|= nullif
<< 1;
1874 opcode
|= cmpltr
<< 13;
1875 opcode
|= flag
<< 12;
1878 /* Handle a logical instruction condition. */
1886 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1890 if (strcmp (name
, "=") == 0)
1892 else if (strcmp (name
, "<") == 0)
1894 else if (strcmp (name
, "<=") == 0)
1896 else if (strcasecmp (name
, "od") == 0)
1898 else if (strcasecmp (name
, "tr") == 0)
1903 else if (strcmp (name
, "<>") == 0)
1908 else if (strcmp (name
, ">=") == 0)
1913 else if (strcmp (name
, ">") == 0)
1918 else if (strcasecmp (name
, "ev") == 0)
1924 as_bad ("Invalid Logical Instruction Condition.");
1927 opcode
|= cmpltr
<< 13;
1928 opcode
|= flag
<< 12;
1931 /* Handle a unit instruction condition. */
1938 if (strncasecmp (s
, "sbz", 3) == 0)
1943 else if (strncasecmp (s
, "shz", 3) == 0)
1948 else if (strncasecmp (s
, "sdc", 3) == 0)
1953 else if (strncasecmp (s
, "sbc", 3) == 0)
1958 else if (strncasecmp (s
, "shc", 3) == 0)
1963 else if (strncasecmp (s
, "tr", 2) == 0)
1969 else if (strncasecmp (s
, "nbz", 3) == 0)
1975 else if (strncasecmp (s
, "nhz", 3) == 0)
1981 else if (strncasecmp (s
, "ndc", 3) == 0)
1987 else if (strncasecmp (s
, "nbc", 3) == 0)
1993 else if (strncasecmp (s
, "nhc", 3) == 0)
2000 as_bad ("Invalid Logical Instruction Condition.");
2002 opcode
|= cmpltr
<< 13;
2003 opcode
|= flag
<< 12;
2006 /* Handle a shift/extract/deposit condition. */
2014 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2018 if (strcmp (name
, "=") == 0)
2020 else if (strcmp (name
, "<") == 0)
2022 else if (strcasecmp (name
, "od") == 0)
2024 else if (strcasecmp (name
, "tr") == 0)
2026 else if (strcmp (name
, "<>") == 0)
2028 else if (strcmp (name
, ">=") == 0)
2030 else if (strcasecmp (name
, "ev") == 0)
2032 /* Handle movb,n. Put things back the way they were.
2033 This includes moving s back to where it started. */
2034 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
2041 as_bad ("Invalid Shift/Extract/Deposit Condition.");
2044 opcode
|= cmpltr
<< 13;
2047 /* Handle bvb and bb conditions. */
2053 if (strncmp (s
, "<", 1) == 0)
2058 else if (strncmp (s
, ">=", 2) == 0)
2064 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2066 opcode
|= cmpltr
<< 13;
2069 /* Handle a 5 bit immediate at 31. */
2072 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2073 the_insn
.field_selector
),
2079 /* Handle an unsigned 5 bit immediate at 31. */
2082 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2085 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2093 /* Handle an unsigned 5 bit immediate at 15. */
2096 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2099 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2103 opcode
|= im5
<< 16;
2107 /* Handle a 11 bit immediate at 31. */
2109 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2111 if (the_insn
.exp
.X_op
== O_constant
)
2113 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2114 the_insn
.field_selector
),
2120 if (is_DP_relative (the_insn
.exp
))
2121 the_insn
.reloc
= R_HPPA_GOTOFF
;
2122 else if (is_PC_relative (the_insn
.exp
))
2123 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2124 else if (is_complex (the_insn
.exp
))
2125 the_insn
.reloc
= R_HPPA_COMPLEX
;
2127 the_insn
.reloc
= R_HPPA
;
2128 the_insn
.format
= 11;
2133 /* Handle a 14 bit immediate at 31. */
2135 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2137 if (the_insn
.exp
.X_op
== O_constant
)
2139 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2140 the_insn
.field_selector
),
2142 if (the_insn
.field_selector
== e_rsel
)
2143 opcode
|= (im14
& 0xfff);
2149 if (is_DP_relative (the_insn
.exp
))
2150 the_insn
.reloc
= R_HPPA_GOTOFF
;
2151 else if (is_PC_relative (the_insn
.exp
))
2152 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2153 else if (is_complex (the_insn
.exp
))
2154 the_insn
.reloc
= R_HPPA_COMPLEX
;
2156 the_insn
.reloc
= R_HPPA
;
2157 the_insn
.format
= 14;
2162 /* Handle a 21 bit immediate at 31. */
2164 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2166 if (the_insn
.exp
.X_op
== O_constant
)
2168 dis_assemble_21 (evaluate_absolute (the_insn
.exp
,
2169 the_insn
.field_selector
),
2175 if (is_DP_relative (the_insn
.exp
))
2176 the_insn
.reloc
= R_HPPA_GOTOFF
;
2177 else if (is_PC_relative (the_insn
.exp
))
2178 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2179 else if (is_complex (the_insn
.exp
))
2180 the_insn
.reloc
= R_HPPA_COMPLEX
;
2182 the_insn
.reloc
= R_HPPA
;
2183 the_insn
.format
= 21;
2188 /* Handle a nullification completer for branch instructions. */
2190 nullif
= pa_parse_nullif (&s
);
2191 opcode
|= nullif
<< 1;
2194 /* Handle a 12 bit branch displacement. */
2196 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2199 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L0\001"))
2201 unsigned int w1
, w
, result
;
2203 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 12,
2205 dis_assemble_12 (result
, &w1
, &w
);
2206 opcode
|= ((w1
<< 2) | w
);
2210 if (is_complex (the_insn
.exp
))
2211 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2213 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2214 the_insn
.format
= 12;
2215 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2216 bzero (&last_call_desc
, sizeof (struct call_desc
));
2221 /* Handle a 17 bit branch displacement. */
2223 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2226 if (the_insn
.exp
.X_add_symbol
)
2228 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2231 unsigned int w2
, w1
, w
, result
;
2233 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2235 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2236 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2240 if (is_complex (the_insn
.exp
))
2241 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2243 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2244 the_insn
.format
= 17;
2245 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2246 bzero (&last_call_desc
, sizeof (struct call_desc
));
2251 unsigned int w2
, w1
, w
, result
;
2253 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2254 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2255 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2260 /* Handle an absolute 17 bit branch target. */
2262 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2265 if (the_insn
.exp
.X_add_symbol
)
2267 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2270 unsigned int w2
, w1
, w
, result
;
2272 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2274 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2275 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2279 if (is_complex (the_insn
.exp
))
2280 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2282 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2283 the_insn
.format
= 17;
2288 unsigned int w2
, w1
, w
, result
;
2290 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2291 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2292 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2297 /* Handle a 5 bit shift count at 26. */
2300 if (the_insn
.exp
.X_op
== O_constant
)
2301 opcode
|= (((31 - the_insn
.exp
.X_add_number
) & 0x1f) << 5);
2305 /* Handle a 5 bit bit position at 26. */
2308 if (the_insn
.exp
.X_op
== O_constant
)
2309 opcode
|= (the_insn
.exp
.X_add_number
& 0x1f) << 5;
2313 /* Handle a 5 bit immediate at 10. */
2316 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2319 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2323 opcode
|= im5
<< 21;
2327 /* Handle a 13 bit immediate at 18. */
2329 pa_get_absolute_expression (s
);
2330 if (the_insn
.exp
.X_op
== O_constant
)
2331 opcode
|= (the_insn
.exp
.X_add_number
& 0x1fff) << 13;
2335 /* Handle a system control completer. */
2337 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2346 while (*s
== ' ' || *s
== '\t')
2350 /* Handle a 26 bit immediate at 31. */
2352 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2354 if (the_insn
.exp
.X_op
== O_constant
)
2356 opcode
|= ((evaluate_absolute (the_insn
.exp
,
2357 the_insn
.field_selector
)
2361 as_bad ("Invalid DIAG operand");
2365 /* Handle a 3 bit SFU identifier at 25. */
2367 sfu
= pa_parse_number (&s
, 0);
2368 if ((sfu
> 7) || (sfu
< 0))
2369 as_bad ("Invalid SFU identifier: %02x", sfu
);
2370 opcode
|= (sfu
& 7) << 6;
2373 /* We don't support any of these. FIXME. */
2380 /* Handle a source FP operand format completer. */
2382 flag
= pa_parse_fp_format (&s
);
2383 opcode
|= (int) flag
<< 11;
2384 the_insn
.fpof1
= flag
;
2387 /* Handle a destination FP operand format completer. */
2390 /* pa_parse_format needs the ',' prefix. */
2392 flag
= pa_parse_fp_format (&s
);
2393 opcode
|= (int) flag
<< 13;
2394 the_insn
.fpof2
= flag
;
2397 /* Handle FP compare conditions. */
2399 cond
= pa_parse_fp_cmp_cond (&s
);
2403 /* Handle L/R register halves like 't'. */
2406 struct pa_89_fp_reg_struct result
;
2408 pa_parse_number (&s
, &result
);
2409 if (result
.number_part
< 32 && result
.number_part
>= 0)
2411 opcode
|= (result
.number_part
& 0x1f);
2413 /* 0x30 opcodes are FP arithmetic operation opcodes
2414 and need to be turned into 0x38 opcodes. This
2415 is not necessary for loads/stores. */
2416 if (need_89_opcode (&the_insn
, &result
))
2418 if ((opcode
& 0xfc000000) == 0x30000000)
2420 opcode
|= (result
.l_r_select
& 1) << 6;
2425 opcode
|= (result
.l_r_select
& 1) << 6;
2433 /* Handle L/R register halves like 'b'. */
2436 struct pa_89_fp_reg_struct result
;
2438 pa_parse_number (&s
, &result
);
2439 if (result
.number_part
< 32 && result
.number_part
>= 0)
2441 opcode
|= (result
.number_part
& 0x1f) << 21;
2442 if (need_89_opcode (&the_insn
, &result
))
2444 opcode
|= (result
.l_r_select
& 1) << 7;
2452 /* Handle L/R register halves like 'x'. */
2455 struct pa_89_fp_reg_struct result
;
2457 pa_parse_number (&s
, &result
);
2458 if (result
.number_part
< 32 && result
.number_part
>= 0)
2460 opcode
|= (result
.number_part
& 0x1f) << 16;
2461 if (need_89_opcode (&the_insn
, &result
))
2463 opcode
|= (result
.l_r_select
& 1) << 12;
2471 /* Handle a 5 bit register field at 10. */
2474 struct pa_89_fp_reg_struct result
;
2477 status
= pa_parse_number (&s
, &result
);
2478 if (result
.number_part
< 32 && result
.number_part
>= 0)
2480 if (the_insn
.fpof1
== SGL
)
2482 result
.number_part
&= 0xF;
2483 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2485 opcode
|= result
.number_part
<< 21;
2491 /* Handle a 5 bit register field at 15. */
2494 struct pa_89_fp_reg_struct result
;
2497 status
= pa_parse_number (&s
, &result
);
2498 if (result
.number_part
< 32 && result
.number_part
>= 0)
2500 if (the_insn
.fpof1
== SGL
)
2502 result
.number_part
&= 0xF;
2503 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2505 opcode
|= result
.number_part
<< 16;
2511 /* Handle a 5 bit register field at 31. */
2514 struct pa_89_fp_reg_struct result
;
2517 status
= pa_parse_number (&s
, &result
);
2518 if (result
.number_part
< 32 && result
.number_part
>= 0)
2520 if (the_insn
.fpof1
== SGL
)
2522 result
.number_part
&= 0xF;
2523 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2525 opcode
|= result
.number_part
;
2531 /* Handle a 5 bit register field at 20. */
2534 struct pa_89_fp_reg_struct result
;
2537 status
= pa_parse_number (&s
, &result
);
2538 if (result
.number_part
< 32 && result
.number_part
>= 0)
2540 if (the_insn
.fpof1
== SGL
)
2542 result
.number_part
&= 0xF;
2543 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2545 opcode
|= result
.number_part
<< 11;
2551 /* Handle a 5 bit register field at 25. */
2554 struct pa_89_fp_reg_struct result
;
2557 status
= pa_parse_number (&s
, &result
);
2558 if (result
.number_part
< 32 && result
.number_part
>= 0)
2560 if (the_insn
.fpof1
== SGL
)
2562 result
.number_part
&= 0xF;
2563 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2565 opcode
|= result
.number_part
<< 6;
2571 /* Handle a floating point operand format at 26.
2572 Only allows single and double precision. */
2574 flag
= pa_parse_fp_format (&s
);
2580 the_insn
.fpof1
= flag
;
2586 as_bad ("Invalid Floating Point Operand Format.");
2596 /* Check if the args matched. */
2599 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2600 && !strcmp (insn
->name
, insn
[1].name
))
2608 as_bad ("Invalid operands %s", error_message
);
2615 the_insn
.opcode
= opcode
;
2619 /* Turn a string in input_line_pointer into a floating point constant of type
2620 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2621 emitted is stored in *sizeP . An error message or NULL is returned. */
2623 #define MAX_LITTLENUMS 6
2626 md_atof (type
, litP
, sizeP
)
2632 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2633 LITTLENUM_TYPE
*wordP
;
2665 return "Bad call to MD_ATOF()";
2667 t
= atof_ieee (input_line_pointer
, type
, words
);
2669 input_line_pointer
= t
;
2670 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2671 for (wordP
= words
; prec
--;)
2673 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2674 litP
+= sizeof (LITTLENUM_TYPE
);
2679 /* Write out big-endian. */
2682 md_number_to_chars (buf
, val
, n
)
2704 /* Translate internal representation of relocation info to BFD target
2708 tc_gen_reloc (section
, fixp
)
2713 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2714 bfd_reloc_code_real_type code
;
2715 static int unwind_reloc_fixp_cnt
= 0;
2716 static arelent
*unwind_reloc_entryP
= NULL
;
2717 static arelent
*no_relocs
= NULL
;
2719 bfd_reloc_code_real_type
**codes
;
2723 if (fixp
->fx_addsy
== 0)
2725 assert (hppa_fixp
!= 0);
2726 assert (section
!= 0);
2729 /* Yuk. I would really like to push all this ELF specific unwind
2730 crud into BFD and the linker. That's how SOM does it -- and
2731 if we could make ELF emulate that then we could share more code
2732 in GAS (and potentially a gnu-linker later).
2734 Unwind section relocations are handled in a special way.
2735 The relocations for the .unwind section are originally
2736 built in the usual way. That is, for each unwind table
2737 entry there are two relocations: one for the beginning of
2738 the function and one for the end.
2740 The first time we enter this function we create a
2741 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2742 of the relocation is initialized to 0. Each additional
2743 pair of times this function is called for the unwind
2744 section represents an additional unwind table entry. Thus,
2745 the addend of the relocation should end up to be the number
2746 of unwind table entries. */
2747 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2749 if (unwind_reloc_entryP
== NULL
)
2751 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2753 assert (reloc
!= 0);
2754 unwind_reloc_entryP
= reloc
;
2755 unwind_reloc_fixp_cnt
++;
2756 unwind_reloc_entryP
->address
2757 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2758 /* A pointer to any function will do. We only
2759 need one to tell us what section the unwind
2760 relocations are for. */
2761 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2762 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2763 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2764 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2765 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2766 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2767 sizeof (arelent
*) * 2);
2768 assert (relocs
!= 0);
2769 relocs
[0] = unwind_reloc_entryP
;
2773 unwind_reloc_fixp_cnt
++;
2774 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2780 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2781 assert (reloc
!= 0);
2783 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2784 codes
= hppa_gen_reloc_type (stdoutput
,
2786 hppa_fixp
->fx_r_format
,
2787 hppa_fixp
->fx_r_field
);
2789 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2792 relocs
= (arelent
**)
2793 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2794 assert (relocs
!= 0);
2796 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2797 sizeof (arelent
) * n_relocs
);
2799 assert (reloc
!= 0);
2801 for (i
= 0; i
< n_relocs
; i
++)
2802 relocs
[i
] = &reloc
[i
];
2804 relocs
[n_relocs
] = NULL
;
2807 switch (fixp
->fx_r_type
)
2809 case R_HPPA_COMPLEX
:
2810 case R_HPPA_COMPLEX_PCREL_CALL
:
2811 case R_HPPA_COMPLEX_ABS_CALL
:
2812 assert (n_relocs
== 5);
2814 for (i
= 0; i
< n_relocs
; i
++)
2816 reloc
[i
].sym_ptr_ptr
= NULL
;
2817 reloc
[i
].address
= 0;
2818 reloc
[i
].addend
= 0;
2819 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2820 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2823 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2824 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2825 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2827 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2828 reloc
[3].addend
= fixp
->fx_addnumber
;
2829 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2830 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2831 reloc
[1].addend
= fixp
->fx_addnumber
;
2836 assert (n_relocs
== 1);
2840 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2841 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2842 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2843 reloc
->addend
= 0; /* default */
2845 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2847 /* Now, do any processing that is dependent on the relocation type. */
2850 case R_HPPA_PLABEL_32
:
2851 case R_HPPA_PLABEL_11
:
2852 case R_HPPA_PLABEL_14
:
2853 case R_HPPA_PLABEL_L21
:
2854 case R_HPPA_PLABEL_R11
:
2855 case R_HPPA_PLABEL_R14
:
2856 /* For plabel relocations, the addend of the
2857 relocation should be either 0 (no static link) or 2
2858 (static link required).
2860 FIXME: assume that fx_addnumber contains this
2862 reloc
->addend
= fixp
->fx_addnumber
;
2865 case R_HPPA_ABS_CALL_11
:
2866 case R_HPPA_ABS_CALL_14
:
2867 case R_HPPA_ABS_CALL_17
:
2868 case R_HPPA_ABS_CALL_L21
:
2869 case R_HPPA_ABS_CALL_R11
:
2870 case R_HPPA_ABS_CALL_R14
:
2871 case R_HPPA_ABS_CALL_R17
:
2872 case R_HPPA_ABS_CALL_LS21
:
2873 case R_HPPA_ABS_CALL_RS11
:
2874 case R_HPPA_ABS_CALL_RS14
:
2875 case R_HPPA_ABS_CALL_RS17
:
2876 case R_HPPA_ABS_CALL_LD21
:
2877 case R_HPPA_ABS_CALL_RD11
:
2878 case R_HPPA_ABS_CALL_RD14
:
2879 case R_HPPA_ABS_CALL_RD17
:
2880 case R_HPPA_ABS_CALL_LR21
:
2881 case R_HPPA_ABS_CALL_RR14
:
2882 case R_HPPA_ABS_CALL_RR17
:
2884 case R_HPPA_PCREL_CALL_11
:
2885 case R_HPPA_PCREL_CALL_14
:
2886 case R_HPPA_PCREL_CALL_17
:
2887 case R_HPPA_PCREL_CALL_L21
:
2888 case R_HPPA_PCREL_CALL_R11
:
2889 case R_HPPA_PCREL_CALL_R14
:
2890 case R_HPPA_PCREL_CALL_R17
:
2891 case R_HPPA_PCREL_CALL_LS21
:
2892 case R_HPPA_PCREL_CALL_RS11
:
2893 case R_HPPA_PCREL_CALL_RS14
:
2894 case R_HPPA_PCREL_CALL_RS17
:
2895 case R_HPPA_PCREL_CALL_LD21
:
2896 case R_HPPA_PCREL_CALL_RD11
:
2897 case R_HPPA_PCREL_CALL_RD14
:
2898 case R_HPPA_PCREL_CALL_RD17
:
2899 case R_HPPA_PCREL_CALL_LR21
:
2900 case R_HPPA_PCREL_CALL_RR14
:
2901 case R_HPPA_PCREL_CALL_RR17
:
2902 /* The constant is stored in the instruction. */
2903 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2906 reloc
->addend
= fixp
->fx_addnumber
;
2913 /* Preliminary relocation handling for SOM. Needs to handle
2914 COMPLEX relocations (yes, I've seen them occur) and it will
2915 need to handle R_ENTRY/R_EXIT relocations in the very near future
2916 (for generating unwinds). */
2917 switch (fixp
->fx_r_type
)
2919 case R_HPPA_COMPLEX
:
2920 case R_HPPA_COMPLEX_PCREL_CALL
:
2921 case R_HPPA_COMPLEX_ABS_CALL
:
2925 assert (n_relocs
== 1);
2929 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2930 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2931 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2938 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2941 reloc
->addend
= fixp
->fx_addnumber
;
2951 /* Process any machine dependent frag types. */
2954 md_convert_frag (abfd
, sec
, fragP
)
2956 register asection
*sec
;
2957 register fragS
*fragP
;
2959 unsigned int address
;
2961 if (fragP
->fr_type
== rs_machine_dependent
)
2963 switch ((int) fragP
->fr_subtype
)
2966 fragP
->fr_type
= rs_fill
;
2967 know (fragP
->fr_var
== 1);
2968 know (fragP
->fr_next
);
2969 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2970 if (address
% fragP
->fr_offset
)
2973 fragP
->fr_next
->fr_address
2978 fragP
->fr_offset
= 0;
2984 /* Round up a section size to the appropriate boundary. */
2987 md_section_align (segment
, size
)
2991 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2992 int align2
= (1 << align
) - 1;
2994 return (size
+ align2
) & ~align2
;
2998 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3000 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3002 addressT from_addr
, to_addr
;
3006 fprintf (stderr
, "pa_create_short_jmp\n");
3010 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3012 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3014 addressT from_addr
, to_addr
;
3018 fprintf (stderr
, "pa_create_long_jump\n");
3022 /* Return the approximate size of a frag before relaxation has occurred. */
3024 md_estimate_size_before_relax (fragP
, segment
)
3025 register fragS
*fragP
;
3032 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3038 /* Parse machine dependent options. There are none on the PA. */
3040 md_parse_option (argP
, cntP
, vecP
)
3048 /* We have no need to default values of symbols. */
3051 md_undefined_symbol (name
)
3057 /* Parse an operand that is machine-specific.
3058 We just return without modifying the expression as we have nothing
3062 md_operand (expressionP
)
3063 expressionS
*expressionP
;
3067 /* Helper function for md_apply_fix. Actually determine if the fix
3068 can be applied, and if so, apply it.
3070 If a fix is applied, then set fx_addsy to NULL which indicates
3071 the fix was applied and need not be emitted into the object file. */
3074 md_apply_fix_1 (fixP
, val
)
3078 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3079 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
3080 long new_val
, result
;
3081 unsigned int w1
, w2
, w
;
3083 /* There should have been an HPPA specific fixup associated
3084 with the GAS fixup. */
3087 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3088 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3090 /* Sanity check the fixup type. */
3091 /* Is this really necessary? */
3092 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3095 /* Remember this value for emit_reloc. FIXME, is this braindamage
3096 documented anywhere!?! */
3097 fixP
->fx_addnumber
= val
;
3099 /* Check if this is an undefined symbol. No relocation can
3100 possibly be performed in this case. */
3101 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3103 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3108 /* Handle all opcodes with the 'j' operand type. */
3110 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3112 /* Mask off 14 bits to be changed. */
3113 bfd_put_32 (stdoutput
,
3114 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3116 low_sign_unext (new_val
, 14, &result
);
3119 /* Handle all opcodes with the 'k' operand type. */
3121 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3123 /* Mask off 21 bits to be changed. */
3124 bfd_put_32 (stdoutput
,
3125 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3127 dis_assemble_21 (new_val
, &result
);
3130 /* Handle all the opcodes with the 'i' operand type. */
3132 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3134 /* Mask off 11 bits to be changed. */
3135 bfd_put_32 (stdoutput
,
3136 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3138 low_sign_unext (new_val
, 11, &result
);
3141 /* Handle all the opcodes with the 'w' operand type. */
3143 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3145 /* Mask off 11 bits to be changed. */
3146 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3147 bfd_put_32 (stdoutput
,
3148 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3151 dis_assemble_12 (result
, &w1
, &w
);
3152 result
= ((w1
<< 2) | w
);
3153 fixP
->fx_addsy
= NULL
;
3156 #define too_far(VAL, NUM_BITS) \
3157 (((int)(VAL) > (1 << (NUM_BITS)) - 1) || ((int)(VAL) < (-1 << (NUM_BITS))))
3159 #define stub_needed(CALLER, CALLEE) \
3160 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3162 /* Handle some of the opcodes with the 'W' operand type. */
3164 /* If a long-call stub or argument relocation stub is
3165 needed, then we can not apply this relocation, instead
3166 the linker must handle it. */
3167 if (too_far (val
, 18)
3168 || stub_needed (((obj_symbol_type
*)
3169 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3170 hppa_fixP
->fx_arg_reloc
))
3173 /* No stubs were needed, we can perform this relocation. */
3174 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3176 /* Mask off 17 bits to be changed. */
3177 bfd_put_32 (stdoutput
,
3178 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3180 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3181 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3182 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3183 fixP
->fx_addsy
= NULL
;
3191 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3192 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3193 result
= fixP
->fx_addnumber
;
3198 fixP
->fx_addnumber
= fixP
->fx_offset
;
3199 bfd_put_32 (stdoutput
, 0, buf
);
3208 as_bad ("bad relocation type/fmt: 0x%02x/0x%02x",
3209 fixP
->fx_r_type
, fmt
);
3213 /* Insert the relocation. */
3214 buf
[0] |= (result
& 0xff000000) >> 24;
3215 buf
[1] |= (result
& 0x00ff0000) >> 16;
3216 buf
[2] |= (result
& 0x0000ff00) >> 8;
3217 buf
[3] |= result
& 0x000000ff;
3220 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3221 (unsigned int) fixP
, fixP
->fx_r_type
);
3224 /* Apply a fix into a frag's data (if possible). */
3227 md_apply_fix (fixP
, valp
)
3231 md_apply_fix_1 (fixP
, (long) *valp
);
3235 /* Exactly what point is a PC-relative offset relative TO?
3236 On the PA, they're relative to the address of the offset. */
3239 md_pcrel_from (fixP
)
3242 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3245 /* Return nonzero if the input line pointer is at the end of
3249 is_end_of_statement ()
3251 return ((*input_line_pointer
== '\n')
3252 || (*input_line_pointer
== ';')
3253 || (*input_line_pointer
== '!'));
3256 /* Read a number from S. The number might come in one of many forms,
3257 the most common will be a hex or decimal constant, but it could be
3258 a pre-defined register (Yuk!), or an absolute symbol.
3260 Return a number or -1 for failure.
3262 When parsing PA-89 FP register numbers RESULT will be
3263 the address of a structure to return information about
3264 L/R half of FP registers, store results there as appropriate.
3266 pa_parse_number can not handle negative constants and will fail
3267 horribly if it is passed such a constant. */
3270 pa_parse_number (s
, result
)
3272 struct pa_89_fp_reg_struct
*result
;
3281 /* Skip whitespace before the number. */
3282 while (*p
== ' ' || *p
== '\t')
3285 /* Store info in RESULT if requested by caller. */
3288 result
->number_part
= -1;
3289 result
->l_r_select
= -1;
3295 /* Looks like a number. */
3298 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3300 /* The number is specified in hex. */
3302 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3303 || ((*p
>= 'A') && (*p
<= 'F')))
3306 num
= num
* 16 + *p
- '0';
3307 else if (*p
>= 'a' && *p
<= 'f')
3308 num
= num
* 16 + *p
- 'a' + 10;
3310 num
= num
* 16 + *p
- 'A' + 10;
3316 /* The number is specified in decimal. */
3317 while (isdigit (*p
))
3319 num
= num
* 10 + *p
- '0';
3324 /* Store info in RESULT if requested by the caller. */
3327 result
->number_part
= num
;
3329 if (IS_R_SELECT (p
))
3331 result
->l_r_select
= 1;
3334 else if (IS_L_SELECT (p
))
3336 result
->l_r_select
= 0;
3340 result
->l_r_select
= 0;
3345 /* The number might be a predefined register. */
3350 /* Tege hack: Special case for general registers as the general
3351 code makes a binary search with case translation, and is VERY
3356 if (*p
== 'e' && *(p
+ 1) == 't'
3357 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3360 num
= *p
- '0' + 28;
3363 else if (!isdigit (*p
))
3364 as_bad ("Undefined register: '%s'. ASSUMING 0", name
);
3368 num
= num
* 10 + *p
++ - '0';
3369 while (isdigit (*p
));
3374 /* Do a normal register search. */
3375 while (is_part_of_name (c
))
3381 status
= reg_name_search (name
);
3387 as_bad ("Undefined register: '%s'. ASSUMING 0", name
);
3394 /* Store info in RESULT if requested by caller. */
3397 result
->number_part
= num
;
3398 if (IS_R_SELECT (p
- 1))
3399 result
->l_r_select
= 1;
3400 else if (IS_L_SELECT (p
- 1))
3401 result
->l_r_select
= 0;
3403 result
->l_r_select
= 0;
3408 /* And finally, it could be a symbol in the absolute section which
3409 is effectively a constant. */
3413 while (is_part_of_name (c
))
3419 if ((sym
= symbol_find (name
)) != NULL
)
3421 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3422 num
= S_GET_VALUE (sym
);
3426 as_bad ("Non-absolute constant: '%s'. ASSUMING 0", name
);
3434 as_bad ("Undefined absolute constant: '%s'. ASSUMING 0", name
);
3440 /* Store info in RESULT if requested by caller. */
3443 result
->number_part
= num
;
3444 if (IS_R_SELECT (p
- 1))
3445 result
->l_r_select
= 1;
3446 else if (IS_L_SELECT (p
- 1))
3447 result
->l_r_select
= 0;
3449 result
->l_r_select
= 0;
3457 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3459 /* Given NAME, find the register number associated with that name, return
3460 the integer value associated with the given name or -1 on failure. */
3463 reg_name_search (name
)
3466 int middle
, low
, high
;
3469 high
= REG_NAME_CNT
- 1;
3473 middle
= (low
+ high
) / 2;
3474 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3479 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3482 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3483 return (pre_defined_registers
[middle
].value
);
3489 /* Return nonzero if the given INSN and L/R information will require
3490 a new PA-89 opcode. */
3493 need_89_opcode (insn
, result
)
3495 struct pa_89_fp_reg_struct
*result
;
3497 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3503 /* Parse a condition for a fcmp instruction. Return the numerical
3504 code associated with the condition. */
3507 pa_parse_fp_cmp_cond (s
)
3514 for (i
= 0; i
< 32; i
++)
3516 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3517 strlen (fp_cond_map
[i
].string
)) == 0)
3519 cond
= fp_cond_map
[i
].cond
;
3520 *s
+= strlen (fp_cond_map
[i
].string
);
3521 while (**s
== ' ' || **s
== '\t')
3527 as_bad ("Invalid FP Compare Condition: %c", **s
);
3531 /* Parse an FP operand format completer returning the completer
3534 static fp_operand_format
3535 pa_parse_fp_format (s
)
3544 if (strncasecmp (*s
, "sgl", 3) == 0)
3549 else if (strncasecmp (*s
, "dbl", 3) == 0)
3554 else if (strncasecmp (*s
, "quad", 4) == 0)
3561 format
= ILLEGAL_FMT
;
3562 as_bad ("Invalid FP Operand Format: %3s", *s
);
3565 while (**s
== ' ' || **s
== '\t' || **s
== 0)
3571 /* Convert from a selector string into a selector type. */
3574 pa_chk_field_selector (str
)
3578 struct selector_entry
*tablep
;
3582 /* Read past any whitespace. */
3583 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3586 /* Yuk. Looks like a linear search through the table. With the
3587 frequence of some selectors it might make sense to sort the
3589 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3591 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3593 *str
+= strlen (tablep
->prefix
);
3594 selector
= tablep
->field_selector
;
3601 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3604 get_expression (str
)
3610 save_in
= input_line_pointer
;
3611 input_line_pointer
= str
;
3612 seg
= expression (&the_insn
.exp
);
3613 if (!(seg
== absolute_section
3614 || seg
== undefined_section
3615 || SEG_NORMAL (seg
)))
3617 as_warn ("Bad segment in expression.");
3618 expr_end
= input_line_pointer
;
3619 input_line_pointer
= save_in
;
3622 expr_end
= input_line_pointer
;
3623 input_line_pointer
= save_in
;
3627 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3629 pa_get_absolute_expression (str
)
3634 save_in
= input_line_pointer
;
3635 input_line_pointer
= str
;
3636 expression (&the_insn
.exp
);
3637 if (the_insn
.exp
.X_op
!= O_constant
)
3639 as_warn ("Bad segment (should be absolute).");
3640 expr_end
= input_line_pointer
;
3641 input_line_pointer
= save_in
;
3644 expr_end
= input_line_pointer
;
3645 input_line_pointer
= save_in
;
3649 /* Evaluate an absolute expression EXP which may be modified by
3650 the selector FIELD_SELECTOR. Return the value of the expression. */
3652 evaluate_absolute (exp
, field_selector
)
3658 value
= exp
.X_add_number
;
3660 switch (field_selector
)
3666 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3668 if (value
& 0x00000400)
3670 value
= (value
& 0xfffff800) >> 11;
3673 /* Sign extend from bit 21. */
3675 if (value
& 0x00000400)
3676 value
|= 0xfffff800;
3681 /* Arithmetic shift right 11 bits. */
3683 value
= (value
& 0xfffff800) >> 11;
3686 /* Set bits 0-20 to zero. */
3688 value
= value
& 0x7ff;
3691 /* Add 0x800 and arithmetic shift right 11 bits. */
3696 value
= (value
& 0xfffff800) >> 11;
3699 /* Set bitgs 0-21 to one. */
3701 value
|= 0xfffff800;
3704 /* This had better get fixed. It looks like we're quickly moving
3711 BAD_CASE (field_selector
);
3717 /* Given an argument location specification return the associated
3718 argument location number. */
3721 pa_build_arg_reloc (type_name
)
3725 if (strncasecmp (type_name
, "no", 2) == 0)
3727 if (strncasecmp (type_name
, "gr", 2) == 0)
3729 else if (strncasecmp (type_name
, "fr", 2) == 0)
3731 else if (strncasecmp (type_name
, "fu", 2) == 0)
3734 as_bad ("Invalid argument location: %s\n", type_name
);
3739 /* Encode and return an argument relocation specification for
3740 the given register in the location specified by arg_reloc. */
3743 pa_align_arg_reloc (reg
, arg_reloc
)
3745 unsigned int arg_reloc
;
3747 unsigned int new_reloc
;
3749 new_reloc
= arg_reloc
;
3765 as_bad ("Invalid argument description: %d", reg
);
3771 /* Parse a PA nullification completer (,n). Return nonzero if the
3772 completer was found; return zero if no completer was found. */
3784 if (strncasecmp (*s
, "n", 1) == 0)
3788 as_bad ("Invalid Nullification: (%c)", **s
);
3793 while (**s
== ' ' || **s
== '\t')
3799 /* Parse a non-negated compare/subtract completer returning the
3800 number (for encoding in instrutions) of the given completer.
3802 ISBRANCH specifies whether or not this is parsing a condition
3803 completer for a branch (vs a nullification completer for a
3804 computational instruction. */
3807 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3812 char *name
= *s
+ 1;
3820 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3824 if (strcmp (name
, "=") == 0)
3828 else if (strcmp (name
, "<") == 0)
3832 else if (strcmp (name
, "<=") == 0)
3836 else if (strcmp (name
, "<<") == 0)
3840 else if (strcmp (name
, "<<=") == 0)
3844 else if (strcasecmp (name
, "sv") == 0)
3848 else if (strcasecmp (name
, "od") == 0)
3852 /* If we have something like addb,n then there is no condition
3854 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3866 while (**s
== ' ' || **s
== '\t')
3870 /* Reset pointers if this was really a ,n for a branch instruction. */
3871 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3877 /* Parse a negated compare/subtract completer returning the
3878 number (for encoding in instrutions) of the given completer.
3880 ISBRANCH specifies whether or not this is parsing a condition
3881 completer for a branch (vs a nullification completer for a
3882 computational instruction. */
3885 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3890 char *name
= *s
+ 1;
3898 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3902 if (strcasecmp (name
, "tr") == 0)
3906 else if (strcmp (name
, "<>") == 0)
3910 else if (strcmp (name
, ">=") == 0)
3914 else if (strcmp (name
, ">") == 0)
3918 else if (strcmp (name
, ">>=") == 0)
3922 else if (strcmp (name
, ">>") == 0)
3926 else if (strcasecmp (name
, "nsv") == 0)
3930 else if (strcasecmp (name
, "ev") == 0)
3934 /* If we have something like addb,n then there is no condition
3936 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3948 while (**s
== ' ' || **s
== '\t')
3952 /* Reset pointers if this was really a ,n for a branch instruction. */
3953 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3959 /* Parse a non-negated addition completer returning the number
3960 (for encoding in instrutions) of the given completer.
3962 ISBRANCH specifies whether or not this is parsing a condition
3963 completer for a branch (vs a nullification completer for a
3964 computational instruction. */
3967 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3972 char *name
= *s
+ 1;
3980 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3984 if (strcmp (name
, "=") == 0)
3988 else if (strcmp (name
, "<") == 0)
3992 else if (strcmp (name
, "<=") == 0)
3996 else if (strcasecmp (name
, "nuv") == 0)
4000 else if (strcasecmp (name
, "znv") == 0)
4004 else if (strcasecmp (name
, "sv") == 0)
4008 else if (strcasecmp (name
, "od") == 0)
4012 /* If we have something like addb,n then there is no condition
4014 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4026 while (**s
== ' ' || **s
== '\t')
4030 /* Reset pointers if this was really a ,n for a branch instruction. */
4031 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4037 /* Parse a negated addition completer returning the number
4038 (for encoding in instrutions) of the given completer.
4040 ISBRANCH specifies whether or not this is parsing a condition
4041 completer for a branch (vs a nullification completer for a
4042 computational instruction. */
4045 pa_parse_neg_add_cmpltr (s
, isbranch
)
4050 char *name
= *s
+ 1;
4058 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4062 if (strcasecmp (name
, "tr") == 0)
4066 else if (strcmp (name
, "<>") == 0)
4070 else if (strcmp (name
, ">=") == 0)
4074 else if (strcmp (name
, ">") == 0)
4078 else if (strcmp (name
, "uv") == 0)
4082 else if (strcmp (name
, "vnz") == 0)
4086 else if (strcasecmp (name
, "nsv") == 0)
4090 else if (strcasecmp (name
, "ev") == 0)
4094 /* If we have something like addb,n then there is no condition
4096 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4108 while (**s
== ' ' || **s
== '\t')
4112 /* Reset pointers if this was really a ,n for a branch instruction. */
4113 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4119 /* Handle a .BLOCK type pseudo-op. */
4127 unsigned int temp_size
;
4130 temp_size
= get_absolute_expression ();
4132 /* Always fill with zeros, that's what the HP assembler does. */
4135 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4136 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4137 bzero (p
, temp_size
);
4139 /* Convert 2 bytes at a time. */
4141 for (i
= 0; i
< temp_size
; i
+= 2)
4143 md_number_to_chars (p
+ i
,
4145 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4148 pa_undefine_label ();
4149 demand_empty_rest_of_line ();
4153 /* Handle a .CALL pseudo-op. This involves storing away information
4154 about where arguments are to be found so the linker can detect
4155 (and correct) argument location mismatches between caller and callee. */
4161 pa_call_args (&last_call_desc
);
4162 demand_empty_rest_of_line ();
4166 /* Do the dirty work of building a call descriptor which describes
4167 where the caller placed arguments to a function call. */
4170 pa_call_args (call_desc
)
4171 struct call_desc
*call_desc
;
4174 unsigned int temp
, arg_reloc
;
4176 while (!is_end_of_statement ())
4178 name
= input_line_pointer
;
4179 c
= get_symbol_end ();
4180 /* Process a source argument. */
4181 if ((strncasecmp (name
, "argw", 4) == 0))
4183 temp
= atoi (name
+ 4);
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
|= pa_align_arg_reloc (temp
, arg_reloc
);
4192 /* Process a return value. */
4193 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4195 p
= input_line_pointer
;
4197 input_line_pointer
++;
4198 name
= input_line_pointer
;
4199 c
= get_symbol_end ();
4200 arg_reloc
= pa_build_arg_reloc (name
);
4201 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4205 as_bad ("Invalid .CALL argument: %s", name
);
4207 p
= input_line_pointer
;
4209 if (!is_end_of_statement ())
4210 input_line_pointer
++;
4214 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4217 is_same_frag (frag1
, frag2
)
4224 else if (frag2
== NULL
)
4226 else if (frag1
== frag2
)
4228 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4229 return (is_same_frag (frag1
, frag2
->fr_next
));
4234 /* Build an entry in the UNWIND subspace from the given
4235 function attributes in CALL_INFO. */
4238 pa_build_unwind_subspace (call_info
)
4239 struct call_info
*call_info
;
4242 asection
*seg
, *save_seg
;
4243 subsegT subseg
, save_subseg
;
4247 /* Get into the right seg/subseg. This may involve creating
4248 the seg the first time through. Make sure to have the
4249 old seg/subseg so that we can reset things when we are done. */
4250 subseg
= SUBSEG_UNWIND
;
4251 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4252 if (seg
== ASEC_NULL
)
4254 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4255 bfd_set_section_flags (stdoutput
, seg
,
4256 SEC_READONLY
| SEC_HAS_CONTENTS
4257 | SEC_LOAD
| SEC_RELOC
);
4261 save_subseg
= now_subseg
;
4262 subseg_set (seg
, subseg
);
4265 /* Get some space to hold relocation information for the unwind
4268 call_info
->start_offset_frag
= frag_now
;
4269 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4271 /* Relocation info. for start offset of the function. */
4272 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4273 call_info
->start_symbol
, (offsetT
) 0,
4274 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4277 /* We need to search for the first relocation involving the start_symbol of
4278 this call_info descriptor. */
4282 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4283 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4285 if (fixP
->fx_addsy
== call_info
->start_symbol
4286 || fixP
->fx_subsy
== call_info
->start_symbol
)
4288 call_info
->start_fix
= fixP
;
4295 call_info
->end_offset_frag
= frag_now
;
4296 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4298 /* Relocation info. for end offset of the function. */
4299 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4300 call_info
->end_symbol
, (offsetT
) 0,
4301 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4304 /* We need to search for the first relocation involving the end_symbol of
4305 this call_info descriptor. */
4309 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4310 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4312 if (fixP
->fx_addsy
== call_info
->end_symbol
4313 || fixP
->fx_subsy
== call_info
->end_symbol
)
4315 call_info
->end_fix
= fixP
;
4321 /* callinfo.frame is in bytes and unwind_desc is in 8 byte units. */
4322 call_info
->ci_unwind
.descriptor
.frame_size
= call_info
->frame
/ 8;
4325 unwind
= (char *) &call_info
->ci_unwind
;
4326 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4330 FRAG_APPEND_1_CHAR (c
);
4334 /* Return back to the original segment/subsegment. */
4335 subseg_set (save_seg
, save_subseg
);
4338 /* Process a .CALLINFO pseudo-op. This information is used later
4339 to build unwind descriptors and maybe one day to support
4340 .ENTER and .LEAVE. */
4343 pa_callinfo (unused
)
4349 /* .CALLINFO must appear within a procedure definition. */
4350 if (!within_procedure
)
4351 as_bad (".callinfo is not within a procedure definition");
4353 /* Mark the fact that we found the .CALLINFO for the
4354 current procedure. */
4355 callinfo_found
= TRUE
;
4357 /* Iterate over the .CALLINFO arguments. */
4358 while (!is_end_of_statement ())
4360 name
= input_line_pointer
;
4361 c
= get_symbol_end ();
4362 /* Frame size specification. */
4363 if ((strncasecmp (name
, "frame", 5) == 0))
4365 p
= input_line_pointer
;
4367 input_line_pointer
++;
4368 temp
= get_absolute_expression ();
4369 if ((temp
& 0x3) != 0)
4371 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4374 last_call_info
->frame
= temp
;
4376 /* Entry register (GR, GR and SR) specifications. */
4377 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4379 p
= input_line_pointer
;
4381 input_line_pointer
++;
4382 temp
= get_absolute_expression ();
4383 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4384 even though %r19 is caller saved. I think this is a bug in
4385 the HP assembler, and we are not going to emulate it. */
4386 if (temp
< 3 || temp
> 18)
4387 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4388 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4390 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4392 p
= input_line_pointer
;
4394 input_line_pointer
++;
4395 temp
= get_absolute_expression ();
4396 /* Similarly the HP assembler takes 31 as the high bound even
4397 though %fr21 is the last callee saved floating point register. */
4398 if (temp
< 12 || temp
> 21)
4399 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4400 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4402 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4404 p
= input_line_pointer
;
4406 input_line_pointer
++;
4407 temp
= get_absolute_expression ();
4409 as_bad ("Value for ENTRY_SR must be 3\n");
4410 last_call_info
->entry_sr
= temp
- 2;
4412 /* Note whether or not this function performs any calls. */
4413 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4414 (strncasecmp (name
, "caller", 6) == 0))
4416 p
= input_line_pointer
;
4418 last_call_info
->makes_calls
= 1;
4420 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4422 p
= input_line_pointer
;
4424 last_call_info
->makes_calls
= 0;
4426 /* Should RP be saved into the stack. */
4427 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4429 p
= input_line_pointer
;
4431 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4433 /* Likewise for SP. */
4434 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4436 p
= input_line_pointer
;
4438 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4440 /* Is this an unwindable procedure. If so mark it so
4441 in the unwind descriptor. */
4442 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4444 p
= input_line_pointer
;
4446 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4448 /* Is this an interrupt routine. If so mark it in the
4449 unwind descriptor. */
4450 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4452 p
= input_line_pointer
;
4454 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4458 as_bad ("Invalid .CALLINFO argument: %s", name
);
4460 if (!is_end_of_statement ())
4461 input_line_pointer
++;
4464 demand_empty_rest_of_line ();
4468 /* Switch into the code subspace. */
4474 sd_chain_struct
*sdchain
;
4476 /* First time through it might be necessary to create the
4478 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4480 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4481 pa_def_spaces
[0].spnum
,
4482 pa_def_spaces
[0].loadable
,
4483 pa_def_spaces
[0].defined
,
4484 pa_def_spaces
[0].private,
4485 pa_def_spaces
[0].sort
,
4486 pa_def_spaces
[0].segment
, 0);
4489 SPACE_DEFINED (sdchain
) = 1;
4490 subseg_set (text_section
, SUBSEG_CODE
);
4491 demand_empty_rest_of_line ();
4495 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4496 the .comm pseudo-op has the following symtax:
4498 <label> .comm <length>
4500 where <label> is optional and is a symbol whose address will be the start of
4501 a block of memory <length> bytes long. <length> must be an absolute
4502 expression. <length> bytes will be allocated in the current space
4511 label_symbol_struct
*label_symbol
= pa_get_label ();
4514 symbol
= label_symbol
->lss_label
;
4519 size
= get_absolute_expression ();
4523 /* It is incorrect to check S_IS_DEFINED at this point as
4524 the symbol will *always* be defined. FIXME. How to
4525 correctly determine when this label really as been
4527 if (S_GET_VALUE (symbol
))
4529 if (S_GET_VALUE (symbol
) != size
)
4531 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4532 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4538 S_SET_VALUE (symbol
, size
);
4539 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4540 S_SET_EXTERNAL (symbol
);
4543 demand_empty_rest_of_line ();
4546 /* Process a .COPYRIGHT pseudo-op. */
4549 pa_copyright (unused
)
4556 if (*input_line_pointer
== '\"')
4558 ++input_line_pointer
;
4559 name
= input_line_pointer
;
4560 while ((c
= next_char_of_string ()) >= 0)
4562 c
= *input_line_pointer
;
4563 *input_line_pointer
= '\0';
4564 *(input_line_pointer
- 1) = '\0';
4566 /* FIXME. Not supported */
4569 *input_line_pointer
= c
;
4573 as_bad ("Expected \"-ed string");
4575 pa_undefine_label ();
4576 demand_empty_rest_of_line ();
4579 /* Process a .END pseudo-op. */
4585 demand_empty_rest_of_line ();
4589 /* Process a .ENTER pseudo-op. This is not supported. */
4598 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4606 if (!within_procedure
)
4607 as_bad ("Misplaced .entry. Ignored.");
4610 if (!callinfo_found
)
4611 as_bad ("Missing .callinfo.");
4613 last_call_info
->start_frag
= frag_now
;
4615 demand_empty_rest_of_line ();
4616 within_entry_exit
= TRUE
;
4617 where
= frag_more (0);
4619 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4620 It will not be on if no .EXPORT pseudo-op exists (static function). */
4621 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4626 /* Handle a .EQU pseudo-op. */
4632 label_symbol_struct
*label_symbol
= pa_get_label ();
4637 symbol
= label_symbol
->lss_label
;
4638 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4639 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4644 as_bad (".REG must use a label");
4646 as_bad (".EQU must use a label");
4649 pa_undefine_label ();
4650 demand_empty_rest_of_line ();
4654 /* Helper function. Does processing for the end of a function. This
4655 usually involves creating some relocations or building special
4656 symbols to mark the end of the function. */
4663 where
= frag_more (0);
4665 /* ELF does not have EXIT relocations. All we do is create a
4666 temporary symbol marking the end of the function. */
4668 char *name
= (char *) xmalloc (strlen ("L\001end_") +
4669 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
4675 strcpy (name
, "L\001end_");
4676 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
4678 symbolP
= symbol_find (name
);
4680 as_warn ("Symbol '%s' already defined.", name
);
4683 /* symbol value should be the offset of the
4684 last instruction of the function */
4685 symbolP
= symbol_new (name
, now_seg
,
4686 (valueT
) (obstack_next_free (&frags
)
4687 - frag_now
->fr_literal
- 4),
4691 symbolP
->bsym
->flags
= BSF_LOCAL
;
4692 symbol_table_insert (symbolP
);
4695 last_call_info
->end_symbol
= symbolP
;
4697 as_bad ("Symbol '%s' could not be created.", name
);
4701 as_bad ("No memory for symbol name.");
4704 /* Stuff away the location of the frag for the end of the function,
4705 and call pa_build_unwind_subspace to add an entry in the unwind
4707 last_call_info
->end_frag
= frag_now
;
4708 pa_build_unwind_subspace (last_call_info
);
4709 exit_processing_complete
= TRUE
;
4712 /* Process a .EXIT pseudo-op. */
4718 if (!within_procedure
)
4719 as_bad (".EXIT must appear within a procedure");
4722 if (!callinfo_found
)
4723 as_bad ("Missing .callinfo");
4726 if (!within_entry_exit
)
4727 as_bad ("No .ENTRY for this .EXIT");
4730 within_entry_exit
= FALSE
;
4735 demand_empty_rest_of_line ();
4739 /* Process a .EXPORT directive. This makes functions external
4740 and provides information such as argument relocation entries
4750 name
= input_line_pointer
;
4751 c
= get_symbol_end ();
4752 /* Make sure the given symbol exists. */
4753 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4755 as_bad ("Cannot define export symbol: %s\n", name
);
4756 p
= input_line_pointer
;
4758 input_line_pointer
++;
4762 /* OK. Set the external bits and process argument relocations. */
4763 S_SET_EXTERNAL (symbol
);
4764 p
= input_line_pointer
;
4766 if (!is_end_of_statement ())
4768 input_line_pointer
++;
4769 pa_export_args (symbol
);
4771 pa_build_symextn_section ();
4776 demand_empty_rest_of_line ();
4780 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4783 pa_export_args (symbolP
)
4787 unsigned int temp
, arg_reloc
;
4788 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4790 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4792 input_line_pointer
+= 8;
4793 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4794 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4796 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4798 input_line_pointer
+= 4;
4799 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4801 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4803 input_line_pointer
+= 4;
4804 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4806 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4808 input_line_pointer
+= 5;
4809 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4811 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4813 input_line_pointer
+= 9;
4814 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4816 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4818 input_line_pointer
+= 6;
4819 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4821 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4823 input_line_pointer
+= 8;
4824 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4826 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4828 input_line_pointer
+= 8;
4829 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4832 /* Now that the type of the exported symbol has been handled,
4833 handle any argument relocation information. */
4834 while (!is_end_of_statement ())
4836 if (*input_line_pointer
== ',')
4837 input_line_pointer
++;
4838 name
= input_line_pointer
;
4839 c
= get_symbol_end ();
4840 /* Argument sources. */
4841 if ((strncasecmp (name
, "argw", 4) == 0))
4843 p
= input_line_pointer
;
4845 input_line_pointer
++;
4846 temp
= atoi (name
+ 4);
4847 name
= input_line_pointer
;
4848 c
= get_symbol_end ();
4849 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4850 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4851 *input_line_pointer
= c
;
4853 /* The return value. */
4854 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4856 p
= input_line_pointer
;
4858 input_line_pointer
++;
4859 name
= input_line_pointer
;
4860 c
= get_symbol_end ();
4861 arg_reloc
= pa_build_arg_reloc (name
);
4862 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4863 *input_line_pointer
= c
;
4865 /* Privelege level. */
4866 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4868 p
= input_line_pointer
;
4870 input_line_pointer
++;
4871 temp
= atoi (input_line_pointer
);
4872 c
= get_symbol_end ();
4873 *input_line_pointer
= c
;
4877 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4878 p
= input_line_pointer
;
4881 if (!is_end_of_statement ())
4882 input_line_pointer
++;
4886 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4887 assembly file must either be defined in the assembly file, or
4888 explicitly IMPORTED from another. */
4897 name
= input_line_pointer
;
4898 c
= get_symbol_end ();
4900 symbol
= symbol_find_or_make (name
);
4901 p
= input_line_pointer
;
4904 if (!is_end_of_statement ())
4906 input_line_pointer
++;
4907 /* Hmmm. This doesn't look right. */
4908 pa_export_args (symbol
);
4912 /* If the section is undefined, then the symbol is undefined
4913 Since this is an import, leave the section undefined. */
4914 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4917 demand_empty_rest_of_line ();
4921 /* Handle a .LABEL pseudo-op. */
4929 name
= input_line_pointer
;
4930 c
= get_symbol_end ();
4932 if (strlen (name
) > 0)
4935 p
= input_line_pointer
;
4940 as_warn ("Missing label name on .LABEL");
4943 if (!is_end_of_statement ())
4945 as_warn ("extra .LABEL arguments ignored.");
4946 ignore_rest_of_line ();
4948 demand_empty_rest_of_line ();
4952 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4961 /* Handle a .ORIGIN pseudo-op. */
4968 pa_undefine_label ();
4972 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4973 is for static functions. FIXME. Should share more code with .EXPORT. */
4982 name
= input_line_pointer
;
4983 c
= get_symbol_end ();
4985 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4987 as_bad ("Cannot define static symbol: %s\n", name
);
4988 p
= input_line_pointer
;
4990 input_line_pointer
++;
4994 S_CLEAR_EXTERNAL (symbol
);
4995 p
= input_line_pointer
;
4997 if (!is_end_of_statement ())
4999 input_line_pointer
++;
5000 pa_export_args (symbol
);
5004 demand_empty_rest_of_line ();
5008 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5009 of a procedure from a syntatical point of view. */
5015 struct call_info
*call_info
;
5017 if (within_procedure
)
5018 as_fatal ("Nested procedures");
5020 /* Reset global variables for new procedure. */
5021 callinfo_found
= FALSE
;
5022 within_procedure
= TRUE
;
5023 exit_processing_complete
= FALSE
;
5025 /* Create another call_info structure. */
5026 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5029 as_fatal ("Cannot allocate unwind descriptor\n");
5031 bzero (call_info
, sizeof (struct call_info
));
5033 call_info
->ci_next
= NULL
;
5035 if (call_info_root
== NULL
)
5037 call_info_root
= call_info
;
5038 last_call_info
= call_info
;
5042 last_call_info
->ci_next
= call_info
;
5043 last_call_info
= call_info
;
5046 /* set up defaults on call_info structure */
5048 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5049 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5050 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5051 call_info
->entry_sr
= ~0;
5052 call_info
->makes_calls
= 1;
5054 /* If we got a .PROC pseudo-op, we know that the function is defined
5055 locally. Make sure it gets into the symbol table. */
5057 label_symbol_struct
*label_symbol
= pa_get_label ();
5061 if (label_symbol
->lss_label
)
5063 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5064 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5067 as_bad ("Missing function name for .PROC (corrupted label)");
5070 as_bad ("Missing function name for .PROC");
5073 demand_empty_rest_of_line ();
5077 /* Process the syntatical end of a procedure. Make sure all the
5078 appropriate pseudo-ops were found within the procedure. */
5085 if (!within_procedure
)
5086 as_bad ("misplaced .procend");
5088 if (!callinfo_found
)
5089 as_bad ("Missing .callinfo for this procedure");
5091 if (within_entry_exit
)
5092 as_bad ("Missing .EXIT for a .ENTRY");
5094 if (!exit_processing_complete
)
5097 within_procedure
= FALSE
;
5098 demand_empty_rest_of_line ();
5102 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5103 then create a new space entry to hold the information specified
5104 by the parameters to the .SPACE directive. */
5106 static sd_chain_struct
*
5107 pa_parse_space_stmt (space_name
, create_flag
)
5111 char *name
, *ptemp
, c
;
5112 char loadable
, defined
, private, sort
;
5114 asection
*seg
= NULL
;
5115 sd_chain_struct
*space
;
5117 /* load default values */
5123 if (strcasecmp (space_name
, "$TEXT$") == 0)
5125 seg
= pa_def_spaces
[0].segment
;
5126 sort
= pa_def_spaces
[0].sort
;
5128 else if (strcasecmp (space_name
, "$PRIVATE$") == 0)
5130 seg
= pa_def_spaces
[1].segment
;
5131 sort
= pa_def_spaces
[1].sort
;
5134 if (!is_end_of_statement ())
5136 print_errors
= FALSE
;
5137 ptemp
= input_line_pointer
+ 1;
5138 /* First see if the space was specified as a number rather than
5139 as a name. According to the PA assembly manual the rest of
5140 the line should be ignored. */
5141 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5142 input_line_pointer
= ptemp
;
5145 while (!is_end_of_statement ())
5147 input_line_pointer
++;
5148 name
= input_line_pointer
;
5149 c
= get_symbol_end ();
5150 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5152 *input_line_pointer
= c
;
5153 input_line_pointer
++;
5154 spnum
= get_absolute_expression ();
5156 else if ((strncasecmp (name
, "SORT", 4) == 0))
5158 *input_line_pointer
= c
;
5159 input_line_pointer
++;
5160 sort
= get_absolute_expression ();
5162 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5164 *input_line_pointer
= c
;
5167 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5169 *input_line_pointer
= c
;
5172 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5174 *input_line_pointer
= c
;
5179 as_bad ("Invalid .SPACE argument");
5180 *input_line_pointer
= c
;
5181 if (! is_end_of_statement ())
5182 input_line_pointer
++;
5186 print_errors
= TRUE
;
5189 if (create_flag
&& seg
== NULL
)
5190 seg
= subseg_new (space_name
, 0);
5192 /* If create_flag is nonzero, then create the new space with
5193 the attributes computed above. Else set the values in
5194 an already existing space -- this can only happen for
5195 the first occurence of a built-in space. */
5197 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5198 private, sort
, seg
, 1);
5201 space
= is_defined_space (space_name
);
5202 SPACE_SPNUM (space
) = spnum
;
5203 SPACE_LOADABLE (space
) = loadable
& 1;
5204 SPACE_DEFINED (space
) = defined
& 1;
5205 SPACE_USER_DEFINED (space
) = 1;
5206 SPACE_PRIVATE (space
) = private & 1;
5207 SPACE_SORT (space
) = sort
& 0xff;
5208 space
->sd_seg
= seg
;
5211 #ifdef obj_set_section_attributes
5212 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5218 /* Adjust the frag's alignment according to the alignment needs
5219 of the given subspace/subsegment. */
5222 pa_align_subseg (seg
, subseg
)
5226 ssd_chain_struct
*now_subspace
;
5230 now_subspace
= pa_subsegment_to_subspace (seg
, subseg
);
5233 if (SUBSPACE_ALIGN (now_subspace
) == 0)
5234 alignment
= now_subspace
->ssd_last_align
;
5235 else if (now_subspace
->ssd_last_align
> SUBSPACE_ALIGN (now_subspace
))
5236 alignment
= now_subspace
->ssd_last_align
;
5238 alignment
= SUBSPACE_ALIGN (now_subspace
);
5240 while ((1 << shift
) < alignment
)
5244 shift
= bfd_get_section_alignment (stdoutput
, seg
);
5246 frag_align (shift
, 0);
5249 /* Handle a .SPACE pseudo-op; this switches the current space to the
5250 given space, creating the new space if necessary. */
5256 char *name
, c
, *space_name
, *save_s
;
5258 sd_chain_struct
*sd_chain
;
5260 if (within_procedure
)
5262 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5263 ignore_rest_of_line ();
5267 /* Check for some of the predefined spaces. FIXME: most of the code
5268 below is repeated several times, can we extract the common parts
5269 and place them into a subroutine or something similar? */
5270 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5272 input_line_pointer
+= 6;
5273 sd_chain
= is_defined_space ("$TEXT$");
5274 if (sd_chain
== NULL
)
5275 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5276 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5277 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5279 current_space
= sd_chain
;
5281 /* No need to align if we are already there. */
5282 if (now_seg
!= text_section
)
5283 pa_align_subseg (now_seg
, now_subseg
);
5285 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5288 = pa_subsegment_to_subspace (text_section
,
5289 sd_chain
->sd_last_subseg
);
5290 demand_empty_rest_of_line ();
5293 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5295 input_line_pointer
+= 9;
5296 sd_chain
= is_defined_space ("$PRIVATE$");
5297 if (sd_chain
== NULL
)
5298 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5299 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5300 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5302 current_space
= sd_chain
;
5304 /* No need to align if we are already there. */
5305 if (now_seg
!= data_section
)
5306 pa_align_subseg (now_seg
, now_subseg
);
5308 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5310 = pa_subsegment_to_subspace (data_section
,
5311 sd_chain
->sd_last_subseg
);
5312 demand_empty_rest_of_line ();
5315 if (!strncasecmp (input_line_pointer
,
5316 GDB_DEBUG_SPACE_NAME
,
5317 strlen (GDB_DEBUG_SPACE_NAME
)))
5319 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5320 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5321 if (sd_chain
== NULL
)
5322 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5323 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5324 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5326 current_space
= sd_chain
;
5329 asection
*gdb_section
5330 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5332 /* No need to align if we are already there. */
5333 if (strcmp (segment_name (now_seg
), GDB_DEBUG_SPACE_NAME
) != 0)
5334 pa_align_subseg (now_seg
, now_subseg
);
5336 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5338 = pa_subsegment_to_subspace (gdb_section
,
5339 sd_chain
->sd_last_subseg
);
5341 demand_empty_rest_of_line ();
5345 /* It could be a space specified by number. */
5347 save_s
= input_line_pointer
;
5348 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5350 if (sd_chain
= pa_find_space_by_number (temp
))
5352 current_space
= sd_chain
;
5354 if (now_seg
!= sd_chain
->sd_seg
)
5355 pa_align_subseg (now_seg
, now_subseg
);
5356 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5358 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5359 sd_chain
->sd_last_subseg
);
5360 demand_empty_rest_of_line ();
5365 /* Not a number, attempt to create a new space. */
5367 input_line_pointer
= save_s
;
5368 name
= input_line_pointer
;
5369 c
= get_symbol_end ();
5370 space_name
= xmalloc (strlen (name
) + 1);
5371 strcpy (space_name
, name
);
5372 *input_line_pointer
= c
;
5374 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5375 current_space
= sd_chain
;
5377 if (now_seg
!= sd_chain
->sd_seg
)
5378 pa_align_subseg (now_seg
, now_subseg
);
5379 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5380 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5381 sd_chain
->sd_last_subseg
);
5382 demand_empty_rest_of_line ();
5387 /* Switch to a new space. (I think). FIXME. */
5396 sd_chain_struct
*space
;
5398 name
= input_line_pointer
;
5399 c
= get_symbol_end ();
5400 space
= is_defined_space (name
);
5404 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5407 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5409 *input_line_pointer
= c
;
5410 demand_empty_rest_of_line ();
5414 /* If VALUE is an exact power of two between zero and 2^31, then
5415 return log2 (VALUE). Else return -1. */
5423 while ((1 << shift
) != value
&& shift
< 32)
5432 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5433 given subspace, creating the new subspace if necessary.
5435 FIXME. Should mirror pa_space more closely, in particular how
5436 they're broken up into subroutines. */
5439 pa_subspace (unused
)
5442 char *name
, *ss_name
, *alias
, c
;
5443 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5444 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5445 sd_chain_struct
*space
;
5446 ssd_chain_struct
*ssd
;
5449 if (within_procedure
)
5451 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5452 ignore_rest_of_line ();
5456 name
= input_line_pointer
;
5457 c
= get_symbol_end ();
5458 ss_name
= xmalloc (strlen (name
) + 1);
5459 strcpy (ss_name
, name
);
5460 *input_line_pointer
= c
;
5462 /* Load default values. */
5475 space
= current_space
;
5476 ssd
= is_defined_subspace (name
, space
->sd_last_subseg
);
5479 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5480 if (!is_end_of_statement ())
5481 as_warn ("Parameters of an existing subspace can\'t be modified");
5482 demand_empty_rest_of_line ();
5487 /* A new subspace. Load default values if it matches one of
5488 the builtin subspaces. */
5490 while (pa_def_subspaces
[i
].name
)
5492 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5494 loadable
= pa_def_subspaces
[i
].loadable
;
5495 common
= pa_def_subspaces
[i
].common
;
5496 dup_common
= pa_def_subspaces
[i
].dup_common
;
5497 code_only
= pa_def_subspaces
[i
].code_only
;
5498 zero
= pa_def_subspaces
[i
].zero
;
5499 space_index
= pa_def_subspaces
[i
].space_index
;
5500 alignment
= pa_def_subspaces
[i
].alignment
;
5501 quadrant
= pa_def_subspaces
[i
].quadrant
;
5502 access
= pa_def_subspaces
[i
].access
;
5503 sort
= pa_def_subspaces
[i
].sort
;
5504 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5505 alias
= pa_def_subspaces
[i
].alias
;
5512 /* We should be working with a new subspace now. Fill in
5513 any information as specified by the user. */
5514 if (!is_end_of_statement ())
5516 input_line_pointer
++;
5517 while (!is_end_of_statement ())
5519 name
= input_line_pointer
;
5520 c
= get_symbol_end ();
5521 if ((strncasecmp (name
, "QUAD", 4) == 0))
5523 *input_line_pointer
= c
;
5524 input_line_pointer
++;
5525 quadrant
= get_absolute_expression ();
5527 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5529 *input_line_pointer
= c
;
5530 input_line_pointer
++;
5531 alignment
= get_absolute_expression ();
5532 if (log2 (alignment
) == -1)
5534 as_bad ("Alignment must be a power of 2");
5538 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5540 *input_line_pointer
= c
;
5541 input_line_pointer
++;
5542 access
= get_absolute_expression ();
5544 else if ((strncasecmp (name
, "SORT", 4) == 0))
5546 *input_line_pointer
= c
;
5547 input_line_pointer
++;
5548 sort
= get_absolute_expression ();
5550 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5552 *input_line_pointer
= c
;
5555 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5557 *input_line_pointer
= c
;
5560 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5562 *input_line_pointer
= c
;
5565 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5567 *input_line_pointer
= c
;
5570 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5572 *input_line_pointer
= c
;
5575 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5576 as_bad ("FIRST not supported as a .SUBSPACE argument");
5578 as_bad ("Invalid .SUBSPACE argument");
5579 if (!is_end_of_statement ())
5580 input_line_pointer
++;
5584 /* Compute a reasonable set of BFD flags based on the information
5585 in the .subspace directive. */
5586 applicable
= bfd_applicable_section_flags (stdoutput
);
5589 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5592 if (common
|| dup_common
)
5593 flags
|= SEC_IS_COMMON
;
5595 /* This is a zero-filled subspace (eg BSS). */
5599 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5600 applicable
&= flags
;
5602 /* If this is an existing subspace, then we want to use the
5603 segment already associated with the subspace.
5605 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5606 lots of sections. It might be a problem in the PA ELF
5607 code, I do not know yet. For now avoid creating anything
5608 but the "standard" sections for ELF. */
5610 section
= ssd
->ssd_seg
;
5612 section
= subseg_new (alias
, 0);
5613 else if (! alias
&& USE_ALIASES
)
5615 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5616 demand_empty_rest_of_line ();
5620 section
= subseg_new (ss_name
, 0);
5622 /* Now set the flags. */
5623 bfd_set_section_flags (stdoutput
, section
, applicable
);
5625 /* Record any alignment request for this section. */
5626 record_alignment (section
, log2 (alignment
));
5628 /* Set the starting offset for this section. */
5629 bfd_set_section_vma (stdoutput
, section
,
5630 pa_subspace_start (space
, quadrant
));
5633 /* Now that all the flags are set, update an existing subspace,
5634 or create a new one. */
5637 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5638 code_only
, common
, dup_common
,
5639 sort
, zero
, access
, space_index
,
5640 alignment
, quadrant
,
5643 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5645 dup_common
, zero
, sort
,
5646 access
, space_index
,
5647 alignment
, quadrant
, section
);
5649 demand_empty_rest_of_line ();
5650 current_subspace
->ssd_seg
= section
;
5651 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5657 /* Create default space and subspace dictionaries. */
5664 space_dict_root
= NULL
;
5665 space_dict_last
= NULL
;
5668 while (pa_def_spaces
[i
].name
)
5672 /* Pick the right name to use for the new section. */
5673 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5674 name
= pa_def_spaces
[i
].alias
;
5676 name
= pa_def_spaces
[i
].name
;
5678 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5679 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5680 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5681 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5682 pa_def_spaces
[i
].segment
, 0);
5687 while (pa_def_subspaces
[i
].name
)
5690 int applicable
, subsegment
;
5691 asection
*segment
= NULL
;
5692 sd_chain_struct
*space
;
5694 /* Pick the right name for the new section and pick the right
5695 subsegment number. */
5696 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5698 name
= pa_def_subspaces
[i
].alias
;
5699 subsegment
= pa_def_subspaces
[i
].subsegment
;
5703 name
= pa_def_subspaces
[i
].name
;
5707 /* Create the new section. */
5708 segment
= subseg_new (name
, subsegment
);
5711 /* For SOM we want to replace the standard .text, .data, and .bss
5712 sections with our own. */
5713 if (! strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && ! USE_ALIASES
)
5715 text_section
= segment
;
5716 applicable
= bfd_applicable_section_flags (stdoutput
);
5717 bfd_set_section_flags (stdoutput
, text_section
,
5718 applicable
& (SEC_ALLOC
| SEC_LOAD
5719 | SEC_RELOC
| SEC_CODE
5721 | SEC_HAS_CONTENTS
));
5723 else if (! strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && ! USE_ALIASES
)
5725 data_section
= segment
;
5726 applicable
= bfd_applicable_section_flags (stdoutput
);
5727 bfd_set_section_flags (stdoutput
, data_section
,
5728 applicable
& (SEC_ALLOC
| SEC_LOAD
5730 | SEC_HAS_CONTENTS
));
5734 else if (! strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && ! USE_ALIASES
)
5736 bss_section
= segment
;
5737 applicable
= bfd_applicable_section_flags (stdoutput
);
5738 bfd_set_section_flags (stdoutput
, bss_section
,
5739 applicable
& SEC_ALLOC
);
5742 /* Find the space associated with this subspace. */
5743 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5744 def_space_index
].segment
);
5747 as_fatal ("Internal error: Unable to find containing space for %s.",
5748 pa_def_subspaces
[i
].name
);
5751 create_new_subspace (space
, name
,
5752 pa_def_subspaces
[i
].loadable
,
5753 pa_def_subspaces
[i
].code_only
,
5754 pa_def_subspaces
[i
].common
,
5755 pa_def_subspaces
[i
].dup_common
,
5756 pa_def_subspaces
[i
].zero
,
5757 pa_def_subspaces
[i
].sort
,
5758 pa_def_subspaces
[i
].access
,
5759 pa_def_subspaces
[i
].space_index
,
5760 pa_def_subspaces
[i
].alignment
,
5761 pa_def_subspaces
[i
].quadrant
,
5769 /* Create a new space NAME, with the appropriate flags as defined
5770 by the given parameters.
5772 Add the new space to the space dictionary chain in numerical
5773 order as defined by the SORT entries. */
5775 static sd_chain_struct
*
5776 create_new_space (name
, spnum
, loadable
, defined
, private,
5777 sort
, seg
, user_defined
)
5787 sd_chain_struct
*chain_entry
;
5789 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5791 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5794 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5795 strcpy (SPACE_NAME (chain_entry
), name
);
5796 SPACE_NAME_INDEX (chain_entry
) = 0;
5797 SPACE_LOADABLE (chain_entry
) = loadable
;
5798 SPACE_DEFINED (chain_entry
) = defined
;
5799 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5800 SPACE_PRIVATE (chain_entry
) = private;
5801 SPACE_SPNUM (chain_entry
) = spnum
;
5802 SPACE_SORT (chain_entry
) = sort
;
5804 chain_entry
->sd_seg
= seg
;
5805 chain_entry
->sd_last_subseg
= -1;
5806 chain_entry
->sd_next
= NULL
;
5808 /* Find spot for the new space based on its sort key. */
5809 if (!space_dict_last
)
5810 space_dict_last
= chain_entry
;
5812 if (space_dict_root
== NULL
)
5813 space_dict_root
= chain_entry
;
5816 sd_chain_struct
*chain_pointer
;
5817 sd_chain_struct
*prev_chain_pointer
;
5819 chain_pointer
= space_dict_root
;
5820 prev_chain_pointer
= NULL
;
5822 while (chain_pointer
)
5824 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5826 prev_chain_pointer
= chain_pointer
;
5827 chain_pointer
= chain_pointer
->sd_next
;
5833 /* At this point we've found the correct place to add the new
5834 entry. So add it and update the linked lists as appropriate. */
5835 if (prev_chain_pointer
)
5837 chain_entry
->sd_next
= chain_pointer
;
5838 prev_chain_pointer
->sd_next
= chain_entry
;
5842 space_dict_root
= chain_entry
;
5843 chain_entry
->sd_next
= chain_pointer
;
5846 if (chain_entry
->sd_next
== NULL
)
5847 space_dict_last
= chain_entry
;
5850 /* This is here to catch predefined spaces which do not get
5851 modified by the user's input. Another call is found at
5852 the bottom of pa_parse_space_stmt to handle cases where
5853 the user modifies a predefined space. */
5854 #ifdef obj_set_section_attributes
5855 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5861 /* Create a new subspace NAME, with the appropriate flags as defined
5862 by the given parameters.
5864 Add the new subspace to the subspace dictionary chain in numerical
5865 order as defined by the SORT entries. */
5867 static ssd_chain_struct
*
5868 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5869 dup_common
, is_zero
, sort
, access
, space_index
,
5870 alignment
, quadrant
, seg
)
5871 sd_chain_struct
*space
;
5873 char loadable
, code_only
, common
, dup_common
, is_zero
;
5881 ssd_chain_struct
*chain_entry
;
5883 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5885 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5887 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5888 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5890 SUBSPACE_ACCESS (chain_entry
) = access
;
5891 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5892 SUBSPACE_COMMON (chain_entry
) = common
;
5893 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5894 SUBSPACE_SORT (chain_entry
) = sort
;
5895 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
5896 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5897 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5898 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
5899 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5900 SUBSPACE_ZERO (chain_entry
) = is_zero
;
5902 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5903 chain_entry
->ssd_seg
= seg
;
5904 chain_entry
->ssd_last_align
= 1;
5905 chain_entry
->ssd_next
= NULL
;
5907 /* Find spot for the new subspace based on its sort key. */
5908 if (space
->sd_subspaces
== NULL
)
5909 space
->sd_subspaces
= chain_entry
;
5912 ssd_chain_struct
*chain_pointer
;
5913 ssd_chain_struct
*prev_chain_pointer
;
5915 chain_pointer
= space
->sd_subspaces
;
5916 prev_chain_pointer
= NULL
;
5918 while (chain_pointer
)
5920 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
5922 prev_chain_pointer
= chain_pointer
;
5923 chain_pointer
= chain_pointer
->ssd_next
;
5930 /* Now we have somewhere to put the new entry. Insert it and update
5932 if (prev_chain_pointer
)
5934 chain_entry
->ssd_next
= chain_pointer
;
5935 prev_chain_pointer
->ssd_next
= chain_entry
;
5939 space
->sd_subspaces
= chain_entry
;
5940 chain_entry
->ssd_next
= chain_pointer
;
5944 #ifdef obj_set_subsection_attributes
5945 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5953 /* Update the information for the given subspace based upon the
5954 various arguments. Return the modified subspace chain entry. */
5956 static ssd_chain_struct
*
5957 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5958 zero
, access
, space_index
, alignment
, quadrant
, subseg
)
5959 sd_chain_struct
*space
;
5973 ssd_chain_struct
*chain_entry
;
5975 if ((chain_entry
= is_defined_subspace (name
, subseg
)))
5977 SUBSPACE_ACCESS (chain_entry
) = access
;
5978 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5979 SUBSPACE_COMMON (chain_entry
) = common
;
5980 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5981 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
5982 SUBSPACE_SORT (chain_entry
) = sort
;
5983 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5984 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5985 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5986 SUBSPACE_ZERO (chain_entry
) = zero
;
5991 #ifdef obj_set_subsection_attributes
5992 obj_set_subsection_attributes (subseg
, space
->sd_seg
, access
,
6000 /* Return the space chain entry for the space with the name NAME or
6001 NULL if no such space exists. */
6003 static sd_chain_struct
*
6004 is_defined_space (name
)
6007 sd_chain_struct
*chain_pointer
;
6009 for (chain_pointer
= space_dict_root
;
6011 chain_pointer
= chain_pointer
->sd_next
)
6013 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6014 return chain_pointer
;
6017 /* No mapping from segment to space was found. Return NULL. */
6021 /* Find and return the space associated with the given seg. If no mapping
6022 from the given seg to a space is found, then return NULL.
6024 Unlike subspaces, the number of spaces is not expected to grow much,
6025 so a linear exhaustive search is OK here. */
6027 static sd_chain_struct
*
6028 pa_segment_to_space (seg
)
6031 sd_chain_struct
*space_chain
;
6033 /* Walk through each space looking for the correct mapping. */
6034 for (space_chain
= space_dict_root
;
6036 space_chain
= space_chain
->sd_next
)
6038 if (space_chain
->sd_seg
== seg
)
6042 /* Mapping was not found. Return NULL. */
6046 /* Return the space chain entry for the subspace with the name NAME or
6047 NULL if no such subspace exists.
6049 Uses a linear search through all the spaces and subspaces, this may
6050 not be appropriate if we ever being placing each function in its
6053 static ssd_chain_struct
*
6054 is_defined_subspace (name
, subseg
)
6058 sd_chain_struct
*space_chain
;
6059 ssd_chain_struct
*subspace_chain
;
6061 /* Walk through each space. */
6062 for (space_chain
= space_dict_root
;
6064 space_chain
= space_chain
->sd_next
)
6066 /* Walk through each subspace looking for a name which matches. */
6067 for (subspace_chain
= space_chain
->sd_subspaces
;
6069 subspace_chain
= subspace_chain
->ssd_next
)
6070 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6071 return subspace_chain
;
6074 /* Subspace wasn't found. Return NULL. */
6078 /* Find and return the subspace associated with the given seg. If no
6079 mapping from the given seg to a subspace is found, then return NULL.
6081 If we ever put each procedure/function within its own subspace
6082 (to make life easier on the compiler and linker), then this will have
6083 to become more efficient. */
6085 static ssd_chain_struct
*
6086 pa_subsegment_to_subspace (seg
, subseg
)
6090 sd_chain_struct
*space_chain
;
6091 ssd_chain_struct
*subspace_chain
;
6093 /* Walk through each space. */
6094 for (space_chain
= space_dict_root
;
6096 space_chain
= space_chain
->sd_next
)
6098 if (space_chain
->sd_seg
== seg
)
6100 /* Walk through each subspace within each space looking for
6101 the correct mapping. */
6102 for (subspace_chain
= space_chain
->sd_subspaces
;
6104 subspace_chain
= subspace_chain
->ssd_next
)
6105 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6106 return subspace_chain
;
6110 /* No mapping from subsegment to subspace found. Return NULL. */
6114 /* Given a number, try and find a space with the name number.
6116 Return a pointer to a space dictionary chain entry for the space
6117 that was found or NULL on failure. */
6119 static sd_chain_struct
*
6120 pa_find_space_by_number (number
)
6123 sd_chain_struct
*space_chain
;
6125 for (space_chain
= space_dict_root
;
6127 space_chain
= space_chain
->sd_next
)
6129 if (SPACE_SPNUM (space_chain
) == number
)
6133 /* No appropriate space found. Return NULL. */
6137 /* Return the starting address for the given subspace. If the starting
6138 address is unknown then return zero. */
6141 pa_subspace_start (space
, quadrant
)
6142 sd_chain_struct
*space
;
6145 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6146 is not correct for the PA OSF1 port. */
6147 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6149 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6155 /* FIXME. Needs documentation. */
6157 pa_next_subseg (space
)
6158 sd_chain_struct
*space
;
6161 space
->sd_last_subseg
++;
6162 return space
->sd_last_subseg
;
6165 /* Helper function for pa_stringer. Used to find the end of
6172 unsigned int c
= *s
& CHAR_MASK
;
6184 /* Handle a .STRING type pseudo-op. */
6187 pa_stringer (append_zero
)
6190 char *s
, num_buf
[4];
6194 /* Preprocess the string to handle PA-specific escape sequences.
6195 For example, \xDD where DD is a hexidecimal number should be
6196 changed to \OOO where OOO is an octal number. */
6198 /* Skip the opening quote. */
6199 s
= input_line_pointer
+ 1;
6201 while (is_a_char (c
= pa_stringer_aux (s
++)))
6208 /* Handle \x<num>. */
6211 unsigned int number
;
6216 /* Get pas the 'x'. */
6218 for (num_digit
= 0, number
= 0, dg
= *s
;
6220 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6221 || (dg
>= 'A' && dg
<= 'F'));
6225 number
= number
* 16 + dg
- '0';
6226 else if (dg
>= 'a' && dg
<= 'f')
6227 number
= number
* 16 + dg
- 'a' + 10;
6229 number
= number
* 16 + dg
- 'A' + 10;
6239 sprintf (num_buf
, "%02o", number
);
6242 sprintf (num_buf
, "%03o", number
);
6245 for (i
= 0; i
<= num_digit
; i
++)
6246 s_start
[i
] = num_buf
[i
];
6250 /* This might be a "\"", skip over the escaped char. */
6257 stringer (append_zero
);
6258 pa_undefine_label ();
6261 /* Handle a .VERSION pseudo-op. */
6268 pa_undefine_label ();
6271 /* Just like a normal cons, but when finished we have to undefine
6272 the latest space label. */
6279 pa_undefine_label ();
6282 /* Switch to the data space. As usual delete our label. */
6289 pa_undefine_label ();
6292 /* FIXME. What's the purpose of this pseudo-op? */
6298 pa_undefine_label ();
6301 /* Like float_cons, but we need to undefine our label. */
6304 pa_float_cons (float_type
)
6307 float_cons (float_type
);
6308 pa_undefine_label ();
6311 /* Like s_fill, but delete our label when finished. */
6318 pa_undefine_label ();
6321 /* Like lcomm, but delete our label when finished. */
6324 pa_lcomm (needs_align
)
6327 s_lcomm (needs_align
);
6328 pa_undefine_label ();
6331 /* Like lsym, but delete our label when finished. */
6338 pa_undefine_label ();
6341 /* Switch to the text space. Like s_text, but delete our
6342 label when finished. */
6348 pa_undefine_label ();
6351 /* On the PA relocations which involve function symbols must not be
6352 adjusted. This so that the linker can know when/how to create argument
6353 relocation stubs for indirect calls and calls to static functions.
6355 FIXME. Also reject R_HPPA relocations which are 32 bits
6356 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6357 needs to generate relocations to push the addend and symbol value
6358 onto the stack, add them, then pop the value off the stack and
6359 use it in a relocation -- yuk. */
6362 hppa_fix_adjustable (fixp
)
6365 struct hppa_fix_struct
*hppa_fix
;
6367 hppa_fix
= fixp
->tc_fix_data
;
6369 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6372 if (fixp
->fx_addsy
== 0
6373 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6379 /* Now for some ELF specific code. FIXME. */
6381 static symext_chainS
*symext_rootP
;
6382 static symext_chainS
*symext_lastP
;
6384 /* Do any symbol processing requested by the target-cpu or target-format. */
6387 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6389 elf_symbol_type
*symbolP
;
6392 symext_chainS
*symextP
;
6393 unsigned int arg_reloc
;
6395 /* Only functions can have argument relocations. */
6396 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6399 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6401 /* If there are no argument relocation bits, then no relocation is
6402 necessary. Do not add this to the symextn section. */
6406 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6408 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6409 symextP
[0].next
= &symextP
[1];
6411 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6412 symextP
[1].next
= NULL
;
6414 if (symext_rootP
== NULL
)
6416 symext_rootP
= &symextP
[0];
6417 symext_lastP
= &symextP
[1];
6421 symext_lastP
->next
= &symextP
[0];
6422 symext_lastP
= &symextP
[1];
6426 /* Make sections needed by the target cpu and/or target format. */
6428 hppa_tc_make_sections (abfd
)
6431 symext_chainS
*symextP
;
6433 asection
*symextn_sec
;
6434 segT save_seg
= now_seg
;
6435 subsegT save_subseg
= now_subseg
;
6437 /* Build the symbol extension section. */
6438 hppa_tc_make_symextn_section ();
6440 /* Force some calculation to occur. */
6441 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6443 hppa_elf_stub_finish (abfd
);
6445 /* If no symbols for the symbol extension section, then stop now. */
6446 if (symext_rootP
== NULL
)
6449 /* Count the number of symbols for the symbol extension section. */
6450 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6453 size
= sizeof (symext_entryS
) * n
;
6455 /* Switch to the symbol extension section. */
6456 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6458 frag_wane (frag_now
);
6461 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6464 int *symtab_map
= elf_sym_extra (abfd
);
6467 /* First, patch the symbol extension record to reflect the true
6468 symbol table index. */
6470 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6472 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6473 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6477 ptr
= frag_more (sizeof (symextP
->entry
));
6478 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6481 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6482 frag_wane (frag_now
);
6484 /* Switch back to the original segment. */
6485 subseg_set (save_seg
, save_subseg
);
6490 /* Make the symbol extension section. */
6493 hppa_tc_make_symextn_section ()
6497 symext_chainS
*symextP
;
6501 segT save_seg
= now_seg
;
6502 subsegT save_subseg
= now_subseg
;
6504 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6507 size
= sizeof (symext_entryS
) * n
;
6509 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6511 bfd_set_section_flags (stdoutput
, symextn_sec
,
6512 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6513 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6515 /* Now, switch back to the original segment. */
6516 subseg_set (save_seg
, save_subseg
);
6520 /* Build the symbol extension section. */
6523 pa_build_symextn_section ()
6526 asection
*save_seg
= now_seg
;
6527 subsegT subseg
= (subsegT
) 0;
6528 subsegT save_subseg
= now_subseg
;
6530 seg
= subseg_new (".hppa_symextn", subseg
);
6531 bfd_set_section_flags (stdoutput
,
6533 SEC_HAS_CONTENTS
| SEC_READONLY
6534 | SEC_ALLOC
| SEC_LOAD
);
6536 subseg_set (save_seg
, save_subseg
);
6540 /* For ELF, this function serves one purpose: to setup the st_size
6541 field of STT_FUNC symbols. To do this, we need to scan the
6542 call_info structure list, determining st_size in one of two possible
6545 1. call_info->start_frag->fr_fix has the size of the fragment.
6546 This approach assumes that the function was built into a
6547 single fragment. This works for most cases, but might fail.
6548 For example, if there was a segment change in the middle of
6551 2. The st_size field is the difference in the addresses of the
6552 call_info->start_frag->fr_address field and the fr_address
6553 field of the next fragment with fr_type == rs_fill and
6557 elf_hppa_final_processing ()
6559 struct call_info
*call_info_pointer
;
6561 for (call_info_pointer
= call_info_root
;
6563 call_info_pointer
= call_info_pointer
->ci_next
)
6565 elf_symbol_type
*esym
6566 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6567 esym
->internal_elf_sym
.st_size
=
6568 S_GET_VALUE (call_info_pointer
->end_symbol
)
6569 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;