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 ".PARISC.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
55 /* ELF objects can have versions, but apparently do not have anywhere
56 to store a copyright string. */
57 #define obj_version obj_elf_version
58 #define obj_copyright obj_elf_version
60 /* Use space aliases. */
65 /* Names of various debugging spaces/subspaces. */
66 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
67 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
68 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
69 #define UNWIND_SECTION_NAME "$UNWIND$"
71 /* Object file formats specify relocation types. */
72 typedef int reloc_type
;
74 /* SOM objects can have both a version string and a copyright string. */
75 #define obj_version obj_som_version
76 #define obj_copyright obj_som_copyright
78 /* Do not use space aliases. */
81 /* How to generate a relocation. */
82 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
84 /* Object file formats specify BFD symbol types. */
85 typedef som_symbol_type obj_symbol_type
;
87 /* This apparently isn't in older versions of hpux reloc.h. */
89 #define R_DLT_REL 0x78
93 /* Various structures and types used internally in tc-hppa.c. */
95 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
99 unsigned int cannot_unwind
:1;
100 unsigned int millicode
:1;
101 unsigned int millicode_save_rest
:1;
102 unsigned int region_desc
:2;
103 unsigned int save_sr
:2;
104 unsigned int entry_fr
:4;
105 unsigned int entry_gr
:5;
106 unsigned int args_stored
:1;
107 unsigned int call_fr
:5;
108 unsigned int call_gr
:5;
109 unsigned int save_sp
:1;
110 unsigned int save_rp
:1;
111 unsigned int save_rp_in_frame
:1;
112 unsigned int extn_ptr_defined
:1;
113 unsigned int cleanup_defined
:1;
115 unsigned int hpe_interrupt_marker
:1;
116 unsigned int hpux_interrupt_marker
:1;
117 unsigned int reserved
:3;
118 unsigned int frame_size
:27;
123 /* Starting and ending offsets of the region described by
125 unsigned int start_offset
;
126 unsigned int end_offset
;
127 struct unwind_desc descriptor
;
130 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
131 control the entry and exit code they generate. It is also used in
132 creation of the correct stack unwind descriptors.
134 NOTE: GAS does not support .enter and .leave for the generation of
135 prologues and epilogues. FIXME.
137 The fields in structure roughly correspond to the arguments available on the
138 .callinfo pseudo-op. */
142 /* The unwind descriptor being built. */
143 struct unwind_table ci_unwind
;
145 /* Name of this function. */
146 symbolS
*start_symbol
;
148 /* (temporary) symbol used to mark the end of this function. */
151 /* Next entry in the chain. */
152 struct call_info
*ci_next
;
155 /* Operand formats for FP instructions. Note not all FP instructions
156 allow all four formats to be used (for example fmpysub only allows
160 SGL
, DBL
, ILLEGAL_FMT
, QUAD
164 /* This fully describes the symbol types which may be attached to
165 an EXPORT or IMPORT directive. Only SOM uses this formation
166 (ELF has no need for it). */
170 SYMBOL_TYPE_ABSOLUTE
,
174 SYMBOL_TYPE_MILLICODE
,
176 SYMBOL_TYPE_PRI_PROG
,
177 SYMBOL_TYPE_SEC_PROG
,
181 /* This structure contains information needed to assemble
182 individual instructions. */
185 /* Holds the opcode after parsing by pa_ip. */
186 unsigned long opcode
;
188 /* Holds an expression associated with the current instruction. */
191 /* Does this instruction use PC-relative addressing. */
194 /* Floating point formats for operand1 and operand2. */
195 fp_operand_format fpof1
;
196 fp_operand_format fpof2
;
198 /* Holds the field selector for this instruction
199 (for example L%, LR%, etc). */
202 /* Holds any argument relocation bits associated with this
203 instruction. (instruction should be some sort of call). */
206 /* The format specification for this instruction. */
209 /* The relocation (if any) associated with this instruction. */
213 /* PA-89 floating point registers are arranged like this:
216 +--------------+--------------+
217 | 0 or 16L | 16 or 16R |
218 +--------------+--------------+
219 | 1 or 17L | 17 or 17R |
220 +--------------+--------------+
228 +--------------+--------------+
229 | 14 or 30L | 30 or 30R |
230 +--------------+--------------+
231 | 15 or 31L | 31 or 31R |
232 +--------------+--------------+
235 The following is a version of pa_parse_number that
236 handles the L/R notation and returns the correct
237 value to put into the instruction register field.
238 The correct value to put into the instruction is
239 encoded in the structure 'pa_89_fp_reg_struct'. */
241 struct pa_89_fp_reg_struct
243 /* The register number. */
250 /* Additional information needed to build argument relocation stubs. */
253 /* The argument relocation specification. */
254 unsigned int arg_reloc
;
256 /* Number of arguments. */
257 unsigned int arg_count
;
260 /* This structure defines an entry in the subspace dictionary
263 struct subspace_dictionary_chain
265 /* Nonzero if this space has been defined by the user code. */
266 unsigned int ssd_defined
;
268 /* Name of this subspace. */
271 /* GAS segment and subsegment associated with this subspace. */
275 /* Next space in the subspace dictionary chain. */
276 struct subspace_dictionary_chain
*ssd_next
;
279 typedef struct subspace_dictionary_chain ssd_chain_struct
;
281 /* This structure defines an entry in the subspace dictionary
284 struct space_dictionary_chain
286 /* Nonzero if this space has been defined by the user code or
287 as a default space. */
288 unsigned int sd_defined
;
290 /* Nonzero if this spaces has been defined by the user code. */
291 unsigned int sd_user_defined
;
293 /* The space number (or index). */
294 unsigned int sd_spnum
;
296 /* The name of this subspace. */
299 /* GAS segment to which this subspace corresponds. */
302 /* Current subsegment number being used. */
305 /* The chain of subspaces contained within this space. */
306 ssd_chain_struct
*sd_subspaces
;
308 /* The next entry in the space dictionary chain. */
309 struct space_dictionary_chain
*sd_next
;
312 typedef struct space_dictionary_chain sd_chain_struct
;
314 /* Structure for previous label tracking. Needed so that alignments,
315 callinfo declarations, etc can be easily attached to a particular
317 typedef struct label_symbol_struct
319 struct symbol
*lss_label
;
320 sd_chain_struct
*lss_space
;
321 struct label_symbol_struct
*lss_next
;
325 /* This structure defines attributes of the default subspace
326 dictionary entries. */
328 struct default_subspace_dict
330 /* Name of the subspace. */
333 /* FIXME. Is this still needed? */
336 /* Nonzero if this subspace is loadable. */
339 /* Nonzero if this subspace contains only code. */
342 /* Nonzero if this is a common subspace. */
345 /* Nonzero if this is a common subspace which allows symbols
346 to be multiply defined. */
349 /* Nonzero if this subspace should be zero filled. */
352 /* Sort key for this subspace. */
355 /* Access control bits for this subspace. Can represent RWX access
356 as well as privilege level changes for gateways. */
359 /* Index of containing space. */
362 /* Alignment (in bytes) of this subspace. */
365 /* Quadrant within space where this subspace should be loaded. */
368 /* An index into the default spaces array. */
371 /* An alias for this section (or NULL if no alias exists). */
374 /* Subsegment associated with this subspace. */
378 /* This structure defines attributes of the default space
379 dictionary entries. */
381 struct default_space_dict
383 /* Name of the space. */
386 /* Space number. It is possible to identify spaces within
387 assembly code numerically! */
390 /* Nonzero if this space is loadable. */
393 /* Nonzero if this space is "defined". FIXME is still needed */
396 /* Nonzero if this space can not be shared. */
399 /* Sort key for this space. */
402 /* Segment associated with this space. */
405 /* An alias for this section (or NULL if no alias exists). */
409 /* Extra information needed to perform fixups (relocations) on the PA. */
410 struct hppa_fix_struct
412 /* The field selector. */
413 enum hppa_reloc_field_selector_type fx_r_field
;
418 /* Format of fixup. */
421 /* Argument relocation bits. */
424 /* The unwind descriptor associated with this fixup. */
427 /* The segment this fixup appears in. */
431 /* Structure to hold information about predefined registers. */
439 /* This structure defines the mapping from a FP condition string
440 to a condition number which can be recorded in an instruction. */
447 /* This structure defines a mapping from a field selector
448 string to a field selector type. */
449 struct selector_entry
455 /* Prototypes for functions local to tc-hppa.c. */
457 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
458 static void pa_cons
PARAMS ((int));
459 static void pa_data
PARAMS ((int));
460 static void pa_float_cons
PARAMS ((int));
461 static void pa_fill
PARAMS ((int));
462 static void pa_lcomm
PARAMS ((int));
463 static void pa_lsym
PARAMS ((int));
464 static void pa_stringer
PARAMS ((int));
465 static void pa_text
PARAMS ((int));
466 static void pa_version
PARAMS ((int));
467 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
468 static int get_expression
PARAMS ((char *));
469 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
470 static int evaluate_absolute
PARAMS ((struct pa_it
*));
471 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
472 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
473 static int pa_parse_nullif
PARAMS ((char **));
474 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
475 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
476 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
477 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
478 static void pa_block
PARAMS ((int));
479 static void pa_call
PARAMS ((int));
480 static void pa_call_args
PARAMS ((struct call_desc
*));
481 static void pa_callinfo
PARAMS ((int));
482 static void pa_code
PARAMS ((int));
483 static void pa_comm
PARAMS ((int));
484 static void pa_copyright
PARAMS ((int));
485 static void pa_end
PARAMS ((int));
486 static void pa_enter
PARAMS ((int));
487 static void pa_entry
PARAMS ((int));
488 static void pa_equ
PARAMS ((int));
489 static void pa_exit
PARAMS ((int));
490 static void pa_export
PARAMS ((int));
491 static void pa_type_args
PARAMS ((symbolS
*, int));
492 static void pa_import
PARAMS ((int));
493 static void pa_label
PARAMS ((int));
494 static void pa_leave
PARAMS ((int));
495 static void pa_origin
PARAMS ((int));
496 static void pa_proc
PARAMS ((int));
497 static void pa_procend
PARAMS ((int));
498 static void pa_space
PARAMS ((int));
499 static void pa_spnum
PARAMS ((int));
500 static void pa_subspace
PARAMS ((int));
501 static void pa_param
PARAMS ((int));
502 static void pa_undefine_label
PARAMS ((void));
503 static int need_89_opcode
PARAMS ((struct pa_it
*,
504 struct pa_89_fp_reg_struct
*));
505 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
506 static label_symbol_struct
*pa_get_label
PARAMS ((void));
507 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
510 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
515 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
516 char *, int, int, int,
520 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
521 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
522 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
523 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
525 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
526 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
527 static void pa_ip
PARAMS ((char *));
528 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
529 long, expressionS
*, int,
530 bfd_reloc_code_real_type
,
531 enum hppa_reloc_field_selector_type
,
533 static int is_end_of_statement
PARAMS ((void));
534 static int reg_name_search
PARAMS ((char *));
535 static int pa_chk_field_selector
PARAMS ((char **));
536 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
537 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
538 static void process_exit
PARAMS ((void));
539 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
540 static int log2
PARAMS ((int));
541 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
542 static unsigned int pa_stringer_aux
PARAMS ((char *));
543 static void pa_spaces_begin
PARAMS ((void));
544 static void hppa_elf_mark_end_of_function
PARAMS ((void));
546 /* File and gloally scoped variable declarations. */
548 /* Root and final entry in the space chain. */
549 static sd_chain_struct
*space_dict_root
;
550 static sd_chain_struct
*space_dict_last
;
552 /* The current space and subspace. */
553 static sd_chain_struct
*current_space
;
554 static ssd_chain_struct
*current_subspace
;
556 /* Root of the call_info chain. */
557 static struct call_info
*call_info_root
;
559 /* The last call_info (for functions) structure
560 seen so it can be associated with fixups and
562 static struct call_info
*last_call_info
;
564 /* The last call description (for actual calls). */
565 static struct call_desc last_call_desc
;
567 /* Relaxation isn't supported for the PA yet. */
568 const relax_typeS md_relax_table
[] =
571 /* Jumps are always the same size -- one instruction. */
572 int md_short_jump_size
= 4;
573 int md_long_jump_size
= 4;
575 /* handle of the OPCODE hash table */
576 static struct hash_control
*op_hash
= NULL
;
578 /* This array holds the chars that always start a comment. If the
579 pre-processor is disabled, these aren't very useful. */
580 const char comment_chars
[] = ";";
582 /* Table of pseudo ops for the PA. FIXME -- how many of these
583 are now redundant with the overall GAS and the object file
585 const pseudo_typeS md_pseudo_table
[] =
587 /* align pseudo-ops on the PA specify the actual alignment requested,
588 not the log2 of the requested alignment. */
589 {"align", s_align_bytes
, 8},
590 {"ALIGN", s_align_bytes
, 8},
591 {"block", pa_block
, 1},
592 {"BLOCK", pa_block
, 1},
593 {"blockz", pa_block
, 0},
594 {"BLOCKZ", pa_block
, 0},
595 {"byte", pa_cons
, 1},
596 {"BYTE", pa_cons
, 1},
597 {"call", pa_call
, 0},
598 {"CALL", pa_call
, 0},
599 {"callinfo", pa_callinfo
, 0},
600 {"CALLINFO", pa_callinfo
, 0},
601 {"code", pa_code
, 0},
602 {"CODE", pa_code
, 0},
603 {"comm", pa_comm
, 0},
604 {"COMM", pa_comm
, 0},
605 {"copyright", pa_copyright
, 0},
606 {"COPYRIGHT", pa_copyright
, 0},
607 {"data", pa_data
, 0},
608 {"DATA", pa_data
, 0},
609 {"double", pa_float_cons
, 'd'},
610 {"DOUBLE", pa_float_cons
, 'd'},
613 {"enter", pa_enter
, 0},
614 {"ENTER", pa_enter
, 0},
615 {"entry", pa_entry
, 0},
616 {"ENTRY", pa_entry
, 0},
619 {"exit", pa_exit
, 0},
620 {"EXIT", pa_exit
, 0},
621 {"export", pa_export
, 0},
622 {"EXPORT", pa_export
, 0},
623 {"fill", pa_fill
, 0},
624 {"FILL", pa_fill
, 0},
625 {"float", pa_float_cons
, 'f'},
626 {"FLOAT", pa_float_cons
, 'f'},
627 {"half", pa_cons
, 2},
628 {"HALF", pa_cons
, 2},
629 {"import", pa_import
, 0},
630 {"IMPORT", pa_import
, 0},
633 {"label", pa_label
, 0},
634 {"LABEL", pa_label
, 0},
635 {"lcomm", pa_lcomm
, 0},
636 {"LCOMM", pa_lcomm
, 0},
637 {"leave", pa_leave
, 0},
638 {"LEAVE", pa_leave
, 0},
639 {"long", pa_cons
, 4},
640 {"LONG", pa_cons
, 4},
641 {"lsym", pa_lsym
, 0},
642 {"LSYM", pa_lsym
, 0},
643 {"octa", pa_cons
, 16},
644 {"OCTA", pa_cons
, 16},
645 {"org", pa_origin
, 0},
646 {"ORG", pa_origin
, 0},
647 {"origin", pa_origin
, 0},
648 {"ORIGIN", pa_origin
, 0},
649 {"param", pa_param
, 0},
650 {"PARAM", pa_param
, 0},
651 {"proc", pa_proc
, 0},
652 {"PROC", pa_proc
, 0},
653 {"procend", pa_procend
, 0},
654 {"PROCEND", pa_procend
, 0},
655 {"quad", pa_cons
, 8},
656 {"QUAD", pa_cons
, 8},
659 {"short", pa_cons
, 2},
660 {"SHORT", pa_cons
, 2},
661 {"single", pa_float_cons
, 'f'},
662 {"SINGLE", pa_float_cons
, 'f'},
663 {"space", pa_space
, 0},
664 {"SPACE", pa_space
, 0},
665 {"spnum", pa_spnum
, 0},
666 {"SPNUM", pa_spnum
, 0},
667 {"string", pa_stringer
, 0},
668 {"STRING", pa_stringer
, 0},
669 {"stringz", pa_stringer
, 1},
670 {"STRINGZ", pa_stringer
, 1},
671 {"subspa", pa_subspace
, 0},
672 {"SUBSPA", pa_subspace
, 0},
673 {"text", pa_text
, 0},
674 {"TEXT", pa_text
, 0},
675 {"version", pa_version
, 0},
676 {"VERSION", pa_version
, 0},
677 {"word", pa_cons
, 4},
678 {"WORD", pa_cons
, 4},
682 /* This array holds the chars that only start a comment at the beginning of
683 a line. If the line seems to have the form '# 123 filename'
684 .line and .file directives will appear in the pre-processed output.
686 Note that input_file.c hand checks for '#' at the beginning of the
687 first line of the input file. This is because the compiler outputs
688 #NO_APP at the beginning of its output.
690 Also note that '/*' will always start a comment. */
691 const char line_comment_chars
[] = "#";
693 /* This array holds the characters which act as line separators. */
694 const char line_separator_chars
[] = "!";
696 /* Chars that can be used to separate mant from exp in floating point nums. */
697 const char EXP_CHARS
[] = "eE";
699 /* Chars that mean this number is a floating point constant.
700 As in 0f12.456 or 0d1.2345e12.
702 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
703 changed in read.c. Ideally it shouldn't hae to know abou it at
704 all, but nothing is ideal around here. */
705 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
707 static struct pa_it the_insn
;
709 /* Points to the end of an expression just parsed by get_expressoin
710 and friends. FIXME. This shouldn't be handled with a file-global
712 static char *expr_end
;
714 /* Nonzero if a .callinfo appeared within the current procedure. */
715 static int callinfo_found
;
717 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
718 static int within_entry_exit
;
720 /* Nonzero if the assembler is currently within a procedure definition. */
721 static int within_procedure
;
723 /* Handle on strucutre which keep track of the last symbol
724 seen in each subspace. */
725 static label_symbol_struct
*label_symbols_rootp
= NULL
;
727 /* Holds the last field selector. */
728 static int hppa_field_selector
;
730 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
731 static symbolS
*dummy_symbol
;
733 /* Nonzero if errors are to be printed. */
734 static int print_errors
= 1;
736 /* List of registers that are pre-defined:
738 Each general register has one predefined name of the form
739 %r<REGNUM> which has the value <REGNUM>.
741 Space and control registers are handled in a similar manner,
742 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
744 Likewise for the floating point registers, but of the form
745 %fr<REGNUM>. Floating point registers have additional predefined
746 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
747 again have the value <REGNUM>.
749 Many registers also have synonyms:
751 %r26 - %r23 have %arg0 - %arg3 as synonyms
752 %r28 - %r29 have %ret0 - %ret1 as synonyms
753 %r30 has %sp as a synonym
754 %r27 has %dp as a synonym
755 %r2 has %rp as a synonym
757 Almost every control register has a synonym; they are not listed
760 The table is sorted. Suitable for searching by a binary search. */
762 static const struct pd_reg pre_defined_registers
[] =
962 /* This table is sorted by order of the length of the string. This is
963 so we check for <> before we check for <. If we had a <> and checked
964 for < first, we would get a false match. */
965 static const struct fp_cond_map fp_cond_map
[] =
1001 static const struct selector_entry selector_table
[] =
1020 /* default space and subspace dictionaries */
1022 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1023 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1025 /* pre-defined subsegments (subspaces) for the HPPA. */
1026 #define SUBSEG_CODE 0
1027 #define SUBSEG_DATA 0
1028 #define SUBSEG_LIT 1
1029 #define SUBSEG_BSS 2
1030 #define SUBSEG_UNWIND 3
1031 #define SUBSEG_GDB_STRINGS 0
1032 #define SUBSEG_GDB_SYMBOLS 1
1034 static struct default_subspace_dict pa_def_subspaces
[] =
1036 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1037 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1038 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1039 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1041 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
1043 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1046 static struct default_space_dict pa_def_spaces
[] =
1048 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1049 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1050 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1053 /* Misc local definitions used by the assembler. */
1055 /* Return nonzero if the string pointed to by S potentially represents
1056 a right or left half of a FP register */
1057 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1058 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1060 /* These macros are used to maintain spaces/subspaces. */
1061 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1062 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1063 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1064 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1066 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1067 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1069 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1070 main loop after insertion. */
1072 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1074 ((OPCODE) |= (FIELD) << (START)); \
1078 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1079 IGNORE is used to suppress the error message. */
1081 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1083 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1086 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1092 #define is_DP_relative(exp) \
1093 ((exp).X_op == O_subtract \
1094 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1096 #define is_PC_relative(exp) \
1097 ((exp).X_op == O_subtract \
1098 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1100 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1101 always be able to reduce the expression to a constant, so we don't
1102 need real complex handling yet. */
1103 #define is_complex(exp) \
1104 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1106 /* Actual functions to implement the PA specific code for the assembler. */
1108 /* Returns a pointer to the label_symbol_struct for the current space.
1109 or NULL if no label_symbol_struct exists for the current space. */
1111 static label_symbol_struct
*
1114 label_symbol_struct
*label_chain
;
1115 sd_chain_struct
*space_chain
= current_space
;
1117 for (label_chain
= label_symbols_rootp
;
1119 label_chain
= label_chain
->lss_next
)
1120 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1126 /* Defines a label for the current space. If one is already defined,
1127 this function will replace it with the new label. */
1130 pa_define_label (symbol
)
1133 label_symbol_struct
*label_chain
= pa_get_label ();
1134 sd_chain_struct
*space_chain
= current_space
;
1137 label_chain
->lss_label
= symbol
;
1140 /* Create a new label entry and add it to the head of the chain. */
1142 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1143 label_chain
->lss_label
= symbol
;
1144 label_chain
->lss_space
= space_chain
;
1145 label_chain
->lss_next
= NULL
;
1147 if (label_symbols_rootp
)
1148 label_chain
->lss_next
= label_symbols_rootp
;
1150 label_symbols_rootp
= label_chain
;
1154 /* Removes a label definition for the current space.
1155 If there is no label_symbol_struct entry, then no action is taken. */
1158 pa_undefine_label ()
1160 label_symbol_struct
*label_chain
;
1161 label_symbol_struct
*prev_label_chain
= NULL
;
1162 sd_chain_struct
*space_chain
= current_space
;
1164 for (label_chain
= label_symbols_rootp
;
1166 label_chain
= label_chain
->lss_next
)
1168 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1170 /* Remove the label from the chain and free its memory. */
1171 if (prev_label_chain
)
1172 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1174 label_symbols_rootp
= label_chain
->lss_next
;
1179 prev_label_chain
= label_chain
;
1184 /* An HPPA-specific version of fix_new. This is required because the HPPA
1185 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1186 results in the creation of an instance of an hppa_fix_struct. An
1187 hppa_fix_struct stores the extra information along with a pointer to the
1188 original fixS. This is attached to the original fixup via the
1189 tc_fix_data field. */
1192 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1193 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1197 symbolS
*add_symbol
;
1201 bfd_reloc_code_real_type r_type
;
1202 enum hppa_reloc_field_selector_type r_field
;
1209 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1210 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1213 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1215 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1216 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1217 hppa_fix
->fx_r_type
= r_type
;
1218 hppa_fix
->fx_r_field
= r_field
;
1219 hppa_fix
->fx_r_format
= r_format
;
1220 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1221 hppa_fix
->segment
= now_seg
;
1224 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1226 /* If necessary call BFD backend function to attach the
1227 unwind bits to the target dependent parts of a BFD symbol.
1229 #ifdef obj_attach_unwind_info
1230 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1234 /* foo-$global$ is used to access non-automatic storage. $global$
1235 is really just a marker and has served its purpose, so eliminate
1236 it now so as not to confuse write.c. */
1237 if (new_fix
->fx_subsy
1238 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1239 new_fix
->fx_subsy
= NULL
;
1242 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1243 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1246 parse_cons_expression_hppa (exp
)
1249 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1253 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1254 hppa_field_selector is set by the parse_cons_expression_hppa. */
1257 cons_fix_new_hppa (frag
, where
, size
, exp
)
1263 unsigned int rel_type
;
1265 /* Get a base relocation type. */
1266 if (is_DP_relative (*exp
))
1267 rel_type
= R_HPPA_GOTOFF
;
1268 else if (is_complex (*exp
))
1269 rel_type
= R_HPPA_COMPLEX
;
1273 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1274 as_warn ("Invalid field selector. Assuming F%%.");
1276 fix_new_hppa (frag
, where
, size
,
1277 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1278 hppa_field_selector
, 32, 0, (char *) 0);
1280 /* Reset field selector to its default state. */
1281 hppa_field_selector
= 0;
1284 /* This function is called once, at assembler startup time. It should
1285 set up all the tables, etc. that the MD part of the assembler will need. */
1290 const char *retval
= NULL
;
1294 last_call_info
= NULL
;
1295 call_info_root
= NULL
;
1297 /* Folding of text and data segments fails miserably on the PA.
1298 Warn user and disable "-R" option. */
1299 if (flag_readonly_data_in_text
)
1301 as_warn ("-R option not supported on this target.");
1302 flag_readonly_data_in_text
= 0;
1307 op_hash
= hash_new ();
1309 while (i
< NUMOPCODES
)
1311 const char *name
= pa_opcodes
[i
].name
;
1312 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1313 if (retval
!= NULL
&& *retval
!= '\0')
1315 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1320 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1321 != pa_opcodes
[i
].match
)
1323 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1324 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1329 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1333 as_fatal ("Broken assembler. No assembly attempted.");
1335 /* SOM will change text_section. To make sure we never put
1336 anything into the old one switch to the new one now. */
1337 subseg_set (text_section
, 0);
1339 dummy_symbol
= symbol_find_or_make ("L$dummy");
1340 S_SET_SEGMENT (dummy_symbol
, text_section
);
1343 /* Assemble a single instruction storing it into a frag. */
1350 /* The had better be something to assemble. */
1353 /* If we are within a procedure definition, make sure we've
1354 defined a label for the procedure; handle case where the
1355 label was defined after the .PROC directive.
1357 Note there's not need to diddle with the segment or fragment
1358 for the label symbol in this case. We have already switched
1359 into the new $CODE$ subspace at this point. */
1360 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1362 label_symbol_struct
*label_symbol
= pa_get_label ();
1366 if (label_symbol
->lss_label
)
1368 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1369 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1371 /* Also handle allocation of a fixup to hold the unwind
1372 information when the label appears after the proc/procend. */
1373 if (within_entry_exit
)
1375 char *where
= frag_more (0);
1377 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1378 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
1379 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1380 (char *) &last_call_info
->ci_unwind
.descriptor
);
1385 as_bad ("Missing function name for .PROC (corrupted label chain)");
1388 as_bad ("Missing function name for .PROC");
1391 /* Assemble the instruction. Results are saved into "the_insn". */
1394 /* Get somewhere to put the assembled instrution. */
1397 /* Output the opcode. */
1398 md_number_to_chars (to
, the_insn
.opcode
, 4);
1400 /* If necessary output more stuff. */
1401 if (the_insn
.reloc
!= R_HPPA_NONE
)
1402 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1403 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1404 the_insn
.reloc
, the_insn
.field_selector
,
1405 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1408 /* Do the real work for assembling a single instruction. Store results
1409 into the global "the_insn" variable. */
1415 char *error_message
= "";
1416 char *s
, c
, *argstart
, *name
, *save_s
;
1420 int cmpltr
, nullif
, flag
, cond
, num
;
1421 unsigned long opcode
;
1422 struct pa_opcode
*insn
;
1424 /* Skip to something interesting. */
1425 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1444 as_bad ("Unknown opcode: `%s'", str
);
1450 /* Convert everything into lower case. */
1453 if (isupper (*save_s
))
1454 *save_s
= tolower (*save_s
);
1458 /* Look up the opcode in the has table. */
1459 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1461 as_bad ("Unknown opcode: `%s'", str
);
1470 /* Mark the location where arguments for the instruction start, then
1471 start processing them. */
1475 /* Do some initialization. */
1476 opcode
= insn
->match
;
1477 bzero (&the_insn
, sizeof (the_insn
));
1479 the_insn
.reloc
= R_HPPA_NONE
;
1481 /* Build the opcode, checking as we go to make
1482 sure that the operands match. */
1483 for (args
= insn
->args
;; ++args
)
1488 /* End of arguments. */
1504 /* These must match exactly. */
1513 /* Handle a 5 bit register or control register field at 10. */
1516 num
= pa_parse_number (&s
, 0);
1517 CHECK_FIELD (num
, 31, 0, 0);
1518 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1520 /* Handle a 5 bit register field at 15. */
1522 num
= pa_parse_number (&s
, 0);
1523 CHECK_FIELD (num
, 31, 0, 0);
1524 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1526 /* Handle a 5 bit register field at 31. */
1529 num
= pa_parse_number (&s
, 0);
1530 CHECK_FIELD (num
, 31, 0, 0);
1531 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1533 /* Handle a 5 bit field length at 31. */
1535 num
= pa_get_absolute_expression (&the_insn
, &s
);
1537 CHECK_FIELD (num
, 32, 1, 0);
1538 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1540 /* Handle a 5 bit immediate at 15. */
1542 num
= pa_get_absolute_expression (&the_insn
, &s
);
1544 CHECK_FIELD (num
, 15, -16, 0);
1545 low_sign_unext (num
, 5, &num
);
1546 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1548 /* Handle a 5 bit immediate at 31. */
1550 num
= pa_get_absolute_expression (&the_insn
, &s
);
1552 CHECK_FIELD (num
, 15, -16, 0)
1553 low_sign_unext (num
, 5, &num
);
1554 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1556 /* Handle an unsigned 5 bit immediate at 31. */
1558 num
= pa_get_absolute_expression (&the_insn
, &s
);
1560 CHECK_FIELD (num
, 31, 0, 0);
1561 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1563 /* Handle an unsigned 5 bit immediate at 15. */
1565 num
= pa_get_absolute_expression (&the_insn
, &s
);
1567 CHECK_FIELD (num
, 31, 0, 0);
1568 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1570 /* Handle a 2 bit space identifier at 17. */
1572 num
= pa_parse_number (&s
, 0);
1573 CHECK_FIELD (num
, 3, 0, 1);
1574 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1576 /* Handle a 3 bit space identifier at 18. */
1578 num
= pa_parse_number (&s
, 0);
1579 CHECK_FIELD (num
, 7, 0, 1);
1580 dis_assemble_3 (num
, &num
);
1581 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1583 /* Handle a completer for an indexing load or store. */
1589 while (*s
== ',' && i
< 2)
1592 if (strncasecmp (s
, "sm", 2) == 0)
1599 else if (strncasecmp (s
, "m", 1) == 0)
1601 else if (strncasecmp (s
, "s", 1) == 0)
1604 as_bad ("Invalid Indexed Load Completer.");
1609 as_bad ("Invalid Indexed Load Completer Syntax.");
1611 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1614 /* Handle a short load/store completer. */
1622 if (strncasecmp (s
, "ma", 2) == 0)
1627 else if (strncasecmp (s
, "mb", 2) == 0)
1633 as_bad ("Invalid Short Load/Store Completer.");
1637 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1640 /* Handle a stbys completer. */
1646 while (*s
== ',' && i
< 2)
1649 if (strncasecmp (s
, "m", 1) == 0)
1651 else if (strncasecmp (s
, "b", 1) == 0)
1653 else if (strncasecmp (s
, "e", 1) == 0)
1656 as_bad ("Invalid Store Bytes Short Completer");
1661 as_bad ("Invalid Store Bytes Short Completer");
1663 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1666 /* Handle a non-negated compare/stubtract condition. */
1668 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1671 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1674 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1676 /* Handle a negated or non-negated compare/subtract condition. */
1679 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1683 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1686 as_bad ("Invalid Compare/Subtract Condition.");
1691 /* Negated condition requires an opcode change. */
1695 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1697 /* Handle non-negated add condition. */
1699 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1702 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1705 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1707 /* Handle a negated or non-negated add condition. */
1710 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1714 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1717 as_bad ("Invalid Compare/Subtract Condition");
1722 /* Negated condition requires an opcode change. */
1726 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1728 /* Handle a compare/subtract condition. */
1735 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1740 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1743 as_bad ("Invalid Compare/Subtract Condition");
1747 opcode
|= cmpltr
<< 13;
1748 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1750 /* Handle a non-negated add condition. */
1759 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1763 if (strcmp (name
, "=") == 0)
1765 else if (strcmp (name
, "<") == 0)
1767 else if (strcmp (name
, "<=") == 0)
1769 else if (strcasecmp (name
, "nuv") == 0)
1771 else if (strcasecmp (name
, "znv") == 0)
1773 else if (strcasecmp (name
, "sv") == 0)
1775 else if (strcasecmp (name
, "od") == 0)
1777 else if (strcasecmp (name
, "n") == 0)
1779 else if (strcasecmp (name
, "tr") == 0)
1784 else if (strcmp (name
, "<>") == 0)
1789 else if (strcmp (name
, ">=") == 0)
1794 else if (strcmp (name
, ">") == 0)
1799 else if (strcasecmp (name
, "uv") == 0)
1804 else if (strcasecmp (name
, "vnz") == 0)
1809 else if (strcasecmp (name
, "nsv") == 0)
1814 else if (strcasecmp (name
, "ev") == 0)
1820 as_bad ("Invalid Add Condition: %s", name
);
1823 nullif
= pa_parse_nullif (&s
);
1824 opcode
|= nullif
<< 1;
1825 opcode
|= cmpltr
<< 13;
1826 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1828 /* HANDLE a logical instruction condition. */
1836 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1840 if (strcmp (name
, "=") == 0)
1842 else if (strcmp (name
, "<") == 0)
1844 else if (strcmp (name
, "<=") == 0)
1846 else if (strcasecmp (name
, "od") == 0)
1848 else if (strcasecmp (name
, "tr") == 0)
1853 else if (strcmp (name
, "<>") == 0)
1858 else if (strcmp (name
, ">=") == 0)
1863 else if (strcmp (name
, ">") == 0)
1868 else if (strcasecmp (name
, "ev") == 0)
1874 as_bad ("Invalid Logical Instruction Condition.");
1877 opcode
|= cmpltr
<< 13;
1878 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1880 /* Handle a unit instruction condition. */
1887 if (strncasecmp (s
, "sbz", 3) == 0)
1892 else if (strncasecmp (s
, "shz", 3) == 0)
1897 else if (strncasecmp (s
, "sdc", 3) == 0)
1902 else if (strncasecmp (s
, "sbc", 3) == 0)
1907 else if (strncasecmp (s
, "shc", 3) == 0)
1912 else if (strncasecmp (s
, "tr", 2) == 0)
1918 else if (strncasecmp (s
, "nbz", 3) == 0)
1924 else if (strncasecmp (s
, "nhz", 3) == 0)
1930 else if (strncasecmp (s
, "ndc", 3) == 0)
1936 else if (strncasecmp (s
, "nbc", 3) == 0)
1942 else if (strncasecmp (s
, "nhc", 3) == 0)
1949 as_bad ("Invalid Logical Instruction Condition.");
1951 opcode
|= cmpltr
<< 13;
1952 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1954 /* Handle a shift/extract/deposit condition. */
1962 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1966 if (strcmp (name
, "=") == 0)
1968 else if (strcmp (name
, "<") == 0)
1970 else if (strcasecmp (name
, "od") == 0)
1972 else if (strcasecmp (name
, "tr") == 0)
1974 else if (strcmp (name
, "<>") == 0)
1976 else if (strcmp (name
, ">=") == 0)
1978 else if (strcasecmp (name
, "ev") == 0)
1980 /* Handle movb,n. Put things back the way they were.
1981 This includes moving s back to where it started. */
1982 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1989 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1992 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1994 /* Handle bvb and bb conditions. */
2000 if (strncmp (s
, "<", 1) == 0)
2005 else if (strncmp (s
, ">=", 2) == 0)
2011 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2013 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2015 /* Handle a system control completer. */
2017 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2025 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2027 /* Handle a nullification completer for branch instructions. */
2029 nullif
= pa_parse_nullif (&s
);
2030 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2032 /* Handle a nullification completer for copr and spop insns. */
2034 nullif
= pa_parse_nullif (&s
);
2035 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2037 /* Handle a 11 bit immediate at 31. */
2039 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2042 if (the_insn
.exp
.X_op
== O_constant
)
2044 num
= evaluate_absolute (&the_insn
);
2045 CHECK_FIELD (num
, 1023, -1024, 0);
2046 low_sign_unext (num
, 11, &num
);
2047 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2051 if (is_DP_relative (the_insn
.exp
))
2052 the_insn
.reloc
= R_HPPA_GOTOFF
;
2053 else if (is_PC_relative (the_insn
.exp
))
2054 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2056 the_insn
.reloc
= R_HPPA
;
2057 the_insn
.format
= 11;
2061 /* Handle a 14 bit immediate at 31. */
2063 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2066 if (the_insn
.exp
.X_op
== O_constant
)
2068 num
= evaluate_absolute (&the_insn
);
2069 CHECK_FIELD (num
, 8191, -8192, 0);
2070 low_sign_unext (num
, 14, &num
);
2071 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2075 if (is_DP_relative (the_insn
.exp
))
2076 the_insn
.reloc
= R_HPPA_GOTOFF
;
2077 else if (is_PC_relative (the_insn
.exp
))
2078 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2080 the_insn
.reloc
= R_HPPA
;
2081 the_insn
.format
= 14;
2085 /* Handle a 21 bit immediate at 31. */
2087 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2090 if (the_insn
.exp
.X_op
== O_constant
)
2092 num
= evaluate_absolute (&the_insn
);
2093 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2094 dis_assemble_21 (num
, &num
);
2095 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2099 if (is_DP_relative (the_insn
.exp
))
2100 the_insn
.reloc
= R_HPPA_GOTOFF
;
2101 else if (is_PC_relative (the_insn
.exp
))
2102 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2104 the_insn
.reloc
= R_HPPA
;
2105 the_insn
.format
= 21;
2109 /* Handle a 12 bit branch displacement. */
2111 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2115 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2117 unsigned int w1
, w
, result
;
2119 num
= evaluate_absolute (&the_insn
);
2122 as_bad ("Branch to unaligned address");
2125 CHECK_FIELD (num
, 8191, -8192, 0);
2126 sign_unext ((num
- 8) >> 2, 12, &result
);
2127 dis_assemble_12 (result
, &w1
, &w
);
2128 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2132 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2133 the_insn
.format
= 12;
2134 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2135 bzero (&last_call_desc
, sizeof (struct call_desc
));
2140 /* Handle a 17 bit branch displacement. */
2142 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2146 if (!the_insn
.exp
.X_add_symbol
2147 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2150 unsigned int w2
, w1
, w
, result
;
2152 num
= evaluate_absolute (&the_insn
);
2155 as_bad ("Branch to unaligned address");
2158 CHECK_FIELD (num
, 262143, -262144, 0);
2160 if (the_insn
.exp
.X_add_symbol
)
2163 sign_unext (num
>> 2, 17, &result
);
2164 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2165 INSERT_FIELD_AND_CONTINUE (opcode
,
2166 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2170 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2171 the_insn
.format
= 17;
2172 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2173 bzero (&last_call_desc
, sizeof (struct call_desc
));
2177 /* Handle an absolute 17 bit branch target. */
2179 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2183 if (!the_insn
.exp
.X_add_symbol
2184 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2187 unsigned int w2
, w1
, w
, result
;
2189 num
= evaluate_absolute (&the_insn
);
2192 as_bad ("Branch to unaligned address");
2195 CHECK_FIELD (num
, 262143, -262144, 0);
2197 if (the_insn
.exp
.X_add_symbol
)
2200 sign_unext (num
>> 2, 17, &result
);
2201 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2202 INSERT_FIELD_AND_CONTINUE (opcode
,
2203 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2207 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2208 the_insn
.format
= 17;
2212 /* Handle a 5 bit shift count at 26. */
2214 num
= pa_get_absolute_expression (&the_insn
, &s
);
2216 CHECK_FIELD (num
, 31, 0, 0);
2217 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2219 /* Handle a 5 bit bit position at 26. */
2221 num
= pa_get_absolute_expression (&the_insn
, &s
);
2223 CHECK_FIELD (num
, 31, 0, 0);
2224 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2226 /* Handle a 5 bit immediate at 10. */
2228 num
= pa_get_absolute_expression (&the_insn
, &s
);
2230 CHECK_FIELD (num
, 31, 0, 0);
2231 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2233 /* Handle a 13 bit immediate at 18. */
2235 num
= pa_get_absolute_expression (&the_insn
, &s
);
2237 CHECK_FIELD (num
, 8191, 0, 0);
2238 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2240 /* Handle a 26 bit immediate at 31. */
2242 num
= pa_get_absolute_expression (&the_insn
, &s
);
2244 CHECK_FIELD (num
, 671108864, 0, 0);
2245 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2247 /* Handle a 3 bit SFU identifier at 25. */
2250 as_bad ("Invalid SFU identifier");
2251 num
= pa_get_absolute_expression (&the_insn
, &s
);
2253 CHECK_FIELD (num
, 7, 0, 0);
2254 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2256 /* Handle a 20 bit SOP field for spop0. */
2258 num
= pa_get_absolute_expression (&the_insn
, &s
);
2260 CHECK_FIELD (num
, 1048575, 0, 0);
2261 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2262 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2264 /* Handle a 15bit SOP field for spop1. */
2266 num
= pa_get_absolute_expression (&the_insn
, &s
);
2268 CHECK_FIELD (num
, 32767, 0, 0);
2269 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2271 /* Handle a 10bit SOP field for spop3. */
2273 num
= pa_get_absolute_expression (&the_insn
, &s
);
2275 CHECK_FIELD (num
, 1023, 0, 0);
2276 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2277 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2279 /* Handle a 15 bit SOP field for spop2. */
2281 num
= pa_get_absolute_expression (&the_insn
, &s
);
2283 CHECK_FIELD (num
, 32767, 0, 0);
2284 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2285 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2287 /* Handle a 3-bit co-processor ID field. */
2290 as_bad ("Invalid COPR identifier");
2291 num
= pa_get_absolute_expression (&the_insn
, &s
);
2293 CHECK_FIELD (num
, 7, 0, 0);
2294 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2296 /* Handle a 22bit SOP field for copr. */
2298 num
= pa_get_absolute_expression (&the_insn
, &s
);
2300 CHECK_FIELD (num
, 4194303, 0, 0);
2301 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2302 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2304 /* Handle a source FP operand format completer. */
2306 flag
= pa_parse_fp_format (&s
);
2307 the_insn
.fpof1
= flag
;
2308 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2310 /* Handle a destination FP operand format completer. */
2312 /* pa_parse_format needs the ',' prefix. */
2314 flag
= pa_parse_fp_format (&s
);
2315 the_insn
.fpof2
= flag
;
2316 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2318 /* Handle FP compare conditions. */
2320 cond
= pa_parse_fp_cmp_cond (&s
);
2321 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2323 /* Handle L/R register halves like 't'. */
2326 struct pa_89_fp_reg_struct result
;
2328 pa_parse_number (&s
, &result
);
2329 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2330 opcode
|= result
.number_part
;
2332 /* 0x30 opcodes are FP arithmetic operation opcodes
2333 and need to be turned into 0x38 opcodes. This
2334 is not necessary for loads/stores. */
2335 if (need_89_opcode (&the_insn
, &result
)
2336 && ((opcode
& 0xfc000000) == 0x30000000))
2339 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2342 /* Handle L/R register halves like 'b'. */
2345 struct pa_89_fp_reg_struct result
;
2347 pa_parse_number (&s
, &result
);
2348 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2349 opcode
|= result
.number_part
<< 21;
2350 if (need_89_opcode (&the_insn
, &result
))
2352 opcode
|= (result
.l_r_select
& 1) << 7;
2358 /* Handle L/R register halves like 'x'. */
2361 struct pa_89_fp_reg_struct result
;
2363 pa_parse_number (&s
, &result
);
2364 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2365 opcode
|= (result
.number_part
& 0x1f) << 16;
2366 if (need_89_opcode (&the_insn
, &result
))
2368 opcode
|= (result
.l_r_select
& 1) << 12;
2374 /* Handle a 5 bit register field at 10. */
2377 struct pa_89_fp_reg_struct result
;
2379 pa_parse_number (&s
, &result
);
2380 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2381 if (the_insn
.fpof1
== SGL
)
2383 result
.number_part
&= 0xF;
2384 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2386 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2389 /* Handle a 5 bit register field at 15. */
2392 struct pa_89_fp_reg_struct result
;
2394 pa_parse_number (&s
, &result
);
2395 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2396 if (the_insn
.fpof1
== SGL
)
2398 result
.number_part
&= 0xF;
2399 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2401 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2404 /* Handle a 5 bit register field at 31. */
2407 struct pa_89_fp_reg_struct result
;
2409 pa_parse_number (&s
, &result
);
2410 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2411 if (the_insn
.fpof1
== SGL
)
2413 result
.number_part
&= 0xF;
2414 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2416 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2419 /* Handle a 5 bit register field at 20. */
2422 struct pa_89_fp_reg_struct result
;
2424 pa_parse_number (&s
, &result
);
2425 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2426 if (the_insn
.fpof1
== SGL
)
2428 result
.number_part
&= 0xF;
2429 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2431 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2434 /* Handle a 5 bit register field at 25. */
2437 struct pa_89_fp_reg_struct result
;
2439 pa_parse_number (&s
, &result
);
2440 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2441 if (the_insn
.fpof1
== SGL
)
2443 result
.number_part
&= 0xF;
2444 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2446 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2449 /* Handle a floating point operand format at 26.
2450 Only allows single and double precision. */
2452 flag
= pa_parse_fp_format (&s
);
2458 the_insn
.fpof1
= flag
;
2464 as_bad ("Invalid Floating Point Operand Format.");
2474 /* Check if the args matched. */
2477 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2478 && !strcmp (insn
->name
, insn
[1].name
))
2486 as_bad ("Invalid operands %s", error_message
);
2493 the_insn
.opcode
= opcode
;
2496 /* Turn a string in input_line_pointer into a floating point constant of type
2497 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2498 emitted is stored in *sizeP . An error message or NULL is returned. */
2500 #define MAX_LITTLENUMS 6
2503 md_atof (type
, litP
, sizeP
)
2509 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2510 LITTLENUM_TYPE
*wordP
;
2542 return "Bad call to MD_ATOF()";
2544 t
= atof_ieee (input_line_pointer
, type
, words
);
2546 input_line_pointer
= t
;
2547 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2548 for (wordP
= words
; prec
--;)
2550 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2551 litP
+= sizeof (LITTLENUM_TYPE
);
2556 /* Write out big-endian. */
2559 md_number_to_chars (buf
, val
, n
)
2564 number_to_chars_bigendian (buf
, val
, n
);
2567 /* Translate internal representation of relocation info to BFD target
2571 tc_gen_reloc (section
, fixp
)
2576 struct hppa_fix_struct
*hppa_fixp
;
2577 bfd_reloc_code_real_type code
;
2578 static arelent
*no_relocs
= NULL
;
2580 bfd_reloc_code_real_type
**codes
;
2584 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2585 if (fixp
->fx_addsy
== 0)
2587 assert (hppa_fixp
!= 0);
2588 assert (section
!= 0);
2590 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2591 assert (reloc
!= 0);
2593 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2594 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2596 hppa_fixp
->fx_r_format
,
2597 hppa_fixp
->fx_r_field
);
2599 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2602 relocs
= (arelent
**)
2603 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2604 assert (relocs
!= 0);
2606 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2607 sizeof (arelent
) * n_relocs
);
2609 assert (reloc
!= 0);
2611 for (i
= 0; i
< n_relocs
; i
++)
2612 relocs
[i
] = &reloc
[i
];
2614 relocs
[n_relocs
] = NULL
;
2617 switch (fixp
->fx_r_type
)
2620 assert (n_relocs
== 1);
2624 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2625 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2626 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2627 reloc
->addend
= 0; /* default */
2629 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2631 /* Now, do any processing that is dependent on the relocation type. */
2634 case R_PARISC_DLTREL21L
:
2635 case R_PARISC_DLTREL14R
:
2636 case R_PARISC_DLTREL14F
:
2637 case R_PARISC_PLABEL32
:
2638 case R_PARISC_PLABEL21L
:
2639 case R_PARISC_PLABEL14R
:
2640 /* For plabel relocations, the addend of the
2641 relocation should be either 0 (no static link) or 2
2642 (static link required).
2644 FIXME: We always assume no static link!
2646 We also slam a zero addend into the DLT relative relocs;
2647 it doesn't make a lot of sense to use any addend since
2648 it gets you a different (eg unknown) DLT entry. */
2652 case R_PARISC_PCREL21L
:
2653 case R_PARISC_PCREL17R
:
2654 case R_PARISC_PCREL17F
:
2655 case R_PARISC_PCREL17C
:
2656 case R_PARISC_PCREL14R
:
2657 case R_PARISC_PCREL14F
:
2658 /* The constant is stored in the instruction. */
2659 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2662 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2665 reloc
->addend
= fixp
->fx_addnumber
;
2672 /* Walk over reach relocation returned by the BFD backend. */
2673 for (i
= 0; i
< n_relocs
; i
++)
2677 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2678 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2679 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2685 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2691 /* For plabel relocations, the addend of the
2692 relocation should be either 0 (no static link) or 2
2693 (static link required).
2695 FIXME: We always assume no static link!
2697 We also slam a zero addend into the DLT relative relocs;
2698 it doesn't make a lot of sense to use any addend since
2699 it gets you a different (eg unknown) DLT entry. */
2700 relocs
[i
]->addend
= 0;
2711 /* There is no symbol or addend associated with these fixups. */
2712 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2713 relocs
[i
]->addend
= 0;
2717 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2718 relocs
[i
]->addend
= 0;
2720 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2729 /* Process any machine dependent frag types. */
2732 md_convert_frag (abfd
, sec
, fragP
)
2734 register asection
*sec
;
2735 register fragS
*fragP
;
2737 unsigned int address
;
2739 if (fragP
->fr_type
== rs_machine_dependent
)
2741 switch ((int) fragP
->fr_subtype
)
2744 fragP
->fr_type
= rs_fill
;
2745 know (fragP
->fr_var
== 1);
2746 know (fragP
->fr_next
);
2747 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2748 if (address
% fragP
->fr_offset
)
2751 fragP
->fr_next
->fr_address
2756 fragP
->fr_offset
= 0;
2762 /* Round up a section size to the appropriate boundary. */
2765 md_section_align (segment
, size
)
2769 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2770 int align2
= (1 << align
) - 1;
2772 return (size
+ align2
) & ~align2
;
2775 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2777 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2779 addressT from_addr
, to_addr
;
2783 fprintf (stderr
, "pa_create_short_jmp\n");
2787 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2789 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2791 addressT from_addr
, to_addr
;
2795 fprintf (stderr
, "pa_create_long_jump\n");
2799 /* Return the approximate size of a frag before relaxation has occurred. */
2801 md_estimate_size_before_relax (fragP
, segment
)
2802 register fragS
*fragP
;
2809 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2815 CONST
char *md_shortopts
= "";
2816 struct option md_longopts
[] = {
2817 {NULL
, no_argument
, NULL
, 0}
2819 size_t md_longopts_size
= sizeof(md_longopts
);
2822 md_parse_option (c
, arg
)
2830 md_show_usage (stream
)
2835 /* We have no need to default values of symbols. */
2838 md_undefined_symbol (name
)
2844 /* Parse an operand that is machine-specific.
2845 We just return without modifying the expression as we have nothing
2849 md_operand (expressionP
)
2850 expressionS
*expressionP
;
2854 /* Apply a fixup to an instruction. */
2857 md_apply_fix (fixP
, valp
)
2861 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2862 struct hppa_fix_struct
*hppa_fixP
;
2863 long new_val
, result
;
2864 unsigned int w1
, w2
, w
;
2867 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2868 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2869 never be "applied" (they are just markers). */
2871 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2872 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2876 /* There should have been an HPPA specific fixup associated
2877 with the GAS fixup. */
2880 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2881 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2883 if (fixP
->fx_r_type
== R_HPPA_NONE
)
2886 /* Remember this value for emit_reloc. FIXME, is this braindamage
2887 documented anywhere!?! */
2888 fixP
->fx_addnumber
= val
;
2890 /* Check if this is an undefined symbol. No relocation can
2891 possibly be performed in this case.
2893 Also avoid doing anything for pc-relative fixups in which the
2894 fixup is in a different space than the symbol it references. */
2895 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
2897 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
)
2900 && S_GET_SEGMENT (fixP
->fx_addsy
) != hppa_fixP
->segment
)
2903 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2906 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
2907 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
2908 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
2909 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
2910 && hppa_fixP
->fx_r_field
!= R_HPPA_TSEL
2911 && hppa_fixP
->fx_r_field
!= R_HPPA_LTSEL
2912 && hppa_fixP
->fx_r_field
!= R_HPPA_RTSEL
2913 && !(fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
))
2914 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
2920 /* Handle all opcodes with the 'j' operand type. */
2922 CHECK_FIELD (new_val
, 8191, -8192, 0);
2924 /* Mask off 14 bits to be changed. */
2925 bfd_put_32 (stdoutput
,
2926 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2928 low_sign_unext (new_val
, 14, &result
);
2931 /* Handle all opcodes with the 'k' operand type. */
2933 CHECK_FIELD (new_val
, 2097152, 0, 0);
2935 /* Mask off 21 bits to be changed. */
2936 bfd_put_32 (stdoutput
,
2937 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2939 dis_assemble_21 (new_val
, &result
);
2942 /* Handle all the opcodes with the 'i' operand type. */
2944 CHECK_FIELD (new_val
, 1023, -1023, 0);
2946 /* Mask off 11 bits to be changed. */
2947 bfd_put_32 (stdoutput
,
2948 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2950 low_sign_unext (new_val
, 11, &result
);
2953 /* Handle all the opcodes with the 'w' operand type. */
2955 CHECK_FIELD (new_val
, 8191, -8192, 0)
2957 /* Mask off 11 bits to be changed. */
2958 sign_unext ((new_val
- 8) >> 2, 12, &result
);
2959 bfd_put_32 (stdoutput
,
2960 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
2963 dis_assemble_12 (result
, &w1
, &w
);
2964 result
= ((w1
<< 2) | w
);
2967 /* Handle some of the opcodes with the 'W' operand type. */
2970 #define stub_needed(CALLER, CALLEE) \
2971 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2972 /* It is necessary to force PC-relative calls/jumps to have a
2973 relocation entry if they're going to need either a argument
2974 relocation or long call stub. FIXME. Can't we need the same
2975 for absolute calls? */
2977 && (stub_needed (((obj_symbol_type
*)
2978 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2979 hppa_fixP
->fx_arg_reloc
)))
2983 CHECK_FIELD (new_val
, 262143, -262144, 0);
2985 /* Mask off 17 bits to be changed. */
2986 bfd_put_32 (stdoutput
,
2987 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
2989 sign_unext ((new_val
- 8) >> 2, 17, &result
);
2990 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2991 result
= ((w2
<< 2) | (w1
<< 16) | w
);
2996 fixP
->fx_addnumber
= fixP
->fx_offset
;
2997 /* If we have a real relocation, then we want zero to
2998 be stored in the object file. If no relocation is going
2999 to be emitted, then we need to store new_val into the
3002 bfd_put_32 (stdoutput
, 0, buf
);
3004 bfd_put_32 (stdoutput
, new_val
, buf
);
3012 as_bad ("Unknown relocation encountered in md_apply_fix.");
3016 /* Insert the relocation. */
3017 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3022 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3023 (unsigned int) fixP
, fixP
->fx_r_type
);
3028 /* Exactly what point is a PC-relative offset relative TO?
3029 On the PA, they're relative to the address of the offset. */
3032 md_pcrel_from (fixP
)
3035 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3038 /* Return nonzero if the input line pointer is at the end of
3042 is_end_of_statement ()
3044 return ((*input_line_pointer
== '\n')
3045 || (*input_line_pointer
== ';')
3046 || (*input_line_pointer
== '!'));
3049 /* Read a number from S. The number might come in one of many forms,
3050 the most common will be a hex or decimal constant, but it could be
3051 a pre-defined register (Yuk!), or an absolute symbol.
3053 Return a number or -1 for failure.
3055 When parsing PA-89 FP register numbers RESULT will be
3056 the address of a structure to return information about
3057 L/R half of FP registers, store results there as appropriate.
3059 pa_parse_number can not handle negative constants and will fail
3060 horribly if it is passed such a constant. */
3063 pa_parse_number (s
, result
)
3065 struct pa_89_fp_reg_struct
*result
;
3074 /* Skip whitespace before the number. */
3075 while (*p
== ' ' || *p
== '\t')
3078 /* Store info in RESULT if requested by caller. */
3081 result
->number_part
= -1;
3082 result
->l_r_select
= -1;
3088 /* Looks like a number. */
3091 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3093 /* The number is specified in hex. */
3095 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3096 || ((*p
>= 'A') && (*p
<= 'F')))
3099 num
= num
* 16 + *p
- '0';
3100 else if (*p
>= 'a' && *p
<= 'f')
3101 num
= num
* 16 + *p
- 'a' + 10;
3103 num
= num
* 16 + *p
- 'A' + 10;
3109 /* The number is specified in decimal. */
3110 while (isdigit (*p
))
3112 num
= num
* 10 + *p
- '0';
3117 /* Store info in RESULT if requested by the caller. */
3120 result
->number_part
= num
;
3122 if (IS_R_SELECT (p
))
3124 result
->l_r_select
= 1;
3127 else if (IS_L_SELECT (p
))
3129 result
->l_r_select
= 0;
3133 result
->l_r_select
= 0;
3138 /* The number might be a predefined register. */
3143 /* Tege hack: Special case for general registers as the general
3144 code makes a binary search with case translation, and is VERY
3149 if (*p
== 'e' && *(p
+ 1) == 't'
3150 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3153 num
= *p
- '0' + 28;
3161 else if (!isdigit (*p
))
3164 as_bad ("Undefined register: '%s'.", name
);
3170 num
= num
* 10 + *p
++ - '0';
3171 while (isdigit (*p
));
3176 /* Do a normal register search. */
3177 while (is_part_of_name (c
))
3183 status
= reg_name_search (name
);
3189 as_bad ("Undefined register: '%s'.", name
);
3195 /* Store info in RESULT if requested by caller. */
3198 result
->number_part
= num
;
3199 if (IS_R_SELECT (p
- 1))
3200 result
->l_r_select
= 1;
3201 else if (IS_L_SELECT (p
- 1))
3202 result
->l_r_select
= 0;
3204 result
->l_r_select
= 0;
3209 /* And finally, it could be a symbol in the absolute section which
3210 is effectively a constant. */
3214 while (is_part_of_name (c
))
3220 if ((sym
= symbol_find (name
)) != NULL
)
3222 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3223 num
= S_GET_VALUE (sym
);
3227 as_bad ("Non-absolute symbol: '%s'.", name
);
3233 /* There is where we'd come for an undefined symbol
3234 or for an empty string. For an empty string we
3235 will return zero. That's a concession made for
3236 compatability with the braindamaged HP assemblers. */
3242 as_bad ("Undefined absolute constant: '%s'.", name
);
3248 /* Store info in RESULT if requested by caller. */
3251 result
->number_part
= num
;
3252 if (IS_R_SELECT (p
- 1))
3253 result
->l_r_select
= 1;
3254 else if (IS_L_SELECT (p
- 1))
3255 result
->l_r_select
= 0;
3257 result
->l_r_select
= 0;
3265 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3267 /* Given NAME, find the register number associated with that name, return
3268 the integer value associated with the given name or -1 on failure. */
3271 reg_name_search (name
)
3274 int middle
, low
, high
;
3278 high
= REG_NAME_CNT
- 1;
3282 middle
= (low
+ high
) / 2;
3283 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3289 return pre_defined_registers
[middle
].value
;
3291 while (low
<= high
);
3297 /* Return nonzero if the given INSN and L/R information will require
3298 a new PA-89 opcode. */
3301 need_89_opcode (insn
, result
)
3303 struct pa_89_fp_reg_struct
*result
;
3305 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3311 /* Parse a condition for a fcmp instruction. Return the numerical
3312 code associated with the condition. */
3315 pa_parse_fp_cmp_cond (s
)
3322 for (i
= 0; i
< 32; i
++)
3324 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3325 strlen (fp_cond_map
[i
].string
)) == 0)
3327 cond
= fp_cond_map
[i
].cond
;
3328 *s
+= strlen (fp_cond_map
[i
].string
);
3329 /* If not a complete match, back up the input string and
3331 if (**s
!= ' ' && **s
!= '\t')
3333 *s
-= strlen (fp_cond_map
[i
].string
);
3336 while (**s
== ' ' || **s
== '\t')
3342 as_bad ("Invalid FP Compare Condition: %s", *s
);
3344 /* Advance over the bogus completer. */
3345 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3351 /* Parse an FP operand format completer returning the completer
3354 static fp_operand_format
3355 pa_parse_fp_format (s
)
3364 if (strncasecmp (*s
, "sgl", 3) == 0)
3369 else if (strncasecmp (*s
, "dbl", 3) == 0)
3374 else if (strncasecmp (*s
, "quad", 4) == 0)
3381 format
= ILLEGAL_FMT
;
3382 as_bad ("Invalid FP Operand Format: %3s", *s
);
3389 /* Convert from a selector string into a selector type. */
3392 pa_chk_field_selector (str
)
3395 int middle
, low
, high
;
3399 /* Read past any whitespace. */
3400 /* FIXME: should we read past newlines and formfeeds??? */
3401 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3404 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3405 name
[0] = tolower ((*str
)[0]),
3407 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3408 name
[0] = tolower ((*str
)[0]),
3409 name
[1] = tolower ((*str
)[1]),
3415 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3419 middle
= (low
+ high
) / 2;
3420 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3427 *str
+= strlen (name
) + 1;
3428 return selector_table
[middle
].field_selector
;
3431 while (low
<= high
);
3436 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3439 get_expression (str
)
3445 save_in
= input_line_pointer
;
3446 input_line_pointer
= str
;
3447 seg
= expression (&the_insn
.exp
);
3448 if (!(seg
== absolute_section
3449 || seg
== undefined_section
3450 || SEG_NORMAL (seg
)))
3452 as_warn ("Bad segment in expression.");
3453 expr_end
= input_line_pointer
;
3454 input_line_pointer
= save_in
;
3457 expr_end
= input_line_pointer
;
3458 input_line_pointer
= save_in
;
3462 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3464 pa_get_absolute_expression (insn
, strp
)
3470 insn
->field_selector
= pa_chk_field_selector (strp
);
3471 save_in
= input_line_pointer
;
3472 input_line_pointer
= *strp
;
3473 expression (&insn
->exp
);
3474 if (insn
->exp
.X_op
!= O_constant
)
3476 as_bad ("Bad segment (should be absolute).");
3477 expr_end
= input_line_pointer
;
3478 input_line_pointer
= save_in
;
3481 expr_end
= input_line_pointer
;
3482 input_line_pointer
= save_in
;
3483 return evaluate_absolute (insn
);
3486 /* Evaluate an absolute expression EXP which may be modified by
3487 the selector FIELD_SELECTOR. Return the value of the expression. */
3489 evaluate_absolute (insn
)
3494 int field_selector
= insn
->field_selector
;
3497 value
= exp
.X_add_number
;
3499 switch (field_selector
)
3505 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3507 if (value
& 0x00000400)
3509 value
= (value
& 0xfffff800) >> 11;
3512 /* Sign extend from bit 21. */
3514 if (value
& 0x00000400)
3515 value
|= 0xfffff800;
3520 /* Arithmetic shift right 11 bits. */
3522 value
= (value
& 0xfffff800) >> 11;
3525 /* Set bits 0-20 to zero. */
3527 value
= value
& 0x7ff;
3530 /* Add 0x800 and arithmetic shift right 11 bits. */
3533 value
= (value
& 0xfffff800) >> 11;
3536 /* Set bitgs 0-21 to one. */
3538 value
|= 0xfffff800;
3541 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3543 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3547 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3552 BAD_CASE (field_selector
);
3558 /* Given an argument location specification return the associated
3559 argument location number. */
3562 pa_build_arg_reloc (type_name
)
3566 if (strncasecmp (type_name
, "no", 2) == 0)
3568 if (strncasecmp (type_name
, "gr", 2) == 0)
3570 else if (strncasecmp (type_name
, "fr", 2) == 0)
3572 else if (strncasecmp (type_name
, "fu", 2) == 0)
3575 as_bad ("Invalid argument location: %s\n", type_name
);
3580 /* Encode and return an argument relocation specification for
3581 the given register in the location specified by arg_reloc. */
3584 pa_align_arg_reloc (reg
, arg_reloc
)
3586 unsigned int arg_reloc
;
3588 unsigned int new_reloc
;
3590 new_reloc
= arg_reloc
;
3606 as_bad ("Invalid argument description: %d", reg
);
3612 /* Parse a PA nullification completer (,n). Return nonzero if the
3613 completer was found; return zero if no completer was found. */
3625 if (strncasecmp (*s
, "n", 1) == 0)
3629 as_bad ("Invalid Nullification: (%c)", **s
);
3638 /* Parse a non-negated compare/subtract completer returning the
3639 number (for encoding in instrutions) of the given completer.
3641 ISBRANCH specifies whether or not this is parsing a condition
3642 completer for a branch (vs a nullification completer for a
3643 computational instruction. */
3646 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3651 char *name
= *s
+ 1;
3659 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3663 if (strcmp (name
, "=") == 0)
3667 else if (strcmp (name
, "<") == 0)
3671 else if (strcmp (name
, "<=") == 0)
3675 else if (strcmp (name
, "<<") == 0)
3679 else if (strcmp (name
, "<<=") == 0)
3683 else if (strcasecmp (name
, "sv") == 0)
3687 else if (strcasecmp (name
, "od") == 0)
3691 /* If we have something like addb,n then there is no condition
3693 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3704 /* Reset pointers if this was really a ,n for a branch instruction. */
3705 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3711 /* Parse a negated compare/subtract completer returning the
3712 number (for encoding in instrutions) of the given completer.
3714 ISBRANCH specifies whether or not this is parsing a condition
3715 completer for a branch (vs a nullification completer for a
3716 computational instruction. */
3719 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3724 char *name
= *s
+ 1;
3732 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3736 if (strcasecmp (name
, "tr") == 0)
3740 else if (strcmp (name
, "<>") == 0)
3744 else if (strcmp (name
, ">=") == 0)
3748 else if (strcmp (name
, ">") == 0)
3752 else if (strcmp (name
, ">>=") == 0)
3756 else if (strcmp (name
, ">>") == 0)
3760 else if (strcasecmp (name
, "nsv") == 0)
3764 else if (strcasecmp (name
, "ev") == 0)
3768 /* If we have something like addb,n then there is no condition
3770 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3781 /* Reset pointers if this was really a ,n for a branch instruction. */
3782 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3788 /* Parse a non-negated addition completer returning the number
3789 (for encoding in instrutions) of the given completer.
3791 ISBRANCH specifies whether or not this is parsing a condition
3792 completer for a branch (vs a nullification completer for a
3793 computational instruction. */
3796 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3801 char *name
= *s
+ 1;
3809 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3813 if (strcmp (name
, "=") == 0)
3817 else if (strcmp (name
, "<") == 0)
3821 else if (strcmp (name
, "<=") == 0)
3825 else if (strcasecmp (name
, "nuv") == 0)
3829 else if (strcasecmp (name
, "znv") == 0)
3833 else if (strcasecmp (name
, "sv") == 0)
3837 else if (strcasecmp (name
, "od") == 0)
3841 /* If we have something like addb,n then there is no condition
3843 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3854 /* Reset pointers if this was really a ,n for a branch instruction. */
3855 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3861 /* Parse a negated addition completer returning the number
3862 (for encoding in instrutions) of the given completer.
3864 ISBRANCH specifies whether or not this is parsing a condition
3865 completer for a branch (vs a nullification completer for a
3866 computational instruction. */
3869 pa_parse_neg_add_cmpltr (s
, isbranch
)
3874 char *name
= *s
+ 1;
3882 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3886 if (strcasecmp (name
, "tr") == 0)
3890 else if (strcmp (name
, "<>") == 0)
3894 else if (strcmp (name
, ">=") == 0)
3898 else if (strcmp (name
, ">") == 0)
3902 else if (strcasecmp (name
, "uv") == 0)
3906 else if (strcasecmp (name
, "vnz") == 0)
3910 else if (strcasecmp (name
, "nsv") == 0)
3914 else if (strcasecmp (name
, "ev") == 0)
3918 /* If we have something like addb,n then there is no condition
3920 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3931 /* Reset pointers if this was really a ,n for a branch instruction. */
3932 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3938 /* Handle a .BLOCK type pseudo-op. */
3946 unsigned int temp_size
;
3949 temp_size
= get_absolute_expression ();
3951 /* Always fill with zeros, that's what the HP assembler does. */
3954 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
3955 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
3956 bzero (p
, temp_size
);
3958 /* Convert 2 bytes at a time. */
3960 for (i
= 0; i
< temp_size
; i
+= 2)
3962 md_number_to_chars (p
+ i
,
3964 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
3967 pa_undefine_label ();
3968 demand_empty_rest_of_line ();
3971 /* Handle a .CALL pseudo-op. This involves storing away information
3972 about where arguments are to be found so the linker can detect
3973 (and correct) argument location mismatches between caller and callee. */
3979 pa_call_args (&last_call_desc
);
3980 demand_empty_rest_of_line ();
3983 /* Do the dirty work of building a call descriptor which describes
3984 where the caller placed arguments to a function call. */
3987 pa_call_args (call_desc
)
3988 struct call_desc
*call_desc
;
3991 unsigned int temp
, arg_reloc
;
3993 while (!is_end_of_statement ())
3995 name
= input_line_pointer
;
3996 c
= get_symbol_end ();
3997 /* Process a source argument. */
3998 if ((strncasecmp (name
, "argw", 4) == 0))
4000 temp
= atoi (name
+ 4);
4001 p
= input_line_pointer
;
4003 input_line_pointer
++;
4004 name
= input_line_pointer
;
4005 c
= get_symbol_end ();
4006 arg_reloc
= pa_build_arg_reloc (name
);
4007 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4009 /* Process a return value. */
4010 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4012 p
= input_line_pointer
;
4014 input_line_pointer
++;
4015 name
= input_line_pointer
;
4016 c
= get_symbol_end ();
4017 arg_reloc
= pa_build_arg_reloc (name
);
4018 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4022 as_bad ("Invalid .CALL argument: %s", name
);
4024 p
= input_line_pointer
;
4026 if (!is_end_of_statement ())
4027 input_line_pointer
++;
4031 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4034 is_same_frag (frag1
, frag2
)
4041 else if (frag2
== NULL
)
4043 else if (frag1
== frag2
)
4045 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4046 return (is_same_frag (frag1
, frag2
->fr_next
));
4052 /* Build an entry in the UNWIND subspace from the given function
4053 attributes in CALL_INFO. This is not needed for SOM as using
4054 R_ENTRY and R_EXIT relocations allow the linker to handle building
4055 of the unwind spaces. */
4058 pa_build_unwind_subspace (call_info
)
4059 struct call_info
*call_info
;
4062 asection
*seg
, *save_seg
;
4063 subsegT subseg
, save_subseg
;
4067 /* Get into the right seg/subseg. This may involve creating
4068 the seg the first time through. Make sure to have the
4069 old seg/subseg so that we can reset things when we are done. */
4070 subseg
= SUBSEG_UNWIND
;
4071 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4072 if (seg
== ASEC_NULL
)
4074 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4075 bfd_set_section_flags (stdoutput
, seg
,
4076 SEC_READONLY
| SEC_HAS_CONTENTS
4077 | SEC_LOAD
| SEC_RELOC
);
4081 save_subseg
= now_subseg
;
4082 subseg_set (seg
, subseg
);
4085 /* Get some space to hold relocation information for the unwind
4089 /* Relocation info. for start offset of the function. */
4090 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4091 call_info
->start_symbol
, (offsetT
) 0,
4092 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0,
4097 /* Relocation info. for end offset of the function. */
4098 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4099 call_info
->end_symbol
, (offsetT
) 0,
4100 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0,
4104 unwind
= (char *) &call_info
->ci_unwind
;
4105 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4109 FRAG_APPEND_1_CHAR (c
);
4113 /* Return back to the original segment/subsegment. */
4114 subseg_set (save_seg
, save_subseg
);
4118 /* Process a .CALLINFO pseudo-op. This information is used later
4119 to build unwind descriptors and maybe one day to support
4120 .ENTER and .LEAVE. */
4123 pa_callinfo (unused
)
4129 /* .CALLINFO must appear within a procedure definition. */
4130 if (!within_procedure
)
4131 as_bad (".callinfo is not within a procedure definition");
4133 /* Mark the fact that we found the .CALLINFO for the
4134 current procedure. */
4135 callinfo_found
= TRUE
;
4137 /* Iterate over the .CALLINFO arguments. */
4138 while (!is_end_of_statement ())
4140 name
= input_line_pointer
;
4141 c
= get_symbol_end ();
4142 /* Frame size specification. */
4143 if ((strncasecmp (name
, "frame", 5) == 0))
4145 p
= input_line_pointer
;
4147 input_line_pointer
++;
4148 temp
= get_absolute_expression ();
4149 if ((temp
& 0x3) != 0)
4151 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4155 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4156 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4159 /* Entry register (GR, GR and SR) specifications. */
4160 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4162 p
= input_line_pointer
;
4164 input_line_pointer
++;
4165 temp
= get_absolute_expression ();
4166 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4167 even though %r19 is caller saved. I think this is a bug in
4168 the HP assembler, and we are not going to emulate it. */
4169 if (temp
< 3 || temp
> 18)
4170 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4171 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4173 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4175 p
= input_line_pointer
;
4177 input_line_pointer
++;
4178 temp
= get_absolute_expression ();
4179 /* Similarly the HP assembler takes 31 as the high bound even
4180 though %fr21 is the last callee saved floating point register. */
4181 if (temp
< 12 || temp
> 21)
4182 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4183 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4185 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4187 p
= input_line_pointer
;
4189 input_line_pointer
++;
4190 temp
= get_absolute_expression ();
4192 as_bad ("Value for ENTRY_SR must be 3\n");
4194 /* Note whether or not this function performs any calls. */
4195 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4196 (strncasecmp (name
, "caller", 6) == 0))
4198 p
= input_line_pointer
;
4201 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4203 p
= input_line_pointer
;
4206 /* Should RP be saved into the stack. */
4207 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4209 p
= input_line_pointer
;
4211 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4213 /* Likewise for SP. */
4214 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4216 p
= input_line_pointer
;
4218 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4220 /* Is this an unwindable procedure. If so mark it so
4221 in the unwind descriptor. */
4222 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4224 p
= input_line_pointer
;
4226 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4228 /* Is this an interrupt routine. If so mark it in the
4229 unwind descriptor. */
4230 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4232 p
= input_line_pointer
;
4234 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4236 /* Is this a millicode routine. "millicode" isn't in my
4237 assembler manual, but my copy is old. The HP assembler
4238 accepts it, and there's a place in the unwind descriptor
4239 to drop the information, so we'll accept it too. */
4240 else if ((strncasecmp (name
, "millicode", 9) == 0))
4242 p
= input_line_pointer
;
4244 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4248 as_bad ("Invalid .CALLINFO argument: %s", name
);
4249 *input_line_pointer
= c
;
4251 if (!is_end_of_statement ())
4252 input_line_pointer
++;
4255 demand_empty_rest_of_line ();
4258 /* Switch into the code subspace. */
4264 sd_chain_struct
*sdchain
;
4266 /* First time through it might be necessary to create the
4268 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4270 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4271 pa_def_spaces
[0].spnum
,
4272 pa_def_spaces
[0].loadable
,
4273 pa_def_spaces
[0].defined
,
4274 pa_def_spaces
[0].private,
4275 pa_def_spaces
[0].sort
,
4276 pa_def_spaces
[0].segment
, 0);
4279 SPACE_DEFINED (sdchain
) = 1;
4280 subseg_set (text_section
, SUBSEG_CODE
);
4281 demand_empty_rest_of_line ();
4284 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4285 the .comm pseudo-op has the following symtax:
4287 <label> .comm <length>
4289 where <label> is optional and is a symbol whose address will be the start of
4290 a block of memory <length> bytes long. <length> must be an absolute
4291 expression. <length> bytes will be allocated in the current space
4300 label_symbol_struct
*label_symbol
= pa_get_label ();
4303 symbol
= label_symbol
->lss_label
;
4308 size
= get_absolute_expression ();
4312 /* It is incorrect to check S_IS_DEFINED at this point as
4313 the symbol will *always* be defined. FIXME. How to
4314 correctly determine when this label really as been
4316 if (S_GET_VALUE (symbol
))
4318 if (S_GET_VALUE (symbol
) != size
)
4320 as_warn ("Length of .comm \"%s\" is already %ld. Not changed.",
4321 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4327 S_SET_VALUE (symbol
, size
);
4328 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4329 S_SET_EXTERNAL (symbol
);
4332 demand_empty_rest_of_line ();
4335 /* Process a .END pseudo-op. */
4341 demand_empty_rest_of_line ();
4344 /* Process a .ENTER pseudo-op. This is not supported. */
4352 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4358 if (!within_procedure
)
4359 as_bad ("Misplaced .entry. Ignored.");
4362 if (!callinfo_found
)
4363 as_bad ("Missing .callinfo.");
4365 demand_empty_rest_of_line ();
4366 within_entry_exit
= TRUE
;
4369 /* SOM defers building of unwind descriptors until the link phase.
4370 The assembler is responsible for creating an R_ENTRY relocation
4371 to mark the beginning of a region and hold the unwind bits, and
4372 for creating an R_EXIT relocation to mark the end of the region.
4374 FIXME. ELF should be using the same conventions! The problem
4375 is an unwind requires too much relocation space. Hmmm. Maybe
4376 if we split the unwind bits up between the relocations which
4377 denote the entry and exit points. */
4378 if (last_call_info
->start_symbol
!= NULL
)
4380 char *where
= frag_more (0);
4382 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4383 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4384 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4385 (char *) &last_call_info
->ci_unwind
.descriptor
);
4390 /* Handle a .EQU pseudo-op. */
4396 label_symbol_struct
*label_symbol
= pa_get_label ();
4401 symbol
= label_symbol
->lss_label
;
4403 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4405 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4406 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4411 as_bad (".REG must use a label");
4413 as_bad (".EQU must use a label");
4416 pa_undefine_label ();
4417 demand_empty_rest_of_line ();
4420 /* Helper function. Does processing for the end of a function. This
4421 usually involves creating some relocations or building special
4422 symbols to mark the end of the function. */
4429 where
= frag_more (0);
4432 /* Mark the end of the function, stuff away the location of the frag
4433 for the end of the function, and finally call pa_build_unwind_subspace
4434 to add an entry in the unwind table. */
4435 hppa_elf_mark_end_of_function ();
4436 pa_build_unwind_subspace (last_call_info
);
4438 /* SOM defers building of unwind descriptors until the link phase.
4439 The assembler is responsible for creating an R_ENTRY relocation
4440 to mark the beginning of a region and hold the unwind bits, and
4441 for creating an R_EXIT relocation to mark the end of the region.
4443 FIXME. ELF should be using the same conventions! The problem
4444 is an unwind requires too much relocation space. Hmmm. Maybe
4445 if we split the unwind bits up between the relocations which
4446 denote the entry and exit points. */
4447 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4448 last_call_info
->start_symbol
, (offsetT
) 0,
4449 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4453 /* Process a .EXIT pseudo-op. */
4459 if (!within_procedure
)
4460 as_bad (".EXIT must appear within a procedure");
4463 if (!callinfo_found
)
4464 as_bad ("Missing .callinfo");
4467 if (!within_entry_exit
)
4468 as_bad ("No .ENTRY for this .EXIT");
4471 within_entry_exit
= FALSE
;
4476 demand_empty_rest_of_line ();
4479 /* Process a .EXPORT directive. This makes functions external
4480 and provides information such as argument relocation entries
4490 name
= input_line_pointer
;
4491 c
= get_symbol_end ();
4492 /* Make sure the given symbol exists. */
4493 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4495 as_bad ("Cannot define export symbol: %s\n", name
);
4496 p
= input_line_pointer
;
4498 input_line_pointer
++;
4502 /* OK. Set the external bits and process argument relocations. */
4503 S_SET_EXTERNAL (symbol
);
4504 p
= input_line_pointer
;
4506 if (!is_end_of_statement ())
4508 input_line_pointer
++;
4509 pa_type_args (symbol
, 1);
4513 demand_empty_rest_of_line ();
4516 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4519 pa_type_args (symbolP
, is_export
)
4524 unsigned int temp
, arg_reloc
;
4525 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4526 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4528 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4531 input_line_pointer
+= 8;
4532 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4533 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4534 type
= SYMBOL_TYPE_ABSOLUTE
;
4536 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4538 input_line_pointer
+= 4;
4539 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4540 instead one should be IMPORTing/EXPORTing ENTRY types.
4542 Complain if one tries to EXPORT a CODE type since that's never
4543 done. Both GCC and HP C still try to IMPORT CODE types, so
4544 silently fix them to be ENTRY types. */
4545 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4548 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4550 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4551 type
= SYMBOL_TYPE_ENTRY
;
4555 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4556 type
= SYMBOL_TYPE_CODE
;
4559 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4561 input_line_pointer
+= 4;
4562 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4563 type
= SYMBOL_TYPE_DATA
;
4565 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4567 input_line_pointer
+= 5;
4568 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4569 type
= SYMBOL_TYPE_ENTRY
;
4571 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4573 input_line_pointer
+= 9;
4574 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4575 type
= SYMBOL_TYPE_MILLICODE
;
4577 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4579 input_line_pointer
+= 6;
4580 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4581 type
= SYMBOL_TYPE_PLABEL
;
4583 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4585 input_line_pointer
+= 8;
4586 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4587 type
= SYMBOL_TYPE_PRI_PROG
;
4589 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4591 input_line_pointer
+= 8;
4592 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4593 type
= SYMBOL_TYPE_SEC_PROG
;
4596 /* SOM requires much more information about symbol types
4597 than BFD understands. This is how we get this information
4598 to the SOM BFD backend. */
4599 #ifdef obj_set_symbol_type
4600 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4603 /* Now that the type of the exported symbol has been handled,
4604 handle any argument relocation information. */
4605 while (!is_end_of_statement ())
4607 if (*input_line_pointer
== ',')
4608 input_line_pointer
++;
4609 name
= input_line_pointer
;
4610 c
= get_symbol_end ();
4611 /* Argument sources. */
4612 if ((strncasecmp (name
, "argw", 4) == 0))
4614 p
= input_line_pointer
;
4616 input_line_pointer
++;
4617 temp
= atoi (name
+ 4);
4618 name
= input_line_pointer
;
4619 c
= get_symbol_end ();
4620 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4621 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4622 *input_line_pointer
= c
;
4624 /* The return value. */
4625 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4627 p
= input_line_pointer
;
4629 input_line_pointer
++;
4630 name
= input_line_pointer
;
4631 c
= get_symbol_end ();
4632 arg_reloc
= pa_build_arg_reloc (name
);
4633 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4634 *input_line_pointer
= c
;
4636 /* Privelege level. */
4637 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4639 p
= input_line_pointer
;
4641 input_line_pointer
++;
4642 temp
= atoi (input_line_pointer
);
4643 c
= get_symbol_end ();
4644 *input_line_pointer
= c
;
4648 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4649 p
= input_line_pointer
;
4652 if (!is_end_of_statement ())
4653 input_line_pointer
++;
4657 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4658 assembly file must either be defined in the assembly file, or
4659 explicitly IMPORTED from another. */
4668 name
= input_line_pointer
;
4669 c
= get_symbol_end ();
4671 symbol
= symbol_find (name
);
4672 /* Ugh. We might be importing a symbol defined earlier in the file,
4673 in which case all the code below will really screw things up
4674 (set the wrong segment, symbol flags & type, etc). */
4675 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4677 symbol
= symbol_find_or_make (name
);
4678 p
= input_line_pointer
;
4681 if (!is_end_of_statement ())
4683 input_line_pointer
++;
4684 pa_type_args (symbol
, 0);
4688 /* Sigh. To be compatable with the HP assembler and to help
4689 poorly written assembly code, we assign a type based on
4690 the the current segment. Note only BSF_FUNCTION really
4691 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4692 if (now_seg
== text_section
)
4693 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4695 /* If the section is undefined, then the symbol is undefined
4696 Since this is an import, leave the section undefined. */
4697 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4702 /* The symbol was already defined. Just eat everything up to
4703 the end of the current statement. */
4704 while (!is_end_of_statement ())
4705 input_line_pointer
++;
4708 demand_empty_rest_of_line ();
4711 /* Handle a .LABEL pseudo-op. */
4719 name
= input_line_pointer
;
4720 c
= get_symbol_end ();
4722 if (strlen (name
) > 0)
4725 p
= input_line_pointer
;
4730 as_warn ("Missing label name on .LABEL");
4733 if (!is_end_of_statement ())
4735 as_warn ("extra .LABEL arguments ignored.");
4736 ignore_rest_of_line ();
4738 demand_empty_rest_of_line ();
4741 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4750 /* Handle a .ORIGIN pseudo-op. */
4757 pa_undefine_label ();
4760 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4761 is for static functions. FIXME. Should share more code with .EXPORT. */
4770 name
= input_line_pointer
;
4771 c
= get_symbol_end ();
4773 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4775 as_bad ("Cannot define static symbol: %s\n", name
);
4776 p
= input_line_pointer
;
4778 input_line_pointer
++;
4782 S_CLEAR_EXTERNAL (symbol
);
4783 p
= input_line_pointer
;
4785 if (!is_end_of_statement ())
4787 input_line_pointer
++;
4788 pa_type_args (symbol
, 0);
4792 demand_empty_rest_of_line ();
4795 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4796 of a procedure from a syntatical point of view. */
4802 struct call_info
*call_info
;
4803 if (within_procedure
)
4804 as_fatal ("Nested procedures");
4806 /* Reset global variables for new procedure. */
4807 callinfo_found
= FALSE
;
4808 within_procedure
= TRUE
;
4811 Enabling
this code creates severe problems with GDB
. It appears as
if
4812 inserting linker stubs between functions within a single
.o makes GDB
4815 /* Create a new CODE subspace for each procedure if we are not
4816 using space/subspace aliases. */
4817 if (!USE_ALIASES
&& call_info_root
!= NULL
)
4821 /* Force creation of a new $CODE$ subspace; inherit attributes from
4822 the first $CODE$ subspace. */
4823 seg
= subseg_force_new ("$CODE$", 0);
4825 /* Now set the flags. */
4826 bfd_set_section_flags (stdoutput
, seg
,
4827 bfd_get_section_flags (abfd
, text_section
));
4829 /* Record any alignment request for this section. */
4830 record_alignment (seg
,
4831 bfd_get_section_alignment (stdoutput
, text_section
));
4833 /* Change the "text_section" to be our new $CODE$ subspace. */
4835 subseg_set (text_section
, 0);
4837 #ifdef obj_set_subsection_attributes
4838 /* Need a way to inherit the the access bits, sort key and quadrant
4839 from the first $CODE$ subspace. FIXME. */
4840 obj_set_subsection_attributes (seg
, current_space
->sd_seg
, 0x2c, 24, 0);
4845 /* Create another call_info structure. */
4846 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4849 as_fatal ("Cannot allocate unwind descriptor\n");
4851 bzero (call_info
, sizeof (struct call_info
));
4853 call_info
->ci_next
= NULL
;
4855 if (call_info_root
== NULL
)
4857 call_info_root
= call_info
;
4858 last_call_info
= call_info
;
4862 last_call_info
->ci_next
= call_info
;
4863 last_call_info
= call_info
;
4866 /* set up defaults on call_info structure */
4868 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4869 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4870 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4872 /* If we got a .PROC pseudo-op, we know that the function is defined
4873 locally. Make sure it gets into the symbol table. */
4875 label_symbol_struct
*label_symbol
= pa_get_label ();
4879 if (label_symbol
->lss_label
)
4881 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4882 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4886 /* The label was defined in a different segment. Fix that
4887 along with the value and associated fragment. */
4888 S_SET_SEGMENT (last_call_info
->start_symbol
, now_seg
);
4889 S_SET_VALUE (last_call_info
->start_symbol
,
4890 ((char*)obstack_next_free (&frags
)
4891 - frag_now
->fr_literal
));
4892 last_call_info
->start_symbol
->sy_frag
= frag_now
;
4897 as_bad ("Missing function name for .PROC (corrupted label chain)");
4900 last_call_info
->start_symbol
= NULL
;
4903 demand_empty_rest_of_line ();
4906 /* Process the syntatical end of a procedure. Make sure all the
4907 appropriate pseudo-ops were found within the procedure. */
4914 /* If we are within a procedure definition, make sure we've
4915 defined a label for the procedure; handle case where the
4916 label was defined after the .PROC directive.
4918 Note there's not need to diddle with the segment or fragment
4919 for the label symbol in this case. We have already switched
4920 into the new $CODE$ subspace at this point. */
4921 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4923 label_symbol_struct
*label_symbol
= pa_get_label ();
4927 if (label_symbol
->lss_label
)
4929 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4930 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4932 /* Also handle allocation of a fixup to hold the unwind
4933 information when the label appears after the proc/procend. */
4934 if (within_entry_exit
)
4936 char *where
= frag_more (0);
4938 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4939 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4940 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4941 (char *) &last_call_info
->ci_unwind
.descriptor
);
4946 as_bad ("Missing function name for .PROC (corrupted label chain)");
4949 as_bad ("Missing function name for .PROC");
4952 if (!within_procedure
)
4953 as_bad ("misplaced .procend");
4955 if (!callinfo_found
)
4956 as_bad ("Missing .callinfo for this procedure");
4958 if (within_entry_exit
)
4959 as_bad ("Missing .EXIT for a .ENTRY");
4962 /* ELF needs to mark the end of each function so that it can compute
4963 the size of the function (apparently its needed in the symbol table. */
4964 hppa_elf_mark_end_of_function ();
4967 within_procedure
= FALSE
;
4968 demand_empty_rest_of_line ();
4969 pa_undefine_label ();
4972 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4973 then create a new space entry to hold the information specified
4974 by the parameters to the .SPACE directive. */
4976 static sd_chain_struct
*
4977 pa_parse_space_stmt (space_name
, create_flag
)
4981 char *name
, *ptemp
, c
;
4982 char loadable
, defined
, private, sort
;
4984 asection
*seg
= NULL
;
4985 sd_chain_struct
*space
;
4987 /* load default values */
4993 if (strcmp (space_name
, "$TEXT$") == 0)
4995 seg
= pa_def_spaces
[0].segment
;
4996 defined
= pa_def_spaces
[0].defined
;
4997 private = pa_def_spaces
[0].private;
4998 sort
= pa_def_spaces
[0].sort
;
4999 spnum
= pa_def_spaces
[0].spnum
;
5001 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5003 seg
= pa_def_spaces
[1].segment
;
5004 defined
= pa_def_spaces
[1].defined
;
5005 private = pa_def_spaces
[1].private;
5006 sort
= pa_def_spaces
[1].sort
;
5007 spnum
= pa_def_spaces
[1].spnum
;
5010 if (!is_end_of_statement ())
5012 print_errors
= FALSE
;
5013 ptemp
= input_line_pointer
+ 1;
5014 /* First see if the space was specified as a number rather than
5015 as a name. According to the PA assembly manual the rest of
5016 the line should be ignored. */
5017 temp
= pa_parse_number (&ptemp
, 0);
5021 input_line_pointer
= ptemp
;
5025 while (!is_end_of_statement ())
5027 input_line_pointer
++;
5028 name
= input_line_pointer
;
5029 c
= get_symbol_end ();
5030 if ((strncasecmp (name
, "spnum", 5) == 0))
5032 *input_line_pointer
= c
;
5033 input_line_pointer
++;
5034 spnum
= get_absolute_expression ();
5036 else if ((strncasecmp (name
, "sort", 4) == 0))
5038 *input_line_pointer
= c
;
5039 input_line_pointer
++;
5040 sort
= get_absolute_expression ();
5042 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5044 *input_line_pointer
= c
;
5047 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5049 *input_line_pointer
= c
;
5052 else if ((strncasecmp (name
, "private", 7) == 0))
5054 *input_line_pointer
= c
;
5059 as_bad ("Invalid .SPACE argument");
5060 *input_line_pointer
= c
;
5061 if (!is_end_of_statement ())
5062 input_line_pointer
++;
5066 print_errors
= TRUE
;
5069 if (create_flag
&& seg
== NULL
)
5070 seg
= subseg_new (space_name
, 0);
5072 /* If create_flag is nonzero, then create the new space with
5073 the attributes computed above. Else set the values in
5074 an already existing space -- this can only happen for
5075 the first occurence of a built-in space. */
5077 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5078 private, sort
, seg
, 1);
5081 space
= is_defined_space (space_name
);
5082 SPACE_SPNUM (space
) = spnum
;
5083 SPACE_DEFINED (space
) = defined
& 1;
5084 SPACE_USER_DEFINED (space
) = 1;
5087 #ifdef obj_set_section_attributes
5088 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5094 /* Handle a .SPACE pseudo-op; this switches the current space to the
5095 given space, creating the new space if necessary. */
5101 char *name
, c
, *space_name
, *save_s
;
5103 sd_chain_struct
*sd_chain
;
5105 if (within_procedure
)
5107 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5108 ignore_rest_of_line ();
5112 /* Check for some of the predefined spaces. FIXME: most of the code
5113 below is repeated several times, can we extract the common parts
5114 and place them into a subroutine or something similar? */
5115 /* FIXME Is this (and the next IF stmt) really right?
5116 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5117 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5119 input_line_pointer
+= 6;
5120 sd_chain
= is_defined_space ("$TEXT$");
5121 if (sd_chain
== NULL
)
5122 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5123 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5124 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5126 current_space
= sd_chain
;
5127 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5129 = pa_subsegment_to_subspace (text_section
,
5130 sd_chain
->sd_last_subseg
);
5131 demand_empty_rest_of_line ();
5134 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5136 input_line_pointer
+= 9;
5137 sd_chain
= is_defined_space ("$PRIVATE$");
5138 if (sd_chain
== NULL
)
5139 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5140 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5141 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5143 current_space
= sd_chain
;
5144 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5146 = pa_subsegment_to_subspace (data_section
,
5147 sd_chain
->sd_last_subseg
);
5148 demand_empty_rest_of_line ();
5151 if (!strncasecmp (input_line_pointer
,
5152 GDB_DEBUG_SPACE_NAME
,
5153 strlen (GDB_DEBUG_SPACE_NAME
)))
5155 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5156 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5157 if (sd_chain
== NULL
)
5158 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5159 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5160 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5162 current_space
= sd_chain
;
5165 asection
*gdb_section
5166 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5168 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5170 = pa_subsegment_to_subspace (gdb_section
,
5171 sd_chain
->sd_last_subseg
);
5173 demand_empty_rest_of_line ();
5177 /* It could be a space specified by number. */
5179 save_s
= input_line_pointer
;
5180 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5182 if ((sd_chain
= pa_find_space_by_number (temp
)))
5184 current_space
= sd_chain
;
5186 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5188 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5189 sd_chain
->sd_last_subseg
);
5190 demand_empty_rest_of_line ();
5195 /* Not a number, attempt to create a new space. */
5197 input_line_pointer
= save_s
;
5198 name
= input_line_pointer
;
5199 c
= get_symbol_end ();
5200 space_name
= xmalloc (strlen (name
) + 1);
5201 strcpy (space_name
, name
);
5202 *input_line_pointer
= c
;
5204 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5205 current_space
= sd_chain
;
5207 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5208 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5209 sd_chain
->sd_last_subseg
);
5210 demand_empty_rest_of_line ();
5214 /* Switch to a new space. (I think). FIXME. */
5223 sd_chain_struct
*space
;
5225 name
= input_line_pointer
;
5226 c
= get_symbol_end ();
5227 space
= is_defined_space (name
);
5231 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5234 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5236 *input_line_pointer
= c
;
5237 demand_empty_rest_of_line ();
5240 /* If VALUE is an exact power of two between zero and 2^31, then
5241 return log2 (VALUE). Else return -1. */
5249 while ((1 << shift
) != value
&& shift
< 32)
5258 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5259 given subspace, creating the new subspace if necessary.
5261 FIXME. Should mirror pa_space more closely, in particular how
5262 they're broken up into subroutines. */
5265 pa_subspace (unused
)
5268 char *name
, *ss_name
, *alias
, c
;
5269 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5270 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5271 sd_chain_struct
*space
;
5272 ssd_chain_struct
*ssd
;
5275 if (within_procedure
)
5277 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5278 ignore_rest_of_line ();
5282 name
= input_line_pointer
;
5283 c
= get_symbol_end ();
5284 ss_name
= xmalloc (strlen (name
) + 1);
5285 strcpy (ss_name
, name
);
5286 *input_line_pointer
= c
;
5288 /* Load default values. */
5301 space
= current_space
;
5302 ssd
= is_defined_subspace (ss_name
);
5303 /* Allow user to override the builtin attributes of subspaces. But
5304 only allow the attributes to be changed once! */
5305 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5307 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5308 if (!is_end_of_statement ())
5309 as_warn ("Parameters of an existing subspace can\'t be modified");
5310 demand_empty_rest_of_line ();
5315 /* A new subspace. Load default values if it matches one of
5316 the builtin subspaces. */
5318 while (pa_def_subspaces
[i
].name
)
5320 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5322 loadable
= pa_def_subspaces
[i
].loadable
;
5323 common
= pa_def_subspaces
[i
].common
;
5324 dup_common
= pa_def_subspaces
[i
].dup_common
;
5325 code_only
= pa_def_subspaces
[i
].code_only
;
5326 zero
= pa_def_subspaces
[i
].zero
;
5327 space_index
= pa_def_subspaces
[i
].space_index
;
5328 alignment
= pa_def_subspaces
[i
].alignment
;
5329 quadrant
= pa_def_subspaces
[i
].quadrant
;
5330 access
= pa_def_subspaces
[i
].access
;
5331 sort
= pa_def_subspaces
[i
].sort
;
5332 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5333 alias
= pa_def_subspaces
[i
].alias
;
5340 /* We should be working with a new subspace now. Fill in
5341 any information as specified by the user. */
5342 if (!is_end_of_statement ())
5344 input_line_pointer
++;
5345 while (!is_end_of_statement ())
5347 name
= input_line_pointer
;
5348 c
= get_symbol_end ();
5349 if ((strncasecmp (name
, "quad", 4) == 0))
5351 *input_line_pointer
= c
;
5352 input_line_pointer
++;
5353 quadrant
= get_absolute_expression ();
5355 else if ((strncasecmp (name
, "align", 5) == 0))
5357 *input_line_pointer
= c
;
5358 input_line_pointer
++;
5359 alignment
= get_absolute_expression ();
5360 if (log2 (alignment
) == -1)
5362 as_bad ("Alignment must be a power of 2");
5366 else if ((strncasecmp (name
, "access", 6) == 0))
5368 *input_line_pointer
= c
;
5369 input_line_pointer
++;
5370 access
= get_absolute_expression ();
5372 else if ((strncasecmp (name
, "sort", 4) == 0))
5374 *input_line_pointer
= c
;
5375 input_line_pointer
++;
5376 sort
= get_absolute_expression ();
5378 else if ((strncasecmp (name
, "code_only", 9) == 0))
5380 *input_line_pointer
= c
;
5383 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5385 *input_line_pointer
= c
;
5388 else if ((strncasecmp (name
, "common", 6) == 0))
5390 *input_line_pointer
= c
;
5393 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5395 *input_line_pointer
= c
;
5398 else if ((strncasecmp (name
, "zero", 4) == 0))
5400 *input_line_pointer
= c
;
5403 else if ((strncasecmp (name
, "first", 5) == 0))
5404 as_bad ("FIRST not supported as a .SUBSPACE argument");
5406 as_bad ("Invalid .SUBSPACE argument");
5407 if (!is_end_of_statement ())
5408 input_line_pointer
++;
5412 /* Compute a reasonable set of BFD flags based on the information
5413 in the .subspace directive. */
5414 applicable
= bfd_applicable_section_flags (stdoutput
);
5417 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5420 if (common
|| dup_common
)
5421 flags
|= SEC_IS_COMMON
;
5423 /* This is a zero-filled subspace (eg BSS). */
5427 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5428 applicable
&= flags
;
5430 /* If this is an existing subspace, then we want to use the
5431 segment already associated with the subspace.
5433 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5434 lots of sections. It might be a problem in the PA ELF
5435 code, I do not know yet. For now avoid creating anything
5436 but the "standard" sections for ELF. */
5438 section
= ssd
->ssd_seg
;
5440 section
= subseg_new (alias
, 0);
5441 else if (!alias
&& USE_ALIASES
)
5443 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5444 demand_empty_rest_of_line ();
5448 section
= subseg_new (ss_name
, 0);
5450 /* Now set the flags. */
5451 bfd_set_section_flags (stdoutput
, section
, applicable
);
5453 /* Record any alignment request for this section. */
5454 record_alignment (section
, log2 (alignment
));
5456 /* Set the starting offset for this section. */
5457 bfd_set_section_vma (stdoutput
, section
,
5458 pa_subspace_start (space
, quadrant
));
5460 /* Now that all the flags are set, update an existing subspace,
5461 or create a new one. */
5464 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5465 code_only
, common
, dup_common
,
5466 sort
, zero
, access
, space_index
,
5467 alignment
, quadrant
,
5470 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5472 dup_common
, zero
, sort
,
5473 access
, space_index
,
5474 alignment
, quadrant
, section
);
5476 demand_empty_rest_of_line ();
5477 current_subspace
->ssd_seg
= section
;
5478 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5480 SUBSPACE_DEFINED (current_subspace
) = 1;
5484 /* Create default space and subspace dictionaries. */
5491 space_dict_root
= NULL
;
5492 space_dict_last
= NULL
;
5495 while (pa_def_spaces
[i
].name
)
5499 /* Pick the right name to use for the new section. */
5500 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5501 name
= pa_def_spaces
[i
].alias
;
5503 name
= pa_def_spaces
[i
].name
;
5505 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5506 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5507 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5508 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5509 pa_def_spaces
[i
].segment
, 0);
5514 while (pa_def_subspaces
[i
].name
)
5517 int applicable
, subsegment
;
5518 asection
*segment
= NULL
;
5519 sd_chain_struct
*space
;
5521 /* Pick the right name for the new section and pick the right
5522 subsegment number. */
5523 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5525 name
= pa_def_subspaces
[i
].alias
;
5526 subsegment
= pa_def_subspaces
[i
].subsegment
;
5530 name
= pa_def_subspaces
[i
].name
;
5534 /* Create the new section. */
5535 segment
= subseg_new (name
, subsegment
);
5538 /* For SOM we want to replace the standard .text, .data, and .bss
5539 sections with our own. We also want to set BFD flags for
5540 all the built-in subspaces. */
5541 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5543 text_section
= segment
;
5544 applicable
= bfd_applicable_section_flags (stdoutput
);
5545 bfd_set_section_flags (stdoutput
, segment
,
5546 applicable
& (SEC_ALLOC
| SEC_LOAD
5547 | SEC_RELOC
| SEC_CODE
5549 | SEC_HAS_CONTENTS
));
5551 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5553 data_section
= segment
;
5554 applicable
= bfd_applicable_section_flags (stdoutput
);
5555 bfd_set_section_flags (stdoutput
, segment
,
5556 applicable
& (SEC_ALLOC
| SEC_LOAD
5558 | SEC_HAS_CONTENTS
));
5562 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5564 bss_section
= segment
;
5565 applicable
= bfd_applicable_section_flags (stdoutput
);
5566 bfd_set_section_flags (stdoutput
, segment
,
5567 applicable
& SEC_ALLOC
);
5569 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5571 applicable
= bfd_applicable_section_flags (stdoutput
);
5572 bfd_set_section_flags (stdoutput
, segment
,
5573 applicable
& (SEC_ALLOC
| SEC_LOAD
5576 | SEC_HAS_CONTENTS
));
5578 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5580 applicable
= bfd_applicable_section_flags (stdoutput
);
5581 bfd_set_section_flags (stdoutput
, segment
,
5582 applicable
& (SEC_ALLOC
| SEC_LOAD
5585 | SEC_HAS_CONTENTS
));
5588 /* Find the space associated with this subspace. */
5589 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5590 def_space_index
].segment
);
5593 as_fatal ("Internal error: Unable to find containing space for %s.",
5594 pa_def_subspaces
[i
].name
);
5597 create_new_subspace (space
, name
,
5598 pa_def_subspaces
[i
].loadable
,
5599 pa_def_subspaces
[i
].code_only
,
5600 pa_def_subspaces
[i
].common
,
5601 pa_def_subspaces
[i
].dup_common
,
5602 pa_def_subspaces
[i
].zero
,
5603 pa_def_subspaces
[i
].sort
,
5604 pa_def_subspaces
[i
].access
,
5605 pa_def_subspaces
[i
].space_index
,
5606 pa_def_subspaces
[i
].alignment
,
5607 pa_def_subspaces
[i
].quadrant
,
5615 /* Create a new space NAME, with the appropriate flags as defined
5616 by the given parameters. */
5618 static sd_chain_struct
*
5619 create_new_space (name
, spnum
, loadable
, defined
, private,
5620 sort
, seg
, user_defined
)
5630 sd_chain_struct
*chain_entry
;
5632 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5634 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5637 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5638 strcpy (SPACE_NAME (chain_entry
), name
);
5639 SPACE_DEFINED (chain_entry
) = defined
;
5640 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5641 SPACE_SPNUM (chain_entry
) = spnum
;
5643 chain_entry
->sd_seg
= seg
;
5644 chain_entry
->sd_last_subseg
= -1;
5645 chain_entry
->sd_subspaces
= NULL
;
5646 chain_entry
->sd_next
= NULL
;
5648 /* Find spot for the new space based on its sort key. */
5649 if (!space_dict_last
)
5650 space_dict_last
= chain_entry
;
5652 if (space_dict_root
== NULL
)
5653 space_dict_root
= chain_entry
;
5656 sd_chain_struct
*chain_pointer
;
5657 sd_chain_struct
*prev_chain_pointer
;
5659 chain_pointer
= space_dict_root
;
5660 prev_chain_pointer
= NULL
;
5662 while (chain_pointer
)
5664 prev_chain_pointer
= chain_pointer
;
5665 chain_pointer
= chain_pointer
->sd_next
;
5668 /* At this point we've found the correct place to add the new
5669 entry. So add it and update the linked lists as appropriate. */
5670 if (prev_chain_pointer
)
5672 chain_entry
->sd_next
= chain_pointer
;
5673 prev_chain_pointer
->sd_next
= chain_entry
;
5677 space_dict_root
= chain_entry
;
5678 chain_entry
->sd_next
= chain_pointer
;
5681 if (chain_entry
->sd_next
== NULL
)
5682 space_dict_last
= chain_entry
;
5685 /* This is here to catch predefined spaces which do not get
5686 modified by the user's input. Another call is found at
5687 the bottom of pa_parse_space_stmt to handle cases where
5688 the user modifies a predefined space. */
5689 #ifdef obj_set_section_attributes
5690 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5696 /* Create a new subspace NAME, with the appropriate flags as defined
5697 by the given parameters.
5699 Add the new subspace to the subspace dictionary chain in numerical
5700 order as defined by the SORT entries. */
5702 static ssd_chain_struct
*
5703 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5704 dup_common
, is_zero
, sort
, access
, space_index
,
5705 alignment
, quadrant
, seg
)
5706 sd_chain_struct
*space
;
5708 int loadable
, code_only
, common
, dup_common
, is_zero
;
5716 ssd_chain_struct
*chain_entry
;
5718 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5720 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5722 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5723 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5725 /* Initialize subspace_defined. When we hit a .subspace directive
5726 we'll set it to 1 which "locks-in" the subspace attributes. */
5727 SUBSPACE_DEFINED (chain_entry
) = 0;
5729 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5730 chain_entry
->ssd_seg
= seg
;
5731 chain_entry
->ssd_next
= NULL
;
5733 /* Find spot for the new subspace based on its sort key. */
5734 if (space
->sd_subspaces
== NULL
)
5735 space
->sd_subspaces
= chain_entry
;
5738 ssd_chain_struct
*chain_pointer
;
5739 ssd_chain_struct
*prev_chain_pointer
;
5741 chain_pointer
= space
->sd_subspaces
;
5742 prev_chain_pointer
= NULL
;
5744 while (chain_pointer
)
5746 prev_chain_pointer
= chain_pointer
;
5747 chain_pointer
= chain_pointer
->ssd_next
;
5750 /* Now we have somewhere to put the new entry. Insert it and update
5752 if (prev_chain_pointer
)
5754 chain_entry
->ssd_next
= chain_pointer
;
5755 prev_chain_pointer
->ssd_next
= chain_entry
;
5759 space
->sd_subspaces
= chain_entry
;
5760 chain_entry
->ssd_next
= chain_pointer
;
5764 #ifdef obj_set_subsection_attributes
5765 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5772 /* Update the information for the given subspace based upon the
5773 various arguments. Return the modified subspace chain entry. */
5775 static ssd_chain_struct
*
5776 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5777 zero
, access
, space_index
, alignment
, quadrant
, section
)
5778 sd_chain_struct
*space
;
5792 ssd_chain_struct
*chain_entry
;
5794 chain_entry
= is_defined_subspace (name
);
5796 #ifdef obj_set_subsection_attributes
5797 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5804 /* Return the space chain entry for the space with the name NAME or
5805 NULL if no such space exists. */
5807 static sd_chain_struct
*
5808 is_defined_space (name
)
5811 sd_chain_struct
*chain_pointer
;
5813 for (chain_pointer
= space_dict_root
;
5815 chain_pointer
= chain_pointer
->sd_next
)
5817 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5818 return chain_pointer
;
5821 /* No mapping from segment to space was found. Return NULL. */
5825 /* Find and return the space associated with the given seg. If no mapping
5826 from the given seg to a space is found, then return NULL.
5828 Unlike subspaces, the number of spaces is not expected to grow much,
5829 so a linear exhaustive search is OK here. */
5831 static sd_chain_struct
*
5832 pa_segment_to_space (seg
)
5835 sd_chain_struct
*space_chain
;
5837 /* Walk through each space looking for the correct mapping. */
5838 for (space_chain
= space_dict_root
;
5840 space_chain
= space_chain
->sd_next
)
5842 if (space_chain
->sd_seg
== seg
)
5846 /* Mapping was not found. Return NULL. */
5850 /* Return the space chain entry for the subspace with the name NAME or
5851 NULL if no such subspace exists.
5853 Uses a linear search through all the spaces and subspaces, this may
5854 not be appropriate if we ever being placing each function in its
5857 static ssd_chain_struct
*
5858 is_defined_subspace (name
)
5861 sd_chain_struct
*space_chain
;
5862 ssd_chain_struct
*subspace_chain
;
5864 /* Walk through each space. */
5865 for (space_chain
= space_dict_root
;
5867 space_chain
= space_chain
->sd_next
)
5869 /* Walk through each subspace looking for a name which matches. */
5870 for (subspace_chain
= space_chain
->sd_subspaces
;
5872 subspace_chain
= subspace_chain
->ssd_next
)
5873 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5874 return subspace_chain
;
5877 /* Subspace wasn't found. Return NULL. */
5881 /* Find and return the subspace associated with the given seg. If no
5882 mapping from the given seg to a subspace is found, then return NULL.
5884 If we ever put each procedure/function within its own subspace
5885 (to make life easier on the compiler and linker), then this will have
5886 to become more efficient. */
5888 static ssd_chain_struct
*
5889 pa_subsegment_to_subspace (seg
, subseg
)
5893 sd_chain_struct
*space_chain
;
5894 ssd_chain_struct
*subspace_chain
;
5896 /* Walk through each space. */
5897 for (space_chain
= space_dict_root
;
5899 space_chain
= space_chain
->sd_next
)
5901 if (space_chain
->sd_seg
== seg
)
5903 /* Walk through each subspace within each space looking for
5904 the correct mapping. */
5905 for (subspace_chain
= space_chain
->sd_subspaces
;
5907 subspace_chain
= subspace_chain
->ssd_next
)
5908 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5909 return subspace_chain
;
5913 /* No mapping from subsegment to subspace found. Return NULL. */
5917 /* Given a number, try and find a space with the name number.
5919 Return a pointer to a space dictionary chain entry for the space
5920 that was found or NULL on failure. */
5922 static sd_chain_struct
*
5923 pa_find_space_by_number (number
)
5926 sd_chain_struct
*space_chain
;
5928 for (space_chain
= space_dict_root
;
5930 space_chain
= space_chain
->sd_next
)
5932 if (SPACE_SPNUM (space_chain
) == number
)
5936 /* No appropriate space found. Return NULL. */
5940 /* Return the starting address for the given subspace. If the starting
5941 address is unknown then return zero. */
5944 pa_subspace_start (space
, quadrant
)
5945 sd_chain_struct
*space
;
5948 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5949 is not correct for the PA OSF1 port. */
5950 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5952 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5958 /* FIXME. Needs documentation. */
5960 pa_next_subseg (space
)
5961 sd_chain_struct
*space
;
5964 space
->sd_last_subseg
++;
5965 return space
->sd_last_subseg
;
5968 /* Helper function for pa_stringer. Used to find the end of
5975 unsigned int c
= *s
& CHAR_MASK
;
5987 /* Handle a .STRING type pseudo-op. */
5990 pa_stringer (append_zero
)
5993 char *s
, num_buf
[4];
5997 /* Preprocess the string to handle PA-specific escape sequences.
5998 For example, \xDD where DD is a hexidecimal number should be
5999 changed to \OOO where OOO is an octal number. */
6001 /* Skip the opening quote. */
6002 s
= input_line_pointer
+ 1;
6004 while (is_a_char (c
= pa_stringer_aux (s
++)))
6011 /* Handle \x<num>. */
6014 unsigned int number
;
6019 /* Get pas the 'x'. */
6021 for (num_digit
= 0, number
= 0, dg
= *s
;
6023 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6024 || (dg
>= 'A' && dg
<= 'F'));
6028 number
= number
* 16 + dg
- '0';
6029 else if (dg
>= 'a' && dg
<= 'f')
6030 number
= number
* 16 + dg
- 'a' + 10;
6032 number
= number
* 16 + dg
- 'A' + 10;
6042 sprintf (num_buf
, "%02o", number
);
6045 sprintf (num_buf
, "%03o", number
);
6048 for (i
= 0; i
<= num_digit
; i
++)
6049 s_start
[i
] = num_buf
[i
];
6053 /* This might be a "\"", skip over the escaped char. */
6060 stringer (append_zero
);
6061 pa_undefine_label ();
6064 /* Handle a .VERSION pseudo-op. */
6071 pa_undefine_label ();
6074 /* Handle a .COPYRIGHT pseudo-op. */
6077 pa_copyright (unused
)
6081 pa_undefine_label ();
6084 /* Just like a normal cons, but when finished we have to undefine
6085 the latest space label. */
6092 pa_undefine_label ();
6095 /* Switch to the data space. As usual delete our label. */
6102 pa_undefine_label ();
6105 /* Like float_cons, but we need to undefine our label. */
6108 pa_float_cons (float_type
)
6111 float_cons (float_type
);
6112 pa_undefine_label ();
6115 /* Like s_fill, but delete our label when finished. */
6122 pa_undefine_label ();
6125 /* Like lcomm, but delete our label when finished. */
6128 pa_lcomm (needs_align
)
6131 s_lcomm (needs_align
);
6132 pa_undefine_label ();
6135 /* Like lsym, but delete our label when finished. */
6142 pa_undefine_label ();
6145 /* Switch to the text space. Like s_text, but delete our
6146 label when finished. */
6152 pa_undefine_label ();
6155 /* On the PA relocations which involve function symbols must not be
6156 adjusted. This so that the linker can know when/how to create argument
6157 relocation stubs for indirect calls and calls to static functions.
6159 "T" field selectors create DLT relative fixups for accessing
6160 globals and statics in PIC code; each DLT relative fixup creates
6161 an entry in the DLT table. The entries contain the address of
6162 the final target (eg accessing "foo" would create a DLT entry
6163 with the address of "foo").
6165 Unfortunately, the HP linker doesn't take into account any addend
6166 when generating the DLT; so accessing $LIT$+8 puts the address of
6167 $LIT$ into the DLT rather than the address of $LIT$+8.
6169 The end result is we can't perform relocation symbol reductions for
6170 any fixup which creates entries in the DLT (eg they use "T" field
6173 FIXME. Also reject R_HPPA relocations which are 32 bits
6174 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6175 needs to generate relocations to push the addend and symbol value
6176 onto the stack, add them, then pop the value off the stack and
6177 use it in a relocation -- yuk. */
6180 hppa_fix_adjustable (fixp
)
6183 struct hppa_fix_struct
*hppa_fix
;
6185 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6187 /* Reject reductions of symbols in 32bit plabel relocs. */
6188 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6191 /* Reject reductions of symbols in DLT relative relocs. */
6192 if (hppa_fix
->fx_r_field
== e_tsel
6193 || hppa_fix
->fx_r_field
== e_ltsel
6194 || hppa_fix
->fx_r_field
== e_rtsel
)
6197 /* Reject reductions of function symbols. */
6198 if (fixp
->fx_addsy
== 0
6199 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6205 /* Return nonzero if the fixup in FIXP will require a relocation,
6206 even it if appears that the fixup could be completely handled
6210 hppa_force_relocation (fixp
)
6213 struct hppa_fix_struct
*hppa_fixp
;
6215 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6217 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6221 #define stub_needed(CALLER, CALLEE) \
6222 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6224 /* It is necessary to force PC-relative calls/jumps to have a relocation
6225 entry if they're going to need either a argument relocation or long
6226 call stub. FIXME. Can't we need the same for absolute calls? */
6227 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6228 && (stub_needed (((obj_symbol_type
*)
6229 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6230 hppa_fixp
->fx_arg_reloc
)))
6235 /* No need (yet) to force another relocations to be emitted. */
6239 /* Now for some ELF specific code. FIXME. */
6241 /* Mark the end of a function so that it's possible to compute
6242 the size of the function in hppa_elf_final_processing. */
6245 hppa_elf_mark_end_of_function ()
6247 /* ELF does not have EXIT relocations. All we do is create a
6248 temporary symbol marking the end of the function. */
6249 char *name
= (char *)
6250 xmalloc (strlen ("L$\001end_") +
6251 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6257 strcpy (name
, "L$\001end_");
6258 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6260 /* If we have a .exit followed by a .procend, then the
6261 symbol will have already been defined. */
6262 symbolP
= symbol_find (name
);
6265 /* The symbol has already been defined! This can
6266 happen if we have a .exit followed by a .procend.
6268 This is *not* an error. All we want to do is free
6269 the memory we just allocated for the name and continue. */
6274 /* symbol value should be the offset of the
6275 last instruction of the function */
6276 symbolP
= symbol_new (name
, now_seg
,
6277 (valueT
) (obstack_next_free (&frags
)
6278 - frag_now
->fr_literal
- 4),
6282 symbolP
->bsym
->flags
= BSF_LOCAL
;
6283 symbol_table_insert (symbolP
);
6287 last_call_info
->end_symbol
= symbolP
;
6289 as_bad ("Symbol '%s' could not be created.", name
);
6293 as_bad ("No memory for symbol name.");
6297 /* For ELF, this function serves one purpose: to setup the st_size
6298 field of STT_FUNC symbols. To do this, we need to scan the
6299 call_info structure list, determining st_size in by taking the
6300 difference in the address of the beginning/end marker symbols. */
6303 elf_hppa_final_processing ()
6305 struct call_info
*call_info_pointer
;
6307 for (call_info_pointer
= call_info_root
;
6309 call_info_pointer
= call_info_pointer
->ci_next
)
6311 elf_symbol_type
*esym
6312 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6313 esym
->internal_elf_sym
.st_size
=
6314 S_GET_VALUE (call_info_pointer
->end_symbol
)
6315 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;