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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "bfd/libhppa.h"
31 #include "bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".PARISC.unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
55 /* ELF objects can have versions, but apparently do not have anywhere
56 to store a copyright string. */
57 #define obj_version obj_elf_version
58 #define obj_copyright obj_elf_version
60 /* Use space aliases. */
65 /* Names of various debugging spaces/subspaces. */
66 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
67 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
68 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
69 #define UNWIND_SECTION_NAME "$UNWIND$"
71 /* Object file formats specify relocation types. */
72 typedef int reloc_type
;
74 /* SOM objects can have both a version string and a copyright string. */
75 #define obj_version obj_som_version
76 #define obj_copyright obj_som_copyright
78 /* Do not use space aliases. */
81 /* How to generate a relocation. */
82 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
84 /* Object file formats specify BFD symbol types. */
85 typedef som_symbol_type obj_symbol_type
;
87 /* This apparently isn't in older versions of hpux reloc.h. */
89 #define R_DLT_REL 0x78
93 /* Various structures and types used internally in tc-hppa.c. */
95 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
99 unsigned int cannot_unwind
:1;
100 unsigned int millicode
:1;
101 unsigned int millicode_save_rest
:1;
102 unsigned int region_desc
:2;
103 unsigned int save_sr
:2;
104 unsigned int entry_fr
:4;
105 unsigned int entry_gr
:5;
106 unsigned int args_stored
:1;
107 unsigned int call_fr
:5;
108 unsigned int call_gr
:5;
109 unsigned int save_sp
:1;
110 unsigned int save_rp
:1;
111 unsigned int save_rp_in_frame
:1;
112 unsigned int extn_ptr_defined
:1;
113 unsigned int cleanup_defined
:1;
115 unsigned int hpe_interrupt_marker
:1;
116 unsigned int hpux_interrupt_marker
:1;
117 unsigned int reserved
:3;
118 unsigned int frame_size
:27;
123 /* Starting and ending offsets of the region described by
125 unsigned int start_offset
;
126 unsigned int end_offset
;
127 struct unwind_desc descriptor
;
130 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
131 control the entry and exit code they generate. It is also used in
132 creation of the correct stack unwind descriptors.
134 NOTE: GAS does not support .enter and .leave for the generation of
135 prologues and epilogues. FIXME.
137 The fields in structure roughly correspond to the arguments available on the
138 .callinfo pseudo-op. */
142 /* The unwind descriptor being built. */
143 struct unwind_table ci_unwind
;
145 /* Name of this function. */
146 symbolS
*start_symbol
;
148 /* (temporary) symbol used to mark the end of this function. */
151 /* Next entry in the chain. */
152 struct call_info
*ci_next
;
155 /* Operand formats for FP instructions. Note not all FP instructions
156 allow all four formats to be used (for example fmpysub only allows
160 SGL
, DBL
, ILLEGAL_FMT
, QUAD
164 /* This fully describes the symbol types which may be attached to
165 an EXPORT or IMPORT directive. Only SOM uses this formation
166 (ELF has no need for it). */
170 SYMBOL_TYPE_ABSOLUTE
,
174 SYMBOL_TYPE_MILLICODE
,
176 SYMBOL_TYPE_PRI_PROG
,
177 SYMBOL_TYPE_SEC_PROG
,
181 /* This structure contains information needed to assemble
182 individual instructions. */
185 /* Holds the opcode after parsing by pa_ip. */
186 unsigned long opcode
;
188 /* Holds an expression associated with the current instruction. */
191 /* Does this instruction use PC-relative addressing. */
194 /* Floating point formats for operand1 and operand2. */
195 fp_operand_format fpof1
;
196 fp_operand_format fpof2
;
198 /* Holds the field selector for this instruction
199 (for example L%, LR%, etc). */
202 /* Holds any argument relocation bits associated with this
203 instruction. (instruction should be some sort of call). */
206 /* The format specification for this instruction. */
209 /* The relocation (if any) associated with this instruction. */
213 /* PA-89 floating point registers are arranged like this:
216 +--------------+--------------+
217 | 0 or 16L | 16 or 16R |
218 +--------------+--------------+
219 | 1 or 17L | 17 or 17R |
220 +--------------+--------------+
228 +--------------+--------------+
229 | 14 or 30L | 30 or 30R |
230 +--------------+--------------+
231 | 15 or 31L | 31 or 31R |
232 +--------------+--------------+
235 The following is a version of pa_parse_number that
236 handles the L/R notation and returns the correct
237 value to put into the instruction register field.
238 The correct value to put into the instruction is
239 encoded in the structure 'pa_11_fp_reg_struct'. */
241 struct pa_11_fp_reg_struct
243 /* The register number. */
250 /* Additional information needed to build argument relocation stubs. */
253 /* The argument relocation specification. */
254 unsigned int arg_reloc
;
256 /* Number of arguments. */
257 unsigned int arg_count
;
260 /* This structure defines an entry in the subspace dictionary
263 struct subspace_dictionary_chain
265 /* Nonzero if this space has been defined by the user code. */
266 unsigned int ssd_defined
;
268 /* Name of this subspace. */
271 /* GAS segment and subsegment associated with this subspace. */
275 /* Next space in the subspace dictionary chain. */
276 struct subspace_dictionary_chain
*ssd_next
;
279 typedef struct subspace_dictionary_chain ssd_chain_struct
;
281 /* This structure defines an entry in the subspace dictionary
284 struct space_dictionary_chain
286 /* Nonzero if this space has been defined by the user code or
287 as a default space. */
288 unsigned int sd_defined
;
290 /* Nonzero if this spaces has been defined by the user code. */
291 unsigned int sd_user_defined
;
293 /* The space number (or index). */
294 unsigned int sd_spnum
;
296 /* The name of this subspace. */
299 /* GAS segment to which this subspace corresponds. */
302 /* Current subsegment number being used. */
305 /* The chain of subspaces contained within this space. */
306 ssd_chain_struct
*sd_subspaces
;
308 /* The next entry in the space dictionary chain. */
309 struct space_dictionary_chain
*sd_next
;
312 typedef struct space_dictionary_chain sd_chain_struct
;
314 /* Structure for previous label tracking. Needed so that alignments,
315 callinfo declarations, etc can be easily attached to a particular
317 typedef struct label_symbol_struct
319 struct symbol
*lss_label
;
320 sd_chain_struct
*lss_space
;
321 struct label_symbol_struct
*lss_next
;
325 /* This structure defines attributes of the default subspace
326 dictionary entries. */
328 struct default_subspace_dict
330 /* Name of the subspace. */
333 /* FIXME. Is this still needed? */
336 /* Nonzero if this subspace is loadable. */
339 /* Nonzero if this subspace contains only code. */
342 /* Nonzero if this is a common subspace. */
345 /* Nonzero if this is a common subspace which allows symbols
346 to be multiply defined. */
349 /* Nonzero if this subspace should be zero filled. */
352 /* Sort key for this subspace. */
355 /* Access control bits for this subspace. Can represent RWX access
356 as well as privilege level changes for gateways. */
359 /* Index of containing space. */
362 /* Alignment (in bytes) of this subspace. */
365 /* Quadrant within space where this subspace should be loaded. */
368 /* An index into the default spaces array. */
371 /* An alias for this section (or NULL if no alias exists). */
374 /* Subsegment associated with this subspace. */
378 /* This structure defines attributes of the default space
379 dictionary entries. */
381 struct default_space_dict
383 /* Name of the space. */
386 /* Space number. It is possible to identify spaces within
387 assembly code numerically! */
390 /* Nonzero if this space is loadable. */
393 /* Nonzero if this space is "defined". FIXME is still needed */
396 /* Nonzero if this space can not be shared. */
399 /* Sort key for this space. */
402 /* Segment associated with this space. */
405 /* An alias for this section (or NULL if no alias exists). */
409 /* Extra information needed to perform fixups (relocations) on the PA. */
410 struct hppa_fix_struct
412 /* The field selector. */
413 enum hppa_reloc_field_selector_type fx_r_field
;
418 /* Format of fixup. */
421 /* Argument relocation bits. */
424 /* The segment this fixup appears in. */
428 /* Structure to hold information about predefined registers. */
436 /* This structure defines the mapping from a FP condition string
437 to a condition number which can be recorded in an instruction. */
444 /* This structure defines a mapping from a field selector
445 string to a field selector type. */
446 struct selector_entry
452 /* Prototypes for functions local to tc-hppa.c. */
454 static void pa_check_current_space_and_subspace
PARAMS ((void));
455 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
456 static void pa_cons
PARAMS ((int));
457 static void pa_data
PARAMS ((int));
458 static void pa_float_cons
PARAMS ((int));
459 static void pa_fill
PARAMS ((int));
460 static void pa_lcomm
PARAMS ((int));
461 static void pa_lsym
PARAMS ((int));
462 static void pa_stringer
PARAMS ((int));
463 static void pa_text
PARAMS ((int));
464 static void pa_version
PARAMS ((int));
465 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
466 static int get_expression
PARAMS ((char *));
467 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
468 static int evaluate_absolute
PARAMS ((struct pa_it
*));
469 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
470 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
471 static int pa_parse_nullif
PARAMS ((char **));
472 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
473 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
474 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
475 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
476 static void pa_align
PARAMS ((int));
477 static void pa_block
PARAMS ((int));
478 static void pa_brtab
PARAMS ((int));
479 static void pa_call
PARAMS ((int));
480 static void pa_call_args
PARAMS ((struct call_desc
*));
481 static void pa_callinfo
PARAMS ((int));
482 static void pa_code
PARAMS ((int));
483 static void pa_comm
PARAMS ((int));
484 static void pa_copyright
PARAMS ((int));
485 static void pa_end
PARAMS ((int));
486 static void pa_enter
PARAMS ((int));
487 static void pa_entry
PARAMS ((int));
488 static void pa_equ
PARAMS ((int));
489 static void pa_exit
PARAMS ((int));
490 static void pa_export
PARAMS ((int));
491 static void pa_type_args
PARAMS ((symbolS
*, int));
492 static void pa_import
PARAMS ((int));
493 static void pa_label
PARAMS ((int));
494 static void pa_leave
PARAMS ((int));
495 static void pa_origin
PARAMS ((int));
496 static void pa_proc
PARAMS ((int));
497 static void pa_procend
PARAMS ((int));
498 static void pa_space
PARAMS ((int));
499 static void pa_spnum
PARAMS ((int));
500 static void pa_subspace
PARAMS ((int));
501 static void pa_param
PARAMS ((int));
502 static void pa_undefine_label
PARAMS ((void));
503 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
504 struct pa_11_fp_reg_struct
*));
505 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
506 static label_symbol_struct
*pa_get_label
PARAMS ((void));
507 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
510 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
515 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
516 char *, int, int, int,
520 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
521 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
522 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
523 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
525 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
526 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
527 static void pa_ip
PARAMS ((char *));
528 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
529 long, expressionS
*, int,
530 bfd_reloc_code_real_type
,
531 enum hppa_reloc_field_selector_type
,
533 static int is_end_of_statement
PARAMS ((void));
534 static int reg_name_search
PARAMS ((char *));
535 static int pa_chk_field_selector
PARAMS ((char **));
536 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
537 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
538 static void process_exit
PARAMS ((void));
539 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
540 static int log2
PARAMS ((int));
541 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
542 static unsigned int pa_stringer_aux
PARAMS ((char *));
543 static void pa_spaces_begin
PARAMS ((void));
544 static void hppa_elf_mark_end_of_function
PARAMS ((void));
546 /* File and gloally scoped variable declarations. */
548 /* Root and final entry in the space chain. */
549 static sd_chain_struct
*space_dict_root
;
550 static sd_chain_struct
*space_dict_last
;
552 /* The current space and subspace. */
553 static sd_chain_struct
*current_space
;
554 static ssd_chain_struct
*current_subspace
;
556 /* Root of the call_info chain. */
557 static struct call_info
*call_info_root
;
559 /* The last call_info (for functions) structure
560 seen so it can be associated with fixups and
562 static struct call_info
*last_call_info
;
564 /* The last call description (for actual calls). */
565 static struct call_desc last_call_desc
;
567 /* Jumps are always the same size -- one instruction. */
568 int md_short_jump_size
= 4;
569 int md_long_jump_size
= 4;
571 /* handle of the OPCODE hash table */
572 static struct hash_control
*op_hash
= NULL
;
574 /* This array holds the chars that always start a comment. If the
575 pre-processor is disabled, these aren't very useful. */
576 const char comment_chars
[] = ";";
578 /* Table of pseudo ops for the PA. FIXME -- how many of these
579 are now redundant with the overall GAS and the object file
581 const pseudo_typeS md_pseudo_table
[] =
583 /* align pseudo-ops on the PA specify the actual alignment requested,
584 not the log2 of the requested alignment. */
585 {"align", pa_align
, 8},
586 {"begin_brtab", pa_brtab
, 1},
587 {"block", pa_block
, 1},
588 {"blockz", pa_block
, 0},
589 {"byte", pa_cons
, 1},
590 {"call", pa_call
, 0},
591 {"callinfo", pa_callinfo
, 0},
592 {"code", pa_code
, 0},
593 {"comm", pa_comm
, 0},
594 {"copyright", pa_copyright
, 0},
595 {"data", pa_data
, 0},
596 {"double", pa_float_cons
, 'd'},
598 {"end_brtab", pa_brtab
, 0},
599 {"enter", pa_enter
, 0},
600 {"entry", pa_entry
, 0},
602 {"exit", pa_exit
, 0},
603 {"export", pa_export
, 0},
604 {"fill", pa_fill
, 0},
605 {"float", pa_float_cons
, 'f'},
606 {"half", pa_cons
, 2},
607 {"import", pa_import
, 0},
609 {"label", pa_label
, 0},
610 {"lcomm", pa_lcomm
, 0},
611 {"leave", pa_leave
, 0},
612 {"long", pa_cons
, 4},
613 {"lsym", pa_lsym
, 0},
614 {"nsubspa", pa_subspace
, 1},
615 {"octa", pa_cons
, 16},
616 {"org", pa_origin
, 0},
617 {"origin", pa_origin
, 0},
618 {"param", pa_param
, 0},
619 {"proc", pa_proc
, 0},
620 {"procend", pa_procend
, 0},
621 {"quad", pa_cons
, 8},
623 {"short", pa_cons
, 2},
624 {"single", pa_float_cons
, 'f'},
625 {"space", pa_space
, 0},
626 {"spnum", pa_spnum
, 0},
627 {"string", pa_stringer
, 0},
628 {"stringz", pa_stringer
, 1},
629 {"subspa", pa_subspace
, 0},
630 {"text", pa_text
, 0},
631 {"version", pa_version
, 0},
632 {"word", pa_cons
, 4},
636 /* This array holds the chars that only start a comment at the beginning of
637 a line. If the line seems to have the form '# 123 filename'
638 .line and .file directives will appear in the pre-processed output.
640 Note that input_file.c hand checks for '#' at the beginning of the
641 first line of the input file. This is because the compiler outputs
642 #NO_APP at the beginning of its output.
644 Also note that '/*' will always start a comment. */
645 const char line_comment_chars
[] = "#";
647 /* This array holds the characters which act as line separators. */
648 const char line_separator_chars
[] = "!";
650 /* Chars that can be used to separate mant from exp in floating point nums. */
651 const char EXP_CHARS
[] = "eE";
653 /* Chars that mean this number is a floating point constant.
654 As in 0f12.456 or 0d1.2345e12.
656 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
657 changed in read.c. Ideally it shouldn't hae to know abou it at
658 all, but nothing is ideal around here. */
659 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
661 static struct pa_it the_insn
;
663 /* Points to the end of an expression just parsed by get_expressoin
664 and friends. FIXME. This shouldn't be handled with a file-global
666 static char *expr_end
;
668 /* Nonzero if a .callinfo appeared within the current procedure. */
669 static int callinfo_found
;
671 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
672 static int within_entry_exit
;
674 /* Nonzero if the assembler is currently within a procedure definition. */
675 static int within_procedure
;
677 /* Handle on strucutre which keep track of the last symbol
678 seen in each subspace. */
679 static label_symbol_struct
*label_symbols_rootp
= NULL
;
681 /* Holds the last field selector. */
682 static int hppa_field_selector
;
684 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
685 static symbolS
*dummy_symbol
;
687 /* Nonzero if errors are to be printed. */
688 static int print_errors
= 1;
690 /* List of registers that are pre-defined:
692 Each general register has one predefined name of the form
693 %r<REGNUM> which has the value <REGNUM>.
695 Space and control registers are handled in a similar manner,
696 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
698 Likewise for the floating point registers, but of the form
699 %fr<REGNUM>. Floating point registers have additional predefined
700 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
701 again have the value <REGNUM>.
703 Many registers also have synonyms:
705 %r26 - %r23 have %arg0 - %arg3 as synonyms
706 %r28 - %r29 have %ret0 - %ret1 as synonyms
707 %r30 has %sp as a synonym
708 %r27 has %dp as a synonym
709 %r2 has %rp as a synonym
711 Almost every control register has a synonym; they are not listed
714 The table is sorted. Suitable for searching by a binary search. */
716 static const struct pd_reg pre_defined_registers
[] =
916 /* This table is sorted by order of the length of the string. This is
917 so we check for <> before we check for <. If we had a <> and checked
918 for < first, we would get a false match. */
919 static const struct fp_cond_map fp_cond_map
[] =
955 static const struct selector_entry selector_table
[] =
977 /* default space and subspace dictionaries */
979 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
980 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
982 /* pre-defined subsegments (subspaces) for the HPPA. */
983 #define SUBSEG_CODE 0
984 #define SUBSEG_DATA 0
987 #define SUBSEG_UNWIND 3
988 #define SUBSEG_GDB_STRINGS 0
989 #define SUBSEG_GDB_SYMBOLS 1
991 static struct default_subspace_dict pa_def_subspaces
[] =
993 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
994 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
995 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
996 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
998 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
1000 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1003 static struct default_space_dict pa_def_spaces
[] =
1005 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1006 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1007 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1010 /* Misc local definitions used by the assembler. */
1012 /* Return nonzero if the string pointed to by S potentially represents
1013 a right or left half of a FP register */
1014 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1015 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1017 /* These macros are used to maintain spaces/subspaces. */
1018 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1019 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1020 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1021 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1023 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1024 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1026 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1027 main loop after insertion. */
1029 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1031 ((OPCODE) |= (FIELD) << (START)); \
1035 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1036 IGNORE is used to suppress the error message. */
1038 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1040 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1043 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1049 #define is_DP_relative(exp) \
1050 ((exp).X_op == O_subtract \
1051 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1053 #define is_PC_relative(exp) \
1054 ((exp).X_op == O_subtract \
1055 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1057 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1058 always be able to reduce the expression to a constant, so we don't
1059 need real complex handling yet. */
1060 #define is_complex(exp) \
1061 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1063 /* Actual functions to implement the PA specific code for the assembler. */
1065 /* Called before writing the object file. Make sure entry/exit and
1066 proc/procend pairs match. */
1071 if (within_entry_exit
)
1072 as_fatal ("Missing .exit\n");
1074 if (within_procedure
)
1075 as_fatal ("Missing .procend\n");
1078 /* Check to make sure we have a valid space and subspace. */
1081 pa_check_current_space_and_subspace ()
1083 if (current_space
== NULL
)
1084 as_fatal ("Not in a space.\n");
1086 if (current_subspace
== NULL
)
1087 as_fatal ("Not in a subspace.\n");
1090 /* Returns a pointer to the label_symbol_struct for the current space.
1091 or NULL if no label_symbol_struct exists for the current space. */
1093 static label_symbol_struct
*
1096 label_symbol_struct
*label_chain
;
1097 sd_chain_struct
*space_chain
= current_space
;
1099 for (label_chain
= label_symbols_rootp
;
1101 label_chain
= label_chain
->lss_next
)
1102 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1108 /* Defines a label for the current space. If one is already defined,
1109 this function will replace it with the new label. */
1112 pa_define_label (symbol
)
1115 label_symbol_struct
*label_chain
= pa_get_label ();
1116 sd_chain_struct
*space_chain
= current_space
;
1119 label_chain
->lss_label
= symbol
;
1122 /* Create a new label entry and add it to the head of the chain. */
1124 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1125 label_chain
->lss_label
= symbol
;
1126 label_chain
->lss_space
= space_chain
;
1127 label_chain
->lss_next
= NULL
;
1129 if (label_symbols_rootp
)
1130 label_chain
->lss_next
= label_symbols_rootp
;
1132 label_symbols_rootp
= label_chain
;
1136 /* Removes a label definition for the current space.
1137 If there is no label_symbol_struct entry, then no action is taken. */
1140 pa_undefine_label ()
1142 label_symbol_struct
*label_chain
;
1143 label_symbol_struct
*prev_label_chain
= NULL
;
1144 sd_chain_struct
*space_chain
= current_space
;
1146 for (label_chain
= label_symbols_rootp
;
1148 label_chain
= label_chain
->lss_next
)
1150 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1152 /* Remove the label from the chain and free its memory. */
1153 if (prev_label_chain
)
1154 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1156 label_symbols_rootp
= label_chain
->lss_next
;
1161 prev_label_chain
= label_chain
;
1166 /* An HPPA-specific version of fix_new. This is required because the HPPA
1167 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1168 results in the creation of an instance of an hppa_fix_struct. An
1169 hppa_fix_struct stores the extra information along with a pointer to the
1170 original fixS. This is attached to the original fixup via the
1171 tc_fix_data field. */
1174 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1175 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1179 symbolS
*add_symbol
;
1183 bfd_reloc_code_real_type r_type
;
1184 enum hppa_reloc_field_selector_type r_field
;
1191 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1192 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1195 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1197 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1198 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1199 hppa_fix
->fx_r_type
= r_type
;
1200 hppa_fix
->fx_r_field
= r_field
;
1201 hppa_fix
->fx_r_format
= r_format
;
1202 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1203 hppa_fix
->segment
= now_seg
;
1205 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1206 new_fix
->fx_offset
= *unwind_bits
;
1209 /* foo-$global$ is used to access non-automatic storage. $global$
1210 is really just a marker and has served its purpose, so eliminate
1211 it now so as not to confuse write.c. */
1212 if (new_fix
->fx_subsy
1213 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1214 new_fix
->fx_subsy
= NULL
;
1217 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1218 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1221 parse_cons_expression_hppa (exp
)
1224 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1228 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1229 hppa_field_selector is set by the parse_cons_expression_hppa. */
1232 cons_fix_new_hppa (frag
, where
, size
, exp
)
1238 unsigned int rel_type
;
1240 /* Get a base relocation type. */
1241 if (is_DP_relative (*exp
))
1242 rel_type
= R_HPPA_GOTOFF
;
1243 else if (is_complex (*exp
))
1244 rel_type
= R_HPPA_COMPLEX
;
1248 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1249 as_warn ("Invalid field selector. Assuming F%%.");
1251 fix_new_hppa (frag
, where
, size
,
1252 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1253 hppa_field_selector
, 32, 0, NULL
);
1255 /* Reset field selector to its default state. */
1256 hppa_field_selector
= 0;
1259 /* This function is called once, at assembler startup time. It should
1260 set up all the tables, etc. that the MD part of the assembler will need. */
1265 const char *retval
= NULL
;
1269 last_call_info
= NULL
;
1270 call_info_root
= NULL
;
1272 /* Set the default machine type. */
1273 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1274 as_warn ("could not set architecture and machine");
1276 /* Folding of text and data segments fails miserably on the PA.
1277 Warn user and disable "-R" option. */
1278 if (flag_readonly_data_in_text
)
1280 as_warn ("-R option not supported on this target.");
1281 flag_readonly_data_in_text
= 0;
1286 op_hash
= hash_new ();
1288 while (i
< NUMOPCODES
)
1290 const char *name
= pa_opcodes
[i
].name
;
1291 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1292 if (retval
!= NULL
&& *retval
!= '\0')
1294 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1299 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1300 != pa_opcodes
[i
].match
)
1302 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1303 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1308 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1312 as_fatal ("Broken assembler. No assembly attempted.");
1314 /* SOM will change text_section. To make sure we never put
1315 anything into the old one switch to the new one now. */
1316 subseg_set (text_section
, 0);
1318 dummy_symbol
= symbol_find_or_make ("L$dummy");
1319 S_SET_SEGMENT (dummy_symbol
, text_section
);
1322 /* Assemble a single instruction storing it into a frag. */
1329 /* The had better be something to assemble. */
1332 /* If we are within a procedure definition, make sure we've
1333 defined a label for the procedure; handle case where the
1334 label was defined after the .PROC directive.
1336 Note there's not need to diddle with the segment or fragment
1337 for the label symbol in this case. We have already switched
1338 into the new $CODE$ subspace at this point. */
1339 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1341 label_symbol_struct
*label_symbol
= pa_get_label ();
1345 if (label_symbol
->lss_label
)
1347 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1348 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1350 /* Also handle allocation of a fixup to hold the unwind
1351 information when the label appears after the proc/procend. */
1352 if (within_entry_exit
)
1354 char *where
= frag_more (0);
1356 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1357 NULL
, (offsetT
) 0, NULL
,
1358 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1359 (int *)&last_call_info
->ci_unwind
.descriptor
);
1364 as_bad ("Missing function name for .PROC (corrupted label chain)");
1367 as_bad ("Missing function name for .PROC");
1370 /* Assemble the instruction. Results are saved into "the_insn". */
1373 /* Get somewhere to put the assembled instrution. */
1376 /* Output the opcode. */
1377 md_number_to_chars (to
, the_insn
.opcode
, 4);
1379 /* If necessary output more stuff. */
1380 if (the_insn
.reloc
!= R_HPPA_NONE
)
1381 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1382 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1383 the_insn
.reloc
, the_insn
.field_selector
,
1384 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1387 /* Do the real work for assembling a single instruction. Store results
1388 into the global "the_insn" variable. */
1394 char *error_message
= "";
1395 char *s
, c
, *argstart
, *name
, *save_s
;
1399 int cmpltr
, nullif
, flag
, cond
, num
;
1400 unsigned long opcode
;
1401 struct pa_opcode
*insn
;
1403 /* We must have a valid space and subspace. */
1404 pa_check_current_space_and_subspace ();
1406 /* Skip to something interesting. */
1407 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1426 as_fatal ("Unknown opcode: `%s'", str
);
1431 /* Convert everything into lower case. */
1434 if (isupper (*save_s
))
1435 *save_s
= tolower (*save_s
);
1439 /* Look up the opcode in the has table. */
1440 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1442 as_bad ("Unknown opcode: `%s'", str
);
1451 /* Mark the location where arguments for the instruction start, then
1452 start processing them. */
1456 /* Do some initialization. */
1457 opcode
= insn
->match
;
1458 bzero (&the_insn
, sizeof (the_insn
));
1460 the_insn
.reloc
= R_HPPA_NONE
;
1462 /* If this instruction is specific to a particular architecture,
1463 then set a new architecture. */
1464 if (bfd_get_mach (stdoutput
) < insn
->arch
)
1466 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1467 as_warn ("could not update architecture and machine");
1470 /* Build the opcode, checking as we go to make
1471 sure that the operands match. */
1472 for (args
= insn
->args
;; ++args
)
1477 /* End of arguments. */
1493 /* These must match exactly. */
1502 /* Handle a 5 bit register or control register field at 10. */
1505 num
= pa_parse_number (&s
, 0);
1506 CHECK_FIELD (num
, 31, 0, 0);
1507 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1509 /* Handle a 5 bit register field at 15. */
1511 num
= pa_parse_number (&s
, 0);
1512 CHECK_FIELD (num
, 31, 0, 0);
1513 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1515 /* Handle a 5 bit register field at 31. */
1518 num
= pa_parse_number (&s
, 0);
1519 CHECK_FIELD (num
, 31, 0, 0);
1520 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1522 /* Handle a 5 bit field length at 31. */
1524 num
= pa_get_absolute_expression (&the_insn
, &s
);
1526 CHECK_FIELD (num
, 32, 1, 0);
1527 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1529 /* Handle a 5 bit immediate at 15. */
1531 num
= pa_get_absolute_expression (&the_insn
, &s
);
1533 CHECK_FIELD (num
, 15, -16, 0);
1534 low_sign_unext (num
, 5, &num
);
1535 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1537 /* Handle a 5 bit immediate at 31. */
1539 num
= pa_get_absolute_expression (&the_insn
, &s
);
1541 CHECK_FIELD (num
, 15, -16, 0)
1542 low_sign_unext (num
, 5, &num
);
1543 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1545 /* Handle an unsigned 5 bit immediate at 31. */
1547 num
= pa_get_absolute_expression (&the_insn
, &s
);
1549 CHECK_FIELD (num
, 31, 0, 0);
1550 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1552 /* Handle an unsigned 5 bit immediate at 15. */
1554 num
= pa_get_absolute_expression (&the_insn
, &s
);
1556 CHECK_FIELD (num
, 31, 0, 0);
1557 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1559 /* Handle a 2 bit space identifier at 17. */
1561 num
= pa_parse_number (&s
, 0);
1562 CHECK_FIELD (num
, 3, 0, 1);
1563 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1565 /* Handle a 3 bit space identifier at 18. */
1567 num
= pa_parse_number (&s
, 0);
1568 CHECK_FIELD (num
, 7, 0, 1);
1569 dis_assemble_3 (num
, &num
);
1570 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1572 /* Handle a completer for an indexing load or store. */
1578 while (*s
== ',' && i
< 2)
1581 if (strncasecmp (s
, "sm", 2) == 0)
1588 else if (strncasecmp (s
, "m", 1) == 0)
1590 else if (strncasecmp (s
, "s", 1) == 0)
1593 as_bad ("Invalid Indexed Load Completer.");
1598 as_bad ("Invalid Indexed Load Completer Syntax.");
1600 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1603 /* Handle a short load/store completer. */
1611 if (strncasecmp (s
, "ma", 2) == 0)
1616 else if (strncasecmp (s
, "mb", 2) == 0)
1622 as_bad ("Invalid Short Load/Store Completer.");
1626 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1629 /* Handle a stbys completer. */
1635 while (*s
== ',' && i
< 2)
1638 if (strncasecmp (s
, "m", 1) == 0)
1640 else if (strncasecmp (s
, "b", 1) == 0)
1642 else if (strncasecmp (s
, "e", 1) == 0)
1645 as_bad ("Invalid Store Bytes Short Completer");
1650 as_bad ("Invalid Store Bytes Short Completer");
1652 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1655 /* Handle a non-negated compare/stubtract condition. */
1657 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1660 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1663 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1665 /* Handle a negated or non-negated compare/subtract condition. */
1668 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1672 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1675 as_bad ("Invalid Compare/Subtract Condition.");
1680 /* Negated condition requires an opcode change. */
1684 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1686 /* Handle non-negated add condition. */
1688 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1691 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1694 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1696 /* Handle a negated or non-negated add condition. */
1699 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1703 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1706 as_bad ("Invalid Compare/Subtract Condition");
1711 /* Negated condition requires an opcode change. */
1715 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1717 /* Handle a compare/subtract condition. */
1724 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1729 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1732 as_bad ("Invalid Compare/Subtract Condition");
1736 opcode
|= cmpltr
<< 13;
1737 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1739 /* Handle a non-negated add condition. */
1748 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1752 if (strcmp (name
, "=") == 0)
1754 else if (strcmp (name
, "<") == 0)
1756 else if (strcmp (name
, "<=") == 0)
1758 else if (strcasecmp (name
, "nuv") == 0)
1760 else if (strcasecmp (name
, "znv") == 0)
1762 else if (strcasecmp (name
, "sv") == 0)
1764 else if (strcasecmp (name
, "od") == 0)
1766 else if (strcasecmp (name
, "n") == 0)
1768 else if (strcasecmp (name
, "tr") == 0)
1773 else if (strcmp (name
, "<>") == 0)
1778 else if (strcmp (name
, ">=") == 0)
1783 else if (strcmp (name
, ">") == 0)
1788 else if (strcasecmp (name
, "uv") == 0)
1793 else if (strcasecmp (name
, "vnz") == 0)
1798 else if (strcasecmp (name
, "nsv") == 0)
1803 else if (strcasecmp (name
, "ev") == 0)
1809 as_bad ("Invalid Add Condition: %s", name
);
1812 nullif
= pa_parse_nullif (&s
);
1813 opcode
|= nullif
<< 1;
1814 opcode
|= cmpltr
<< 13;
1815 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1817 /* HANDLE a logical instruction condition. */
1825 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1829 if (strcmp (name
, "=") == 0)
1831 else if (strcmp (name
, "<") == 0)
1833 else if (strcmp (name
, "<=") == 0)
1835 else if (strcasecmp (name
, "od") == 0)
1837 else if (strcasecmp (name
, "tr") == 0)
1842 else if (strcmp (name
, "<>") == 0)
1847 else if (strcmp (name
, ">=") == 0)
1852 else if (strcmp (name
, ">") == 0)
1857 else if (strcasecmp (name
, "ev") == 0)
1863 as_bad ("Invalid Logical Instruction Condition.");
1866 opcode
|= cmpltr
<< 13;
1867 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1869 /* Handle a unit instruction condition. */
1876 if (strncasecmp (s
, "sbz", 3) == 0)
1881 else if (strncasecmp (s
, "shz", 3) == 0)
1886 else if (strncasecmp (s
, "sdc", 3) == 0)
1891 else if (strncasecmp (s
, "sbc", 3) == 0)
1896 else if (strncasecmp (s
, "shc", 3) == 0)
1901 else if (strncasecmp (s
, "tr", 2) == 0)
1907 else if (strncasecmp (s
, "nbz", 3) == 0)
1913 else if (strncasecmp (s
, "nhz", 3) == 0)
1919 else if (strncasecmp (s
, "ndc", 3) == 0)
1925 else if (strncasecmp (s
, "nbc", 3) == 0)
1931 else if (strncasecmp (s
, "nhc", 3) == 0)
1938 as_bad ("Invalid Logical Instruction Condition.");
1940 opcode
|= cmpltr
<< 13;
1941 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1943 /* Handle a shift/extract/deposit condition. */
1951 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1955 if (strcmp (name
, "=") == 0)
1957 else if (strcmp (name
, "<") == 0)
1959 else if (strcasecmp (name
, "od") == 0)
1961 else if (strcasecmp (name
, "tr") == 0)
1963 else if (strcmp (name
, "<>") == 0)
1965 else if (strcmp (name
, ">=") == 0)
1967 else if (strcasecmp (name
, "ev") == 0)
1969 /* Handle movb,n. Put things back the way they were.
1970 This includes moving s back to where it started. */
1971 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1978 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1981 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1983 /* Handle bvb and bb conditions. */
1989 if (strncmp (s
, "<", 1) == 0)
1994 else if (strncmp (s
, ">=", 2) == 0)
2000 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2002 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2004 /* Handle a system control completer. */
2006 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2014 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2016 /* Handle a nullification completer for branch instructions. */
2018 nullif
= pa_parse_nullif (&s
);
2019 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2021 /* Handle a nullification completer for copr and spop insns. */
2023 nullif
= pa_parse_nullif (&s
);
2024 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2026 /* Handle a 11 bit immediate at 31. */
2028 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2031 if (the_insn
.exp
.X_op
== O_constant
)
2033 num
= evaluate_absolute (&the_insn
);
2034 CHECK_FIELD (num
, 1023, -1024, 0);
2035 low_sign_unext (num
, 11, &num
);
2036 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2040 if (is_DP_relative (the_insn
.exp
))
2041 the_insn
.reloc
= R_HPPA_GOTOFF
;
2042 else if (is_PC_relative (the_insn
.exp
))
2043 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2045 the_insn
.reloc
= R_HPPA
;
2046 the_insn
.format
= 11;
2050 /* Handle a 14 bit immediate at 31. */
2052 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2055 if (the_insn
.exp
.X_op
== O_constant
)
2057 num
= evaluate_absolute (&the_insn
);
2058 CHECK_FIELD (num
, 8191, -8192, 0);
2059 low_sign_unext (num
, 14, &num
);
2060 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2064 if (is_DP_relative (the_insn
.exp
))
2065 the_insn
.reloc
= R_HPPA_GOTOFF
;
2066 else if (is_PC_relative (the_insn
.exp
))
2067 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2069 the_insn
.reloc
= R_HPPA
;
2070 the_insn
.format
= 14;
2074 /* Handle a 21 bit immediate at 31. */
2076 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2079 if (the_insn
.exp
.X_op
== O_constant
)
2081 num
= evaluate_absolute (&the_insn
);
2082 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2083 dis_assemble_21 (num
, &num
);
2084 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2088 if (is_DP_relative (the_insn
.exp
))
2089 the_insn
.reloc
= R_HPPA_GOTOFF
;
2090 else if (is_PC_relative (the_insn
.exp
))
2091 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2093 the_insn
.reloc
= R_HPPA
;
2094 the_insn
.format
= 21;
2098 /* Handle a 12 bit branch displacement. */
2100 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2104 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2106 unsigned int w1
, w
, result
;
2108 num
= evaluate_absolute (&the_insn
);
2111 as_bad ("Branch to unaligned address");
2114 CHECK_FIELD (num
, 8199, -8184, 0);
2115 sign_unext ((num
- 8) >> 2, 12, &result
);
2116 dis_assemble_12 (result
, &w1
, &w
);
2117 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2121 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2122 the_insn
.format
= 12;
2123 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2124 bzero (&last_call_desc
, sizeof (struct call_desc
));
2129 /* Handle a 17 bit branch displacement. */
2131 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2135 if (!the_insn
.exp
.X_add_symbol
2136 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2139 unsigned int w2
, w1
, w
, result
;
2141 num
= evaluate_absolute (&the_insn
);
2144 as_bad ("Branch to unaligned address");
2147 CHECK_FIELD (num
, 262143, -262144, 0);
2149 if (the_insn
.exp
.X_add_symbol
)
2152 sign_unext (num
>> 2, 17, &result
);
2153 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2154 INSERT_FIELD_AND_CONTINUE (opcode
,
2155 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2159 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2160 the_insn
.format
= 17;
2161 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2162 bzero (&last_call_desc
, sizeof (struct call_desc
));
2166 /* Handle an absolute 17 bit branch target. */
2168 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2172 if (!the_insn
.exp
.X_add_symbol
2173 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2176 unsigned int w2
, w1
, w
, result
;
2178 num
= evaluate_absolute (&the_insn
);
2181 as_bad ("Branch to unaligned address");
2184 CHECK_FIELD (num
, 262143, -262144, 0);
2186 if (the_insn
.exp
.X_add_symbol
)
2189 sign_unext (num
>> 2, 17, &result
);
2190 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2191 INSERT_FIELD_AND_CONTINUE (opcode
,
2192 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2196 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2197 the_insn
.format
= 17;
2198 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2199 bzero (&last_call_desc
, sizeof (struct call_desc
));
2203 /* Handle a 5 bit shift count at 26. */
2205 num
= pa_get_absolute_expression (&the_insn
, &s
);
2207 CHECK_FIELD (num
, 31, 0, 0);
2208 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2210 /* Handle a 5 bit bit position at 26. */
2212 num
= pa_get_absolute_expression (&the_insn
, &s
);
2214 CHECK_FIELD (num
, 31, 0, 0);
2215 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2217 /* Handle a 5 bit immediate at 10. */
2219 num
= pa_get_absolute_expression (&the_insn
, &s
);
2221 CHECK_FIELD (num
, 31, 0, 0);
2222 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2224 /* Handle a 13 bit immediate at 18. */
2226 num
= pa_get_absolute_expression (&the_insn
, &s
);
2228 CHECK_FIELD (num
, 8191, 0, 0);
2229 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2231 /* Handle a 26 bit immediate at 31. */
2233 num
= pa_get_absolute_expression (&the_insn
, &s
);
2235 CHECK_FIELD (num
, 671108864, 0, 0);
2236 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2238 /* Handle a 3 bit SFU identifier at 25. */
2241 as_bad ("Invalid SFU identifier");
2242 num
= pa_get_absolute_expression (&the_insn
, &s
);
2244 CHECK_FIELD (num
, 7, 0, 0);
2245 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2247 /* Handle a 20 bit SOP field for spop0. */
2249 num
= pa_get_absolute_expression (&the_insn
, &s
);
2251 CHECK_FIELD (num
, 1048575, 0, 0);
2252 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2253 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2255 /* Handle a 15bit SOP field for spop1. */
2257 num
= pa_get_absolute_expression (&the_insn
, &s
);
2259 CHECK_FIELD (num
, 32767, 0, 0);
2260 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2262 /* Handle a 10bit SOP field for spop3. */
2264 num
= pa_get_absolute_expression (&the_insn
, &s
);
2266 CHECK_FIELD (num
, 1023, 0, 0);
2267 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2268 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2270 /* Handle a 15 bit SOP field for spop2. */
2272 num
= pa_get_absolute_expression (&the_insn
, &s
);
2274 CHECK_FIELD (num
, 32767, 0, 0);
2275 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2276 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2278 /* Handle a 3-bit co-processor ID field. */
2281 as_bad ("Invalid COPR identifier");
2282 num
= pa_get_absolute_expression (&the_insn
, &s
);
2284 CHECK_FIELD (num
, 7, 0, 0);
2285 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2287 /* Handle a 22bit SOP field for copr. */
2289 num
= pa_get_absolute_expression (&the_insn
, &s
);
2291 CHECK_FIELD (num
, 4194303, 0, 0);
2292 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2293 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2295 /* Handle a source FP operand format completer. */
2297 flag
= pa_parse_fp_format (&s
);
2298 the_insn
.fpof1
= flag
;
2299 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2301 /* Handle a destination FP operand format completer. */
2303 /* pa_parse_format needs the ',' prefix. */
2305 flag
= pa_parse_fp_format (&s
);
2306 the_insn
.fpof2
= flag
;
2307 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2309 /* Handle FP compare conditions. */
2311 cond
= pa_parse_fp_cmp_cond (&s
);
2312 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2314 /* Handle L/R register halves like 't'. */
2317 struct pa_11_fp_reg_struct result
;
2319 pa_parse_number (&s
, &result
);
2320 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2321 opcode
|= result
.number_part
;
2323 /* 0x30 opcodes are FP arithmetic operation opcodes
2324 and need to be turned into 0x38 opcodes. This
2325 is not necessary for loads/stores. */
2326 if (need_pa11_opcode (&the_insn
, &result
)
2327 && ((opcode
& 0xfc000000) == 0x30000000))
2330 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2333 /* Handle L/R register halves like 'b'. */
2336 struct pa_11_fp_reg_struct result
;
2338 pa_parse_number (&s
, &result
);
2339 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2340 opcode
|= result
.number_part
<< 21;
2341 if (need_pa11_opcode (&the_insn
, &result
))
2343 opcode
|= (result
.l_r_select
& 1) << 7;
2349 /* Handle L/R register halves like 'x'. */
2352 struct pa_11_fp_reg_struct result
;
2354 pa_parse_number (&s
, &result
);
2355 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2356 opcode
|= (result
.number_part
& 0x1f) << 16;
2357 if (need_pa11_opcode (&the_insn
, &result
))
2359 opcode
|= (result
.l_r_select
& 1) << 12;
2365 /* Handle a 5 bit register field at 10. */
2368 struct pa_11_fp_reg_struct result
;
2370 pa_parse_number (&s
, &result
);
2371 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2372 if (the_insn
.fpof1
== SGL
)
2374 if (result
.number_part
< 16)
2376 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2380 result
.number_part
&= 0xF;
2381 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2383 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2386 /* Handle a 5 bit register field at 15. */
2389 struct pa_11_fp_reg_struct result
;
2391 pa_parse_number (&s
, &result
);
2392 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2393 if (the_insn
.fpof1
== SGL
)
2395 if (result
.number_part
< 16)
2397 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2400 result
.number_part
&= 0xF;
2401 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2403 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2406 /* Handle a 5 bit register field at 31. */
2409 struct pa_11_fp_reg_struct result
;
2411 pa_parse_number (&s
, &result
);
2412 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2413 if (the_insn
.fpof1
== SGL
)
2415 if (result
.number_part
< 16)
2417 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2420 result
.number_part
&= 0xF;
2421 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2423 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2426 /* Handle a 5 bit register field at 20. */
2429 struct pa_11_fp_reg_struct result
;
2431 pa_parse_number (&s
, &result
);
2432 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2433 if (the_insn
.fpof1
== SGL
)
2435 if (result
.number_part
< 16)
2437 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2440 result
.number_part
&= 0xF;
2441 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2443 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2446 /* Handle a 5 bit register field at 25. */
2449 struct pa_11_fp_reg_struct result
;
2451 pa_parse_number (&s
, &result
);
2452 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2453 if (the_insn
.fpof1
== SGL
)
2455 if (result
.number_part
< 16)
2457 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2460 result
.number_part
&= 0xF;
2461 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2463 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2466 /* Handle a floating point operand format at 26.
2467 Only allows single and double precision. */
2469 flag
= pa_parse_fp_format (&s
);
2475 the_insn
.fpof1
= flag
;
2481 as_bad ("Invalid Floating Point Operand Format.");
2491 /* Check if the args matched. */
2494 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2495 && !strcmp (insn
->name
, insn
[1].name
))
2503 as_bad ("Invalid operands %s", error_message
);
2510 the_insn
.opcode
= opcode
;
2513 /* Turn a string in input_line_pointer into a floating point constant of type
2514 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2515 emitted is stored in *sizeP . An error message or NULL is returned. */
2517 #define MAX_LITTLENUMS 6
2520 md_atof (type
, litP
, sizeP
)
2526 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2527 LITTLENUM_TYPE
*wordP
;
2559 return "Bad call to MD_ATOF()";
2561 t
= atof_ieee (input_line_pointer
, type
, words
);
2563 input_line_pointer
= t
;
2564 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2565 for (wordP
= words
; prec
--;)
2567 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2568 litP
+= sizeof (LITTLENUM_TYPE
);
2573 /* Write out big-endian. */
2576 md_number_to_chars (buf
, val
, n
)
2581 number_to_chars_bigendian (buf
, val
, n
);
2584 /* Translate internal representation of relocation info to BFD target
2588 tc_gen_reloc (section
, fixp
)
2593 struct hppa_fix_struct
*hppa_fixp
;
2594 bfd_reloc_code_real_type code
;
2595 static arelent
*no_relocs
= NULL
;
2597 bfd_reloc_code_real_type
**codes
;
2601 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2602 if (fixp
->fx_addsy
== 0)
2604 assert (hppa_fixp
!= 0);
2605 assert (section
!= 0);
2607 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2608 assert (reloc
!= 0);
2610 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2611 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2613 hppa_fixp
->fx_r_format
,
2614 hppa_fixp
->fx_r_field
,
2615 fixp
->fx_subsy
!= NULL
);
2617 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2620 relocs
= (arelent
**)
2621 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2622 assert (relocs
!= 0);
2624 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2625 sizeof (arelent
) * n_relocs
);
2627 assert (reloc
!= 0);
2629 for (i
= 0; i
< n_relocs
; i
++)
2630 relocs
[i
] = &reloc
[i
];
2632 relocs
[n_relocs
] = NULL
;
2635 switch (fixp
->fx_r_type
)
2638 assert (n_relocs
== 1);
2642 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2643 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2644 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2645 reloc
->addend
= 0; /* default */
2647 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2649 /* Now, do any processing that is dependent on the relocation type. */
2652 case R_PARISC_DLTREL21L
:
2653 case R_PARISC_DLTREL14R
:
2654 case R_PARISC_DLTREL14F
:
2655 case R_PARISC_PLABEL32
:
2656 case R_PARISC_PLABEL21L
:
2657 case R_PARISC_PLABEL14R
:
2658 /* For plabel relocations, the addend of the
2659 relocation should be either 0 (no static link) or 2
2660 (static link required).
2662 FIXME: We always assume no static link!
2664 We also slam a zero addend into the DLT relative relocs;
2665 it doesn't make a lot of sense to use any addend since
2666 it gets you a different (eg unknown) DLT entry. */
2670 case R_PARISC_PCREL21L
:
2671 case R_PARISC_PCREL17R
:
2672 case R_PARISC_PCREL17F
:
2673 case R_PARISC_PCREL17C
:
2674 case R_PARISC_PCREL14R
:
2675 case R_PARISC_PCREL14F
:
2676 /* The constant is stored in the instruction. */
2677 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2680 reloc
->addend
= fixp
->fx_offset
;
2687 /* Walk over reach relocation returned by the BFD backend. */
2688 for (i
= 0; i
< n_relocs
; i
++)
2692 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2693 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2694 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2699 /* The only time we ever use a R_COMP2 fixup is for the difference
2700 of two symbols. With that in mind we fill in all four
2701 relocs now and break out of the loop. */
2703 relocs
[0]->sym_ptr_ptr
= &bfd_abs_symbol
;
2704 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
2705 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2706 relocs
[0]->addend
= 0;
2707 relocs
[0]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2708 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
2709 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2710 relocs
[1]->addend
= 0;
2711 relocs
[2]->sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2712 relocs
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[2]);
2713 relocs
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2714 relocs
[2]->addend
= 0;
2715 relocs
[3]->sym_ptr_ptr
= &bfd_abs_symbol
;
2716 relocs
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[3]);
2717 relocs
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2718 relocs
[3]->addend
= 0;
2719 relocs
[4]->sym_ptr_ptr
= &bfd_abs_symbol
;
2720 relocs
[4]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[4]);
2721 relocs
[4]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2722 relocs
[4]->addend
= 0;
2726 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2732 /* For plabel relocations, the addend of the
2733 relocation should be either 0 (no static link) or 2
2734 (static link required).
2736 FIXME: We always assume no static link!
2738 We also slam a zero addend into the DLT relative relocs;
2739 it doesn't make a lot of sense to use any addend since
2740 it gets you a different (eg unknown) DLT entry. */
2741 relocs
[i
]->addend
= 0;
2753 /* There is no symbol or addend associated with these fixups. */
2754 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2755 relocs
[i
]->addend
= 0;
2760 /* There is no symbol associated with these fixups. */
2761 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2762 relocs
[i
]->addend
= fixp
->fx_offset
;
2766 relocs
[i
]->addend
= fixp
->fx_offset
;
2775 /* Process any machine dependent frag types. */
2778 md_convert_frag (abfd
, sec
, fragP
)
2780 register asection
*sec
;
2781 register fragS
*fragP
;
2783 unsigned int address
;
2785 if (fragP
->fr_type
== rs_machine_dependent
)
2787 switch ((int) fragP
->fr_subtype
)
2790 fragP
->fr_type
= rs_fill
;
2791 know (fragP
->fr_var
== 1);
2792 know (fragP
->fr_next
);
2793 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2794 if (address
% fragP
->fr_offset
)
2797 fragP
->fr_next
->fr_address
2802 fragP
->fr_offset
= 0;
2808 /* Round up a section size to the appropriate boundary. */
2811 md_section_align (segment
, size
)
2815 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2816 int align2
= (1 << align
) - 1;
2818 return (size
+ align2
) & ~align2
;
2821 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2823 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2825 addressT from_addr
, to_addr
;
2829 fprintf (stderr
, "pa_create_short_jmp\n");
2833 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2835 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2837 addressT from_addr
, to_addr
;
2841 fprintf (stderr
, "pa_create_long_jump\n");
2845 /* Return the approximate size of a frag before relaxation has occurred. */
2847 md_estimate_size_before_relax (fragP
, segment
)
2848 register fragS
*fragP
;
2855 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2861 CONST
char *md_shortopts
= "";
2862 struct option md_longopts
[] = {
2863 {NULL
, no_argument
, NULL
, 0}
2865 size_t md_longopts_size
= sizeof(md_longopts
);
2868 md_parse_option (c
, arg
)
2876 md_show_usage (stream
)
2881 /* We have no need to default values of symbols. */
2884 md_undefined_symbol (name
)
2890 /* Apply a fixup to an instruction. */
2893 md_apply_fix (fixP
, valp
)
2897 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2898 struct hppa_fix_struct
*hppa_fixP
;
2899 long new_val
, result
;
2900 unsigned int w1
, w2
, w
;
2902 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2903 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2904 never be "applied" (they are just markers). Likewise for
2905 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
2907 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2908 || fixP
->fx_r_type
== R_HPPA_EXIT
2909 || fixP
->fx_r_type
== R_HPPA_BEGIN_BRTAB
2910 || fixP
->fx_r_type
== R_HPPA_END_BRTAB
)
2914 /* There should have been an HPPA specific fixup associated
2915 with the GAS fixup. */
2918 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2919 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2921 /* If there is a symbol associated with this fixup, then it's something
2922 which will need a SOM relocation (except for some PC-relative relocs).
2923 In such cases we should treat the "val" or "addend" as zero since it
2924 will be added in as needed from fx_offset in tc_gen_reloc. */
2925 if ((fixP
->fx_addsy
!= NULL
2926 || fixP
->fx_r_type
== R_HPPA_NONE
)
2929 || hppa_fixP
->fx_r_field
== e_psel
2930 || hppa_fixP
->fx_r_field
== e_rpsel
2931 || hppa_fixP
->fx_r_field
== e_lpsel
2932 || hppa_fixP
->fx_r_field
== e_tsel
2933 || hppa_fixP
->fx_r_field
== e_rtsel
2934 || hppa_fixP
->fx_r_field
== e_ltsel
2937 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2939 /* This is truely disgusting. The machine independent code blindly
2940 adds in the value of the symbol being relocated against. Damn! */
2942 && fixP
->fx_addsy
!= NULL
2943 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
2944 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
2945 0, hppa_fixP
->fx_r_field
);
2948 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2950 /* Handle pc-relative exceptions from above. */
2951 #define arg_reloc_stub_needed(CALLER, CALLEE) \
2952 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2953 if ((fmt
== 12 || fmt
== 17)
2956 && !arg_reloc_stub_needed (((obj_symbol_type
*)
2957 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2958 hppa_fixP
->fx_arg_reloc
)
2959 && ((int)(*valp
) > -262144 && (int)(*valp
) < 262143)
2960 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
2962 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2964 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2965 #undef arg_reloc_stub_needed
2969 /* Handle all opcodes with the 'j' operand type. */
2971 CHECK_FIELD (new_val
, 8191, -8192, 0);
2973 /* Mask off 14 bits to be changed. */
2974 bfd_put_32 (stdoutput
,
2975 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2977 low_sign_unext (new_val
, 14, &result
);
2980 /* Handle all opcodes with the 'k' operand type. */
2982 CHECK_FIELD (new_val
, 2097152, 0, 0);
2984 /* Mask off 21 bits to be changed. */
2985 bfd_put_32 (stdoutput
,
2986 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2988 dis_assemble_21 (new_val
, &result
);
2991 /* Handle all the opcodes with the 'i' operand type. */
2993 CHECK_FIELD (new_val
, 1023, -1023, 0);
2995 /* Mask off 11 bits to be changed. */
2996 bfd_put_32 (stdoutput
,
2997 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2999 low_sign_unext (new_val
, 11, &result
);
3002 /* Handle all the opcodes with the 'w' operand type. */
3004 CHECK_FIELD (new_val
, 8199, -8184, 0)
3006 /* Mask off 11 bits to be changed. */
3007 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3008 bfd_put_32 (stdoutput
,
3009 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3012 dis_assemble_12 (result
, &w1
, &w
);
3013 result
= ((w1
<< 2) | w
);
3016 /* Handle some of the opcodes with the 'W' operand type. */
3018 CHECK_FIELD (new_val
, 262143, -262144, 0);
3020 /* Mask off 17 bits to be changed. */
3021 bfd_put_32 (stdoutput
,
3022 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3024 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3025 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3026 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3031 bfd_put_32 (stdoutput
, new_val
, buf
);
3035 as_bad ("Unknown relocation encountered in md_apply_fix.");
3039 /* Insert the relocation. */
3040 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3045 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3046 (unsigned int) fixP
, fixP
->fx_r_type
);
3051 /* Exactly what point is a PC-relative offset relative TO?
3052 On the PA, they're relative to the address of the offset. */
3055 md_pcrel_from (fixP
)
3058 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3061 /* Return nonzero if the input line pointer is at the end of
3065 is_end_of_statement ()
3067 return ((*input_line_pointer
== '\n')
3068 || (*input_line_pointer
== ';')
3069 || (*input_line_pointer
== '!'));
3072 /* Read a number from S. The number might come in one of many forms,
3073 the most common will be a hex or decimal constant, but it could be
3074 a pre-defined register (Yuk!), or an absolute symbol.
3076 Return a number or -1 for failure.
3078 When parsing PA-89 FP register numbers RESULT will be
3079 the address of a structure to return information about
3080 L/R half of FP registers, store results there as appropriate.
3082 pa_parse_number can not handle negative constants and will fail
3083 horribly if it is passed such a constant. */
3086 pa_parse_number (s
, result
)
3088 struct pa_11_fp_reg_struct
*result
;
3097 /* Skip whitespace before the number. */
3098 while (*p
== ' ' || *p
== '\t')
3101 /* Store info in RESULT if requested by caller. */
3104 result
->number_part
= -1;
3105 result
->l_r_select
= -1;
3111 /* Looks like a number. */
3114 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3116 /* The number is specified in hex. */
3118 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3119 || ((*p
>= 'A') && (*p
<= 'F')))
3122 num
= num
* 16 + *p
- '0';
3123 else if (*p
>= 'a' && *p
<= 'f')
3124 num
= num
* 16 + *p
- 'a' + 10;
3126 num
= num
* 16 + *p
- 'A' + 10;
3132 /* The number is specified in decimal. */
3133 while (isdigit (*p
))
3135 num
= num
* 10 + *p
- '0';
3140 /* Store info in RESULT if requested by the caller. */
3143 result
->number_part
= num
;
3145 if (IS_R_SELECT (p
))
3147 result
->l_r_select
= 1;
3150 else if (IS_L_SELECT (p
))
3152 result
->l_r_select
= 0;
3156 result
->l_r_select
= 0;
3161 /* The number might be a predefined register. */
3166 /* Tege hack: Special case for general registers as the general
3167 code makes a binary search with case translation, and is VERY
3172 if (*p
== 'e' && *(p
+ 1) == 't'
3173 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3176 num
= *p
- '0' + 28;
3184 else if (!isdigit (*p
))
3187 as_bad ("Undefined register: '%s'.", name
);
3193 num
= num
* 10 + *p
++ - '0';
3194 while (isdigit (*p
));
3199 /* Do a normal register search. */
3200 while (is_part_of_name (c
))
3206 status
= reg_name_search (name
);
3212 as_bad ("Undefined register: '%s'.", name
);
3218 /* Store info in RESULT if requested by caller. */
3221 result
->number_part
= num
;
3222 if (IS_R_SELECT (p
- 1))
3223 result
->l_r_select
= 1;
3224 else if (IS_L_SELECT (p
- 1))
3225 result
->l_r_select
= 0;
3227 result
->l_r_select
= 0;
3232 /* And finally, it could be a symbol in the absolute section which
3233 is effectively a constant. */
3237 while (is_part_of_name (c
))
3243 if ((sym
= symbol_find (name
)) != NULL
)
3245 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3246 num
= S_GET_VALUE (sym
);
3250 as_bad ("Non-absolute symbol: '%s'.", name
);
3256 /* There is where we'd come for an undefined symbol
3257 or for an empty string. For an empty string we
3258 will return zero. That's a concession made for
3259 compatability with the braindamaged HP assemblers. */
3265 as_bad ("Undefined absolute constant: '%s'.", name
);
3271 /* Store info in RESULT if requested by caller. */
3274 result
->number_part
= num
;
3275 if (IS_R_SELECT (p
- 1))
3276 result
->l_r_select
= 1;
3277 else if (IS_L_SELECT (p
- 1))
3278 result
->l_r_select
= 0;
3280 result
->l_r_select
= 0;
3288 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3290 /* Given NAME, find the register number associated with that name, return
3291 the integer value associated with the given name or -1 on failure. */
3294 reg_name_search (name
)
3297 int middle
, low
, high
;
3301 high
= REG_NAME_CNT
- 1;
3305 middle
= (low
+ high
) / 2;
3306 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3312 return pre_defined_registers
[middle
].value
;
3314 while (low
<= high
);
3320 /* Return nonzero if the given INSN and L/R information will require
3321 a new PA-1.1 opcode. */
3324 need_pa11_opcode (insn
, result
)
3326 struct pa_11_fp_reg_struct
*result
;
3328 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3330 /* If this instruction is specific to a particular architecture,
3331 then set a new architecture. */
3332 if (bfd_get_mach (stdoutput
) < pa11
)
3334 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
3335 as_warn ("could not update architecture and machine");
3343 /* Parse a condition for a fcmp instruction. Return the numerical
3344 code associated with the condition. */
3347 pa_parse_fp_cmp_cond (s
)
3354 for (i
= 0; i
< 32; i
++)
3356 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3357 strlen (fp_cond_map
[i
].string
)) == 0)
3359 cond
= fp_cond_map
[i
].cond
;
3360 *s
+= strlen (fp_cond_map
[i
].string
);
3361 /* If not a complete match, back up the input string and
3363 if (**s
!= ' ' && **s
!= '\t')
3365 *s
-= strlen (fp_cond_map
[i
].string
);
3368 while (**s
== ' ' || **s
== '\t')
3374 as_bad ("Invalid FP Compare Condition: %s", *s
);
3376 /* Advance over the bogus completer. */
3377 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3383 /* Parse an FP operand format completer returning the completer
3386 static fp_operand_format
3387 pa_parse_fp_format (s
)
3396 if (strncasecmp (*s
, "sgl", 3) == 0)
3401 else if (strncasecmp (*s
, "dbl", 3) == 0)
3406 else if (strncasecmp (*s
, "quad", 4) == 0)
3413 format
= ILLEGAL_FMT
;
3414 as_bad ("Invalid FP Operand Format: %3s", *s
);
3421 /* Convert from a selector string into a selector type. */
3424 pa_chk_field_selector (str
)
3427 int middle
, low
, high
;
3431 /* Read past any whitespace. */
3432 /* FIXME: should we read past newlines and formfeeds??? */
3433 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3436 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3437 name
[0] = tolower ((*str
)[0]),
3439 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3440 name
[0] = tolower ((*str
)[0]),
3441 name
[1] = tolower ((*str
)[1]),
3444 else if ((*str
)[3] == '\'' || (*str
)[3] == '%')
3445 name
[0] = tolower ((*str
)[0]),
3446 name
[1] = tolower ((*str
)[1]),
3447 name
[2] = tolower ((*str
)[2]),
3454 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3458 middle
= (low
+ high
) / 2;
3459 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3466 *str
+= strlen (name
) + 1;
3468 if (selector_table
[middle
].field_selector
== e_nsel
)
3471 return selector_table
[middle
].field_selector
;
3474 while (low
<= high
);
3479 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3482 get_expression (str
)
3488 save_in
= input_line_pointer
;
3489 input_line_pointer
= str
;
3490 seg
= expression (&the_insn
.exp
);
3491 if (!(seg
== absolute_section
3492 || seg
== undefined_section
3493 || SEG_NORMAL (seg
)))
3495 as_warn ("Bad segment in expression.");
3496 expr_end
= input_line_pointer
;
3497 input_line_pointer
= save_in
;
3500 expr_end
= input_line_pointer
;
3501 input_line_pointer
= save_in
;
3505 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3507 pa_get_absolute_expression (insn
, strp
)
3513 insn
->field_selector
= pa_chk_field_selector (strp
);
3514 save_in
= input_line_pointer
;
3515 input_line_pointer
= *strp
;
3516 expression (&insn
->exp
);
3517 if (insn
->exp
.X_op
!= O_constant
)
3519 as_bad ("Bad segment (should be absolute).");
3520 expr_end
= input_line_pointer
;
3521 input_line_pointer
= save_in
;
3524 expr_end
= input_line_pointer
;
3525 input_line_pointer
= save_in
;
3526 return evaluate_absolute (insn
);
3529 /* Evaluate an absolute expression EXP which may be modified by
3530 the selector FIELD_SELECTOR. Return the value of the expression. */
3532 evaluate_absolute (insn
)
3537 int field_selector
= insn
->field_selector
;
3540 value
= exp
.X_add_number
;
3542 switch (field_selector
)
3548 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3550 if (value
& 0x00000400)
3552 value
= (value
& 0xfffff800) >> 11;
3555 /* Sign extend from bit 21. */
3557 if (value
& 0x00000400)
3558 value
|= 0xfffff800;
3563 /* Arithmetic shift right 11 bits. */
3565 value
= (value
& 0xfffff800) >> 11;
3568 /* Set bits 0-20 to zero. */
3570 value
= value
& 0x7ff;
3573 /* Add 0x800 and arithmetic shift right 11 bits. */
3576 value
= (value
& 0xfffff800) >> 11;
3579 /* Set bitgs 0-21 to one. */
3581 value
|= 0xfffff800;
3584 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3586 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3590 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3595 BAD_CASE (field_selector
);
3601 /* Given an argument location specification return the associated
3602 argument location number. */
3605 pa_build_arg_reloc (type_name
)
3609 if (strncasecmp (type_name
, "no", 2) == 0)
3611 if (strncasecmp (type_name
, "gr", 2) == 0)
3613 else if (strncasecmp (type_name
, "fr", 2) == 0)
3615 else if (strncasecmp (type_name
, "fu", 2) == 0)
3618 as_bad ("Invalid argument location: %s\n", type_name
);
3623 /* Encode and return an argument relocation specification for
3624 the given register in the location specified by arg_reloc. */
3627 pa_align_arg_reloc (reg
, arg_reloc
)
3629 unsigned int arg_reloc
;
3631 unsigned int new_reloc
;
3633 new_reloc
= arg_reloc
;
3649 as_bad ("Invalid argument description: %d", reg
);
3655 /* Parse a PA nullification completer (,n). Return nonzero if the
3656 completer was found; return zero if no completer was found. */
3668 if (strncasecmp (*s
, "n", 1) == 0)
3672 as_bad ("Invalid Nullification: (%c)", **s
);
3681 /* Parse a non-negated compare/subtract completer returning the
3682 number (for encoding in instrutions) of the given completer.
3684 ISBRANCH specifies whether or not this is parsing a condition
3685 completer for a branch (vs a nullification completer for a
3686 computational instruction. */
3689 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3694 char *name
= *s
+ 1;
3702 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3706 if (strcmp (name
, "=") == 0)
3710 else if (strcmp (name
, "<") == 0)
3714 else if (strcmp (name
, "<=") == 0)
3718 else if (strcmp (name
, "<<") == 0)
3722 else if (strcmp (name
, "<<=") == 0)
3726 else if (strcasecmp (name
, "sv") == 0)
3730 else if (strcasecmp (name
, "od") == 0)
3734 /* If we have something like addb,n then there is no condition
3736 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3747 /* Reset pointers if this was really a ,n for a branch instruction. */
3748 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3754 /* Parse a negated compare/subtract completer returning the
3755 number (for encoding in instrutions) of the given completer.
3757 ISBRANCH specifies whether or not this is parsing a condition
3758 completer for a branch (vs a nullification completer for a
3759 computational instruction. */
3762 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3767 char *name
= *s
+ 1;
3775 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3779 if (strcasecmp (name
, "tr") == 0)
3783 else if (strcmp (name
, "<>") == 0)
3787 else if (strcmp (name
, ">=") == 0)
3791 else if (strcmp (name
, ">") == 0)
3795 else if (strcmp (name
, ">>=") == 0)
3799 else if (strcmp (name
, ">>") == 0)
3803 else if (strcasecmp (name
, "nsv") == 0)
3807 else if (strcasecmp (name
, "ev") == 0)
3811 /* If we have something like addb,n then there is no condition
3813 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3824 /* Reset pointers if this was really a ,n for a branch instruction. */
3825 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3831 /* Parse a non-negated addition completer returning the number
3832 (for encoding in instrutions) of the given completer.
3834 ISBRANCH specifies whether or not this is parsing a condition
3835 completer for a branch (vs a nullification completer for a
3836 computational instruction. */
3839 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3844 char *name
= *s
+ 1;
3852 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3856 if (strcmp (name
, "=") == 0)
3860 else if (strcmp (name
, "<") == 0)
3864 else if (strcmp (name
, "<=") == 0)
3868 else if (strcasecmp (name
, "nuv") == 0)
3872 else if (strcasecmp (name
, "znv") == 0)
3876 else if (strcasecmp (name
, "sv") == 0)
3880 else if (strcasecmp (name
, "od") == 0)
3884 /* If we have something like addb,n then there is no condition
3886 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3897 /* Reset pointers if this was really a ,n for a branch instruction. */
3898 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3904 /* Parse a negated addition completer returning the number
3905 (for encoding in instrutions) of the given completer.
3907 ISBRANCH specifies whether or not this is parsing a condition
3908 completer for a branch (vs a nullification completer for a
3909 computational instruction. */
3912 pa_parse_neg_add_cmpltr (s
, isbranch
)
3917 char *name
= *s
+ 1;
3925 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3929 if (strcasecmp (name
, "tr") == 0)
3933 else if (strcmp (name
, "<>") == 0)
3937 else if (strcmp (name
, ">=") == 0)
3941 else if (strcmp (name
, ">") == 0)
3945 else if (strcasecmp (name
, "uv") == 0)
3949 else if (strcasecmp (name
, "vnz") == 0)
3953 else if (strcasecmp (name
, "nsv") == 0)
3957 else if (strcasecmp (name
, "ev") == 0)
3961 /* If we have something like addb,n then there is no condition
3963 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3974 /* Reset pointers if this was really a ,n for a branch instruction. */
3975 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3981 /* Handle an alignment directive. Special so that we can update the
3982 alignment of the subspace if necessary. */
3986 /* We must have a valid space and subspace. */
3987 pa_check_current_space_and_subspace ();
3989 /* Let the generic gas code do most of the work. */
3990 s_align_bytes (bytes
);
3992 /* If bytes is a power of 2, then update the current subspace's
3993 alignment if necessary. */
3994 if (log2 (bytes
) != -1)
3995 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
3998 /* Handle a .BLOCK type pseudo-op. */
4006 unsigned int temp_size
;
4009 /* We must have a valid space and subspace. */
4010 pa_check_current_space_and_subspace ();
4012 temp_size
= get_absolute_expression ();
4014 /* Always fill with zeros, that's what the HP assembler does. */
4017 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4018 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4019 bzero (p
, temp_size
);
4021 /* Convert 2 bytes at a time. */
4023 for (i
= 0; i
< temp_size
; i
+= 2)
4025 md_number_to_chars (p
+ i
,
4027 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4030 pa_undefine_label ();
4031 demand_empty_rest_of_line ();
4034 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4042 /* The BRTAB relocations are only availble in SOM (to denote
4043 the beginning and end of branch tables). */
4044 char *where
= frag_more (0);
4046 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4047 NULL
, (offsetT
) 0, NULL
,
4048 0, begin
? R_HPPA_BEGIN_BRTAB
: R_HPPA_END_BRTAB
,
4049 e_fsel
, 0, 0, NULL
);
4052 demand_empty_rest_of_line ();
4055 /* Handle a .CALL pseudo-op. This involves storing away information
4056 about where arguments are to be found so the linker can detect
4057 (and correct) argument location mismatches between caller and callee. */
4063 /* We must have a valid space and subspace. */
4064 pa_check_current_space_and_subspace ();
4066 pa_call_args (&last_call_desc
);
4067 demand_empty_rest_of_line ();
4070 /* Do the dirty work of building a call descriptor which describes
4071 where the caller placed arguments to a function call. */
4074 pa_call_args (call_desc
)
4075 struct call_desc
*call_desc
;
4078 unsigned int temp
, arg_reloc
;
4080 while (!is_end_of_statement ())
4082 name
= input_line_pointer
;
4083 c
= get_symbol_end ();
4084 /* Process a source argument. */
4085 if ((strncasecmp (name
, "argw", 4) == 0))
4087 temp
= atoi (name
+ 4);
4088 p
= input_line_pointer
;
4090 input_line_pointer
++;
4091 name
= input_line_pointer
;
4092 c
= get_symbol_end ();
4093 arg_reloc
= pa_build_arg_reloc (name
);
4094 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4096 /* Process a return value. */
4097 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4099 p
= input_line_pointer
;
4101 input_line_pointer
++;
4102 name
= input_line_pointer
;
4103 c
= get_symbol_end ();
4104 arg_reloc
= pa_build_arg_reloc (name
);
4105 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4109 as_bad ("Invalid .CALL argument: %s", name
);
4111 p
= input_line_pointer
;
4113 if (!is_end_of_statement ())
4114 input_line_pointer
++;
4118 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4121 is_same_frag (frag1
, frag2
)
4128 else if (frag2
== NULL
)
4130 else if (frag1
== frag2
)
4132 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4133 return (is_same_frag (frag1
, frag2
->fr_next
));
4139 /* Build an entry in the UNWIND subspace from the given function
4140 attributes in CALL_INFO. This is not needed for SOM as using
4141 R_ENTRY and R_EXIT relocations allow the linker to handle building
4142 of the unwind spaces. */
4145 pa_build_unwind_subspace (call_info
)
4146 struct call_info
*call_info
;
4149 asection
*seg
, *save_seg
;
4150 subsegT subseg
, save_subseg
;
4154 /* Get into the right seg/subseg. This may involve creating
4155 the seg the first time through. Make sure to have the
4156 old seg/subseg so that we can reset things when we are done. */
4157 subseg
= SUBSEG_UNWIND
;
4158 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4159 if (seg
== ASEC_NULL
)
4161 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4162 bfd_set_section_flags (stdoutput
, seg
,
4163 SEC_READONLY
| SEC_HAS_CONTENTS
4164 | SEC_LOAD
| SEC_RELOC
);
4168 save_subseg
= now_subseg
;
4169 subseg_set (seg
, subseg
);
4172 /* Get some space to hold relocation information for the unwind
4175 md_number_to_chars (p
, 0, 4);
4177 /* Relocation info. for start offset of the function. */
4178 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4179 call_info
->start_symbol
, (offsetT
) 0,
4180 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4183 md_number_to_chars (p
, 0, 4);
4185 /* Relocation info. for end offset of the function.
4187 Because we allow reductions of 32bit relocations for ELF, this will be
4188 reduced to section_sym + offset which avoids putting the temporary
4189 symbol into the symbol table. It (should) end up giving the same
4190 value as call_info->start_symbol + function size once the linker is
4191 finished with its work. */
4193 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4194 call_info
->end_symbol
, (offsetT
) 0,
4195 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4198 unwind
= (char *) &call_info
->ci_unwind
;
4199 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4203 FRAG_APPEND_1_CHAR (c
);
4207 /* Return back to the original segment/subsegment. */
4208 subseg_set (save_seg
, save_subseg
);
4212 /* Process a .CALLINFO pseudo-op. This information is used later
4213 to build unwind descriptors and maybe one day to support
4214 .ENTER and .LEAVE. */
4217 pa_callinfo (unused
)
4223 /* We must have a valid space and subspace. */
4224 pa_check_current_space_and_subspace ();
4226 /* .CALLINFO must appear within a procedure definition. */
4227 if (!within_procedure
)
4228 as_bad (".callinfo is not within a procedure definition");
4230 /* Mark the fact that we found the .CALLINFO for the
4231 current procedure. */
4232 callinfo_found
= TRUE
;
4234 /* Iterate over the .CALLINFO arguments. */
4235 while (!is_end_of_statement ())
4237 name
= input_line_pointer
;
4238 c
= get_symbol_end ();
4239 /* Frame size specification. */
4240 if ((strncasecmp (name
, "frame", 5) == 0))
4242 p
= input_line_pointer
;
4244 input_line_pointer
++;
4245 temp
= get_absolute_expression ();
4246 if ((temp
& 0x3) != 0)
4248 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4252 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4253 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4256 /* Entry register (GR, GR and SR) specifications. */
4257 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4259 p
= input_line_pointer
;
4261 input_line_pointer
++;
4262 temp
= get_absolute_expression ();
4263 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4264 even though %r19 is caller saved. I think this is a bug in
4265 the HP assembler, and we are not going to emulate it. */
4266 if (temp
< 3 || temp
> 18)
4267 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4268 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4270 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4272 p
= input_line_pointer
;
4274 input_line_pointer
++;
4275 temp
= get_absolute_expression ();
4276 /* Similarly the HP assembler takes 31 as the high bound even
4277 though %fr21 is the last callee saved floating point register. */
4278 if (temp
< 12 || temp
> 21)
4279 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4280 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4282 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4284 p
= input_line_pointer
;
4286 input_line_pointer
++;
4287 temp
= get_absolute_expression ();
4289 as_bad ("Value for ENTRY_SR must be 3\n");
4291 /* Note whether or not this function performs any calls. */
4292 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4293 (strncasecmp (name
, "caller", 6) == 0))
4295 p
= input_line_pointer
;
4298 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4300 p
= input_line_pointer
;
4303 /* Should RP be saved into the stack. */
4304 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4306 p
= input_line_pointer
;
4308 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4310 /* Likewise for SP. */
4311 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4313 p
= input_line_pointer
;
4315 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4317 /* Is this an unwindable procedure. If so mark it so
4318 in the unwind descriptor. */
4319 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4321 p
= input_line_pointer
;
4323 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4325 /* Is this an interrupt routine. If so mark it in the
4326 unwind descriptor. */
4327 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4329 p
= input_line_pointer
;
4331 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4333 /* Is this a millicode routine. "millicode" isn't in my
4334 assembler manual, but my copy is old. The HP assembler
4335 accepts it, and there's a place in the unwind descriptor
4336 to drop the information, so we'll accept it too. */
4337 else if ((strncasecmp (name
, "millicode", 9) == 0))
4339 p
= input_line_pointer
;
4341 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4345 as_bad ("Invalid .CALLINFO argument: %s", name
);
4346 *input_line_pointer
= c
;
4348 if (!is_end_of_statement ())
4349 input_line_pointer
++;
4352 demand_empty_rest_of_line ();
4355 /* Switch into the code subspace. */
4361 current_space
= is_defined_space ("$TEXT$");
4363 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
4365 pa_undefine_label ();
4368 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4369 the .comm pseudo-op has the following symtax:
4371 <label> .comm <length>
4373 where <label> is optional and is a symbol whose address will be the start of
4374 a block of memory <length> bytes long. <length> must be an absolute
4375 expression. <length> bytes will be allocated in the current space
4378 Also note the label may not even be on the same line as the .comm.
4380 This difference in syntax means the colon function will be called
4381 on the symbol before we arrive in pa_comm. colon will set a number
4382 of attributes of the symbol that need to be fixed here. In particular
4383 the value, section pointer, fragment pointer, flags, etc. What
4386 This also makes error detection all but impossible. */
4394 label_symbol_struct
*label_symbol
= pa_get_label ();
4397 symbol
= label_symbol
->lss_label
;
4402 size
= get_absolute_expression ();
4406 S_SET_VALUE (symbol
, size
);
4407 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4408 S_SET_EXTERNAL (symbol
);
4410 /* colon() has already set the frag to the current location in the
4411 current subspace; we need to reset the fragment to the zero address
4412 fragment. We also need to reset the segment pointer. */
4413 symbol
->sy_frag
= &zero_address_frag
;
4415 demand_empty_rest_of_line ();
4418 /* Process a .END pseudo-op. */
4424 demand_empty_rest_of_line ();
4427 /* Process a .ENTER pseudo-op. This is not supported. */
4432 /* We must have a valid space and subspace. */
4433 pa_check_current_space_and_subspace ();
4438 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4444 /* We must have a valid space and subspace. */
4445 pa_check_current_space_and_subspace ();
4447 if (!within_procedure
)
4448 as_bad ("Misplaced .entry. Ignored.");
4451 if (!callinfo_found
)
4452 as_bad ("Missing .callinfo.");
4454 demand_empty_rest_of_line ();
4455 within_entry_exit
= TRUE
;
4458 /* SOM defers building of unwind descriptors until the link phase.
4459 The assembler is responsible for creating an R_ENTRY relocation
4460 to mark the beginning of a region and hold the unwind bits, and
4461 for creating an R_EXIT relocation to mark the end of the region.
4463 FIXME. ELF should be using the same conventions! The problem
4464 is an unwind requires too much relocation space. Hmmm. Maybe
4465 if we split the unwind bits up between the relocations which
4466 denote the entry and exit points. */
4467 if (last_call_info
->start_symbol
!= NULL
)
4469 char *where
= frag_more (0);
4471 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4472 NULL
, (offsetT
) 0, NULL
,
4473 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4474 (int *) &last_call_info
->ci_unwind
.descriptor
);
4479 /* Handle a .EQU pseudo-op. */
4485 label_symbol_struct
*label_symbol
= pa_get_label ();
4490 symbol
= label_symbol
->lss_label
;
4492 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4494 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4495 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4500 as_bad (".REG must use a label");
4502 as_bad (".EQU must use a label");
4505 pa_undefine_label ();
4506 demand_empty_rest_of_line ();
4509 /* Helper function. Does processing for the end of a function. This
4510 usually involves creating some relocations or building special
4511 symbols to mark the end of the function. */
4518 where
= frag_more (0);
4521 /* Mark the end of the function, stuff away the location of the frag
4522 for the end of the function, and finally call pa_build_unwind_subspace
4523 to add an entry in the unwind table. */
4524 hppa_elf_mark_end_of_function ();
4525 pa_build_unwind_subspace (last_call_info
);
4527 /* SOM defers building of unwind descriptors until the link phase.
4528 The assembler is responsible for creating an R_ENTRY relocation
4529 to mark the beginning of a region and hold the unwind bits, and
4530 for creating an R_EXIT relocation to mark the end of the region.
4532 FIXME. ELF should be using the same conventions! The problem
4533 is an unwind requires too much relocation space. Hmmm. Maybe
4534 if we split the unwind bits up between the relocations which
4535 denote the entry and exit points. */
4536 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4538 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4539 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4543 /* Process a .EXIT pseudo-op. */
4549 /* We must have a valid space and subspace. */
4550 pa_check_current_space_and_subspace ();
4552 if (!within_procedure
)
4553 as_bad (".EXIT must appear within a procedure");
4556 if (!callinfo_found
)
4557 as_bad ("Missing .callinfo");
4560 if (!within_entry_exit
)
4561 as_bad ("No .ENTRY for this .EXIT");
4564 within_entry_exit
= FALSE
;
4569 demand_empty_rest_of_line ();
4572 /* Process a .EXPORT directive. This makes functions external
4573 and provides information such as argument relocation entries
4583 name
= input_line_pointer
;
4584 c
= get_symbol_end ();
4585 /* Make sure the given symbol exists. */
4586 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4588 as_bad ("Cannot define export symbol: %s\n", name
);
4589 p
= input_line_pointer
;
4591 input_line_pointer
++;
4595 /* OK. Set the external bits and process argument relocations. */
4596 S_SET_EXTERNAL (symbol
);
4597 p
= input_line_pointer
;
4599 if (!is_end_of_statement ())
4601 input_line_pointer
++;
4602 pa_type_args (symbol
, 1);
4606 demand_empty_rest_of_line ();
4609 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4612 pa_type_args (symbolP
, is_export
)
4617 unsigned int temp
, arg_reloc
;
4618 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4619 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4621 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4624 input_line_pointer
+= 8;
4625 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4626 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4627 type
= SYMBOL_TYPE_ABSOLUTE
;
4629 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4631 input_line_pointer
+= 4;
4632 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4633 instead one should be IMPORTing/EXPORTing ENTRY types.
4635 Complain if one tries to EXPORT a CODE type since that's never
4636 done. Both GCC and HP C still try to IMPORT CODE types, so
4637 silently fix them to be ENTRY types. */
4638 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4641 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4643 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4644 type
= SYMBOL_TYPE_ENTRY
;
4648 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4649 type
= SYMBOL_TYPE_CODE
;
4652 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4654 input_line_pointer
+= 4;
4655 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4656 type
= SYMBOL_TYPE_DATA
;
4658 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4660 input_line_pointer
+= 5;
4661 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4662 type
= SYMBOL_TYPE_ENTRY
;
4664 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4666 input_line_pointer
+= 9;
4667 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4668 type
= SYMBOL_TYPE_MILLICODE
;
4670 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4672 input_line_pointer
+= 6;
4673 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4674 type
= SYMBOL_TYPE_PLABEL
;
4676 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4678 input_line_pointer
+= 8;
4679 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4680 type
= SYMBOL_TYPE_PRI_PROG
;
4682 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4684 input_line_pointer
+= 8;
4685 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4686 type
= SYMBOL_TYPE_SEC_PROG
;
4689 /* SOM requires much more information about symbol types
4690 than BFD understands. This is how we get this information
4691 to the SOM BFD backend. */
4692 #ifdef obj_set_symbol_type
4693 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4696 /* Now that the type of the exported symbol has been handled,
4697 handle any argument relocation information. */
4698 while (!is_end_of_statement ())
4700 if (*input_line_pointer
== ',')
4701 input_line_pointer
++;
4702 name
= input_line_pointer
;
4703 c
= get_symbol_end ();
4704 /* Argument sources. */
4705 if ((strncasecmp (name
, "argw", 4) == 0))
4707 p
= input_line_pointer
;
4709 input_line_pointer
++;
4710 temp
= atoi (name
+ 4);
4711 name
= input_line_pointer
;
4712 c
= get_symbol_end ();
4713 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4714 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4715 *input_line_pointer
= c
;
4717 /* The return value. */
4718 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4720 p
= input_line_pointer
;
4722 input_line_pointer
++;
4723 name
= input_line_pointer
;
4724 c
= get_symbol_end ();
4725 arg_reloc
= pa_build_arg_reloc (name
);
4726 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4727 *input_line_pointer
= c
;
4729 /* Privelege level. */
4730 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4732 p
= input_line_pointer
;
4734 input_line_pointer
++;
4735 temp
= atoi (input_line_pointer
);
4736 c
= get_symbol_end ();
4737 *input_line_pointer
= c
;
4741 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4742 p
= input_line_pointer
;
4745 if (!is_end_of_statement ())
4746 input_line_pointer
++;
4750 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4751 assembly file must either be defined in the assembly file, or
4752 explicitly IMPORTED from another. */
4761 name
= input_line_pointer
;
4762 c
= get_symbol_end ();
4764 symbol
= symbol_find (name
);
4765 /* Ugh. We might be importing a symbol defined earlier in the file,
4766 in which case all the code below will really screw things up
4767 (set the wrong segment, symbol flags & type, etc). */
4768 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4770 symbol
= symbol_find_or_make (name
);
4771 p
= input_line_pointer
;
4774 if (!is_end_of_statement ())
4776 input_line_pointer
++;
4777 pa_type_args (symbol
, 0);
4781 /* Sigh. To be compatable with the HP assembler and to help
4782 poorly written assembly code, we assign a type based on
4783 the the current segment. Note only BSF_FUNCTION really
4784 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4785 if (now_seg
== text_section
)
4786 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4788 /* If the section is undefined, then the symbol is undefined
4789 Since this is an import, leave the section undefined. */
4790 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4795 /* The symbol was already defined. Just eat everything up to
4796 the end of the current statement. */
4797 while (!is_end_of_statement ())
4798 input_line_pointer
++;
4801 demand_empty_rest_of_line ();
4804 /* Handle a .LABEL pseudo-op. */
4812 name
= input_line_pointer
;
4813 c
= get_symbol_end ();
4815 if (strlen (name
) > 0)
4818 p
= input_line_pointer
;
4823 as_warn ("Missing label name on .LABEL");
4826 if (!is_end_of_statement ())
4828 as_warn ("extra .LABEL arguments ignored.");
4829 ignore_rest_of_line ();
4831 demand_empty_rest_of_line ();
4834 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4840 /* We must have a valid space and subspace. */
4841 pa_check_current_space_and_subspace ();
4846 /* Handle a .ORIGIN pseudo-op. */
4852 /* We must have a valid space and subspace. */
4853 pa_check_current_space_and_subspace ();
4856 pa_undefine_label ();
4859 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4860 is for static functions. FIXME. Should share more code with .EXPORT. */
4869 name
= input_line_pointer
;
4870 c
= get_symbol_end ();
4872 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4874 as_bad ("Cannot define static symbol: %s\n", name
);
4875 p
= input_line_pointer
;
4877 input_line_pointer
++;
4881 S_CLEAR_EXTERNAL (symbol
);
4882 p
= input_line_pointer
;
4884 if (!is_end_of_statement ())
4886 input_line_pointer
++;
4887 pa_type_args (symbol
, 0);
4891 demand_empty_rest_of_line ();
4894 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4895 of a procedure from a syntatical point of view. */
4901 struct call_info
*call_info
;
4903 /* We must have a valid space and subspace. */
4904 pa_check_current_space_and_subspace ();
4906 if (within_procedure
)
4907 as_fatal ("Nested procedures");
4909 /* Reset global variables for new procedure. */
4910 callinfo_found
= FALSE
;
4911 within_procedure
= TRUE
;
4913 /* Create another call_info structure. */
4914 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4917 as_fatal ("Cannot allocate unwind descriptor\n");
4919 bzero (call_info
, sizeof (struct call_info
));
4921 call_info
->ci_next
= NULL
;
4923 if (call_info_root
== NULL
)
4925 call_info_root
= call_info
;
4926 last_call_info
= call_info
;
4930 last_call_info
->ci_next
= call_info
;
4931 last_call_info
= call_info
;
4934 /* set up defaults on call_info structure */
4936 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4937 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4938 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4940 /* If we got a .PROC pseudo-op, we know that the function is defined
4941 locally. Make sure it gets into the symbol table. */
4943 label_symbol_struct
*label_symbol
= pa_get_label ();
4947 if (label_symbol
->lss_label
)
4949 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4950 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4953 as_bad ("Missing function name for .PROC (corrupted label chain)");
4956 last_call_info
->start_symbol
= NULL
;
4959 demand_empty_rest_of_line ();
4962 /* Process the syntatical end of a procedure. Make sure all the
4963 appropriate pseudo-ops were found within the procedure. */
4970 /* We must have a valid space and subspace. */
4971 pa_check_current_space_and_subspace ();
4973 /* If we are within a procedure definition, make sure we've
4974 defined a label for the procedure; handle case where the
4975 label was defined after the .PROC directive.
4977 Note there's not need to diddle with the segment or fragment
4978 for the label symbol in this case. We have already switched
4979 into the new $CODE$ subspace at this point. */
4980 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4982 label_symbol_struct
*label_symbol
= pa_get_label ();
4986 if (label_symbol
->lss_label
)
4988 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4989 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4991 /* Also handle allocation of a fixup to hold the unwind
4992 information when the label appears after the proc/procend. */
4993 if (within_entry_exit
)
4995 char *where
= frag_more (0);
4997 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4998 NULL
, (offsetT
) 0, NULL
,
4999 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
5000 (int *) &last_call_info
->ci_unwind
.descriptor
);
5005 as_bad ("Missing function name for .PROC (corrupted label chain)");
5008 as_bad ("Missing function name for .PROC");
5011 if (!within_procedure
)
5012 as_bad ("misplaced .procend");
5014 if (!callinfo_found
)
5015 as_bad ("Missing .callinfo for this procedure");
5017 if (within_entry_exit
)
5018 as_bad ("Missing .EXIT for a .ENTRY");
5021 /* ELF needs to mark the end of each function so that it can compute
5022 the size of the function (apparently its needed in the symbol table). */
5023 hppa_elf_mark_end_of_function ();
5026 within_procedure
= FALSE
;
5027 demand_empty_rest_of_line ();
5028 pa_undefine_label ();
5031 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5032 then create a new space entry to hold the information specified
5033 by the parameters to the .SPACE directive. */
5035 static sd_chain_struct
*
5036 pa_parse_space_stmt (space_name
, create_flag
)
5040 char *name
, *ptemp
, c
;
5041 char loadable
, defined
, private, sort
;
5043 asection
*seg
= NULL
;
5044 sd_chain_struct
*space
;
5046 /* load default values */
5052 if (strcmp (space_name
, "$TEXT$") == 0)
5054 seg
= pa_def_spaces
[0].segment
;
5055 defined
= pa_def_spaces
[0].defined
;
5056 private = pa_def_spaces
[0].private;
5057 sort
= pa_def_spaces
[0].sort
;
5058 spnum
= pa_def_spaces
[0].spnum
;
5060 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5062 seg
= pa_def_spaces
[1].segment
;
5063 defined
= pa_def_spaces
[1].defined
;
5064 private = pa_def_spaces
[1].private;
5065 sort
= pa_def_spaces
[1].sort
;
5066 spnum
= pa_def_spaces
[1].spnum
;
5069 if (!is_end_of_statement ())
5071 print_errors
= FALSE
;
5072 ptemp
= input_line_pointer
+ 1;
5073 /* First see if the space was specified as a number rather than
5074 as a name. According to the PA assembly manual the rest of
5075 the line should be ignored. */
5076 temp
= pa_parse_number (&ptemp
, 0);
5080 input_line_pointer
= ptemp
;
5084 while (!is_end_of_statement ())
5086 input_line_pointer
++;
5087 name
= input_line_pointer
;
5088 c
= get_symbol_end ();
5089 if ((strncasecmp (name
, "spnum", 5) == 0))
5091 *input_line_pointer
= c
;
5092 input_line_pointer
++;
5093 spnum
= get_absolute_expression ();
5095 else if ((strncasecmp (name
, "sort", 4) == 0))
5097 *input_line_pointer
= c
;
5098 input_line_pointer
++;
5099 sort
= get_absolute_expression ();
5101 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5103 *input_line_pointer
= c
;
5106 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5108 *input_line_pointer
= c
;
5111 else if ((strncasecmp (name
, "private", 7) == 0))
5113 *input_line_pointer
= c
;
5118 as_bad ("Invalid .SPACE argument");
5119 *input_line_pointer
= c
;
5120 if (!is_end_of_statement ())
5121 input_line_pointer
++;
5125 print_errors
= TRUE
;
5128 if (create_flag
&& seg
== NULL
)
5129 seg
= subseg_new (space_name
, 0);
5131 /* If create_flag is nonzero, then create the new space with
5132 the attributes computed above. Else set the values in
5133 an already existing space -- this can only happen for
5134 the first occurence of a built-in space. */
5136 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5137 private, sort
, seg
, 1);
5140 space
= is_defined_space (space_name
);
5141 SPACE_SPNUM (space
) = spnum
;
5142 SPACE_DEFINED (space
) = defined
& 1;
5143 SPACE_USER_DEFINED (space
) = 1;
5146 #ifdef obj_set_section_attributes
5147 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5153 /* Handle a .SPACE pseudo-op; this switches the current space to the
5154 given space, creating the new space if necessary. */
5160 char *name
, c
, *space_name
, *save_s
;
5162 sd_chain_struct
*sd_chain
;
5164 if (within_procedure
)
5166 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5167 ignore_rest_of_line ();
5171 /* Check for some of the predefined spaces. FIXME: most of the code
5172 below is repeated several times, can we extract the common parts
5173 and place them into a subroutine or something similar? */
5174 /* FIXME Is this (and the next IF stmt) really right?
5175 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5176 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5178 input_line_pointer
+= 6;
5179 sd_chain
= is_defined_space ("$TEXT$");
5180 if (sd_chain
== NULL
)
5181 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5182 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5183 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5185 current_space
= sd_chain
;
5186 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5188 = pa_subsegment_to_subspace (text_section
,
5189 sd_chain
->sd_last_subseg
);
5190 demand_empty_rest_of_line ();
5193 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5195 input_line_pointer
+= 9;
5196 sd_chain
= is_defined_space ("$PRIVATE$");
5197 if (sd_chain
== NULL
)
5198 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5199 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5200 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5202 current_space
= sd_chain
;
5203 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5205 = pa_subsegment_to_subspace (data_section
,
5206 sd_chain
->sd_last_subseg
);
5207 demand_empty_rest_of_line ();
5210 if (!strncasecmp (input_line_pointer
,
5211 GDB_DEBUG_SPACE_NAME
,
5212 strlen (GDB_DEBUG_SPACE_NAME
)))
5214 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5215 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5216 if (sd_chain
== NULL
)
5217 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5218 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5219 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5221 current_space
= sd_chain
;
5224 asection
*gdb_section
5225 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5227 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5229 = pa_subsegment_to_subspace (gdb_section
,
5230 sd_chain
->sd_last_subseg
);
5232 demand_empty_rest_of_line ();
5236 /* It could be a space specified by number. */
5238 save_s
= input_line_pointer
;
5239 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5241 if ((sd_chain
= pa_find_space_by_number (temp
)))
5243 current_space
= sd_chain
;
5245 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5247 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5248 sd_chain
->sd_last_subseg
);
5249 demand_empty_rest_of_line ();
5254 /* Not a number, attempt to create a new space. */
5256 input_line_pointer
= save_s
;
5257 name
= input_line_pointer
;
5258 c
= get_symbol_end ();
5259 space_name
= xmalloc (strlen (name
) + 1);
5260 strcpy (space_name
, name
);
5261 *input_line_pointer
= c
;
5263 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5264 current_space
= sd_chain
;
5266 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5267 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5268 sd_chain
->sd_last_subseg
);
5269 demand_empty_rest_of_line ();
5273 /* Switch to a new space. (I think). FIXME. */
5282 sd_chain_struct
*space
;
5284 name
= input_line_pointer
;
5285 c
= get_symbol_end ();
5286 space
= is_defined_space (name
);
5290 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5293 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5295 *input_line_pointer
= c
;
5296 demand_empty_rest_of_line ();
5299 /* If VALUE is an exact power of two between zero and 2^31, then
5300 return log2 (VALUE). Else return -1. */
5308 while ((1 << shift
) != value
&& shift
< 32)
5317 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5318 given subspace, creating the new subspace if necessary.
5320 FIXME. Should mirror pa_space more closely, in particular how
5321 they're broken up into subroutines. */
5324 pa_subspace (create_new
)
5327 char *name
, *ss_name
, *alias
, c
;
5328 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5329 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5330 sd_chain_struct
*space
;
5331 ssd_chain_struct
*ssd
;
5334 if (current_space
== NULL
)
5335 as_fatal ("Must be in a space before changing or declaring subspaces.\n");
5337 if (within_procedure
)
5339 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5340 ignore_rest_of_line ();
5344 name
= input_line_pointer
;
5345 c
= get_symbol_end ();
5346 ss_name
= xmalloc (strlen (name
) + 1);
5347 strcpy (ss_name
, name
);
5348 *input_line_pointer
= c
;
5350 /* Load default values. */
5363 space
= current_space
;
5367 ssd
= is_defined_subspace (ss_name
);
5368 /* Allow user to override the builtin attributes of subspaces. But
5369 only allow the attributes to be changed once! */
5370 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5372 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5373 current_subspace
= ssd
;
5374 if (!is_end_of_statement ())
5375 as_warn ("Parameters of an existing subspace can\'t be modified");
5376 demand_empty_rest_of_line ();
5381 /* A new subspace. Load default values if it matches one of
5382 the builtin subspaces. */
5384 while (pa_def_subspaces
[i
].name
)
5386 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5388 loadable
= pa_def_subspaces
[i
].loadable
;
5389 common
= pa_def_subspaces
[i
].common
;
5390 dup_common
= pa_def_subspaces
[i
].dup_common
;
5391 code_only
= pa_def_subspaces
[i
].code_only
;
5392 zero
= pa_def_subspaces
[i
].zero
;
5393 space_index
= pa_def_subspaces
[i
].space_index
;
5394 alignment
= pa_def_subspaces
[i
].alignment
;
5395 quadrant
= pa_def_subspaces
[i
].quadrant
;
5396 access
= pa_def_subspaces
[i
].access
;
5397 sort
= pa_def_subspaces
[i
].sort
;
5398 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5399 alias
= pa_def_subspaces
[i
].alias
;
5406 /* We should be working with a new subspace now. Fill in
5407 any information as specified by the user. */
5408 if (!is_end_of_statement ())
5410 input_line_pointer
++;
5411 while (!is_end_of_statement ())
5413 name
= input_line_pointer
;
5414 c
= get_symbol_end ();
5415 if ((strncasecmp (name
, "quad", 4) == 0))
5417 *input_line_pointer
= c
;
5418 input_line_pointer
++;
5419 quadrant
= get_absolute_expression ();
5421 else if ((strncasecmp (name
, "align", 5) == 0))
5423 *input_line_pointer
= c
;
5424 input_line_pointer
++;
5425 alignment
= get_absolute_expression ();
5426 if (log2 (alignment
) == -1)
5428 as_bad ("Alignment must be a power of 2");
5432 else if ((strncasecmp (name
, "access", 6) == 0))
5434 *input_line_pointer
= c
;
5435 input_line_pointer
++;
5436 access
= get_absolute_expression ();
5438 else if ((strncasecmp (name
, "sort", 4) == 0))
5440 *input_line_pointer
= c
;
5441 input_line_pointer
++;
5442 sort
= get_absolute_expression ();
5444 else if ((strncasecmp (name
, "code_only", 9) == 0))
5446 *input_line_pointer
= c
;
5449 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5451 *input_line_pointer
= c
;
5454 else if ((strncasecmp (name
, "common", 6) == 0))
5456 *input_line_pointer
= c
;
5459 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5461 *input_line_pointer
= c
;
5464 else if ((strncasecmp (name
, "zero", 4) == 0))
5466 *input_line_pointer
= c
;
5469 else if ((strncasecmp (name
, "first", 5) == 0))
5470 as_bad ("FIRST not supported as a .SUBSPACE argument");
5472 as_bad ("Invalid .SUBSPACE argument");
5473 if (!is_end_of_statement ())
5474 input_line_pointer
++;
5478 /* Compute a reasonable set of BFD flags based on the information
5479 in the .subspace directive. */
5480 applicable
= bfd_applicable_section_flags (stdoutput
);
5483 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5486 if (common
|| dup_common
)
5487 flags
|= SEC_IS_COMMON
;
5489 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5491 /* This is a zero-filled subspace (eg BSS). */
5493 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
5495 applicable
&= flags
;
5497 /* If this is an existing subspace, then we want to use the
5498 segment already associated with the subspace.
5500 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5501 lots of sections. It might be a problem in the PA ELF
5502 code, I do not know yet. For now avoid creating anything
5503 but the "standard" sections for ELF. */
5505 section
= subseg_force_new (ss_name
, 0);
5507 section
= ssd
->ssd_seg
;
5509 section
= subseg_new (alias
, 0);
5510 else if (!alias
&& USE_ALIASES
)
5512 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5513 demand_empty_rest_of_line ();
5517 section
= subseg_new (ss_name
, 0);
5520 seg_info (section
)->bss
= 1;
5522 /* Now set the flags. */
5523 bfd_set_section_flags (stdoutput
, section
, applicable
);
5525 /* Record any alignment request for this section. */
5526 record_alignment (section
, log2 (alignment
));
5528 /* Set the starting offset for this section. */
5529 bfd_set_section_vma (stdoutput
, section
,
5530 pa_subspace_start (space
, quadrant
));
5532 /* Now that all the flags are set, update an existing subspace,
5533 or create a new one. */
5536 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5537 code_only
, common
, dup_common
,
5538 sort
, zero
, access
, space_index
,
5539 alignment
, quadrant
,
5542 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5544 dup_common
, zero
, sort
,
5545 access
, space_index
,
5546 alignment
, quadrant
, section
);
5548 demand_empty_rest_of_line ();
5549 current_subspace
->ssd_seg
= section
;
5550 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5552 SUBSPACE_DEFINED (current_subspace
) = 1;
5556 /* Create default space and subspace dictionaries. */
5563 space_dict_root
= NULL
;
5564 space_dict_last
= NULL
;
5567 while (pa_def_spaces
[i
].name
)
5571 /* Pick the right name to use for the new section. */
5572 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5573 name
= pa_def_spaces
[i
].alias
;
5575 name
= pa_def_spaces
[i
].name
;
5577 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5578 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5579 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5580 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5581 pa_def_spaces
[i
].segment
, 0);
5586 while (pa_def_subspaces
[i
].name
)
5589 int applicable
, subsegment
;
5590 asection
*segment
= NULL
;
5591 sd_chain_struct
*space
;
5593 /* Pick the right name for the new section and pick the right
5594 subsegment number. */
5595 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5597 name
= pa_def_subspaces
[i
].alias
;
5598 subsegment
= pa_def_subspaces
[i
].subsegment
;
5602 name
= pa_def_subspaces
[i
].name
;
5606 /* Create the new section. */
5607 segment
= subseg_new (name
, subsegment
);
5610 /* For SOM we want to replace the standard .text, .data, and .bss
5611 sections with our own. We also want to set BFD flags for
5612 all the built-in subspaces. */
5613 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5615 text_section
= segment
;
5616 applicable
= bfd_applicable_section_flags (stdoutput
);
5617 bfd_set_section_flags (stdoutput
, segment
,
5618 applicable
& (SEC_ALLOC
| SEC_LOAD
5619 | SEC_RELOC
| SEC_CODE
5621 | SEC_HAS_CONTENTS
));
5623 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5625 data_section
= segment
;
5626 applicable
= bfd_applicable_section_flags (stdoutput
);
5627 bfd_set_section_flags (stdoutput
, segment
,
5628 applicable
& (SEC_ALLOC
| SEC_LOAD
5630 | SEC_HAS_CONTENTS
));
5634 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5636 bss_section
= segment
;
5637 applicable
= bfd_applicable_section_flags (stdoutput
);
5638 bfd_set_section_flags (stdoutput
, segment
,
5639 applicable
& SEC_ALLOC
);
5641 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5643 applicable
= bfd_applicable_section_flags (stdoutput
);
5644 bfd_set_section_flags (stdoutput
, segment
,
5645 applicable
& (SEC_ALLOC
| SEC_LOAD
5648 | SEC_HAS_CONTENTS
));
5650 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5652 applicable
= bfd_applicable_section_flags (stdoutput
);
5653 bfd_set_section_flags (stdoutput
, segment
,
5654 applicable
& (SEC_ALLOC
| SEC_LOAD
5657 | SEC_HAS_CONTENTS
));
5660 /* Find the space associated with this subspace. */
5661 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5662 def_space_index
].segment
);
5665 as_fatal ("Internal error: Unable to find containing space for %s.",
5666 pa_def_subspaces
[i
].name
);
5669 create_new_subspace (space
, name
,
5670 pa_def_subspaces
[i
].loadable
,
5671 pa_def_subspaces
[i
].code_only
,
5672 pa_def_subspaces
[i
].common
,
5673 pa_def_subspaces
[i
].dup_common
,
5674 pa_def_subspaces
[i
].zero
,
5675 pa_def_subspaces
[i
].sort
,
5676 pa_def_subspaces
[i
].access
,
5677 pa_def_subspaces
[i
].space_index
,
5678 pa_def_subspaces
[i
].alignment
,
5679 pa_def_subspaces
[i
].quadrant
,
5687 /* Create a new space NAME, with the appropriate flags as defined
5688 by the given parameters. */
5690 static sd_chain_struct
*
5691 create_new_space (name
, spnum
, loadable
, defined
, private,
5692 sort
, seg
, user_defined
)
5702 sd_chain_struct
*chain_entry
;
5704 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5706 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5709 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5710 strcpy (SPACE_NAME (chain_entry
), name
);
5711 SPACE_DEFINED (chain_entry
) = defined
;
5712 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5713 SPACE_SPNUM (chain_entry
) = spnum
;
5715 chain_entry
->sd_seg
= seg
;
5716 chain_entry
->sd_last_subseg
= -1;
5717 chain_entry
->sd_subspaces
= NULL
;
5718 chain_entry
->sd_next
= NULL
;
5720 /* Find spot for the new space based on its sort key. */
5721 if (!space_dict_last
)
5722 space_dict_last
= chain_entry
;
5724 if (space_dict_root
== NULL
)
5725 space_dict_root
= chain_entry
;
5728 sd_chain_struct
*chain_pointer
;
5729 sd_chain_struct
*prev_chain_pointer
;
5731 chain_pointer
= space_dict_root
;
5732 prev_chain_pointer
= NULL
;
5734 while (chain_pointer
)
5736 prev_chain_pointer
= chain_pointer
;
5737 chain_pointer
= chain_pointer
->sd_next
;
5740 /* At this point we've found the correct place to add the new
5741 entry. So add it and update the linked lists as appropriate. */
5742 if (prev_chain_pointer
)
5744 chain_entry
->sd_next
= chain_pointer
;
5745 prev_chain_pointer
->sd_next
= chain_entry
;
5749 space_dict_root
= chain_entry
;
5750 chain_entry
->sd_next
= chain_pointer
;
5753 if (chain_entry
->sd_next
== NULL
)
5754 space_dict_last
= chain_entry
;
5757 /* This is here to catch predefined spaces which do not get
5758 modified by the user's input. Another call is found at
5759 the bottom of pa_parse_space_stmt to handle cases where
5760 the user modifies a predefined space. */
5761 #ifdef obj_set_section_attributes
5762 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5768 /* Create a new subspace NAME, with the appropriate flags as defined
5769 by the given parameters.
5771 Add the new subspace to the subspace dictionary chain in numerical
5772 order as defined by the SORT entries. */
5774 static ssd_chain_struct
*
5775 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5776 dup_common
, is_zero
, sort
, access
, space_index
,
5777 alignment
, quadrant
, seg
)
5778 sd_chain_struct
*space
;
5780 int loadable
, code_only
, common
, dup_common
, is_zero
;
5788 ssd_chain_struct
*chain_entry
;
5790 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5792 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5794 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5795 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5797 /* Initialize subspace_defined. When we hit a .subspace directive
5798 we'll set it to 1 which "locks-in" the subspace attributes. */
5799 SUBSPACE_DEFINED (chain_entry
) = 0;
5801 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5802 chain_entry
->ssd_seg
= seg
;
5803 chain_entry
->ssd_next
= NULL
;
5805 /* Find spot for the new subspace based on its sort key. */
5806 if (space
->sd_subspaces
== NULL
)
5807 space
->sd_subspaces
= chain_entry
;
5810 ssd_chain_struct
*chain_pointer
;
5811 ssd_chain_struct
*prev_chain_pointer
;
5813 chain_pointer
= space
->sd_subspaces
;
5814 prev_chain_pointer
= NULL
;
5816 while (chain_pointer
)
5818 prev_chain_pointer
= chain_pointer
;
5819 chain_pointer
= chain_pointer
->ssd_next
;
5822 /* Now we have somewhere to put the new entry. Insert it and update
5824 if (prev_chain_pointer
)
5826 chain_entry
->ssd_next
= chain_pointer
;
5827 prev_chain_pointer
->ssd_next
= chain_entry
;
5831 space
->sd_subspaces
= chain_entry
;
5832 chain_entry
->ssd_next
= chain_pointer
;
5836 #ifdef obj_set_subsection_attributes
5837 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5844 /* Update the information for the given subspace based upon the
5845 various arguments. Return the modified subspace chain entry. */
5847 static ssd_chain_struct
*
5848 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5849 zero
, access
, space_index
, alignment
, quadrant
, section
)
5850 sd_chain_struct
*space
;
5864 ssd_chain_struct
*chain_entry
;
5866 chain_entry
= is_defined_subspace (name
);
5868 #ifdef obj_set_subsection_attributes
5869 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5876 /* Return the space chain entry for the space with the name NAME or
5877 NULL if no such space exists. */
5879 static sd_chain_struct
*
5880 is_defined_space (name
)
5883 sd_chain_struct
*chain_pointer
;
5885 for (chain_pointer
= space_dict_root
;
5887 chain_pointer
= chain_pointer
->sd_next
)
5889 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5890 return chain_pointer
;
5893 /* No mapping from segment to space was found. Return NULL. */
5897 /* Find and return the space associated with the given seg. If no mapping
5898 from the given seg to a space is found, then return NULL.
5900 Unlike subspaces, the number of spaces is not expected to grow much,
5901 so a linear exhaustive search is OK here. */
5903 static sd_chain_struct
*
5904 pa_segment_to_space (seg
)
5907 sd_chain_struct
*space_chain
;
5909 /* Walk through each space looking for the correct mapping. */
5910 for (space_chain
= space_dict_root
;
5912 space_chain
= space_chain
->sd_next
)
5914 if (space_chain
->sd_seg
== seg
)
5918 /* Mapping was not found. Return NULL. */
5922 /* Return the space chain entry for the subspace with the name NAME or
5923 NULL if no such subspace exists.
5925 Uses a linear search through all the spaces and subspaces, this may
5926 not be appropriate if we ever being placing each function in its
5929 static ssd_chain_struct
*
5930 is_defined_subspace (name
)
5933 sd_chain_struct
*space_chain
;
5934 ssd_chain_struct
*subspace_chain
;
5936 /* Walk through each space. */
5937 for (space_chain
= space_dict_root
;
5939 space_chain
= space_chain
->sd_next
)
5941 /* Walk through each subspace looking for a name which matches. */
5942 for (subspace_chain
= space_chain
->sd_subspaces
;
5944 subspace_chain
= subspace_chain
->ssd_next
)
5945 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5946 return subspace_chain
;
5949 /* Subspace wasn't found. Return NULL. */
5953 /* Find and return the subspace associated with the given seg. If no
5954 mapping from the given seg to a subspace is found, then return NULL.
5956 If we ever put each procedure/function within its own subspace
5957 (to make life easier on the compiler and linker), then this will have
5958 to become more efficient. */
5960 static ssd_chain_struct
*
5961 pa_subsegment_to_subspace (seg
, subseg
)
5965 sd_chain_struct
*space_chain
;
5966 ssd_chain_struct
*subspace_chain
;
5968 /* Walk through each space. */
5969 for (space_chain
= space_dict_root
;
5971 space_chain
= space_chain
->sd_next
)
5973 if (space_chain
->sd_seg
== seg
)
5975 /* Walk through each subspace within each space looking for
5976 the correct mapping. */
5977 for (subspace_chain
= space_chain
->sd_subspaces
;
5979 subspace_chain
= subspace_chain
->ssd_next
)
5980 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5981 return subspace_chain
;
5985 /* No mapping from subsegment to subspace found. Return NULL. */
5989 /* Given a number, try and find a space with the name number.
5991 Return a pointer to a space dictionary chain entry for the space
5992 that was found or NULL on failure. */
5994 static sd_chain_struct
*
5995 pa_find_space_by_number (number
)
5998 sd_chain_struct
*space_chain
;
6000 for (space_chain
= space_dict_root
;
6002 space_chain
= space_chain
->sd_next
)
6004 if (SPACE_SPNUM (space_chain
) == number
)
6008 /* No appropriate space found. Return NULL. */
6012 /* Return the starting address for the given subspace. If the starting
6013 address is unknown then return zero. */
6016 pa_subspace_start (space
, quadrant
)
6017 sd_chain_struct
*space
;
6020 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6021 is not correct for the PA OSF1 port. */
6022 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6024 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6030 /* FIXME. Needs documentation. */
6032 pa_next_subseg (space
)
6033 sd_chain_struct
*space
;
6036 space
->sd_last_subseg
++;
6037 return space
->sd_last_subseg
;
6040 /* Helper function for pa_stringer. Used to find the end of
6047 unsigned int c
= *s
& CHAR_MASK
;
6049 /* We must have a valid space and subspace. */
6050 pa_check_current_space_and_subspace ();
6063 /* Handle a .STRING type pseudo-op. */
6066 pa_stringer (append_zero
)
6069 char *s
, num_buf
[4];
6073 /* Preprocess the string to handle PA-specific escape sequences.
6074 For example, \xDD where DD is a hexidecimal number should be
6075 changed to \OOO where OOO is an octal number. */
6077 /* Skip the opening quote. */
6078 s
= input_line_pointer
+ 1;
6080 while (is_a_char (c
= pa_stringer_aux (s
++)))
6087 /* Handle \x<num>. */
6090 unsigned int number
;
6095 /* Get pas the 'x'. */
6097 for (num_digit
= 0, number
= 0, dg
= *s
;
6099 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6100 || (dg
>= 'A' && dg
<= 'F'));
6104 number
= number
* 16 + dg
- '0';
6105 else if (dg
>= 'a' && dg
<= 'f')
6106 number
= number
* 16 + dg
- 'a' + 10;
6108 number
= number
* 16 + dg
- 'A' + 10;
6118 sprintf (num_buf
, "%02o", number
);
6121 sprintf (num_buf
, "%03o", number
);
6124 for (i
= 0; i
<= num_digit
; i
++)
6125 s_start
[i
] = num_buf
[i
];
6129 /* This might be a "\"", skip over the escaped char. */
6136 stringer (append_zero
);
6137 pa_undefine_label ();
6140 /* Handle a .VERSION pseudo-op. */
6147 pa_undefine_label ();
6150 /* Handle a .COPYRIGHT pseudo-op. */
6153 pa_copyright (unused
)
6157 pa_undefine_label ();
6160 /* Just like a normal cons, but when finished we have to undefine
6161 the latest space label. */
6168 pa_undefine_label ();
6171 /* Switch to the data space. As usual delete our label. */
6177 current_space
= is_defined_space ("$PRIVATE$");
6179 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6181 pa_undefine_label ();
6184 /* Like float_cons, but we need to undefine our label. */
6187 pa_float_cons (float_type
)
6190 float_cons (float_type
);
6191 pa_undefine_label ();
6194 /* Like s_fill, but delete our label when finished. */
6200 /* We must have a valid space and subspace. */
6201 pa_check_current_space_and_subspace ();
6204 pa_undefine_label ();
6207 /* Like lcomm, but delete our label when finished. */
6210 pa_lcomm (needs_align
)
6213 /* We must have a valid space and subspace. */
6214 pa_check_current_space_and_subspace ();
6216 s_lcomm (needs_align
);
6217 pa_undefine_label ();
6220 /* Like lsym, but delete our label when finished. */
6226 /* We must have a valid space and subspace. */
6227 pa_check_current_space_and_subspace ();
6230 pa_undefine_label ();
6233 /* Switch to the text space. Like s_text, but delete our
6234 label when finished. */
6239 current_space
= is_defined_space ("$TEXT$");
6241 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6244 pa_undefine_label ();
6247 /* On the PA relocations which involve function symbols must not be
6248 adjusted. This so that the linker can know when/how to create argument
6249 relocation stubs for indirect calls and calls to static functions.
6251 "T" field selectors create DLT relative fixups for accessing
6252 globals and statics in PIC code; each DLT relative fixup creates
6253 an entry in the DLT table. The entries contain the address of
6254 the final target (eg accessing "foo" would create a DLT entry
6255 with the address of "foo").
6257 Unfortunately, the HP linker doesn't take into account any addend
6258 when generating the DLT; so accessing $LIT$+8 puts the address of
6259 $LIT$ into the DLT rather than the address of $LIT$+8.
6261 The end result is we can't perform relocation symbol reductions for
6262 any fixup which creates entries in the DLT (eg they use "T" field
6265 Reject reductions involving symbols with external scope; such
6266 reductions make life a living hell for object file editors.
6268 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6269 the code space. The SOM BFD backend doesn't know how to pull the
6270 right bits out of an instruction. */
6273 hppa_fix_adjustable (fixp
)
6276 struct hppa_fix_struct
*hppa_fix
;
6278 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6281 /* Reject reductions of symbols in 32bit relocs. */
6282 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6285 /* Reject reductions of symbols in sym1-sym2 expressions when
6286 the fixup will occur in a CODE subspace.
6288 XXX FIXME: Long term we probably want to reject all of these;
6289 for example reducing in the debug section would lose if we ever
6290 supported using the optimizing hp linker. */
6293 && (hppa_fix
->segment
->flags
& SEC_CODE
))
6295 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6296 fixp
->fx_subsy
->sy_used_in_reloc
= 1;
6300 /* We can't adjust DP relative relocs that use LR% and RR% field
6301 selectors. That confuses the optimization pass in HP linker. */
6302 if (fixp
->fx_r_type
== R_DP_RELATIVE
6303 && (hppa_fix
->fx_r_field
== e_lrsel
6304 || hppa_fix
->fx_r_field
== e_rrsel
6305 || hppa_fix
->fx_r_field
== e_nlrsel
))
6309 /* Reject reductions of symbols in DLT relative relocs,
6310 relocations with plabels. */
6311 if (hppa_fix
->fx_r_field
== e_tsel
6312 || hppa_fix
->fx_r_field
== e_ltsel
6313 || hppa_fix
->fx_r_field
== e_rtsel
6314 || hppa_fix
->fx_r_field
== e_psel
6315 || hppa_fix
->fx_r_field
== e_rpsel
6316 || hppa_fix
->fx_r_field
== e_lpsel
)
6319 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6322 /* Reject reductions of function symbols. */
6323 if (fixp
->fx_addsy
== 0
6324 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6330 /* Return nonzero if the fixup in FIXP will require a relocation,
6331 even it if appears that the fixup could be completely handled
6335 hppa_force_relocation (fixp
)
6338 struct hppa_fix_struct
*hppa_fixp
;
6341 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6343 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
6344 || fixp
->fx_r_type
== R_HPPA_BEGIN_BRTAB
6345 || fixp
->fx_r_type
== R_HPPA_END_BRTAB
6346 || (fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
6347 && (hppa_fixp
->segment
->flags
& SEC_CODE
) != 0))
6351 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6352 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6354 /* It is necessary to force PC-relative calls/jumps to have a relocation
6355 entry if they're going to need either a argument relocation or long
6356 call stub. FIXME. Can't we need the same for absolute calls? */
6357 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6358 && (arg_reloc_stub_needed (((obj_symbol_type
*)
6359 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6361 hppa_fixp
->fx_arg_reloc
)))
6363 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
6364 - md_pcrel_from (fixp
));
6365 /* Now check and see if we're going to need a long-branch stub. */
6366 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
6367 && (distance
> 262143 || distance
< -262144))
6370 #undef arg_reloc_stub_needed
6372 /* No need (yet) to force another relocations to be emitted. */
6376 /* Now for some ELF specific code. FIXME. */
6378 /* Mark the end of a function so that it's possible to compute
6379 the size of the function in hppa_elf_final_processing. */
6382 hppa_elf_mark_end_of_function ()
6384 /* ELF does not have EXIT relocations. All we do is create a
6385 temporary symbol marking the end of the function. */
6386 char *name
= (char *)
6387 xmalloc (strlen ("L$\001end_") +
6388 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6394 strcpy (name
, "L$\001end_");
6395 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6397 /* If we have a .exit followed by a .procend, then the
6398 symbol will have already been defined. */
6399 symbolP
= symbol_find (name
);
6402 /* The symbol has already been defined! This can
6403 happen if we have a .exit followed by a .procend.
6405 This is *not* an error. All we want to do is free
6406 the memory we just allocated for the name and continue. */
6411 /* symbol value should be the offset of the
6412 last instruction of the function */
6413 symbolP
= symbol_new (name
, now_seg
, (valueT
) (frag_now_fix () - 4),
6417 symbolP
->bsym
->flags
= BSF_LOCAL
;
6418 symbol_table_insert (symbolP
);
6422 last_call_info
->end_symbol
= symbolP
;
6424 as_bad ("Symbol '%s' could not be created.", name
);
6428 as_bad ("No memory for symbol name.");
6432 /* For ELF, this function serves one purpose: to setup the st_size
6433 field of STT_FUNC symbols. To do this, we need to scan the
6434 call_info structure list, determining st_size in by taking the
6435 difference in the address of the beginning/end marker symbols. */
6438 elf_hppa_final_processing ()
6440 struct call_info
*call_info_pointer
;
6442 for (call_info_pointer
= call_info_root
;
6444 call_info_pointer
= call_info_pointer
->ci_next
)
6446 elf_symbol_type
*esym
6447 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6448 esym
->internal_elf_sym
.st_size
=
6449 S_GET_VALUE (call_info_pointer
->end_symbol
)
6450 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;