1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "../bfd/libhppa.h"
31 #include "../bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".hppa_unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
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
;
88 /* Various structures and types used internally in tc-hppa.c. */
90 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
94 unsigned int cannot_unwind
:1;
95 unsigned int millicode
:1;
96 unsigned int millicode_save_rest
:1;
97 unsigned int region_desc
:2;
98 unsigned int save_sr
:2;
99 unsigned int entry_fr
:4;
100 unsigned int entry_gr
:5;
101 unsigned int args_stored
:1;
102 unsigned int call_fr
:5;
103 unsigned int call_gr
:5;
104 unsigned int save_sp
:1;
105 unsigned int save_rp
:1;
106 unsigned int save_rp_in_frame
:1;
107 unsigned int extn_ptr_defined
:1;
108 unsigned int cleanup_defined
:1;
110 unsigned int hpe_interrupt_marker
:1;
111 unsigned int hpux_interrupt_marker
:1;
112 unsigned int reserved
:3;
113 unsigned int frame_size
:27;
118 /* Starting and ending offsets of the region described by
120 unsigned int start_offset
;
121 unsigned int end_offset
;
122 struct unwind_desc descriptor
;
125 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
126 control the entry and exit code they generate. It is also used in
127 creation of the correct stack unwind descriptors.
129 NOTE: GAS does not support .enter and .leave for the generation of
130 prologues and epilogues. FIXME.
132 The fields in structure roughly correspond to the arguments available on the
133 .callinfo pseudo-op. */
137 /* The unwind descriptor being built. */
138 struct unwind_table ci_unwind
;
140 /* Name of this function. */
141 symbolS
*start_symbol
;
143 /* (temporary) symbol used to mark the end of this function. */
146 /* Next entry in the chain. */
147 struct call_info
*ci_next
;
150 /* Operand formats for FP instructions. Note not all FP instructions
151 allow all four formats to be used (for example fmpysub only allows
155 SGL
, DBL
, ILLEGAL_FMT
, QUAD
159 /* This fully describes the symbol types which may be attached to
160 an EXPORT or IMPORT directive. Only SOM uses this formation
161 (ELF has no need for it). */
165 SYMBOL_TYPE_ABSOLUTE
,
169 SYMBOL_TYPE_MILLICODE
,
171 SYMBOL_TYPE_PRI_PROG
,
172 SYMBOL_TYPE_SEC_PROG
,
176 /* This structure contains information needed to assemble
177 individual instructions. */
180 /* Holds the opcode after parsing by pa_ip. */
181 unsigned long opcode
;
183 /* Holds an expression associated with the current instruction. */
186 /* Does this instruction use PC-relative addressing. */
189 /* Floating point formats for operand1 and operand2. */
190 fp_operand_format fpof1
;
191 fp_operand_format fpof2
;
193 /* Holds the field selector for this instruction
194 (for example L%, LR%, etc). */
197 /* Holds any argument relocation bits associated with this
198 instruction. (instruction should be some sort of call). */
201 /* The format specification for this instruction. */
204 /* The relocation (if any) associated with this instruction. */
208 /* PA-89 floating point registers are arranged like this:
211 +--------------+--------------+
212 | 0 or 16L | 16 or 16R |
213 +--------------+--------------+
214 | 1 or 17L | 17 or 17R |
215 +--------------+--------------+
223 +--------------+--------------+
224 | 14 or 30L | 30 or 30R |
225 +--------------+--------------+
226 | 15 or 31L | 31 or 31R |
227 +--------------+--------------+
230 The following is a version of pa_parse_number that
231 handles the L/R notation and returns the correct
232 value to put into the instruction register field.
233 The correct value to put into the instruction is
234 encoded in the structure 'pa_89_fp_reg_struct'. */
236 struct pa_89_fp_reg_struct
238 /* The register number. */
245 /* Additional information needed to build argument relocation stubs. */
248 /* The argument relocation specification. */
249 unsigned int arg_reloc
;
251 /* Number of arguments. */
252 unsigned int arg_count
;
255 /* This structure defines an entry in the subspace dictionary
258 struct subspace_dictionary_chain
260 /* Nonzero if this space has been defined by the user code. */
261 unsigned int ssd_defined
;
263 /* Name of this subspace. */
266 /* GAS segment and subsegment associated with this subspace. */
270 /* Next space in the subspace dictionary chain. */
271 struct subspace_dictionary_chain
*ssd_next
;
274 typedef struct subspace_dictionary_chain ssd_chain_struct
;
276 /* This structure defines an entry in the subspace dictionary
279 struct space_dictionary_chain
281 /* Nonzero if this space has been defined by the user code or
282 as a default space. */
283 unsigned int sd_defined
;
285 /* Nonzero if this spaces has been defined by the user code. */
286 unsigned int sd_user_defined
;
288 /* The space number (or index). */
289 unsigned int sd_spnum
;
291 /* The name of this subspace. */
294 /* GAS segment to which this subspace corresponds. */
297 /* Current subsegment number being used. */
300 /* The chain of subspaces contained within this space. */
301 ssd_chain_struct
*sd_subspaces
;
303 /* The next entry in the space dictionary chain. */
304 struct space_dictionary_chain
*sd_next
;
307 typedef struct space_dictionary_chain sd_chain_struct
;
309 /* Structure for previous label tracking. Needed so that alignments,
310 callinfo declarations, etc can be easily attached to a particular
312 typedef struct label_symbol_struct
314 struct symbol
*lss_label
;
315 sd_chain_struct
*lss_space
;
316 struct label_symbol_struct
*lss_next
;
320 /* This structure defines attributes of the default subspace
321 dictionary entries. */
323 struct default_subspace_dict
325 /* Name of the subspace. */
328 /* FIXME. Is this still needed? */
331 /* Nonzero if this subspace is loadable. */
334 /* Nonzero if this subspace contains only code. */
337 /* Nonzero if this is a common subspace. */
340 /* Nonzero if this is a common subspace which allows symbols
341 to be multiply defined. */
344 /* Nonzero if this subspace should be zero filled. */
347 /* Sort key for this subspace. */
350 /* Access control bits for this subspace. Can represent RWX access
351 as well as privilege level changes for gateways. */
354 /* Index of containing space. */
357 /* Alignment (in bytes) of this subspace. */
360 /* Quadrant within space where this subspace should be loaded. */
363 /* An index into the default spaces array. */
366 /* An alias for this section (or NULL if no alias exists). */
369 /* Subsegment associated with this subspace. */
373 /* This structure defines attributes of the default space
374 dictionary entries. */
376 struct default_space_dict
378 /* Name of the space. */
381 /* Space number. It is possible to identify spaces within
382 assembly code numerically! */
385 /* Nonzero if this space is loadable. */
388 /* Nonzero if this space is "defined". FIXME is still needed */
391 /* Nonzero if this space can not be shared. */
394 /* Sort key for this space. */
397 /* Segment associated with this space. */
400 /* An alias for this section (or NULL if no alias exists). */
404 /* Extra information needed to perform fixups (relocations) on the PA. */
405 struct hppa_fix_struct
407 /* The field selector. */
408 enum hppa_reloc_field_selector_type fx_r_field
;
413 /* Format of fixup. */
416 /* Argument relocation bits. */
419 /* The unwind descriptor associated with this fixup. */
422 /* The segment this fixup appears in. */
426 /* Structure to hold information about predefined registers. */
434 /* This structure defines the mapping from a FP condition string
435 to a condition number which can be recorded in an instruction. */
442 /* This structure defines a mapping from a field selector
443 string to a field selector type. */
444 struct selector_entry
450 /* Prototypes for functions local to tc-hppa.c. */
452 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
453 static void pa_cons
PARAMS ((int));
454 static void pa_data
PARAMS ((int));
455 static void pa_float_cons
PARAMS ((int));
456 static void pa_fill
PARAMS ((int));
457 static void pa_lcomm
PARAMS ((int));
458 static void pa_lsym
PARAMS ((int));
459 static void pa_stringer
PARAMS ((int));
460 static void pa_text
PARAMS ((int));
461 static void pa_version
PARAMS ((int));
462 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
463 static int get_expression
PARAMS ((char *));
464 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
465 static int evaluate_absolute
PARAMS ((struct pa_it
*));
466 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
467 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
468 static int pa_parse_nullif
PARAMS ((char **));
469 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
470 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
471 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
472 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
473 static void pa_block
PARAMS ((int));
474 static void pa_call
PARAMS ((int));
475 static void pa_call_args
PARAMS ((struct call_desc
*));
476 static void pa_callinfo
PARAMS ((int));
477 static void pa_code
PARAMS ((int));
478 static void pa_comm
PARAMS ((int));
479 static void pa_copyright
PARAMS ((int));
480 static void pa_end
PARAMS ((int));
481 static void pa_enter
PARAMS ((int));
482 static void pa_entry
PARAMS ((int));
483 static void pa_equ
PARAMS ((int));
484 static void pa_exit
PARAMS ((int));
485 static void pa_export
PARAMS ((int));
486 static void pa_type_args
PARAMS ((symbolS
*, int));
487 static void pa_import
PARAMS ((int));
488 static void pa_label
PARAMS ((int));
489 static void pa_leave
PARAMS ((int));
490 static void pa_origin
PARAMS ((int));
491 static void pa_proc
PARAMS ((int));
492 static void pa_procend
PARAMS ((int));
493 static void pa_space
PARAMS ((int));
494 static void pa_spnum
PARAMS ((int));
495 static void pa_subspace
PARAMS ((int));
496 static void pa_param
PARAMS ((int));
497 static void pa_undefine_label
PARAMS ((void));
498 static int need_89_opcode
PARAMS ((struct pa_it
*,
499 struct pa_89_fp_reg_struct
*));
500 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
501 static label_symbol_struct
*pa_get_label
PARAMS ((void));
502 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
505 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
510 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
511 char *, int, int, int,
515 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
516 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
517 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
518 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
520 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
521 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
522 static void pa_ip
PARAMS ((char *));
523 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
524 long, expressionS
*, int,
525 bfd_reloc_code_real_type
,
526 enum hppa_reloc_field_selector_type
,
528 static int is_end_of_statement
PARAMS ((void));
529 static int reg_name_search
PARAMS ((char *));
530 static int pa_chk_field_selector
PARAMS ((char **));
531 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
532 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
533 static void process_exit
PARAMS ((void));
534 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
535 static int log2
PARAMS ((int));
536 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
537 static unsigned int pa_stringer_aux
PARAMS ((char *));
538 static void pa_spaces_begin
PARAMS ((void));
539 static void hppa_elf_mark_end_of_function
PARAMS ((void));
541 /* File and gloally scoped variable declarations. */
543 /* Root and final entry in the space chain. */
544 static sd_chain_struct
*space_dict_root
;
545 static sd_chain_struct
*space_dict_last
;
547 /* The current space and subspace. */
548 static sd_chain_struct
*current_space
;
549 static ssd_chain_struct
*current_subspace
;
551 /* Root of the call_info chain. */
552 static struct call_info
*call_info_root
;
554 /* The last call_info (for functions) structure
555 seen so it can be associated with fixups and
557 static struct call_info
*last_call_info
;
559 /* The last call description (for actual calls). */
560 static struct call_desc last_call_desc
;
562 /* Relaxation isn't supported for the PA yet. */
563 const relax_typeS md_relax_table
[] =
566 /* Jumps are always the same size -- one instruction. */
567 int md_short_jump_size
= 4;
568 int md_long_jump_size
= 4;
570 /* handle of the OPCODE hash table */
571 static struct hash_control
*op_hash
= NULL
;
573 /* This array holds the chars that always start a comment. If the
574 pre-processor is disabled, these aren't very useful. */
575 const char comment_chars
[] = ";";
577 /* Table of pseudo ops for the PA. FIXME -- how many of these
578 are now redundant with the overall GAS and the object file
580 const pseudo_typeS md_pseudo_table
[] =
582 /* align pseudo-ops on the PA specify the actual alignment requested,
583 not the log2 of the requested alignment. */
584 {"align", s_align_bytes
, 8},
585 {"ALIGN", s_align_bytes
, 8},
586 {"block", pa_block
, 1},
587 {"BLOCK", pa_block
, 1},
588 {"blockz", pa_block
, 0},
589 {"BLOCKZ", pa_block
, 0},
590 {"byte", pa_cons
, 1},
591 {"BYTE", pa_cons
, 1},
592 {"call", pa_call
, 0},
593 {"CALL", pa_call
, 0},
594 {"callinfo", pa_callinfo
, 0},
595 {"CALLINFO", pa_callinfo
, 0},
596 {"code", pa_code
, 0},
597 {"CODE", pa_code
, 0},
598 {"comm", pa_comm
, 0},
599 {"COMM", pa_comm
, 0},
600 {"copyright", pa_copyright
, 0},
601 {"COPYRIGHT", pa_copyright
, 0},
602 {"data", pa_data
, 0},
603 {"DATA", pa_data
, 0},
604 {"double", pa_float_cons
, 'd'},
605 {"DOUBLE", pa_float_cons
, 'd'},
608 {"enter", pa_enter
, 0},
609 {"ENTER", pa_enter
, 0},
610 {"entry", pa_entry
, 0},
611 {"ENTRY", pa_entry
, 0},
614 {"exit", pa_exit
, 0},
615 {"EXIT", pa_exit
, 0},
616 {"export", pa_export
, 0},
617 {"EXPORT", pa_export
, 0},
618 {"fill", pa_fill
, 0},
619 {"FILL", pa_fill
, 0},
620 {"float", pa_float_cons
, 'f'},
621 {"FLOAT", pa_float_cons
, 'f'},
622 {"half", pa_cons
, 2},
623 {"HALF", pa_cons
, 2},
624 {"import", pa_import
, 0},
625 {"IMPORT", pa_import
, 0},
628 {"label", pa_label
, 0},
629 {"LABEL", pa_label
, 0},
630 {"lcomm", pa_lcomm
, 0},
631 {"LCOMM", pa_lcomm
, 0},
632 {"leave", pa_leave
, 0},
633 {"LEAVE", pa_leave
, 0},
634 {"long", pa_cons
, 4},
635 {"LONG", pa_cons
, 4},
636 {"lsym", pa_lsym
, 0},
637 {"LSYM", pa_lsym
, 0},
638 {"octa", pa_cons
, 16},
639 {"OCTA", pa_cons
, 16},
640 {"org", pa_origin
, 0},
641 {"ORG", pa_origin
, 0},
642 {"origin", pa_origin
, 0},
643 {"ORIGIN", pa_origin
, 0},
644 {"param", pa_param
, 0},
645 {"PARAM", pa_param
, 0},
646 {"proc", pa_proc
, 0},
647 {"PROC", pa_proc
, 0},
648 {"procend", pa_procend
, 0},
649 {"PROCEND", pa_procend
, 0},
650 {"quad", pa_cons
, 8},
651 {"QUAD", pa_cons
, 8},
654 {"short", pa_cons
, 2},
655 {"SHORT", pa_cons
, 2},
656 {"single", pa_float_cons
, 'f'},
657 {"SINGLE", pa_float_cons
, 'f'},
658 {"space", pa_space
, 0},
659 {"SPACE", pa_space
, 0},
660 {"spnum", pa_spnum
, 0},
661 {"SPNUM", pa_spnum
, 0},
662 {"string", pa_stringer
, 0},
663 {"STRING", pa_stringer
, 0},
664 {"stringz", pa_stringer
, 1},
665 {"STRINGZ", pa_stringer
, 1},
666 {"subspa", pa_subspace
, 0},
667 {"SUBSPA", pa_subspace
, 0},
668 {"text", pa_text
, 0},
669 {"TEXT", pa_text
, 0},
670 {"version", pa_version
, 0},
671 {"VERSION", pa_version
, 0},
672 {"word", pa_cons
, 4},
673 {"WORD", pa_cons
, 4},
677 /* This array holds the chars that only start a comment at the beginning of
678 a line. If the line seems to have the form '# 123 filename'
679 .line and .file directives will appear in the pre-processed output.
681 Note that input_file.c hand checks for '#' at the beginning of the
682 first line of the input file. This is because the compiler outputs
683 #NO_APP at the beginning of its output.
685 Also note that '/*' will always start a comment. */
686 const char line_comment_chars
[] = "#";
688 /* This array holds the characters which act as line separators. */
689 const char line_separator_chars
[] = "!";
691 /* Chars that can be used to separate mant from exp in floating point nums. */
692 const char EXP_CHARS
[] = "eE";
694 /* Chars that mean this number is a floating point constant.
695 As in 0f12.456 or 0d1.2345e12.
697 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
698 changed in read.c. Ideally it shouldn't hae to know abou it at
699 all, but nothing is ideal around here. */
700 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
702 static struct pa_it the_insn
;
704 /* Points to the end of an expression just parsed by get_expressoin
705 and friends. FIXME. This shouldn't be handled with a file-global
707 static char *expr_end
;
709 /* Nonzero if a .callinfo appeared within the current procedure. */
710 static int callinfo_found
;
712 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
713 static int within_entry_exit
;
715 /* Nonzero if the assembler is currently within a procedure definition. */
716 static int within_procedure
;
718 /* Handle on strucutre which keep track of the last symbol
719 seen in each subspace. */
720 static label_symbol_struct
*label_symbols_rootp
= NULL
;
722 /* Holds the last field selector. */
723 static int hppa_field_selector
;
725 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
726 static symbolS
*dummy_symbol
;
728 /* Nonzero if errors are to be printed. */
729 static int print_errors
= 1;
731 /* List of registers that are pre-defined:
733 Each general register has one predefined name of the form
734 %r<REGNUM> which has the value <REGNUM>.
736 Space and control registers are handled in a similar manner,
737 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
739 Likewise for the floating point registers, but of the form
740 %fr<REGNUM>. Floating point registers have additional predefined
741 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
742 again have the value <REGNUM>.
744 Many registers also have synonyms:
746 %r26 - %r23 have %arg0 - %arg3 as synonyms
747 %r28 - %r29 have %ret0 - %ret1 as synonyms
748 %r30 has %sp as a synonym
749 %r27 has %dp as a synonym
750 %r2 has %rp as a synonym
752 Almost every control register has a synonym; they are not listed
755 The table is sorted. Suitable for searching by a binary search. */
757 static const struct pd_reg pre_defined_registers
[] =
957 /* This table is sorted by order of the length of the string. This is
958 so we check for <> before we check for <. If we had a <> and checked
959 for < first, we would get a false match. */
960 static const struct fp_cond_map fp_cond_map
[] =
996 static const struct selector_entry selector_table
[] =
1015 /* default space and subspace dictionaries */
1017 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1018 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1020 /* pre-defined subsegments (subspaces) for the HPPA. */
1021 #define SUBSEG_CODE 0
1022 #define SUBSEG_DATA 0
1023 #define SUBSEG_LIT 1
1024 #define SUBSEG_BSS 2
1025 #define SUBSEG_UNWIND 3
1026 #define SUBSEG_GDB_STRINGS 0
1027 #define SUBSEG_GDB_SYMBOLS 1
1029 static struct default_subspace_dict pa_def_subspaces
[] =
1031 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1032 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1033 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1034 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1036 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1038 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1041 static struct default_space_dict pa_def_spaces
[] =
1043 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1044 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1045 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1048 /* Misc local definitions used by the assembler. */
1050 /* Return nonzero if the string pointed to by S potentially represents
1051 a right or left half of a FP register */
1052 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1053 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1055 /* These macros are used to maintain spaces/subspaces. */
1056 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1057 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1058 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1059 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1061 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1062 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1064 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1065 main loop after insertion. */
1067 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1069 ((OPCODE) |= (FIELD) << (START)); \
1073 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1074 IGNORE is used to suppress the error message. */
1076 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1078 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1081 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1087 #define is_DP_relative(exp) \
1088 ((exp).X_op == O_subtract \
1089 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1091 #define is_PC_relative(exp) \
1092 ((exp).X_op == O_subtract \
1093 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1095 #define is_complex(exp) \
1096 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1098 /* Actual functions to implement the PA specific code for the assembler. */
1100 /* Returns a pointer to the label_symbol_struct for the current space.
1101 or NULL if no label_symbol_struct exists for the current space. */
1103 static label_symbol_struct
*
1106 label_symbol_struct
*label_chain
;
1107 sd_chain_struct
*space_chain
= current_space
;
1109 for (label_chain
= label_symbols_rootp
;
1111 label_chain
= label_chain
->lss_next
)
1112 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1118 /* Defines a label for the current space. If one is already defined,
1119 this function will replace it with the new label. */
1122 pa_define_label (symbol
)
1125 label_symbol_struct
*label_chain
= pa_get_label ();
1126 sd_chain_struct
*space_chain
= current_space
;
1129 label_chain
->lss_label
= symbol
;
1132 /* Create a new label entry and add it to the head of the chain. */
1134 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1135 label_chain
->lss_label
= symbol
;
1136 label_chain
->lss_space
= space_chain
;
1137 label_chain
->lss_next
= NULL
;
1139 if (label_symbols_rootp
)
1140 label_chain
->lss_next
= label_symbols_rootp
;
1142 label_symbols_rootp
= label_chain
;
1146 /* Removes a label definition for the current space.
1147 If there is no label_symbol_struct entry, then no action is taken. */
1150 pa_undefine_label ()
1152 label_symbol_struct
*label_chain
;
1153 label_symbol_struct
*prev_label_chain
= NULL
;
1154 sd_chain_struct
*space_chain
= current_space
;
1156 for (label_chain
= label_symbols_rootp
;
1158 label_chain
= label_chain
->lss_next
)
1160 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1162 /* Remove the label from the chain and free its memory. */
1163 if (prev_label_chain
)
1164 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1166 label_symbols_rootp
= label_chain
->lss_next
;
1171 prev_label_chain
= label_chain
;
1176 /* An HPPA-specific version of fix_new. This is required because the HPPA
1177 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1178 results in the creation of an instance of an hppa_fix_struct. An
1179 hppa_fix_struct stores the extra information along with a pointer to the
1180 original fixS. This is attached to the original fixup via the
1181 tc_fix_data field. */
1184 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1185 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1189 symbolS
*add_symbol
;
1193 bfd_reloc_code_real_type r_type
;
1194 enum hppa_reloc_field_selector_type r_field
;
1201 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1202 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1205 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1207 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1208 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1209 hppa_fix
->fx_r_type
= r_type
;
1210 hppa_fix
->fx_r_field
= r_field
;
1211 hppa_fix
->fx_r_format
= r_format
;
1212 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1213 hppa_fix
->segment
= now_seg
;
1216 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1218 /* If necessary call BFD backend function to attach the
1219 unwind bits to the target dependent parts of a BFD symbol.
1221 #ifdef obj_attach_unwind_info
1222 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1226 /* foo-$global$ is used to access non-automatic storage. $global$
1227 is really just a marker and has served its purpose, so eliminate
1228 it now so as not to confuse write.c. */
1229 if (new_fix
->fx_subsy
1230 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1231 new_fix
->fx_subsy
= NULL
;
1234 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1235 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1238 parse_cons_expression_hppa (exp
)
1241 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1245 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1246 hppa_field_selector is set by the parse_cons_expression_hppa. */
1249 cons_fix_new_hppa (frag
, where
, size
, exp
)
1255 unsigned int rel_type
;
1257 if (is_DP_relative (*exp
))
1258 rel_type
= R_HPPA_GOTOFF
;
1259 else if (is_complex (*exp
))
1260 rel_type
= R_HPPA_COMPLEX
;
1264 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1265 as_warn ("Invalid field selector. Assuming F%%.");
1267 fix_new_hppa (frag
, where
, size
,
1268 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1269 hppa_field_selector
, 32, 0, (char *) 0);
1271 /* Reset field selector to its default state. */
1272 hppa_field_selector
= 0;
1275 /* This function is called once, at assembler startup time. It should
1276 set up all the tables, etc. that the MD part of the assembler will need. */
1281 const char *retval
= NULL
;
1285 last_call_info
= NULL
;
1286 call_info_root
= NULL
;
1288 /* Folding of text and data segments fails miserably on the PA.
1289 Warn user and disable "-R" option. */
1292 as_warn ("-R option not supported on this target.");
1293 flag_readonly_data_in_text
= 0;
1299 op_hash
= hash_new ();
1301 while (i
< NUMOPCODES
)
1303 const char *name
= pa_opcodes
[i
].name
;
1304 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1305 if (retval
!= NULL
&& *retval
!= '\0')
1307 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1312 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1313 != pa_opcodes
[i
].match
)
1315 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1316 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1321 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1325 as_fatal ("Broken assembler. No assembly attempted.");
1327 /* SOM will change text_section. To make sure we never put
1328 anything into the old one switch to the new one now. */
1329 subseg_set (text_section
, 0);
1331 dummy_symbol
= symbol_find_or_make ("L$dummy");
1332 S_SET_SEGMENT (dummy_symbol
, text_section
);
1335 /* Assemble a single instruction storing it into a frag. */
1342 /* The had better be something to assemble. */
1345 /* If we are within a procedure definition, make sure we've
1346 defined a label for the procedure; handle case where the
1347 label was defined after the .PROC directive.
1349 Note there's not need to diddle with the segment or fragment
1350 for the label symbol in this case. We have already switched
1351 into the new $CODE$ subspace at this point. */
1352 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1354 label_symbol_struct
*label_symbol
= pa_get_label ();
1358 if (label_symbol
->lss_label
)
1360 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1361 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1363 /* Also handle allocation of a fixup to hold the unwind
1364 information when the label appears after the proc/procend. */
1365 if (within_entry_exit
)
1367 char *where
= frag_more (0);
1369 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1370 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
1371 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1372 (char *) &last_call_info
->ci_unwind
.descriptor
);
1377 as_bad ("Missing function name for .PROC (corrupted label chain)");
1380 as_bad ("Missing function name for .PROC");
1383 /* Assemble the instruction. Results are saved into "the_insn". */
1386 /* Get somewhere to put the assembled instrution. */
1389 /* Output the opcode. */
1390 md_number_to_chars (to
, the_insn
.opcode
, 4);
1392 /* If necessary output more stuff. */
1393 if (the_insn
.reloc
!= R_HPPA_NONE
)
1394 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1395 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1396 the_insn
.reloc
, the_insn
.field_selector
,
1397 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1400 /* Do the real work for assembling a single instruction. Store results
1401 into the global "the_insn" variable. */
1407 char *error_message
= "";
1408 char *s
, c
, *argstart
, *name
, *save_s
;
1412 int cmpltr
, nullif
, flag
, cond
, num
;
1413 unsigned long opcode
;
1414 struct pa_opcode
*insn
;
1416 /* Skip to something interesting. */
1417 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1436 as_bad ("Unknown opcode: `%s'", str
);
1442 /* Convert everything into lower case. */
1445 if (isupper (*save_s
))
1446 *save_s
= tolower (*save_s
);
1450 /* Look up the opcode in the has table. */
1451 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1453 as_bad ("Unknown opcode: `%s'", str
);
1462 /* Mark the location where arguments for the instruction start, then
1463 start processing them. */
1467 /* Do some initialization. */
1468 opcode
= insn
->match
;
1469 bzero (&the_insn
, sizeof (the_insn
));
1471 the_insn
.reloc
= R_HPPA_NONE
;
1473 /* Build the opcode, checking as we go to make
1474 sure that the operands match. */
1475 for (args
= insn
->args
;; ++args
)
1480 /* End of arguments. */
1496 /* These must match exactly. */
1505 /* Handle a 5 bit register or control register field at 10. */
1508 num
= pa_parse_number (&s
, 0);
1509 CHECK_FIELD (num
, 31, 0, 0);
1510 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1512 /* Handle a 5 bit register field at 15. */
1514 num
= pa_parse_number (&s
, 0);
1515 CHECK_FIELD (num
, 31, 0, 0);
1516 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1518 /* Handle a 5 bit register field at 31. */
1521 num
= pa_parse_number (&s
, 0);
1522 CHECK_FIELD (num
, 31, 0, 0);
1523 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1525 /* Handle a 5 bit field length at 31. */
1527 num
= pa_get_absolute_expression (&the_insn
, &s
);
1529 CHECK_FIELD (num
, 32, 1, 0);
1530 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1532 /* Handle a 5 bit immediate at 15. */
1534 num
= pa_get_absolute_expression (&the_insn
, &s
);
1536 CHECK_FIELD (num
, 15, -16, 0);
1537 low_sign_unext (num
, 5, &num
);
1538 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1540 /* Handle a 5 bit immediate at 31. */
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
, 0);
1548 /* Handle an unsigned 5 bit immediate at 31. */
1550 num
= pa_get_absolute_expression (&the_insn
, &s
);
1552 CHECK_FIELD (num
, 31, 0, 0);
1553 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1555 /* Handle an unsigned 5 bit immediate at 15. */
1557 num
= pa_get_absolute_expression (&the_insn
, &s
);
1559 CHECK_FIELD (num
, 31, 0, 0);
1560 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1562 /* Handle a 2 bit space identifier at 17. */
1564 num
= pa_parse_number (&s
, 0);
1565 CHECK_FIELD (num
, 3, 0, 1);
1566 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1568 /* Handle a 3 bit space identifier at 18. */
1570 num
= pa_parse_number (&s
, 0);
1571 CHECK_FIELD (num
, 7, 0, 1);
1572 dis_assemble_3 (num
, &num
);
1573 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1575 /* Handle a completer for an indexing load or store. */
1581 while (*s
== ',' && i
< 2)
1584 if (strncasecmp (s
, "sm", 2) == 0)
1591 else if (strncasecmp (s
, "m", 1) == 0)
1593 else if (strncasecmp (s
, "s", 1) == 0)
1596 as_bad ("Invalid Indexed Load Completer.");
1601 as_bad ("Invalid Indexed Load Completer Syntax.");
1603 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1606 /* Handle a short load/store completer. */
1614 if (strncasecmp (s
, "ma", 2) == 0)
1619 else if (strncasecmp (s
, "mb", 2) == 0)
1625 as_bad ("Invalid Short Load/Store Completer.");
1629 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1632 /* Handle a stbys completer. */
1638 while (*s
== ',' && i
< 2)
1641 if (strncasecmp (s
, "m", 1) == 0)
1643 else if (strncasecmp (s
, "b", 1) == 0)
1645 else if (strncasecmp (s
, "e", 1) == 0)
1648 as_bad ("Invalid Store Bytes Short Completer");
1653 as_bad ("Invalid Store Bytes Short Completer");
1655 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1658 /* Handle a non-negated compare/stubtract condition. */
1660 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1663 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1666 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1668 /* Handle a negated or non-negated compare/subtract condition. */
1671 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1675 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1678 as_bad ("Invalid Compare/Subtract Condition.");
1683 /* Negated condition requires an opcode change. */
1687 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1689 /* Handle non-negated add condition. */
1691 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1694 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1697 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1699 /* Handle a negated or non-negated add condition. */
1702 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1706 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1709 as_bad ("Invalid Compare/Subtract Condition");
1714 /* Negated condition requires an opcode change. */
1718 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1720 /* Handle a compare/subtract condition. */
1727 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1732 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1735 as_bad ("Invalid Compare/Subtract Condition");
1739 opcode
|= cmpltr
<< 13;
1740 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1742 /* Handle a non-negated add condition. */
1751 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1755 if (strcmp (name
, "=") == 0)
1757 else if (strcmp (name
, "<") == 0)
1759 else if (strcmp (name
, "<=") == 0)
1761 else if (strcasecmp (name
, "nuv") == 0)
1763 else if (strcasecmp (name
, "znv") == 0)
1765 else if (strcasecmp (name
, "sv") == 0)
1767 else if (strcasecmp (name
, "od") == 0)
1769 else if (strcasecmp (name
, "n") == 0)
1771 else if (strcasecmp (name
, "tr") == 0)
1776 else if (strcmp (name
, "<>") == 0)
1781 else if (strcmp (name
, ">=") == 0)
1786 else if (strcmp (name
, ">") == 0)
1791 else if (strcasecmp (name
, "uv") == 0)
1796 else if (strcasecmp (name
, "vnz") == 0)
1801 else if (strcasecmp (name
, "nsv") == 0)
1806 else if (strcasecmp (name
, "ev") == 0)
1812 as_bad ("Invalid Add Condition: %s", name
);
1815 nullif
= pa_parse_nullif (&s
);
1816 opcode
|= nullif
<< 1;
1817 opcode
|= cmpltr
<< 13;
1818 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1820 /* HANDLE a logical instruction condition. */
1828 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1832 if (strcmp (name
, "=") == 0)
1834 else if (strcmp (name
, "<") == 0)
1836 else if (strcmp (name
, "<=") == 0)
1838 else if (strcasecmp (name
, "od") == 0)
1840 else if (strcasecmp (name
, "tr") == 0)
1845 else if (strcmp (name
, "<>") == 0)
1850 else if (strcmp (name
, ">=") == 0)
1855 else if (strcmp (name
, ">") == 0)
1860 else if (strcasecmp (name
, "ev") == 0)
1866 as_bad ("Invalid Logical Instruction Condition.");
1869 opcode
|= cmpltr
<< 13;
1870 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1872 /* Handle a unit instruction condition. */
1879 if (strncasecmp (s
, "sbz", 3) == 0)
1884 else if (strncasecmp (s
, "shz", 3) == 0)
1889 else if (strncasecmp (s
, "sdc", 3) == 0)
1894 else if (strncasecmp (s
, "sbc", 3) == 0)
1899 else if (strncasecmp (s
, "shc", 3) == 0)
1904 else if (strncasecmp (s
, "tr", 2) == 0)
1910 else if (strncasecmp (s
, "nbz", 3) == 0)
1916 else if (strncasecmp (s
, "nhz", 3) == 0)
1922 else if (strncasecmp (s
, "ndc", 3) == 0)
1928 else if (strncasecmp (s
, "nbc", 3) == 0)
1934 else if (strncasecmp (s
, "nhc", 3) == 0)
1941 as_bad ("Invalid Logical Instruction Condition.");
1943 opcode
|= cmpltr
<< 13;
1944 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1946 /* Handle a shift/extract/deposit condition. */
1954 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1958 if (strcmp (name
, "=") == 0)
1960 else if (strcmp (name
, "<") == 0)
1962 else if (strcasecmp (name
, "od") == 0)
1964 else if (strcasecmp (name
, "tr") == 0)
1966 else if (strcmp (name
, "<>") == 0)
1968 else if (strcmp (name
, ">=") == 0)
1970 else if (strcasecmp (name
, "ev") == 0)
1972 /* Handle movb,n. Put things back the way they were.
1973 This includes moving s back to where it started. */
1974 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1981 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1984 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1986 /* Handle bvb and bb conditions. */
1992 if (strncmp (s
, "<", 1) == 0)
1997 else if (strncmp (s
, ">=", 2) == 0)
2003 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2005 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2007 /* Handle a system control completer. */
2009 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2017 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2019 /* Handle a nullification completer for branch instructions. */
2021 nullif
= pa_parse_nullif (&s
);
2022 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2024 /* Handle a nullification completer for copr and spop insns. */
2026 nullif
= pa_parse_nullif (&s
);
2027 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2029 /* Handle a 11 bit immediate at 31. */
2031 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2034 if (the_insn
.exp
.X_op
== O_constant
)
2036 num
= evaluate_absolute (&the_insn
);
2037 CHECK_FIELD (num
, 1023, -1024, 0);
2038 low_sign_unext (num
, 11, &num
);
2039 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2043 if (is_DP_relative (the_insn
.exp
))
2044 the_insn
.reloc
= R_HPPA_GOTOFF
;
2045 else if (is_PC_relative (the_insn
.exp
))
2046 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2047 else if (is_complex (the_insn
.exp
))
2048 the_insn
.reloc
= R_HPPA_COMPLEX
;
2050 the_insn
.reloc
= R_HPPA
;
2051 the_insn
.format
= 11;
2055 /* Handle a 14 bit immediate at 31. */
2057 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2060 if (the_insn
.exp
.X_op
== O_constant
)
2062 num
= evaluate_absolute (&the_insn
);
2063 CHECK_FIELD (num
, 8191, -8192, 0);
2064 low_sign_unext (num
, 14, &num
);
2065 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2069 if (is_DP_relative (the_insn
.exp
))
2070 the_insn
.reloc
= R_HPPA_GOTOFF
;
2071 else if (is_PC_relative (the_insn
.exp
))
2072 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2073 else if (is_complex (the_insn
.exp
))
2074 the_insn
.reloc
= R_HPPA_COMPLEX
;
2076 the_insn
.reloc
= R_HPPA
;
2077 the_insn
.format
= 14;
2081 /* Handle a 21 bit immediate at 31. */
2083 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2086 if (the_insn
.exp
.X_op
== O_constant
)
2088 num
= evaluate_absolute (&the_insn
);
2089 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2090 dis_assemble_21 (num
, &num
);
2091 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2095 if (is_DP_relative (the_insn
.exp
))
2096 the_insn
.reloc
= R_HPPA_GOTOFF
;
2097 else if (is_PC_relative (the_insn
.exp
))
2098 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2099 else if (is_complex (the_insn
.exp
))
2100 the_insn
.reloc
= R_HPPA_COMPLEX
;
2102 the_insn
.reloc
= R_HPPA
;
2103 the_insn
.format
= 21;
2107 /* Handle a 12 bit branch displacement. */
2109 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2113 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2115 unsigned int w1
, w
, result
;
2117 num
= evaluate_absolute (&the_insn
);
2120 as_bad ("Branch to unaligned address");
2123 CHECK_FIELD (num
, 8191, -8192, 0);
2124 sign_unext ((num
- 8) >> 2, 12, &result
);
2125 dis_assemble_12 (result
, &w1
, &w
);
2126 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2130 if (is_complex (the_insn
.exp
))
2131 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2133 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2134 the_insn
.format
= 12;
2135 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2136 bzero (&last_call_desc
, sizeof (struct call_desc
));
2141 /* Handle a 17 bit branch displacement. */
2143 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2147 if (!the_insn
.exp
.X_add_symbol
2148 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2151 unsigned int w2
, w1
, w
, result
;
2153 num
= evaluate_absolute (&the_insn
);
2156 as_bad ("Branch to unaligned address");
2159 CHECK_FIELD (num
, 262143, -262144, 0);
2161 if (the_insn
.exp
.X_add_symbol
)
2164 sign_unext (num
>> 2, 17, &result
);
2165 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2166 INSERT_FIELD_AND_CONTINUE (opcode
,
2167 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2171 if (is_complex (the_insn
.exp
))
2172 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2174 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2175 the_insn
.format
= 17;
2176 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2177 bzero (&last_call_desc
, sizeof (struct call_desc
));
2181 /* Handle an absolute 17 bit branch target. */
2183 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2187 if (!the_insn
.exp
.X_add_symbol
2188 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2191 unsigned int w2
, w1
, w
, result
;
2193 num
= evaluate_absolute (&the_insn
);
2196 as_bad ("Branch to unaligned address");
2199 CHECK_FIELD (num
, 262143, -262144, 0);
2201 if (the_insn
.exp
.X_add_symbol
)
2204 sign_unext (num
>> 2, 17, &result
);
2205 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2206 INSERT_FIELD_AND_CONTINUE (opcode
,
2207 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2211 if (is_complex (the_insn
.exp
))
2212 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2214 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2215 the_insn
.format
= 17;
2219 /* Handle a 5 bit shift count at 26. */
2221 num
= pa_get_absolute_expression (&the_insn
, &s
);
2223 CHECK_FIELD (num
, 31, 0, 0);
2224 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2226 /* Handle a 5 bit bit position at 26. */
2228 num
= pa_get_absolute_expression (&the_insn
, &s
);
2230 CHECK_FIELD (num
, 31, 0, 0);
2231 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2233 /* Handle a 5 bit immediate at 10. */
2235 num
= pa_get_absolute_expression (&the_insn
, &s
);
2237 CHECK_FIELD (num
, 31, 0, 0);
2238 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2240 /* Handle a 13 bit immediate at 18. */
2242 num
= pa_get_absolute_expression (&the_insn
, &s
);
2244 CHECK_FIELD (num
, 4095, -4096, 0);
2245 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2247 /* Handle a 26 bit immediate at 31. */
2249 num
= pa_get_absolute_expression (&the_insn
, &s
);
2251 CHECK_FIELD (num
, 671108864, 0, 0);
2252 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2254 /* Handle a 3 bit SFU identifier at 25. */
2257 as_bad ("Invalid SFU identifier");
2258 num
= pa_get_absolute_expression (&the_insn
, &s
);
2260 CHECK_FIELD (num
, 7, 0, 0);
2261 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2263 /* Handle a 20 bit SOP field for spop0. */
2265 num
= pa_get_absolute_expression (&the_insn
, &s
);
2267 CHECK_FIELD (num
, 1048575, 0, 0);
2268 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2269 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2271 /* Handle a 15bit SOP field for spop1. */
2273 num
= pa_get_absolute_expression (&the_insn
, &s
);
2275 CHECK_FIELD (num
, 32767, 0, 0);
2276 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2278 /* Handle a 10bit SOP field for spop3. */
2280 num
= pa_get_absolute_expression (&the_insn
, &s
);
2282 CHECK_FIELD (num
, 1023, 0, 0);
2283 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2284 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2286 /* Handle a 15 bit SOP field for spop2. */
2288 num
= pa_get_absolute_expression (&the_insn
, &s
);
2290 CHECK_FIELD (num
, 32767, 0, 0);
2291 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2292 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2294 /* Handle a 3-bit co-processor ID field. */
2297 as_bad ("Invalid COPR identifier");
2298 num
= pa_get_absolute_expression (&the_insn
, &s
);
2300 CHECK_FIELD (num
, 7, 0, 0);
2301 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2303 /* Handle a 22bit SOP field for copr. */
2305 num
= pa_get_absolute_expression (&the_insn
, &s
);
2307 CHECK_FIELD (num
, 4194303, 0, 0);
2308 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2309 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2311 /* Handle a source FP operand format completer. */
2313 flag
= pa_parse_fp_format (&s
);
2314 the_insn
.fpof1
= flag
;
2315 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2317 /* Handle a destination FP operand format completer. */
2319 /* pa_parse_format needs the ',' prefix. */
2321 flag
= pa_parse_fp_format (&s
);
2322 the_insn
.fpof2
= flag
;
2323 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2325 /* Handle FP compare conditions. */
2327 cond
= pa_parse_fp_cmp_cond (&s
);
2328 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2330 /* Handle L/R register halves like 't'. */
2333 struct pa_89_fp_reg_struct result
;
2335 pa_parse_number (&s
, &result
);
2336 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2337 opcode
|= result
.number_part
;
2339 /* 0x30 opcodes are FP arithmetic operation opcodes
2340 and need to be turned into 0x38 opcodes. This
2341 is not necessary for loads/stores. */
2342 if (need_89_opcode (&the_insn
, &result
)
2343 && ((opcode
& 0xfc000000) == 0x30000000))
2346 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2349 /* Handle L/R register halves like 'b'. */
2352 struct pa_89_fp_reg_struct result
;
2354 pa_parse_number (&s
, &result
);
2355 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2356 opcode
|= result
.number_part
<< 21;
2357 if (need_89_opcode (&the_insn
, &result
))
2359 opcode
|= (result
.l_r_select
& 1) << 7;
2365 /* Handle L/R register halves like 'x'. */
2368 struct pa_89_fp_reg_struct result
;
2370 pa_parse_number (&s
, &result
);
2371 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2372 opcode
|= (result
.number_part
& 0x1f) << 16;
2373 if (need_89_opcode (&the_insn
, &result
))
2375 opcode
|= (result
.l_r_select
& 1) << 12;
2381 /* Handle a 5 bit register field at 10. */
2384 struct pa_89_fp_reg_struct result
;
2386 pa_parse_number (&s
, &result
);
2387 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2388 if (the_insn
.fpof1
== SGL
)
2390 result
.number_part
&= 0xF;
2391 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2393 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2396 /* Handle a 5 bit register field at 15. */
2399 struct pa_89_fp_reg_struct result
;
2401 pa_parse_number (&s
, &result
);
2402 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2403 if (the_insn
.fpof1
== SGL
)
2405 result
.number_part
&= 0xF;
2406 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2408 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2411 /* Handle a 5 bit register field at 31. */
2414 struct pa_89_fp_reg_struct result
;
2416 pa_parse_number (&s
, &result
);
2417 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2418 if (the_insn
.fpof1
== SGL
)
2420 result
.number_part
&= 0xF;
2421 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2423 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2426 /* Handle a 5 bit register field at 20. */
2429 struct pa_89_fp_reg_struct result
;
2431 pa_parse_number (&s
, &result
);
2432 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2433 if (the_insn
.fpof1
== SGL
)
2435 result
.number_part
&= 0xF;
2436 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2438 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2441 /* Handle a 5 bit register field at 25. */
2444 struct pa_89_fp_reg_struct result
;
2446 pa_parse_number (&s
, &result
);
2447 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2448 if (the_insn
.fpof1
== SGL
)
2450 result
.number_part
&= 0xF;
2451 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2453 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2456 /* Handle a floating point operand format at 26.
2457 Only allows single and double precision. */
2459 flag
= pa_parse_fp_format (&s
);
2465 the_insn
.fpof1
= flag
;
2471 as_bad ("Invalid Floating Point Operand Format.");
2481 /* Check if the args matched. */
2484 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2485 && !strcmp (insn
->name
, insn
[1].name
))
2493 as_bad ("Invalid operands %s", error_message
);
2500 the_insn
.opcode
= opcode
;
2503 /* Turn a string in input_line_pointer into a floating point constant of type
2504 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2505 emitted is stored in *sizeP . An error message or NULL is returned. */
2507 #define MAX_LITTLENUMS 6
2510 md_atof (type
, litP
, sizeP
)
2516 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2517 LITTLENUM_TYPE
*wordP
;
2549 return "Bad call to MD_ATOF()";
2551 t
= atof_ieee (input_line_pointer
, type
, words
);
2553 input_line_pointer
= t
;
2554 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2555 for (wordP
= words
; prec
--;)
2557 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2558 litP
+= sizeof (LITTLENUM_TYPE
);
2563 /* Write out big-endian. */
2566 md_number_to_chars (buf
, val
, n
)
2571 number_to_chars_bigendian (buf
, val
, n
);
2574 /* Translate internal representation of relocation info to BFD target
2578 tc_gen_reloc (section
, fixp
)
2583 struct hppa_fix_struct
*hppa_fixp
;
2584 bfd_reloc_code_real_type code
;
2585 static int unwind_reloc_fixp_cnt
= 0;
2586 static arelent
*unwind_reloc_entryP
= NULL
;
2587 static arelent
*no_relocs
= NULL
;
2589 bfd_reloc_code_real_type
**codes
;
2593 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2594 if (fixp
->fx_addsy
== 0)
2596 assert (hppa_fixp
!= 0);
2597 assert (section
!= 0);
2600 /* Yuk. I would really like to push all this ELF specific unwind
2601 crud into BFD and the linker. That's how SOM does it -- and
2602 if we could make ELF emulate that then we could share more code
2603 in GAS (and potentially a gnu-linker later).
2605 Unwind section relocations are handled in a special way.
2606 The relocations for the .unwind section are originally
2607 built in the usual way. That is, for each unwind table
2608 entry there are two relocations: one for the beginning of
2609 the function and one for the end.
2611 The first time we enter this function we create a
2612 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2613 of the relocation is initialized to 0. Each additional
2614 pair of times this function is called for the unwind
2615 section represents an additional unwind table entry. Thus,
2616 the addend of the relocation should end up to be the number
2617 of unwind table entries. */
2618 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2620 if (unwind_reloc_entryP
== NULL
)
2622 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2624 assert (reloc
!= 0);
2625 unwind_reloc_entryP
= reloc
;
2626 unwind_reloc_fixp_cnt
++;
2627 unwind_reloc_entryP
->address
2628 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2629 /* A pointer to any function will do. We only
2630 need one to tell us what section the unwind
2631 relocations are for. */
2632 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2633 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2634 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2635 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2636 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2637 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2638 sizeof (arelent
*) * 2);
2639 assert (relocs
!= 0);
2640 relocs
[0] = unwind_reloc_entryP
;
2644 unwind_reloc_fixp_cnt
++;
2645 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2651 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2652 assert (reloc
!= 0);
2654 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2655 codes
= hppa_gen_reloc_type (stdoutput
,
2657 hppa_fixp
->fx_r_format
,
2658 hppa_fixp
->fx_r_field
);
2660 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2663 relocs
= (arelent
**)
2664 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2665 assert (relocs
!= 0);
2667 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2668 sizeof (arelent
) * n_relocs
);
2670 assert (reloc
!= 0);
2672 for (i
= 0; i
< n_relocs
; i
++)
2673 relocs
[i
] = &reloc
[i
];
2675 relocs
[n_relocs
] = NULL
;
2678 switch (fixp
->fx_r_type
)
2680 case R_HPPA_COMPLEX
:
2681 case R_HPPA_COMPLEX_PCREL_CALL
:
2682 case R_HPPA_COMPLEX_ABS_CALL
:
2683 assert (n_relocs
== 5);
2685 for (i
= 0; i
< n_relocs
; i
++)
2687 reloc
[i
].sym_ptr_ptr
= NULL
;
2688 reloc
[i
].address
= 0;
2689 reloc
[i
].addend
= 0;
2690 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2691 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2694 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2695 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2696 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2698 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2699 reloc
[3].addend
= fixp
->fx_addnumber
;
2700 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2701 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2702 reloc
[1].addend
= fixp
->fx_addnumber
;
2707 assert (n_relocs
== 1);
2711 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2712 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2713 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2714 reloc
->addend
= 0; /* default */
2716 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2718 /* Now, do any processing that is dependent on the relocation type. */
2721 case R_HPPA_PLABEL_32
:
2722 case R_HPPA_PLABEL_11
:
2723 case R_HPPA_PLABEL_14
:
2724 case R_HPPA_PLABEL_L21
:
2725 case R_HPPA_PLABEL_R11
:
2726 case R_HPPA_PLABEL_R14
:
2727 /* For plabel relocations, the addend of the
2728 relocation should be either 0 (no static link) or 2
2729 (static link required).
2731 FIXME: We always assume no static link! */
2735 case R_HPPA_ABS_CALL_11
:
2736 case R_HPPA_ABS_CALL_14
:
2737 case R_HPPA_ABS_CALL_17
:
2738 case R_HPPA_ABS_CALL_L21
:
2739 case R_HPPA_ABS_CALL_R11
:
2740 case R_HPPA_ABS_CALL_R14
:
2741 case R_HPPA_ABS_CALL_R17
:
2742 case R_HPPA_ABS_CALL_LS21
:
2743 case R_HPPA_ABS_CALL_RS11
:
2744 case R_HPPA_ABS_CALL_RS14
:
2745 case R_HPPA_ABS_CALL_RS17
:
2746 case R_HPPA_ABS_CALL_LD21
:
2747 case R_HPPA_ABS_CALL_RD11
:
2748 case R_HPPA_ABS_CALL_RD14
:
2749 case R_HPPA_ABS_CALL_RD17
:
2750 case R_HPPA_ABS_CALL_LR21
:
2751 case R_HPPA_ABS_CALL_RR14
:
2752 case R_HPPA_ABS_CALL_RR17
:
2754 case R_HPPA_PCREL_CALL_11
:
2755 case R_HPPA_PCREL_CALL_14
:
2756 case R_HPPA_PCREL_CALL_17
:
2757 case R_HPPA_PCREL_CALL_L21
:
2758 case R_HPPA_PCREL_CALL_R11
:
2759 case R_HPPA_PCREL_CALL_R14
:
2760 case R_HPPA_PCREL_CALL_R17
:
2761 case R_HPPA_PCREL_CALL_LS21
:
2762 case R_HPPA_PCREL_CALL_RS11
:
2763 case R_HPPA_PCREL_CALL_RS14
:
2764 case R_HPPA_PCREL_CALL_RS17
:
2765 case R_HPPA_PCREL_CALL_LD21
:
2766 case R_HPPA_PCREL_CALL_RD11
:
2767 case R_HPPA_PCREL_CALL_RD14
:
2768 case R_HPPA_PCREL_CALL_RD17
:
2769 case R_HPPA_PCREL_CALL_LR21
:
2770 case R_HPPA_PCREL_CALL_RR14
:
2771 case R_HPPA_PCREL_CALL_RR17
:
2772 /* The constant is stored in the instruction. */
2773 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2776 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2777 relocs
[i
]->addend
= 0;
2779 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2787 /* Walk over reach relocation returned by the BFD backend. */
2788 for (i
= 0; i
< n_relocs
; i
++)
2792 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2793 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2794 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2800 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2805 /* For plabel relocations, the addend of the
2806 relocation should be either 0 (no static link) or 2
2807 (static link required).
2809 FIXME: We always assume no static link! */
2810 relocs
[i
]->addend
= 0;
2821 /* There is no symbol or addend associated with these fixups. */
2822 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2823 relocs
[i
]->addend
= 0;
2827 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2828 relocs
[i
]->addend
= 0;
2830 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2839 /* Process any machine dependent frag types. */
2842 md_convert_frag (abfd
, sec
, fragP
)
2844 register asection
*sec
;
2845 register fragS
*fragP
;
2847 unsigned int address
;
2849 if (fragP
->fr_type
== rs_machine_dependent
)
2851 switch ((int) fragP
->fr_subtype
)
2854 fragP
->fr_type
= rs_fill
;
2855 know (fragP
->fr_var
== 1);
2856 know (fragP
->fr_next
);
2857 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2858 if (address
% fragP
->fr_offset
)
2861 fragP
->fr_next
->fr_address
2866 fragP
->fr_offset
= 0;
2872 /* Round up a section size to the appropriate boundary. */
2875 md_section_align (segment
, size
)
2879 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2880 int align2
= (1 << align
) - 1;
2882 return (size
+ align2
) & ~align2
;
2885 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2887 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2889 addressT from_addr
, to_addr
;
2893 fprintf (stderr
, "pa_create_short_jmp\n");
2897 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2899 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2901 addressT from_addr
, to_addr
;
2905 fprintf (stderr
, "pa_create_long_jump\n");
2909 /* Return the approximate size of a frag before relaxation has occurred. */
2911 md_estimate_size_before_relax (fragP
, segment
)
2912 register fragS
*fragP
;
2919 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2925 /* Parse machine dependent options. There are none on the PA. */
2927 md_parse_option (argP
, cntP
, vecP
)
2935 /* We have no need to default values of symbols. */
2938 md_undefined_symbol (name
)
2944 /* Parse an operand that is machine-specific.
2945 We just return without modifying the expression as we have nothing
2949 md_operand (expressionP
)
2950 expressionS
*expressionP
;
2954 /* Apply a fixup to an instruction. */
2957 md_apply_fix (fixP
, valp
)
2961 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2962 struct hppa_fix_struct
*hppa_fixP
;
2963 long new_val
, result
;
2964 unsigned int w1
, w2
, w
;
2967 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2968 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2969 never be "applied" (they are just markers). */
2971 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2972 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2976 /* There should have been an HPPA specific fixup associated
2977 with the GAS fixup. */
2980 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2981 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2983 if (fixP
->fx_r_type
== R_HPPA_NONE
)
2986 /* Remember this value for emit_reloc. FIXME, is this braindamage
2987 documented anywhere!?! */
2988 fixP
->fx_addnumber
= val
;
2990 /* Check if this is an undefined symbol. No relocation can
2991 possibly be performed in this case.
2993 Also avoid doing anything for pc-relative fixups in which the
2994 fixup is in a different space than the symbol it references. */
2995 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
2997 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
)
3000 && S_GET_SEGMENT (fixP
->fx_addsy
) != hppa_fixP
->segment
)
3003 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
3006 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
3007 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
3008 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
3009 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
3010 && hppa_fixP
->fx_r_field
!= R_HPPA_TSEL
3011 && hppa_fixP
->fx_r_field
!= R_HPPA_LTSEL
3012 && hppa_fixP
->fx_r_field
!= R_HPPA_RTSEL
3013 && !(fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
))
3014 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3020 /* Handle all opcodes with the 'j' operand type. */
3022 CHECK_FIELD (new_val
, 8191, -8192, 0);
3024 /* Mask off 14 bits to be changed. */
3025 bfd_put_32 (stdoutput
,
3026 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3028 low_sign_unext (new_val
, 14, &result
);
3031 /* Handle all opcodes with the 'k' operand type. */
3033 CHECK_FIELD (new_val
, 2097152, 0, 0);
3035 /* Mask off 21 bits to be changed. */
3036 bfd_put_32 (stdoutput
,
3037 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3039 dis_assemble_21 (new_val
, &result
);
3042 /* Handle all the opcodes with the 'i' operand type. */
3044 CHECK_FIELD (new_val
, 1023, -1023, 0);
3046 /* Mask off 11 bits to be changed. */
3047 bfd_put_32 (stdoutput
,
3048 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3050 low_sign_unext (new_val
, 11, &result
);
3053 /* Handle all the opcodes with the 'w' operand type. */
3055 CHECK_FIELD (new_val
, 8191, -8192, 0)
3057 /* Mask off 11 bits to be changed. */
3058 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3059 bfd_put_32 (stdoutput
,
3060 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3063 dis_assemble_12 (result
, &w1
, &w
);
3064 result
= ((w1
<< 2) | w
);
3067 /* Handle some of the opcodes with the 'W' operand type. */
3070 #define stub_needed(CALLER, CALLEE) \
3071 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3072 /* It is necessary to force PC-relative calls/jumps to have a
3073 relocation entry if they're going to need either a argument
3074 relocation or long call stub. FIXME. Can't we need the same
3075 for absolute calls? */
3077 && (stub_needed (((obj_symbol_type
*)
3078 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3079 hppa_fixP
->fx_arg_reloc
)))
3083 CHECK_FIELD (new_val
, 262143, -262144, 0);
3085 /* Mask off 17 bits to be changed. */
3086 bfd_put_32 (stdoutput
,
3087 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3089 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3090 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3091 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3096 /* These are ELF specific relocations. ELF unfortunately
3097 handles unwinds in a completely different manner. */
3098 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3099 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3100 result
= fixP
->fx_addnumber
;
3105 fixP
->fx_addnumber
= fixP
->fx_offset
;
3106 /* If we have a real relocation, then we want zero to
3107 be stored in the object file. If no relocation is going
3108 to be emitted, then we need to store new_val into the
3111 bfd_put_32 (stdoutput
, 0, buf
);
3113 bfd_put_32 (stdoutput
, new_val
, buf
);
3122 as_bad ("Unknown relocation encountered in md_apply_fix.");
3126 /* Insert the relocation. */
3127 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3132 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3133 (unsigned int) fixP
, fixP
->fx_r_type
);
3138 /* Exactly what point is a PC-relative offset relative TO?
3139 On the PA, they're relative to the address of the offset. */
3142 md_pcrel_from (fixP
)
3145 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3148 /* Return nonzero if the input line pointer is at the end of
3152 is_end_of_statement ()
3154 return ((*input_line_pointer
== '\n')
3155 || (*input_line_pointer
== ';')
3156 || (*input_line_pointer
== '!'));
3159 /* Read a number from S. The number might come in one of many forms,
3160 the most common will be a hex or decimal constant, but it could be
3161 a pre-defined register (Yuk!), or an absolute symbol.
3163 Return a number or -1 for failure.
3165 When parsing PA-89 FP register numbers RESULT will be
3166 the address of a structure to return information about
3167 L/R half of FP registers, store results there as appropriate.
3169 pa_parse_number can not handle negative constants and will fail
3170 horribly if it is passed such a constant. */
3173 pa_parse_number (s
, result
)
3175 struct pa_89_fp_reg_struct
*result
;
3184 /* Skip whitespace before the number. */
3185 while (*p
== ' ' || *p
== '\t')
3188 /* Store info in RESULT if requested by caller. */
3191 result
->number_part
= -1;
3192 result
->l_r_select
= -1;
3198 /* Looks like a number. */
3201 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3203 /* The number is specified in hex. */
3205 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3206 || ((*p
>= 'A') && (*p
<= 'F')))
3209 num
= num
* 16 + *p
- '0';
3210 else if (*p
>= 'a' && *p
<= 'f')
3211 num
= num
* 16 + *p
- 'a' + 10;
3213 num
= num
* 16 + *p
- 'A' + 10;
3219 /* The number is specified in decimal. */
3220 while (isdigit (*p
))
3222 num
= num
* 10 + *p
- '0';
3227 /* Store info in RESULT if requested by the caller. */
3230 result
->number_part
= num
;
3232 if (IS_R_SELECT (p
))
3234 result
->l_r_select
= 1;
3237 else if (IS_L_SELECT (p
))
3239 result
->l_r_select
= 0;
3243 result
->l_r_select
= 0;
3248 /* The number might be a predefined register. */
3253 /* Tege hack: Special case for general registers as the general
3254 code makes a binary search with case translation, and is VERY
3259 if (*p
== 'e' && *(p
+ 1) == 't'
3260 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3263 num
= *p
- '0' + 28;
3271 else if (!isdigit (*p
))
3274 as_bad ("Undefined register: '%s'.", name
);
3280 num
= num
* 10 + *p
++ - '0';
3281 while (isdigit (*p
));
3286 /* Do a normal register search. */
3287 while (is_part_of_name (c
))
3293 status
= reg_name_search (name
);
3299 as_bad ("Undefined register: '%s'.", name
);
3305 /* Store info in RESULT if requested by caller. */
3308 result
->number_part
= num
;
3309 if (IS_R_SELECT (p
- 1))
3310 result
->l_r_select
= 1;
3311 else if (IS_L_SELECT (p
- 1))
3312 result
->l_r_select
= 0;
3314 result
->l_r_select
= 0;
3319 /* And finally, it could be a symbol in the absolute section which
3320 is effectively a constant. */
3324 while (is_part_of_name (c
))
3330 if ((sym
= symbol_find (name
)) != NULL
)
3332 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3333 num
= S_GET_VALUE (sym
);
3337 as_bad ("Non-absolute symbol: '%s'.", name
);
3343 /* There is where we'd come for an undefined symbol
3344 or for an empty string. For an empty string we
3345 will return zero. That's a concession made for
3346 compatability with the braindamaged HP assemblers. */
3352 as_bad ("Undefined absolute constant: '%s'.", name
);
3358 /* Store info in RESULT if requested by caller. */
3361 result
->number_part
= num
;
3362 if (IS_R_SELECT (p
- 1))
3363 result
->l_r_select
= 1;
3364 else if (IS_L_SELECT (p
- 1))
3365 result
->l_r_select
= 0;
3367 result
->l_r_select
= 0;
3375 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3377 /* Given NAME, find the register number associated with that name, return
3378 the integer value associated with the given name or -1 on failure. */
3381 reg_name_search (name
)
3384 int middle
, low
, high
;
3388 high
= REG_NAME_CNT
- 1;
3392 middle
= (low
+ high
) / 2;
3393 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3399 return pre_defined_registers
[middle
].value
;
3401 while (low
<= high
);
3407 /* Return nonzero if the given INSN and L/R information will require
3408 a new PA-89 opcode. */
3411 need_89_opcode (insn
, result
)
3413 struct pa_89_fp_reg_struct
*result
;
3415 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3421 /* Parse a condition for a fcmp instruction. Return the numerical
3422 code associated with the condition. */
3425 pa_parse_fp_cmp_cond (s
)
3432 for (i
= 0; i
< 32; i
++)
3434 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3435 strlen (fp_cond_map
[i
].string
)) == 0)
3437 cond
= fp_cond_map
[i
].cond
;
3438 *s
+= strlen (fp_cond_map
[i
].string
);
3439 while (**s
== ' ' || **s
== '\t')
3445 as_bad ("Invalid FP Compare Condition: %c", **s
);
3449 /* Parse an FP operand format completer returning the completer
3452 static fp_operand_format
3453 pa_parse_fp_format (s
)
3462 if (strncasecmp (*s
, "sgl", 3) == 0)
3467 else if (strncasecmp (*s
, "dbl", 3) == 0)
3472 else if (strncasecmp (*s
, "quad", 4) == 0)
3479 format
= ILLEGAL_FMT
;
3480 as_bad ("Invalid FP Operand Format: %3s", *s
);
3487 /* Convert from a selector string into a selector type. */
3490 pa_chk_field_selector (str
)
3493 int middle
, low
, high
;
3497 /* Read past any whitespace. */
3498 /* FIXME: should we read past newlines and formfeeds??? */
3499 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3502 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3503 name
[0] = tolower ((*str
)[0]),
3505 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3506 name
[0] = tolower ((*str
)[0]),
3507 name
[1] = tolower ((*str
)[1]),
3513 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3517 middle
= (low
+ high
) / 2;
3518 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3525 *str
+= strlen (name
) + 1;
3526 return selector_table
[middle
].field_selector
;
3529 while (low
<= high
);
3534 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3537 get_expression (str
)
3543 save_in
= input_line_pointer
;
3544 input_line_pointer
= str
;
3545 seg
= expression (&the_insn
.exp
);
3546 if (!(seg
== absolute_section
3547 || seg
== undefined_section
3548 || SEG_NORMAL (seg
)))
3550 as_warn ("Bad segment in expression.");
3551 expr_end
= input_line_pointer
;
3552 input_line_pointer
= save_in
;
3555 expr_end
= input_line_pointer
;
3556 input_line_pointer
= save_in
;
3560 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3562 pa_get_absolute_expression (insn
, strp
)
3568 insn
->field_selector
= pa_chk_field_selector (strp
);
3569 save_in
= input_line_pointer
;
3570 input_line_pointer
= *strp
;
3571 expression (&insn
->exp
);
3572 if (insn
->exp
.X_op
!= O_constant
)
3574 as_bad ("Bad segment (should be absolute).");
3575 expr_end
= input_line_pointer
;
3576 input_line_pointer
= save_in
;
3579 expr_end
= input_line_pointer
;
3580 input_line_pointer
= save_in
;
3581 return evaluate_absolute (insn
);
3584 /* Evaluate an absolute expression EXP which may be modified by
3585 the selector FIELD_SELECTOR. Return the value of the expression. */
3587 evaluate_absolute (insn
)
3592 int field_selector
= insn
->field_selector
;
3595 value
= exp
.X_add_number
;
3597 switch (field_selector
)
3603 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3605 if (value
& 0x00000400)
3607 value
= (value
& 0xfffff800) >> 11;
3610 /* Sign extend from bit 21. */
3612 if (value
& 0x00000400)
3613 value
|= 0xfffff800;
3618 /* Arithmetic shift right 11 bits. */
3620 value
= (value
& 0xfffff800) >> 11;
3623 /* Set bits 0-20 to zero. */
3625 value
= value
& 0x7ff;
3628 /* Add 0x800 and arithmetic shift right 11 bits. */
3631 value
= (value
& 0xfffff800) >> 11;
3634 /* Set bitgs 0-21 to one. */
3636 value
|= 0xfffff800;
3639 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3641 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3645 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3650 BAD_CASE (field_selector
);
3656 /* Given an argument location specification return the associated
3657 argument location number. */
3660 pa_build_arg_reloc (type_name
)
3664 if (strncasecmp (type_name
, "no", 2) == 0)
3666 if (strncasecmp (type_name
, "gr", 2) == 0)
3668 else if (strncasecmp (type_name
, "fr", 2) == 0)
3670 else if (strncasecmp (type_name
, "fu", 2) == 0)
3673 as_bad ("Invalid argument location: %s\n", type_name
);
3678 /* Encode and return an argument relocation specification for
3679 the given register in the location specified by arg_reloc. */
3682 pa_align_arg_reloc (reg
, arg_reloc
)
3684 unsigned int arg_reloc
;
3686 unsigned int new_reloc
;
3688 new_reloc
= arg_reloc
;
3704 as_bad ("Invalid argument description: %d", reg
);
3710 /* Parse a PA nullification completer (,n). Return nonzero if the
3711 completer was found; return zero if no completer was found. */
3723 if (strncasecmp (*s
, "n", 1) == 0)
3727 as_bad ("Invalid Nullification: (%c)", **s
);
3736 /* Parse a non-negated compare/subtract completer returning the
3737 number (for encoding in instrutions) of the given completer.
3739 ISBRANCH specifies whether or not this is parsing a condition
3740 completer for a branch (vs a nullification completer for a
3741 computational instruction. */
3744 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3749 char *name
= *s
+ 1;
3757 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3761 if (strcmp (name
, "=") == 0)
3765 else if (strcmp (name
, "<") == 0)
3769 else if (strcmp (name
, "<=") == 0)
3773 else if (strcmp (name
, "<<") == 0)
3777 else if (strcmp (name
, "<<=") == 0)
3781 else if (strcasecmp (name
, "sv") == 0)
3785 else if (strcasecmp (name
, "od") == 0)
3789 /* If we have something like addb,n then there is no condition
3791 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3802 /* Reset pointers if this was really a ,n for a branch instruction. */
3803 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3809 /* Parse a negated compare/subtract completer returning the
3810 number (for encoding in instrutions) of the given completer.
3812 ISBRANCH specifies whether or not this is parsing a condition
3813 completer for a branch (vs a nullification completer for a
3814 computational instruction. */
3817 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3822 char *name
= *s
+ 1;
3830 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3834 if (strcasecmp (name
, "tr") == 0)
3838 else if (strcmp (name
, "<>") == 0)
3842 else if (strcmp (name
, ">=") == 0)
3846 else if (strcmp (name
, ">") == 0)
3850 else if (strcmp (name
, ">>=") == 0)
3854 else if (strcmp (name
, ">>") == 0)
3858 else if (strcasecmp (name
, "nsv") == 0)
3862 else if (strcasecmp (name
, "ev") == 0)
3866 /* If we have something like addb,n then there is no condition
3868 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3879 /* Reset pointers if this was really a ,n for a branch instruction. */
3880 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3886 /* Parse a non-negated addition completer returning the number
3887 (for encoding in instrutions) of the given completer.
3889 ISBRANCH specifies whether or not this is parsing a condition
3890 completer for a branch (vs a nullification completer for a
3891 computational instruction. */
3894 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3899 char *name
= *s
+ 1;
3907 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3911 if (strcmp (name
, "=") == 0)
3915 else if (strcmp (name
, "<") == 0)
3919 else if (strcmp (name
, "<=") == 0)
3923 else if (strcasecmp (name
, "nuv") == 0)
3927 else if (strcasecmp (name
, "znv") == 0)
3931 else if (strcasecmp (name
, "sv") == 0)
3935 else if (strcasecmp (name
, "od") == 0)
3939 /* If we have something like addb,n then there is no condition
3941 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3952 /* Reset pointers if this was really a ,n for a branch instruction. */
3953 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3959 /* Parse a negated addition completer returning the number
3960 (for encoding in instrutions) of the given completer.
3962 ISBRANCH specifies whether or not this is parsing a condition
3963 completer for a branch (vs a nullification completer for a
3964 computational instruction. */
3967 pa_parse_neg_add_cmpltr (s
, isbranch
)
3972 char *name
= *s
+ 1;
3980 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3984 if (strcasecmp (name
, "tr") == 0)
3988 else if (strcmp (name
, "<>") == 0)
3992 else if (strcmp (name
, ">=") == 0)
3996 else if (strcmp (name
, ">") == 0)
4000 else if (strcasecmp (name
, "uv") == 0)
4004 else if (strcasecmp (name
, "vnz") == 0)
4008 else if (strcasecmp (name
, "nsv") == 0)
4012 else if (strcasecmp (name
, "ev") == 0)
4016 /* If we have something like addb,n then there is no condition
4018 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4029 /* Reset pointers if this was really a ,n for a branch instruction. */
4030 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4036 /* Handle a .BLOCK type pseudo-op. */
4044 unsigned int temp_size
;
4047 temp_size
= get_absolute_expression ();
4049 /* Always fill with zeros, that's what the HP assembler does. */
4052 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4053 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4054 bzero (p
, temp_size
);
4056 /* Convert 2 bytes at a time. */
4058 for (i
= 0; i
< temp_size
; i
+= 2)
4060 md_number_to_chars (p
+ i
,
4062 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4065 pa_undefine_label ();
4066 demand_empty_rest_of_line ();
4069 /* Handle a .CALL pseudo-op. This involves storing away information
4070 about where arguments are to be found so the linker can detect
4071 (and correct) argument location mismatches between caller and callee. */
4077 pa_call_args (&last_call_desc
);
4078 demand_empty_rest_of_line ();
4081 /* Do the dirty work of building a call descriptor which describes
4082 where the caller placed arguments to a function call. */
4085 pa_call_args (call_desc
)
4086 struct call_desc
*call_desc
;
4089 unsigned int temp
, arg_reloc
;
4091 while (!is_end_of_statement ())
4093 name
= input_line_pointer
;
4094 c
= get_symbol_end ();
4095 /* Process a source argument. */
4096 if ((strncasecmp (name
, "argw", 4) == 0))
4098 temp
= atoi (name
+ 4);
4099 p
= input_line_pointer
;
4101 input_line_pointer
++;
4102 name
= input_line_pointer
;
4103 c
= get_symbol_end ();
4104 arg_reloc
= pa_build_arg_reloc (name
);
4105 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4107 /* Process a return value. */
4108 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4110 p
= input_line_pointer
;
4112 input_line_pointer
++;
4113 name
= input_line_pointer
;
4114 c
= get_symbol_end ();
4115 arg_reloc
= pa_build_arg_reloc (name
);
4116 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4120 as_bad ("Invalid .CALL argument: %s", name
);
4122 p
= input_line_pointer
;
4124 if (!is_end_of_statement ())
4125 input_line_pointer
++;
4129 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4132 is_same_frag (frag1
, frag2
)
4139 else if (frag2
== NULL
)
4141 else if (frag1
== frag2
)
4143 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4144 return (is_same_frag (frag1
, frag2
->fr_next
));
4150 /* Build an entry in the UNWIND subspace from the given function
4151 attributes in CALL_INFO. This is not needed for SOM as using
4152 R_ENTRY and R_EXIT relocations allow the linker to handle building
4153 of the unwind spaces. */
4156 pa_build_unwind_subspace (call_info
)
4157 struct call_info
*call_info
;
4160 asection
*seg
, *save_seg
;
4161 subsegT subseg
, save_subseg
;
4165 /* Get into the right seg/subseg. This may involve creating
4166 the seg the first time through. Make sure to have the
4167 old seg/subseg so that we can reset things when we are done. */
4168 subseg
= SUBSEG_UNWIND
;
4169 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4170 if (seg
== ASEC_NULL
)
4172 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4173 bfd_set_section_flags (stdoutput
, seg
,
4174 SEC_READONLY
| SEC_HAS_CONTENTS
4175 | SEC_LOAD
| SEC_RELOC
);
4179 save_subseg
= now_subseg
;
4180 subseg_set (seg
, subseg
);
4183 /* Get some space to hold relocation information for the unwind
4187 /* Relocation info. for start offset of the function. */
4188 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4189 call_info
->start_symbol
, (offsetT
) 0,
4190 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4195 /* Relocation info. for end offset of the function. */
4196 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4197 call_info
->end_symbol
, (offsetT
) 0,
4198 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4202 unwind
= (char *) &call_info
->ci_unwind
;
4203 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4207 FRAG_APPEND_1_CHAR (c
);
4211 /* Return back to the original segment/subsegment. */
4212 subseg_set (save_seg
, save_subseg
);
4216 /* Process a .CALLINFO pseudo-op. This information is used later
4217 to build unwind descriptors and maybe one day to support
4218 .ENTER and .LEAVE. */
4221 pa_callinfo (unused
)
4227 /* .CALLINFO must appear within a procedure definition. */
4228 if (!within_procedure
)
4229 as_bad (".callinfo is not within a procedure definition");
4231 /* Mark the fact that we found the .CALLINFO for the
4232 current procedure. */
4233 callinfo_found
= TRUE
;
4235 /* Iterate over the .CALLINFO arguments. */
4236 while (!is_end_of_statement ())
4238 name
= input_line_pointer
;
4239 c
= get_symbol_end ();
4240 /* Frame size specification. */
4241 if ((strncasecmp (name
, "frame", 5) == 0))
4243 p
= input_line_pointer
;
4245 input_line_pointer
++;
4246 temp
= get_absolute_expression ();
4247 if ((temp
& 0x3) != 0)
4249 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4253 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4254 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4257 /* Entry register (GR, GR and SR) specifications. */
4258 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4260 p
= input_line_pointer
;
4262 input_line_pointer
++;
4263 temp
= get_absolute_expression ();
4264 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4265 even though %r19 is caller saved. I think this is a bug in
4266 the HP assembler, and we are not going to emulate it. */
4267 if (temp
< 3 || temp
> 18)
4268 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4269 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4271 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4273 p
= input_line_pointer
;
4275 input_line_pointer
++;
4276 temp
= get_absolute_expression ();
4277 /* Similarly the HP assembler takes 31 as the high bound even
4278 though %fr21 is the last callee saved floating point register. */
4279 if (temp
< 12 || temp
> 21)
4280 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4281 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4283 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4285 p
= input_line_pointer
;
4287 input_line_pointer
++;
4288 temp
= get_absolute_expression ();
4290 as_bad ("Value for ENTRY_SR must be 3\n");
4292 /* Note whether or not this function performs any calls. */
4293 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4294 (strncasecmp (name
, "caller", 6) == 0))
4296 p
= input_line_pointer
;
4299 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4301 p
= input_line_pointer
;
4304 /* Should RP be saved into the stack. */
4305 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4307 p
= input_line_pointer
;
4309 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4311 /* Likewise for SP. */
4312 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4314 p
= input_line_pointer
;
4316 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4318 /* Is this an unwindable procedure. If so mark it so
4319 in the unwind descriptor. */
4320 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4322 p
= input_line_pointer
;
4324 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4326 /* Is this an interrupt routine. If so mark it in the
4327 unwind descriptor. */
4328 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4330 p
= input_line_pointer
;
4332 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4334 /* Is this a millicode routine. "millicode" isn't in my
4335 assembler manual, but my copy is old. The HP assembler
4336 accepts it, and there's a place in the unwind descriptor
4337 to drop the information, so we'll accept it too. */
4338 else if ((strncasecmp (name
, "millicode", 9) == 0))
4340 p
= input_line_pointer
;
4342 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4346 as_bad ("Invalid .CALLINFO argument: %s", name
);
4347 *input_line_pointer
= c
;
4349 if (!is_end_of_statement ())
4350 input_line_pointer
++;
4353 demand_empty_rest_of_line ();
4356 /* Switch into the code subspace. */
4362 sd_chain_struct
*sdchain
;
4364 /* First time through it might be necessary to create the
4366 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4368 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4369 pa_def_spaces
[0].spnum
,
4370 pa_def_spaces
[0].loadable
,
4371 pa_def_spaces
[0].defined
,
4372 pa_def_spaces
[0].private,
4373 pa_def_spaces
[0].sort
,
4374 pa_def_spaces
[0].segment
, 0);
4377 SPACE_DEFINED (sdchain
) = 1;
4378 subseg_set (text_section
, SUBSEG_CODE
);
4379 demand_empty_rest_of_line ();
4382 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4383 the .comm pseudo-op has the following symtax:
4385 <label> .comm <length>
4387 where <label> is optional and is a symbol whose address will be the start of
4388 a block of memory <length> bytes long. <length> must be an absolute
4389 expression. <length> bytes will be allocated in the current space
4398 label_symbol_struct
*label_symbol
= pa_get_label ();
4401 symbol
= label_symbol
->lss_label
;
4406 size
= get_absolute_expression ();
4410 /* It is incorrect to check S_IS_DEFINED at this point as
4411 the symbol will *always* be defined. FIXME. How to
4412 correctly determine when this label really as been
4414 if (S_GET_VALUE (symbol
))
4416 if (S_GET_VALUE (symbol
) != size
)
4418 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4419 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4425 S_SET_VALUE (symbol
, size
);
4426 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4427 S_SET_EXTERNAL (symbol
);
4430 demand_empty_rest_of_line ();
4433 /* Process a .END pseudo-op. */
4439 demand_empty_rest_of_line ();
4442 /* Process a .ENTER pseudo-op. This is not supported. */
4450 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4456 if (!within_procedure
)
4457 as_bad ("Misplaced .entry. Ignored.");
4460 if (!callinfo_found
)
4461 as_bad ("Missing .callinfo.");
4463 demand_empty_rest_of_line ();
4464 within_entry_exit
= TRUE
;
4467 /* SOM defers building of unwind descriptors until the link phase.
4468 The assembler is responsible for creating an R_ENTRY relocation
4469 to mark the beginning of a region and hold the unwind bits, and
4470 for creating an R_EXIT relocation to mark the end of the region.
4472 FIXME. ELF should be using the same conventions! The problem
4473 is an unwind requires too much relocation space. Hmmm. Maybe
4474 if we split the unwind bits up between the relocations which
4475 denote the entry and exit points. */
4476 if (last_call_info
->start_symbol
!= NULL
)
4478 char *where
= frag_more (0);
4480 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4481 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4482 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4483 (char *) &last_call_info
->ci_unwind
.descriptor
);
4488 /* Handle a .EQU pseudo-op. */
4494 label_symbol_struct
*label_symbol
= pa_get_label ();
4499 symbol
= label_symbol
->lss_label
;
4501 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4503 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4504 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4509 as_bad (".REG must use a label");
4511 as_bad (".EQU must use a label");
4514 pa_undefine_label ();
4515 demand_empty_rest_of_line ();
4518 /* Helper function. Does processing for the end of a function. This
4519 usually involves creating some relocations or building special
4520 symbols to mark the end of the function. */
4527 where
= frag_more (0);
4530 /* Mark the end of the function, stuff away the location of the frag
4531 for the end of the function, and finally call pa_build_unwind_subspace
4532 to add an entry in the unwind table. */
4533 hppa_elf_mark_end_of_function ();
4534 pa_build_unwind_subspace (last_call_info
);
4536 /* SOM defers building of unwind descriptors until the link phase.
4537 The assembler is responsible for creating an R_ENTRY relocation
4538 to mark the beginning of a region and hold the unwind bits, and
4539 for creating an R_EXIT relocation to mark the end of the region.
4541 FIXME. ELF should be using the same conventions! The problem
4542 is an unwind requires too much relocation space. Hmmm. Maybe
4543 if we split the unwind bits up between the relocations which
4544 denote the entry and exit points. */
4545 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4546 last_call_info
->start_symbol
, (offsetT
) 0,
4547 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4551 /* Process a .EXIT pseudo-op. */
4557 if (!within_procedure
)
4558 as_bad (".EXIT must appear within a procedure");
4561 if (!callinfo_found
)
4562 as_bad ("Missing .callinfo");
4565 if (!within_entry_exit
)
4566 as_bad ("No .ENTRY for this .EXIT");
4569 within_entry_exit
= FALSE
;
4574 demand_empty_rest_of_line ();
4577 /* Process a .EXPORT directive. This makes functions external
4578 and provides information such as argument relocation entries
4588 name
= input_line_pointer
;
4589 c
= get_symbol_end ();
4590 /* Make sure the given symbol exists. */
4591 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4593 as_bad ("Cannot define export symbol: %s\n", name
);
4594 p
= input_line_pointer
;
4596 input_line_pointer
++;
4600 /* OK. Set the external bits and process argument relocations. */
4601 S_SET_EXTERNAL (symbol
);
4602 p
= input_line_pointer
;
4604 if (!is_end_of_statement ())
4606 input_line_pointer
++;
4607 pa_type_args (symbol
, 1);
4611 demand_empty_rest_of_line ();
4614 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4617 pa_type_args (symbolP
, is_export
)
4622 unsigned int temp
, arg_reloc
;
4623 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4624 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4626 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4629 input_line_pointer
+= 8;
4630 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4631 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4632 type
= SYMBOL_TYPE_ABSOLUTE
;
4634 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4636 input_line_pointer
+= 4;
4637 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4638 instead one should be IMPORTing/EXPORTing ENTRY types.
4640 Complain if one tries to EXPORT a CODE type since that's never
4641 done. Both GCC and HP C still try to IMPORT CODE types, so
4642 silently fix them to be ENTRY types. */
4643 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4646 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4648 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4649 type
= SYMBOL_TYPE_ENTRY
;
4653 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4654 type
= SYMBOL_TYPE_CODE
;
4657 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4659 input_line_pointer
+= 4;
4660 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4661 type
= SYMBOL_TYPE_DATA
;
4663 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4665 input_line_pointer
+= 5;
4666 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4667 type
= SYMBOL_TYPE_ENTRY
;
4669 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4671 input_line_pointer
+= 9;
4672 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4673 type
= SYMBOL_TYPE_MILLICODE
;
4675 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4677 input_line_pointer
+= 6;
4678 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4679 type
= SYMBOL_TYPE_PLABEL
;
4681 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4683 input_line_pointer
+= 8;
4684 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4685 type
= SYMBOL_TYPE_PRI_PROG
;
4687 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4689 input_line_pointer
+= 8;
4690 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4691 type
= SYMBOL_TYPE_SEC_PROG
;
4694 /* SOM requires much more information about symbol types
4695 than BFD understands. This is how we get this information
4696 to the SOM BFD backend. */
4697 #ifdef obj_set_symbol_type
4698 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4701 /* Now that the type of the exported symbol has been handled,
4702 handle any argument relocation information. */
4703 while (!is_end_of_statement ())
4705 if (*input_line_pointer
== ',')
4706 input_line_pointer
++;
4707 name
= input_line_pointer
;
4708 c
= get_symbol_end ();
4709 /* Argument sources. */
4710 if ((strncasecmp (name
, "argw", 4) == 0))
4712 p
= input_line_pointer
;
4714 input_line_pointer
++;
4715 temp
= atoi (name
+ 4);
4716 name
= input_line_pointer
;
4717 c
= get_symbol_end ();
4718 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4719 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4720 *input_line_pointer
= c
;
4722 /* The return value. */
4723 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4725 p
= input_line_pointer
;
4727 input_line_pointer
++;
4728 name
= input_line_pointer
;
4729 c
= get_symbol_end ();
4730 arg_reloc
= pa_build_arg_reloc (name
);
4731 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4732 *input_line_pointer
= c
;
4734 /* Privelege level. */
4735 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4737 p
= input_line_pointer
;
4739 input_line_pointer
++;
4740 temp
= atoi (input_line_pointer
);
4741 c
= get_symbol_end ();
4742 *input_line_pointer
= c
;
4746 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4747 p
= input_line_pointer
;
4750 if (!is_end_of_statement ())
4751 input_line_pointer
++;
4755 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4756 assembly file must either be defined in the assembly file, or
4757 explicitly IMPORTED from another. */
4766 name
= input_line_pointer
;
4767 c
= get_symbol_end ();
4769 symbol
= symbol_find (name
);
4770 /* Ugh. We might be importing a symbol defined earlier in the file,
4771 in which case all the code below will really screw things up
4772 (set the wrong segment, symbol flags & type, etc). */
4773 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4775 symbol
= symbol_find_or_make (name
);
4776 p
= input_line_pointer
;
4779 if (!is_end_of_statement ())
4781 input_line_pointer
++;
4782 pa_type_args (symbol
, 0);
4786 /* Sigh. To be compatable with the HP assembler and to help
4787 poorly written assembly code, we assign a type based on
4788 the the current segment. Note only BSF_FUNCTION really
4789 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4790 if (now_seg
== text_section
)
4791 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4793 /* If the section is undefined, then the symbol is undefined
4794 Since this is an import, leave the section undefined. */
4795 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4800 /* The symbol was already defined. Just eat everything up to
4801 the end of the current statement. */
4802 while (!is_end_of_statement ())
4803 input_line_pointer
++;
4806 demand_empty_rest_of_line ();
4809 /* Handle a .LABEL pseudo-op. */
4817 name
= input_line_pointer
;
4818 c
= get_symbol_end ();
4820 if (strlen (name
) > 0)
4823 p
= input_line_pointer
;
4828 as_warn ("Missing label name on .LABEL");
4831 if (!is_end_of_statement ())
4833 as_warn ("extra .LABEL arguments ignored.");
4834 ignore_rest_of_line ();
4836 demand_empty_rest_of_line ();
4839 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4848 /* Handle a .ORIGIN pseudo-op. */
4855 pa_undefine_label ();
4858 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4859 is for static functions. FIXME. Should share more code with .EXPORT. */
4868 name
= input_line_pointer
;
4869 c
= get_symbol_end ();
4871 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4873 as_bad ("Cannot define static symbol: %s\n", name
);
4874 p
= input_line_pointer
;
4876 input_line_pointer
++;
4880 S_CLEAR_EXTERNAL (symbol
);
4881 p
= input_line_pointer
;
4883 if (!is_end_of_statement ())
4885 input_line_pointer
++;
4886 pa_type_args (symbol
, 0);
4890 demand_empty_rest_of_line ();
4893 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4894 of a procedure from a syntatical point of view. */
4900 struct call_info
*call_info
;
4903 if (within_procedure
)
4904 as_fatal ("Nested procedures");
4906 /* Reset global variables for new procedure. */
4907 callinfo_found
= FALSE
;
4908 within_procedure
= TRUE
;
4911 Enabling
this code creates severe problems with GDB
. It appears as
if
4912 inserting linker stubs between functions within a single
.o makes GDB
4915 /* Create a new CODE subspace for each procedure if we are not
4916 using space/subspace aliases. */
4917 if (!USE_ALIASES
&& call_info_root
!= NULL
)
4919 /* Force creation of a new $CODE$ subspace; inherit attributes from
4920 the first $CODE$ subspace. */
4921 seg
= subseg_force_new ("$CODE$", 0);
4923 /* Now set the flags. */
4924 bfd_set_section_flags (stdoutput
, seg
,
4925 bfd_get_section_flags (abfd
, text_section
));
4927 /* Record any alignment request for this section. */
4928 record_alignment (seg
,
4929 bfd_get_section_alignment (stdoutput
, text_section
));
4931 /* Change the "text_section" to be our new $CODE$ subspace. */
4933 subseg_set (text_section
, 0);
4935 #ifdef obj_set_subsection_attributes
4936 /* Need a way to inherit the the access bits, sort key and quadrant
4937 from the first $CODE$ subspace. FIXME. */
4938 obj_set_subsection_attributes (seg
, current_space
->sd_seg
, 0x2c, 24, 0);
4943 /* Create another call_info structure. */
4944 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4947 as_fatal ("Cannot allocate unwind descriptor\n");
4949 bzero (call_info
, sizeof (struct call_info
));
4951 call_info
->ci_next
= NULL
;
4953 if (call_info_root
== NULL
)
4955 call_info_root
= call_info
;
4956 last_call_info
= call_info
;
4960 last_call_info
->ci_next
= call_info
;
4961 last_call_info
= call_info
;
4964 /* set up defaults on call_info structure */
4966 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4967 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4968 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4970 /* If we got a .PROC pseudo-op, we know that the function is defined
4971 locally. Make sure it gets into the symbol table. */
4973 label_symbol_struct
*label_symbol
= pa_get_label ();
4977 if (label_symbol
->lss_label
)
4979 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4980 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4984 /* The label was defined in a different segment. Fix that
4985 along with the value and associated fragment. */
4986 S_SET_SEGMENT (last_call_info
->start_symbol
, now_seg
);
4987 S_SET_VALUE (last_call_info
->start_symbol
,
4988 ((char*)obstack_next_free (&frags
)
4989 - frag_now
->fr_literal
));
4990 last_call_info
->start_symbol
->sy_frag
= frag_now
;
4995 as_bad ("Missing function name for .PROC (corrupted label chain)");
4998 last_call_info
->start_symbol
= NULL
;
5001 demand_empty_rest_of_line ();
5004 /* Process the syntatical end of a procedure. Make sure all the
5005 appropriate pseudo-ops were found within the procedure. */
5012 if (!within_procedure
)
5013 as_bad ("misplaced .procend");
5015 if (!callinfo_found
)
5016 as_bad ("Missing .callinfo for this procedure");
5018 if (within_entry_exit
)
5019 as_bad ("Missing .EXIT for a .ENTRY");
5022 /* ELF needs to mark the end of each function so that it can compute
5023 the size of the function (apparently its needed in the symbol table. */
5024 hppa_elf_mark_end_of_function ();
5027 within_procedure
= FALSE
;
5028 demand_empty_rest_of_line ();
5029 pa_undefine_label ();
5032 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5033 then create a new space entry to hold the information specified
5034 by the parameters to the .SPACE directive. */
5036 static sd_chain_struct
*
5037 pa_parse_space_stmt (space_name
, create_flag
)
5041 char *name
, *ptemp
, c
;
5042 char loadable
, defined
, private, sort
;
5044 asection
*seg
= NULL
;
5045 sd_chain_struct
*space
;
5047 /* load default values */
5053 if (strcmp (space_name
, "$TEXT$") == 0)
5055 seg
= pa_def_spaces
[0].segment
;
5056 sort
= pa_def_spaces
[0].sort
;
5058 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5060 seg
= pa_def_spaces
[1].segment
;
5061 sort
= pa_def_spaces
[1].sort
;
5064 if (!is_end_of_statement ())
5066 print_errors
= FALSE
;
5067 ptemp
= input_line_pointer
+ 1;
5068 /* First see if the space was specified as a number rather than
5069 as a name. According to the PA assembly manual the rest of
5070 the line should be ignored. */
5071 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5072 input_line_pointer
= ptemp
;
5075 while (!is_end_of_statement ())
5077 input_line_pointer
++;
5078 name
= input_line_pointer
;
5079 c
= get_symbol_end ();
5080 if ((strncasecmp (name
, "spnum", 5) == 0))
5082 *input_line_pointer
= c
;
5083 input_line_pointer
++;
5084 spnum
= get_absolute_expression ();
5086 else if ((strncasecmp (name
, "sort", 4) == 0))
5088 *input_line_pointer
= c
;
5089 input_line_pointer
++;
5090 sort
= get_absolute_expression ();
5092 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5094 *input_line_pointer
= c
;
5097 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5099 *input_line_pointer
= c
;
5102 else if ((strncasecmp (name
, "private", 7) == 0))
5104 *input_line_pointer
= c
;
5109 as_bad ("Invalid .SPACE argument");
5110 *input_line_pointer
= c
;
5111 if (!is_end_of_statement ())
5112 input_line_pointer
++;
5116 print_errors
= TRUE
;
5119 if (create_flag
&& seg
== NULL
)
5120 seg
= subseg_new (space_name
, 0);
5122 /* If create_flag is nonzero, then create the new space with
5123 the attributes computed above. Else set the values in
5124 an already existing space -- this can only happen for
5125 the first occurence of a built-in space. */
5127 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5128 private, sort
, seg
, 1);
5131 space
= is_defined_space (space_name
);
5132 SPACE_SPNUM (space
) = spnum
;
5133 SPACE_DEFINED (space
) = defined
& 1;
5134 SPACE_USER_DEFINED (space
) = 1;
5135 space
->sd_seg
= seg
;
5138 #ifdef obj_set_section_attributes
5139 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5145 /* Handle a .SPACE pseudo-op; this switches the current space to the
5146 given space, creating the new space if necessary. */
5152 char *name
, c
, *space_name
, *save_s
;
5154 sd_chain_struct
*sd_chain
;
5156 if (within_procedure
)
5158 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5159 ignore_rest_of_line ();
5163 /* Check for some of the predefined spaces. FIXME: most of the code
5164 below is repeated several times, can we extract the common parts
5165 and place them into a subroutine or something similar? */
5166 /* FIXME Is this (and the next IF stmt) really right?
5167 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5168 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5170 input_line_pointer
+= 6;
5171 sd_chain
= is_defined_space ("$TEXT$");
5172 if (sd_chain
== NULL
)
5173 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5174 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5175 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5177 current_space
= sd_chain
;
5178 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5180 = pa_subsegment_to_subspace (text_section
,
5181 sd_chain
->sd_last_subseg
);
5182 demand_empty_rest_of_line ();
5185 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5187 input_line_pointer
+= 9;
5188 sd_chain
= is_defined_space ("$PRIVATE$");
5189 if (sd_chain
== NULL
)
5190 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5191 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5192 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5194 current_space
= sd_chain
;
5195 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5197 = pa_subsegment_to_subspace (data_section
,
5198 sd_chain
->sd_last_subseg
);
5199 demand_empty_rest_of_line ();
5202 if (!strncasecmp (input_line_pointer
,
5203 GDB_DEBUG_SPACE_NAME
,
5204 strlen (GDB_DEBUG_SPACE_NAME
)))
5206 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5207 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5208 if (sd_chain
== NULL
)
5209 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5210 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5211 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5213 current_space
= sd_chain
;
5216 asection
*gdb_section
5217 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5219 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5221 = pa_subsegment_to_subspace (gdb_section
,
5222 sd_chain
->sd_last_subseg
);
5224 demand_empty_rest_of_line ();
5228 /* It could be a space specified by number. */
5230 save_s
= input_line_pointer
;
5231 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5233 if (sd_chain
= pa_find_space_by_number (temp
))
5235 current_space
= sd_chain
;
5237 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5239 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5240 sd_chain
->sd_last_subseg
);
5241 demand_empty_rest_of_line ();
5246 /* Not a number, attempt to create a new space. */
5248 input_line_pointer
= save_s
;
5249 name
= input_line_pointer
;
5250 c
= get_symbol_end ();
5251 space_name
= xmalloc (strlen (name
) + 1);
5252 strcpy (space_name
, name
);
5253 *input_line_pointer
= c
;
5255 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5256 current_space
= sd_chain
;
5258 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5259 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5260 sd_chain
->sd_last_subseg
);
5261 demand_empty_rest_of_line ();
5265 /* Switch to a new space. (I think). FIXME. */
5274 sd_chain_struct
*space
;
5276 name
= input_line_pointer
;
5277 c
= get_symbol_end ();
5278 space
= is_defined_space (name
);
5282 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5285 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5287 *input_line_pointer
= c
;
5288 demand_empty_rest_of_line ();
5291 /* If VALUE is an exact power of two between zero and 2^31, then
5292 return log2 (VALUE). Else return -1. */
5300 while ((1 << shift
) != value
&& shift
< 32)
5309 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5310 given subspace, creating the new subspace if necessary.
5312 FIXME. Should mirror pa_space more closely, in particular how
5313 they're broken up into subroutines. */
5316 pa_subspace (unused
)
5319 char *name
, *ss_name
, *alias
, c
;
5320 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5321 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5322 sd_chain_struct
*space
;
5323 ssd_chain_struct
*ssd
;
5326 if (within_procedure
)
5328 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5329 ignore_rest_of_line ();
5333 name
= input_line_pointer
;
5334 c
= get_symbol_end ();
5335 ss_name
= xmalloc (strlen (name
) + 1);
5336 strcpy (ss_name
, name
);
5337 *input_line_pointer
= c
;
5339 /* Load default values. */
5352 space
= current_space
;
5353 ssd
= is_defined_subspace (ss_name
);
5354 /* Allow user to override the builtin attributes of subspaces. But
5355 only allow the attributes to be changed once! */
5356 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5358 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5359 if (!is_end_of_statement ())
5360 as_warn ("Parameters of an existing subspace can\'t be modified");
5361 demand_empty_rest_of_line ();
5366 /* A new subspace. Load default values if it matches one of
5367 the builtin subspaces. */
5369 while (pa_def_subspaces
[i
].name
)
5371 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5373 loadable
= pa_def_subspaces
[i
].loadable
;
5374 common
= pa_def_subspaces
[i
].common
;
5375 dup_common
= pa_def_subspaces
[i
].dup_common
;
5376 code_only
= pa_def_subspaces
[i
].code_only
;
5377 zero
= pa_def_subspaces
[i
].zero
;
5378 space_index
= pa_def_subspaces
[i
].space_index
;
5379 alignment
= pa_def_subspaces
[i
].alignment
;
5380 quadrant
= pa_def_subspaces
[i
].quadrant
;
5381 access
= pa_def_subspaces
[i
].access
;
5382 sort
= pa_def_subspaces
[i
].sort
;
5383 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5384 alias
= pa_def_subspaces
[i
].alias
;
5391 /* We should be working with a new subspace now. Fill in
5392 any information as specified by the user. */
5393 if (!is_end_of_statement ())
5395 input_line_pointer
++;
5396 while (!is_end_of_statement ())
5398 name
= input_line_pointer
;
5399 c
= get_symbol_end ();
5400 if ((strncasecmp (name
, "quad", 4) == 0))
5402 *input_line_pointer
= c
;
5403 input_line_pointer
++;
5404 quadrant
= get_absolute_expression ();
5406 else if ((strncasecmp (name
, "align", 5) == 0))
5408 *input_line_pointer
= c
;
5409 input_line_pointer
++;
5410 alignment
= get_absolute_expression ();
5411 if (log2 (alignment
) == -1)
5413 as_bad ("Alignment must be a power of 2");
5417 else if ((strncasecmp (name
, "access", 6) == 0))
5419 *input_line_pointer
= c
;
5420 input_line_pointer
++;
5421 access
= get_absolute_expression ();
5423 else if ((strncasecmp (name
, "sort", 4) == 0))
5425 *input_line_pointer
= c
;
5426 input_line_pointer
++;
5427 sort
= get_absolute_expression ();
5429 else if ((strncasecmp (name
, "code_only", 9) == 0))
5431 *input_line_pointer
= c
;
5434 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5436 *input_line_pointer
= c
;
5439 else if ((strncasecmp (name
, "common", 6) == 0))
5441 *input_line_pointer
= c
;
5444 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5446 *input_line_pointer
= c
;
5449 else if ((strncasecmp (name
, "zero", 4) == 0))
5451 *input_line_pointer
= c
;
5454 else if ((strncasecmp (name
, "first", 5) == 0))
5455 as_bad ("FIRST not supported as a .SUBSPACE argument");
5457 as_bad ("Invalid .SUBSPACE argument");
5458 if (!is_end_of_statement ())
5459 input_line_pointer
++;
5463 /* Compute a reasonable set of BFD flags based on the information
5464 in the .subspace directive. */
5465 applicable
= bfd_applicable_section_flags (stdoutput
);
5468 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5471 if (common
|| dup_common
)
5472 flags
|= SEC_IS_COMMON
;
5474 /* This is a zero-filled subspace (eg BSS). */
5478 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5479 applicable
&= flags
;
5481 /* If this is an existing subspace, then we want to use the
5482 segment already associated with the subspace.
5484 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5485 lots of sections. It might be a problem in the PA ELF
5486 code, I do not know yet. For now avoid creating anything
5487 but the "standard" sections for ELF. */
5489 section
= ssd
->ssd_seg
;
5491 section
= subseg_new (alias
, 0);
5492 else if (!alias
&& USE_ALIASES
)
5494 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5495 demand_empty_rest_of_line ();
5499 section
= subseg_new (ss_name
, 0);
5501 /* Now set the flags. */
5502 bfd_set_section_flags (stdoutput
, section
, applicable
);
5504 /* Record any alignment request for this section. */
5505 record_alignment (section
, log2 (alignment
));
5507 /* Set the starting offset for this section. */
5508 bfd_set_section_vma (stdoutput
, section
,
5509 pa_subspace_start (space
, quadrant
));
5511 /* Now that all the flags are set, update an existing subspace,
5512 or create a new one. */
5515 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5516 code_only
, common
, dup_common
,
5517 sort
, zero
, access
, space_index
,
5518 alignment
, quadrant
,
5521 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5523 dup_common
, zero
, sort
,
5524 access
, space_index
,
5525 alignment
, quadrant
, section
);
5527 demand_empty_rest_of_line ();
5528 current_subspace
->ssd_seg
= section
;
5529 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5531 SUBSPACE_DEFINED (current_subspace
) = 1;
5535 /* Create default space and subspace dictionaries. */
5542 space_dict_root
= NULL
;
5543 space_dict_last
= NULL
;
5546 while (pa_def_spaces
[i
].name
)
5550 /* Pick the right name to use for the new section. */
5551 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5552 name
= pa_def_spaces
[i
].alias
;
5554 name
= pa_def_spaces
[i
].name
;
5556 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5557 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5558 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5559 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5560 pa_def_spaces
[i
].segment
, 0);
5565 while (pa_def_subspaces
[i
].name
)
5568 int applicable
, subsegment
;
5569 asection
*segment
= NULL
;
5570 sd_chain_struct
*space
;
5572 /* Pick the right name for the new section and pick the right
5573 subsegment number. */
5574 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5576 name
= pa_def_subspaces
[i
].alias
;
5577 subsegment
= pa_def_subspaces
[i
].subsegment
;
5581 name
= pa_def_subspaces
[i
].name
;
5585 /* Create the new section. */
5586 segment
= subseg_new (name
, subsegment
);
5589 /* For SOM we want to replace the standard .text, .data, and .bss
5590 sections with our own. */
5591 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5593 text_section
= segment
;
5594 applicable
= bfd_applicable_section_flags (stdoutput
);
5595 bfd_set_section_flags (stdoutput
, text_section
,
5596 applicable
& (SEC_ALLOC
| SEC_LOAD
5597 | SEC_RELOC
| SEC_CODE
5599 | SEC_HAS_CONTENTS
));
5601 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5603 data_section
= segment
;
5604 applicable
= bfd_applicable_section_flags (stdoutput
);
5605 bfd_set_section_flags (stdoutput
, data_section
,
5606 applicable
& (SEC_ALLOC
| SEC_LOAD
5608 | SEC_HAS_CONTENTS
));
5612 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5614 bss_section
= segment
;
5615 applicable
= bfd_applicable_section_flags (stdoutput
);
5616 bfd_set_section_flags (stdoutput
, bss_section
,
5617 applicable
& SEC_ALLOC
);
5620 /* Find the space associated with this subspace. */
5621 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5622 def_space_index
].segment
);
5625 as_fatal ("Internal error: Unable to find containing space for %s.",
5626 pa_def_subspaces
[i
].name
);
5629 create_new_subspace (space
, name
,
5630 pa_def_subspaces
[i
].loadable
,
5631 pa_def_subspaces
[i
].code_only
,
5632 pa_def_subspaces
[i
].common
,
5633 pa_def_subspaces
[i
].dup_common
,
5634 pa_def_subspaces
[i
].zero
,
5635 pa_def_subspaces
[i
].sort
,
5636 pa_def_subspaces
[i
].access
,
5637 pa_def_subspaces
[i
].space_index
,
5638 pa_def_subspaces
[i
].alignment
,
5639 pa_def_subspaces
[i
].quadrant
,
5647 /* Create a new space NAME, with the appropriate flags as defined
5648 by the given parameters. */
5650 static sd_chain_struct
*
5651 create_new_space (name
, spnum
, loadable
, defined
, private,
5652 sort
, seg
, user_defined
)
5662 sd_chain_struct
*chain_entry
;
5664 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5666 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5669 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5670 strcpy (SPACE_NAME (chain_entry
), name
);
5671 SPACE_DEFINED (chain_entry
) = defined
;
5672 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5673 SPACE_SPNUM (chain_entry
) = spnum
;
5675 chain_entry
->sd_seg
= seg
;
5676 chain_entry
->sd_last_subseg
= -1;
5677 chain_entry
->sd_next
= NULL
;
5679 /* Find spot for the new space based on its sort key. */
5680 if (!space_dict_last
)
5681 space_dict_last
= chain_entry
;
5683 if (space_dict_root
== NULL
)
5684 space_dict_root
= chain_entry
;
5687 sd_chain_struct
*chain_pointer
;
5688 sd_chain_struct
*prev_chain_pointer
;
5690 chain_pointer
= space_dict_root
;
5691 prev_chain_pointer
= NULL
;
5693 while (chain_pointer
)
5695 prev_chain_pointer
= chain_pointer
;
5696 chain_pointer
= chain_pointer
->sd_next
;
5699 /* At this point we've found the correct place to add the new
5700 entry. So add it and update the linked lists as appropriate. */
5701 if (prev_chain_pointer
)
5703 chain_entry
->sd_next
= chain_pointer
;
5704 prev_chain_pointer
->sd_next
= chain_entry
;
5708 space_dict_root
= chain_entry
;
5709 chain_entry
->sd_next
= chain_pointer
;
5712 if (chain_entry
->sd_next
== NULL
)
5713 space_dict_last
= chain_entry
;
5716 /* This is here to catch predefined spaces which do not get
5717 modified by the user's input. Another call is found at
5718 the bottom of pa_parse_space_stmt to handle cases where
5719 the user modifies a predefined space. */
5720 #ifdef obj_set_section_attributes
5721 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5727 /* Create a new subspace NAME, with the appropriate flags as defined
5728 by the given parameters.
5730 Add the new subspace to the subspace dictionary chain in numerical
5731 order as defined by the SORT entries. */
5733 static ssd_chain_struct
*
5734 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5735 dup_common
, is_zero
, sort
, access
, space_index
,
5736 alignment
, quadrant
, seg
)
5737 sd_chain_struct
*space
;
5739 int loadable
, code_only
, common
, dup_common
, is_zero
;
5747 ssd_chain_struct
*chain_entry
;
5749 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5751 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5753 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5754 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5756 /* Initialize subspace_defined. When we hit a .subspace directive
5757 we'll set it to 1 which "locks-in" the subspace attributes. */
5758 SUBSPACE_DEFINED (chain_entry
) = 0;
5760 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5761 chain_entry
->ssd_seg
= seg
;
5762 chain_entry
->ssd_next
= NULL
;
5764 /* Find spot for the new subspace based on its sort key. */
5765 if (space
->sd_subspaces
== NULL
)
5766 space
->sd_subspaces
= chain_entry
;
5769 ssd_chain_struct
*chain_pointer
;
5770 ssd_chain_struct
*prev_chain_pointer
;
5772 chain_pointer
= space
->sd_subspaces
;
5773 prev_chain_pointer
= NULL
;
5775 while (chain_pointer
)
5777 prev_chain_pointer
= chain_pointer
;
5778 chain_pointer
= chain_pointer
->ssd_next
;
5781 /* Now we have somewhere to put the new entry. Insert it and update
5783 if (prev_chain_pointer
)
5785 chain_entry
->ssd_next
= chain_pointer
;
5786 prev_chain_pointer
->ssd_next
= chain_entry
;
5790 space
->sd_subspaces
= chain_entry
;
5791 chain_entry
->ssd_next
= chain_pointer
;
5795 #ifdef obj_set_subsection_attributes
5796 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5803 /* Update the information for the given subspace based upon the
5804 various arguments. Return the modified subspace chain entry. */
5806 static ssd_chain_struct
*
5807 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5808 zero
, access
, space_index
, alignment
, quadrant
, section
)
5809 sd_chain_struct
*space
;
5823 ssd_chain_struct
*chain_entry
;
5825 chain_entry
= is_defined_subspace (name
);
5827 #ifdef obj_set_subsection_attributes
5828 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5835 /* Return the space chain entry for the space with the name NAME or
5836 NULL if no such space exists. */
5838 static sd_chain_struct
*
5839 is_defined_space (name
)
5842 sd_chain_struct
*chain_pointer
;
5844 for (chain_pointer
= space_dict_root
;
5846 chain_pointer
= chain_pointer
->sd_next
)
5848 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5849 return chain_pointer
;
5852 /* No mapping from segment to space was found. Return NULL. */
5856 /* Find and return the space associated with the given seg. If no mapping
5857 from the given seg to a space is found, then return NULL.
5859 Unlike subspaces, the number of spaces is not expected to grow much,
5860 so a linear exhaustive search is OK here. */
5862 static sd_chain_struct
*
5863 pa_segment_to_space (seg
)
5866 sd_chain_struct
*space_chain
;
5868 /* Walk through each space looking for the correct mapping. */
5869 for (space_chain
= space_dict_root
;
5871 space_chain
= space_chain
->sd_next
)
5873 if (space_chain
->sd_seg
== seg
)
5877 /* Mapping was not found. Return NULL. */
5881 /* Return the space chain entry for the subspace with the name NAME or
5882 NULL if no such subspace exists.
5884 Uses a linear search through all the spaces and subspaces, this may
5885 not be appropriate if we ever being placing each function in its
5888 static ssd_chain_struct
*
5889 is_defined_subspace (name
)
5892 sd_chain_struct
*space_chain
;
5893 ssd_chain_struct
*subspace_chain
;
5895 /* Walk through each space. */
5896 for (space_chain
= space_dict_root
;
5898 space_chain
= space_chain
->sd_next
)
5900 /* Walk through each subspace looking for a name which matches. */
5901 for (subspace_chain
= space_chain
->sd_subspaces
;
5903 subspace_chain
= subspace_chain
->ssd_next
)
5904 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5905 return subspace_chain
;
5908 /* Subspace wasn't found. Return NULL. */
5912 /* Find and return the subspace associated with the given seg. If no
5913 mapping from the given seg to a subspace is found, then return NULL.
5915 If we ever put each procedure/function within its own subspace
5916 (to make life easier on the compiler and linker), then this will have
5917 to become more efficient. */
5919 static ssd_chain_struct
*
5920 pa_subsegment_to_subspace (seg
, subseg
)
5924 sd_chain_struct
*space_chain
;
5925 ssd_chain_struct
*subspace_chain
;
5927 /* Walk through each space. */
5928 for (space_chain
= space_dict_root
;
5930 space_chain
= space_chain
->sd_next
)
5932 if (space_chain
->sd_seg
== seg
)
5934 /* Walk through each subspace within each space looking for
5935 the correct mapping. */
5936 for (subspace_chain
= space_chain
->sd_subspaces
;
5938 subspace_chain
= subspace_chain
->ssd_next
)
5939 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5940 return subspace_chain
;
5944 /* No mapping from subsegment to subspace found. Return NULL. */
5948 /* Given a number, try and find a space with the name number.
5950 Return a pointer to a space dictionary chain entry for the space
5951 that was found or NULL on failure. */
5953 static sd_chain_struct
*
5954 pa_find_space_by_number (number
)
5957 sd_chain_struct
*space_chain
;
5959 for (space_chain
= space_dict_root
;
5961 space_chain
= space_chain
->sd_next
)
5963 if (SPACE_SPNUM (space_chain
) == number
)
5967 /* No appropriate space found. Return NULL. */
5971 /* Return the starting address for the given subspace. If the starting
5972 address is unknown then return zero. */
5975 pa_subspace_start (space
, quadrant
)
5976 sd_chain_struct
*space
;
5979 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5980 is not correct for the PA OSF1 port. */
5981 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5983 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5989 /* FIXME. Needs documentation. */
5991 pa_next_subseg (space
)
5992 sd_chain_struct
*space
;
5995 space
->sd_last_subseg
++;
5996 return space
->sd_last_subseg
;
5999 /* Helper function for pa_stringer. Used to find the end of
6006 unsigned int c
= *s
& CHAR_MASK
;
6018 /* Handle a .STRING type pseudo-op. */
6021 pa_stringer (append_zero
)
6024 char *s
, num_buf
[4];
6028 /* Preprocess the string to handle PA-specific escape sequences.
6029 For example, \xDD where DD is a hexidecimal number should be
6030 changed to \OOO where OOO is an octal number. */
6032 /* Skip the opening quote. */
6033 s
= input_line_pointer
+ 1;
6035 while (is_a_char (c
= pa_stringer_aux (s
++)))
6042 /* Handle \x<num>. */
6045 unsigned int number
;
6050 /* Get pas the 'x'. */
6052 for (num_digit
= 0, number
= 0, dg
= *s
;
6054 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6055 || (dg
>= 'A' && dg
<= 'F'));
6059 number
= number
* 16 + dg
- '0';
6060 else if (dg
>= 'a' && dg
<= 'f')
6061 number
= number
* 16 + dg
- 'a' + 10;
6063 number
= number
* 16 + dg
- 'A' + 10;
6073 sprintf (num_buf
, "%02o", number
);
6076 sprintf (num_buf
, "%03o", number
);
6079 for (i
= 0; i
<= num_digit
; i
++)
6080 s_start
[i
] = num_buf
[i
];
6084 /* This might be a "\"", skip over the escaped char. */
6091 stringer (append_zero
);
6092 pa_undefine_label ();
6095 /* Handle a .VERSION pseudo-op. */
6102 pa_undefine_label ();
6105 /* Handle a .COPYRIGHT pseudo-op. */
6108 pa_copyright (unused
)
6112 pa_undefine_label ();
6115 /* Just like a normal cons, but when finished we have to undefine
6116 the latest space label. */
6123 pa_undefine_label ();
6126 /* Switch to the data space. As usual delete our label. */
6133 pa_undefine_label ();
6136 /* Like float_cons, but we need to undefine our label. */
6139 pa_float_cons (float_type
)
6142 float_cons (float_type
);
6143 pa_undefine_label ();
6146 /* Like s_fill, but delete our label when finished. */
6153 pa_undefine_label ();
6156 /* Like lcomm, but delete our label when finished. */
6159 pa_lcomm (needs_align
)
6162 s_lcomm (needs_align
);
6163 pa_undefine_label ();
6166 /* Like lsym, but delete our label when finished. */
6173 pa_undefine_label ();
6176 /* Switch to the text space. Like s_text, but delete our
6177 label when finished. */
6183 pa_undefine_label ();
6186 /* On the PA relocations which involve function symbols must not be
6187 adjusted. This so that the linker can know when/how to create argument
6188 relocation stubs for indirect calls and calls to static functions.
6190 FIXME. Also reject R_HPPA relocations which are 32 bits
6191 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6192 needs to generate relocations to push the addend and symbol value
6193 onto the stack, add them, then pop the value off the stack and
6194 use it in a relocation -- yuk. */
6197 hppa_fix_adjustable (fixp
)
6200 struct hppa_fix_struct
*hppa_fix
;
6202 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6204 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6207 if (fixp
->fx_addsy
== 0
6208 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6214 /* Return nonzero if the fixup in FIXP will require a relocation,
6215 even it if appears that the fixup could be completely handled
6219 hppa_force_relocation (fixp
)
6222 struct hppa_fix_struct
*hppa_fixp
;
6224 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6226 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6230 #define stub_needed(CALLER, CALLEE) \
6231 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6233 /* It is necessary to force PC-relative calls/jumps to have a relocation
6234 entry if they're going to need either a argument relocation or long
6235 call stub. FIXME. Can't we need the same for absolute calls? */
6236 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6237 && (stub_needed (((obj_symbol_type
*)
6238 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6239 hppa_fixp
->fx_arg_reloc
)))
6244 /* No need (yet) to force another relocations to be emitted. */
6248 /* Now for some ELF specific code. FIXME. */
6250 static symext_chainS
*symext_rootP
;
6251 static symext_chainS
*symext_lastP
;
6253 /* Mark the end of a function so that it's possible to compute
6254 the size of the function in hppa_elf_final_processing. */
6257 hppa_elf_mark_end_of_function ()
6259 /* ELF does not have EXIT relocations. All we do is create a
6260 temporary symbol marking the end of the function. */
6261 char *name
= (char *)
6262 xmalloc (strlen ("L$\001end_") +
6263 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6269 strcpy (name
, "L$\001end_");
6270 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6272 /* If we have a .exit followed by a .procend, then the
6273 symbol will have already been defined. */
6274 symbolP
= symbol_find (name
);
6277 /* The symbol has already been defined! This can
6278 happen if we have a .exit followed by a .procend.
6280 This is *not* an error. All we want to do is free
6281 the memory we just allocated for the name and continue. */
6286 /* symbol value should be the offset of the
6287 last instruction of the function */
6288 symbolP
= symbol_new (name
, now_seg
,
6289 (valueT
) (obstack_next_free (&frags
)
6290 - frag_now
->fr_literal
- 4),
6294 symbolP
->bsym
->flags
= BSF_LOCAL
;
6295 symbol_table_insert (symbolP
);
6299 last_call_info
->end_symbol
= symbolP
;
6301 as_bad ("Symbol '%s' could not be created.", name
);
6305 as_bad ("No memory for symbol name.");
6309 /* Do any symbol processing requested by the target-cpu or target-format. */
6312 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6314 elf_symbol_type
*symbolP
;
6317 /* Just call the ELF BFD routine. */
6318 elf_hppa_tc_symbol (abfd
, symbolP
, sym_idx
, &symext_rootP
, &symext_lastP
);
6321 /* Make sections needed by the target cpu and/or target format. */
6323 hppa_tc_make_sections (abfd
)
6326 /* Just call the ELF BFD routine. */
6327 elf_hppa_tc_make_sections (abfd
, symext_rootP
);
6330 /* For ELF, this function serves one purpose: to setup the st_size
6331 field of STT_FUNC symbols. To do this, we need to scan the
6332 call_info structure list, determining st_size in by taking the
6333 difference in the address of the beginning/end marker symbols. */
6336 elf_hppa_final_processing ()
6338 struct call_info
*call_info_pointer
;
6340 for (call_info_pointer
= call_info_root
;
6342 call_info_pointer
= call_info_pointer
->ci_next
)
6344 elf_symbol_type
*esym
6345 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6346 esym
->internal_elf_sym
.st_size
=
6347 S_GET_VALUE (call_info_pointer
->end_symbol
)
6348 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;