1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "bfd/libhppa.h"
31 #include "bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".PARISC.unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
55 /* ELF objects can have versions, but apparently do not have anywhere
56 to store a copyright string. */
57 #define obj_version obj_elf_version
58 #define obj_copyright obj_elf_version
60 /* Use space aliases. */
65 /* Names of various debugging spaces/subspaces. */
66 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
67 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
68 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
69 #define UNWIND_SECTION_NAME "$UNWIND$"
71 /* Object file formats specify relocation types. */
72 typedef int reloc_type
;
74 /* SOM objects can have both a version string and a copyright string. */
75 #define obj_version obj_som_version
76 #define obj_copyright obj_som_copyright
78 /* Do not use space aliases. */
81 /* How to generate a relocation. */
82 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
84 /* Object file formats specify BFD symbol types. */
85 typedef som_symbol_type obj_symbol_type
;
87 /* This apparently isn't in older versions of hpux reloc.h. */
89 #define R_DLT_REL 0x78
93 /* Various structures and types used internally in tc-hppa.c. */
95 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
99 unsigned int cannot_unwind
:1;
100 unsigned int millicode
:1;
101 unsigned int millicode_save_rest
:1;
102 unsigned int region_desc
:2;
103 unsigned int save_sr
:2;
104 unsigned int entry_fr
:4;
105 unsigned int entry_gr
:5;
106 unsigned int args_stored
:1;
107 unsigned int call_fr
:5;
108 unsigned int call_gr
:5;
109 unsigned int save_sp
:1;
110 unsigned int save_rp
:1;
111 unsigned int save_rp_in_frame
:1;
112 unsigned int extn_ptr_defined
:1;
113 unsigned int cleanup_defined
:1;
115 unsigned int hpe_interrupt_marker
:1;
116 unsigned int hpux_interrupt_marker
:1;
117 unsigned int reserved
:3;
118 unsigned int frame_size
:27;
123 /* Starting and ending offsets of the region described by
125 unsigned int start_offset
;
126 unsigned int end_offset
;
127 struct unwind_desc descriptor
;
130 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
131 control the entry and exit code they generate. It is also used in
132 creation of the correct stack unwind descriptors.
134 NOTE: GAS does not support .enter and .leave for the generation of
135 prologues and epilogues. FIXME.
137 The fields in structure roughly correspond to the arguments available on the
138 .callinfo pseudo-op. */
142 /* The unwind descriptor being built. */
143 struct unwind_table ci_unwind
;
145 /* Name of this function. */
146 symbolS
*start_symbol
;
148 /* Size of the function in bytes. */
149 unsigned long function_size
;
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_call
PARAMS ((int));
479 static void pa_call_args
PARAMS ((struct call_desc
*));
480 static void pa_callinfo
PARAMS ((int));
481 static void pa_code
PARAMS ((int));
482 static void pa_comm
PARAMS ((int));
483 static void pa_copyright
PARAMS ((int));
484 static void pa_end
PARAMS ((int));
485 static void pa_enter
PARAMS ((int));
486 static void pa_entry
PARAMS ((int));
487 static void pa_equ
PARAMS ((int));
488 static void pa_exit
PARAMS ((int));
489 static void pa_export
PARAMS ((int));
490 static void pa_type_args
PARAMS ((symbolS
*, int));
491 static void pa_import
PARAMS ((int));
492 static void pa_label
PARAMS ((int));
493 static void pa_leave
PARAMS ((int));
494 static void pa_origin
PARAMS ((int));
495 static void pa_proc
PARAMS ((int));
496 static void pa_procend
PARAMS ((int));
497 static void pa_space
PARAMS ((int));
498 static void pa_spnum
PARAMS ((int));
499 static void pa_subspace
PARAMS ((int));
500 static void pa_param
PARAMS ((int));
501 static void pa_undefine_label
PARAMS ((void));
502 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
503 struct pa_11_fp_reg_struct
*));
504 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
505 static label_symbol_struct
*pa_get_label
PARAMS ((void));
506 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
509 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
514 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
515 char *, int, int, int,
519 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
520 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
521 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
522 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
524 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
525 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
526 static void pa_ip
PARAMS ((char *));
527 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
528 long, expressionS
*, int,
529 bfd_reloc_code_real_type
,
530 enum hppa_reloc_field_selector_type
,
532 static int is_end_of_statement
PARAMS ((void));
533 static int reg_name_search
PARAMS ((char *));
534 static int pa_chk_field_selector
PARAMS ((char **));
535 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
536 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
537 static void process_exit
PARAMS ((void));
538 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
539 static int log2
PARAMS ((int));
540 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
541 static unsigned int pa_stringer_aux
PARAMS ((char *));
542 static void pa_spaces_begin
PARAMS ((void));
544 /* File and gloally scoped variable declarations. */
546 /* Root and final entry in the space chain. */
547 static sd_chain_struct
*space_dict_root
;
548 static sd_chain_struct
*space_dict_last
;
550 /* The current space and subspace. */
551 static sd_chain_struct
*current_space
;
552 static ssd_chain_struct
*current_subspace
;
554 /* Root of the call_info chain. */
555 static struct call_info
*call_info_root
;
557 /* The last call_info (for functions) structure
558 seen so it can be associated with fixups and
560 static struct call_info
*last_call_info
;
562 /* The last call description (for actual calls). */
563 static struct call_desc last_call_desc
;
565 /* Jumps are always the same size -- one instruction. */
566 int md_short_jump_size
= 4;
567 int md_long_jump_size
= 4;
569 /* handle of the OPCODE hash table */
570 static struct hash_control
*op_hash
= NULL
;
572 /* This array holds the chars that always start a comment. If the
573 pre-processor is disabled, these aren't very useful. */
574 const char comment_chars
[] = ";";
576 /* Table of pseudo ops for the PA. FIXME -- how many of these
577 are now redundant with the overall GAS and the object file
579 const pseudo_typeS md_pseudo_table
[] =
581 /* align pseudo-ops on the PA specify the actual alignment requested,
582 not the log2 of the requested alignment. */
583 {"align", pa_align
, 8},
584 {"block", pa_block
, 1},
585 {"blockz", pa_block
, 0},
586 {"byte", pa_cons
, 1},
587 {"call", pa_call
, 0},
588 {"callinfo", pa_callinfo
, 0},
589 {"code", pa_code
, 0},
590 {"comm", pa_comm
, 0},
591 {"copyright", pa_copyright
, 0},
592 {"data", pa_data
, 0},
593 {"double", pa_float_cons
, 'd'},
595 {"enter", pa_enter
, 0},
596 {"entry", pa_entry
, 0},
598 {"exit", pa_exit
, 0},
599 {"export", pa_export
, 0},
600 {"fill", pa_fill
, 0},
601 {"float", pa_float_cons
, 'f'},
602 {"half", pa_cons
, 2},
603 {"import", pa_import
, 0},
605 {"label", pa_label
, 0},
606 {"lcomm", pa_lcomm
, 0},
607 {"leave", pa_leave
, 0},
608 {"long", pa_cons
, 4},
609 {"lsym", pa_lsym
, 0},
610 {"octa", pa_cons
, 16},
611 {"org", pa_origin
, 0},
612 {"origin", pa_origin
, 0},
613 {"param", pa_param
, 0},
614 {"proc", pa_proc
, 0},
615 {"procend", pa_procend
, 0},
616 {"quad", pa_cons
, 8},
618 {"short", pa_cons
, 2},
619 {"single", pa_float_cons
, 'f'},
620 {"space", pa_space
, 0},
621 {"spnum", pa_spnum
, 0},
622 {"string", pa_stringer
, 0},
623 {"stringz", pa_stringer
, 1},
624 {"subspa", pa_subspace
, 0},
625 {"text", pa_text
, 0},
626 {"version", pa_version
, 0},
627 {"word", pa_cons
, 4},
631 /* This array holds the chars that only start a comment at the beginning of
632 a line. If the line seems to have the form '# 123 filename'
633 .line and .file directives will appear in the pre-processed output.
635 Note that input_file.c hand checks for '#' at the beginning of the
636 first line of the input file. This is because the compiler outputs
637 #NO_APP at the beginning of its output.
639 Also note that '/*' will always start a comment. */
640 const char line_comment_chars
[] = "#";
642 /* This array holds the characters which act as line separators. */
643 const char line_separator_chars
[] = "!";
645 /* Chars that can be used to separate mant from exp in floating point nums. */
646 const char EXP_CHARS
[] = "eE";
648 /* Chars that mean this number is a floating point constant.
649 As in 0f12.456 or 0d1.2345e12.
651 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
652 changed in read.c. Ideally it shouldn't hae to know abou it at
653 all, but nothing is ideal around here. */
654 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
656 static struct pa_it the_insn
;
658 /* Points to the end of an expression just parsed by get_expressoin
659 and friends. FIXME. This shouldn't be handled with a file-global
661 static char *expr_end
;
663 /* Nonzero if a .callinfo appeared within the current procedure. */
664 static int callinfo_found
;
666 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
667 static int within_entry_exit
;
669 /* Nonzero if the assembler is currently within a procedure definition. */
670 static int within_procedure
;
672 /* Handle on strucutre which keep track of the last symbol
673 seen in each subspace. */
674 static label_symbol_struct
*label_symbols_rootp
= NULL
;
676 /* Holds the last field selector. */
677 static int hppa_field_selector
;
679 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
680 static symbolS
*dummy_symbol
;
682 /* Nonzero if errors are to be printed. */
683 static int print_errors
= 1;
685 /* List of registers that are pre-defined:
687 Each general register has one predefined name of the form
688 %r<REGNUM> which has the value <REGNUM>.
690 Space and control registers are handled in a similar manner,
691 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
693 Likewise for the floating point registers, but of the form
694 %fr<REGNUM>. Floating point registers have additional predefined
695 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
696 again have the value <REGNUM>.
698 Many registers also have synonyms:
700 %r26 - %r23 have %arg0 - %arg3 as synonyms
701 %r28 - %r29 have %ret0 - %ret1 as synonyms
702 %r30 has %sp as a synonym
703 %r27 has %dp as a synonym
704 %r2 has %rp as a synonym
706 Almost every control register has a synonym; they are not listed
709 The table is sorted. Suitable for searching by a binary search. */
711 static const struct pd_reg pre_defined_registers
[] =
911 /* This table is sorted by order of the length of the string. This is
912 so we check for <> before we check for <. If we had a <> and checked
913 for < first, we would get a false match. */
914 static const struct fp_cond_map fp_cond_map
[] =
950 static const struct selector_entry selector_table
[] =
969 /* default space and subspace dictionaries */
971 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
972 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
974 /* pre-defined subsegments (subspaces) for the HPPA. */
975 #define SUBSEG_CODE 0
976 #define SUBSEG_DATA 0
979 #define SUBSEG_UNWIND 3
980 #define SUBSEG_GDB_STRINGS 0
981 #define SUBSEG_GDB_SYMBOLS 1
983 static struct default_subspace_dict pa_def_subspaces
[] =
985 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
986 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
987 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
988 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
990 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
992 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
995 static struct default_space_dict pa_def_spaces
[] =
997 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
998 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
999 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1002 /* Misc local definitions used by the assembler. */
1004 /* Return nonzero if the string pointed to by S potentially represents
1005 a right or left half of a FP register */
1006 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1007 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1009 /* These macros are used to maintain spaces/subspaces. */
1010 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1011 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1012 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1013 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1015 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1016 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1018 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1019 main loop after insertion. */
1021 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1023 ((OPCODE) |= (FIELD) << (START)); \
1027 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1028 IGNORE is used to suppress the error message. */
1030 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1032 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1035 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1041 #define is_DP_relative(exp) \
1042 ((exp).X_op == O_subtract \
1043 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1045 #define is_PC_relative(exp) \
1046 ((exp).X_op == O_subtract \
1047 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1049 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1050 always be able to reduce the expression to a constant, so we don't
1051 need real complex handling yet. */
1052 #define is_complex(exp) \
1053 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1055 /* Actual functions to implement the PA specific code for the assembler. */
1057 /* Called before writing the object file. Make sure entry/exit and
1058 proc/procend pairs match. */
1063 if (within_entry_exit
)
1064 as_fatal ("Missing .exit\n");
1066 if (within_procedure
)
1067 as_fatal ("Missing .procend\n");
1070 /* Check to make sure we have a valid space and subspace. */
1073 pa_check_current_space_and_subspace ()
1075 if (current_space
== NULL
)
1076 as_fatal ("Not in a space.\n");
1078 if (current_subspace
== NULL
)
1079 as_fatal ("Not in a subspace.\n");
1082 /* Returns a pointer to the label_symbol_struct for the current space.
1083 or NULL if no label_symbol_struct exists for the current space. */
1085 static label_symbol_struct
*
1088 label_symbol_struct
*label_chain
;
1089 sd_chain_struct
*space_chain
= current_space
;
1091 for (label_chain
= label_symbols_rootp
;
1093 label_chain
= label_chain
->lss_next
)
1094 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1100 /* Defines a label for the current space. If one is already defined,
1101 this function will replace it with the new label. */
1104 pa_define_label (symbol
)
1107 label_symbol_struct
*label_chain
= pa_get_label ();
1108 sd_chain_struct
*space_chain
= current_space
;
1111 label_chain
->lss_label
= symbol
;
1114 /* Create a new label entry and add it to the head of the chain. */
1116 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1117 label_chain
->lss_label
= symbol
;
1118 label_chain
->lss_space
= space_chain
;
1119 label_chain
->lss_next
= NULL
;
1121 if (label_symbols_rootp
)
1122 label_chain
->lss_next
= label_symbols_rootp
;
1124 label_symbols_rootp
= label_chain
;
1128 /* Removes a label definition for the current space.
1129 If there is no label_symbol_struct entry, then no action is taken. */
1132 pa_undefine_label ()
1134 label_symbol_struct
*label_chain
;
1135 label_symbol_struct
*prev_label_chain
= NULL
;
1136 sd_chain_struct
*space_chain
= current_space
;
1138 for (label_chain
= label_symbols_rootp
;
1140 label_chain
= label_chain
->lss_next
)
1142 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1144 /* Remove the label from the chain and free its memory. */
1145 if (prev_label_chain
)
1146 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1148 label_symbols_rootp
= label_chain
->lss_next
;
1153 prev_label_chain
= label_chain
;
1158 /* An HPPA-specific version of fix_new. This is required because the HPPA
1159 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1160 results in the creation of an instance of an hppa_fix_struct. An
1161 hppa_fix_struct stores the extra information along with a pointer to the
1162 original fixS. This is attached to the original fixup via the
1163 tc_fix_data field. */
1166 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1167 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1171 symbolS
*add_symbol
;
1175 bfd_reloc_code_real_type r_type
;
1176 enum hppa_reloc_field_selector_type r_field
;
1183 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1184 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1187 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1189 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1190 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1191 hppa_fix
->fx_r_type
= r_type
;
1192 hppa_fix
->fx_r_field
= r_field
;
1193 hppa_fix
->fx_r_format
= r_format
;
1194 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1195 hppa_fix
->segment
= now_seg
;
1197 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1198 new_fix
->fx_offset
= *unwind_bits
;
1201 /* foo-$global$ is used to access non-automatic storage. $global$
1202 is really just a marker and has served its purpose, so eliminate
1203 it now so as not to confuse write.c. */
1204 if (new_fix
->fx_subsy
1205 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1206 new_fix
->fx_subsy
= NULL
;
1209 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1210 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1213 parse_cons_expression_hppa (exp
)
1216 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1220 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1221 hppa_field_selector is set by the parse_cons_expression_hppa. */
1224 cons_fix_new_hppa (frag
, where
, size
, exp
)
1230 unsigned int rel_type
;
1232 /* Get a base relocation type. */
1233 if (is_DP_relative (*exp
))
1234 rel_type
= R_HPPA_GOTOFF
;
1235 else if (is_complex (*exp
))
1236 rel_type
= R_HPPA_COMPLEX
;
1240 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1241 as_warn ("Invalid field selector. Assuming F%%.");
1243 fix_new_hppa (frag
, where
, size
,
1244 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1245 hppa_field_selector
, 32, 0, NULL
);
1247 /* Reset field selector to its default state. */
1248 hppa_field_selector
= 0;
1251 /* This function is called once, at assembler startup time. It should
1252 set up all the tables, etc. that the MD part of the assembler will need. */
1257 const char *retval
= NULL
;
1261 last_call_info
= NULL
;
1262 call_info_root
= NULL
;
1264 /* Set the default machine type. */
1265 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1266 as_warn ("could not set architecture and machine");
1268 /* Folding of text and data segments fails miserably on the PA.
1269 Warn user and disable "-R" option. */
1270 if (flag_readonly_data_in_text
)
1272 as_warn ("-R option not supported on this target.");
1273 flag_readonly_data_in_text
= 0;
1278 op_hash
= hash_new ();
1280 while (i
< NUMOPCODES
)
1282 const char *name
= pa_opcodes
[i
].name
;
1283 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1284 if (retval
!= NULL
&& *retval
!= '\0')
1286 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1291 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1292 != pa_opcodes
[i
].match
)
1294 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1295 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1300 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1304 as_fatal ("Broken assembler. No assembly attempted.");
1306 /* SOM will change text_section. To make sure we never put
1307 anything into the old one switch to the new one now. */
1308 subseg_set (text_section
, 0);
1310 dummy_symbol
= symbol_find_or_make ("L$dummy");
1311 S_SET_SEGMENT (dummy_symbol
, text_section
);
1314 /* Assemble a single instruction storing it into a frag. */
1321 /* The had better be something to assemble. */
1324 /* If we are within a procedure definition, make sure we've
1325 defined a label for the procedure; handle case where the
1326 label was defined after the .PROC directive.
1328 Note there's not need to diddle with the segment or fragment
1329 for the label symbol in this case. We have already switched
1330 into the new $CODE$ subspace at this point. */
1331 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1333 label_symbol_struct
*label_symbol
= pa_get_label ();
1337 if (label_symbol
->lss_label
)
1339 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1340 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1342 /* Also handle allocation of a fixup to hold the unwind
1343 information when the label appears after the proc/procend. */
1344 if (within_entry_exit
)
1346 char *where
= frag_more (0);
1348 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1349 NULL
, (offsetT
) 0, NULL
,
1350 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1351 (int *)&last_call_info
->ci_unwind
.descriptor
);
1356 as_bad ("Missing function name for .PROC (corrupted label chain)");
1359 as_bad ("Missing function name for .PROC");
1362 /* Assemble the instruction. Results are saved into "the_insn". */
1365 /* Get somewhere to put the assembled instrution. */
1368 /* Output the opcode. */
1369 md_number_to_chars (to
, the_insn
.opcode
, 4);
1371 /* If necessary output more stuff. */
1372 if (the_insn
.reloc
!= R_HPPA_NONE
)
1373 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1374 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1375 the_insn
.reloc
, the_insn
.field_selector
,
1376 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1379 /* Do the real work for assembling a single instruction. Store results
1380 into the global "the_insn" variable. */
1386 char *error_message
= "";
1387 char *s
, c
, *argstart
, *name
, *save_s
;
1391 int cmpltr
, nullif
, flag
, cond
, num
;
1392 unsigned long opcode
;
1393 struct pa_opcode
*insn
;
1395 /* We must have a valid space and subspace. */
1396 pa_check_current_space_and_subspace ();
1398 /* Skip to something interesting. */
1399 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1418 as_fatal ("Unknown opcode: `%s'", str
);
1423 /* Convert everything into lower case. */
1426 if (isupper (*save_s
))
1427 *save_s
= tolower (*save_s
);
1431 /* Look up the opcode in the has table. */
1432 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1434 as_bad ("Unknown opcode: `%s'", str
);
1443 /* Mark the location where arguments for the instruction start, then
1444 start processing them. */
1448 /* Do some initialization. */
1449 opcode
= insn
->match
;
1450 bzero (&the_insn
, sizeof (the_insn
));
1452 the_insn
.reloc
= R_HPPA_NONE
;
1454 /* If this instruction is specific to a particular architecture,
1455 then set a new architecture. */
1456 if (bfd_get_mach (stdoutput
) < insn
->arch
)
1458 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1459 as_warn ("could not update architecture and machine");
1462 /* Build the opcode, checking as we go to make
1463 sure that the operands match. */
1464 for (args
= insn
->args
;; ++args
)
1469 /* End of arguments. */
1485 /* These must match exactly. */
1494 /* Handle a 5 bit register or control register field at 10. */
1497 num
= pa_parse_number (&s
, 0);
1498 CHECK_FIELD (num
, 31, 0, 0);
1499 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1501 /* Handle a 5 bit register field at 15. */
1503 num
= pa_parse_number (&s
, 0);
1504 CHECK_FIELD (num
, 31, 0, 0);
1505 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1507 /* Handle a 5 bit register field at 31. */
1510 num
= pa_parse_number (&s
, 0);
1511 CHECK_FIELD (num
, 31, 0, 0);
1512 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1514 /* Handle a 5 bit field length at 31. */
1516 num
= pa_get_absolute_expression (&the_insn
, &s
);
1518 CHECK_FIELD (num
, 32, 1, 0);
1519 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1521 /* Handle a 5 bit immediate at 15. */
1523 num
= pa_get_absolute_expression (&the_insn
, &s
);
1525 CHECK_FIELD (num
, 15, -16, 0);
1526 low_sign_unext (num
, 5, &num
);
1527 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1529 /* Handle a 5 bit immediate at 31. */
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
, 0);
1537 /* Handle an unsigned 5 bit immediate at 31. */
1539 num
= pa_get_absolute_expression (&the_insn
, &s
);
1541 CHECK_FIELD (num
, 31, 0, 0);
1542 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1544 /* Handle an unsigned 5 bit immediate at 15. */
1546 num
= pa_get_absolute_expression (&the_insn
, &s
);
1548 CHECK_FIELD (num
, 31, 0, 0);
1549 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1551 /* Handle a 2 bit space identifier at 17. */
1553 num
= pa_parse_number (&s
, 0);
1554 CHECK_FIELD (num
, 3, 0, 1);
1555 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1557 /* Handle a 3 bit space identifier at 18. */
1559 num
= pa_parse_number (&s
, 0);
1560 CHECK_FIELD (num
, 7, 0, 1);
1561 dis_assemble_3 (num
, &num
);
1562 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1564 /* Handle a completer for an indexing load or store. */
1570 while (*s
== ',' && i
< 2)
1573 if (strncasecmp (s
, "sm", 2) == 0)
1580 else if (strncasecmp (s
, "m", 1) == 0)
1582 else if (strncasecmp (s
, "s", 1) == 0)
1585 as_bad ("Invalid Indexed Load Completer.");
1590 as_bad ("Invalid Indexed Load Completer Syntax.");
1592 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1595 /* Handle a short load/store completer. */
1603 if (strncasecmp (s
, "ma", 2) == 0)
1608 else if (strncasecmp (s
, "mb", 2) == 0)
1614 as_bad ("Invalid Short Load/Store Completer.");
1618 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1621 /* Handle a stbys completer. */
1627 while (*s
== ',' && i
< 2)
1630 if (strncasecmp (s
, "m", 1) == 0)
1632 else if (strncasecmp (s
, "b", 1) == 0)
1634 else if (strncasecmp (s
, "e", 1) == 0)
1637 as_bad ("Invalid Store Bytes Short Completer");
1642 as_bad ("Invalid Store Bytes Short Completer");
1644 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1647 /* Handle a non-negated compare/stubtract condition. */
1649 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1652 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1655 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1657 /* Handle a negated or non-negated compare/subtract condition. */
1660 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1664 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1667 as_bad ("Invalid Compare/Subtract Condition.");
1672 /* Negated condition requires an opcode change. */
1676 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1678 /* Handle non-negated add condition. */
1680 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1683 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1686 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1688 /* Handle a negated or non-negated add condition. */
1691 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1695 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1698 as_bad ("Invalid Compare/Subtract Condition");
1703 /* Negated condition requires an opcode change. */
1707 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1709 /* Handle a compare/subtract condition. */
1716 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1721 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1724 as_bad ("Invalid Compare/Subtract Condition");
1728 opcode
|= cmpltr
<< 13;
1729 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1731 /* Handle a non-negated add condition. */
1740 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1744 if (strcmp (name
, "=") == 0)
1746 else if (strcmp (name
, "<") == 0)
1748 else if (strcmp (name
, "<=") == 0)
1750 else if (strcasecmp (name
, "nuv") == 0)
1752 else if (strcasecmp (name
, "znv") == 0)
1754 else if (strcasecmp (name
, "sv") == 0)
1756 else if (strcasecmp (name
, "od") == 0)
1758 else if (strcasecmp (name
, "n") == 0)
1760 else if (strcasecmp (name
, "tr") == 0)
1765 else if (strcmp (name
, "<>") == 0)
1770 else if (strcmp (name
, ">=") == 0)
1775 else if (strcmp (name
, ">") == 0)
1780 else if (strcasecmp (name
, "uv") == 0)
1785 else if (strcasecmp (name
, "vnz") == 0)
1790 else if (strcasecmp (name
, "nsv") == 0)
1795 else if (strcasecmp (name
, "ev") == 0)
1801 as_bad ("Invalid Add Condition: %s", name
);
1804 nullif
= pa_parse_nullif (&s
);
1805 opcode
|= nullif
<< 1;
1806 opcode
|= cmpltr
<< 13;
1807 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1809 /* HANDLE a logical instruction condition. */
1817 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1821 if (strcmp (name
, "=") == 0)
1823 else if (strcmp (name
, "<") == 0)
1825 else if (strcmp (name
, "<=") == 0)
1827 else if (strcasecmp (name
, "od") == 0)
1829 else if (strcasecmp (name
, "tr") == 0)
1834 else if (strcmp (name
, "<>") == 0)
1839 else if (strcmp (name
, ">=") == 0)
1844 else if (strcmp (name
, ">") == 0)
1849 else if (strcasecmp (name
, "ev") == 0)
1855 as_bad ("Invalid Logical Instruction Condition.");
1858 opcode
|= cmpltr
<< 13;
1859 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1861 /* Handle a unit instruction condition. */
1868 if (strncasecmp (s
, "sbz", 3) == 0)
1873 else if (strncasecmp (s
, "shz", 3) == 0)
1878 else if (strncasecmp (s
, "sdc", 3) == 0)
1883 else if (strncasecmp (s
, "sbc", 3) == 0)
1888 else if (strncasecmp (s
, "shc", 3) == 0)
1893 else if (strncasecmp (s
, "tr", 2) == 0)
1899 else if (strncasecmp (s
, "nbz", 3) == 0)
1905 else if (strncasecmp (s
, "nhz", 3) == 0)
1911 else if (strncasecmp (s
, "ndc", 3) == 0)
1917 else if (strncasecmp (s
, "nbc", 3) == 0)
1923 else if (strncasecmp (s
, "nhc", 3) == 0)
1930 as_bad ("Invalid Logical Instruction Condition.");
1932 opcode
|= cmpltr
<< 13;
1933 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1935 /* Handle a shift/extract/deposit condition. */
1943 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1947 if (strcmp (name
, "=") == 0)
1949 else if (strcmp (name
, "<") == 0)
1951 else if (strcasecmp (name
, "od") == 0)
1953 else if (strcasecmp (name
, "tr") == 0)
1955 else if (strcmp (name
, "<>") == 0)
1957 else if (strcmp (name
, ">=") == 0)
1959 else if (strcasecmp (name
, "ev") == 0)
1961 /* Handle movb,n. Put things back the way they were.
1962 This includes moving s back to where it started. */
1963 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1970 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1973 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1975 /* Handle bvb and bb conditions. */
1981 if (strncmp (s
, "<", 1) == 0)
1986 else if (strncmp (s
, ">=", 2) == 0)
1992 as_bad ("Invalid Bit Branch Condition: %c", *s
);
1994 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1996 /* Handle a system control completer. */
1998 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2006 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2008 /* Handle a nullification completer for branch instructions. */
2010 nullif
= pa_parse_nullif (&s
);
2011 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2013 /* Handle a nullification completer for copr and spop insns. */
2015 nullif
= pa_parse_nullif (&s
);
2016 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2018 /* Handle a 11 bit immediate at 31. */
2020 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2023 if (the_insn
.exp
.X_op
== O_constant
)
2025 num
= evaluate_absolute (&the_insn
);
2026 CHECK_FIELD (num
, 1023, -1024, 0);
2027 low_sign_unext (num
, 11, &num
);
2028 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2032 if (is_DP_relative (the_insn
.exp
))
2033 the_insn
.reloc
= R_HPPA_GOTOFF
;
2034 else if (is_PC_relative (the_insn
.exp
))
2035 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2037 the_insn
.reloc
= R_HPPA
;
2038 the_insn
.format
= 11;
2042 /* Handle a 14 bit immediate at 31. */
2044 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2047 if (the_insn
.exp
.X_op
== O_constant
)
2049 num
= evaluate_absolute (&the_insn
);
2050 CHECK_FIELD (num
, 8191, -8192, 0);
2051 low_sign_unext (num
, 14, &num
);
2052 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2056 if (is_DP_relative (the_insn
.exp
))
2057 the_insn
.reloc
= R_HPPA_GOTOFF
;
2058 else if (is_PC_relative (the_insn
.exp
))
2059 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2061 the_insn
.reloc
= R_HPPA
;
2062 the_insn
.format
= 14;
2066 /* Handle a 21 bit immediate at 31. */
2068 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2071 if (the_insn
.exp
.X_op
== O_constant
)
2073 num
= evaluate_absolute (&the_insn
);
2074 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2075 dis_assemble_21 (num
, &num
);
2076 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2080 if (is_DP_relative (the_insn
.exp
))
2081 the_insn
.reloc
= R_HPPA_GOTOFF
;
2082 else if (is_PC_relative (the_insn
.exp
))
2083 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2085 the_insn
.reloc
= R_HPPA
;
2086 the_insn
.format
= 21;
2090 /* Handle a 12 bit branch displacement. */
2092 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2096 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2098 unsigned int w1
, w
, result
;
2100 num
= evaluate_absolute (&the_insn
);
2103 as_bad ("Branch to unaligned address");
2106 CHECK_FIELD (num
, 8191, -8192, 0);
2107 sign_unext ((num
- 8) >> 2, 12, &result
);
2108 dis_assemble_12 (result
, &w1
, &w
);
2109 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2113 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2114 the_insn
.format
= 12;
2115 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2116 bzero (&last_call_desc
, sizeof (struct call_desc
));
2121 /* Handle a 17 bit branch displacement. */
2123 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2127 if (!the_insn
.exp
.X_add_symbol
2128 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2131 unsigned int w2
, w1
, w
, result
;
2133 num
= evaluate_absolute (&the_insn
);
2136 as_bad ("Branch to unaligned address");
2139 CHECK_FIELD (num
, 262143, -262144, 0);
2141 if (the_insn
.exp
.X_add_symbol
)
2144 sign_unext (num
>> 2, 17, &result
);
2145 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2146 INSERT_FIELD_AND_CONTINUE (opcode
,
2147 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2151 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2152 the_insn
.format
= 17;
2153 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2154 bzero (&last_call_desc
, sizeof (struct call_desc
));
2158 /* Handle an absolute 17 bit branch target. */
2160 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2164 if (!the_insn
.exp
.X_add_symbol
2165 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2168 unsigned int w2
, w1
, w
, result
;
2170 num
= evaluate_absolute (&the_insn
);
2173 as_bad ("Branch to unaligned address");
2176 CHECK_FIELD (num
, 262143, -262144, 0);
2178 if (the_insn
.exp
.X_add_symbol
)
2181 sign_unext (num
>> 2, 17, &result
);
2182 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2183 INSERT_FIELD_AND_CONTINUE (opcode
,
2184 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2188 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2189 the_insn
.format
= 17;
2190 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2191 bzero (&last_call_desc
, sizeof (struct call_desc
));
2195 /* Handle a 5 bit shift count at 26. */
2197 num
= pa_get_absolute_expression (&the_insn
, &s
);
2199 CHECK_FIELD (num
, 31, 0, 0);
2200 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2202 /* Handle a 5 bit bit position at 26. */
2204 num
= pa_get_absolute_expression (&the_insn
, &s
);
2206 CHECK_FIELD (num
, 31, 0, 0);
2207 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2209 /* Handle a 5 bit immediate at 10. */
2211 num
= pa_get_absolute_expression (&the_insn
, &s
);
2213 CHECK_FIELD (num
, 31, 0, 0);
2214 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2216 /* Handle a 13 bit immediate at 18. */
2218 num
= pa_get_absolute_expression (&the_insn
, &s
);
2220 CHECK_FIELD (num
, 8191, 0, 0);
2221 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2223 /* Handle a 26 bit immediate at 31. */
2225 num
= pa_get_absolute_expression (&the_insn
, &s
);
2227 CHECK_FIELD (num
, 671108864, 0, 0);
2228 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2230 /* Handle a 3 bit SFU identifier at 25. */
2233 as_bad ("Invalid SFU identifier");
2234 num
= pa_get_absolute_expression (&the_insn
, &s
);
2236 CHECK_FIELD (num
, 7, 0, 0);
2237 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2239 /* Handle a 20 bit SOP field for spop0. */
2241 num
= pa_get_absolute_expression (&the_insn
, &s
);
2243 CHECK_FIELD (num
, 1048575, 0, 0);
2244 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2245 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2247 /* Handle a 15bit SOP field for spop1. */
2249 num
= pa_get_absolute_expression (&the_insn
, &s
);
2251 CHECK_FIELD (num
, 32767, 0, 0);
2252 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2254 /* Handle a 10bit SOP field for spop3. */
2256 num
= pa_get_absolute_expression (&the_insn
, &s
);
2258 CHECK_FIELD (num
, 1023, 0, 0);
2259 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2260 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2262 /* Handle a 15 bit SOP field for spop2. */
2264 num
= pa_get_absolute_expression (&the_insn
, &s
);
2266 CHECK_FIELD (num
, 32767, 0, 0);
2267 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2268 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2270 /* Handle a 3-bit co-processor ID field. */
2273 as_bad ("Invalid COPR identifier");
2274 num
= pa_get_absolute_expression (&the_insn
, &s
);
2276 CHECK_FIELD (num
, 7, 0, 0);
2277 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2279 /* Handle a 22bit SOP field for copr. */
2281 num
= pa_get_absolute_expression (&the_insn
, &s
);
2283 CHECK_FIELD (num
, 4194303, 0, 0);
2284 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2285 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2287 /* Handle a source FP operand format completer. */
2289 flag
= pa_parse_fp_format (&s
);
2290 the_insn
.fpof1
= flag
;
2291 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2293 /* Handle a destination FP operand format completer. */
2295 /* pa_parse_format needs the ',' prefix. */
2297 flag
= pa_parse_fp_format (&s
);
2298 the_insn
.fpof2
= flag
;
2299 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2301 /* Handle FP compare conditions. */
2303 cond
= pa_parse_fp_cmp_cond (&s
);
2304 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2306 /* Handle L/R register halves like 't'. */
2309 struct pa_11_fp_reg_struct result
;
2311 pa_parse_number (&s
, &result
);
2312 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2313 opcode
|= result
.number_part
;
2315 /* 0x30 opcodes are FP arithmetic operation opcodes
2316 and need to be turned into 0x38 opcodes. This
2317 is not necessary for loads/stores. */
2318 if (need_pa11_opcode (&the_insn
, &result
)
2319 && ((opcode
& 0xfc000000) == 0x30000000))
2322 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2325 /* Handle L/R register halves like 'b'. */
2328 struct pa_11_fp_reg_struct result
;
2330 pa_parse_number (&s
, &result
);
2331 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2332 opcode
|= result
.number_part
<< 21;
2333 if (need_pa11_opcode (&the_insn
, &result
))
2335 opcode
|= (result
.l_r_select
& 1) << 7;
2341 /* Handle L/R register halves like 'x'. */
2344 struct pa_11_fp_reg_struct result
;
2346 pa_parse_number (&s
, &result
);
2347 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2348 opcode
|= (result
.number_part
& 0x1f) << 16;
2349 if (need_pa11_opcode (&the_insn
, &result
))
2351 opcode
|= (result
.l_r_select
& 1) << 12;
2357 /* Handle a 5 bit register field at 10. */
2360 struct pa_11_fp_reg_struct result
;
2362 pa_parse_number (&s
, &result
);
2363 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2364 if (the_insn
.fpof1
== SGL
)
2366 result
.number_part
&= 0xF;
2367 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2369 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2372 /* Handle a 5 bit register field at 15. */
2375 struct pa_11_fp_reg_struct result
;
2377 pa_parse_number (&s
, &result
);
2378 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2379 if (the_insn
.fpof1
== SGL
)
2381 result
.number_part
&= 0xF;
2382 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2384 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2387 /* Handle a 5 bit register field at 31. */
2390 struct pa_11_fp_reg_struct result
;
2392 pa_parse_number (&s
, &result
);
2393 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2394 if (the_insn
.fpof1
== SGL
)
2396 result
.number_part
&= 0xF;
2397 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2399 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2402 /* Handle a 5 bit register field at 20. */
2405 struct pa_11_fp_reg_struct result
;
2407 pa_parse_number (&s
, &result
);
2408 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2409 if (the_insn
.fpof1
== SGL
)
2411 result
.number_part
&= 0xF;
2412 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2414 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2417 /* Handle a 5 bit register field at 25. */
2420 struct pa_11_fp_reg_struct result
;
2422 pa_parse_number (&s
, &result
);
2423 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2424 if (the_insn
.fpof1
== SGL
)
2426 result
.number_part
&= 0xF;
2427 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2429 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2432 /* Handle a floating point operand format at 26.
2433 Only allows single and double precision. */
2435 flag
= pa_parse_fp_format (&s
);
2441 the_insn
.fpof1
= flag
;
2447 as_bad ("Invalid Floating Point Operand Format.");
2457 /* Check if the args matched. */
2460 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2461 && !strcmp (insn
->name
, insn
[1].name
))
2469 as_bad ("Invalid operands %s", error_message
);
2476 the_insn
.opcode
= opcode
;
2479 /* Turn a string in input_line_pointer into a floating point constant of type
2480 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2481 emitted is stored in *sizeP . An error message or NULL is returned. */
2483 #define MAX_LITTLENUMS 6
2486 md_atof (type
, litP
, sizeP
)
2492 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2493 LITTLENUM_TYPE
*wordP
;
2525 return "Bad call to MD_ATOF()";
2527 t
= atof_ieee (input_line_pointer
, type
, words
);
2529 input_line_pointer
= t
;
2530 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2531 for (wordP
= words
; prec
--;)
2533 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2534 litP
+= sizeof (LITTLENUM_TYPE
);
2539 /* Write out big-endian. */
2542 md_number_to_chars (buf
, val
, n
)
2547 number_to_chars_bigendian (buf
, val
, n
);
2550 /* Translate internal representation of relocation info to BFD target
2554 tc_gen_reloc (section
, fixp
)
2559 struct hppa_fix_struct
*hppa_fixp
;
2560 bfd_reloc_code_real_type code
;
2561 static arelent
*no_relocs
= NULL
;
2563 bfd_reloc_code_real_type
**codes
;
2567 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2568 if (fixp
->fx_addsy
== 0)
2570 assert (hppa_fixp
!= 0);
2571 assert (section
!= 0);
2573 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2574 assert (reloc
!= 0);
2576 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2577 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2579 hppa_fixp
->fx_r_format
,
2580 hppa_fixp
->fx_r_field
);
2582 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2585 relocs
= (arelent
**)
2586 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2587 assert (relocs
!= 0);
2589 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2590 sizeof (arelent
) * n_relocs
);
2592 assert (reloc
!= 0);
2594 for (i
= 0; i
< n_relocs
; i
++)
2595 relocs
[i
] = &reloc
[i
];
2597 relocs
[n_relocs
] = NULL
;
2600 switch (fixp
->fx_r_type
)
2603 assert (n_relocs
== 1);
2607 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2608 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2609 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2610 reloc
->addend
= 0; /* default */
2612 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2614 /* Now, do any processing that is dependent on the relocation type. */
2617 case R_PARISC_DLTREL21L
:
2618 case R_PARISC_DLTREL14R
:
2619 case R_PARISC_DLTREL14F
:
2620 case R_PARISC_PLABEL32
:
2621 case R_PARISC_PLABEL21L
:
2622 case R_PARISC_PLABEL14R
:
2623 /* For plabel relocations, the addend of the
2624 relocation should be either 0 (no static link) or 2
2625 (static link required).
2627 FIXME: We always assume no static link!
2629 We also slam a zero addend into the DLT relative relocs;
2630 it doesn't make a lot of sense to use any addend since
2631 it gets you a different (eg unknown) DLT entry. */
2635 case R_PARISC_PCREL21L
:
2636 case R_PARISC_PCREL17R
:
2637 case R_PARISC_PCREL17F
:
2638 case R_PARISC_PCREL17C
:
2639 case R_PARISC_PCREL14R
:
2640 case R_PARISC_PCREL14F
:
2641 /* The constant is stored in the instruction. */
2642 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2645 reloc
->addend
= fixp
->fx_offset
;
2652 /* Walk over reach relocation returned by the BFD backend. */
2653 for (i
= 0; i
< n_relocs
; i
++)
2657 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2658 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2659 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2665 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2671 /* For plabel relocations, the addend of the
2672 relocation should be either 0 (no static link) or 2
2673 (static link required).
2675 FIXME: We always assume no static link!
2677 We also slam a zero addend into the DLT relative relocs;
2678 it doesn't make a lot of sense to use any addend since
2679 it gets you a different (eg unknown) DLT entry. */
2680 relocs
[i
]->addend
= 0;
2690 /* There is no symbol or addend associated with these fixups. */
2691 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2692 relocs
[i
]->addend
= 0;
2697 /* There is no symbol associated with these fixups. */
2698 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2699 relocs
[i
]->addend
= fixp
->fx_offset
;
2703 relocs
[i
]->addend
= fixp
->fx_offset
;
2711 /* Process any machine dependent frag types. */
2714 md_convert_frag (abfd
, sec
, fragP
)
2716 register asection
*sec
;
2717 register fragS
*fragP
;
2719 unsigned int address
;
2721 if (fragP
->fr_type
== rs_machine_dependent
)
2723 switch ((int) fragP
->fr_subtype
)
2726 fragP
->fr_type
= rs_fill
;
2727 know (fragP
->fr_var
== 1);
2728 know (fragP
->fr_next
);
2729 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2730 if (address
% fragP
->fr_offset
)
2733 fragP
->fr_next
->fr_address
2738 fragP
->fr_offset
= 0;
2744 /* Round up a section size to the appropriate boundary. */
2747 md_section_align (segment
, size
)
2751 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2752 int align2
= (1 << align
) - 1;
2754 return (size
+ align2
) & ~align2
;
2757 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2759 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2761 addressT from_addr
, to_addr
;
2765 fprintf (stderr
, "pa_create_short_jmp\n");
2769 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2771 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2773 addressT from_addr
, to_addr
;
2777 fprintf (stderr
, "pa_create_long_jump\n");
2781 /* Return the approximate size of a frag before relaxation has occurred. */
2783 md_estimate_size_before_relax (fragP
, segment
)
2784 register fragS
*fragP
;
2791 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2797 CONST
char *md_shortopts
= "";
2798 struct option md_longopts
[] = {
2799 {NULL
, no_argument
, NULL
, 0}
2801 size_t md_longopts_size
= sizeof(md_longopts
);
2804 md_parse_option (c
, arg
)
2812 md_show_usage (stream
)
2817 /* We have no need to default values of symbols. */
2820 md_undefined_symbol (name
)
2826 /* Apply a fixup to an instruction. */
2829 md_apply_fix (fixP
, valp
)
2833 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2834 struct hppa_fix_struct
*hppa_fixP
;
2835 long new_val
, result
;
2836 unsigned int w1
, w2
, w
;
2838 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2839 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2840 never be "applied" (they are just markers). */
2842 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2843 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2847 /* There should have been an HPPA specific fixup associated
2848 with the GAS fixup. */
2851 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2852 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2854 /* If there is a symbol associated with this fixup, then it's something
2855 which will need a SOM relocation (except for some PC-relative relocs).
2856 In such cases we should treat the "val" or "addend" as zero since it
2857 will be added in as needed from fx_offset in tc_gen_reloc. */
2858 if ((fixP
->fx_addsy
!= NULL
2859 || fixP
->fx_r_type
== R_HPPA_NONE
)
2862 || hppa_fixP
->fx_r_field
== e_psel
2863 || hppa_fixP
->fx_r_field
== e_rpsel
2864 || hppa_fixP
->fx_r_field
== e_lpsel
2865 || hppa_fixP
->fx_r_field
== e_tsel
2866 || hppa_fixP
->fx_r_field
== e_rtsel
2867 || hppa_fixP
->fx_r_field
== e_ltsel
2870 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2872 /* This is truely disgusting. The machine independent code blindly
2873 adds in the value of the symbol being relocated against. Damn! */
2875 && fixP
->fx_addsy
!= NULL
2876 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
2877 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
2878 0, hppa_fixP
->fx_r_field
);
2881 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2883 /* Handle pc-relative exceptions from above. */
2884 #define arg_reloc_stub_needed(CALLER, CALLEE) \
2885 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2886 if ((fmt
== 12 || fmt
== 17)
2889 && !arg_reloc_stub_needed (((obj_symbol_type
*)
2890 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2891 hppa_fixP
->fx_arg_reloc
)
2892 && (*valp
> -262144 && *valp
< 262143)
2893 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
2895 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2897 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2898 #undef arg_reloc_stub_needed
2902 /* Handle all opcodes with the 'j' operand type. */
2904 CHECK_FIELD (new_val
, 8191, -8192, 0);
2906 /* Mask off 14 bits to be changed. */
2907 bfd_put_32 (stdoutput
,
2908 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2910 low_sign_unext (new_val
, 14, &result
);
2913 /* Handle all opcodes with the 'k' operand type. */
2915 CHECK_FIELD (new_val
, 2097152, 0, 0);
2917 /* Mask off 21 bits to be changed. */
2918 bfd_put_32 (stdoutput
,
2919 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2921 dis_assemble_21 (new_val
, &result
);
2924 /* Handle all the opcodes with the 'i' operand type. */
2926 CHECK_FIELD (new_val
, 1023, -1023, 0);
2928 /* Mask off 11 bits to be changed. */
2929 bfd_put_32 (stdoutput
,
2930 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2932 low_sign_unext (new_val
, 11, &result
);
2935 /* Handle all the opcodes with the 'w' operand type. */
2937 CHECK_FIELD (new_val
, 8191, -8192, 0)
2939 /* Mask off 11 bits to be changed. */
2940 sign_unext ((new_val
- 8) >> 2, 12, &result
);
2941 bfd_put_32 (stdoutput
,
2942 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
2945 dis_assemble_12 (result
, &w1
, &w
);
2946 result
= ((w1
<< 2) | w
);
2949 /* Handle some of the opcodes with the 'W' operand type. */
2951 CHECK_FIELD (new_val
, 262143, -262144, 0);
2953 /* Mask off 17 bits to be changed. */
2954 bfd_put_32 (stdoutput
,
2955 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
2957 sign_unext ((new_val
- 8) >> 2, 17, &result
);
2958 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2959 result
= ((w2
<< 2) | (w1
<< 16) | w
);
2964 bfd_put_32 (stdoutput
, new_val
, buf
);
2968 as_bad ("Unknown relocation encountered in md_apply_fix.");
2972 /* Insert the relocation. */
2973 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
2978 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
2979 (unsigned int) fixP
, fixP
->fx_r_type
);
2984 /* Exactly what point is a PC-relative offset relative TO?
2985 On the PA, they're relative to the address of the offset. */
2988 md_pcrel_from (fixP
)
2991 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2994 /* Return nonzero if the input line pointer is at the end of
2998 is_end_of_statement ()
3000 return ((*input_line_pointer
== '\n')
3001 || (*input_line_pointer
== ';')
3002 || (*input_line_pointer
== '!'));
3005 /* Read a number from S. The number might come in one of many forms,
3006 the most common will be a hex or decimal constant, but it could be
3007 a pre-defined register (Yuk!), or an absolute symbol.
3009 Return a number or -1 for failure.
3011 When parsing PA-89 FP register numbers RESULT will be
3012 the address of a structure to return information about
3013 L/R half of FP registers, store results there as appropriate.
3015 pa_parse_number can not handle negative constants and will fail
3016 horribly if it is passed such a constant. */
3019 pa_parse_number (s
, result
)
3021 struct pa_11_fp_reg_struct
*result
;
3030 /* Skip whitespace before the number. */
3031 while (*p
== ' ' || *p
== '\t')
3034 /* Store info in RESULT if requested by caller. */
3037 result
->number_part
= -1;
3038 result
->l_r_select
= -1;
3044 /* Looks like a number. */
3047 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3049 /* The number is specified in hex. */
3051 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3052 || ((*p
>= 'A') && (*p
<= 'F')))
3055 num
= num
* 16 + *p
- '0';
3056 else if (*p
>= 'a' && *p
<= 'f')
3057 num
= num
* 16 + *p
- 'a' + 10;
3059 num
= num
* 16 + *p
- 'A' + 10;
3065 /* The number is specified in decimal. */
3066 while (isdigit (*p
))
3068 num
= num
* 10 + *p
- '0';
3073 /* Store info in RESULT if requested by the caller. */
3076 result
->number_part
= num
;
3078 if (IS_R_SELECT (p
))
3080 result
->l_r_select
= 1;
3083 else if (IS_L_SELECT (p
))
3085 result
->l_r_select
= 0;
3089 result
->l_r_select
= 0;
3094 /* The number might be a predefined register. */
3099 /* Tege hack: Special case for general registers as the general
3100 code makes a binary search with case translation, and is VERY
3105 if (*p
== 'e' && *(p
+ 1) == 't'
3106 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3109 num
= *p
- '0' + 28;
3117 else if (!isdigit (*p
))
3120 as_bad ("Undefined register: '%s'.", name
);
3126 num
= num
* 10 + *p
++ - '0';
3127 while (isdigit (*p
));
3132 /* Do a normal register search. */
3133 while (is_part_of_name (c
))
3139 status
= reg_name_search (name
);
3145 as_bad ("Undefined register: '%s'.", name
);
3151 /* Store info in RESULT if requested by caller. */
3154 result
->number_part
= num
;
3155 if (IS_R_SELECT (p
- 1))
3156 result
->l_r_select
= 1;
3157 else if (IS_L_SELECT (p
- 1))
3158 result
->l_r_select
= 0;
3160 result
->l_r_select
= 0;
3165 /* And finally, it could be a symbol in the absolute section which
3166 is effectively a constant. */
3170 while (is_part_of_name (c
))
3176 if ((sym
= symbol_find (name
)) != NULL
)
3178 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3179 num
= S_GET_VALUE (sym
);
3183 as_bad ("Non-absolute symbol: '%s'.", name
);
3189 /* There is where we'd come for an undefined symbol
3190 or for an empty string. For an empty string we
3191 will return zero. That's a concession made for
3192 compatability with the braindamaged HP assemblers. */
3198 as_bad ("Undefined absolute constant: '%s'.", name
);
3204 /* Store info in RESULT if requested by caller. */
3207 result
->number_part
= num
;
3208 if (IS_R_SELECT (p
- 1))
3209 result
->l_r_select
= 1;
3210 else if (IS_L_SELECT (p
- 1))
3211 result
->l_r_select
= 0;
3213 result
->l_r_select
= 0;
3221 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3223 /* Given NAME, find the register number associated with that name, return
3224 the integer value associated with the given name or -1 on failure. */
3227 reg_name_search (name
)
3230 int middle
, low
, high
;
3234 high
= REG_NAME_CNT
- 1;
3238 middle
= (low
+ high
) / 2;
3239 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3245 return pre_defined_registers
[middle
].value
;
3247 while (low
<= high
);
3253 /* Return nonzero if the given INSN and L/R information will require
3254 a new PA-1.1 opcode. */
3257 need_pa11_opcode (insn
, result
)
3259 struct pa_11_fp_reg_struct
*result
;
3261 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3263 /* If this instruction is specific to a particular architecture,
3264 then set a new architecture. */
3265 if (bfd_get_mach (stdoutput
) < pa11
)
3267 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
3268 as_warn ("could not update architecture and machine");
3276 /* Parse a condition for a fcmp instruction. Return the numerical
3277 code associated with the condition. */
3280 pa_parse_fp_cmp_cond (s
)
3287 for (i
= 0; i
< 32; i
++)
3289 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3290 strlen (fp_cond_map
[i
].string
)) == 0)
3292 cond
= fp_cond_map
[i
].cond
;
3293 *s
+= strlen (fp_cond_map
[i
].string
);
3294 /* If not a complete match, back up the input string and
3296 if (**s
!= ' ' && **s
!= '\t')
3298 *s
-= strlen (fp_cond_map
[i
].string
);
3301 while (**s
== ' ' || **s
== '\t')
3307 as_bad ("Invalid FP Compare Condition: %s", *s
);
3309 /* Advance over the bogus completer. */
3310 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3316 /* Parse an FP operand format completer returning the completer
3319 static fp_operand_format
3320 pa_parse_fp_format (s
)
3329 if (strncasecmp (*s
, "sgl", 3) == 0)
3334 else if (strncasecmp (*s
, "dbl", 3) == 0)
3339 else if (strncasecmp (*s
, "quad", 4) == 0)
3346 format
= ILLEGAL_FMT
;
3347 as_bad ("Invalid FP Operand Format: %3s", *s
);
3354 /* Convert from a selector string into a selector type. */
3357 pa_chk_field_selector (str
)
3360 int middle
, low
, high
;
3364 /* Read past any whitespace. */
3365 /* FIXME: should we read past newlines and formfeeds??? */
3366 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3369 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3370 name
[0] = tolower ((*str
)[0]),
3372 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3373 name
[0] = tolower ((*str
)[0]),
3374 name
[1] = tolower ((*str
)[1]),
3380 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3384 middle
= (low
+ high
) / 2;
3385 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3392 *str
+= strlen (name
) + 1;
3393 return selector_table
[middle
].field_selector
;
3396 while (low
<= high
);
3401 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3404 get_expression (str
)
3410 save_in
= input_line_pointer
;
3411 input_line_pointer
= str
;
3412 seg
= expression (&the_insn
.exp
);
3413 if (!(seg
== absolute_section
3414 || seg
== undefined_section
3415 || SEG_NORMAL (seg
)))
3417 as_warn ("Bad segment in expression.");
3418 expr_end
= input_line_pointer
;
3419 input_line_pointer
= save_in
;
3422 expr_end
= input_line_pointer
;
3423 input_line_pointer
= save_in
;
3427 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3429 pa_get_absolute_expression (insn
, strp
)
3435 insn
->field_selector
= pa_chk_field_selector (strp
);
3436 save_in
= input_line_pointer
;
3437 input_line_pointer
= *strp
;
3438 expression (&insn
->exp
);
3439 if (insn
->exp
.X_op
!= O_constant
)
3441 as_bad ("Bad segment (should be absolute).");
3442 expr_end
= input_line_pointer
;
3443 input_line_pointer
= save_in
;
3446 expr_end
= input_line_pointer
;
3447 input_line_pointer
= save_in
;
3448 return evaluate_absolute (insn
);
3451 /* Evaluate an absolute expression EXP which may be modified by
3452 the selector FIELD_SELECTOR. Return the value of the expression. */
3454 evaluate_absolute (insn
)
3459 int field_selector
= insn
->field_selector
;
3462 value
= exp
.X_add_number
;
3464 switch (field_selector
)
3470 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3472 if (value
& 0x00000400)
3474 value
= (value
& 0xfffff800) >> 11;
3477 /* Sign extend from bit 21. */
3479 if (value
& 0x00000400)
3480 value
|= 0xfffff800;
3485 /* Arithmetic shift right 11 bits. */
3487 value
= (value
& 0xfffff800) >> 11;
3490 /* Set bits 0-20 to zero. */
3492 value
= value
& 0x7ff;
3495 /* Add 0x800 and arithmetic shift right 11 bits. */
3498 value
= (value
& 0xfffff800) >> 11;
3501 /* Set bitgs 0-21 to one. */
3503 value
|= 0xfffff800;
3506 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3508 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3512 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3517 BAD_CASE (field_selector
);
3523 /* Given an argument location specification return the associated
3524 argument location number. */
3527 pa_build_arg_reloc (type_name
)
3531 if (strncasecmp (type_name
, "no", 2) == 0)
3533 if (strncasecmp (type_name
, "gr", 2) == 0)
3535 else if (strncasecmp (type_name
, "fr", 2) == 0)
3537 else if (strncasecmp (type_name
, "fu", 2) == 0)
3540 as_bad ("Invalid argument location: %s\n", type_name
);
3545 /* Encode and return an argument relocation specification for
3546 the given register in the location specified by arg_reloc. */
3549 pa_align_arg_reloc (reg
, arg_reloc
)
3551 unsigned int arg_reloc
;
3553 unsigned int new_reloc
;
3555 new_reloc
= arg_reloc
;
3571 as_bad ("Invalid argument description: %d", reg
);
3577 /* Parse a PA nullification completer (,n). Return nonzero if the
3578 completer was found; return zero if no completer was found. */
3590 if (strncasecmp (*s
, "n", 1) == 0)
3594 as_bad ("Invalid Nullification: (%c)", **s
);
3603 /* Parse a non-negated compare/subtract completer returning the
3604 number (for encoding in instrutions) of the given completer.
3606 ISBRANCH specifies whether or not this is parsing a condition
3607 completer for a branch (vs a nullification completer for a
3608 computational instruction. */
3611 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3616 char *name
= *s
+ 1;
3624 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3628 if (strcmp (name
, "=") == 0)
3632 else if (strcmp (name
, "<") == 0)
3636 else if (strcmp (name
, "<=") == 0)
3640 else if (strcmp (name
, "<<") == 0)
3644 else if (strcmp (name
, "<<=") == 0)
3648 else if (strcasecmp (name
, "sv") == 0)
3652 else if (strcasecmp (name
, "od") == 0)
3656 /* If we have something like addb,n then there is no condition
3658 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3669 /* Reset pointers if this was really a ,n for a branch instruction. */
3670 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3676 /* Parse a negated compare/subtract completer returning the
3677 number (for encoding in instrutions) of the given completer.
3679 ISBRANCH specifies whether or not this is parsing a condition
3680 completer for a branch (vs a nullification completer for a
3681 computational instruction. */
3684 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3689 char *name
= *s
+ 1;
3697 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3701 if (strcasecmp (name
, "tr") == 0)
3705 else if (strcmp (name
, "<>") == 0)
3709 else if (strcmp (name
, ">=") == 0)
3713 else if (strcmp (name
, ">") == 0)
3717 else if (strcmp (name
, ">>=") == 0)
3721 else if (strcmp (name
, ">>") == 0)
3725 else if (strcasecmp (name
, "nsv") == 0)
3729 else if (strcasecmp (name
, "ev") == 0)
3733 /* If we have something like addb,n then there is no condition
3735 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3746 /* Reset pointers if this was really a ,n for a branch instruction. */
3747 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3753 /* Parse a non-negated addition completer returning the number
3754 (for encoding in instrutions) of the given completer.
3756 ISBRANCH specifies whether or not this is parsing a condition
3757 completer for a branch (vs a nullification completer for a
3758 computational instruction. */
3761 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3766 char *name
= *s
+ 1;
3774 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3778 if (strcmp (name
, "=") == 0)
3782 else if (strcmp (name
, "<") == 0)
3786 else if (strcmp (name
, "<=") == 0)
3790 else if (strcasecmp (name
, "nuv") == 0)
3794 else if (strcasecmp (name
, "znv") == 0)
3798 else if (strcasecmp (name
, "sv") == 0)
3802 else if (strcasecmp (name
, "od") == 0)
3806 /* If we have something like addb,n then there is no condition
3808 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3819 /* Reset pointers if this was really a ,n for a branch instruction. */
3820 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3826 /* Parse a negated addition completer returning the number
3827 (for encoding in instrutions) of the given completer.
3829 ISBRANCH specifies whether or not this is parsing a condition
3830 completer for a branch (vs a nullification completer for a
3831 computational instruction. */
3834 pa_parse_neg_add_cmpltr (s
, isbranch
)
3839 char *name
= *s
+ 1;
3847 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3851 if (strcasecmp (name
, "tr") == 0)
3855 else if (strcmp (name
, "<>") == 0)
3859 else if (strcmp (name
, ">=") == 0)
3863 else if (strcmp (name
, ">") == 0)
3867 else if (strcasecmp (name
, "uv") == 0)
3871 else if (strcasecmp (name
, "vnz") == 0)
3875 else if (strcasecmp (name
, "nsv") == 0)
3879 else if (strcasecmp (name
, "ev") == 0)
3883 /* If we have something like addb,n then there is no condition
3885 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3896 /* Reset pointers if this was really a ,n for a branch instruction. */
3897 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3903 /* Handle an alignment directive. Special so that we can update the
3904 alignment of the subspace if necessary. */
3908 /* We must have a valid space and subspace. */
3909 pa_check_current_space_and_subspace ();
3911 /* Let the generic gas code do most of the work. */
3912 s_align_bytes (bytes
);
3914 /* If bytes is a power of 2, then update the current subspace's
3915 alignment if necessary. */
3916 if (log2 (bytes
) != -1)
3917 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
3920 /* Handle a .BLOCK type pseudo-op. */
3928 unsigned int temp_size
;
3931 /* We must have a valid space and subspace. */
3932 pa_check_current_space_and_subspace ();
3934 temp_size
= get_absolute_expression ();
3936 /* Always fill with zeros, that's what the HP assembler does. */
3939 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
3940 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
3941 bzero (p
, temp_size
);
3943 /* Convert 2 bytes at a time. */
3945 for (i
= 0; i
< temp_size
; i
+= 2)
3947 md_number_to_chars (p
+ i
,
3949 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
3952 pa_undefine_label ();
3953 demand_empty_rest_of_line ();
3956 /* Handle a .CALL pseudo-op. This involves storing away information
3957 about where arguments are to be found so the linker can detect
3958 (and correct) argument location mismatches between caller and callee. */
3964 /* We must have a valid space and subspace. */
3965 pa_check_current_space_and_subspace ();
3967 pa_call_args (&last_call_desc
);
3968 demand_empty_rest_of_line ();
3971 /* Do the dirty work of building a call descriptor which describes
3972 where the caller placed arguments to a function call. */
3975 pa_call_args (call_desc
)
3976 struct call_desc
*call_desc
;
3979 unsigned int temp
, arg_reloc
;
3981 while (!is_end_of_statement ())
3983 name
= input_line_pointer
;
3984 c
= get_symbol_end ();
3985 /* Process a source argument. */
3986 if ((strncasecmp (name
, "argw", 4) == 0))
3988 temp
= atoi (name
+ 4);
3989 p
= input_line_pointer
;
3991 input_line_pointer
++;
3992 name
= input_line_pointer
;
3993 c
= get_symbol_end ();
3994 arg_reloc
= pa_build_arg_reloc (name
);
3995 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
3997 /* Process a return value. */
3998 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4000 p
= input_line_pointer
;
4002 input_line_pointer
++;
4003 name
= input_line_pointer
;
4004 c
= get_symbol_end ();
4005 arg_reloc
= pa_build_arg_reloc (name
);
4006 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4010 as_bad ("Invalid .CALL argument: %s", name
);
4012 p
= input_line_pointer
;
4014 if (!is_end_of_statement ())
4015 input_line_pointer
++;
4019 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4022 is_same_frag (frag1
, frag2
)
4029 else if (frag2
== NULL
)
4031 else if (frag1
== frag2
)
4033 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4034 return (is_same_frag (frag1
, frag2
->fr_next
));
4040 /* Build an entry in the UNWIND subspace from the given function
4041 attributes in CALL_INFO. This is not needed for SOM as using
4042 R_ENTRY and R_EXIT relocations allow the linker to handle building
4043 of the unwind spaces. */
4046 pa_build_unwind_subspace (call_info
)
4047 struct call_info
*call_info
;
4050 asection
*seg
, *save_seg
;
4051 subsegT subseg
, save_subseg
;
4055 /* Get into the right seg/subseg. This may involve creating
4056 the seg the first time through. Make sure to have the
4057 old seg/subseg so that we can reset things when we are done. */
4058 subseg
= SUBSEG_UNWIND
;
4059 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4060 if (seg
== ASEC_NULL
)
4062 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4063 bfd_set_section_flags (stdoutput
, seg
,
4064 SEC_READONLY
| SEC_HAS_CONTENTS
4065 | SEC_LOAD
| SEC_RELOC
);
4069 save_subseg
= now_subseg
;
4070 subseg_set (seg
, subseg
);
4073 /* Get some space to hold relocation information for the unwind
4077 /* Relocation info. for start offset of the function. */
4078 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4079 call_info
->start_symbol
, (offsetT
) 0,
4080 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4084 /* Relocation info. for end offset of the function. */
4085 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4086 call_info
->start_symbol
,
4087 call_info
->function_size
,
4088 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4091 unwind
= (char *) &call_info
->ci_unwind
;
4092 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4096 FRAG_APPEND_1_CHAR (c
);
4100 /* Return back to the original segment/subsegment. */
4101 subseg_set (save_seg
, save_subseg
);
4105 /* Process a .CALLINFO pseudo-op. This information is used later
4106 to build unwind descriptors and maybe one day to support
4107 .ENTER and .LEAVE. */
4110 pa_callinfo (unused
)
4116 /* We must have a valid space and subspace. */
4117 pa_check_current_space_and_subspace ();
4119 /* .CALLINFO must appear within a procedure definition. */
4120 if (!within_procedure
)
4121 as_bad (".callinfo is not within a procedure definition");
4123 /* Mark the fact that we found the .CALLINFO for the
4124 current procedure. */
4125 callinfo_found
= TRUE
;
4127 /* Iterate over the .CALLINFO arguments. */
4128 while (!is_end_of_statement ())
4130 name
= input_line_pointer
;
4131 c
= get_symbol_end ();
4132 /* Frame size specification. */
4133 if ((strncasecmp (name
, "frame", 5) == 0))
4135 p
= input_line_pointer
;
4137 input_line_pointer
++;
4138 temp
= get_absolute_expression ();
4139 if ((temp
& 0x3) != 0)
4141 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4145 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4146 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4149 /* Entry register (GR, GR and SR) specifications. */
4150 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4152 p
= input_line_pointer
;
4154 input_line_pointer
++;
4155 temp
= get_absolute_expression ();
4156 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4157 even though %r19 is caller saved. I think this is a bug in
4158 the HP assembler, and we are not going to emulate it. */
4159 if (temp
< 3 || temp
> 18)
4160 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4161 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4163 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4165 p
= input_line_pointer
;
4167 input_line_pointer
++;
4168 temp
= get_absolute_expression ();
4169 /* Similarly the HP assembler takes 31 as the high bound even
4170 though %fr21 is the last callee saved floating point register. */
4171 if (temp
< 12 || temp
> 21)
4172 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4173 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4175 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4177 p
= input_line_pointer
;
4179 input_line_pointer
++;
4180 temp
= get_absolute_expression ();
4182 as_bad ("Value for ENTRY_SR must be 3\n");
4184 /* Note whether or not this function performs any calls. */
4185 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4186 (strncasecmp (name
, "caller", 6) == 0))
4188 p
= input_line_pointer
;
4191 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4193 p
= input_line_pointer
;
4196 /* Should RP be saved into the stack. */
4197 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4199 p
= input_line_pointer
;
4201 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4203 /* Likewise for SP. */
4204 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4206 p
= input_line_pointer
;
4208 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4210 /* Is this an unwindable procedure. If so mark it so
4211 in the unwind descriptor. */
4212 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4214 p
= input_line_pointer
;
4216 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4218 /* Is this an interrupt routine. If so mark it in the
4219 unwind descriptor. */
4220 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4222 p
= input_line_pointer
;
4224 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4226 /* Is this a millicode routine. "millicode" isn't in my
4227 assembler manual, but my copy is old. The HP assembler
4228 accepts it, and there's a place in the unwind descriptor
4229 to drop the information, so we'll accept it too. */
4230 else if ((strncasecmp (name
, "millicode", 9) == 0))
4232 p
= input_line_pointer
;
4234 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4238 as_bad ("Invalid .CALLINFO argument: %s", name
);
4239 *input_line_pointer
= c
;
4241 if (!is_end_of_statement ())
4242 input_line_pointer
++;
4245 demand_empty_rest_of_line ();
4248 /* Switch into the code subspace. */
4254 current_space
= is_defined_space ("$TEXT$");
4256 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
4258 pa_undefine_label ();
4261 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4262 the .comm pseudo-op has the following symtax:
4264 <label> .comm <length>
4266 where <label> is optional and is a symbol whose address will be the start of
4267 a block of memory <length> bytes long. <length> must be an absolute
4268 expression. <length> bytes will be allocated in the current space
4271 Also note the label may not even be on the same line as the .comm.
4273 This difference in syntax means the colon function will be called
4274 on the symbol before we arrive in pa_comm. colon will set a number
4275 of attributes of the symbol that need to be fixed here. In particular
4276 the value, section pointer, fragment pointer, flags, etc. What
4279 This also makes error detection all but impossible. */
4287 label_symbol_struct
*label_symbol
= pa_get_label ();
4290 symbol
= label_symbol
->lss_label
;
4295 size
= get_absolute_expression ();
4299 S_SET_VALUE (symbol
, size
);
4300 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4301 S_SET_EXTERNAL (symbol
);
4303 /* colon() has already set the frag to the current location in the
4304 current subspace; we need to reset the fragment to the zero address
4305 fragment. We also need to reset the segment pointer. */
4306 symbol
->sy_frag
= &zero_address_frag
;
4308 demand_empty_rest_of_line ();
4311 /* Process a .END pseudo-op. */
4317 demand_empty_rest_of_line ();
4320 /* Process a .ENTER pseudo-op. This is not supported. */
4325 /* We must have a valid space and subspace. */
4326 pa_check_current_space_and_subspace ();
4331 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4337 /* We must have a valid space and subspace. */
4338 pa_check_current_space_and_subspace ();
4340 if (!within_procedure
)
4341 as_bad ("Misplaced .entry. Ignored.");
4344 if (!callinfo_found
)
4345 as_bad ("Missing .callinfo.");
4347 demand_empty_rest_of_line ();
4348 within_entry_exit
= TRUE
;
4351 /* SOM defers building of unwind descriptors until the link phase.
4352 The assembler is responsible for creating an R_ENTRY relocation
4353 to mark the beginning of a region and hold the unwind bits, and
4354 for creating an R_EXIT relocation to mark the end of the region.
4356 FIXME. ELF should be using the same conventions! The problem
4357 is an unwind requires too much relocation space. Hmmm. Maybe
4358 if we split the unwind bits up between the relocations which
4359 denote the entry and exit points. */
4360 if (last_call_info
->start_symbol
!= NULL
)
4362 char *where
= frag_more (0);
4364 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4365 NULL
, (offsetT
) 0, NULL
,
4366 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4367 (int *) &last_call_info
->ci_unwind
.descriptor
);
4372 /* Handle a .EQU pseudo-op. */
4378 label_symbol_struct
*label_symbol
= pa_get_label ();
4383 symbol
= label_symbol
->lss_label
;
4385 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4387 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4388 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4393 as_bad (".REG must use a label");
4395 as_bad (".EQU must use a label");
4398 pa_undefine_label ();
4399 demand_empty_rest_of_line ();
4402 /* Helper function. Does processing for the end of a function. This
4403 usually involves creating some relocations or building special
4404 symbols to mark the end of the function. */
4411 where
= frag_more (0);
4413 last_call_info
->function_size
4414 = where
- frag_now
->fr_literal
- S_GET_VALUE (last_call_info
->start_symbol
);
4417 /* Mark the end of the function, stuff away the location of the frag
4418 for the end of the function, and finally call pa_build_unwind_subspace
4419 to add an entry in the unwind table. */
4420 pa_build_unwind_subspace (last_call_info
);
4422 /* SOM defers building of unwind descriptors until the link phase.
4423 The assembler is responsible for creating an R_ENTRY relocation
4424 to mark the beginning of a region and hold the unwind bits, and
4425 for creating an R_EXIT relocation to mark the end of the region.
4427 FIXME. ELF should be using the same conventions! The problem
4428 is an unwind requires too much relocation space. Hmmm. Maybe
4429 if we split the unwind bits up between the relocations which
4430 denote the entry and exit points. */
4431 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4433 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4434 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4438 /* Process a .EXIT pseudo-op. */
4444 /* We must have a valid space and subspace. */
4445 pa_check_current_space_and_subspace ();
4447 if (!within_procedure
)
4448 as_bad (".EXIT must appear within a procedure");
4451 if (!callinfo_found
)
4452 as_bad ("Missing .callinfo");
4455 if (!within_entry_exit
)
4456 as_bad ("No .ENTRY for this .EXIT");
4459 within_entry_exit
= FALSE
;
4464 demand_empty_rest_of_line ();
4467 /* Process a .EXPORT directive. This makes functions external
4468 and provides information such as argument relocation entries
4478 name
= input_line_pointer
;
4479 c
= get_symbol_end ();
4480 /* Make sure the given symbol exists. */
4481 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4483 as_bad ("Cannot define export symbol: %s\n", name
);
4484 p
= input_line_pointer
;
4486 input_line_pointer
++;
4490 /* OK. Set the external bits and process argument relocations. */
4491 S_SET_EXTERNAL (symbol
);
4492 p
= input_line_pointer
;
4494 if (!is_end_of_statement ())
4496 input_line_pointer
++;
4497 pa_type_args (symbol
, 1);
4501 demand_empty_rest_of_line ();
4504 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4507 pa_type_args (symbolP
, is_export
)
4512 unsigned int temp
, arg_reloc
;
4513 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4514 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4516 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4519 input_line_pointer
+= 8;
4520 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4521 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4522 type
= SYMBOL_TYPE_ABSOLUTE
;
4524 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4526 input_line_pointer
+= 4;
4527 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4528 instead one should be IMPORTing/EXPORTing ENTRY types.
4530 Complain if one tries to EXPORT a CODE type since that's never
4531 done. Both GCC and HP C still try to IMPORT CODE types, so
4532 silently fix them to be ENTRY types. */
4533 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4536 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4538 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4539 type
= SYMBOL_TYPE_ENTRY
;
4543 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4544 type
= SYMBOL_TYPE_CODE
;
4547 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4549 input_line_pointer
+= 4;
4550 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4551 type
= SYMBOL_TYPE_DATA
;
4553 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4555 input_line_pointer
+= 5;
4556 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4557 type
= SYMBOL_TYPE_ENTRY
;
4559 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4561 input_line_pointer
+= 9;
4562 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4563 type
= SYMBOL_TYPE_MILLICODE
;
4565 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4567 input_line_pointer
+= 6;
4568 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4569 type
= SYMBOL_TYPE_PLABEL
;
4571 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4573 input_line_pointer
+= 8;
4574 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4575 type
= SYMBOL_TYPE_PRI_PROG
;
4577 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4579 input_line_pointer
+= 8;
4580 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4581 type
= SYMBOL_TYPE_SEC_PROG
;
4584 /* SOM requires much more information about symbol types
4585 than BFD understands. This is how we get this information
4586 to the SOM BFD backend. */
4587 #ifdef obj_set_symbol_type
4588 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4591 /* Now that the type of the exported symbol has been handled,
4592 handle any argument relocation information. */
4593 while (!is_end_of_statement ())
4595 if (*input_line_pointer
== ',')
4596 input_line_pointer
++;
4597 name
= input_line_pointer
;
4598 c
= get_symbol_end ();
4599 /* Argument sources. */
4600 if ((strncasecmp (name
, "argw", 4) == 0))
4602 p
= input_line_pointer
;
4604 input_line_pointer
++;
4605 temp
= atoi (name
+ 4);
4606 name
= input_line_pointer
;
4607 c
= get_symbol_end ();
4608 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4609 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4610 *input_line_pointer
= c
;
4612 /* The return value. */
4613 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4615 p
= input_line_pointer
;
4617 input_line_pointer
++;
4618 name
= input_line_pointer
;
4619 c
= get_symbol_end ();
4620 arg_reloc
= pa_build_arg_reloc (name
);
4621 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4622 *input_line_pointer
= c
;
4624 /* Privelege level. */
4625 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4627 p
= input_line_pointer
;
4629 input_line_pointer
++;
4630 temp
= atoi (input_line_pointer
);
4631 c
= get_symbol_end ();
4632 *input_line_pointer
= c
;
4636 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4637 p
= input_line_pointer
;
4640 if (!is_end_of_statement ())
4641 input_line_pointer
++;
4645 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4646 assembly file must either be defined in the assembly file, or
4647 explicitly IMPORTED from another. */
4656 name
= input_line_pointer
;
4657 c
= get_symbol_end ();
4659 symbol
= symbol_find (name
);
4660 /* Ugh. We might be importing a symbol defined earlier in the file,
4661 in which case all the code below will really screw things up
4662 (set the wrong segment, symbol flags & type, etc). */
4663 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4665 symbol
= symbol_find_or_make (name
);
4666 p
= input_line_pointer
;
4669 if (!is_end_of_statement ())
4671 input_line_pointer
++;
4672 pa_type_args (symbol
, 0);
4676 /* Sigh. To be compatable with the HP assembler and to help
4677 poorly written assembly code, we assign a type based on
4678 the the current segment. Note only BSF_FUNCTION really
4679 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4680 if (now_seg
== text_section
)
4681 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4683 /* If the section is undefined, then the symbol is undefined
4684 Since this is an import, leave the section undefined. */
4685 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4690 /* The symbol was already defined. Just eat everything up to
4691 the end of the current statement. */
4692 while (!is_end_of_statement ())
4693 input_line_pointer
++;
4696 demand_empty_rest_of_line ();
4699 /* Handle a .LABEL pseudo-op. */
4707 name
= input_line_pointer
;
4708 c
= get_symbol_end ();
4710 if (strlen (name
) > 0)
4713 p
= input_line_pointer
;
4718 as_warn ("Missing label name on .LABEL");
4721 if (!is_end_of_statement ())
4723 as_warn ("extra .LABEL arguments ignored.");
4724 ignore_rest_of_line ();
4726 demand_empty_rest_of_line ();
4729 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4735 /* We must have a valid space and subspace. */
4736 pa_check_current_space_and_subspace ();
4741 /* Handle a .ORIGIN pseudo-op. */
4747 /* We must have a valid space and subspace. */
4748 pa_check_current_space_and_subspace ();
4751 pa_undefine_label ();
4754 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4755 is for static functions. FIXME. Should share more code with .EXPORT. */
4764 name
= input_line_pointer
;
4765 c
= get_symbol_end ();
4767 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4769 as_bad ("Cannot define static symbol: %s\n", name
);
4770 p
= input_line_pointer
;
4772 input_line_pointer
++;
4776 S_CLEAR_EXTERNAL (symbol
);
4777 p
= input_line_pointer
;
4779 if (!is_end_of_statement ())
4781 input_line_pointer
++;
4782 pa_type_args (symbol
, 0);
4786 demand_empty_rest_of_line ();
4789 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4790 of a procedure from a syntatical point of view. */
4796 struct call_info
*call_info
;
4798 /* We must have a valid space and subspace. */
4799 pa_check_current_space_and_subspace ();
4801 if (within_procedure
)
4802 as_fatal ("Nested procedures");
4804 /* Reset global variables for new procedure. */
4805 callinfo_found
= FALSE
;
4806 within_procedure
= TRUE
;
4808 /* Create another call_info structure. */
4809 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4812 as_fatal ("Cannot allocate unwind descriptor\n");
4814 bzero (call_info
, sizeof (struct call_info
));
4816 call_info
->ci_next
= NULL
;
4818 if (call_info_root
== NULL
)
4820 call_info_root
= call_info
;
4821 last_call_info
= call_info
;
4825 last_call_info
->ci_next
= call_info
;
4826 last_call_info
= call_info
;
4829 /* set up defaults on call_info structure */
4831 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4832 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4833 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4835 /* If we got a .PROC pseudo-op, we know that the function is defined
4836 locally. Make sure it gets into the symbol table. */
4838 label_symbol_struct
*label_symbol
= pa_get_label ();
4842 if (label_symbol
->lss_label
)
4844 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4845 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4848 as_bad ("Missing function name for .PROC (corrupted label chain)");
4851 last_call_info
->start_symbol
= NULL
;
4854 demand_empty_rest_of_line ();
4857 /* Process the syntatical end of a procedure. Make sure all the
4858 appropriate pseudo-ops were found within the procedure. */
4865 /* We must have a valid space and subspace. */
4866 pa_check_current_space_and_subspace ();
4868 /* If we are within a procedure definition, make sure we've
4869 defined a label for the procedure; handle case where the
4870 label was defined after the .PROC directive.
4872 Note there's not need to diddle with the segment or fragment
4873 for the label symbol in this case. We have already switched
4874 into the new $CODE$ subspace at this point. */
4875 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4877 label_symbol_struct
*label_symbol
= pa_get_label ();
4881 if (label_symbol
->lss_label
)
4883 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4884 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4886 /* Also handle allocation of a fixup to hold the unwind
4887 information when the label appears after the proc/procend. */
4888 if (within_entry_exit
)
4890 char *where
= frag_more (0);
4892 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4893 NULL
, (offsetT
) 0, NULL
,
4894 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4895 (int *) &last_call_info
->ci_unwind
.descriptor
);
4900 as_bad ("Missing function name for .PROC (corrupted label chain)");
4903 as_bad ("Missing function name for .PROC");
4906 if (!within_procedure
)
4907 as_bad ("misplaced .procend");
4909 if (!callinfo_found
)
4910 as_bad ("Missing .callinfo for this procedure");
4912 if (within_entry_exit
)
4913 as_bad ("Missing .EXIT for a .ENTRY");
4915 last_call_info
->function_size
4916 = frag_more (0) - frag_now
->fr_literal
- S_GET_VALUE (last_call_info
->start_symbol
);
4917 within_procedure
= FALSE
;
4918 demand_empty_rest_of_line ();
4919 pa_undefine_label ();
4922 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4923 then create a new space entry to hold the information specified
4924 by the parameters to the .SPACE directive. */
4926 static sd_chain_struct
*
4927 pa_parse_space_stmt (space_name
, create_flag
)
4931 char *name
, *ptemp
, c
;
4932 char loadable
, defined
, private, sort
;
4934 asection
*seg
= NULL
;
4935 sd_chain_struct
*space
;
4937 /* load default values */
4943 if (strcmp (space_name
, "$TEXT$") == 0)
4945 seg
= pa_def_spaces
[0].segment
;
4946 defined
= pa_def_spaces
[0].defined
;
4947 private = pa_def_spaces
[0].private;
4948 sort
= pa_def_spaces
[0].sort
;
4949 spnum
= pa_def_spaces
[0].spnum
;
4951 else if (strcmp (space_name
, "$PRIVATE$") == 0)
4953 seg
= pa_def_spaces
[1].segment
;
4954 defined
= pa_def_spaces
[1].defined
;
4955 private = pa_def_spaces
[1].private;
4956 sort
= pa_def_spaces
[1].sort
;
4957 spnum
= pa_def_spaces
[1].spnum
;
4960 if (!is_end_of_statement ())
4962 print_errors
= FALSE
;
4963 ptemp
= input_line_pointer
+ 1;
4964 /* First see if the space was specified as a number rather than
4965 as a name. According to the PA assembly manual the rest of
4966 the line should be ignored. */
4967 temp
= pa_parse_number (&ptemp
, 0);
4971 input_line_pointer
= ptemp
;
4975 while (!is_end_of_statement ())
4977 input_line_pointer
++;
4978 name
= input_line_pointer
;
4979 c
= get_symbol_end ();
4980 if ((strncasecmp (name
, "spnum", 5) == 0))
4982 *input_line_pointer
= c
;
4983 input_line_pointer
++;
4984 spnum
= get_absolute_expression ();
4986 else if ((strncasecmp (name
, "sort", 4) == 0))
4988 *input_line_pointer
= c
;
4989 input_line_pointer
++;
4990 sort
= get_absolute_expression ();
4992 else if ((strncasecmp (name
, "unloadable", 10) == 0))
4994 *input_line_pointer
= c
;
4997 else if ((strncasecmp (name
, "notdefined", 10) == 0))
4999 *input_line_pointer
= c
;
5002 else if ((strncasecmp (name
, "private", 7) == 0))
5004 *input_line_pointer
= c
;
5009 as_bad ("Invalid .SPACE argument");
5010 *input_line_pointer
= c
;
5011 if (!is_end_of_statement ())
5012 input_line_pointer
++;
5016 print_errors
= TRUE
;
5019 if (create_flag
&& seg
== NULL
)
5020 seg
= subseg_new (space_name
, 0);
5022 /* If create_flag is nonzero, then create the new space with
5023 the attributes computed above. Else set the values in
5024 an already existing space -- this can only happen for
5025 the first occurence of a built-in space. */
5027 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5028 private, sort
, seg
, 1);
5031 space
= is_defined_space (space_name
);
5032 SPACE_SPNUM (space
) = spnum
;
5033 SPACE_DEFINED (space
) = defined
& 1;
5034 SPACE_USER_DEFINED (space
) = 1;
5037 #ifdef obj_set_section_attributes
5038 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5044 /* Handle a .SPACE pseudo-op; this switches the current space to the
5045 given space, creating the new space if necessary. */
5051 char *name
, c
, *space_name
, *save_s
;
5053 sd_chain_struct
*sd_chain
;
5055 if (within_procedure
)
5057 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5058 ignore_rest_of_line ();
5062 /* Check for some of the predefined spaces. FIXME: most of the code
5063 below is repeated several times, can we extract the common parts
5064 and place them into a subroutine or something similar? */
5065 /* FIXME Is this (and the next IF stmt) really right?
5066 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5067 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5069 input_line_pointer
+= 6;
5070 sd_chain
= is_defined_space ("$TEXT$");
5071 if (sd_chain
== NULL
)
5072 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5073 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5074 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5076 current_space
= sd_chain
;
5077 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5079 = pa_subsegment_to_subspace (text_section
,
5080 sd_chain
->sd_last_subseg
);
5081 demand_empty_rest_of_line ();
5084 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5086 input_line_pointer
+= 9;
5087 sd_chain
= is_defined_space ("$PRIVATE$");
5088 if (sd_chain
== NULL
)
5089 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5090 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5091 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5093 current_space
= sd_chain
;
5094 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5096 = pa_subsegment_to_subspace (data_section
,
5097 sd_chain
->sd_last_subseg
);
5098 demand_empty_rest_of_line ();
5101 if (!strncasecmp (input_line_pointer
,
5102 GDB_DEBUG_SPACE_NAME
,
5103 strlen (GDB_DEBUG_SPACE_NAME
)))
5105 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5106 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5107 if (sd_chain
== NULL
)
5108 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5109 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5110 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5112 current_space
= sd_chain
;
5115 asection
*gdb_section
5116 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5118 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5120 = pa_subsegment_to_subspace (gdb_section
,
5121 sd_chain
->sd_last_subseg
);
5123 demand_empty_rest_of_line ();
5127 /* It could be a space specified by number. */
5129 save_s
= input_line_pointer
;
5130 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5132 if ((sd_chain
= pa_find_space_by_number (temp
)))
5134 current_space
= sd_chain
;
5136 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5138 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5139 sd_chain
->sd_last_subseg
);
5140 demand_empty_rest_of_line ();
5145 /* Not a number, attempt to create a new space. */
5147 input_line_pointer
= save_s
;
5148 name
= input_line_pointer
;
5149 c
= get_symbol_end ();
5150 space_name
= xmalloc (strlen (name
) + 1);
5151 strcpy (space_name
, name
);
5152 *input_line_pointer
= c
;
5154 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5155 current_space
= sd_chain
;
5157 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5158 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5159 sd_chain
->sd_last_subseg
);
5160 demand_empty_rest_of_line ();
5164 /* Switch to a new space. (I think). FIXME. */
5173 sd_chain_struct
*space
;
5175 name
= input_line_pointer
;
5176 c
= get_symbol_end ();
5177 space
= is_defined_space (name
);
5181 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5184 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5186 *input_line_pointer
= c
;
5187 demand_empty_rest_of_line ();
5190 /* If VALUE is an exact power of two between zero and 2^31, then
5191 return log2 (VALUE). Else return -1. */
5199 while ((1 << shift
) != value
&& shift
< 32)
5208 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5209 given subspace, creating the new subspace if necessary.
5211 FIXME. Should mirror pa_space more closely, in particular how
5212 they're broken up into subroutines. */
5215 pa_subspace (unused
)
5218 char *name
, *ss_name
, *alias
, c
;
5219 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5220 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5221 sd_chain_struct
*space
;
5222 ssd_chain_struct
*ssd
;
5225 if (current_space
== NULL
)
5226 as_fatal ("Must be in a space before changing or declaring subspaces.\n");
5228 if (within_procedure
)
5230 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5231 ignore_rest_of_line ();
5235 name
= input_line_pointer
;
5236 c
= get_symbol_end ();
5237 ss_name
= xmalloc (strlen (name
) + 1);
5238 strcpy (ss_name
, name
);
5239 *input_line_pointer
= c
;
5241 /* Load default values. */
5254 space
= current_space
;
5255 ssd
= is_defined_subspace (ss_name
);
5256 /* Allow user to override the builtin attributes of subspaces. But
5257 only allow the attributes to be changed once! */
5258 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5260 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5261 current_subspace
= ssd
;
5262 if (!is_end_of_statement ())
5263 as_warn ("Parameters of an existing subspace can\'t be modified");
5264 demand_empty_rest_of_line ();
5269 /* A new subspace. Load default values if it matches one of
5270 the builtin subspaces. */
5272 while (pa_def_subspaces
[i
].name
)
5274 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5276 loadable
= pa_def_subspaces
[i
].loadable
;
5277 common
= pa_def_subspaces
[i
].common
;
5278 dup_common
= pa_def_subspaces
[i
].dup_common
;
5279 code_only
= pa_def_subspaces
[i
].code_only
;
5280 zero
= pa_def_subspaces
[i
].zero
;
5281 space_index
= pa_def_subspaces
[i
].space_index
;
5282 alignment
= pa_def_subspaces
[i
].alignment
;
5283 quadrant
= pa_def_subspaces
[i
].quadrant
;
5284 access
= pa_def_subspaces
[i
].access
;
5285 sort
= pa_def_subspaces
[i
].sort
;
5286 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5287 alias
= pa_def_subspaces
[i
].alias
;
5294 /* We should be working with a new subspace now. Fill in
5295 any information as specified by the user. */
5296 if (!is_end_of_statement ())
5298 input_line_pointer
++;
5299 while (!is_end_of_statement ())
5301 name
= input_line_pointer
;
5302 c
= get_symbol_end ();
5303 if ((strncasecmp (name
, "quad", 4) == 0))
5305 *input_line_pointer
= c
;
5306 input_line_pointer
++;
5307 quadrant
= get_absolute_expression ();
5309 else if ((strncasecmp (name
, "align", 5) == 0))
5311 *input_line_pointer
= c
;
5312 input_line_pointer
++;
5313 alignment
= get_absolute_expression ();
5314 if (log2 (alignment
) == -1)
5316 as_bad ("Alignment must be a power of 2");
5320 else if ((strncasecmp (name
, "access", 6) == 0))
5322 *input_line_pointer
= c
;
5323 input_line_pointer
++;
5324 access
= get_absolute_expression ();
5326 else if ((strncasecmp (name
, "sort", 4) == 0))
5328 *input_line_pointer
= c
;
5329 input_line_pointer
++;
5330 sort
= get_absolute_expression ();
5332 else if ((strncasecmp (name
, "code_only", 9) == 0))
5334 *input_line_pointer
= c
;
5337 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5339 *input_line_pointer
= c
;
5342 else if ((strncasecmp (name
, "common", 6) == 0))
5344 *input_line_pointer
= c
;
5347 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5349 *input_line_pointer
= c
;
5352 else if ((strncasecmp (name
, "zero", 4) == 0))
5354 *input_line_pointer
= c
;
5357 else if ((strncasecmp (name
, "first", 5) == 0))
5358 as_bad ("FIRST not supported as a .SUBSPACE argument");
5360 as_bad ("Invalid .SUBSPACE argument");
5361 if (!is_end_of_statement ())
5362 input_line_pointer
++;
5366 /* Compute a reasonable set of BFD flags based on the information
5367 in the .subspace directive. */
5368 applicable
= bfd_applicable_section_flags (stdoutput
);
5371 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5374 if (common
|| dup_common
)
5375 flags
|= SEC_IS_COMMON
;
5377 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5379 /* This is a zero-filled subspace (eg BSS). */
5381 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
5383 applicable
&= flags
;
5385 /* If this is an existing subspace, then we want to use the
5386 segment already associated with the subspace.
5388 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5389 lots of sections. It might be a problem in the PA ELF
5390 code, I do not know yet. For now avoid creating anything
5391 but the "standard" sections for ELF. */
5393 section
= ssd
->ssd_seg
;
5395 section
= subseg_new (alias
, 0);
5396 else if (!alias
&& USE_ALIASES
)
5398 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5399 demand_empty_rest_of_line ();
5403 section
= subseg_new (ss_name
, 0);
5406 seg_info (section
)->bss
= 1;
5408 /* Now set the flags. */
5409 bfd_set_section_flags (stdoutput
, section
, applicable
);
5411 /* Record any alignment request for this section. */
5412 record_alignment (section
, log2 (alignment
));
5414 /* Set the starting offset for this section. */
5415 bfd_set_section_vma (stdoutput
, section
,
5416 pa_subspace_start (space
, quadrant
));
5418 /* Now that all the flags are set, update an existing subspace,
5419 or create a new one. */
5422 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5423 code_only
, common
, dup_common
,
5424 sort
, zero
, access
, space_index
,
5425 alignment
, quadrant
,
5428 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5430 dup_common
, zero
, sort
,
5431 access
, space_index
,
5432 alignment
, quadrant
, section
);
5434 demand_empty_rest_of_line ();
5435 current_subspace
->ssd_seg
= section
;
5436 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5438 SUBSPACE_DEFINED (current_subspace
) = 1;
5442 /* Create default space and subspace dictionaries. */
5449 space_dict_root
= NULL
;
5450 space_dict_last
= NULL
;
5453 while (pa_def_spaces
[i
].name
)
5457 /* Pick the right name to use for the new section. */
5458 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5459 name
= pa_def_spaces
[i
].alias
;
5461 name
= pa_def_spaces
[i
].name
;
5463 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5464 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5465 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5466 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5467 pa_def_spaces
[i
].segment
, 0);
5472 while (pa_def_subspaces
[i
].name
)
5475 int applicable
, subsegment
;
5476 asection
*segment
= NULL
;
5477 sd_chain_struct
*space
;
5479 /* Pick the right name for the new section and pick the right
5480 subsegment number. */
5481 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5483 name
= pa_def_subspaces
[i
].alias
;
5484 subsegment
= pa_def_subspaces
[i
].subsegment
;
5488 name
= pa_def_subspaces
[i
].name
;
5492 /* Create the new section. */
5493 segment
= subseg_new (name
, subsegment
);
5496 /* For SOM we want to replace the standard .text, .data, and .bss
5497 sections with our own. We also want to set BFD flags for
5498 all the built-in subspaces. */
5499 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5501 text_section
= segment
;
5502 applicable
= bfd_applicable_section_flags (stdoutput
);
5503 bfd_set_section_flags (stdoutput
, segment
,
5504 applicable
& (SEC_ALLOC
| SEC_LOAD
5505 | SEC_RELOC
| SEC_CODE
5507 | SEC_HAS_CONTENTS
));
5509 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5511 data_section
= segment
;
5512 applicable
= bfd_applicable_section_flags (stdoutput
);
5513 bfd_set_section_flags (stdoutput
, segment
,
5514 applicable
& (SEC_ALLOC
| SEC_LOAD
5516 | SEC_HAS_CONTENTS
));
5520 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5522 bss_section
= segment
;
5523 applicable
= bfd_applicable_section_flags (stdoutput
);
5524 bfd_set_section_flags (stdoutput
, segment
,
5525 applicable
& SEC_ALLOC
);
5527 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5529 applicable
= bfd_applicable_section_flags (stdoutput
);
5530 bfd_set_section_flags (stdoutput
, segment
,
5531 applicable
& (SEC_ALLOC
| SEC_LOAD
5534 | SEC_HAS_CONTENTS
));
5536 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5538 applicable
= bfd_applicable_section_flags (stdoutput
);
5539 bfd_set_section_flags (stdoutput
, segment
,
5540 applicable
& (SEC_ALLOC
| SEC_LOAD
5543 | SEC_HAS_CONTENTS
));
5546 /* Find the space associated with this subspace. */
5547 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5548 def_space_index
].segment
);
5551 as_fatal ("Internal error: Unable to find containing space for %s.",
5552 pa_def_subspaces
[i
].name
);
5555 create_new_subspace (space
, name
,
5556 pa_def_subspaces
[i
].loadable
,
5557 pa_def_subspaces
[i
].code_only
,
5558 pa_def_subspaces
[i
].common
,
5559 pa_def_subspaces
[i
].dup_common
,
5560 pa_def_subspaces
[i
].zero
,
5561 pa_def_subspaces
[i
].sort
,
5562 pa_def_subspaces
[i
].access
,
5563 pa_def_subspaces
[i
].space_index
,
5564 pa_def_subspaces
[i
].alignment
,
5565 pa_def_subspaces
[i
].quadrant
,
5573 /* Create a new space NAME, with the appropriate flags as defined
5574 by the given parameters. */
5576 static sd_chain_struct
*
5577 create_new_space (name
, spnum
, loadable
, defined
, private,
5578 sort
, seg
, user_defined
)
5588 sd_chain_struct
*chain_entry
;
5590 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5592 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5595 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5596 strcpy (SPACE_NAME (chain_entry
), name
);
5597 SPACE_DEFINED (chain_entry
) = defined
;
5598 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5599 SPACE_SPNUM (chain_entry
) = spnum
;
5601 chain_entry
->sd_seg
= seg
;
5602 chain_entry
->sd_last_subseg
= -1;
5603 chain_entry
->sd_subspaces
= NULL
;
5604 chain_entry
->sd_next
= NULL
;
5606 /* Find spot for the new space based on its sort key. */
5607 if (!space_dict_last
)
5608 space_dict_last
= chain_entry
;
5610 if (space_dict_root
== NULL
)
5611 space_dict_root
= chain_entry
;
5614 sd_chain_struct
*chain_pointer
;
5615 sd_chain_struct
*prev_chain_pointer
;
5617 chain_pointer
= space_dict_root
;
5618 prev_chain_pointer
= NULL
;
5620 while (chain_pointer
)
5622 prev_chain_pointer
= chain_pointer
;
5623 chain_pointer
= chain_pointer
->sd_next
;
5626 /* At this point we've found the correct place to add the new
5627 entry. So add it and update the linked lists as appropriate. */
5628 if (prev_chain_pointer
)
5630 chain_entry
->sd_next
= chain_pointer
;
5631 prev_chain_pointer
->sd_next
= chain_entry
;
5635 space_dict_root
= chain_entry
;
5636 chain_entry
->sd_next
= chain_pointer
;
5639 if (chain_entry
->sd_next
== NULL
)
5640 space_dict_last
= chain_entry
;
5643 /* This is here to catch predefined spaces which do not get
5644 modified by the user's input. Another call is found at
5645 the bottom of pa_parse_space_stmt to handle cases where
5646 the user modifies a predefined space. */
5647 #ifdef obj_set_section_attributes
5648 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5654 /* Create a new subspace NAME, with the appropriate flags as defined
5655 by the given parameters.
5657 Add the new subspace to the subspace dictionary chain in numerical
5658 order as defined by the SORT entries. */
5660 static ssd_chain_struct
*
5661 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5662 dup_common
, is_zero
, sort
, access
, space_index
,
5663 alignment
, quadrant
, seg
)
5664 sd_chain_struct
*space
;
5666 int loadable
, code_only
, common
, dup_common
, is_zero
;
5674 ssd_chain_struct
*chain_entry
;
5676 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5678 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5680 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5681 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5683 /* Initialize subspace_defined. When we hit a .subspace directive
5684 we'll set it to 1 which "locks-in" the subspace attributes. */
5685 SUBSPACE_DEFINED (chain_entry
) = 0;
5687 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5688 chain_entry
->ssd_seg
= seg
;
5689 chain_entry
->ssd_next
= NULL
;
5691 /* Find spot for the new subspace based on its sort key. */
5692 if (space
->sd_subspaces
== NULL
)
5693 space
->sd_subspaces
= chain_entry
;
5696 ssd_chain_struct
*chain_pointer
;
5697 ssd_chain_struct
*prev_chain_pointer
;
5699 chain_pointer
= space
->sd_subspaces
;
5700 prev_chain_pointer
= NULL
;
5702 while (chain_pointer
)
5704 prev_chain_pointer
= chain_pointer
;
5705 chain_pointer
= chain_pointer
->ssd_next
;
5708 /* Now we have somewhere to put the new entry. Insert it and update
5710 if (prev_chain_pointer
)
5712 chain_entry
->ssd_next
= chain_pointer
;
5713 prev_chain_pointer
->ssd_next
= chain_entry
;
5717 space
->sd_subspaces
= chain_entry
;
5718 chain_entry
->ssd_next
= chain_pointer
;
5722 #ifdef obj_set_subsection_attributes
5723 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5730 /* Update the information for the given subspace based upon the
5731 various arguments. Return the modified subspace chain entry. */
5733 static ssd_chain_struct
*
5734 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5735 zero
, access
, space_index
, alignment
, quadrant
, section
)
5736 sd_chain_struct
*space
;
5750 ssd_chain_struct
*chain_entry
;
5752 chain_entry
= is_defined_subspace (name
);
5754 #ifdef obj_set_subsection_attributes
5755 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5762 /* Return the space chain entry for the space with the name NAME or
5763 NULL if no such space exists. */
5765 static sd_chain_struct
*
5766 is_defined_space (name
)
5769 sd_chain_struct
*chain_pointer
;
5771 for (chain_pointer
= space_dict_root
;
5773 chain_pointer
= chain_pointer
->sd_next
)
5775 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5776 return chain_pointer
;
5779 /* No mapping from segment to space was found. Return NULL. */
5783 /* Find and return the space associated with the given seg. If no mapping
5784 from the given seg to a space is found, then return NULL.
5786 Unlike subspaces, the number of spaces is not expected to grow much,
5787 so a linear exhaustive search is OK here. */
5789 static sd_chain_struct
*
5790 pa_segment_to_space (seg
)
5793 sd_chain_struct
*space_chain
;
5795 /* Walk through each space looking for the correct mapping. */
5796 for (space_chain
= space_dict_root
;
5798 space_chain
= space_chain
->sd_next
)
5800 if (space_chain
->sd_seg
== seg
)
5804 /* Mapping was not found. Return NULL. */
5808 /* Return the space chain entry for the subspace with the name NAME or
5809 NULL if no such subspace exists.
5811 Uses a linear search through all the spaces and subspaces, this may
5812 not be appropriate if we ever being placing each function in its
5815 static ssd_chain_struct
*
5816 is_defined_subspace (name
)
5819 sd_chain_struct
*space_chain
;
5820 ssd_chain_struct
*subspace_chain
;
5822 /* Walk through each space. */
5823 for (space_chain
= space_dict_root
;
5825 space_chain
= space_chain
->sd_next
)
5827 /* Walk through each subspace looking for a name which matches. */
5828 for (subspace_chain
= space_chain
->sd_subspaces
;
5830 subspace_chain
= subspace_chain
->ssd_next
)
5831 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5832 return subspace_chain
;
5835 /* Subspace wasn't found. Return NULL. */
5839 /* Find and return the subspace associated with the given seg. If no
5840 mapping from the given seg to a subspace is found, then return NULL.
5842 If we ever put each procedure/function within its own subspace
5843 (to make life easier on the compiler and linker), then this will have
5844 to become more efficient. */
5846 static ssd_chain_struct
*
5847 pa_subsegment_to_subspace (seg
, subseg
)
5851 sd_chain_struct
*space_chain
;
5852 ssd_chain_struct
*subspace_chain
;
5854 /* Walk through each space. */
5855 for (space_chain
= space_dict_root
;
5857 space_chain
= space_chain
->sd_next
)
5859 if (space_chain
->sd_seg
== seg
)
5861 /* Walk through each subspace within each space looking for
5862 the correct mapping. */
5863 for (subspace_chain
= space_chain
->sd_subspaces
;
5865 subspace_chain
= subspace_chain
->ssd_next
)
5866 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5867 return subspace_chain
;
5871 /* No mapping from subsegment to subspace found. Return NULL. */
5875 /* Given a number, try and find a space with the name number.
5877 Return a pointer to a space dictionary chain entry for the space
5878 that was found or NULL on failure. */
5880 static sd_chain_struct
*
5881 pa_find_space_by_number (number
)
5884 sd_chain_struct
*space_chain
;
5886 for (space_chain
= space_dict_root
;
5888 space_chain
= space_chain
->sd_next
)
5890 if (SPACE_SPNUM (space_chain
) == number
)
5894 /* No appropriate space found. Return NULL. */
5898 /* Return the starting address for the given subspace. If the starting
5899 address is unknown then return zero. */
5902 pa_subspace_start (space
, quadrant
)
5903 sd_chain_struct
*space
;
5906 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5907 is not correct for the PA OSF1 port. */
5908 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5910 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5916 /* FIXME. Needs documentation. */
5918 pa_next_subseg (space
)
5919 sd_chain_struct
*space
;
5922 space
->sd_last_subseg
++;
5923 return space
->sd_last_subseg
;
5926 /* Helper function for pa_stringer. Used to find the end of
5933 unsigned int c
= *s
& CHAR_MASK
;
5935 /* We must have a valid space and subspace. */
5936 pa_check_current_space_and_subspace ();
5949 /* Handle a .STRING type pseudo-op. */
5952 pa_stringer (append_zero
)
5955 char *s
, num_buf
[4];
5959 /* Preprocess the string to handle PA-specific escape sequences.
5960 For example, \xDD where DD is a hexidecimal number should be
5961 changed to \OOO where OOO is an octal number. */
5963 /* Skip the opening quote. */
5964 s
= input_line_pointer
+ 1;
5966 while (is_a_char (c
= pa_stringer_aux (s
++)))
5973 /* Handle \x<num>. */
5976 unsigned int number
;
5981 /* Get pas the 'x'. */
5983 for (num_digit
= 0, number
= 0, dg
= *s
;
5985 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
5986 || (dg
>= 'A' && dg
<= 'F'));
5990 number
= number
* 16 + dg
- '0';
5991 else if (dg
>= 'a' && dg
<= 'f')
5992 number
= number
* 16 + dg
- 'a' + 10;
5994 number
= number
* 16 + dg
- 'A' + 10;
6004 sprintf (num_buf
, "%02o", number
);
6007 sprintf (num_buf
, "%03o", number
);
6010 for (i
= 0; i
<= num_digit
; i
++)
6011 s_start
[i
] = num_buf
[i
];
6015 /* This might be a "\"", skip over the escaped char. */
6022 stringer (append_zero
);
6023 pa_undefine_label ();
6026 /* Handle a .VERSION pseudo-op. */
6033 pa_undefine_label ();
6036 /* Handle a .COPYRIGHT pseudo-op. */
6039 pa_copyright (unused
)
6043 pa_undefine_label ();
6046 /* Just like a normal cons, but when finished we have to undefine
6047 the latest space label. */
6054 pa_undefine_label ();
6057 /* Switch to the data space. As usual delete our label. */
6063 current_space
= is_defined_space ("$PRIVATE$");
6065 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6067 pa_undefine_label ();
6070 /* Like float_cons, but we need to undefine our label. */
6073 pa_float_cons (float_type
)
6076 float_cons (float_type
);
6077 pa_undefine_label ();
6080 /* Like s_fill, but delete our label when finished. */
6086 /* We must have a valid space and subspace. */
6087 pa_check_current_space_and_subspace ();
6090 pa_undefine_label ();
6093 /* Like lcomm, but delete our label when finished. */
6096 pa_lcomm (needs_align
)
6099 /* We must have a valid space and subspace. */
6100 pa_check_current_space_and_subspace ();
6102 s_lcomm (needs_align
);
6103 pa_undefine_label ();
6106 /* Like lsym, but delete our label when finished. */
6112 /* We must have a valid space and subspace. */
6113 pa_check_current_space_and_subspace ();
6116 pa_undefine_label ();
6119 /* Switch to the text space. Like s_text, but delete our
6120 label when finished. */
6125 current_space
= is_defined_space ("$TEXT$");
6127 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6130 pa_undefine_label ();
6133 /* On the PA relocations which involve function symbols must not be
6134 adjusted. This so that the linker can know when/how to create argument
6135 relocation stubs for indirect calls and calls to static functions.
6137 "T" field selectors create DLT relative fixups for accessing
6138 globals and statics in PIC code; each DLT relative fixup creates
6139 an entry in the DLT table. The entries contain the address of
6140 the final target (eg accessing "foo" would create a DLT entry
6141 with the address of "foo").
6143 Unfortunately, the HP linker doesn't take into account any addend
6144 when generating the DLT; so accessing $LIT$+8 puts the address of
6145 $LIT$ into the DLT rather than the address of $LIT$+8.
6147 The end result is we can't perform relocation symbol reductions for
6148 any fixup which creates entries in the DLT (eg they use "T" field
6151 Reject reductions involving symbols with external scope; such
6152 reductions make life a living hell for object file editors.
6154 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6155 the code space. The SOM BFD backend doesn't know how to pull the
6156 right bits out of an instruction. */
6159 hppa_fix_adjustable (fixp
)
6162 struct hppa_fix_struct
*hppa_fix
;
6164 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6167 /* Reject reductions of symbols in 32bit relocs. */
6168 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6172 /* Reject reductions of symbols in DLT relative relocs,
6173 relocations with plabels. */
6174 if (hppa_fix
->fx_r_field
== e_tsel
6175 || hppa_fix
->fx_r_field
== e_ltsel
6176 || hppa_fix
->fx_r_field
== e_rtsel
6177 || hppa_fix
->fx_r_field
== e_psel
6178 || hppa_fix
->fx_r_field
== e_rpsel
6179 || hppa_fix
->fx_r_field
== e_lpsel
)
6182 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6185 /* Reject reductions of function symbols. */
6186 if (fixp
->fx_addsy
== 0
6187 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6193 /* Return nonzero if the fixup in FIXP will require a relocation,
6194 even it if appears that the fixup could be completely handled
6198 hppa_force_relocation (fixp
)
6201 struct hppa_fix_struct
*hppa_fixp
;
6202 unsigned int distance
;
6204 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6206 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6210 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6211 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6213 /* It is necessary to force PC-relative calls/jumps to have a relocation
6214 entry if they're going to need either a argument relocation or long
6215 call stub. FIXME. Can't we need the same for absolute calls? */
6216 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6217 && (arg_reloc_stub_needed (((obj_symbol_type
*)
6218 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6220 hppa_fixp
->fx_arg_reloc
)))
6222 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
6223 - md_pcrel_from (fixp
));
6224 /* Now check and see if we're going to need a long-branch stub. */
6225 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
6226 && (distance
> 262143 || distance
< -262144))
6229 #undef arg_reloc_stub_needed
6231 /* No need (yet) to force another relocations to be emitted. */
6235 /* Now for some ELF specific code. FIXME. */
6237 /* For ELF, this function serves one purpose: to setup the st_size
6238 field of STT_FUNC symbols. */
6241 elf_hppa_final_processing ()
6243 struct call_info
*call_info_pointer
;
6245 for (call_info_pointer
= call_info_root
;
6247 call_info_pointer
= call_info_pointer
->ci_next
)
6249 elf_symbol_type
*esym
6250 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6251 esym
->internal_elf_sym
.st_size
= call_info_pointer
->function_size
;