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. */
63 /* Some local functions only used by ELF. */
64 static void pa_build_symextn_section
PARAMS ((void));
65 static void hppa_tc_make_symextn_section
PARAMS ((void));
69 /* Names of various debugging spaces/subspaces. */
70 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
71 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
72 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
73 #define UNWIND_SECTION_NAME "$UNWIND$"
75 /* Object file formats specify relocation types. */
76 typedef int reloc_type
;
78 /* SOM objects can have both a version string and a copyright string. */
79 #define obj_version obj_som_version
80 #define obj_copyright obj_som_copyright
82 /* Do not use space aliases. */
85 /* How to generate a relocation. */
86 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
88 /* Object file formats specify BFD symbol types. */
89 typedef som_symbol_type obj_symbol_type
;
92 /* Various structures and types used internally in tc-hppa.c. */
94 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
98 unsigned int cannot_unwind
:1;
99 unsigned int millicode
:1;
100 unsigned int millicode_save_rest
:1;
101 unsigned int region_desc
:2;
102 unsigned int save_sr
:2;
103 unsigned int entry_fr
:4;
104 unsigned int entry_gr
:5;
105 unsigned int args_stored
:1;
106 unsigned int call_fr
:5;
107 unsigned int call_gr
:5;
108 unsigned int save_sp
:1;
109 unsigned int save_rp
:1;
110 unsigned int save_rp_in_frame
:1;
111 unsigned int extn_ptr_defined
:1;
112 unsigned int cleanup_defined
:1;
114 unsigned int hpe_interrupt_marker
:1;
115 unsigned int hpux_interrupt_marker
:1;
116 unsigned int reserved
:3;
117 unsigned int frame_size
:27;
122 /* Starting and ending offsets of the region described by
124 unsigned int start_offset
;
125 unsigned int end_offset
;
126 struct unwind_desc descriptor
;
129 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
130 control the entry and exit code they generate. It is also used in
131 creation of the correct stack unwind descriptors.
133 NOTE: GAS does not support .enter and .leave for the generation of
134 prologues and epilogues. FIXME.
136 The fields in structure roughly correspond to the arguments available on the
137 .callinfo pseudo-op. */
141 /* The unwind descriptor being built. */
142 struct unwind_table ci_unwind
;
144 /* Name of this function. */
145 symbolS
*start_symbol
;
147 /* (temporary) symbol used to mark the end of this function. */
150 /* Next entry in the chain. */
151 struct call_info
*ci_next
;
154 /* Operand formats for FP instructions. Note not all FP instructions
155 allow all four formats to be used (for example fmpysub only allows
159 SGL
, DBL
, ILLEGAL_FMT
, QUAD
163 /* This fully describes the symbol types which may be attached to
164 an EXPORT or IMPORT directive. Only SOM uses this formation
165 (ELF has no need for it). */
169 SYMBOL_TYPE_ABSOLUTE
,
173 SYMBOL_TYPE_MILLICODE
,
175 SYMBOL_TYPE_PRI_PROG
,
176 SYMBOL_TYPE_SEC_PROG
,
180 /* This structure contains information needed to assemble
181 individual instructions. */
184 /* Holds the opcode after parsing by pa_ip. */
185 unsigned long opcode
;
187 /* Holds an expression associated with the current instruction. */
190 /* Does this instruction use PC-relative addressing. */
193 /* Floating point formats for operand1 and operand2. */
194 fp_operand_format fpof1
;
195 fp_operand_format fpof2
;
197 /* Holds the field selector for this instruction
198 (for example L%, LR%, etc). */
201 /* Holds any argument relocation bits associated with this
202 instruction. (instruction should be some sort of call). */
205 /* The format specification for this instruction. */
208 /* The relocation (if any) associated with this instruction. */
212 /* PA-89 floating point registers are arranged like this:
215 +--------------+--------------+
216 | 0 or 16L | 16 or 16R |
217 +--------------+--------------+
218 | 1 or 17L | 17 or 17R |
219 +--------------+--------------+
227 +--------------+--------------+
228 | 14 or 30L | 30 or 30R |
229 +--------------+--------------+
230 | 15 or 31L | 31 or 31R |
231 +--------------+--------------+
234 The following is a version of pa_parse_number that
235 handles the L/R notation and returns the correct
236 value to put into the instruction register field.
237 The correct value to put into the instruction is
238 encoded in the structure 'pa_89_fp_reg_struct'. */
240 struct pa_89_fp_reg_struct
242 /* The register number. */
249 /* Additional information needed to build argument relocation stubs. */
252 /* The argument relocation specification. */
253 unsigned int arg_reloc
;
255 /* Number of arguments. */
256 unsigned int arg_count
;
259 /* This structure defines an entry in the subspace dictionary
262 struct subspace_dictionary_chain
264 /* Nonzero if this space has been defined by the user code. */
265 unsigned int ssd_defined
;
267 /* Name of this subspace. */
270 /* GAS segment and subsegment associated with this subspace. */
274 /* Next space in the subspace dictionary chain. */
275 struct subspace_dictionary_chain
*ssd_next
;
278 typedef struct subspace_dictionary_chain ssd_chain_struct
;
280 /* This structure defines an entry in the subspace dictionary
283 struct space_dictionary_chain
285 /* Nonzero if this space has been defined by the user code or
286 as a default space. */
287 unsigned int sd_defined
;
289 /* Nonzero if this spaces has been defined by the user code. */
290 unsigned int sd_user_defined
;
292 /* The space number (or index). */
293 unsigned int sd_spnum
;
295 /* The name of this subspace. */
298 /* GAS segment to which this subspace corresponds. */
301 /* Current subsegment number being used. */
304 /* The chain of subspaces contained within this space. */
305 ssd_chain_struct
*sd_subspaces
;
307 /* The next entry in the space dictionary chain. */
308 struct space_dictionary_chain
*sd_next
;
311 typedef struct space_dictionary_chain sd_chain_struct
;
313 /* Structure for previous label tracking. Needed so that alignments,
314 callinfo declarations, etc can be easily attached to a particular
316 typedef struct label_symbol_struct
318 struct symbol
*lss_label
;
319 sd_chain_struct
*lss_space
;
320 struct label_symbol_struct
*lss_next
;
324 /* This structure defines attributes of the default subspace
325 dictionary entries. */
327 struct default_subspace_dict
329 /* Name of the subspace. */
332 /* FIXME. Is this still needed? */
335 /* Nonzero if this subspace is loadable. */
338 /* Nonzero if this subspace contains only code. */
341 /* Nonzero if this is a common subspace. */
344 /* Nonzero if this is a common subspace which allows symbols
345 to be multiply defined. */
348 /* Nonzero if this subspace should be zero filled. */
351 /* Sort key for this subspace. */
354 /* Access control bits for this subspace. Can represent RWX access
355 as well as privilege level changes for gateways. */
358 /* Index of containing space. */
361 /* Alignment (in bytes) of this subspace. */
364 /* Quadrant within space where this subspace should be loaded. */
367 /* An index into the default spaces array. */
370 /* An alias for this section (or NULL if no alias exists). */
373 /* Subsegment associated with this subspace. */
377 /* This structure defines attributes of the default space
378 dictionary entries. */
380 struct default_space_dict
382 /* Name of the space. */
385 /* Space number. It is possible to identify spaces within
386 assembly code numerically! */
389 /* Nonzero if this space is loadable. */
392 /* Nonzero if this space is "defined". FIXME is still needed */
395 /* Nonzero if this space can not be shared. */
398 /* Sort key for this space. */
401 /* Segment associated with this space. */
404 /* An alias for this section (or NULL if no alias exists). */
408 /* Extra information needed to perform fixups (relocations) on the PA. */
409 struct hppa_fix_struct
411 /* The field selector. */
412 enum hppa_reloc_field_selector_type fx_r_field
;
417 /* Format of fixup. */
420 /* Argument relocation bits. */
423 /* The unwind descriptor associated with this fixup. */
426 /* The segment this fixup appears in. */
430 /* Structure to hold information about predefined registers. */
438 /* This structure defines the mapping from a FP condition string
439 to a condition number which can be recorded in an instruction. */
446 /* This structure defines a mapping from a field selector
447 string to a field selector type. */
448 struct selector_entry
454 /* Prototypes for functions local to tc-hppa.c. */
456 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
457 static void pa_cons
PARAMS ((int));
458 static void pa_data
PARAMS ((int));
459 static void pa_float_cons
PARAMS ((int));
460 static void pa_fill
PARAMS ((int));
461 static void pa_lcomm
PARAMS ((int));
462 static void pa_lsym
PARAMS ((int));
463 static void pa_stringer
PARAMS ((int));
464 static void pa_text
PARAMS ((int));
465 static void pa_version
PARAMS ((int));
466 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
467 static int get_expression
PARAMS ((char *));
468 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
469 static int evaluate_absolute
PARAMS ((struct pa_it
*));
470 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
471 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
472 static int pa_parse_nullif
PARAMS ((char **));
473 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
474 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
475 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
476 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
477 static void pa_block
PARAMS ((int));
478 static void pa_call
PARAMS ((int));
479 static void pa_call_args
PARAMS ((struct call_desc
*));
480 static void pa_callinfo
PARAMS ((int));
481 static void pa_code
PARAMS ((int));
482 static void pa_comm
PARAMS ((int));
483 static void pa_copyright
PARAMS ((int));
484 static void pa_end
PARAMS ((int));
485 static void pa_enter
PARAMS ((int));
486 static void pa_entry
PARAMS ((int));
487 static void pa_equ
PARAMS ((int));
488 static void pa_exit
PARAMS ((int));
489 static void pa_export
PARAMS ((int));
490 static void pa_type_args
PARAMS ((symbolS
*, int));
491 static void pa_import
PARAMS ((int));
492 static void pa_label
PARAMS ((int));
493 static void pa_leave
PARAMS ((int));
494 static void pa_origin
PARAMS ((int));
495 static void pa_proc
PARAMS ((int));
496 static void pa_procend
PARAMS ((int));
497 static void pa_space
PARAMS ((int));
498 static void pa_spnum
PARAMS ((int));
499 static void pa_subspace
PARAMS ((int));
500 static void pa_param
PARAMS ((int));
501 static void pa_undefine_label
PARAMS ((void));
502 static int need_89_opcode
PARAMS ((struct pa_it
*,
503 struct pa_89_fp_reg_struct
*));
504 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
505 static label_symbol_struct
*pa_get_label
PARAMS ((void));
506 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, char,
509 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
514 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
515 char *, char, char, char,
516 char, char, char, int,
519 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
520 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
521 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
522 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
524 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
525 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
526 static void pa_ip
PARAMS ((char *));
527 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
528 long, expressionS
*, int,
529 bfd_reloc_code_real_type
,
530 enum hppa_reloc_field_selector_type
,
532 static int is_end_of_statement
PARAMS ((void));
533 static int reg_name_search
PARAMS ((char *));
534 static int pa_chk_field_selector
PARAMS ((char **));
535 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
536 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
537 static void process_exit
PARAMS ((void));
538 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
539 static int log2
PARAMS ((int));
540 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
541 static unsigned int pa_stringer_aux
PARAMS ((char *));
542 static void pa_spaces_begin
PARAMS ((void));
543 static void hppa_elf_mark_end_of_function
PARAMS ((void));
545 /* File and gloally scoped variable declarations. */
547 /* Root and final entry in the space chain. */
548 static sd_chain_struct
*space_dict_root
;
549 static sd_chain_struct
*space_dict_last
;
551 /* The current space and subspace. */
552 static sd_chain_struct
*current_space
;
553 static ssd_chain_struct
*current_subspace
;
555 /* Root of the call_info chain. */
556 static struct call_info
*call_info_root
;
558 /* The last call_info (for functions) structure
559 seen so it can be associated with fixups and
561 static struct call_info
*last_call_info
;
563 /* The last call description (for actual calls). */
564 static struct call_desc last_call_desc
;
566 /* Relaxation isn't supported for the PA yet. */
567 const relax_typeS md_relax_table
[] =
570 /* Jumps are always the same size -- one instruction. */
571 int md_short_jump_size
= 4;
572 int md_long_jump_size
= 4;
574 /* handle of the OPCODE hash table */
575 static struct hash_control
*op_hash
= NULL
;
577 /* This array holds the chars that always start a comment. If the
578 pre-processor is disabled, these aren't very useful. */
579 const char comment_chars
[] = ";";
581 /* Table of pseudo ops for the PA. FIXME -- how many of these
582 are now redundant with the overall GAS and the object file
584 const pseudo_typeS md_pseudo_table
[] =
586 /* align pseudo-ops on the PA specify the actual alignment requested,
587 not the log2 of the requested alignment. */
588 {"align", s_align_bytes
, 8},
589 {"ALIGN", s_align_bytes
, 8},
590 {"block", pa_block
, 1},
591 {"BLOCK", pa_block
, 1},
592 {"blockz", pa_block
, 0},
593 {"BLOCKZ", pa_block
, 0},
594 {"byte", pa_cons
, 1},
595 {"BYTE", pa_cons
, 1},
596 {"call", pa_call
, 0},
597 {"CALL", pa_call
, 0},
598 {"callinfo", pa_callinfo
, 0},
599 {"CALLINFO", pa_callinfo
, 0},
600 {"code", pa_code
, 0},
601 {"CODE", pa_code
, 0},
602 {"comm", pa_comm
, 0},
603 {"COMM", pa_comm
, 0},
604 {"copyright", pa_copyright
, 0},
605 {"COPYRIGHT", pa_copyright
, 0},
606 {"data", pa_data
, 0},
607 {"DATA", pa_data
, 0},
608 {"double", pa_float_cons
, 'd'},
609 {"DOUBLE", pa_float_cons
, 'd'},
612 {"enter", pa_enter
, 0},
613 {"ENTER", pa_enter
, 0},
614 {"entry", pa_entry
, 0},
615 {"ENTRY", pa_entry
, 0},
618 {"exit", pa_exit
, 0},
619 {"EXIT", pa_exit
, 0},
620 {"export", pa_export
, 0},
621 {"EXPORT", pa_export
, 0},
622 {"fill", pa_fill
, 0},
623 {"FILL", pa_fill
, 0},
624 {"float", pa_float_cons
, 'f'},
625 {"FLOAT", pa_float_cons
, 'f'},
626 {"half", pa_cons
, 2},
627 {"HALF", pa_cons
, 2},
628 {"import", pa_import
, 0},
629 {"IMPORT", pa_import
, 0},
632 {"label", pa_label
, 0},
633 {"LABEL", pa_label
, 0},
634 {"lcomm", pa_lcomm
, 0},
635 {"LCOMM", pa_lcomm
, 0},
636 {"leave", pa_leave
, 0},
637 {"LEAVE", pa_leave
, 0},
638 {"long", pa_cons
, 4},
639 {"LONG", pa_cons
, 4},
640 {"lsym", pa_lsym
, 0},
641 {"LSYM", pa_lsym
, 0},
642 {"octa", pa_cons
, 16},
643 {"OCTA", pa_cons
, 16},
644 {"org", pa_origin
, 0},
645 {"ORG", pa_origin
, 0},
646 {"origin", pa_origin
, 0},
647 {"ORIGIN", pa_origin
, 0},
648 {"param", pa_param
, 0},
649 {"PARAM", pa_param
, 0},
650 {"proc", pa_proc
, 0},
651 {"PROC", pa_proc
, 0},
652 {"procend", pa_procend
, 0},
653 {"PROCEND", pa_procend
, 0},
654 {"quad", pa_cons
, 8},
655 {"QUAD", pa_cons
, 8},
658 {"short", pa_cons
, 2},
659 {"SHORT", pa_cons
, 2},
660 {"single", pa_float_cons
, 'f'},
661 {"SINGLE", pa_float_cons
, 'f'},
662 {"space", pa_space
, 0},
663 {"SPACE", pa_space
, 0},
664 {"spnum", pa_spnum
, 0},
665 {"SPNUM", pa_spnum
, 0},
666 {"string", pa_stringer
, 0},
667 {"STRING", pa_stringer
, 0},
668 {"stringz", pa_stringer
, 1},
669 {"STRINGZ", pa_stringer
, 1},
670 {"subspa", pa_subspace
, 0},
671 {"SUBSPA", pa_subspace
, 0},
672 {"text", pa_text
, 0},
673 {"TEXT", pa_text
, 0},
674 {"version", pa_version
, 0},
675 {"VERSION", pa_version
, 0},
676 {"word", pa_cons
, 4},
677 {"WORD", pa_cons
, 4},
681 /* This array holds the chars that only start a comment at the beginning of
682 a line. If the line seems to have the form '# 123 filename'
683 .line and .file directives will appear in the pre-processed output.
685 Note that input_file.c hand checks for '#' at the beginning of the
686 first line of the input file. This is because the compiler outputs
687 #NO_APP at the beginning of its output.
689 Also note that '/*' will always start a comment. */
690 const char line_comment_chars
[] = "#";
692 /* This array holds the characters which act as line separators. */
693 const char line_separator_chars
[] = "!";
695 /* Chars that can be used to separate mant from exp in floating point nums. */
696 const char EXP_CHARS
[] = "eE";
698 /* Chars that mean this number is a floating point constant.
699 As in 0f12.456 or 0d1.2345e12.
701 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
702 changed in read.c. Ideally it shouldn't hae to know abou it at
703 all, but nothing is ideal around here. */
704 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
706 static struct pa_it the_insn
;
708 /* Points to the end of an expression just parsed by get_expressoin
709 and friends. FIXME. This shouldn't be handled with a file-global
711 static char *expr_end
;
713 /* Nonzero if a .callinfo appeared within the current procedure. */
714 static int callinfo_found
;
716 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
717 static int within_entry_exit
;
719 /* Nonzero if the assembler is currently within a procedure definition. */
720 static int within_procedure
;
722 /* Handle on strucutre which keep track of the last symbol
723 seen in each subspace. */
724 static label_symbol_struct
*label_symbols_rootp
= NULL
;
726 /* Holds the last field selector. */
727 static int hppa_field_selector
;
729 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
730 static symbolS
*dummy_symbol
;
732 /* Nonzero if errors are to be printed. */
733 static int print_errors
= 1;
735 /* List of registers that are pre-defined:
737 Each general register has one predefined name of the form
738 %r<REGNUM> which has the value <REGNUM>.
740 Space and control registers are handled in a similar manner,
741 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
743 Likewise for the floating point registers, but of the form
744 %fr<REGNUM>. Floating point registers have additional predefined
745 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
746 again have the value <REGNUM>.
748 Many registers also have synonyms:
750 %r26 - %r23 have %arg0 - %arg3 as synonyms
751 %r28 - %r29 have %ret0 - %ret1 as synonyms
752 %r30 has %sp as a synonym
753 %r27 has %dp as a synonym
754 %r2 has %rp as a synonym
756 Almost every control register has a synonym; they are not listed
759 The table is sorted. Suitable for searching by a binary search. */
761 static const struct pd_reg pre_defined_registers
[] =
961 /* This table is sorted by order of the length of the string. This is
962 so we check for <> before we check for <. If we had a <> and checked
963 for < first, we would get a false match. */
964 static const struct fp_cond_map fp_cond_map
[] =
1000 static const struct selector_entry selector_table
[] =
1019 /* default space and subspace dictionaries */
1021 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1022 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1024 /* pre-defined subsegments (subspaces) for the HPPA. */
1025 #define SUBSEG_CODE 0
1026 #define SUBSEG_DATA 0
1027 #define SUBSEG_LIT 1
1028 #define SUBSEG_BSS 2
1029 #define SUBSEG_UNWIND 3
1030 #define SUBSEG_GDB_STRINGS 0
1031 #define SUBSEG_GDB_SYMBOLS 1
1033 static struct default_subspace_dict pa_def_subspaces
[] =
1035 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1036 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1037 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1038 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1040 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1042 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1045 static struct default_space_dict pa_def_spaces
[] =
1047 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1048 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1049 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1052 /* Misc local definitions used by the assembler. */
1054 /* Return nonzero if the string pointed to by S potentially represents
1055 a right or left half of a FP register */
1056 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1057 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1059 /* These macros are used to maintain spaces/subspaces. */
1060 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1061 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1062 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1063 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1065 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1066 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1068 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1069 main loop after insertion. */
1071 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1073 ((OPCODE) |= (FIELD) << (START)); \
1077 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1078 IGNORE is used to suppress the error message. */
1080 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1082 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1085 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1091 #define is_DP_relative(exp) \
1092 ((exp).X_op == O_subtract \
1093 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1095 #define is_PC_relative(exp) \
1096 ((exp).X_op == O_subtract \
1097 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1099 #define is_complex(exp) \
1100 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1102 /* Actual functions to implement the PA specific code for the assembler. */
1104 /* Returns a pointer to the label_symbol_struct for the current space.
1105 or NULL if no label_symbol_struct exists for the current space. */
1107 static label_symbol_struct
*
1110 label_symbol_struct
*label_chain
;
1111 sd_chain_struct
*space_chain
= current_space
;
1113 for (label_chain
= label_symbols_rootp
;
1115 label_chain
= label_chain
->lss_next
)
1116 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1122 /* Defines a label for the current space. If one is already defined,
1123 this function will replace it with the new label. */
1126 pa_define_label (symbol
)
1129 label_symbol_struct
*label_chain
= pa_get_label ();
1130 sd_chain_struct
*space_chain
= current_space
;
1133 label_chain
->lss_label
= symbol
;
1136 /* Create a new label entry and add it to the head of the chain. */
1138 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1139 label_chain
->lss_label
= symbol
;
1140 label_chain
->lss_space
= space_chain
;
1141 label_chain
->lss_next
= NULL
;
1143 if (label_symbols_rootp
)
1144 label_chain
->lss_next
= label_symbols_rootp
;
1146 label_symbols_rootp
= label_chain
;
1150 /* Removes a label definition for the current space.
1151 If there is no label_symbol_struct entry, then no action is taken. */
1154 pa_undefine_label ()
1156 label_symbol_struct
*label_chain
;
1157 label_symbol_struct
*prev_label_chain
= NULL
;
1158 sd_chain_struct
*space_chain
= current_space
;
1160 for (label_chain
= label_symbols_rootp
;
1162 label_chain
= label_chain
->lss_next
)
1164 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1166 /* Remove the label from the chain and free its memory. */
1167 if (prev_label_chain
)
1168 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1170 label_symbols_rootp
= label_chain
->lss_next
;
1175 prev_label_chain
= label_chain
;
1180 /* An HPPA-specific version of fix_new. This is required because the HPPA
1181 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1182 results in the creation of an instance of an hppa_fix_struct. An
1183 hppa_fix_struct stores the extra information along with a pointer to the
1184 original fixS. This is attached to the original fixup via the
1185 tc_fix_data field. */
1188 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1189 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1193 symbolS
*add_symbol
;
1197 bfd_reloc_code_real_type r_type
;
1198 enum hppa_reloc_field_selector_type r_field
;
1205 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1206 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1209 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1211 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1212 new_fix
->tc_fix_data
= hppa_fix
;
1213 hppa_fix
->fx_r_type
= r_type
;
1214 hppa_fix
->fx_r_field
= r_field
;
1215 hppa_fix
->fx_r_format
= r_format
;
1216 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1217 hppa_fix
->segment
= now_seg
;
1220 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1222 /* If necessary call BFD backend function to attach the
1223 unwind bits to the target dependent parts of a BFD symbol.
1225 #ifdef obj_attach_unwind_info
1226 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1230 /* foo-$global$ is used to access non-automatic storage. $global$
1231 is really just a marker and has served its purpose, so eliminate
1232 it now so as not to confuse write.c. */
1233 if (new_fix
->fx_subsy
1234 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1235 new_fix
->fx_subsy
= NULL
;
1238 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1239 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1242 parse_cons_expression_hppa (exp
)
1245 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1249 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1250 hppa_field_selector is set by the parse_cons_expression_hppa. */
1253 cons_fix_new_hppa (frag
, where
, size
, exp
)
1259 unsigned int rel_type
;
1261 if (is_DP_relative (*exp
))
1262 rel_type
= R_HPPA_GOTOFF
;
1263 else if (is_complex (*exp
))
1264 rel_type
= R_HPPA_COMPLEX
;
1268 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1269 as_warn ("Invalid field selector. Assuming F%%.");
1271 fix_new_hppa (frag
, where
, size
,
1272 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1273 hppa_field_selector
, 32, 0, (char *) 0);
1275 /* Reset field selector to its default state. */
1276 hppa_field_selector
= 0;
1279 /* This function is called once, at assembler startup time. It should
1280 set up all the tables, etc. that the MD part of the assembler will need. */
1285 const char *retval
= NULL
;
1289 last_call_info
= NULL
;
1290 call_info_root
= NULL
;
1292 /* Folding of text and data segments fails miserably on the PA.
1293 Warn user and disable "-R" option. */
1296 as_warn ("-R option not supported on this target.");
1297 flag_readonly_data_in_text
= 0;
1303 op_hash
= hash_new ();
1305 while (i
< NUMOPCODES
)
1307 const char *name
= pa_opcodes
[i
].name
;
1308 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1309 if (retval
!= NULL
&& *retval
!= '\0')
1311 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1316 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1317 != pa_opcodes
[i
].match
)
1319 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1320 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1325 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1329 as_fatal ("Broken assembler. No assembly attempted.");
1331 /* SOM will change text_section. To make sure we never put
1332 anything into the old one switch to the new one now. */
1333 subseg_set (text_section
, 0);
1335 dummy_symbol
= symbol_find_or_make ("L$dummy");
1336 S_SET_SEGMENT (dummy_symbol
, text_section
);
1339 /* Assemble a single instruction storing it into a frag. */
1346 /* The had better be something to assemble. */
1349 /* If we are within a procedure definition, make sure we've
1350 defined a label for the procedure; handle case where the
1351 label was defined after the .PROC directive.
1353 Note there's not need to diddle with the segment or fragment
1354 for the label symbol in this case. We have already switched
1355 into the new $CODE$ subspace at this point. */
1356 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1358 label_symbol_struct
*label_symbol
= pa_get_label ();
1362 if (label_symbol
->lss_label
)
1364 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1365 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1367 /* Also handle allocation of a fixup to hold the unwind
1368 information when the label appears after the proc/procend. */
1369 if (within_entry_exit
)
1371 char *where
= frag_more (0);
1373 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1374 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
1375 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1376 (char *) &last_call_info
->ci_unwind
.descriptor
);
1381 as_bad ("Missing function name for .PROC (corrupted label chain)");
1384 as_bad ("Missing function name for .PROC");
1387 /* Assemble the instruction. Results are saved into "the_insn". */
1390 /* Get somewhere to put the assembled instrution. */
1393 /* Output the opcode. */
1394 md_number_to_chars (to
, the_insn
.opcode
, 4);
1396 /* If necessary output more stuff. */
1397 if (the_insn
.reloc
!= R_HPPA_NONE
)
1398 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1399 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1400 the_insn
.reloc
, the_insn
.field_selector
,
1401 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1404 /* Do the real work for assembling a single instruction. Store results
1405 into the global "the_insn" variable. */
1411 char *error_message
= "";
1412 char *s
, c
, *argstart
, *name
, *save_s
;
1416 int cmpltr
, nullif
, flag
, cond
, num
;
1417 unsigned long opcode
;
1418 struct pa_opcode
*insn
;
1420 /* Skip to something interesting. */
1421 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1440 as_bad ("Unknown opcode: `%s'", str
);
1446 /* Convert everything into lower case. */
1449 if (isupper (*save_s
))
1450 *save_s
= tolower (*save_s
);
1454 /* Look up the opcode in the has table. */
1455 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1457 as_bad ("Unknown opcode: `%s'", str
);
1466 /* Mark the location where arguments for the instruction start, then
1467 start processing them. */
1471 /* Do some initialization. */
1472 opcode
= insn
->match
;
1473 bzero (&the_insn
, sizeof (the_insn
));
1475 the_insn
.reloc
= R_HPPA_NONE
;
1477 /* Build the opcode, checking as we go to make
1478 sure that the operands match. */
1479 for (args
= insn
->args
;; ++args
)
1484 /* End of arguments. */
1500 /* These must match exactly. */
1509 /* Handle a 5 bit register or control register field at 10. */
1512 num
= pa_parse_number (&s
, 0);
1513 CHECK_FIELD (num
, 31, 0, 0);
1514 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1516 /* Handle a 5 bit register field at 15. */
1518 num
= pa_parse_number (&s
, 0);
1519 CHECK_FIELD (num
, 31, 0, 0);
1520 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1522 /* Handle a 5 bit register field at 31. */
1525 num
= pa_parse_number (&s
, 0);
1526 CHECK_FIELD (num
, 31, 0, 0);
1527 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1529 /* Handle a 5 bit field length at 31. */
1531 num
= pa_get_absolute_expression (&the_insn
, &s
);
1533 CHECK_FIELD (num
, 32, 1, 0);
1534 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1536 /* Handle a 5 bit immediate at 15. */
1538 num
= pa_get_absolute_expression (&the_insn
, &s
);
1540 CHECK_FIELD (num
, 15, -16, 0);
1541 low_sign_unext (num
, 5, &num
);
1542 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1544 /* Handle a 5 bit immediate at 31. */
1546 num
= pa_get_absolute_expression (&the_insn
, &s
);
1548 CHECK_FIELD (num
, 15, -16, 0)
1549 low_sign_unext (num
, 5, &num
);
1550 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1552 /* Handle an unsigned 5 bit immediate at 31. */
1554 num
= pa_get_absolute_expression (&the_insn
, &s
);
1556 CHECK_FIELD (num
, 31, 0, 0);
1557 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1559 /* Handle an unsigned 5 bit immediate at 15. */
1561 num
= pa_get_absolute_expression (&the_insn
, &s
);
1563 CHECK_FIELD (num
, 31, 0, 0);
1564 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1566 /* Handle a 2 bit space identifier at 17. */
1568 num
= pa_parse_number (&s
, 0);
1569 CHECK_FIELD (num
, 3, 0, 1);
1570 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1572 /* Handle a 3 bit space identifier at 18. */
1574 num
= pa_parse_number (&s
, 0);
1575 CHECK_FIELD (num
, 7, 0, 1);
1576 dis_assemble_3 (num
, &num
);
1577 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1579 /* Handle a completer for an indexing load or store. */
1585 while (*s
== ',' && i
< 2)
1588 if (strncasecmp (s
, "sm", 2) == 0)
1595 else if (strncasecmp (s
, "m", 1) == 0)
1597 else if (strncasecmp (s
, "s", 1) == 0)
1600 as_bad ("Invalid Indexed Load Completer.");
1605 as_bad ("Invalid Indexed Load Completer Syntax.");
1607 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1610 /* Handle a short load/store completer. */
1618 if (strncasecmp (s
, "ma", 2) == 0)
1623 else if (strncasecmp (s
, "mb", 2) == 0)
1629 as_bad ("Invalid Short Load/Store Completer.");
1633 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1636 /* Handle a stbys completer. */
1642 while (*s
== ',' && i
< 2)
1645 if (strncasecmp (s
, "m", 1) == 0)
1647 else if (strncasecmp (s
, "b", 1) == 0)
1649 else if (strncasecmp (s
, "e", 1) == 0)
1652 as_bad ("Invalid Store Bytes Short Completer");
1657 as_bad ("Invalid Store Bytes Short Completer");
1659 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1662 /* Handle a non-negated compare/stubtract condition. */
1664 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1667 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1670 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1672 /* Handle a negated or non-negated compare/subtract condition. */
1675 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1679 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1682 as_bad ("Invalid Compare/Subtract Condition.");
1687 /* Negated condition requires an opcode change. */
1691 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1693 /* Handle a negated or non-negated add condition. */
1696 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1700 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1703 as_bad ("Invalid Compare/Subtract Condition");
1708 /* Negated condition requires an opcode change. */
1712 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1714 /* Handle a compare/subtract condition. */
1721 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1726 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1729 as_bad ("Invalid Compare/Subtract Condition");
1733 opcode
|= cmpltr
<< 13;
1734 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1736 /* Handle a non-negated add condition. */
1745 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1749 if (strcmp (name
, "=") == 0)
1751 else if (strcmp (name
, "<") == 0)
1753 else if (strcmp (name
, "<=") == 0)
1755 else if (strcasecmp (name
, "nuv") == 0)
1757 else if (strcasecmp (name
, "znv") == 0)
1759 else if (strcasecmp (name
, "sv") == 0)
1761 else if (strcasecmp (name
, "od") == 0)
1763 else if (strcasecmp (name
, "n") == 0)
1765 else if (strcasecmp (name
, "tr") == 0)
1770 else if (strcmp (name
, "<>") == 0)
1775 else if (strcmp (name
, ">=") == 0)
1780 else if (strcmp (name
, ">") == 0)
1785 else if (strcasecmp (name
, "uv") == 0)
1790 else if (strcasecmp (name
, "vnz") == 0)
1795 else if (strcasecmp (name
, "nsv") == 0)
1800 else if (strcasecmp (name
, "ev") == 0)
1806 as_bad ("Invalid Add Condition: %s", name
);
1809 nullif
= pa_parse_nullif (&s
);
1810 opcode
|= nullif
<< 1;
1811 opcode
|= cmpltr
<< 13;
1812 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1814 /* HANDLE a logical instruction condition. */
1822 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1826 if (strcmp (name
, "=") == 0)
1828 else if (strcmp (name
, "<") == 0)
1830 else if (strcmp (name
, "<=") == 0)
1832 else if (strcasecmp (name
, "od") == 0)
1834 else if (strcasecmp (name
, "tr") == 0)
1839 else if (strcmp (name
, "<>") == 0)
1844 else if (strcmp (name
, ">=") == 0)
1849 else if (strcmp (name
, ">") == 0)
1854 else if (strcasecmp (name
, "ev") == 0)
1860 as_bad ("Invalid Logical Instruction Condition.");
1863 opcode
|= cmpltr
<< 13;
1864 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1866 /* Handle a unit instruction condition. */
1873 if (strncasecmp (s
, "sbz", 3) == 0)
1878 else if (strncasecmp (s
, "shz", 3) == 0)
1883 else if (strncasecmp (s
, "sdc", 3) == 0)
1888 else if (strncasecmp (s
, "sbc", 3) == 0)
1893 else if (strncasecmp (s
, "shc", 3) == 0)
1898 else if (strncasecmp (s
, "tr", 2) == 0)
1904 else if (strncasecmp (s
, "nbz", 3) == 0)
1910 else if (strncasecmp (s
, "nhz", 3) == 0)
1916 else if (strncasecmp (s
, "ndc", 3) == 0)
1922 else if (strncasecmp (s
, "nbc", 3) == 0)
1928 else if (strncasecmp (s
, "nhc", 3) == 0)
1935 as_bad ("Invalid Logical Instruction Condition.");
1937 opcode
|= cmpltr
<< 13;
1938 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1940 /* Handle a shift/extract/deposit condition. */
1948 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1952 if (strcmp (name
, "=") == 0)
1954 else if (strcmp (name
, "<") == 0)
1956 else if (strcasecmp (name
, "od") == 0)
1958 else if (strcasecmp (name
, "tr") == 0)
1960 else if (strcmp (name
, "<>") == 0)
1962 else if (strcmp (name
, ">=") == 0)
1964 else if (strcasecmp (name
, "ev") == 0)
1966 /* Handle movb,n. Put things back the way they were.
1967 This includes moving s back to where it started. */
1968 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1975 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1978 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1980 /* Handle bvb and bb conditions. */
1986 if (strncmp (s
, "<", 1) == 0)
1991 else if (strncmp (s
, ">=", 2) == 0)
1997 as_bad ("Invalid Bit Branch Condition: %c", *s
);
1999 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2001 /* Handle a system control completer. */
2003 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2011 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2013 /* Handle a nullification completer for branch instructions. */
2015 nullif
= pa_parse_nullif (&s
);
2016 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2018 /* Handle a nullification completer for copr and spop insns. */
2020 nullif
= pa_parse_nullif (&s
);
2021 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2023 /* Handle a 11 bit immediate at 31. */
2025 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2028 if (the_insn
.exp
.X_op
== O_constant
)
2030 num
= evaluate_absolute (&the_insn
);
2031 CHECK_FIELD (num
, 1023, -1024, 0);
2032 low_sign_unext (num
, 11, &num
);
2033 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2037 if (is_DP_relative (the_insn
.exp
))
2038 the_insn
.reloc
= R_HPPA_GOTOFF
;
2039 else if (is_PC_relative (the_insn
.exp
))
2040 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2041 else if (is_complex (the_insn
.exp
))
2042 the_insn
.reloc
= R_HPPA_COMPLEX
;
2044 the_insn
.reloc
= R_HPPA
;
2045 the_insn
.format
= 11;
2049 /* Handle a 14 bit immediate at 31. */
2051 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2054 if (the_insn
.exp
.X_op
== O_constant
)
2056 num
= evaluate_absolute (&the_insn
);
2057 CHECK_FIELD (num
, 8191, -8192, 0);
2058 low_sign_unext (num
, 14, &num
);
2059 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2063 if (is_DP_relative (the_insn
.exp
))
2064 the_insn
.reloc
= R_HPPA_GOTOFF
;
2065 else if (is_PC_relative (the_insn
.exp
))
2066 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2067 else if (is_complex (the_insn
.exp
))
2068 the_insn
.reloc
= R_HPPA_COMPLEX
;
2070 the_insn
.reloc
= R_HPPA
;
2071 the_insn
.format
= 14;
2075 /* Handle a 21 bit immediate at 31. */
2077 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2080 if (the_insn
.exp
.X_op
== O_constant
)
2082 num
= evaluate_absolute (&the_insn
);
2083 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2084 dis_assemble_21 (num
, &num
);
2085 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2089 if (is_DP_relative (the_insn
.exp
))
2090 the_insn
.reloc
= R_HPPA_GOTOFF
;
2091 else if (is_PC_relative (the_insn
.exp
))
2092 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2093 else if (is_complex (the_insn
.exp
))
2094 the_insn
.reloc
= R_HPPA_COMPLEX
;
2096 the_insn
.reloc
= R_HPPA
;
2097 the_insn
.format
= 21;
2101 /* Handle a 12 bit branch displacement. */
2103 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2107 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2109 unsigned int w1
, w
, result
;
2111 num
= evaluate_absolute (&the_insn
);
2114 as_bad ("Branch to unaligned address");
2117 CHECK_FIELD (num
, 8191, -8192, 0);
2118 sign_unext ((num
- 8) >> 2, 12, &result
);
2119 dis_assemble_12 (result
, &w1
, &w
);
2120 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2124 if (is_complex (the_insn
.exp
))
2125 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2127 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2128 the_insn
.format
= 12;
2129 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2130 bzero (&last_call_desc
, sizeof (struct call_desc
));
2135 /* Handle a 17 bit branch displacement. */
2137 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2141 if (!the_insn
.exp
.X_add_symbol
2142 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2145 unsigned int w2
, w1
, w
, result
;
2147 num
= evaluate_absolute (&the_insn
);
2150 as_bad ("Branch to unaligned address");
2153 CHECK_FIELD (num
, 262143, -262144, 0);
2155 if (the_insn
.exp
.X_add_symbol
)
2158 sign_unext (num
>> 2, 17, &result
);
2159 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2160 INSERT_FIELD_AND_CONTINUE (opcode
,
2161 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2165 if (is_complex (the_insn
.exp
))
2166 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2168 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2169 the_insn
.format
= 17;
2170 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2171 bzero (&last_call_desc
, sizeof (struct call_desc
));
2175 /* Handle an absolute 17 bit branch target. */
2177 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2181 if (!the_insn
.exp
.X_add_symbol
2182 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2185 unsigned int w2
, w1
, w
, result
;
2187 num
= evaluate_absolute (&the_insn
);
2190 as_bad ("Branch to unaligned address");
2193 CHECK_FIELD (num
, 262143, -262144, 0);
2195 if (the_insn
.exp
.X_add_symbol
)
2198 sign_unext (num
>> 2, 17, &result
);
2199 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2200 INSERT_FIELD_AND_CONTINUE (opcode
,
2201 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2205 if (is_complex (the_insn
.exp
))
2206 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2208 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2209 the_insn
.format
= 17;
2213 /* Handle a 5 bit shift count at 26. */
2215 num
= pa_get_absolute_expression (&the_insn
, &s
);
2217 CHECK_FIELD (num
, 31, 0, 0);
2218 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2220 /* Handle a 5 bit bit position at 26. */
2222 num
= pa_get_absolute_expression (&the_insn
, &s
);
2224 CHECK_FIELD (num
, 31, 0, 0);
2225 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2227 /* Handle a 5 bit immediate at 10. */
2229 num
= pa_get_absolute_expression (&the_insn
, &s
);
2231 CHECK_FIELD (num
, 31, 0, 0);
2232 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2234 /* Handle a 13 bit immediate at 18. */
2236 num
= pa_get_absolute_expression (&the_insn
, &s
);
2238 CHECK_FIELD (num
, 4095, -4096, 0);
2239 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2241 /* Handle a 26 bit immediate at 31. */
2243 num
= pa_get_absolute_expression (&the_insn
, &s
);
2245 CHECK_FIELD (num
, 671108864, 0, 0);
2246 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2248 /* Handle a 3 bit SFU identifier at 25. */
2251 as_bad ("Invalid SFU identifier");
2252 num
= pa_get_absolute_expression (&the_insn
, &s
);
2254 CHECK_FIELD (num
, 7, 0, 0);
2255 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2257 /* Handle a 20 bit SOP field for spop0. */
2259 num
= pa_get_absolute_expression (&the_insn
, &s
);
2261 CHECK_FIELD (num
, 1048575, 0, 0);
2262 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2263 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2265 /* Handle a 15bit SOP field for spop1. */
2267 num
= pa_get_absolute_expression (&the_insn
, &s
);
2269 CHECK_FIELD (num
, 32767, 0, 0);
2270 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2272 /* Handle a 10bit SOP field for spop3. */
2274 num
= pa_get_absolute_expression (&the_insn
, &s
);
2276 CHECK_FIELD (num
, 1023, 0, 0);
2277 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2278 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2280 /* Handle a 15 bit SOP field for spop2. */
2282 num
= pa_get_absolute_expression (&the_insn
, &s
);
2284 CHECK_FIELD (num
, 32767, 0, 0);
2285 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2286 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2288 /* Handle a 3-bit co-processor ID field. */
2291 as_bad ("Invalid COPR identifier");
2292 num
= pa_get_absolute_expression (&the_insn
, &s
);
2294 CHECK_FIELD (num
, 7, 0, 0);
2295 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2297 /* Handle a 22bit SOP field for copr. */
2299 num
= pa_get_absolute_expression (&the_insn
, &s
);
2301 CHECK_FIELD (num
, 4194303, 0, 0);
2302 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2303 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2305 /* Handle a source FP operand format completer. */
2307 flag
= pa_parse_fp_format (&s
);
2308 the_insn
.fpof1
= flag
;
2309 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2311 /* Handle a destination FP operand format completer. */
2313 /* pa_parse_format needs the ',' prefix. */
2315 flag
= pa_parse_fp_format (&s
);
2316 the_insn
.fpof2
= flag
;
2317 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2319 /* Handle FP compare conditions. */
2321 cond
= pa_parse_fp_cmp_cond (&s
);
2322 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2324 /* Handle L/R register halves like 't'. */
2327 struct pa_89_fp_reg_struct result
;
2329 pa_parse_number (&s
, &result
);
2330 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2331 opcode
|= result
.number_part
;
2333 /* 0x30 opcodes are FP arithmetic operation opcodes
2334 and need to be turned into 0x38 opcodes. This
2335 is not necessary for loads/stores. */
2336 if (need_89_opcode (&the_insn
, &result
)
2337 && ((opcode
& 0xfc000000) == 0x30000000))
2340 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2343 /* Handle L/R register halves like 'b'. */
2346 struct pa_89_fp_reg_struct result
;
2348 pa_parse_number (&s
, &result
);
2349 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2350 opcode
|= result
.number_part
<< 21;
2351 if (need_89_opcode (&the_insn
, &result
))
2353 opcode
|= (result
.l_r_select
& 1) << 7;
2359 /* Handle L/R register halves like 'x'. */
2362 struct pa_89_fp_reg_struct result
;
2364 pa_parse_number (&s
, &result
);
2365 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2366 opcode
|= (result
.number_part
& 0x1f) << 16;
2367 if (need_89_opcode (&the_insn
, &result
))
2369 opcode
|= (result
.l_r_select
& 1) << 12;
2375 /* Handle a 5 bit register field at 10. */
2378 struct pa_89_fp_reg_struct result
;
2380 pa_parse_number (&s
, &result
);
2381 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2382 if (the_insn
.fpof1
== SGL
)
2384 result
.number_part
&= 0xF;
2385 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2387 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2390 /* Handle a 5 bit register field at 15. */
2393 struct pa_89_fp_reg_struct result
;
2395 pa_parse_number (&s
, &result
);
2396 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2397 if (the_insn
.fpof1
== SGL
)
2399 result
.number_part
&= 0xF;
2400 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2402 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2405 /* Handle a 5 bit register field at 31. */
2408 struct pa_89_fp_reg_struct result
;
2410 pa_parse_number (&s
, &result
);
2411 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2412 if (the_insn
.fpof1
== SGL
)
2414 result
.number_part
&= 0xF;
2415 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2417 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2420 /* Handle a 5 bit register field at 20. */
2423 struct pa_89_fp_reg_struct result
;
2425 pa_parse_number (&s
, &result
);
2426 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2427 if (the_insn
.fpof1
== SGL
)
2429 result
.number_part
&= 0xF;
2430 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2432 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2435 /* Handle a 5 bit register field at 25. */
2438 struct pa_89_fp_reg_struct result
;
2440 pa_parse_number (&s
, &result
);
2441 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2442 if (the_insn
.fpof1
== SGL
)
2444 result
.number_part
&= 0xF;
2445 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2447 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2450 /* Handle a floating point operand format at 26.
2451 Only allows single and double precision. */
2453 flag
= pa_parse_fp_format (&s
);
2459 the_insn
.fpof1
= flag
;
2465 as_bad ("Invalid Floating Point Operand Format.");
2475 /* Check if the args matched. */
2478 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2479 && !strcmp (insn
->name
, insn
[1].name
))
2487 as_bad ("Invalid operands %s", error_message
);
2494 the_insn
.opcode
= opcode
;
2497 /* Turn a string in input_line_pointer into a floating point constant of type
2498 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2499 emitted is stored in *sizeP . An error message or NULL is returned. */
2501 #define MAX_LITTLENUMS 6
2504 md_atof (type
, litP
, sizeP
)
2510 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2511 LITTLENUM_TYPE
*wordP
;
2543 return "Bad call to MD_ATOF()";
2545 t
= atof_ieee (input_line_pointer
, type
, words
);
2547 input_line_pointer
= t
;
2548 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2549 for (wordP
= words
; prec
--;)
2551 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2552 litP
+= sizeof (LITTLENUM_TYPE
);
2557 /* Write out big-endian. */
2560 md_number_to_chars (buf
, val
, n
)
2565 number_to_chars_bigendian (buf
, val
, n
);
2568 /* Translate internal representation of relocation info to BFD target
2572 tc_gen_reloc (section
, fixp
)
2577 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2578 bfd_reloc_code_real_type code
;
2579 static int unwind_reloc_fixp_cnt
= 0;
2580 static arelent
*unwind_reloc_entryP
= NULL
;
2581 static arelent
*no_relocs
= NULL
;
2583 bfd_reloc_code_real_type
**codes
;
2587 if (fixp
->fx_addsy
== 0)
2589 assert (hppa_fixp
!= 0);
2590 assert (section
!= 0);
2593 /* Yuk. I would really like to push all this ELF specific unwind
2594 crud into BFD and the linker. That's how SOM does it -- and
2595 if we could make ELF emulate that then we could share more code
2596 in GAS (and potentially a gnu-linker later).
2598 Unwind section relocations are handled in a special way.
2599 The relocations for the .unwind section are originally
2600 built in the usual way. That is, for each unwind table
2601 entry there are two relocations: one for the beginning of
2602 the function and one for the end.
2604 The first time we enter this function we create a
2605 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2606 of the relocation is initialized to 0. Each additional
2607 pair of times this function is called for the unwind
2608 section represents an additional unwind table entry. Thus,
2609 the addend of the relocation should end up to be the number
2610 of unwind table entries. */
2611 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2613 if (unwind_reloc_entryP
== NULL
)
2615 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2617 assert (reloc
!= 0);
2618 unwind_reloc_entryP
= reloc
;
2619 unwind_reloc_fixp_cnt
++;
2620 unwind_reloc_entryP
->address
2621 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2622 /* A pointer to any function will do. We only
2623 need one to tell us what section the unwind
2624 relocations are for. */
2625 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2626 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2627 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2628 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2629 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2630 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2631 sizeof (arelent
*) * 2);
2632 assert (relocs
!= 0);
2633 relocs
[0] = unwind_reloc_entryP
;
2637 unwind_reloc_fixp_cnt
++;
2638 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2644 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2645 assert (reloc
!= 0);
2647 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2648 codes
= hppa_gen_reloc_type (stdoutput
,
2650 hppa_fixp
->fx_r_format
,
2651 hppa_fixp
->fx_r_field
);
2653 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2656 relocs
= (arelent
**)
2657 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2658 assert (relocs
!= 0);
2660 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2661 sizeof (arelent
) * n_relocs
);
2663 assert (reloc
!= 0);
2665 for (i
= 0; i
< n_relocs
; i
++)
2666 relocs
[i
] = &reloc
[i
];
2668 relocs
[n_relocs
] = NULL
;
2671 switch (fixp
->fx_r_type
)
2673 case R_HPPA_COMPLEX
:
2674 case R_HPPA_COMPLEX_PCREL_CALL
:
2675 case R_HPPA_COMPLEX_ABS_CALL
:
2676 assert (n_relocs
== 5);
2678 for (i
= 0; i
< n_relocs
; i
++)
2680 reloc
[i
].sym_ptr_ptr
= NULL
;
2681 reloc
[i
].address
= 0;
2682 reloc
[i
].addend
= 0;
2683 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2684 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2687 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2688 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2689 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2691 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2692 reloc
[3].addend
= fixp
->fx_addnumber
;
2693 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2694 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2695 reloc
[1].addend
= fixp
->fx_addnumber
;
2700 assert (n_relocs
== 1);
2704 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2705 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2706 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2707 reloc
->addend
= 0; /* default */
2709 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2711 /* Now, do any processing that is dependent on the relocation type. */
2714 case R_HPPA_PLABEL_32
:
2715 case R_HPPA_PLABEL_11
:
2716 case R_HPPA_PLABEL_14
:
2717 case R_HPPA_PLABEL_L21
:
2718 case R_HPPA_PLABEL_R11
:
2719 case R_HPPA_PLABEL_R14
:
2720 /* For plabel relocations, the addend of the
2721 relocation should be either 0 (no static link) or 2
2722 (static link required).
2724 FIXME: We always assume no static link! */
2728 case R_HPPA_ABS_CALL_11
:
2729 case R_HPPA_ABS_CALL_14
:
2730 case R_HPPA_ABS_CALL_17
:
2731 case R_HPPA_ABS_CALL_L21
:
2732 case R_HPPA_ABS_CALL_R11
:
2733 case R_HPPA_ABS_CALL_R14
:
2734 case R_HPPA_ABS_CALL_R17
:
2735 case R_HPPA_ABS_CALL_LS21
:
2736 case R_HPPA_ABS_CALL_RS11
:
2737 case R_HPPA_ABS_CALL_RS14
:
2738 case R_HPPA_ABS_CALL_RS17
:
2739 case R_HPPA_ABS_CALL_LD21
:
2740 case R_HPPA_ABS_CALL_RD11
:
2741 case R_HPPA_ABS_CALL_RD14
:
2742 case R_HPPA_ABS_CALL_RD17
:
2743 case R_HPPA_ABS_CALL_LR21
:
2744 case R_HPPA_ABS_CALL_RR14
:
2745 case R_HPPA_ABS_CALL_RR17
:
2747 case R_HPPA_PCREL_CALL_11
:
2748 case R_HPPA_PCREL_CALL_14
:
2749 case R_HPPA_PCREL_CALL_17
:
2750 case R_HPPA_PCREL_CALL_L21
:
2751 case R_HPPA_PCREL_CALL_R11
:
2752 case R_HPPA_PCREL_CALL_R14
:
2753 case R_HPPA_PCREL_CALL_R17
:
2754 case R_HPPA_PCREL_CALL_LS21
:
2755 case R_HPPA_PCREL_CALL_RS11
:
2756 case R_HPPA_PCREL_CALL_RS14
:
2757 case R_HPPA_PCREL_CALL_RS17
:
2758 case R_HPPA_PCREL_CALL_LD21
:
2759 case R_HPPA_PCREL_CALL_RD11
:
2760 case R_HPPA_PCREL_CALL_RD14
:
2761 case R_HPPA_PCREL_CALL_RD17
:
2762 case R_HPPA_PCREL_CALL_LR21
:
2763 case R_HPPA_PCREL_CALL_RR14
:
2764 case R_HPPA_PCREL_CALL_RR17
:
2765 /* The constant is stored in the instruction. */
2766 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2769 reloc
->addend
= fixp
->fx_addnumber
;
2776 /* Walk over reach relocation returned by the BFD backend. */
2777 for (i
= 0; i
< n_relocs
; i
++)
2781 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2782 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2783 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2789 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2794 /* For plabel relocations, the addend of the
2795 relocation should be either 0 (no static link) or 2
2796 (static link required).
2798 FIXME: We always assume no static link! */
2799 relocs
[i
]->addend
= 0;
2810 /* There is no symbol or addend associated with these fixups. */
2811 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2812 relocs
[i
]->addend
= 0;
2816 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2825 /* Process any machine dependent frag types. */
2828 md_convert_frag (abfd
, sec
, fragP
)
2830 register asection
*sec
;
2831 register fragS
*fragP
;
2833 unsigned int address
;
2835 if (fragP
->fr_type
== rs_machine_dependent
)
2837 switch ((int) fragP
->fr_subtype
)
2840 fragP
->fr_type
= rs_fill
;
2841 know (fragP
->fr_var
== 1);
2842 know (fragP
->fr_next
);
2843 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2844 if (address
% fragP
->fr_offset
)
2847 fragP
->fr_next
->fr_address
2852 fragP
->fr_offset
= 0;
2858 /* Round up a section size to the appropriate boundary. */
2861 md_section_align (segment
, size
)
2865 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2866 int align2
= (1 << align
) - 1;
2868 return (size
+ align2
) & ~align2
;
2871 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2873 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2875 addressT from_addr
, to_addr
;
2879 fprintf (stderr
, "pa_create_short_jmp\n");
2883 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2885 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2887 addressT from_addr
, to_addr
;
2891 fprintf (stderr
, "pa_create_long_jump\n");
2895 /* Return the approximate size of a frag before relaxation has occurred. */
2897 md_estimate_size_before_relax (fragP
, segment
)
2898 register fragS
*fragP
;
2905 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2911 /* Parse machine dependent options. There are none on the PA. */
2913 md_parse_option (argP
, cntP
, vecP
)
2921 /* We have no need to default values of symbols. */
2924 md_undefined_symbol (name
)
2930 /* Parse an operand that is machine-specific.
2931 We just return without modifying the expression as we have nothing
2935 md_operand (expressionP
)
2936 expressionS
*expressionP
;
2940 /* Apply a fixup to an instruction. */
2943 md_apply_fix (fixP
, valp
)
2947 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2948 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
2949 long new_val
, result
;
2950 unsigned int w1
, w2
, w
;
2953 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2954 never be "applied" (they are just markers). */
2956 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2957 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2961 /* There should have been an HPPA specific fixup associated
2962 with the GAS fixup. */
2965 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2966 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2968 if (fixP
->fx_r_type
== R_HPPA_NONE
)
2971 /* Remember this value for emit_reloc. FIXME, is this braindamage
2972 documented anywhere!?! */
2973 fixP
->fx_addnumber
= val
;
2975 /* Check if this is an undefined symbol. No relocation can
2976 possibly be performed in this case.
2978 Also avoid doing anything for pc-relative fixups in which the
2979 fixup is in a different space than the symbol it references. */
2980 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
2982 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
)
2985 && S_GET_SEGMENT (fixP
->fx_addsy
) != hppa_fixP
->segment
)
2988 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2991 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
2992 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
2993 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
2994 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
2995 && hppa_fixP
->fx_r_field
!= R_HPPA_TSEL
2996 && hppa_fixP
->fx_r_field
!= R_HPPA_LTSEL
2997 && hppa_fixP
->fx_r_field
!= R_HPPA_RTSEL
)
2998 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3004 /* Handle all opcodes with the 'j' operand type. */
3006 CHECK_FIELD (new_val
, 8191, -8192, 0);
3008 /* Mask off 14 bits to be changed. */
3009 bfd_put_32 (stdoutput
,
3010 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3012 low_sign_unext (new_val
, 14, &result
);
3015 /* Handle all opcodes with the 'k' operand type. */
3017 CHECK_FIELD (new_val
, 2097152, 0, 0);
3019 /* Mask off 21 bits to be changed. */
3020 bfd_put_32 (stdoutput
,
3021 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3023 dis_assemble_21 (new_val
, &result
);
3026 /* Handle all the opcodes with the 'i' operand type. */
3028 CHECK_FIELD (new_val
, 1023, -1023, 0);
3030 /* Mask off 11 bits to be changed. */
3031 bfd_put_32 (stdoutput
,
3032 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3034 low_sign_unext (new_val
, 11, &result
);
3037 /* Handle all the opcodes with the 'w' operand type. */
3039 CHECK_FIELD (new_val
, 8191, -8192, 0)
3041 /* Mask off 11 bits to be changed. */
3042 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3043 bfd_put_32 (stdoutput
,
3044 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3047 dis_assemble_12 (result
, &w1
, &w
);
3048 result
= ((w1
<< 2) | w
);
3051 /* Handle some of the opcodes with the 'W' operand type. */
3054 #define stub_needed(CALLER, CALLEE) \
3055 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3056 /* It is necessary to force PC-relative calls/jumps to have a
3057 relocation entry if they're going to need either a argument
3058 relocation or long call stub. FIXME. Can't we need the same
3059 for absolute calls? */
3061 && (stub_needed (((obj_symbol_type
*)
3062 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3063 hppa_fixP
->fx_arg_reloc
)))
3067 CHECK_FIELD (new_val
, 262143, -262144, 0);
3069 /* Mask off 17 bits to be changed. */
3070 bfd_put_32 (stdoutput
,
3071 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3073 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3074 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3075 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3080 /* These are ELF specific relocations. ELF unfortunately
3081 handles unwinds in a completely different manner. */
3082 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3083 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3084 result
= fixP
->fx_addnumber
;
3089 fixP
->fx_addnumber
= fixP
->fx_offset
;
3090 /* If we have a real relocation, then we want zero to
3091 be stored in the object file. If no relocation is going
3092 to be emitted, then we need to store new_val into the
3095 bfd_put_32 (stdoutput
, 0, buf
);
3097 bfd_put_32 (stdoutput
, new_val
, buf
);
3106 as_bad ("Unknown relocation encountered in md_apply_fix.");
3110 /* Insert the relocation. */
3111 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3116 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3117 (unsigned int) fixP
, fixP
->fx_r_type
);
3122 /* Exactly what point is a PC-relative offset relative TO?
3123 On the PA, they're relative to the address of the offset. */
3126 md_pcrel_from (fixP
)
3129 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3132 /* Return nonzero if the input line pointer is at the end of
3136 is_end_of_statement ()
3138 return ((*input_line_pointer
== '\n')
3139 || (*input_line_pointer
== ';')
3140 || (*input_line_pointer
== '!'));
3143 /* Read a number from S. The number might come in one of many forms,
3144 the most common will be a hex or decimal constant, but it could be
3145 a pre-defined register (Yuk!), or an absolute symbol.
3147 Return a number or -1 for failure.
3149 When parsing PA-89 FP register numbers RESULT will be
3150 the address of a structure to return information about
3151 L/R half of FP registers, store results there as appropriate.
3153 pa_parse_number can not handle negative constants and will fail
3154 horribly if it is passed such a constant. */
3157 pa_parse_number (s
, result
)
3159 struct pa_89_fp_reg_struct
*result
;
3168 /* Skip whitespace before the number. */
3169 while (*p
== ' ' || *p
== '\t')
3172 /* Store info in RESULT if requested by caller. */
3175 result
->number_part
= -1;
3176 result
->l_r_select
= -1;
3182 /* Looks like a number. */
3185 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3187 /* The number is specified in hex. */
3189 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3190 || ((*p
>= 'A') && (*p
<= 'F')))
3193 num
= num
* 16 + *p
- '0';
3194 else if (*p
>= 'a' && *p
<= 'f')
3195 num
= num
* 16 + *p
- 'a' + 10;
3197 num
= num
* 16 + *p
- 'A' + 10;
3203 /* The number is specified in decimal. */
3204 while (isdigit (*p
))
3206 num
= num
* 10 + *p
- '0';
3211 /* Store info in RESULT if requested by the caller. */
3214 result
->number_part
= num
;
3216 if (IS_R_SELECT (p
))
3218 result
->l_r_select
= 1;
3221 else if (IS_L_SELECT (p
))
3223 result
->l_r_select
= 0;
3227 result
->l_r_select
= 0;
3232 /* The number might be a predefined register. */
3237 /* Tege hack: Special case for general registers as the general
3238 code makes a binary search with case translation, and is VERY
3243 if (*p
== 'e' && *(p
+ 1) == 't'
3244 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3247 num
= *p
- '0' + 28;
3255 else if (!isdigit (*p
))
3258 as_bad ("Undefined register: '%s'.", name
);
3264 num
= num
* 10 + *p
++ - '0';
3265 while (isdigit (*p
));
3270 /* Do a normal register search. */
3271 while (is_part_of_name (c
))
3277 status
= reg_name_search (name
);
3283 as_bad ("Undefined register: '%s'.", name
);
3289 /* Store info in RESULT if requested by caller. */
3292 result
->number_part
= num
;
3293 if (IS_R_SELECT (p
- 1))
3294 result
->l_r_select
= 1;
3295 else if (IS_L_SELECT (p
- 1))
3296 result
->l_r_select
= 0;
3298 result
->l_r_select
= 0;
3303 /* And finally, it could be a symbol in the absolute section which
3304 is effectively a constant. */
3308 while (is_part_of_name (c
))
3314 if ((sym
= symbol_find (name
)) != NULL
)
3316 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3317 num
= S_GET_VALUE (sym
);
3321 as_bad ("Non-absolute symbol: '%s'.", name
);
3327 /* There is where we'd come for an undefined symbol
3328 or for an empty string. For an empty string we
3329 will return zero. That's a concession made for
3330 compatability with the braindamaged HP assemblers. */
3336 as_bad ("Undefined absolute constant: '%s'.", name
);
3342 /* Store info in RESULT if requested by caller. */
3345 result
->number_part
= num
;
3346 if (IS_R_SELECT (p
- 1))
3347 result
->l_r_select
= 1;
3348 else if (IS_L_SELECT (p
- 1))
3349 result
->l_r_select
= 0;
3351 result
->l_r_select
= 0;
3359 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3361 /* Given NAME, find the register number associated with that name, return
3362 the integer value associated with the given name or -1 on failure. */
3365 reg_name_search (name
)
3368 int middle
, low
, high
;
3372 high
= REG_NAME_CNT
- 1;
3376 middle
= (low
+ high
) / 2;
3377 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3383 return pre_defined_registers
[middle
].value
;
3385 while (low
<= high
);
3391 /* Return nonzero if the given INSN and L/R information will require
3392 a new PA-89 opcode. */
3395 need_89_opcode (insn
, result
)
3397 struct pa_89_fp_reg_struct
*result
;
3399 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3405 /* Parse a condition for a fcmp instruction. Return the numerical
3406 code associated with the condition. */
3409 pa_parse_fp_cmp_cond (s
)
3416 for (i
= 0; i
< 32; i
++)
3418 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3419 strlen (fp_cond_map
[i
].string
)) == 0)
3421 cond
= fp_cond_map
[i
].cond
;
3422 *s
+= strlen (fp_cond_map
[i
].string
);
3423 while (**s
== ' ' || **s
== '\t')
3429 as_bad ("Invalid FP Compare Condition: %c", **s
);
3433 /* Parse an FP operand format completer returning the completer
3436 static fp_operand_format
3437 pa_parse_fp_format (s
)
3446 if (strncasecmp (*s
, "sgl", 3) == 0)
3451 else if (strncasecmp (*s
, "dbl", 3) == 0)
3456 else if (strncasecmp (*s
, "quad", 4) == 0)
3463 format
= ILLEGAL_FMT
;
3464 as_bad ("Invalid FP Operand Format: %3s", *s
);
3471 /* Convert from a selector string into a selector type. */
3474 pa_chk_field_selector (str
)
3477 int middle
, low
, high
;
3481 /* Read past any whitespace. */
3482 /* FIXME: should we read past newlines and formfeeds??? */
3483 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3486 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3487 name
[0] = tolower ((*str
)[0]),
3489 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3490 name
[0] = tolower ((*str
)[0]),
3491 name
[1] = tolower ((*str
)[1]),
3497 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3501 middle
= (low
+ high
) / 2;
3502 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3509 *str
+= strlen (name
) + 1;
3510 return selector_table
[middle
].field_selector
;
3513 while (low
<= high
);
3518 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3521 get_expression (str
)
3527 save_in
= input_line_pointer
;
3528 input_line_pointer
= str
;
3529 seg
= expression (&the_insn
.exp
);
3530 if (!(seg
== absolute_section
3531 || seg
== undefined_section
3532 || SEG_NORMAL (seg
)))
3534 as_warn ("Bad segment in expression.");
3535 expr_end
= input_line_pointer
;
3536 input_line_pointer
= save_in
;
3539 expr_end
= input_line_pointer
;
3540 input_line_pointer
= save_in
;
3544 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3546 pa_get_absolute_expression (insn
, strp
)
3552 insn
->field_selector
= pa_chk_field_selector (strp
);
3553 save_in
= input_line_pointer
;
3554 input_line_pointer
= *strp
;
3555 expression (&insn
->exp
);
3556 if (insn
->exp
.X_op
!= O_constant
)
3558 as_bad ("Bad segment (should be absolute).");
3559 expr_end
= input_line_pointer
;
3560 input_line_pointer
= save_in
;
3563 expr_end
= input_line_pointer
;
3564 input_line_pointer
= save_in
;
3565 return evaluate_absolute (insn
);
3568 /* Evaluate an absolute expression EXP which may be modified by
3569 the selector FIELD_SELECTOR. Return the value of the expression. */
3571 evaluate_absolute (insn
)
3576 int field_selector
= insn
->field_selector
;
3579 value
= exp
.X_add_number
;
3581 switch (field_selector
)
3587 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3589 if (value
& 0x00000400)
3591 value
= (value
& 0xfffff800) >> 11;
3594 /* Sign extend from bit 21. */
3596 if (value
& 0x00000400)
3597 value
|= 0xfffff800;
3602 /* Arithmetic shift right 11 bits. */
3604 value
= (value
& 0xfffff800) >> 11;
3607 /* Set bits 0-20 to zero. */
3609 value
= value
& 0x7ff;
3612 /* Add 0x800 and arithmetic shift right 11 bits. */
3615 value
= (value
& 0xfffff800) >> 11;
3618 /* Set bitgs 0-21 to one. */
3620 value
|= 0xfffff800;
3623 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3625 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3629 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3634 BAD_CASE (field_selector
);
3640 /* Given an argument location specification return the associated
3641 argument location number. */
3644 pa_build_arg_reloc (type_name
)
3648 if (strncasecmp (type_name
, "no", 2) == 0)
3650 if (strncasecmp (type_name
, "gr", 2) == 0)
3652 else if (strncasecmp (type_name
, "fr", 2) == 0)
3654 else if (strncasecmp (type_name
, "fu", 2) == 0)
3657 as_bad ("Invalid argument location: %s\n", type_name
);
3662 /* Encode and return an argument relocation specification for
3663 the given register in the location specified by arg_reloc. */
3666 pa_align_arg_reloc (reg
, arg_reloc
)
3668 unsigned int arg_reloc
;
3670 unsigned int new_reloc
;
3672 new_reloc
= arg_reloc
;
3688 as_bad ("Invalid argument description: %d", reg
);
3694 /* Parse a PA nullification completer (,n). Return nonzero if the
3695 completer was found; return zero if no completer was found. */
3707 if (strncasecmp (*s
, "n", 1) == 0)
3711 as_bad ("Invalid Nullification: (%c)", **s
);
3720 /* Parse a non-negated compare/subtract completer returning the
3721 number (for encoding in instrutions) of the given completer.
3723 ISBRANCH specifies whether or not this is parsing a condition
3724 completer for a branch (vs a nullification completer for a
3725 computational instruction. */
3728 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3733 char *name
= *s
+ 1;
3741 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3745 if (strcmp (name
, "=") == 0)
3749 else if (strcmp (name
, "<") == 0)
3753 else if (strcmp (name
, "<=") == 0)
3757 else if (strcmp (name
, "<<") == 0)
3761 else if (strcmp (name
, "<<=") == 0)
3765 else if (strcasecmp (name
, "sv") == 0)
3769 else if (strcasecmp (name
, "od") == 0)
3773 /* If we have something like addb,n then there is no condition
3775 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3786 /* Reset pointers if this was really a ,n for a branch instruction. */
3787 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3793 /* Parse a negated compare/subtract completer returning the
3794 number (for encoding in instrutions) of the given completer.
3796 ISBRANCH specifies whether or not this is parsing a condition
3797 completer for a branch (vs a nullification completer for a
3798 computational instruction. */
3801 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3806 char *name
= *s
+ 1;
3814 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3818 if (strcasecmp (name
, "tr") == 0)
3822 else if (strcmp (name
, "<>") == 0)
3826 else if (strcmp (name
, ">=") == 0)
3830 else if (strcmp (name
, ">") == 0)
3834 else if (strcmp (name
, ">>=") == 0)
3838 else if (strcmp (name
, ">>") == 0)
3842 else if (strcasecmp (name
, "nsv") == 0)
3846 else if (strcasecmp (name
, "ev") == 0)
3850 /* If we have something like addb,n then there is no condition
3852 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3863 /* Reset pointers if this was really a ,n for a branch instruction. */
3864 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3870 /* Parse a non-negated addition completer returning the number
3871 (for encoding in instrutions) of the given completer.
3873 ISBRANCH specifies whether or not this is parsing a condition
3874 completer for a branch (vs a nullification completer for a
3875 computational instruction. */
3878 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3883 char *name
= *s
+ 1;
3891 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3895 if (strcmp (name
, "=") == 0)
3899 else if (strcmp (name
, "<") == 0)
3903 else if (strcmp (name
, "<=") == 0)
3907 else if (strcasecmp (name
, "nuv") == 0)
3911 else if (strcasecmp (name
, "znv") == 0)
3915 else if (strcasecmp (name
, "sv") == 0)
3919 else if (strcasecmp (name
, "od") == 0)
3923 /* If we have something like addb,n then there is no condition
3925 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3936 /* Reset pointers if this was really a ,n for a branch instruction. */
3937 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3943 /* Parse a negated addition completer returning the number
3944 (for encoding in instrutions) of the given completer.
3946 ISBRANCH specifies whether or not this is parsing a condition
3947 completer for a branch (vs a nullification completer for a
3948 computational instruction. */
3951 pa_parse_neg_add_cmpltr (s
, isbranch
)
3956 char *name
= *s
+ 1;
3964 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3968 if (strcasecmp (name
, "tr") == 0)
3972 else if (strcmp (name
, "<>") == 0)
3976 else if (strcmp (name
, ">=") == 0)
3980 else if (strcmp (name
, ">") == 0)
3984 else if (strcasecmp (name
, "uv") == 0)
3988 else if (strcasecmp (name
, "vnz") == 0)
3992 else if (strcasecmp (name
, "nsv") == 0)
3996 else if (strcasecmp (name
, "ev") == 0)
4000 /* If we have something like addb,n then there is no condition
4002 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4013 /* Reset pointers if this was really a ,n for a branch instruction. */
4014 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4020 /* Handle a .BLOCK type pseudo-op. */
4028 unsigned int temp_size
;
4031 temp_size
= get_absolute_expression ();
4033 /* Always fill with zeros, that's what the HP assembler does. */
4036 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4037 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4038 bzero (p
, temp_size
);
4040 /* Convert 2 bytes at a time. */
4042 for (i
= 0; i
< temp_size
; i
+= 2)
4044 md_number_to_chars (p
+ i
,
4046 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4049 pa_undefine_label ();
4050 demand_empty_rest_of_line ();
4053 /* Handle a .CALL pseudo-op. This involves storing away information
4054 about where arguments are to be found so the linker can detect
4055 (and correct) argument location mismatches between caller and callee. */
4061 pa_call_args (&last_call_desc
);
4062 demand_empty_rest_of_line ();
4065 /* Do the dirty work of building a call descriptor which describes
4066 where the caller placed arguments to a function call. */
4069 pa_call_args (call_desc
)
4070 struct call_desc
*call_desc
;
4073 unsigned int temp
, arg_reloc
;
4075 while (!is_end_of_statement ())
4077 name
= input_line_pointer
;
4078 c
= get_symbol_end ();
4079 /* Process a source argument. */
4080 if ((strncasecmp (name
, "argw", 4) == 0))
4082 temp
= atoi (name
+ 4);
4083 p
= input_line_pointer
;
4085 input_line_pointer
++;
4086 name
= input_line_pointer
;
4087 c
= get_symbol_end ();
4088 arg_reloc
= pa_build_arg_reloc (name
);
4089 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4091 /* Process a return value. */
4092 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4094 p
= input_line_pointer
;
4096 input_line_pointer
++;
4097 name
= input_line_pointer
;
4098 c
= get_symbol_end ();
4099 arg_reloc
= pa_build_arg_reloc (name
);
4100 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4104 as_bad ("Invalid .CALL argument: %s", name
);
4106 p
= input_line_pointer
;
4108 if (!is_end_of_statement ())
4109 input_line_pointer
++;
4113 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4116 is_same_frag (frag1
, frag2
)
4123 else if (frag2
== NULL
)
4125 else if (frag1
== frag2
)
4127 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4128 return (is_same_frag (frag1
, frag2
->fr_next
));
4134 /* Build an entry in the UNWIND subspace from the given function
4135 attributes in CALL_INFO. This is not needed for SOM as using
4136 R_ENTRY and R_EXIT relocations allow the linker to handle building
4137 of the unwind spaces. */
4140 pa_build_unwind_subspace (call_info
)
4141 struct call_info
*call_info
;
4144 asection
*seg
, *save_seg
;
4145 subsegT subseg
, save_subseg
;
4149 /* Get into the right seg/subseg. This may involve creating
4150 the seg the first time through. Make sure to have the
4151 old seg/subseg so that we can reset things when we are done. */
4152 subseg
= SUBSEG_UNWIND
;
4153 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4154 if (seg
== ASEC_NULL
)
4156 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4157 bfd_set_section_flags (stdoutput
, seg
,
4158 SEC_READONLY
| SEC_HAS_CONTENTS
4159 | SEC_LOAD
| SEC_RELOC
);
4163 save_subseg
= now_subseg
;
4164 subseg_set (seg
, subseg
);
4167 /* Get some space to hold relocation information for the unwind
4171 /* Relocation info. for start offset of the function. */
4172 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4173 call_info
->start_symbol
, (offsetT
) 0,
4174 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4179 /* Relocation info. for end offset of the function. */
4180 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4181 call_info
->end_symbol
, (offsetT
) 0,
4182 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4186 unwind
= (char *) &call_info
->ci_unwind
;
4187 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4191 FRAG_APPEND_1_CHAR (c
);
4195 /* Return back to the original segment/subsegment. */
4196 subseg_set (save_seg
, save_subseg
);
4200 /* Process a .CALLINFO pseudo-op. This information is used later
4201 to build unwind descriptors and maybe one day to support
4202 .ENTER and .LEAVE. */
4205 pa_callinfo (unused
)
4211 /* .CALLINFO must appear within a procedure definition. */
4212 if (!within_procedure
)
4213 as_bad (".callinfo is not within a procedure definition");
4215 /* Mark the fact that we found the .CALLINFO for the
4216 current procedure. */
4217 callinfo_found
= TRUE
;
4219 /* Iterate over the .CALLINFO arguments. */
4220 while (!is_end_of_statement ())
4222 name
= input_line_pointer
;
4223 c
= get_symbol_end ();
4224 /* Frame size specification. */
4225 if ((strncasecmp (name
, "frame", 5) == 0))
4227 p
= input_line_pointer
;
4229 input_line_pointer
++;
4230 temp
= get_absolute_expression ();
4231 if ((temp
& 0x3) != 0)
4233 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4237 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4238 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4241 /* Entry register (GR, GR and SR) specifications. */
4242 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4244 p
= input_line_pointer
;
4246 input_line_pointer
++;
4247 temp
= get_absolute_expression ();
4248 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4249 even though %r19 is caller saved. I think this is a bug in
4250 the HP assembler, and we are not going to emulate it. */
4251 if (temp
< 3 || temp
> 18)
4252 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4253 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4255 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4257 p
= input_line_pointer
;
4259 input_line_pointer
++;
4260 temp
= get_absolute_expression ();
4261 /* Similarly the HP assembler takes 31 as the high bound even
4262 though %fr21 is the last callee saved floating point register. */
4263 if (temp
< 12 || temp
> 21)
4264 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4265 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4267 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4269 p
= input_line_pointer
;
4271 input_line_pointer
++;
4272 temp
= get_absolute_expression ();
4274 as_bad ("Value for ENTRY_SR must be 3\n");
4276 /* Note whether or not this function performs any calls. */
4277 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4278 (strncasecmp (name
, "caller", 6) == 0))
4280 p
= input_line_pointer
;
4283 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4285 p
= input_line_pointer
;
4288 /* Should RP be saved into the stack. */
4289 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4291 p
= input_line_pointer
;
4293 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4295 /* Likewise for SP. */
4296 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4298 p
= input_line_pointer
;
4300 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4302 /* Is this an unwindable procedure. If so mark it so
4303 in the unwind descriptor. */
4304 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4306 p
= input_line_pointer
;
4308 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4310 /* Is this an interrupt routine. If so mark it in the
4311 unwind descriptor. */
4312 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4314 p
= input_line_pointer
;
4316 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4320 as_bad ("Invalid .CALLINFO argument: %s", name
);
4322 if (!is_end_of_statement ())
4323 input_line_pointer
++;
4326 demand_empty_rest_of_line ();
4329 /* Switch into the code subspace. */
4335 sd_chain_struct
*sdchain
;
4337 /* First time through it might be necessary to create the
4339 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4341 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4342 pa_def_spaces
[0].spnum
,
4343 pa_def_spaces
[0].loadable
,
4344 pa_def_spaces
[0].defined
,
4345 pa_def_spaces
[0].private,
4346 pa_def_spaces
[0].sort
,
4347 pa_def_spaces
[0].segment
, 0);
4350 SPACE_DEFINED (sdchain
) = 1;
4351 subseg_set (text_section
, SUBSEG_CODE
);
4352 demand_empty_rest_of_line ();
4355 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4356 the .comm pseudo-op has the following symtax:
4358 <label> .comm <length>
4360 where <label> is optional and is a symbol whose address will be the start of
4361 a block of memory <length> bytes long. <length> must be an absolute
4362 expression. <length> bytes will be allocated in the current space
4371 label_symbol_struct
*label_symbol
= pa_get_label ();
4374 symbol
= label_symbol
->lss_label
;
4379 size
= get_absolute_expression ();
4383 /* It is incorrect to check S_IS_DEFINED at this point as
4384 the symbol will *always* be defined. FIXME. How to
4385 correctly determine when this label really as been
4387 if (S_GET_VALUE (symbol
))
4389 if (S_GET_VALUE (symbol
) != size
)
4391 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4392 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4398 S_SET_VALUE (symbol
, size
);
4399 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4400 S_SET_EXTERNAL (symbol
);
4403 demand_empty_rest_of_line ();
4406 /* Process a .END pseudo-op. */
4412 demand_empty_rest_of_line ();
4415 /* Process a .ENTER pseudo-op. This is not supported. */
4423 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4429 if (!within_procedure
)
4430 as_bad ("Misplaced .entry. Ignored.");
4433 if (!callinfo_found
)
4434 as_bad ("Missing .callinfo.");
4436 demand_empty_rest_of_line ();
4437 within_entry_exit
= TRUE
;
4440 /* SOM defers building of unwind descriptors until the link phase.
4441 The assembler is responsible for creating an R_ENTRY relocation
4442 to mark the beginning of a region and hold the unwind bits, and
4443 for creating an R_EXIT relocation to mark the end of the region.
4445 FIXME. ELF should be using the same conventions! The problem
4446 is an unwind requires too much relocation space. Hmmm. Maybe
4447 if we split the unwind bits up between the relocations which
4448 denote the entry and exit points. */
4449 if (last_call_info
->start_symbol
!= NULL
)
4451 char *where
= frag_more (0);
4453 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4454 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4455 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4456 (char *) &last_call_info
->ci_unwind
.descriptor
);
4461 /* Handle a .EQU pseudo-op. */
4467 label_symbol_struct
*label_symbol
= pa_get_label ();
4472 symbol
= label_symbol
->lss_label
;
4473 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4474 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4479 as_bad (".REG must use a label");
4481 as_bad (".EQU must use a label");
4484 pa_undefine_label ();
4485 demand_empty_rest_of_line ();
4488 /* Helper function. Does processing for the end of a function. This
4489 usually involves creating some relocations or building special
4490 symbols to mark the end of the function. */
4497 where
= frag_more (0);
4500 /* Mark the end of the function, stuff away the location of the frag
4501 for the end of the function, and finally call pa_build_unwind_subspace
4502 to add an entry in the unwind table. */
4503 hppa_elf_mark_end_of_function ();
4504 pa_build_unwind_subspace (last_call_info
);
4506 /* SOM defers building of unwind descriptors until the link phase.
4507 The assembler is responsible for creating an R_ENTRY relocation
4508 to mark the beginning of a region and hold the unwind bits, and
4509 for creating an R_EXIT relocation to mark the end of the region.
4511 FIXME. ELF should be using the same conventions! The problem
4512 is an unwind requires too much relocation space. Hmmm. Maybe
4513 if we split the unwind bits up between the relocations which
4514 denote the entry and exit points. */
4515 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4516 last_call_info
->start_symbol
, (offsetT
) 0,
4517 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4521 /* Process a .EXIT pseudo-op. */
4527 if (!within_procedure
)
4528 as_bad (".EXIT must appear within a procedure");
4531 if (!callinfo_found
)
4532 as_bad ("Missing .callinfo");
4535 if (!within_entry_exit
)
4536 as_bad ("No .ENTRY for this .EXIT");
4539 within_entry_exit
= FALSE
;
4544 demand_empty_rest_of_line ();
4547 /* Process a .EXPORT directive. This makes functions external
4548 and provides information such as argument relocation entries
4558 name
= input_line_pointer
;
4559 c
= get_symbol_end ();
4560 /* Make sure the given symbol exists. */
4561 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4563 as_bad ("Cannot define export symbol: %s\n", name
);
4564 p
= input_line_pointer
;
4566 input_line_pointer
++;
4570 /* OK. Set the external bits and process argument relocations. */
4571 S_SET_EXTERNAL (symbol
);
4572 p
= input_line_pointer
;
4574 if (!is_end_of_statement ())
4576 input_line_pointer
++;
4577 pa_type_args (symbol
, 1);
4579 pa_build_symextn_section ();
4584 demand_empty_rest_of_line ();
4587 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4590 pa_type_args (symbolP
, is_export
)
4595 unsigned int temp
, arg_reloc
;
4596 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4597 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4599 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4602 input_line_pointer
+= 8;
4603 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4604 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4605 type
= SYMBOL_TYPE_ABSOLUTE
;
4607 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4609 input_line_pointer
+= 4;
4610 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4611 instead one should be IMPORTing/EXPORTing ENTRY types.
4613 Complain if one tries to EXPORT a CODE type since that's never
4614 done. Both GCC and HP C still try to IMPORT CODE types, so
4615 silently fix them to be ENTRY types. */
4616 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4619 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4621 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4622 type
= SYMBOL_TYPE_ENTRY
;
4626 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4627 type
= SYMBOL_TYPE_CODE
;
4630 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4632 input_line_pointer
+= 4;
4633 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4634 type
= SYMBOL_TYPE_DATA
;
4636 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4638 input_line_pointer
+= 5;
4639 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4640 type
= SYMBOL_TYPE_ENTRY
;
4642 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4644 input_line_pointer
+= 9;
4645 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4646 type
= SYMBOL_TYPE_MILLICODE
;
4648 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4650 input_line_pointer
+= 6;
4651 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4652 type
= SYMBOL_TYPE_PLABEL
;
4654 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4656 input_line_pointer
+= 8;
4657 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4658 type
= SYMBOL_TYPE_PRI_PROG
;
4660 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4662 input_line_pointer
+= 8;
4663 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4664 type
= SYMBOL_TYPE_SEC_PROG
;
4667 /* SOM requires much more information about symbol types
4668 than BFD understands. This is how we get this information
4669 to the SOM BFD backend. */
4670 #ifdef obj_set_symbol_type
4671 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4674 /* Now that the type of the exported symbol has been handled,
4675 handle any argument relocation information. */
4676 while (!is_end_of_statement ())
4678 if (*input_line_pointer
== ',')
4679 input_line_pointer
++;
4680 name
= input_line_pointer
;
4681 c
= get_symbol_end ();
4682 /* Argument sources. */
4683 if ((strncasecmp (name
, "argw", 4) == 0))
4685 p
= input_line_pointer
;
4687 input_line_pointer
++;
4688 temp
= atoi (name
+ 4);
4689 name
= input_line_pointer
;
4690 c
= get_symbol_end ();
4691 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4692 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4693 *input_line_pointer
= c
;
4695 /* The return value. */
4696 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4698 p
= input_line_pointer
;
4700 input_line_pointer
++;
4701 name
= input_line_pointer
;
4702 c
= get_symbol_end ();
4703 arg_reloc
= pa_build_arg_reloc (name
);
4704 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4705 *input_line_pointer
= c
;
4707 /* Privelege level. */
4708 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4710 p
= input_line_pointer
;
4712 input_line_pointer
++;
4713 temp
= atoi (input_line_pointer
);
4714 c
= get_symbol_end ();
4715 *input_line_pointer
= c
;
4719 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4720 p
= input_line_pointer
;
4723 if (!is_end_of_statement ())
4724 input_line_pointer
++;
4728 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4729 assembly file must either be defined in the assembly file, or
4730 explicitly IMPORTED from another. */
4739 name
= input_line_pointer
;
4740 c
= get_symbol_end ();
4742 symbol
= symbol_find_or_make (name
);
4743 p
= input_line_pointer
;
4746 if (!is_end_of_statement ())
4748 input_line_pointer
++;
4749 pa_type_args (symbol
, 0);
4753 /* Sigh. To be compatable with the HP assembler and to help
4754 poorly written assembly code, we assign a type based on
4755 the the current segment. Note only BSF_FUNCTION really
4756 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
4757 if (now_seg
== text_section
)
4758 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4760 /* If the section is undefined, then the symbol is undefined
4761 Since this is an import, leave the section undefined. */
4762 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4765 demand_empty_rest_of_line ();
4768 /* Handle a .LABEL pseudo-op. */
4776 name
= input_line_pointer
;
4777 c
= get_symbol_end ();
4779 if (strlen (name
) > 0)
4782 p
= input_line_pointer
;
4787 as_warn ("Missing label name on .LABEL");
4790 if (!is_end_of_statement ())
4792 as_warn ("extra .LABEL arguments ignored.");
4793 ignore_rest_of_line ();
4795 demand_empty_rest_of_line ();
4798 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4807 /* Handle a .ORIGIN pseudo-op. */
4814 pa_undefine_label ();
4817 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4818 is for static functions. FIXME. Should share more code with .EXPORT. */
4827 name
= input_line_pointer
;
4828 c
= get_symbol_end ();
4830 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4832 as_bad ("Cannot define static symbol: %s\n", name
);
4833 p
= input_line_pointer
;
4835 input_line_pointer
++;
4839 S_CLEAR_EXTERNAL (symbol
);
4840 p
= input_line_pointer
;
4842 if (!is_end_of_statement ())
4844 input_line_pointer
++;
4845 pa_type_args (symbol
, 0);
4849 demand_empty_rest_of_line ();
4852 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4853 of a procedure from a syntatical point of view. */
4859 struct call_info
*call_info
;
4862 if (within_procedure
)
4863 as_fatal ("Nested procedures");
4865 /* Reset global variables for new procedure. */
4866 callinfo_found
= FALSE
;
4867 within_procedure
= TRUE
;
4869 /* Create a new CODE subspace for each procedure if we are not
4870 using space/subspace aliases. */
4871 if (!USE_ALIASES
&& call_info_root
!= NULL
)
4873 /* Force creation of a new $CODE$ subspace; inherit attributes from
4874 the first $CODE$ subspace. */
4875 seg
= subseg_force_new ("$CODE$", 0);
4877 /* Now set the flags. */
4878 bfd_set_section_flags (stdoutput
, seg
,
4879 bfd_get_section_flags (abfd
, text_section
));
4881 /* Record any alignment request for this section. */
4882 record_alignment (seg
,
4883 bfd_get_section_alignment (stdoutput
, text_section
));
4885 /* Change the "text_section" to be our new $CODE$ subspace. */
4887 subseg_set (text_section
, 0);
4889 #ifdef obj_set_subsection_attributes
4890 /* Need a way to inherit the the access bits, sort key and quadrant
4891 from the first $CODE$ subspace. FIXME. */
4892 obj_set_subsection_attributes (seg
, current_space
->sd_seg
, 0x2c, 24, 0);
4896 /* Create another call_info structure. */
4897 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4900 as_fatal ("Cannot allocate unwind descriptor\n");
4902 bzero (call_info
, sizeof (struct call_info
));
4904 call_info
->ci_next
= NULL
;
4906 if (call_info_root
== NULL
)
4908 call_info_root
= call_info
;
4909 last_call_info
= call_info
;
4913 last_call_info
->ci_next
= call_info
;
4914 last_call_info
= call_info
;
4917 /* set up defaults on call_info structure */
4919 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4920 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4921 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4923 /* If we got a .PROC pseudo-op, we know that the function is defined
4924 locally. Make sure it gets into the symbol table. */
4926 label_symbol_struct
*label_symbol
= pa_get_label ();
4930 if (label_symbol
->lss_label
)
4932 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4933 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4936 /* The label was defined in a different segment. Fix that
4937 along with the value and associated fragment. */
4938 S_SET_SEGMENT (last_call_info
->start_symbol
, now_seg
);
4939 S_SET_VALUE (last_call_info
->start_symbol
,
4940 ((char*)obstack_next_free (&frags
)
4941 - frag_now
->fr_literal
));
4942 last_call_info
->start_symbol
->sy_frag
= frag_now
;
4946 as_bad ("Missing function name for .PROC (corrupted label chain)");
4949 last_call_info
->start_symbol
= NULL
;
4952 demand_empty_rest_of_line ();
4955 /* Process the syntatical end of a procedure. Make sure all the
4956 appropriate pseudo-ops were found within the procedure. */
4963 if (!within_procedure
)
4964 as_bad ("misplaced .procend");
4966 if (!callinfo_found
)
4967 as_bad ("Missing .callinfo for this procedure");
4969 if (within_entry_exit
)
4970 as_bad ("Missing .EXIT for a .ENTRY");
4973 /* ELF needs to mark the end of each function so that it can compute
4974 the size of the function (apparently its needed in the symbol table. */
4975 hppa_elf_mark_end_of_function ();
4978 within_procedure
= FALSE
;
4979 demand_empty_rest_of_line ();
4980 pa_undefine_label ();
4983 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4984 then create a new space entry to hold the information specified
4985 by the parameters to the .SPACE directive. */
4987 static sd_chain_struct
*
4988 pa_parse_space_stmt (space_name
, create_flag
)
4992 char *name
, *ptemp
, c
;
4993 char loadable
, defined
, private, sort
;
4995 asection
*seg
= NULL
;
4996 sd_chain_struct
*space
;
4998 /* load default values */
5004 if (strcmp (space_name
, "$TEXT$") == 0)
5006 seg
= pa_def_spaces
[0].segment
;
5007 sort
= pa_def_spaces
[0].sort
;
5009 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5011 seg
= pa_def_spaces
[1].segment
;
5012 sort
= pa_def_spaces
[1].sort
;
5015 if (!is_end_of_statement ())
5017 print_errors
= FALSE
;
5018 ptemp
= input_line_pointer
+ 1;
5019 /* First see if the space was specified as a number rather than
5020 as a name. According to the PA assembly manual the rest of
5021 the line should be ignored. */
5022 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5023 input_line_pointer
= ptemp
;
5026 while (!is_end_of_statement ())
5028 input_line_pointer
++;
5029 name
= input_line_pointer
;
5030 c
= get_symbol_end ();
5031 if ((strncasecmp (name
, "spnum", 5) == 0))
5033 *input_line_pointer
= c
;
5034 input_line_pointer
++;
5035 spnum
= get_absolute_expression ();
5037 else if ((strncasecmp (name
, "sort", 4) == 0))
5039 *input_line_pointer
= c
;
5040 input_line_pointer
++;
5041 sort
= get_absolute_expression ();
5043 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5045 *input_line_pointer
= c
;
5048 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5050 *input_line_pointer
= c
;
5053 else if ((strncasecmp (name
, "private", 7) == 0))
5055 *input_line_pointer
= c
;
5060 as_bad ("Invalid .SPACE argument");
5061 *input_line_pointer
= c
;
5062 if (!is_end_of_statement ())
5063 input_line_pointer
++;
5067 print_errors
= TRUE
;
5070 if (create_flag
&& seg
== NULL
)
5071 seg
= subseg_new (space_name
, 0);
5073 /* If create_flag is nonzero, then create the new space with
5074 the attributes computed above. Else set the values in
5075 an already existing space -- this can only happen for
5076 the first occurence of a built-in space. */
5078 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5079 private, sort
, seg
, 1);
5082 space
= is_defined_space (space_name
);
5083 SPACE_SPNUM (space
) = spnum
;
5084 SPACE_DEFINED (space
) = defined
& 1;
5085 SPACE_USER_DEFINED (space
) = 1;
5086 space
->sd_seg
= seg
;
5089 #ifdef obj_set_section_attributes
5090 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5096 /* Handle a .SPACE pseudo-op; this switches the current space to the
5097 given space, creating the new space if necessary. */
5103 char *name
, c
, *space_name
, *save_s
;
5105 sd_chain_struct
*sd_chain
;
5107 if (within_procedure
)
5109 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5110 ignore_rest_of_line ();
5114 /* Check for some of the predefined spaces. FIXME: most of the code
5115 below is repeated several times, can we extract the common parts
5116 and place them into a subroutine or something similar? */
5117 /* FIXME Is this (and the next IF stmt) really right?
5118 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5119 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5121 input_line_pointer
+= 6;
5122 sd_chain
= is_defined_space ("$TEXT$");
5123 if (sd_chain
== NULL
)
5124 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5125 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5126 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5128 current_space
= sd_chain
;
5129 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5131 = pa_subsegment_to_subspace (text_section
,
5132 sd_chain
->sd_last_subseg
);
5133 demand_empty_rest_of_line ();
5136 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5138 input_line_pointer
+= 9;
5139 sd_chain
= is_defined_space ("$PRIVATE$");
5140 if (sd_chain
== NULL
)
5141 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5142 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5143 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5145 current_space
= sd_chain
;
5146 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5148 = pa_subsegment_to_subspace (data_section
,
5149 sd_chain
->sd_last_subseg
);
5150 demand_empty_rest_of_line ();
5153 if (!strncasecmp (input_line_pointer
,
5154 GDB_DEBUG_SPACE_NAME
,
5155 strlen (GDB_DEBUG_SPACE_NAME
)))
5157 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5158 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5159 if (sd_chain
== NULL
)
5160 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5161 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5162 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5164 current_space
= sd_chain
;
5167 asection
*gdb_section
5168 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5170 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5172 = pa_subsegment_to_subspace (gdb_section
,
5173 sd_chain
->sd_last_subseg
);
5175 demand_empty_rest_of_line ();
5179 /* It could be a space specified by number. */
5181 save_s
= input_line_pointer
;
5182 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5184 if (sd_chain
= pa_find_space_by_number (temp
))
5186 current_space
= sd_chain
;
5188 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5190 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5191 sd_chain
->sd_last_subseg
);
5192 demand_empty_rest_of_line ();
5197 /* Not a number, attempt to create a new space. */
5199 input_line_pointer
= save_s
;
5200 name
= input_line_pointer
;
5201 c
= get_symbol_end ();
5202 space_name
= xmalloc (strlen (name
) + 1);
5203 strcpy (space_name
, name
);
5204 *input_line_pointer
= c
;
5206 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5207 current_space
= sd_chain
;
5209 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5210 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5211 sd_chain
->sd_last_subseg
);
5212 demand_empty_rest_of_line ();
5216 /* Switch to a new space. (I think). FIXME. */
5225 sd_chain_struct
*space
;
5227 name
= input_line_pointer
;
5228 c
= get_symbol_end ();
5229 space
= is_defined_space (name
);
5233 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5236 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5238 *input_line_pointer
= c
;
5239 demand_empty_rest_of_line ();
5242 /* If VALUE is an exact power of two between zero and 2^31, then
5243 return log2 (VALUE). Else return -1. */
5251 while ((1 << shift
) != value
&& shift
< 32)
5260 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5261 given subspace, creating the new subspace if necessary.
5263 FIXME. Should mirror pa_space more closely, in particular how
5264 they're broken up into subroutines. */
5267 pa_subspace (unused
)
5270 char *name
, *ss_name
, *alias
, c
;
5271 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5272 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5273 sd_chain_struct
*space
;
5274 ssd_chain_struct
*ssd
;
5277 if (within_procedure
)
5279 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5280 ignore_rest_of_line ();
5284 name
= input_line_pointer
;
5285 c
= get_symbol_end ();
5286 ss_name
= xmalloc (strlen (name
) + 1);
5287 strcpy (ss_name
, name
);
5288 *input_line_pointer
= c
;
5290 /* Load default values. */
5303 space
= current_space
;
5304 ssd
= is_defined_subspace (ss_name
);
5305 /* Allow user to override the builtin attributes of subspaces. But
5306 only allow the attributes to be changed once! */
5307 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5309 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5310 if (!is_end_of_statement ())
5311 as_warn ("Parameters of an existing subspace can\'t be modified");
5312 demand_empty_rest_of_line ();
5317 /* A new subspace. Load default values if it matches one of
5318 the builtin subspaces. */
5320 while (pa_def_subspaces
[i
].name
)
5322 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5324 loadable
= pa_def_subspaces
[i
].loadable
;
5325 common
= pa_def_subspaces
[i
].common
;
5326 dup_common
= pa_def_subspaces
[i
].dup_common
;
5327 code_only
= pa_def_subspaces
[i
].code_only
;
5328 zero
= pa_def_subspaces
[i
].zero
;
5329 space_index
= pa_def_subspaces
[i
].space_index
;
5330 alignment
= pa_def_subspaces
[i
].alignment
;
5331 quadrant
= pa_def_subspaces
[i
].quadrant
;
5332 access
= pa_def_subspaces
[i
].access
;
5333 sort
= pa_def_subspaces
[i
].sort
;
5334 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5335 alias
= pa_def_subspaces
[i
].alias
;
5342 /* We should be working with a new subspace now. Fill in
5343 any information as specified by the user. */
5344 if (!is_end_of_statement ())
5346 input_line_pointer
++;
5347 while (!is_end_of_statement ())
5349 name
= input_line_pointer
;
5350 c
= get_symbol_end ();
5351 if ((strncasecmp (name
, "quad", 4) == 0))
5353 *input_line_pointer
= c
;
5354 input_line_pointer
++;
5355 quadrant
= get_absolute_expression ();
5357 else if ((strncasecmp (name
, "align", 5) == 0))
5359 *input_line_pointer
= c
;
5360 input_line_pointer
++;
5361 alignment
= get_absolute_expression ();
5362 if (log2 (alignment
) == -1)
5364 as_bad ("Alignment must be a power of 2");
5368 else if ((strncasecmp (name
, "access", 6) == 0))
5370 *input_line_pointer
= c
;
5371 input_line_pointer
++;
5372 access
= get_absolute_expression ();
5374 else if ((strncasecmp (name
, "sort", 4) == 0))
5376 *input_line_pointer
= c
;
5377 input_line_pointer
++;
5378 sort
= get_absolute_expression ();
5380 else if ((strncasecmp (name
, "code_only", 9) == 0))
5382 *input_line_pointer
= c
;
5385 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5387 *input_line_pointer
= c
;
5390 else if ((strncasecmp (name
, "common", 6) == 0))
5392 *input_line_pointer
= c
;
5395 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5397 *input_line_pointer
= c
;
5400 else if ((strncasecmp (name
, "zero", 4) == 0))
5402 *input_line_pointer
= c
;
5405 else if ((strncasecmp (name
, "first", 5) == 0))
5406 as_bad ("FIRST not supported as a .SUBSPACE argument");
5408 as_bad ("Invalid .SUBSPACE argument");
5409 if (!is_end_of_statement ())
5410 input_line_pointer
++;
5414 /* Compute a reasonable set of BFD flags based on the information
5415 in the .subspace directive. */
5416 applicable
= bfd_applicable_section_flags (stdoutput
);
5419 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5422 if (common
|| dup_common
)
5423 flags
|= SEC_IS_COMMON
;
5425 /* This is a zero-filled subspace (eg BSS). */
5429 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5430 applicable
&= flags
;
5432 /* If this is an existing subspace, then we want to use the
5433 segment already associated with the subspace.
5435 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5436 lots of sections. It might be a problem in the PA ELF
5437 code, I do not know yet. For now avoid creating anything
5438 but the "standard" sections for ELF. */
5440 section
= ssd
->ssd_seg
;
5442 section
= subseg_new (alias
, 0);
5443 else if (!alias
&& USE_ALIASES
)
5445 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5446 demand_empty_rest_of_line ();
5450 section
= subseg_new (ss_name
, 0);
5452 /* Now set the flags. */
5453 bfd_set_section_flags (stdoutput
, section
, applicable
);
5455 /* Record any alignment request for this section. */
5456 record_alignment (section
, log2 (alignment
));
5458 /* Set the starting offset for this section. */
5459 bfd_set_section_vma (stdoutput
, section
,
5460 pa_subspace_start (space
, quadrant
));
5462 /* Now that all the flags are set, update an existing subspace,
5463 or create a new one. */
5466 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5467 code_only
, common
, dup_common
,
5468 sort
, zero
, access
, space_index
,
5469 alignment
, quadrant
,
5472 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5474 dup_common
, zero
, sort
,
5475 access
, space_index
,
5476 alignment
, quadrant
, section
);
5478 demand_empty_rest_of_line ();
5479 current_subspace
->ssd_seg
= section
;
5480 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5482 SUBSPACE_DEFINED (current_subspace
) = 1;
5486 /* Create default space and subspace dictionaries. */
5493 space_dict_root
= NULL
;
5494 space_dict_last
= NULL
;
5497 while (pa_def_spaces
[i
].name
)
5501 /* Pick the right name to use for the new section. */
5502 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5503 name
= pa_def_spaces
[i
].alias
;
5505 name
= pa_def_spaces
[i
].name
;
5507 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5508 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5509 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5510 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5511 pa_def_spaces
[i
].segment
, 0);
5516 while (pa_def_subspaces
[i
].name
)
5519 int applicable
, subsegment
;
5520 asection
*segment
= NULL
;
5521 sd_chain_struct
*space
;
5523 /* Pick the right name for the new section and pick the right
5524 subsegment number. */
5525 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5527 name
= pa_def_subspaces
[i
].alias
;
5528 subsegment
= pa_def_subspaces
[i
].subsegment
;
5532 name
= pa_def_subspaces
[i
].name
;
5536 /* Create the new section. */
5537 segment
= subseg_new (name
, subsegment
);
5540 /* For SOM we want to replace the standard .text, .data, and .bss
5541 sections with our own. */
5542 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5544 text_section
= segment
;
5545 applicable
= bfd_applicable_section_flags (stdoutput
);
5546 bfd_set_section_flags (stdoutput
, text_section
,
5547 applicable
& (SEC_ALLOC
| SEC_LOAD
5548 | SEC_RELOC
| SEC_CODE
5550 | SEC_HAS_CONTENTS
));
5552 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5554 data_section
= segment
;
5555 applicable
= bfd_applicable_section_flags (stdoutput
);
5556 bfd_set_section_flags (stdoutput
, data_section
,
5557 applicable
& (SEC_ALLOC
| SEC_LOAD
5559 | SEC_HAS_CONTENTS
));
5563 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5565 bss_section
= segment
;
5566 applicable
= bfd_applicable_section_flags (stdoutput
);
5567 bfd_set_section_flags (stdoutput
, bss_section
,
5568 applicable
& SEC_ALLOC
);
5571 /* Find the space associated with this subspace. */
5572 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5573 def_space_index
].segment
);
5576 as_fatal ("Internal error: Unable to find containing space for %s.",
5577 pa_def_subspaces
[i
].name
);
5580 create_new_subspace (space
, name
,
5581 pa_def_subspaces
[i
].loadable
,
5582 pa_def_subspaces
[i
].code_only
,
5583 pa_def_subspaces
[i
].common
,
5584 pa_def_subspaces
[i
].dup_common
,
5585 pa_def_subspaces
[i
].zero
,
5586 pa_def_subspaces
[i
].sort
,
5587 pa_def_subspaces
[i
].access
,
5588 pa_def_subspaces
[i
].space_index
,
5589 pa_def_subspaces
[i
].alignment
,
5590 pa_def_subspaces
[i
].quadrant
,
5598 /* Create a new space NAME, with the appropriate flags as defined
5599 by the given parameters. */
5601 static sd_chain_struct
*
5602 create_new_space (name
, spnum
, loadable
, defined
, private,
5603 sort
, seg
, user_defined
)
5613 sd_chain_struct
*chain_entry
;
5615 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5617 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5620 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5621 strcpy (SPACE_NAME (chain_entry
), name
);
5622 SPACE_DEFINED (chain_entry
) = defined
;
5623 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5624 SPACE_SPNUM (chain_entry
) = spnum
;
5626 chain_entry
->sd_seg
= seg
;
5627 chain_entry
->sd_last_subseg
= -1;
5628 chain_entry
->sd_next
= NULL
;
5630 /* Find spot for the new space based on its sort key. */
5631 if (!space_dict_last
)
5632 space_dict_last
= chain_entry
;
5634 if (space_dict_root
== NULL
)
5635 space_dict_root
= chain_entry
;
5638 sd_chain_struct
*chain_pointer
;
5639 sd_chain_struct
*prev_chain_pointer
;
5641 chain_pointer
= space_dict_root
;
5642 prev_chain_pointer
= NULL
;
5644 while (chain_pointer
)
5646 prev_chain_pointer
= chain_pointer
;
5647 chain_pointer
= chain_pointer
->sd_next
;
5650 /* At this point we've found the correct place to add the new
5651 entry. So add it and update the linked lists as appropriate. */
5652 if (prev_chain_pointer
)
5654 chain_entry
->sd_next
= chain_pointer
;
5655 prev_chain_pointer
->sd_next
= chain_entry
;
5659 space_dict_root
= chain_entry
;
5660 chain_entry
->sd_next
= chain_pointer
;
5663 if (chain_entry
->sd_next
== NULL
)
5664 space_dict_last
= chain_entry
;
5667 /* This is here to catch predefined spaces which do not get
5668 modified by the user's input. Another call is found at
5669 the bottom of pa_parse_space_stmt to handle cases where
5670 the user modifies a predefined space. */
5671 #ifdef obj_set_section_attributes
5672 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5678 /* Create a new subspace NAME, with the appropriate flags as defined
5679 by the given parameters.
5681 Add the new subspace to the subspace dictionary chain in numerical
5682 order as defined by the SORT entries. */
5684 static ssd_chain_struct
*
5685 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5686 dup_common
, is_zero
, sort
, access
, space_index
,
5687 alignment
, quadrant
, seg
)
5688 sd_chain_struct
*space
;
5690 char loadable
, code_only
, common
, dup_common
, is_zero
;
5698 ssd_chain_struct
*chain_entry
;
5700 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5702 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5704 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5705 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5707 /* Initialize subspace_defined. When we hit a .subspace directive
5708 we'll set it to 1 which "locks-in" the subspace attributes. */
5709 SUBSPACE_DEFINED (chain_entry
) = 0;
5711 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5712 chain_entry
->ssd_seg
= seg
;
5713 chain_entry
->ssd_next
= NULL
;
5715 /* Find spot for the new subspace based on its sort key. */
5716 if (space
->sd_subspaces
== NULL
)
5717 space
->sd_subspaces
= chain_entry
;
5720 ssd_chain_struct
*chain_pointer
;
5721 ssd_chain_struct
*prev_chain_pointer
;
5723 chain_pointer
= space
->sd_subspaces
;
5724 prev_chain_pointer
= NULL
;
5726 while (chain_pointer
)
5728 prev_chain_pointer
= chain_pointer
;
5729 chain_pointer
= chain_pointer
->ssd_next
;
5732 /* Now we have somewhere to put the new entry. Insert it and update
5734 if (prev_chain_pointer
)
5736 chain_entry
->ssd_next
= chain_pointer
;
5737 prev_chain_pointer
->ssd_next
= chain_entry
;
5741 space
->sd_subspaces
= chain_entry
;
5742 chain_entry
->ssd_next
= chain_pointer
;
5746 #ifdef obj_set_subsection_attributes
5747 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5754 /* Update the information for the given subspace based upon the
5755 various arguments. Return the modified subspace chain entry. */
5757 static ssd_chain_struct
*
5758 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5759 zero
, access
, space_index
, alignment
, quadrant
, section
)
5760 sd_chain_struct
*space
;
5774 ssd_chain_struct
*chain_entry
;
5776 chain_entry
= is_defined_subspace (name
);
5778 #ifdef obj_set_subsection_attributes
5779 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5786 /* Return the space chain entry for the space with the name NAME or
5787 NULL if no such space exists. */
5789 static sd_chain_struct
*
5790 is_defined_space (name
)
5793 sd_chain_struct
*chain_pointer
;
5795 for (chain_pointer
= space_dict_root
;
5797 chain_pointer
= chain_pointer
->sd_next
)
5799 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5800 return chain_pointer
;
5803 /* No mapping from segment to space was found. Return NULL. */
5807 /* Find and return the space associated with the given seg. If no mapping
5808 from the given seg to a space is found, then return NULL.
5810 Unlike subspaces, the number of spaces is not expected to grow much,
5811 so a linear exhaustive search is OK here. */
5813 static sd_chain_struct
*
5814 pa_segment_to_space (seg
)
5817 sd_chain_struct
*space_chain
;
5819 /* Walk through each space looking for the correct mapping. */
5820 for (space_chain
= space_dict_root
;
5822 space_chain
= space_chain
->sd_next
)
5824 if (space_chain
->sd_seg
== seg
)
5828 /* Mapping was not found. Return NULL. */
5832 /* Return the space chain entry for the subspace with the name NAME or
5833 NULL if no such subspace exists.
5835 Uses a linear search through all the spaces and subspaces, this may
5836 not be appropriate if we ever being placing each function in its
5839 static ssd_chain_struct
*
5840 is_defined_subspace (name
)
5843 sd_chain_struct
*space_chain
;
5844 ssd_chain_struct
*subspace_chain
;
5846 /* Walk through each space. */
5847 for (space_chain
= space_dict_root
;
5849 space_chain
= space_chain
->sd_next
)
5851 /* Walk through each subspace looking for a name which matches. */
5852 for (subspace_chain
= space_chain
->sd_subspaces
;
5854 subspace_chain
= subspace_chain
->ssd_next
)
5855 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5856 return subspace_chain
;
5859 /* Subspace wasn't found. Return NULL. */
5863 /* Find and return the subspace associated with the given seg. If no
5864 mapping from the given seg to a subspace is found, then return NULL.
5866 If we ever put each procedure/function within its own subspace
5867 (to make life easier on the compiler and linker), then this will have
5868 to become more efficient. */
5870 static ssd_chain_struct
*
5871 pa_subsegment_to_subspace (seg
, subseg
)
5875 sd_chain_struct
*space_chain
;
5876 ssd_chain_struct
*subspace_chain
;
5878 /* Walk through each space. */
5879 for (space_chain
= space_dict_root
;
5881 space_chain
= space_chain
->sd_next
)
5883 if (space_chain
->sd_seg
== seg
)
5885 /* Walk through each subspace within each space looking for
5886 the correct mapping. */
5887 for (subspace_chain
= space_chain
->sd_subspaces
;
5889 subspace_chain
= subspace_chain
->ssd_next
)
5890 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5891 return subspace_chain
;
5895 /* No mapping from subsegment to subspace found. Return NULL. */
5899 /* Given a number, try and find a space with the name number.
5901 Return a pointer to a space dictionary chain entry for the space
5902 that was found or NULL on failure. */
5904 static sd_chain_struct
*
5905 pa_find_space_by_number (number
)
5908 sd_chain_struct
*space_chain
;
5910 for (space_chain
= space_dict_root
;
5912 space_chain
= space_chain
->sd_next
)
5914 if (SPACE_SPNUM (space_chain
) == number
)
5918 /* No appropriate space found. Return NULL. */
5922 /* Return the starting address for the given subspace. If the starting
5923 address is unknown then return zero. */
5926 pa_subspace_start (space
, quadrant
)
5927 sd_chain_struct
*space
;
5930 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5931 is not correct for the PA OSF1 port. */
5932 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5934 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5940 /* FIXME. Needs documentation. */
5942 pa_next_subseg (space
)
5943 sd_chain_struct
*space
;
5946 space
->sd_last_subseg
++;
5947 return space
->sd_last_subseg
;
5950 /* Helper function for pa_stringer. Used to find the end of
5957 unsigned int c
= *s
& CHAR_MASK
;
5969 /* Handle a .STRING type pseudo-op. */
5972 pa_stringer (append_zero
)
5975 char *s
, num_buf
[4];
5979 /* Preprocess the string to handle PA-specific escape sequences.
5980 For example, \xDD where DD is a hexidecimal number should be
5981 changed to \OOO where OOO is an octal number. */
5983 /* Skip the opening quote. */
5984 s
= input_line_pointer
+ 1;
5986 while (is_a_char (c
= pa_stringer_aux (s
++)))
5993 /* Handle \x<num>. */
5996 unsigned int number
;
6001 /* Get pas the 'x'. */
6003 for (num_digit
= 0, number
= 0, dg
= *s
;
6005 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6006 || (dg
>= 'A' && dg
<= 'F'));
6010 number
= number
* 16 + dg
- '0';
6011 else if (dg
>= 'a' && dg
<= 'f')
6012 number
= number
* 16 + dg
- 'a' + 10;
6014 number
= number
* 16 + dg
- 'A' + 10;
6024 sprintf (num_buf
, "%02o", number
);
6027 sprintf (num_buf
, "%03o", number
);
6030 for (i
= 0; i
<= num_digit
; i
++)
6031 s_start
[i
] = num_buf
[i
];
6035 /* This might be a "\"", skip over the escaped char. */
6042 stringer (append_zero
);
6043 pa_undefine_label ();
6046 /* Handle a .VERSION pseudo-op. */
6053 pa_undefine_label ();
6056 /* Handle a .COPYRIGHT pseudo-op. */
6059 pa_copyright (unused
)
6063 pa_undefine_label ();
6066 /* Just like a normal cons, but when finished we have to undefine
6067 the latest space label. */
6074 pa_undefine_label ();
6077 /* Switch to the data space. As usual delete our label. */
6084 pa_undefine_label ();
6087 /* Like float_cons, but we need to undefine our label. */
6090 pa_float_cons (float_type
)
6093 float_cons (float_type
);
6094 pa_undefine_label ();
6097 /* Like s_fill, but delete our label when finished. */
6104 pa_undefine_label ();
6107 /* Like lcomm, but delete our label when finished. */
6110 pa_lcomm (needs_align
)
6113 s_lcomm (needs_align
);
6114 pa_undefine_label ();
6117 /* Like lsym, but delete our label when finished. */
6124 pa_undefine_label ();
6127 /* Switch to the text space. Like s_text, but delete our
6128 label when finished. */
6134 pa_undefine_label ();
6137 /* On the PA relocations which involve function symbols must not be
6138 adjusted. This so that the linker can know when/how to create argument
6139 relocation stubs for indirect calls and calls to static functions.
6141 FIXME. Also reject R_HPPA relocations which are 32 bits
6142 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6143 needs to generate relocations to push the addend and symbol value
6144 onto the stack, add them, then pop the value off the stack and
6145 use it in a relocation -- yuk. */
6148 hppa_fix_adjustable (fixp
)
6151 struct hppa_fix_struct
*hppa_fix
;
6153 hppa_fix
= fixp
->tc_fix_data
;
6155 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6158 if (fixp
->fx_addsy
== 0
6159 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6165 /* Return nonzero if the fixup in FIXP will require a relocation,
6166 even it if appears that the fixup could be completely handled
6170 hppa_force_relocation (fixp
)
6173 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
6176 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6180 #define stub_needed(CALLER, CALLEE) \
6181 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6183 /* It is necessary to force PC-relative calls/jumps to have a relocation
6184 entry if they're going to need either a argument relocation or long
6185 call stub. FIXME. Can't we need the same for absolute calls? */
6186 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6187 && (stub_needed (((obj_symbol_type
*)
6188 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6189 hppa_fixp
->fx_arg_reloc
)))
6194 /* No need (yet) to force another relocations to be emitted. */
6198 /* Now for some ELF specific code. FIXME. */
6200 static symext_chainS
*symext_rootP
;
6201 static symext_chainS
*symext_lastP
;
6203 /* Mark the end of a function so that it's possible to compute
6204 the size of the function in hppa_elf_final_processing. */
6207 hppa_elf_mark_end_of_function ()
6209 /* ELF does not have EXIT relocations. All we do is create a
6210 temporary symbol marking the end of the function. */
6211 char *name
= (char *)
6212 xmalloc (strlen ("L$\001end_") +
6213 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6219 strcpy (name
, "L$\001end_");
6220 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6222 /* If we have a .exit followed by a .procend, then the
6223 symbol will have already been defined. */
6224 symbolP
= symbol_find (name
);
6227 /* The symbol has already been defined! This can
6228 happen if we have a .exit followed by a .procend.
6230 This is *not* an error. All we want to do is free
6231 the memory we just allocated for the name and continue. */
6236 /* symbol value should be the offset of the
6237 last instruction of the function */
6238 symbolP
= symbol_new (name
, now_seg
,
6239 (valueT
) (obstack_next_free (&frags
)
6240 - frag_now
->fr_literal
- 4),
6244 symbolP
->bsym
->flags
= BSF_LOCAL
;
6245 symbol_table_insert (symbolP
);
6249 last_call_info
->end_symbol
= symbolP
;
6251 as_bad ("Symbol '%s' could not be created.", name
);
6255 as_bad ("No memory for symbol name.");
6259 /* Do any symbol processing requested by the target-cpu or target-format. */
6262 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6264 elf_symbol_type
*symbolP
;
6267 symext_chainS
*symextP
;
6268 unsigned int arg_reloc
;
6270 /* Only functions can have argument relocations. */
6271 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6274 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6276 /* If there are no argument relocation bits, then no relocation is
6277 necessary. Do not add this to the symextn section. */
6281 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6283 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6284 symextP
[0].next
= &symextP
[1];
6286 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6287 symextP
[1].next
= NULL
;
6289 if (symext_rootP
== NULL
)
6291 symext_rootP
= &symextP
[0];
6292 symext_lastP
= &symextP
[1];
6296 symext_lastP
->next
= &symextP
[0];
6297 symext_lastP
= &symextP
[1];
6301 /* Make sections needed by the target cpu and/or target format. */
6303 hppa_tc_make_sections (abfd
)
6306 symext_chainS
*symextP
;
6307 segT save_seg
= now_seg
;
6308 subsegT save_subseg
= now_subseg
;
6310 /* Build the symbol extension section. */
6311 hppa_tc_make_symextn_section ();
6313 /* Force some calculation to occur. */
6314 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6316 hppa_elf_stub_finish (abfd
);
6318 /* If no symbols for the symbol extension section, then stop now. */
6319 if (symext_rootP
== NULL
)
6322 /* Switch to the symbol extension section. */
6323 subseg_new (SYMEXTN_SECTION_NAME
, 0);
6325 frag_wane (frag_now
);
6328 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6331 int *symtab_map
= elf_sym_extra (abfd
);
6334 /* First, patch the symbol extension record to reflect the true
6335 symbol table index. */
6337 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6339 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6340 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6344 ptr
= frag_more (sizeof (symextP
->entry
));
6345 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6348 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6349 frag_wane (frag_now
);
6351 /* Switch back to the original segment. */
6352 subseg_set (save_seg
, save_subseg
);
6355 /* Make the symbol extension section. */
6358 hppa_tc_make_symextn_section ()
6362 symext_chainS
*symextP
;
6366 segT save_seg
= now_seg
;
6367 subsegT save_subseg
= now_subseg
;
6369 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6372 size
= sizeof (symext_entryS
) * n
;
6374 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6376 bfd_set_section_flags (stdoutput
, symextn_sec
,
6377 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6378 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6380 /* Now, switch back to the original segment. */
6381 subseg_set (save_seg
, save_subseg
);
6385 /* Build the symbol extension section. */
6388 pa_build_symextn_section ()
6391 asection
*save_seg
= now_seg
;
6392 subsegT subseg
= (subsegT
) 0;
6393 subsegT save_subseg
= now_subseg
;
6395 seg
= subseg_new (".hppa_symextn", subseg
);
6396 bfd_set_section_flags (stdoutput
,
6398 SEC_HAS_CONTENTS
| SEC_READONLY
6399 | SEC_ALLOC
| SEC_LOAD
);
6401 subseg_set (save_seg
, save_subseg
);
6404 /* For ELF, this function serves one purpose: to setup the st_size
6405 field of STT_FUNC symbols. To do this, we need to scan the
6406 call_info structure list, determining st_size in by taking the
6407 difference in the address of the beginning/end marker symbols. */
6410 elf_hppa_final_processing ()
6412 struct call_info
*call_info_pointer
;
6414 for (call_info_pointer
= call_info_root
;
6416 call_info_pointer
= call_info_pointer
->ci_next
)
6418 elf_symbol_type
*esym
6419 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6420 esym
->internal_elf_sym
.st_size
=
6421 S_GET_VALUE (call_info_pointer
->end_symbol
)
6422 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;