1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "bfd/libhppa.h"
31 #include "bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".PARISC.unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
55 /* ELF objects can have versions, but apparently do not have anywhere
56 to store a copyright string. */
57 #define obj_version obj_elf_version
58 #define obj_copyright obj_elf_version
60 /* Use space aliases. */
65 /* Names of various debugging spaces/subspaces. */
66 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
67 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
68 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
69 #define UNWIND_SECTION_NAME "$UNWIND$"
71 /* Object file formats specify relocation types. */
72 typedef int reloc_type
;
74 /* SOM objects can have both a version string and a copyright string. */
75 #define obj_version obj_som_version
76 #define obj_copyright obj_som_copyright
78 /* Do not use space aliases. */
81 /* How to generate a relocation. */
82 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
84 /* Object file formats specify BFD symbol types. */
85 typedef som_symbol_type obj_symbol_type
;
87 /* This apparently isn't in older versions of hpux reloc.h. */
89 #define R_DLT_REL 0x78
93 /* Various structures and types used internally in tc-hppa.c. */
95 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
99 unsigned int cannot_unwind
:1;
100 unsigned int millicode
:1;
101 unsigned int millicode_save_rest
:1;
102 unsigned int region_desc
:2;
103 unsigned int save_sr
:2;
104 unsigned int entry_fr
:4;
105 unsigned int entry_gr
:5;
106 unsigned int args_stored
:1;
107 unsigned int call_fr
:5;
108 unsigned int call_gr
:5;
109 unsigned int save_sp
:1;
110 unsigned int save_rp
:1;
111 unsigned int save_rp_in_frame
:1;
112 unsigned int extn_ptr_defined
:1;
113 unsigned int cleanup_defined
:1;
115 unsigned int hpe_interrupt_marker
:1;
116 unsigned int hpux_interrupt_marker
:1;
117 unsigned int reserved
:3;
118 unsigned int frame_size
:27;
123 /* Starting and ending offsets of the region described by
125 unsigned int start_offset
;
126 unsigned int end_offset
;
127 struct unwind_desc descriptor
;
130 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
131 control the entry and exit code they generate. It is also used in
132 creation of the correct stack unwind descriptors.
134 NOTE: GAS does not support .enter and .leave for the generation of
135 prologues and epilogues. FIXME.
137 The fields in structure roughly correspond to the arguments available on the
138 .callinfo pseudo-op. */
142 /* The unwind descriptor being built. */
143 struct unwind_table ci_unwind
;
145 /* Name of this function. */
146 symbolS
*start_symbol
;
148 /* (temporary) symbol used to mark the end of this function. */
151 /* Next entry in the chain. */
152 struct call_info
*ci_next
;
155 /* Operand formats for FP instructions. Note not all FP instructions
156 allow all four formats to be used (for example fmpysub only allows
160 SGL
, DBL
, ILLEGAL_FMT
, QUAD
164 /* This fully describes the symbol types which may be attached to
165 an EXPORT or IMPORT directive. Only SOM uses this formation
166 (ELF has no need for it). */
170 SYMBOL_TYPE_ABSOLUTE
,
174 SYMBOL_TYPE_MILLICODE
,
176 SYMBOL_TYPE_PRI_PROG
,
177 SYMBOL_TYPE_SEC_PROG
,
181 /* This structure contains information needed to assemble
182 individual instructions. */
185 /* Holds the opcode after parsing by pa_ip. */
186 unsigned long opcode
;
188 /* Holds an expression associated with the current instruction. */
191 /* Does this instruction use PC-relative addressing. */
194 /* Floating point formats for operand1 and operand2. */
195 fp_operand_format fpof1
;
196 fp_operand_format fpof2
;
198 /* Holds the field selector for this instruction
199 (for example L%, LR%, etc). */
202 /* Holds any argument relocation bits associated with this
203 instruction. (instruction should be some sort of call). */
206 /* The format specification for this instruction. */
209 /* The relocation (if any) associated with this instruction. */
213 /* PA-89 floating point registers are arranged like this:
216 +--------------+--------------+
217 | 0 or 16L | 16 or 16R |
218 +--------------+--------------+
219 | 1 or 17L | 17 or 17R |
220 +--------------+--------------+
228 +--------------+--------------+
229 | 14 or 30L | 30 or 30R |
230 +--------------+--------------+
231 | 15 or 31L | 31 or 31R |
232 +--------------+--------------+
235 The following is a version of pa_parse_number that
236 handles the L/R notation and returns the correct
237 value to put into the instruction register field.
238 The correct value to put into the instruction is
239 encoded in the structure 'pa_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));
543 static void hppa_elf_mark_end_of_function
PARAMS ((void));
545 /* File and gloally scoped variable declarations. */
547 /* Root and final entry in the space chain. */
548 static sd_chain_struct
*space_dict_root
;
549 static sd_chain_struct
*space_dict_last
;
551 /* The current space and subspace. */
552 static sd_chain_struct
*current_space
;
553 static ssd_chain_struct
*current_subspace
;
555 /* Root of the call_info chain. */
556 static struct call_info
*call_info_root
;
558 /* The last call_info (for functions) structure
559 seen so it can be associated with fixups and
561 static struct call_info
*last_call_info
;
563 /* The last call description (for actual calls). */
564 static struct call_desc last_call_desc
;
566 /* Jumps are always the same size -- one instruction. */
567 int md_short_jump_size
= 4;
568 int md_long_jump_size
= 4;
570 /* handle of the OPCODE hash table */
571 static struct hash_control
*op_hash
= NULL
;
573 /* This array holds the chars that always start a comment. If the
574 pre-processor is disabled, these aren't very useful. */
575 const char comment_chars
[] = ";";
577 /* Table of pseudo ops for the PA. FIXME -- how many of these
578 are now redundant with the overall GAS and the object file
580 const pseudo_typeS md_pseudo_table
[] =
582 /* align pseudo-ops on the PA specify the actual alignment requested,
583 not the log2 of the requested alignment. */
584 {"align", pa_align
, 8},
585 {"block", pa_block
, 1},
586 {"blockz", pa_block
, 0},
587 {"byte", pa_cons
, 1},
588 {"call", pa_call
, 0},
589 {"callinfo", pa_callinfo
, 0},
590 {"code", pa_code
, 0},
591 {"comm", pa_comm
, 0},
592 {"copyright", pa_copyright
, 0},
593 {"data", pa_data
, 0},
594 {"double", pa_float_cons
, 'd'},
596 {"enter", pa_enter
, 0},
597 {"entry", pa_entry
, 0},
599 {"exit", pa_exit
, 0},
600 {"export", pa_export
, 0},
601 {"fill", pa_fill
, 0},
602 {"float", pa_float_cons
, 'f'},
603 {"half", pa_cons
, 2},
604 {"import", pa_import
, 0},
606 {"label", pa_label
, 0},
607 {"lcomm", pa_lcomm
, 0},
608 {"leave", pa_leave
, 0},
609 {"long", pa_cons
, 4},
610 {"lsym", pa_lsym
, 0},
611 {"octa", pa_cons
, 16},
612 {"org", pa_origin
, 0},
613 {"origin", pa_origin
, 0},
614 {"param", pa_param
, 0},
615 {"proc", pa_proc
, 0},
616 {"procend", pa_procend
, 0},
617 {"quad", pa_cons
, 8},
619 {"short", pa_cons
, 2},
620 {"single", pa_float_cons
, 'f'},
621 {"space", pa_space
, 0},
622 {"spnum", pa_spnum
, 0},
623 {"string", pa_stringer
, 0},
624 {"stringz", pa_stringer
, 1},
625 {"subspa", pa_subspace
, 0},
626 {"text", pa_text
, 0},
627 {"version", pa_version
, 0},
628 {"word", pa_cons
, 4},
632 /* This array holds the chars that only start a comment at the beginning of
633 a line. If the line seems to have the form '# 123 filename'
634 .line and .file directives will appear in the pre-processed output.
636 Note that input_file.c hand checks for '#' at the beginning of the
637 first line of the input file. This is because the compiler outputs
638 #NO_APP at the beginning of its output.
640 Also note that '/*' will always start a comment. */
641 const char line_comment_chars
[] = "#";
643 /* This array holds the characters which act as line separators. */
644 const char line_separator_chars
[] = "!";
646 /* Chars that can be used to separate mant from exp in floating point nums. */
647 const char EXP_CHARS
[] = "eE";
649 /* Chars that mean this number is a floating point constant.
650 As in 0f12.456 or 0d1.2345e12.
652 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
653 changed in read.c. Ideally it shouldn't hae to know abou it at
654 all, but nothing is ideal around here. */
655 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
657 static struct pa_it the_insn
;
659 /* Points to the end of an expression just parsed by get_expressoin
660 and friends. FIXME. This shouldn't be handled with a file-global
662 static char *expr_end
;
664 /* Nonzero if a .callinfo appeared within the current procedure. */
665 static int callinfo_found
;
667 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
668 static int within_entry_exit
;
670 /* Nonzero if the assembler is currently within a procedure definition. */
671 static int within_procedure
;
673 /* Handle on strucutre which keep track of the last symbol
674 seen in each subspace. */
675 static label_symbol_struct
*label_symbols_rootp
= NULL
;
677 /* Holds the last field selector. */
678 static int hppa_field_selector
;
680 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
681 static symbolS
*dummy_symbol
;
683 /* Nonzero if errors are to be printed. */
684 static int print_errors
= 1;
686 /* List of registers that are pre-defined:
688 Each general register has one predefined name of the form
689 %r<REGNUM> which has the value <REGNUM>.
691 Space and control registers are handled in a similar manner,
692 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
694 Likewise for the floating point registers, but of the form
695 %fr<REGNUM>. Floating point registers have additional predefined
696 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
697 again have the value <REGNUM>.
699 Many registers also have synonyms:
701 %r26 - %r23 have %arg0 - %arg3 as synonyms
702 %r28 - %r29 have %ret0 - %ret1 as synonyms
703 %r30 has %sp as a synonym
704 %r27 has %dp as a synonym
705 %r2 has %rp as a synonym
707 Almost every control register has a synonym; they are not listed
710 The table is sorted. Suitable for searching by a binary search. */
712 static const struct pd_reg pre_defined_registers
[] =
912 /* This table is sorted by order of the length of the string. This is
913 so we check for <> before we check for <. If we had a <> and checked
914 for < first, we would get a false match. */
915 static const struct fp_cond_map fp_cond_map
[] =
951 static const struct selector_entry selector_table
[] =
970 /* default space and subspace dictionaries */
972 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
973 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
975 /* pre-defined subsegments (subspaces) for the HPPA. */
976 #define SUBSEG_CODE 0
977 #define SUBSEG_DATA 0
980 #define SUBSEG_UNWIND 3
981 #define SUBSEG_GDB_STRINGS 0
982 #define SUBSEG_GDB_SYMBOLS 1
984 static struct default_subspace_dict pa_def_subspaces
[] =
986 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
987 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
988 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
989 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
991 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
993 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
996 static struct default_space_dict pa_def_spaces
[] =
998 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
999 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1000 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1003 /* Misc local definitions used by the assembler. */
1005 /* Return nonzero if the string pointed to by S potentially represents
1006 a right or left half of a FP register */
1007 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1008 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1010 /* These macros are used to maintain spaces/subspaces. */
1011 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1012 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1013 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1014 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1016 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1017 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1019 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1020 main loop after insertion. */
1022 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1024 ((OPCODE) |= (FIELD) << (START)); \
1028 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1029 IGNORE is used to suppress the error message. */
1031 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1033 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1036 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1042 #define is_DP_relative(exp) \
1043 ((exp).X_op == O_subtract \
1044 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1046 #define is_PC_relative(exp) \
1047 ((exp).X_op == O_subtract \
1048 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1050 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1051 always be able to reduce the expression to a constant, so we don't
1052 need real complex handling yet. */
1053 #define is_complex(exp) \
1054 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1056 /* Actual functions to implement the PA specific code for the assembler. */
1058 /* Called before writing the object file. Make sure entry/exit and
1059 proc/procend pairs match. */
1064 if (within_entry_exit
)
1065 as_fatal ("Missing .exit\n");
1067 if (within_procedure
)
1068 as_fatal ("Missing .procend\n");
1071 /* Check to make sure we have a valid space and subspace. */
1074 pa_check_current_space_and_subspace ()
1076 if (current_space
== NULL
)
1077 as_fatal ("Not in a space.\n");
1079 if (current_subspace
== NULL
)
1080 as_fatal ("Not in a subspace.\n");
1083 /* Returns a pointer to the label_symbol_struct for the current space.
1084 or NULL if no label_symbol_struct exists for the current space. */
1086 static label_symbol_struct
*
1089 label_symbol_struct
*label_chain
;
1090 sd_chain_struct
*space_chain
= current_space
;
1092 for (label_chain
= label_symbols_rootp
;
1094 label_chain
= label_chain
->lss_next
)
1095 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1101 /* Defines a label for the current space. If one is already defined,
1102 this function will replace it with the new label. */
1105 pa_define_label (symbol
)
1108 label_symbol_struct
*label_chain
= pa_get_label ();
1109 sd_chain_struct
*space_chain
= current_space
;
1112 label_chain
->lss_label
= symbol
;
1115 /* Create a new label entry and add it to the head of the chain. */
1117 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1118 label_chain
->lss_label
= symbol
;
1119 label_chain
->lss_space
= space_chain
;
1120 label_chain
->lss_next
= NULL
;
1122 if (label_symbols_rootp
)
1123 label_chain
->lss_next
= label_symbols_rootp
;
1125 label_symbols_rootp
= label_chain
;
1129 /* Removes a label definition for the current space.
1130 If there is no label_symbol_struct entry, then no action is taken. */
1133 pa_undefine_label ()
1135 label_symbol_struct
*label_chain
;
1136 label_symbol_struct
*prev_label_chain
= NULL
;
1137 sd_chain_struct
*space_chain
= current_space
;
1139 for (label_chain
= label_symbols_rootp
;
1141 label_chain
= label_chain
->lss_next
)
1143 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1145 /* Remove the label from the chain and free its memory. */
1146 if (prev_label_chain
)
1147 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1149 label_symbols_rootp
= label_chain
->lss_next
;
1154 prev_label_chain
= label_chain
;
1159 /* An HPPA-specific version of fix_new. This is required because the HPPA
1160 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1161 results in the creation of an instance of an hppa_fix_struct. An
1162 hppa_fix_struct stores the extra information along with a pointer to the
1163 original fixS. This is attached to the original fixup via the
1164 tc_fix_data field. */
1167 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1168 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1172 symbolS
*add_symbol
;
1176 bfd_reloc_code_real_type r_type
;
1177 enum hppa_reloc_field_selector_type r_field
;
1184 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1185 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1188 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1190 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1191 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1192 hppa_fix
->fx_r_type
= r_type
;
1193 hppa_fix
->fx_r_field
= r_field
;
1194 hppa_fix
->fx_r_format
= r_format
;
1195 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1196 hppa_fix
->segment
= now_seg
;
1198 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1199 new_fix
->fx_offset
= *unwind_bits
;
1202 /* foo-$global$ is used to access non-automatic storage. $global$
1203 is really just a marker and has served its purpose, so eliminate
1204 it now so as not to confuse write.c. */
1205 if (new_fix
->fx_subsy
1206 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1207 new_fix
->fx_subsy
= NULL
;
1210 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1211 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1214 parse_cons_expression_hppa (exp
)
1217 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1221 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1222 hppa_field_selector is set by the parse_cons_expression_hppa. */
1225 cons_fix_new_hppa (frag
, where
, size
, exp
)
1231 unsigned int rel_type
;
1233 /* Get a base relocation type. */
1234 if (is_DP_relative (*exp
))
1235 rel_type
= R_HPPA_GOTOFF
;
1236 else if (is_complex (*exp
))
1237 rel_type
= R_HPPA_COMPLEX
;
1241 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1242 as_warn ("Invalid field selector. Assuming F%%.");
1244 fix_new_hppa (frag
, where
, size
,
1245 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1246 hppa_field_selector
, 32, 0, NULL
);
1248 /* Reset field selector to its default state. */
1249 hppa_field_selector
= 0;
1252 /* This function is called once, at assembler startup time. It should
1253 set up all the tables, etc. that the MD part of the assembler will need. */
1258 const char *retval
= NULL
;
1262 last_call_info
= NULL
;
1263 call_info_root
= NULL
;
1265 /* Set the default machine type. */
1266 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1267 as_warn ("could not set architecture and machine");
1269 /* Folding of text and data segments fails miserably on the PA.
1270 Warn user and disable "-R" option. */
1271 if (flag_readonly_data_in_text
)
1273 as_warn ("-R option not supported on this target.");
1274 flag_readonly_data_in_text
= 0;
1279 op_hash
= hash_new ();
1281 while (i
< NUMOPCODES
)
1283 const char *name
= pa_opcodes
[i
].name
;
1284 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1285 if (retval
!= NULL
&& *retval
!= '\0')
1287 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1292 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1293 != pa_opcodes
[i
].match
)
1295 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1296 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1301 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1305 as_fatal ("Broken assembler. No assembly attempted.");
1307 /* SOM will change text_section. To make sure we never put
1308 anything into the old one switch to the new one now. */
1309 subseg_set (text_section
, 0);
1311 dummy_symbol
= symbol_find_or_make ("L$dummy");
1312 S_SET_SEGMENT (dummy_symbol
, text_section
);
1315 /* Assemble a single instruction storing it into a frag. */
1322 /* The had better be something to assemble. */
1325 /* If we are within a procedure definition, make sure we've
1326 defined a label for the procedure; handle case where the
1327 label was defined after the .PROC directive.
1329 Note there's not need to diddle with the segment or fragment
1330 for the label symbol in this case. We have already switched
1331 into the new $CODE$ subspace at this point. */
1332 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1334 label_symbol_struct
*label_symbol
= pa_get_label ();
1338 if (label_symbol
->lss_label
)
1340 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1341 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1343 /* Also handle allocation of a fixup to hold the unwind
1344 information when the label appears after the proc/procend. */
1345 if (within_entry_exit
)
1347 char *where
= frag_more (0);
1349 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1350 NULL
, (offsetT
) 0, NULL
,
1351 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1352 (int *)&last_call_info
->ci_unwind
.descriptor
);
1357 as_bad ("Missing function name for .PROC (corrupted label chain)");
1360 as_bad ("Missing function name for .PROC");
1363 /* Assemble the instruction. Results are saved into "the_insn". */
1366 /* Get somewhere to put the assembled instrution. */
1369 /* Output the opcode. */
1370 md_number_to_chars (to
, the_insn
.opcode
, 4);
1372 /* If necessary output more stuff. */
1373 if (the_insn
.reloc
!= R_HPPA_NONE
)
1374 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1375 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1376 the_insn
.reloc
, the_insn
.field_selector
,
1377 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1380 /* Do the real work for assembling a single instruction. Store results
1381 into the global "the_insn" variable. */
1387 char *error_message
= "";
1388 char *s
, c
, *argstart
, *name
, *save_s
;
1392 int cmpltr
, nullif
, flag
, cond
, num
;
1393 unsigned long opcode
;
1394 struct pa_opcode
*insn
;
1396 /* We must have a valid space and subspace. */
1397 pa_check_current_space_and_subspace ();
1399 /* Skip to something interesting. */
1400 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1419 as_fatal ("Unknown opcode: `%s'", str
);
1424 /* Convert everything into lower case. */
1427 if (isupper (*save_s
))
1428 *save_s
= tolower (*save_s
);
1432 /* Look up the opcode in the has table. */
1433 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1435 as_bad ("Unknown opcode: `%s'", str
);
1444 /* Mark the location where arguments for the instruction start, then
1445 start processing them. */
1449 /* Do some initialization. */
1450 opcode
= insn
->match
;
1451 bzero (&the_insn
, sizeof (the_insn
));
1453 the_insn
.reloc
= R_HPPA_NONE
;
1455 /* If this instruction is specific to a particular architecture,
1456 then set a new architecture. */
1457 if (bfd_get_mach (stdoutput
) < insn
->arch
)
1459 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1460 as_warn ("could not update architecture and machine");
1463 /* Build the opcode, checking as we go to make
1464 sure that the operands match. */
1465 for (args
= insn
->args
;; ++args
)
1470 /* End of arguments. */
1486 /* These must match exactly. */
1495 /* Handle a 5 bit register or control register field at 10. */
1498 num
= pa_parse_number (&s
, 0);
1499 CHECK_FIELD (num
, 31, 0, 0);
1500 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1502 /* Handle a 5 bit register field at 15. */
1504 num
= pa_parse_number (&s
, 0);
1505 CHECK_FIELD (num
, 31, 0, 0);
1506 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1508 /* Handle a 5 bit register field at 31. */
1511 num
= pa_parse_number (&s
, 0);
1512 CHECK_FIELD (num
, 31, 0, 0);
1513 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1515 /* Handle a 5 bit field length at 31. */
1517 num
= pa_get_absolute_expression (&the_insn
, &s
);
1519 CHECK_FIELD (num
, 32, 1, 0);
1520 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1522 /* Handle a 5 bit immediate at 15. */
1524 num
= pa_get_absolute_expression (&the_insn
, &s
);
1526 CHECK_FIELD (num
, 15, -16, 0);
1527 low_sign_unext (num
, 5, &num
);
1528 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1530 /* Handle a 5 bit immediate at 31. */
1532 num
= pa_get_absolute_expression (&the_insn
, &s
);
1534 CHECK_FIELD (num
, 15, -16, 0)
1535 low_sign_unext (num
, 5, &num
);
1536 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1538 /* Handle an unsigned 5 bit immediate at 31. */
1540 num
= pa_get_absolute_expression (&the_insn
, &s
);
1542 CHECK_FIELD (num
, 31, 0, 0);
1543 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1545 /* Handle an unsigned 5 bit immediate at 15. */
1547 num
= pa_get_absolute_expression (&the_insn
, &s
);
1549 CHECK_FIELD (num
, 31, 0, 0);
1550 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1552 /* Handle a 2 bit space identifier at 17. */
1554 num
= pa_parse_number (&s
, 0);
1555 CHECK_FIELD (num
, 3, 0, 1);
1556 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1558 /* Handle a 3 bit space identifier at 18. */
1560 num
= pa_parse_number (&s
, 0);
1561 CHECK_FIELD (num
, 7, 0, 1);
1562 dis_assemble_3 (num
, &num
);
1563 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1565 /* Handle a completer for an indexing load or store. */
1571 while (*s
== ',' && i
< 2)
1574 if (strncasecmp (s
, "sm", 2) == 0)
1581 else if (strncasecmp (s
, "m", 1) == 0)
1583 else if (strncasecmp (s
, "s", 1) == 0)
1586 as_bad ("Invalid Indexed Load Completer.");
1591 as_bad ("Invalid Indexed Load Completer Syntax.");
1593 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1596 /* Handle a short load/store completer. */
1604 if (strncasecmp (s
, "ma", 2) == 0)
1609 else if (strncasecmp (s
, "mb", 2) == 0)
1615 as_bad ("Invalid Short Load/Store Completer.");
1619 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1622 /* Handle a stbys completer. */
1628 while (*s
== ',' && i
< 2)
1631 if (strncasecmp (s
, "m", 1) == 0)
1633 else if (strncasecmp (s
, "b", 1) == 0)
1635 else if (strncasecmp (s
, "e", 1) == 0)
1638 as_bad ("Invalid Store Bytes Short Completer");
1643 as_bad ("Invalid Store Bytes Short Completer");
1645 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1648 /* Handle a non-negated compare/stubtract condition. */
1650 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1653 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1656 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1658 /* Handle a negated or non-negated compare/subtract condition. */
1661 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1665 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1668 as_bad ("Invalid Compare/Subtract Condition.");
1673 /* Negated condition requires an opcode change. */
1677 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1679 /* Handle non-negated add condition. */
1681 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1684 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1687 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1689 /* Handle a negated or non-negated add condition. */
1692 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1696 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1699 as_bad ("Invalid Compare/Subtract Condition");
1704 /* Negated condition requires an opcode change. */
1708 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1710 /* Handle a compare/subtract condition. */
1717 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1722 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1725 as_bad ("Invalid Compare/Subtract Condition");
1729 opcode
|= cmpltr
<< 13;
1730 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1732 /* Handle a non-negated add condition. */
1741 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1745 if (strcmp (name
, "=") == 0)
1747 else if (strcmp (name
, "<") == 0)
1749 else if (strcmp (name
, "<=") == 0)
1751 else if (strcasecmp (name
, "nuv") == 0)
1753 else if (strcasecmp (name
, "znv") == 0)
1755 else if (strcasecmp (name
, "sv") == 0)
1757 else if (strcasecmp (name
, "od") == 0)
1759 else if (strcasecmp (name
, "n") == 0)
1761 else if (strcasecmp (name
, "tr") == 0)
1766 else if (strcmp (name
, "<>") == 0)
1771 else if (strcmp (name
, ">=") == 0)
1776 else if (strcmp (name
, ">") == 0)
1781 else if (strcasecmp (name
, "uv") == 0)
1786 else if (strcasecmp (name
, "vnz") == 0)
1791 else if (strcasecmp (name
, "nsv") == 0)
1796 else if (strcasecmp (name
, "ev") == 0)
1802 as_bad ("Invalid Add Condition: %s", name
);
1805 nullif
= pa_parse_nullif (&s
);
1806 opcode
|= nullif
<< 1;
1807 opcode
|= cmpltr
<< 13;
1808 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1810 /* HANDLE a logical instruction condition. */
1818 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1822 if (strcmp (name
, "=") == 0)
1824 else if (strcmp (name
, "<") == 0)
1826 else if (strcmp (name
, "<=") == 0)
1828 else if (strcasecmp (name
, "od") == 0)
1830 else if (strcasecmp (name
, "tr") == 0)
1835 else if (strcmp (name
, "<>") == 0)
1840 else if (strcmp (name
, ">=") == 0)
1845 else if (strcmp (name
, ">") == 0)
1850 else if (strcasecmp (name
, "ev") == 0)
1856 as_bad ("Invalid Logical Instruction Condition.");
1859 opcode
|= cmpltr
<< 13;
1860 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1862 /* Handle a unit instruction condition. */
1869 if (strncasecmp (s
, "sbz", 3) == 0)
1874 else if (strncasecmp (s
, "shz", 3) == 0)
1879 else if (strncasecmp (s
, "sdc", 3) == 0)
1884 else if (strncasecmp (s
, "sbc", 3) == 0)
1889 else if (strncasecmp (s
, "shc", 3) == 0)
1894 else if (strncasecmp (s
, "tr", 2) == 0)
1900 else if (strncasecmp (s
, "nbz", 3) == 0)
1906 else if (strncasecmp (s
, "nhz", 3) == 0)
1912 else if (strncasecmp (s
, "ndc", 3) == 0)
1918 else if (strncasecmp (s
, "nbc", 3) == 0)
1924 else if (strncasecmp (s
, "nhc", 3) == 0)
1931 as_bad ("Invalid Logical Instruction Condition.");
1933 opcode
|= cmpltr
<< 13;
1934 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1936 /* Handle a shift/extract/deposit condition. */
1944 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1948 if (strcmp (name
, "=") == 0)
1950 else if (strcmp (name
, "<") == 0)
1952 else if (strcasecmp (name
, "od") == 0)
1954 else if (strcasecmp (name
, "tr") == 0)
1956 else if (strcmp (name
, "<>") == 0)
1958 else if (strcmp (name
, ">=") == 0)
1960 else if (strcasecmp (name
, "ev") == 0)
1962 /* Handle movb,n. Put things back the way they were.
1963 This includes moving s back to where it started. */
1964 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1971 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1974 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1976 /* Handle bvb and bb conditions. */
1982 if (strncmp (s
, "<", 1) == 0)
1987 else if (strncmp (s
, ">=", 2) == 0)
1993 as_bad ("Invalid Bit Branch Condition: %c", *s
);
1995 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1997 /* Handle a system control completer. */
1999 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2007 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2009 /* Handle a nullification completer for branch instructions. */
2011 nullif
= pa_parse_nullif (&s
);
2012 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2014 /* Handle a nullification completer for copr and spop insns. */
2016 nullif
= pa_parse_nullif (&s
);
2017 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2019 /* Handle a 11 bit immediate at 31. */
2021 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2024 if (the_insn
.exp
.X_op
== O_constant
)
2026 num
= evaluate_absolute (&the_insn
);
2027 CHECK_FIELD (num
, 1023, -1024, 0);
2028 low_sign_unext (num
, 11, &num
);
2029 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2033 if (is_DP_relative (the_insn
.exp
))
2034 the_insn
.reloc
= R_HPPA_GOTOFF
;
2035 else if (is_PC_relative (the_insn
.exp
))
2036 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2038 the_insn
.reloc
= R_HPPA
;
2039 the_insn
.format
= 11;
2043 /* Handle a 14 bit immediate at 31. */
2045 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2048 if (the_insn
.exp
.X_op
== O_constant
)
2050 num
= evaluate_absolute (&the_insn
);
2051 CHECK_FIELD (num
, 8191, -8192, 0);
2052 low_sign_unext (num
, 14, &num
);
2053 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2057 if (is_DP_relative (the_insn
.exp
))
2058 the_insn
.reloc
= R_HPPA_GOTOFF
;
2059 else if (is_PC_relative (the_insn
.exp
))
2060 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2062 the_insn
.reloc
= R_HPPA
;
2063 the_insn
.format
= 14;
2067 /* Handle a 21 bit immediate at 31. */
2069 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2072 if (the_insn
.exp
.X_op
== O_constant
)
2074 num
= evaluate_absolute (&the_insn
);
2075 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2076 dis_assemble_21 (num
, &num
);
2077 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2081 if (is_DP_relative (the_insn
.exp
))
2082 the_insn
.reloc
= R_HPPA_GOTOFF
;
2083 else if (is_PC_relative (the_insn
.exp
))
2084 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2086 the_insn
.reloc
= R_HPPA
;
2087 the_insn
.format
= 21;
2091 /* Handle a 12 bit branch displacement. */
2093 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2097 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2099 unsigned int w1
, w
, result
;
2101 num
= evaluate_absolute (&the_insn
);
2104 as_bad ("Branch to unaligned address");
2107 CHECK_FIELD (num
, 8191, -8192, 0);
2108 sign_unext ((num
- 8) >> 2, 12, &result
);
2109 dis_assemble_12 (result
, &w1
, &w
);
2110 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2114 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2115 the_insn
.format
= 12;
2116 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2117 bzero (&last_call_desc
, sizeof (struct call_desc
));
2122 /* Handle a 17 bit branch displacement. */
2124 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2128 if (!the_insn
.exp
.X_add_symbol
2129 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2132 unsigned int w2
, w1
, w
, result
;
2134 num
= evaluate_absolute (&the_insn
);
2137 as_bad ("Branch to unaligned address");
2140 CHECK_FIELD (num
, 262143, -262144, 0);
2142 if (the_insn
.exp
.X_add_symbol
)
2145 sign_unext (num
>> 2, 17, &result
);
2146 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2147 INSERT_FIELD_AND_CONTINUE (opcode
,
2148 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2152 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2153 the_insn
.format
= 17;
2154 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2155 bzero (&last_call_desc
, sizeof (struct call_desc
));
2159 /* Handle an absolute 17 bit branch target. */
2161 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2165 if (!the_insn
.exp
.X_add_symbol
2166 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2169 unsigned int w2
, w1
, w
, result
;
2171 num
= evaluate_absolute (&the_insn
);
2174 as_bad ("Branch to unaligned address");
2177 CHECK_FIELD (num
, 262143, -262144, 0);
2179 if (the_insn
.exp
.X_add_symbol
)
2182 sign_unext (num
>> 2, 17, &result
);
2183 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2184 INSERT_FIELD_AND_CONTINUE (opcode
,
2185 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2189 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2190 the_insn
.format
= 17;
2191 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2192 bzero (&last_call_desc
, sizeof (struct call_desc
));
2196 /* Handle a 5 bit shift count at 26. */
2198 num
= pa_get_absolute_expression (&the_insn
, &s
);
2200 CHECK_FIELD (num
, 31, 0, 0);
2201 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2203 /* Handle a 5 bit bit position at 26. */
2205 num
= pa_get_absolute_expression (&the_insn
, &s
);
2207 CHECK_FIELD (num
, 31, 0, 0);
2208 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2210 /* Handle a 5 bit immediate at 10. */
2212 num
= pa_get_absolute_expression (&the_insn
, &s
);
2214 CHECK_FIELD (num
, 31, 0, 0);
2215 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2217 /* Handle a 13 bit immediate at 18. */
2219 num
= pa_get_absolute_expression (&the_insn
, &s
);
2221 CHECK_FIELD (num
, 8191, 0, 0);
2222 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2224 /* Handle a 26 bit immediate at 31. */
2226 num
= pa_get_absolute_expression (&the_insn
, &s
);
2228 CHECK_FIELD (num
, 671108864, 0, 0);
2229 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2231 /* Handle a 3 bit SFU identifier at 25. */
2234 as_bad ("Invalid SFU identifier");
2235 num
= pa_get_absolute_expression (&the_insn
, &s
);
2237 CHECK_FIELD (num
, 7, 0, 0);
2238 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2240 /* Handle a 20 bit SOP field for spop0. */
2242 num
= pa_get_absolute_expression (&the_insn
, &s
);
2244 CHECK_FIELD (num
, 1048575, 0, 0);
2245 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2246 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2248 /* Handle a 15bit SOP field for spop1. */
2250 num
= pa_get_absolute_expression (&the_insn
, &s
);
2252 CHECK_FIELD (num
, 32767, 0, 0);
2253 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2255 /* Handle a 10bit SOP field for spop3. */
2257 num
= pa_get_absolute_expression (&the_insn
, &s
);
2259 CHECK_FIELD (num
, 1023, 0, 0);
2260 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2261 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2263 /* Handle a 15 bit SOP field for spop2. */
2265 num
= pa_get_absolute_expression (&the_insn
, &s
);
2267 CHECK_FIELD (num
, 32767, 0, 0);
2268 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2269 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2271 /* Handle a 3-bit co-processor ID field. */
2274 as_bad ("Invalid COPR identifier");
2275 num
= pa_get_absolute_expression (&the_insn
, &s
);
2277 CHECK_FIELD (num
, 7, 0, 0);
2278 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2280 /* Handle a 22bit SOP field for copr. */
2282 num
= pa_get_absolute_expression (&the_insn
, &s
);
2284 CHECK_FIELD (num
, 4194303, 0, 0);
2285 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2286 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2288 /* Handle a source FP operand format completer. */
2290 flag
= pa_parse_fp_format (&s
);
2291 the_insn
.fpof1
= flag
;
2292 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2294 /* Handle a destination FP operand format completer. */
2296 /* pa_parse_format needs the ',' prefix. */
2298 flag
= pa_parse_fp_format (&s
);
2299 the_insn
.fpof2
= flag
;
2300 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2302 /* Handle FP compare conditions. */
2304 cond
= pa_parse_fp_cmp_cond (&s
);
2305 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2307 /* Handle L/R register halves like 't'. */
2310 struct pa_11_fp_reg_struct result
;
2312 pa_parse_number (&s
, &result
);
2313 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2314 opcode
|= result
.number_part
;
2316 /* 0x30 opcodes are FP arithmetic operation opcodes
2317 and need to be turned into 0x38 opcodes. This
2318 is not necessary for loads/stores. */
2319 if (need_pa11_opcode (&the_insn
, &result
)
2320 && ((opcode
& 0xfc000000) == 0x30000000))
2323 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2326 /* Handle L/R register halves like 'b'. */
2329 struct pa_11_fp_reg_struct result
;
2331 pa_parse_number (&s
, &result
);
2332 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2333 opcode
|= result
.number_part
<< 21;
2334 if (need_pa11_opcode (&the_insn
, &result
))
2336 opcode
|= (result
.l_r_select
& 1) << 7;
2342 /* Handle L/R register halves like 'x'. */
2345 struct pa_11_fp_reg_struct result
;
2347 pa_parse_number (&s
, &result
);
2348 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2349 opcode
|= (result
.number_part
& 0x1f) << 16;
2350 if (need_pa11_opcode (&the_insn
, &result
))
2352 opcode
|= (result
.l_r_select
& 1) << 12;
2358 /* Handle a 5 bit register field at 10. */
2361 struct pa_11_fp_reg_struct result
;
2363 pa_parse_number (&s
, &result
);
2364 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2365 if (the_insn
.fpof1
== SGL
)
2367 if (result
.number_part
< 16)
2369 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2373 result
.number_part
&= 0xF;
2374 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2376 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2379 /* Handle a 5 bit register field at 15. */
2382 struct pa_11_fp_reg_struct result
;
2384 pa_parse_number (&s
, &result
);
2385 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2386 if (the_insn
.fpof1
== SGL
)
2388 if (result
.number_part
< 16)
2390 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2393 result
.number_part
&= 0xF;
2394 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2396 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2399 /* Handle a 5 bit register field at 31. */
2402 struct pa_11_fp_reg_struct result
;
2404 pa_parse_number (&s
, &result
);
2405 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2406 if (the_insn
.fpof1
== SGL
)
2408 if (result
.number_part
< 16)
2410 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2413 result
.number_part
&= 0xF;
2414 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2416 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2419 /* Handle a 5 bit register field at 20. */
2422 struct pa_11_fp_reg_struct result
;
2424 pa_parse_number (&s
, &result
);
2425 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2426 if (the_insn
.fpof1
== SGL
)
2428 if (result
.number_part
< 16)
2430 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2433 result
.number_part
&= 0xF;
2434 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2436 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2439 /* Handle a 5 bit register field at 25. */
2442 struct pa_11_fp_reg_struct result
;
2444 pa_parse_number (&s
, &result
);
2445 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2446 if (the_insn
.fpof1
== SGL
)
2448 if (result
.number_part
< 16)
2450 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2453 result
.number_part
&= 0xF;
2454 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2456 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2459 /* Handle a floating point operand format at 26.
2460 Only allows single and double precision. */
2462 flag
= pa_parse_fp_format (&s
);
2468 the_insn
.fpof1
= flag
;
2474 as_bad ("Invalid Floating Point Operand Format.");
2484 /* Check if the args matched. */
2487 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2488 && !strcmp (insn
->name
, insn
[1].name
))
2496 as_bad ("Invalid operands %s", error_message
);
2503 the_insn
.opcode
= opcode
;
2506 /* Turn a string in input_line_pointer into a floating point constant of type
2507 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2508 emitted is stored in *sizeP . An error message or NULL is returned. */
2510 #define MAX_LITTLENUMS 6
2513 md_atof (type
, litP
, sizeP
)
2519 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2520 LITTLENUM_TYPE
*wordP
;
2552 return "Bad call to MD_ATOF()";
2554 t
= atof_ieee (input_line_pointer
, type
, words
);
2556 input_line_pointer
= t
;
2557 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2558 for (wordP
= words
; prec
--;)
2560 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2561 litP
+= sizeof (LITTLENUM_TYPE
);
2566 /* Write out big-endian. */
2569 md_number_to_chars (buf
, val
, n
)
2574 number_to_chars_bigendian (buf
, val
, n
);
2577 /* Translate internal representation of relocation info to BFD target
2581 tc_gen_reloc (section
, fixp
)
2586 struct hppa_fix_struct
*hppa_fixp
;
2587 bfd_reloc_code_real_type code
;
2588 static arelent
*no_relocs
= NULL
;
2590 bfd_reloc_code_real_type
**codes
;
2594 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2595 if (fixp
->fx_addsy
== 0)
2597 assert (hppa_fixp
!= 0);
2598 assert (section
!= 0);
2600 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2601 assert (reloc
!= 0);
2603 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2604 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2606 hppa_fixp
->fx_r_format
,
2607 hppa_fixp
->fx_r_field
);
2609 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2612 relocs
= (arelent
**)
2613 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2614 assert (relocs
!= 0);
2616 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2617 sizeof (arelent
) * n_relocs
);
2619 assert (reloc
!= 0);
2621 for (i
= 0; i
< n_relocs
; i
++)
2622 relocs
[i
] = &reloc
[i
];
2624 relocs
[n_relocs
] = NULL
;
2627 switch (fixp
->fx_r_type
)
2630 assert (n_relocs
== 1);
2634 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2635 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2636 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2637 reloc
->addend
= 0; /* default */
2639 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2641 /* Now, do any processing that is dependent on the relocation type. */
2644 case R_PARISC_DLTREL21L
:
2645 case R_PARISC_DLTREL14R
:
2646 case R_PARISC_DLTREL14F
:
2647 case R_PARISC_PLABEL32
:
2648 case R_PARISC_PLABEL21L
:
2649 case R_PARISC_PLABEL14R
:
2650 /* For plabel relocations, the addend of the
2651 relocation should be either 0 (no static link) or 2
2652 (static link required).
2654 FIXME: We always assume no static link!
2656 We also slam a zero addend into the DLT relative relocs;
2657 it doesn't make a lot of sense to use any addend since
2658 it gets you a different (eg unknown) DLT entry. */
2662 case R_PARISC_PCREL21L
:
2663 case R_PARISC_PCREL17R
:
2664 case R_PARISC_PCREL17F
:
2665 case R_PARISC_PCREL17C
:
2666 case R_PARISC_PCREL14R
:
2667 case R_PARISC_PCREL14F
:
2668 /* The constant is stored in the instruction. */
2669 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2672 reloc
->addend
= fixp
->fx_offset
;
2679 /* Walk over reach relocation returned by the BFD backend. */
2680 for (i
= 0; i
< n_relocs
; i
++)
2684 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2685 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2686 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2692 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2698 /* For plabel relocations, the addend of the
2699 relocation should be either 0 (no static link) or 2
2700 (static link required).
2702 FIXME: We always assume no static link!
2704 We also slam a zero addend into the DLT relative relocs;
2705 it doesn't make a lot of sense to use any addend since
2706 it gets you a different (eg unknown) DLT entry. */
2707 relocs
[i
]->addend
= 0;
2717 /* There is no symbol or addend associated with these fixups. */
2718 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2719 relocs
[i
]->addend
= 0;
2724 /* There is no symbol associated with these fixups. */
2725 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2726 relocs
[i
]->addend
= fixp
->fx_offset
;
2730 relocs
[i
]->addend
= fixp
->fx_offset
;
2738 /* Process any machine dependent frag types. */
2741 md_convert_frag (abfd
, sec
, fragP
)
2743 register asection
*sec
;
2744 register fragS
*fragP
;
2746 unsigned int address
;
2748 if (fragP
->fr_type
== rs_machine_dependent
)
2750 switch ((int) fragP
->fr_subtype
)
2753 fragP
->fr_type
= rs_fill
;
2754 know (fragP
->fr_var
== 1);
2755 know (fragP
->fr_next
);
2756 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2757 if (address
% fragP
->fr_offset
)
2760 fragP
->fr_next
->fr_address
2765 fragP
->fr_offset
= 0;
2771 /* Round up a section size to the appropriate boundary. */
2774 md_section_align (segment
, size
)
2778 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2779 int align2
= (1 << align
) - 1;
2781 return (size
+ align2
) & ~align2
;
2784 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2786 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2788 addressT from_addr
, to_addr
;
2792 fprintf (stderr
, "pa_create_short_jmp\n");
2796 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2798 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2800 addressT from_addr
, to_addr
;
2804 fprintf (stderr
, "pa_create_long_jump\n");
2808 /* Return the approximate size of a frag before relaxation has occurred. */
2810 md_estimate_size_before_relax (fragP
, segment
)
2811 register fragS
*fragP
;
2818 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2824 CONST
char *md_shortopts
= "";
2825 struct option md_longopts
[] = {
2826 {NULL
, no_argument
, NULL
, 0}
2828 size_t md_longopts_size
= sizeof(md_longopts
);
2831 md_parse_option (c
, arg
)
2839 md_show_usage (stream
)
2844 /* We have no need to default values of symbols. */
2847 md_undefined_symbol (name
)
2853 /* Apply a fixup to an instruction. */
2856 md_apply_fix (fixP
, valp
)
2860 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2861 struct hppa_fix_struct
*hppa_fixP
;
2862 long new_val
, result
;
2863 unsigned int w1
, w2
, w
;
2865 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2866 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2867 never be "applied" (they are just markers). */
2869 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2870 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2874 /* There should have been an HPPA specific fixup associated
2875 with the GAS fixup. */
2878 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2879 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2881 /* If there is a symbol associated with this fixup, then it's something
2882 which will need a SOM relocation (except for some PC-relative relocs).
2883 In such cases we should treat the "val" or "addend" as zero since it
2884 will be added in as needed from fx_offset in tc_gen_reloc. */
2885 if ((fixP
->fx_addsy
!= NULL
2886 || fixP
->fx_r_type
== R_HPPA_NONE
)
2889 || hppa_fixP
->fx_r_field
== e_psel
2890 || hppa_fixP
->fx_r_field
== e_rpsel
2891 || hppa_fixP
->fx_r_field
== e_lpsel
2892 || hppa_fixP
->fx_r_field
== e_tsel
2893 || hppa_fixP
->fx_r_field
== e_rtsel
2894 || hppa_fixP
->fx_r_field
== e_ltsel
2897 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2899 /* This is truely disgusting. The machine independent code blindly
2900 adds in the value of the symbol being relocated against. Damn! */
2902 && fixP
->fx_addsy
!= NULL
2903 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
2904 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
2905 0, hppa_fixP
->fx_r_field
);
2908 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2910 /* Handle pc-relative exceptions from above. */
2911 #define arg_reloc_stub_needed(CALLER, CALLEE) \
2912 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2913 if ((fmt
== 12 || fmt
== 17)
2916 && !arg_reloc_stub_needed (((obj_symbol_type
*)
2917 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2918 hppa_fixP
->fx_arg_reloc
)
2919 && ((int)(*valp
) > -262144 && (int)(*valp
) < 262143)
2920 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
2922 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2924 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2925 #undef arg_reloc_stub_needed
2929 /* Handle all opcodes with the 'j' operand type. */
2931 CHECK_FIELD (new_val
, 8191, -8192, 0);
2933 /* Mask off 14 bits to be changed. */
2934 bfd_put_32 (stdoutput
,
2935 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2937 low_sign_unext (new_val
, 14, &result
);
2940 /* Handle all opcodes with the 'k' operand type. */
2942 CHECK_FIELD (new_val
, 2097152, 0, 0);
2944 /* Mask off 21 bits to be changed. */
2945 bfd_put_32 (stdoutput
,
2946 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2948 dis_assemble_21 (new_val
, &result
);
2951 /* Handle all the opcodes with the 'i' operand type. */
2953 CHECK_FIELD (new_val
, 1023, -1023, 0);
2955 /* Mask off 11 bits to be changed. */
2956 bfd_put_32 (stdoutput
,
2957 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2959 low_sign_unext (new_val
, 11, &result
);
2962 /* Handle all the opcodes with the 'w' operand type. */
2964 CHECK_FIELD (new_val
, 8191, -8192, 0)
2966 /* Mask off 11 bits to be changed. */
2967 sign_unext ((new_val
- 8) >> 2, 12, &result
);
2968 bfd_put_32 (stdoutput
,
2969 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
2972 dis_assemble_12 (result
, &w1
, &w
);
2973 result
= ((w1
<< 2) | w
);
2976 /* Handle some of the opcodes with the 'W' operand type. */
2978 CHECK_FIELD (new_val
, 262143, -262144, 0);
2980 /* Mask off 17 bits to be changed. */
2981 bfd_put_32 (stdoutput
,
2982 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
2984 sign_unext ((new_val
- 8) >> 2, 17, &result
);
2985 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2986 result
= ((w2
<< 2) | (w1
<< 16) | w
);
2991 bfd_put_32 (stdoutput
, new_val
, buf
);
2995 as_bad ("Unknown relocation encountered in md_apply_fix.");
2999 /* Insert the relocation. */
3000 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3005 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3006 (unsigned int) fixP
, fixP
->fx_r_type
);
3011 /* Exactly what point is a PC-relative offset relative TO?
3012 On the PA, they're relative to the address of the offset. */
3015 md_pcrel_from (fixP
)
3018 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3021 /* Return nonzero if the input line pointer is at the end of
3025 is_end_of_statement ()
3027 return ((*input_line_pointer
== '\n')
3028 || (*input_line_pointer
== ';')
3029 || (*input_line_pointer
== '!'));
3032 /* Read a number from S. The number might come in one of many forms,
3033 the most common will be a hex or decimal constant, but it could be
3034 a pre-defined register (Yuk!), or an absolute symbol.
3036 Return a number or -1 for failure.
3038 When parsing PA-89 FP register numbers RESULT will be
3039 the address of a structure to return information about
3040 L/R half of FP registers, store results there as appropriate.
3042 pa_parse_number can not handle negative constants and will fail
3043 horribly if it is passed such a constant. */
3046 pa_parse_number (s
, result
)
3048 struct pa_11_fp_reg_struct
*result
;
3057 /* Skip whitespace before the number. */
3058 while (*p
== ' ' || *p
== '\t')
3061 /* Store info in RESULT if requested by caller. */
3064 result
->number_part
= -1;
3065 result
->l_r_select
= -1;
3071 /* Looks like a number. */
3074 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3076 /* The number is specified in hex. */
3078 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3079 || ((*p
>= 'A') && (*p
<= 'F')))
3082 num
= num
* 16 + *p
- '0';
3083 else if (*p
>= 'a' && *p
<= 'f')
3084 num
= num
* 16 + *p
- 'a' + 10;
3086 num
= num
* 16 + *p
- 'A' + 10;
3092 /* The number is specified in decimal. */
3093 while (isdigit (*p
))
3095 num
= num
* 10 + *p
- '0';
3100 /* Store info in RESULT if requested by the caller. */
3103 result
->number_part
= num
;
3105 if (IS_R_SELECT (p
))
3107 result
->l_r_select
= 1;
3110 else if (IS_L_SELECT (p
))
3112 result
->l_r_select
= 0;
3116 result
->l_r_select
= 0;
3121 /* The number might be a predefined register. */
3126 /* Tege hack: Special case for general registers as the general
3127 code makes a binary search with case translation, and is VERY
3132 if (*p
== 'e' && *(p
+ 1) == 't'
3133 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3136 num
= *p
- '0' + 28;
3144 else if (!isdigit (*p
))
3147 as_bad ("Undefined register: '%s'.", name
);
3153 num
= num
* 10 + *p
++ - '0';
3154 while (isdigit (*p
));
3159 /* Do a normal register search. */
3160 while (is_part_of_name (c
))
3166 status
= reg_name_search (name
);
3172 as_bad ("Undefined register: '%s'.", name
);
3178 /* Store info in RESULT if requested by caller. */
3181 result
->number_part
= num
;
3182 if (IS_R_SELECT (p
- 1))
3183 result
->l_r_select
= 1;
3184 else if (IS_L_SELECT (p
- 1))
3185 result
->l_r_select
= 0;
3187 result
->l_r_select
= 0;
3192 /* And finally, it could be a symbol in the absolute section which
3193 is effectively a constant. */
3197 while (is_part_of_name (c
))
3203 if ((sym
= symbol_find (name
)) != NULL
)
3205 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3206 num
= S_GET_VALUE (sym
);
3210 as_bad ("Non-absolute symbol: '%s'.", name
);
3216 /* There is where we'd come for an undefined symbol
3217 or for an empty string. For an empty string we
3218 will return zero. That's a concession made for
3219 compatability with the braindamaged HP assemblers. */
3225 as_bad ("Undefined absolute constant: '%s'.", name
);
3231 /* Store info in RESULT if requested by caller. */
3234 result
->number_part
= num
;
3235 if (IS_R_SELECT (p
- 1))
3236 result
->l_r_select
= 1;
3237 else if (IS_L_SELECT (p
- 1))
3238 result
->l_r_select
= 0;
3240 result
->l_r_select
= 0;
3248 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3250 /* Given NAME, find the register number associated with that name, return
3251 the integer value associated with the given name or -1 on failure. */
3254 reg_name_search (name
)
3257 int middle
, low
, high
;
3261 high
= REG_NAME_CNT
- 1;
3265 middle
= (low
+ high
) / 2;
3266 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3272 return pre_defined_registers
[middle
].value
;
3274 while (low
<= high
);
3280 /* Return nonzero if the given INSN and L/R information will require
3281 a new PA-1.1 opcode. */
3284 need_pa11_opcode (insn
, result
)
3286 struct pa_11_fp_reg_struct
*result
;
3288 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3290 /* If this instruction is specific to a particular architecture,
3291 then set a new architecture. */
3292 if (bfd_get_mach (stdoutput
) < pa11
)
3294 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
3295 as_warn ("could not update architecture and machine");
3303 /* Parse a condition for a fcmp instruction. Return the numerical
3304 code associated with the condition. */
3307 pa_parse_fp_cmp_cond (s
)
3314 for (i
= 0; i
< 32; i
++)
3316 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3317 strlen (fp_cond_map
[i
].string
)) == 0)
3319 cond
= fp_cond_map
[i
].cond
;
3320 *s
+= strlen (fp_cond_map
[i
].string
);
3321 /* If not a complete match, back up the input string and
3323 if (**s
!= ' ' && **s
!= '\t')
3325 *s
-= strlen (fp_cond_map
[i
].string
);
3328 while (**s
== ' ' || **s
== '\t')
3334 as_bad ("Invalid FP Compare Condition: %s", *s
);
3336 /* Advance over the bogus completer. */
3337 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3343 /* Parse an FP operand format completer returning the completer
3346 static fp_operand_format
3347 pa_parse_fp_format (s
)
3356 if (strncasecmp (*s
, "sgl", 3) == 0)
3361 else if (strncasecmp (*s
, "dbl", 3) == 0)
3366 else if (strncasecmp (*s
, "quad", 4) == 0)
3373 format
= ILLEGAL_FMT
;
3374 as_bad ("Invalid FP Operand Format: %3s", *s
);
3381 /* Convert from a selector string into a selector type. */
3384 pa_chk_field_selector (str
)
3387 int middle
, low
, high
;
3391 /* Read past any whitespace. */
3392 /* FIXME: should we read past newlines and formfeeds??? */
3393 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3396 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3397 name
[0] = tolower ((*str
)[0]),
3399 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3400 name
[0] = tolower ((*str
)[0]),
3401 name
[1] = tolower ((*str
)[1]),
3407 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3411 middle
= (low
+ high
) / 2;
3412 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3419 *str
+= strlen (name
) + 1;
3420 return selector_table
[middle
].field_selector
;
3423 while (low
<= high
);
3428 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3431 get_expression (str
)
3437 save_in
= input_line_pointer
;
3438 input_line_pointer
= str
;
3439 seg
= expression (&the_insn
.exp
);
3440 if (!(seg
== absolute_section
3441 || seg
== undefined_section
3442 || SEG_NORMAL (seg
)))
3444 as_warn ("Bad segment in expression.");
3445 expr_end
= input_line_pointer
;
3446 input_line_pointer
= save_in
;
3449 expr_end
= input_line_pointer
;
3450 input_line_pointer
= save_in
;
3454 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3456 pa_get_absolute_expression (insn
, strp
)
3462 insn
->field_selector
= pa_chk_field_selector (strp
);
3463 save_in
= input_line_pointer
;
3464 input_line_pointer
= *strp
;
3465 expression (&insn
->exp
);
3466 if (insn
->exp
.X_op
!= O_constant
)
3468 as_bad ("Bad segment (should be absolute).");
3469 expr_end
= input_line_pointer
;
3470 input_line_pointer
= save_in
;
3473 expr_end
= input_line_pointer
;
3474 input_line_pointer
= save_in
;
3475 return evaluate_absolute (insn
);
3478 /* Evaluate an absolute expression EXP which may be modified by
3479 the selector FIELD_SELECTOR. Return the value of the expression. */
3481 evaluate_absolute (insn
)
3486 int field_selector
= insn
->field_selector
;
3489 value
= exp
.X_add_number
;
3491 switch (field_selector
)
3497 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3499 if (value
& 0x00000400)
3501 value
= (value
& 0xfffff800) >> 11;
3504 /* Sign extend from bit 21. */
3506 if (value
& 0x00000400)
3507 value
|= 0xfffff800;
3512 /* Arithmetic shift right 11 bits. */
3514 value
= (value
& 0xfffff800) >> 11;
3517 /* Set bits 0-20 to zero. */
3519 value
= value
& 0x7ff;
3522 /* Add 0x800 and arithmetic shift right 11 bits. */
3525 value
= (value
& 0xfffff800) >> 11;
3528 /* Set bitgs 0-21 to one. */
3530 value
|= 0xfffff800;
3533 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3535 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3539 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3544 BAD_CASE (field_selector
);
3550 /* Given an argument location specification return the associated
3551 argument location number. */
3554 pa_build_arg_reloc (type_name
)
3558 if (strncasecmp (type_name
, "no", 2) == 0)
3560 if (strncasecmp (type_name
, "gr", 2) == 0)
3562 else if (strncasecmp (type_name
, "fr", 2) == 0)
3564 else if (strncasecmp (type_name
, "fu", 2) == 0)
3567 as_bad ("Invalid argument location: %s\n", type_name
);
3572 /* Encode and return an argument relocation specification for
3573 the given register in the location specified by arg_reloc. */
3576 pa_align_arg_reloc (reg
, arg_reloc
)
3578 unsigned int arg_reloc
;
3580 unsigned int new_reloc
;
3582 new_reloc
= arg_reloc
;
3598 as_bad ("Invalid argument description: %d", reg
);
3604 /* Parse a PA nullification completer (,n). Return nonzero if the
3605 completer was found; return zero if no completer was found. */
3617 if (strncasecmp (*s
, "n", 1) == 0)
3621 as_bad ("Invalid Nullification: (%c)", **s
);
3630 /* Parse a non-negated compare/subtract completer returning the
3631 number (for encoding in instrutions) of the given completer.
3633 ISBRANCH specifies whether or not this is parsing a condition
3634 completer for a branch (vs a nullification completer for a
3635 computational instruction. */
3638 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3643 char *name
= *s
+ 1;
3651 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3655 if (strcmp (name
, "=") == 0)
3659 else if (strcmp (name
, "<") == 0)
3663 else if (strcmp (name
, "<=") == 0)
3667 else if (strcmp (name
, "<<") == 0)
3671 else if (strcmp (name
, "<<=") == 0)
3675 else if (strcasecmp (name
, "sv") == 0)
3679 else if (strcasecmp (name
, "od") == 0)
3683 /* If we have something like addb,n then there is no condition
3685 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3696 /* Reset pointers if this was really a ,n for a branch instruction. */
3697 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3703 /* Parse a negated compare/subtract completer returning the
3704 number (for encoding in instrutions) of the given completer.
3706 ISBRANCH specifies whether or not this is parsing a condition
3707 completer for a branch (vs a nullification completer for a
3708 computational instruction. */
3711 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3716 char *name
= *s
+ 1;
3724 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3728 if (strcasecmp (name
, "tr") == 0)
3732 else if (strcmp (name
, "<>") == 0)
3736 else if (strcmp (name
, ">=") == 0)
3740 else if (strcmp (name
, ">") == 0)
3744 else if (strcmp (name
, ">>=") == 0)
3748 else if (strcmp (name
, ">>") == 0)
3752 else if (strcasecmp (name
, "nsv") == 0)
3756 else if (strcasecmp (name
, "ev") == 0)
3760 /* If we have something like addb,n then there is no condition
3762 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3773 /* Reset pointers if this was really a ,n for a branch instruction. */
3774 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3780 /* Parse a non-negated addition completer returning the number
3781 (for encoding in instrutions) of the given completer.
3783 ISBRANCH specifies whether or not this is parsing a condition
3784 completer for a branch (vs a nullification completer for a
3785 computational instruction. */
3788 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3793 char *name
= *s
+ 1;
3801 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3805 if (strcmp (name
, "=") == 0)
3809 else if (strcmp (name
, "<") == 0)
3813 else if (strcmp (name
, "<=") == 0)
3817 else if (strcasecmp (name
, "nuv") == 0)
3821 else if (strcasecmp (name
, "znv") == 0)
3825 else if (strcasecmp (name
, "sv") == 0)
3829 else if (strcasecmp (name
, "od") == 0)
3833 /* If we have something like addb,n then there is no condition
3835 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3846 /* Reset pointers if this was really a ,n for a branch instruction. */
3847 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3853 /* Parse a negated addition completer returning the number
3854 (for encoding in instrutions) of the given completer.
3856 ISBRANCH specifies whether or not this is parsing a condition
3857 completer for a branch (vs a nullification completer for a
3858 computational instruction. */
3861 pa_parse_neg_add_cmpltr (s
, isbranch
)
3866 char *name
= *s
+ 1;
3874 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3878 if (strcasecmp (name
, "tr") == 0)
3882 else if (strcmp (name
, "<>") == 0)
3886 else if (strcmp (name
, ">=") == 0)
3890 else if (strcmp (name
, ">") == 0)
3894 else if (strcasecmp (name
, "uv") == 0)
3898 else if (strcasecmp (name
, "vnz") == 0)
3902 else if (strcasecmp (name
, "nsv") == 0)
3906 else if (strcasecmp (name
, "ev") == 0)
3910 /* If we have something like addb,n then there is no condition
3912 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3923 /* Reset pointers if this was really a ,n for a branch instruction. */
3924 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3930 /* Handle an alignment directive. Special so that we can update the
3931 alignment of the subspace if necessary. */
3935 /* We must have a valid space and subspace. */
3936 pa_check_current_space_and_subspace ();
3938 /* Let the generic gas code do most of the work. */
3939 s_align_bytes (bytes
);
3941 /* If bytes is a power of 2, then update the current subspace's
3942 alignment if necessary. */
3943 if (log2 (bytes
) != -1)
3944 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
3947 /* Handle a .BLOCK type pseudo-op. */
3955 unsigned int temp_size
;
3958 /* We must have a valid space and subspace. */
3959 pa_check_current_space_and_subspace ();
3961 temp_size
= get_absolute_expression ();
3963 /* Always fill with zeros, that's what the HP assembler does. */
3966 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
3967 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
3968 bzero (p
, temp_size
);
3970 /* Convert 2 bytes at a time. */
3972 for (i
= 0; i
< temp_size
; i
+= 2)
3974 md_number_to_chars (p
+ i
,
3976 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
3979 pa_undefine_label ();
3980 demand_empty_rest_of_line ();
3983 /* Handle a .CALL pseudo-op. This involves storing away information
3984 about where arguments are to be found so the linker can detect
3985 (and correct) argument location mismatches between caller and callee. */
3991 /* We must have a valid space and subspace. */
3992 pa_check_current_space_and_subspace ();
3994 pa_call_args (&last_call_desc
);
3995 demand_empty_rest_of_line ();
3998 /* Do the dirty work of building a call descriptor which describes
3999 where the caller placed arguments to a function call. */
4002 pa_call_args (call_desc
)
4003 struct call_desc
*call_desc
;
4006 unsigned int temp
, arg_reloc
;
4008 while (!is_end_of_statement ())
4010 name
= input_line_pointer
;
4011 c
= get_symbol_end ();
4012 /* Process a source argument. */
4013 if ((strncasecmp (name
, "argw", 4) == 0))
4015 temp
= atoi (name
+ 4);
4016 p
= input_line_pointer
;
4018 input_line_pointer
++;
4019 name
= input_line_pointer
;
4020 c
= get_symbol_end ();
4021 arg_reloc
= pa_build_arg_reloc (name
);
4022 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4024 /* Process a return value. */
4025 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4027 p
= input_line_pointer
;
4029 input_line_pointer
++;
4030 name
= input_line_pointer
;
4031 c
= get_symbol_end ();
4032 arg_reloc
= pa_build_arg_reloc (name
);
4033 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4037 as_bad ("Invalid .CALL argument: %s", name
);
4039 p
= input_line_pointer
;
4041 if (!is_end_of_statement ())
4042 input_line_pointer
++;
4046 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4049 is_same_frag (frag1
, frag2
)
4056 else if (frag2
== NULL
)
4058 else if (frag1
== frag2
)
4060 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4061 return (is_same_frag (frag1
, frag2
->fr_next
));
4067 /* Build an entry in the UNWIND subspace from the given function
4068 attributes in CALL_INFO. This is not needed for SOM as using
4069 R_ENTRY and R_EXIT relocations allow the linker to handle building
4070 of the unwind spaces. */
4073 pa_build_unwind_subspace (call_info
)
4074 struct call_info
*call_info
;
4077 asection
*seg
, *save_seg
;
4078 subsegT subseg
, save_subseg
;
4082 /* Get into the right seg/subseg. This may involve creating
4083 the seg the first time through. Make sure to have the
4084 old seg/subseg so that we can reset things when we are done. */
4085 subseg
= SUBSEG_UNWIND
;
4086 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4087 if (seg
== ASEC_NULL
)
4089 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4090 bfd_set_section_flags (stdoutput
, seg
,
4091 SEC_READONLY
| SEC_HAS_CONTENTS
4092 | SEC_LOAD
| SEC_RELOC
);
4096 save_subseg
= now_subseg
;
4097 subseg_set (seg
, subseg
);
4100 /* Get some space to hold relocation information for the unwind
4104 /* Relocation info. for start offset of the function. */
4105 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4106 call_info
->start_symbol
, (offsetT
) 0,
4107 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4111 /* Relocation info. for end offset of the function.
4113 Because we allow reductions of 32bit relocations for ELF, this will be
4114 reduced to section_sym + offset which avoids putting the temporary
4115 symbol into the symbol table. It (should) end up giving the same
4116 value as call_info->start_symbol + function size once the linker is
4117 finished with its work. */
4119 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4120 call_info
->end_symbol
, (offsetT
) 0,
4121 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4124 unwind
= (char *) &call_info
->ci_unwind
;
4125 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4129 FRAG_APPEND_1_CHAR (c
);
4133 /* Return back to the original segment/subsegment. */
4134 subseg_set (save_seg
, save_subseg
);
4138 /* Process a .CALLINFO pseudo-op. This information is used later
4139 to build unwind descriptors and maybe one day to support
4140 .ENTER and .LEAVE. */
4143 pa_callinfo (unused
)
4149 /* We must have a valid space and subspace. */
4150 pa_check_current_space_and_subspace ();
4152 /* .CALLINFO must appear within a procedure definition. */
4153 if (!within_procedure
)
4154 as_bad (".callinfo is not within a procedure definition");
4156 /* Mark the fact that we found the .CALLINFO for the
4157 current procedure. */
4158 callinfo_found
= TRUE
;
4160 /* Iterate over the .CALLINFO arguments. */
4161 while (!is_end_of_statement ())
4163 name
= input_line_pointer
;
4164 c
= get_symbol_end ();
4165 /* Frame size specification. */
4166 if ((strncasecmp (name
, "frame", 5) == 0))
4168 p
= input_line_pointer
;
4170 input_line_pointer
++;
4171 temp
= get_absolute_expression ();
4172 if ((temp
& 0x3) != 0)
4174 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4178 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4179 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4182 /* Entry register (GR, GR and SR) specifications. */
4183 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4185 p
= input_line_pointer
;
4187 input_line_pointer
++;
4188 temp
= get_absolute_expression ();
4189 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4190 even though %r19 is caller saved. I think this is a bug in
4191 the HP assembler, and we are not going to emulate it. */
4192 if (temp
< 3 || temp
> 18)
4193 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4194 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4196 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4198 p
= input_line_pointer
;
4200 input_line_pointer
++;
4201 temp
= get_absolute_expression ();
4202 /* Similarly the HP assembler takes 31 as the high bound even
4203 though %fr21 is the last callee saved floating point register. */
4204 if (temp
< 12 || temp
> 21)
4205 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4206 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4208 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4210 p
= input_line_pointer
;
4212 input_line_pointer
++;
4213 temp
= get_absolute_expression ();
4215 as_bad ("Value for ENTRY_SR must be 3\n");
4217 /* Note whether or not this function performs any calls. */
4218 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4219 (strncasecmp (name
, "caller", 6) == 0))
4221 p
= input_line_pointer
;
4224 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4226 p
= input_line_pointer
;
4229 /* Should RP be saved into the stack. */
4230 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4232 p
= input_line_pointer
;
4234 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4236 /* Likewise for SP. */
4237 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4239 p
= input_line_pointer
;
4241 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4243 /* Is this an unwindable procedure. If so mark it so
4244 in the unwind descriptor. */
4245 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4247 p
= input_line_pointer
;
4249 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4251 /* Is this an interrupt routine. If so mark it in the
4252 unwind descriptor. */
4253 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4255 p
= input_line_pointer
;
4257 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4259 /* Is this a millicode routine. "millicode" isn't in my
4260 assembler manual, but my copy is old. The HP assembler
4261 accepts it, and there's a place in the unwind descriptor
4262 to drop the information, so we'll accept it too. */
4263 else if ((strncasecmp (name
, "millicode", 9) == 0))
4265 p
= input_line_pointer
;
4267 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4271 as_bad ("Invalid .CALLINFO argument: %s", name
);
4272 *input_line_pointer
= c
;
4274 if (!is_end_of_statement ())
4275 input_line_pointer
++;
4278 demand_empty_rest_of_line ();
4281 /* Switch into the code subspace. */
4287 current_space
= is_defined_space ("$TEXT$");
4289 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
4291 pa_undefine_label ();
4294 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4295 the .comm pseudo-op has the following symtax:
4297 <label> .comm <length>
4299 where <label> is optional and is a symbol whose address will be the start of
4300 a block of memory <length> bytes long. <length> must be an absolute
4301 expression. <length> bytes will be allocated in the current space
4304 Also note the label may not even be on the same line as the .comm.
4306 This difference in syntax means the colon function will be called
4307 on the symbol before we arrive in pa_comm. colon will set a number
4308 of attributes of the symbol that need to be fixed here. In particular
4309 the value, section pointer, fragment pointer, flags, etc. What
4312 This also makes error detection all but impossible. */
4320 label_symbol_struct
*label_symbol
= pa_get_label ();
4323 symbol
= label_symbol
->lss_label
;
4328 size
= get_absolute_expression ();
4332 S_SET_VALUE (symbol
, size
);
4333 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4334 S_SET_EXTERNAL (symbol
);
4336 /* colon() has already set the frag to the current location in the
4337 current subspace; we need to reset the fragment to the zero address
4338 fragment. We also need to reset the segment pointer. */
4339 symbol
->sy_frag
= &zero_address_frag
;
4341 demand_empty_rest_of_line ();
4344 /* Process a .END pseudo-op. */
4350 demand_empty_rest_of_line ();
4353 /* Process a .ENTER pseudo-op. This is not supported. */
4358 /* We must have a valid space and subspace. */
4359 pa_check_current_space_and_subspace ();
4364 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4370 /* We must have a valid space and subspace. */
4371 pa_check_current_space_and_subspace ();
4373 if (!within_procedure
)
4374 as_bad ("Misplaced .entry. Ignored.");
4377 if (!callinfo_found
)
4378 as_bad ("Missing .callinfo.");
4380 demand_empty_rest_of_line ();
4381 within_entry_exit
= TRUE
;
4384 /* SOM defers building of unwind descriptors until the link phase.
4385 The assembler is responsible for creating an R_ENTRY relocation
4386 to mark the beginning of a region and hold the unwind bits, and
4387 for creating an R_EXIT relocation to mark the end of the region.
4389 FIXME. ELF should be using the same conventions! The problem
4390 is an unwind requires too much relocation space. Hmmm. Maybe
4391 if we split the unwind bits up between the relocations which
4392 denote the entry and exit points. */
4393 if (last_call_info
->start_symbol
!= NULL
)
4395 char *where
= frag_more (0);
4397 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4398 NULL
, (offsetT
) 0, NULL
,
4399 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4400 (int *) &last_call_info
->ci_unwind
.descriptor
);
4405 /* Handle a .EQU pseudo-op. */
4411 label_symbol_struct
*label_symbol
= pa_get_label ();
4416 symbol
= label_symbol
->lss_label
;
4418 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4420 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4421 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4426 as_bad (".REG must use a label");
4428 as_bad (".EQU must use a label");
4431 pa_undefine_label ();
4432 demand_empty_rest_of_line ();
4435 /* Helper function. Does processing for the end of a function. This
4436 usually involves creating some relocations or building special
4437 symbols to mark the end of the function. */
4444 where
= frag_more (0);
4447 /* Mark the end of the function, stuff away the location of the frag
4448 for the end of the function, and finally call pa_build_unwind_subspace
4449 to add an entry in the unwind table. */
4450 hppa_elf_mark_end_of_function ();
4451 pa_build_unwind_subspace (last_call_info
);
4453 /* SOM defers building of unwind descriptors until the link phase.
4454 The assembler is responsible for creating an R_ENTRY relocation
4455 to mark the beginning of a region and hold the unwind bits, and
4456 for creating an R_EXIT relocation to mark the end of the region.
4458 FIXME. ELF should be using the same conventions! The problem
4459 is an unwind requires too much relocation space. Hmmm. Maybe
4460 if we split the unwind bits up between the relocations which
4461 denote the entry and exit points. */
4462 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4464 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4465 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4469 /* Process a .EXIT pseudo-op. */
4475 /* We must have a valid space and subspace. */
4476 pa_check_current_space_and_subspace ();
4478 if (!within_procedure
)
4479 as_bad (".EXIT must appear within a procedure");
4482 if (!callinfo_found
)
4483 as_bad ("Missing .callinfo");
4486 if (!within_entry_exit
)
4487 as_bad ("No .ENTRY for this .EXIT");
4490 within_entry_exit
= FALSE
;
4495 demand_empty_rest_of_line ();
4498 /* Process a .EXPORT directive. This makes functions external
4499 and provides information such as argument relocation entries
4509 name
= input_line_pointer
;
4510 c
= get_symbol_end ();
4511 /* Make sure the given symbol exists. */
4512 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4514 as_bad ("Cannot define export symbol: %s\n", name
);
4515 p
= input_line_pointer
;
4517 input_line_pointer
++;
4521 /* OK. Set the external bits and process argument relocations. */
4522 S_SET_EXTERNAL (symbol
);
4523 p
= input_line_pointer
;
4525 if (!is_end_of_statement ())
4527 input_line_pointer
++;
4528 pa_type_args (symbol
, 1);
4532 demand_empty_rest_of_line ();
4535 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4538 pa_type_args (symbolP
, is_export
)
4543 unsigned int temp
, arg_reloc
;
4544 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4545 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4547 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4550 input_line_pointer
+= 8;
4551 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4552 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4553 type
= SYMBOL_TYPE_ABSOLUTE
;
4555 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4557 input_line_pointer
+= 4;
4558 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4559 instead one should be IMPORTing/EXPORTing ENTRY types.
4561 Complain if one tries to EXPORT a CODE type since that's never
4562 done. Both GCC and HP C still try to IMPORT CODE types, so
4563 silently fix them to be ENTRY types. */
4564 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4567 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4569 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4570 type
= SYMBOL_TYPE_ENTRY
;
4574 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4575 type
= SYMBOL_TYPE_CODE
;
4578 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4580 input_line_pointer
+= 4;
4581 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4582 type
= SYMBOL_TYPE_DATA
;
4584 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4586 input_line_pointer
+= 5;
4587 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4588 type
= SYMBOL_TYPE_ENTRY
;
4590 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4592 input_line_pointer
+= 9;
4593 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4594 type
= SYMBOL_TYPE_MILLICODE
;
4596 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4598 input_line_pointer
+= 6;
4599 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4600 type
= SYMBOL_TYPE_PLABEL
;
4602 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4604 input_line_pointer
+= 8;
4605 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4606 type
= SYMBOL_TYPE_PRI_PROG
;
4608 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4610 input_line_pointer
+= 8;
4611 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4612 type
= SYMBOL_TYPE_SEC_PROG
;
4615 /* SOM requires much more information about symbol types
4616 than BFD understands. This is how we get this information
4617 to the SOM BFD backend. */
4618 #ifdef obj_set_symbol_type
4619 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4622 /* Now that the type of the exported symbol has been handled,
4623 handle any argument relocation information. */
4624 while (!is_end_of_statement ())
4626 if (*input_line_pointer
== ',')
4627 input_line_pointer
++;
4628 name
= input_line_pointer
;
4629 c
= get_symbol_end ();
4630 /* Argument sources. */
4631 if ((strncasecmp (name
, "argw", 4) == 0))
4633 p
= input_line_pointer
;
4635 input_line_pointer
++;
4636 temp
= atoi (name
+ 4);
4637 name
= input_line_pointer
;
4638 c
= get_symbol_end ();
4639 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4640 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4641 *input_line_pointer
= c
;
4643 /* The return value. */
4644 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4646 p
= input_line_pointer
;
4648 input_line_pointer
++;
4649 name
= input_line_pointer
;
4650 c
= get_symbol_end ();
4651 arg_reloc
= pa_build_arg_reloc (name
);
4652 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4653 *input_line_pointer
= c
;
4655 /* Privelege level. */
4656 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4658 p
= input_line_pointer
;
4660 input_line_pointer
++;
4661 temp
= atoi (input_line_pointer
);
4662 c
= get_symbol_end ();
4663 *input_line_pointer
= c
;
4667 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4668 p
= input_line_pointer
;
4671 if (!is_end_of_statement ())
4672 input_line_pointer
++;
4676 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4677 assembly file must either be defined in the assembly file, or
4678 explicitly IMPORTED from another. */
4687 name
= input_line_pointer
;
4688 c
= get_symbol_end ();
4690 symbol
= symbol_find (name
);
4691 /* Ugh. We might be importing a symbol defined earlier in the file,
4692 in which case all the code below will really screw things up
4693 (set the wrong segment, symbol flags & type, etc). */
4694 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4696 symbol
= symbol_find_or_make (name
);
4697 p
= input_line_pointer
;
4700 if (!is_end_of_statement ())
4702 input_line_pointer
++;
4703 pa_type_args (symbol
, 0);
4707 /* Sigh. To be compatable with the HP assembler and to help
4708 poorly written assembly code, we assign a type based on
4709 the the current segment. Note only BSF_FUNCTION really
4710 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4711 if (now_seg
== text_section
)
4712 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4714 /* If the section is undefined, then the symbol is undefined
4715 Since this is an import, leave the section undefined. */
4716 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4721 /* The symbol was already defined. Just eat everything up to
4722 the end of the current statement. */
4723 while (!is_end_of_statement ())
4724 input_line_pointer
++;
4727 demand_empty_rest_of_line ();
4730 /* Handle a .LABEL pseudo-op. */
4738 name
= input_line_pointer
;
4739 c
= get_symbol_end ();
4741 if (strlen (name
) > 0)
4744 p
= input_line_pointer
;
4749 as_warn ("Missing label name on .LABEL");
4752 if (!is_end_of_statement ())
4754 as_warn ("extra .LABEL arguments ignored.");
4755 ignore_rest_of_line ();
4757 demand_empty_rest_of_line ();
4760 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4766 /* We must have a valid space and subspace. */
4767 pa_check_current_space_and_subspace ();
4772 /* Handle a .ORIGIN pseudo-op. */
4778 /* We must have a valid space and subspace. */
4779 pa_check_current_space_and_subspace ();
4782 pa_undefine_label ();
4785 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4786 is for static functions. FIXME. Should share more code with .EXPORT. */
4795 name
= input_line_pointer
;
4796 c
= get_symbol_end ();
4798 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4800 as_bad ("Cannot define static symbol: %s\n", name
);
4801 p
= input_line_pointer
;
4803 input_line_pointer
++;
4807 S_CLEAR_EXTERNAL (symbol
);
4808 p
= input_line_pointer
;
4810 if (!is_end_of_statement ())
4812 input_line_pointer
++;
4813 pa_type_args (symbol
, 0);
4817 demand_empty_rest_of_line ();
4820 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4821 of a procedure from a syntatical point of view. */
4827 struct call_info
*call_info
;
4829 /* We must have a valid space and subspace. */
4830 pa_check_current_space_and_subspace ();
4832 if (within_procedure
)
4833 as_fatal ("Nested procedures");
4835 /* Reset global variables for new procedure. */
4836 callinfo_found
= FALSE
;
4837 within_procedure
= TRUE
;
4839 /* Create another call_info structure. */
4840 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4843 as_fatal ("Cannot allocate unwind descriptor\n");
4845 bzero (call_info
, sizeof (struct call_info
));
4847 call_info
->ci_next
= NULL
;
4849 if (call_info_root
== NULL
)
4851 call_info_root
= call_info
;
4852 last_call_info
= call_info
;
4856 last_call_info
->ci_next
= call_info
;
4857 last_call_info
= call_info
;
4860 /* set up defaults on call_info structure */
4862 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4863 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4864 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4866 /* If we got a .PROC pseudo-op, we know that the function is defined
4867 locally. Make sure it gets into the symbol table. */
4869 label_symbol_struct
*label_symbol
= pa_get_label ();
4873 if (label_symbol
->lss_label
)
4875 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4876 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4879 as_bad ("Missing function name for .PROC (corrupted label chain)");
4882 last_call_info
->start_symbol
= NULL
;
4885 demand_empty_rest_of_line ();
4888 /* Process the syntatical end of a procedure. Make sure all the
4889 appropriate pseudo-ops were found within the procedure. */
4896 /* We must have a valid space and subspace. */
4897 pa_check_current_space_and_subspace ();
4899 /* If we are within a procedure definition, make sure we've
4900 defined a label for the procedure; handle case where the
4901 label was defined after the .PROC directive.
4903 Note there's not need to diddle with the segment or fragment
4904 for the label symbol in this case. We have already switched
4905 into the new $CODE$ subspace at this point. */
4906 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4908 label_symbol_struct
*label_symbol
= pa_get_label ();
4912 if (label_symbol
->lss_label
)
4914 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4915 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4917 /* Also handle allocation of a fixup to hold the unwind
4918 information when the label appears after the proc/procend. */
4919 if (within_entry_exit
)
4921 char *where
= frag_more (0);
4923 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4924 NULL
, (offsetT
) 0, NULL
,
4925 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4926 (int *) &last_call_info
->ci_unwind
.descriptor
);
4931 as_bad ("Missing function name for .PROC (corrupted label chain)");
4934 as_bad ("Missing function name for .PROC");
4937 if (!within_procedure
)
4938 as_bad ("misplaced .procend");
4940 if (!callinfo_found
)
4941 as_bad ("Missing .callinfo for this procedure");
4943 if (within_entry_exit
)
4944 as_bad ("Missing .EXIT for a .ENTRY");
4947 /* ELF needs to mark the end of each function so that it can compute
4948 the size of the function (apparently its needed in the symbol table). */
4949 hppa_elf_mark_end_of_function ();
4952 within_procedure
= FALSE
;
4953 demand_empty_rest_of_line ();
4954 pa_undefine_label ();
4957 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4958 then create a new space entry to hold the information specified
4959 by the parameters to the .SPACE directive. */
4961 static sd_chain_struct
*
4962 pa_parse_space_stmt (space_name
, create_flag
)
4966 char *name
, *ptemp
, c
;
4967 char loadable
, defined
, private, sort
;
4969 asection
*seg
= NULL
;
4970 sd_chain_struct
*space
;
4972 /* load default values */
4978 if (strcmp (space_name
, "$TEXT$") == 0)
4980 seg
= pa_def_spaces
[0].segment
;
4981 defined
= pa_def_spaces
[0].defined
;
4982 private = pa_def_spaces
[0].private;
4983 sort
= pa_def_spaces
[0].sort
;
4984 spnum
= pa_def_spaces
[0].spnum
;
4986 else if (strcmp (space_name
, "$PRIVATE$") == 0)
4988 seg
= pa_def_spaces
[1].segment
;
4989 defined
= pa_def_spaces
[1].defined
;
4990 private = pa_def_spaces
[1].private;
4991 sort
= pa_def_spaces
[1].sort
;
4992 spnum
= pa_def_spaces
[1].spnum
;
4995 if (!is_end_of_statement ())
4997 print_errors
= FALSE
;
4998 ptemp
= input_line_pointer
+ 1;
4999 /* First see if the space was specified as a number rather than
5000 as a name. According to the PA assembly manual the rest of
5001 the line should be ignored. */
5002 temp
= pa_parse_number (&ptemp
, 0);
5006 input_line_pointer
= ptemp
;
5010 while (!is_end_of_statement ())
5012 input_line_pointer
++;
5013 name
= input_line_pointer
;
5014 c
= get_symbol_end ();
5015 if ((strncasecmp (name
, "spnum", 5) == 0))
5017 *input_line_pointer
= c
;
5018 input_line_pointer
++;
5019 spnum
= get_absolute_expression ();
5021 else if ((strncasecmp (name
, "sort", 4) == 0))
5023 *input_line_pointer
= c
;
5024 input_line_pointer
++;
5025 sort
= get_absolute_expression ();
5027 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5029 *input_line_pointer
= c
;
5032 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5034 *input_line_pointer
= c
;
5037 else if ((strncasecmp (name
, "private", 7) == 0))
5039 *input_line_pointer
= c
;
5044 as_bad ("Invalid .SPACE argument");
5045 *input_line_pointer
= c
;
5046 if (!is_end_of_statement ())
5047 input_line_pointer
++;
5051 print_errors
= TRUE
;
5054 if (create_flag
&& seg
== NULL
)
5055 seg
= subseg_new (space_name
, 0);
5057 /* If create_flag is nonzero, then create the new space with
5058 the attributes computed above. Else set the values in
5059 an already existing space -- this can only happen for
5060 the first occurence of a built-in space. */
5062 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5063 private, sort
, seg
, 1);
5066 space
= is_defined_space (space_name
);
5067 SPACE_SPNUM (space
) = spnum
;
5068 SPACE_DEFINED (space
) = defined
& 1;
5069 SPACE_USER_DEFINED (space
) = 1;
5072 #ifdef obj_set_section_attributes
5073 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5079 /* Handle a .SPACE pseudo-op; this switches the current space to the
5080 given space, creating the new space if necessary. */
5086 char *name
, c
, *space_name
, *save_s
;
5088 sd_chain_struct
*sd_chain
;
5090 if (within_procedure
)
5092 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5093 ignore_rest_of_line ();
5097 /* Check for some of the predefined spaces. FIXME: most of the code
5098 below is repeated several times, can we extract the common parts
5099 and place them into a subroutine or something similar? */
5100 /* FIXME Is this (and the next IF stmt) really right?
5101 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5102 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5104 input_line_pointer
+= 6;
5105 sd_chain
= is_defined_space ("$TEXT$");
5106 if (sd_chain
== NULL
)
5107 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5108 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5109 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5111 current_space
= sd_chain
;
5112 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5114 = pa_subsegment_to_subspace (text_section
,
5115 sd_chain
->sd_last_subseg
);
5116 demand_empty_rest_of_line ();
5119 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5121 input_line_pointer
+= 9;
5122 sd_chain
= is_defined_space ("$PRIVATE$");
5123 if (sd_chain
== NULL
)
5124 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5125 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5126 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5128 current_space
= sd_chain
;
5129 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5131 = pa_subsegment_to_subspace (data_section
,
5132 sd_chain
->sd_last_subseg
);
5133 demand_empty_rest_of_line ();
5136 if (!strncasecmp (input_line_pointer
,
5137 GDB_DEBUG_SPACE_NAME
,
5138 strlen (GDB_DEBUG_SPACE_NAME
)))
5140 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5141 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5142 if (sd_chain
== NULL
)
5143 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5144 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5145 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5147 current_space
= sd_chain
;
5150 asection
*gdb_section
5151 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5153 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5155 = pa_subsegment_to_subspace (gdb_section
,
5156 sd_chain
->sd_last_subseg
);
5158 demand_empty_rest_of_line ();
5162 /* It could be a space specified by number. */
5164 save_s
= input_line_pointer
;
5165 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5167 if ((sd_chain
= pa_find_space_by_number (temp
)))
5169 current_space
= sd_chain
;
5171 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5173 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5174 sd_chain
->sd_last_subseg
);
5175 demand_empty_rest_of_line ();
5180 /* Not a number, attempt to create a new space. */
5182 input_line_pointer
= save_s
;
5183 name
= input_line_pointer
;
5184 c
= get_symbol_end ();
5185 space_name
= xmalloc (strlen (name
) + 1);
5186 strcpy (space_name
, name
);
5187 *input_line_pointer
= c
;
5189 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5190 current_space
= sd_chain
;
5192 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5193 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5194 sd_chain
->sd_last_subseg
);
5195 demand_empty_rest_of_line ();
5199 /* Switch to a new space. (I think). FIXME. */
5208 sd_chain_struct
*space
;
5210 name
= input_line_pointer
;
5211 c
= get_symbol_end ();
5212 space
= is_defined_space (name
);
5216 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5219 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5221 *input_line_pointer
= c
;
5222 demand_empty_rest_of_line ();
5225 /* If VALUE is an exact power of two between zero and 2^31, then
5226 return log2 (VALUE). Else return -1. */
5234 while ((1 << shift
) != value
&& shift
< 32)
5243 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5244 given subspace, creating the new subspace if necessary.
5246 FIXME. Should mirror pa_space more closely, in particular how
5247 they're broken up into subroutines. */
5250 pa_subspace (unused
)
5253 char *name
, *ss_name
, *alias
, c
;
5254 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5255 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5256 sd_chain_struct
*space
;
5257 ssd_chain_struct
*ssd
;
5260 if (current_space
== NULL
)
5261 as_fatal ("Must be in a space before changing or declaring subspaces.\n");
5263 if (within_procedure
)
5265 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5266 ignore_rest_of_line ();
5270 name
= input_line_pointer
;
5271 c
= get_symbol_end ();
5272 ss_name
= xmalloc (strlen (name
) + 1);
5273 strcpy (ss_name
, name
);
5274 *input_line_pointer
= c
;
5276 /* Load default values. */
5289 space
= current_space
;
5290 ssd
= is_defined_subspace (ss_name
);
5291 /* Allow user to override the builtin attributes of subspaces. But
5292 only allow the attributes to be changed once! */
5293 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5295 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5296 current_subspace
= ssd
;
5297 if (!is_end_of_statement ())
5298 as_warn ("Parameters of an existing subspace can\'t be modified");
5299 demand_empty_rest_of_line ();
5304 /* A new subspace. Load default values if it matches one of
5305 the builtin subspaces. */
5307 while (pa_def_subspaces
[i
].name
)
5309 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5311 loadable
= pa_def_subspaces
[i
].loadable
;
5312 common
= pa_def_subspaces
[i
].common
;
5313 dup_common
= pa_def_subspaces
[i
].dup_common
;
5314 code_only
= pa_def_subspaces
[i
].code_only
;
5315 zero
= pa_def_subspaces
[i
].zero
;
5316 space_index
= pa_def_subspaces
[i
].space_index
;
5317 alignment
= pa_def_subspaces
[i
].alignment
;
5318 quadrant
= pa_def_subspaces
[i
].quadrant
;
5319 access
= pa_def_subspaces
[i
].access
;
5320 sort
= pa_def_subspaces
[i
].sort
;
5321 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5322 alias
= pa_def_subspaces
[i
].alias
;
5329 /* We should be working with a new subspace now. Fill in
5330 any information as specified by the user. */
5331 if (!is_end_of_statement ())
5333 input_line_pointer
++;
5334 while (!is_end_of_statement ())
5336 name
= input_line_pointer
;
5337 c
= get_symbol_end ();
5338 if ((strncasecmp (name
, "quad", 4) == 0))
5340 *input_line_pointer
= c
;
5341 input_line_pointer
++;
5342 quadrant
= get_absolute_expression ();
5344 else if ((strncasecmp (name
, "align", 5) == 0))
5346 *input_line_pointer
= c
;
5347 input_line_pointer
++;
5348 alignment
= get_absolute_expression ();
5349 if (log2 (alignment
) == -1)
5351 as_bad ("Alignment must be a power of 2");
5355 else if ((strncasecmp (name
, "access", 6) == 0))
5357 *input_line_pointer
= c
;
5358 input_line_pointer
++;
5359 access
= get_absolute_expression ();
5361 else if ((strncasecmp (name
, "sort", 4) == 0))
5363 *input_line_pointer
= c
;
5364 input_line_pointer
++;
5365 sort
= get_absolute_expression ();
5367 else if ((strncasecmp (name
, "code_only", 9) == 0))
5369 *input_line_pointer
= c
;
5372 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5374 *input_line_pointer
= c
;
5377 else if ((strncasecmp (name
, "common", 6) == 0))
5379 *input_line_pointer
= c
;
5382 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5384 *input_line_pointer
= c
;
5387 else if ((strncasecmp (name
, "zero", 4) == 0))
5389 *input_line_pointer
= c
;
5392 else if ((strncasecmp (name
, "first", 5) == 0))
5393 as_bad ("FIRST not supported as a .SUBSPACE argument");
5395 as_bad ("Invalid .SUBSPACE argument");
5396 if (!is_end_of_statement ())
5397 input_line_pointer
++;
5401 /* Compute a reasonable set of BFD flags based on the information
5402 in the .subspace directive. */
5403 applicable
= bfd_applicable_section_flags (stdoutput
);
5406 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5409 if (common
|| dup_common
)
5410 flags
|= SEC_IS_COMMON
;
5412 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5414 /* This is a zero-filled subspace (eg BSS). */
5416 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
5418 applicable
&= flags
;
5420 /* If this is an existing subspace, then we want to use the
5421 segment already associated with the subspace.
5423 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5424 lots of sections. It might be a problem in the PA ELF
5425 code, I do not know yet. For now avoid creating anything
5426 but the "standard" sections for ELF. */
5428 section
= ssd
->ssd_seg
;
5430 section
= subseg_new (alias
, 0);
5431 else if (!alias
&& USE_ALIASES
)
5433 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5434 demand_empty_rest_of_line ();
5438 section
= subseg_new (ss_name
, 0);
5441 seg_info (section
)->bss
= 1;
5443 /* Now set the flags. */
5444 bfd_set_section_flags (stdoutput
, section
, applicable
);
5446 /* Record any alignment request for this section. */
5447 record_alignment (section
, log2 (alignment
));
5449 /* Set the starting offset for this section. */
5450 bfd_set_section_vma (stdoutput
, section
,
5451 pa_subspace_start (space
, quadrant
));
5453 /* Now that all the flags are set, update an existing subspace,
5454 or create a new one. */
5457 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5458 code_only
, common
, dup_common
,
5459 sort
, zero
, access
, space_index
,
5460 alignment
, quadrant
,
5463 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5465 dup_common
, zero
, sort
,
5466 access
, space_index
,
5467 alignment
, quadrant
, section
);
5469 demand_empty_rest_of_line ();
5470 current_subspace
->ssd_seg
= section
;
5471 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5473 SUBSPACE_DEFINED (current_subspace
) = 1;
5477 /* Create default space and subspace dictionaries. */
5484 space_dict_root
= NULL
;
5485 space_dict_last
= NULL
;
5488 while (pa_def_spaces
[i
].name
)
5492 /* Pick the right name to use for the new section. */
5493 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5494 name
= pa_def_spaces
[i
].alias
;
5496 name
= pa_def_spaces
[i
].name
;
5498 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5499 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5500 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5501 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5502 pa_def_spaces
[i
].segment
, 0);
5507 while (pa_def_subspaces
[i
].name
)
5510 int applicable
, subsegment
;
5511 asection
*segment
= NULL
;
5512 sd_chain_struct
*space
;
5514 /* Pick the right name for the new section and pick the right
5515 subsegment number. */
5516 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5518 name
= pa_def_subspaces
[i
].alias
;
5519 subsegment
= pa_def_subspaces
[i
].subsegment
;
5523 name
= pa_def_subspaces
[i
].name
;
5527 /* Create the new section. */
5528 segment
= subseg_new (name
, subsegment
);
5531 /* For SOM we want to replace the standard .text, .data, and .bss
5532 sections with our own. We also want to set BFD flags for
5533 all the built-in subspaces. */
5534 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5536 text_section
= segment
;
5537 applicable
= bfd_applicable_section_flags (stdoutput
);
5538 bfd_set_section_flags (stdoutput
, segment
,
5539 applicable
& (SEC_ALLOC
| SEC_LOAD
5540 | SEC_RELOC
| SEC_CODE
5542 | SEC_HAS_CONTENTS
));
5544 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5546 data_section
= segment
;
5547 applicable
= bfd_applicable_section_flags (stdoutput
);
5548 bfd_set_section_flags (stdoutput
, segment
,
5549 applicable
& (SEC_ALLOC
| SEC_LOAD
5551 | SEC_HAS_CONTENTS
));
5555 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5557 bss_section
= segment
;
5558 applicable
= bfd_applicable_section_flags (stdoutput
);
5559 bfd_set_section_flags (stdoutput
, segment
,
5560 applicable
& SEC_ALLOC
);
5562 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5564 applicable
= bfd_applicable_section_flags (stdoutput
);
5565 bfd_set_section_flags (stdoutput
, segment
,
5566 applicable
& (SEC_ALLOC
| SEC_LOAD
5569 | SEC_HAS_CONTENTS
));
5571 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5573 applicable
= bfd_applicable_section_flags (stdoutput
);
5574 bfd_set_section_flags (stdoutput
, segment
,
5575 applicable
& (SEC_ALLOC
| SEC_LOAD
5578 | SEC_HAS_CONTENTS
));
5581 /* Find the space associated with this subspace. */
5582 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5583 def_space_index
].segment
);
5586 as_fatal ("Internal error: Unable to find containing space for %s.",
5587 pa_def_subspaces
[i
].name
);
5590 create_new_subspace (space
, name
,
5591 pa_def_subspaces
[i
].loadable
,
5592 pa_def_subspaces
[i
].code_only
,
5593 pa_def_subspaces
[i
].common
,
5594 pa_def_subspaces
[i
].dup_common
,
5595 pa_def_subspaces
[i
].zero
,
5596 pa_def_subspaces
[i
].sort
,
5597 pa_def_subspaces
[i
].access
,
5598 pa_def_subspaces
[i
].space_index
,
5599 pa_def_subspaces
[i
].alignment
,
5600 pa_def_subspaces
[i
].quadrant
,
5608 /* Create a new space NAME, with the appropriate flags as defined
5609 by the given parameters. */
5611 static sd_chain_struct
*
5612 create_new_space (name
, spnum
, loadable
, defined
, private,
5613 sort
, seg
, user_defined
)
5623 sd_chain_struct
*chain_entry
;
5625 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5627 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5630 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5631 strcpy (SPACE_NAME (chain_entry
), name
);
5632 SPACE_DEFINED (chain_entry
) = defined
;
5633 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5634 SPACE_SPNUM (chain_entry
) = spnum
;
5636 chain_entry
->sd_seg
= seg
;
5637 chain_entry
->sd_last_subseg
= -1;
5638 chain_entry
->sd_subspaces
= NULL
;
5639 chain_entry
->sd_next
= NULL
;
5641 /* Find spot for the new space based on its sort key. */
5642 if (!space_dict_last
)
5643 space_dict_last
= chain_entry
;
5645 if (space_dict_root
== NULL
)
5646 space_dict_root
= chain_entry
;
5649 sd_chain_struct
*chain_pointer
;
5650 sd_chain_struct
*prev_chain_pointer
;
5652 chain_pointer
= space_dict_root
;
5653 prev_chain_pointer
= NULL
;
5655 while (chain_pointer
)
5657 prev_chain_pointer
= chain_pointer
;
5658 chain_pointer
= chain_pointer
->sd_next
;
5661 /* At this point we've found the correct place to add the new
5662 entry. So add it and update the linked lists as appropriate. */
5663 if (prev_chain_pointer
)
5665 chain_entry
->sd_next
= chain_pointer
;
5666 prev_chain_pointer
->sd_next
= chain_entry
;
5670 space_dict_root
= chain_entry
;
5671 chain_entry
->sd_next
= chain_pointer
;
5674 if (chain_entry
->sd_next
== NULL
)
5675 space_dict_last
= chain_entry
;
5678 /* This is here to catch predefined spaces which do not get
5679 modified by the user's input. Another call is found at
5680 the bottom of pa_parse_space_stmt to handle cases where
5681 the user modifies a predefined space. */
5682 #ifdef obj_set_section_attributes
5683 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5689 /* Create a new subspace NAME, with the appropriate flags as defined
5690 by the given parameters.
5692 Add the new subspace to the subspace dictionary chain in numerical
5693 order as defined by the SORT entries. */
5695 static ssd_chain_struct
*
5696 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5697 dup_common
, is_zero
, sort
, access
, space_index
,
5698 alignment
, quadrant
, seg
)
5699 sd_chain_struct
*space
;
5701 int loadable
, code_only
, common
, dup_common
, is_zero
;
5709 ssd_chain_struct
*chain_entry
;
5711 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5713 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5715 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5716 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5718 /* Initialize subspace_defined. When we hit a .subspace directive
5719 we'll set it to 1 which "locks-in" the subspace attributes. */
5720 SUBSPACE_DEFINED (chain_entry
) = 0;
5722 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5723 chain_entry
->ssd_seg
= seg
;
5724 chain_entry
->ssd_next
= NULL
;
5726 /* Find spot for the new subspace based on its sort key. */
5727 if (space
->sd_subspaces
== NULL
)
5728 space
->sd_subspaces
= chain_entry
;
5731 ssd_chain_struct
*chain_pointer
;
5732 ssd_chain_struct
*prev_chain_pointer
;
5734 chain_pointer
= space
->sd_subspaces
;
5735 prev_chain_pointer
= NULL
;
5737 while (chain_pointer
)
5739 prev_chain_pointer
= chain_pointer
;
5740 chain_pointer
= chain_pointer
->ssd_next
;
5743 /* Now we have somewhere to put the new entry. Insert it and update
5745 if (prev_chain_pointer
)
5747 chain_entry
->ssd_next
= chain_pointer
;
5748 prev_chain_pointer
->ssd_next
= chain_entry
;
5752 space
->sd_subspaces
= chain_entry
;
5753 chain_entry
->ssd_next
= chain_pointer
;
5757 #ifdef obj_set_subsection_attributes
5758 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5765 /* Update the information for the given subspace based upon the
5766 various arguments. Return the modified subspace chain entry. */
5768 static ssd_chain_struct
*
5769 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5770 zero
, access
, space_index
, alignment
, quadrant
, section
)
5771 sd_chain_struct
*space
;
5785 ssd_chain_struct
*chain_entry
;
5787 chain_entry
= is_defined_subspace (name
);
5789 #ifdef obj_set_subsection_attributes
5790 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5797 /* Return the space chain entry for the space with the name NAME or
5798 NULL if no such space exists. */
5800 static sd_chain_struct
*
5801 is_defined_space (name
)
5804 sd_chain_struct
*chain_pointer
;
5806 for (chain_pointer
= space_dict_root
;
5808 chain_pointer
= chain_pointer
->sd_next
)
5810 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5811 return chain_pointer
;
5814 /* No mapping from segment to space was found. Return NULL. */
5818 /* Find and return the space associated with the given seg. If no mapping
5819 from the given seg to a space is found, then return NULL.
5821 Unlike subspaces, the number of spaces is not expected to grow much,
5822 so a linear exhaustive search is OK here. */
5824 static sd_chain_struct
*
5825 pa_segment_to_space (seg
)
5828 sd_chain_struct
*space_chain
;
5830 /* Walk through each space looking for the correct mapping. */
5831 for (space_chain
= space_dict_root
;
5833 space_chain
= space_chain
->sd_next
)
5835 if (space_chain
->sd_seg
== seg
)
5839 /* Mapping was not found. Return NULL. */
5843 /* Return the space chain entry for the subspace with the name NAME or
5844 NULL if no such subspace exists.
5846 Uses a linear search through all the spaces and subspaces, this may
5847 not be appropriate if we ever being placing each function in its
5850 static ssd_chain_struct
*
5851 is_defined_subspace (name
)
5854 sd_chain_struct
*space_chain
;
5855 ssd_chain_struct
*subspace_chain
;
5857 /* Walk through each space. */
5858 for (space_chain
= space_dict_root
;
5860 space_chain
= space_chain
->sd_next
)
5862 /* Walk through each subspace looking for a name which matches. */
5863 for (subspace_chain
= space_chain
->sd_subspaces
;
5865 subspace_chain
= subspace_chain
->ssd_next
)
5866 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5867 return subspace_chain
;
5870 /* Subspace wasn't found. Return NULL. */
5874 /* Find and return the subspace associated with the given seg. If no
5875 mapping from the given seg to a subspace is found, then return NULL.
5877 If we ever put each procedure/function within its own subspace
5878 (to make life easier on the compiler and linker), then this will have
5879 to become more efficient. */
5881 static ssd_chain_struct
*
5882 pa_subsegment_to_subspace (seg
, subseg
)
5886 sd_chain_struct
*space_chain
;
5887 ssd_chain_struct
*subspace_chain
;
5889 /* Walk through each space. */
5890 for (space_chain
= space_dict_root
;
5892 space_chain
= space_chain
->sd_next
)
5894 if (space_chain
->sd_seg
== seg
)
5896 /* Walk through each subspace within each space looking for
5897 the correct mapping. */
5898 for (subspace_chain
= space_chain
->sd_subspaces
;
5900 subspace_chain
= subspace_chain
->ssd_next
)
5901 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5902 return subspace_chain
;
5906 /* No mapping from subsegment to subspace found. Return NULL. */
5910 /* Given a number, try and find a space with the name number.
5912 Return a pointer to a space dictionary chain entry for the space
5913 that was found or NULL on failure. */
5915 static sd_chain_struct
*
5916 pa_find_space_by_number (number
)
5919 sd_chain_struct
*space_chain
;
5921 for (space_chain
= space_dict_root
;
5923 space_chain
= space_chain
->sd_next
)
5925 if (SPACE_SPNUM (space_chain
) == number
)
5929 /* No appropriate space found. Return NULL. */
5933 /* Return the starting address for the given subspace. If the starting
5934 address is unknown then return zero. */
5937 pa_subspace_start (space
, quadrant
)
5938 sd_chain_struct
*space
;
5941 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5942 is not correct for the PA OSF1 port. */
5943 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5945 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5951 /* FIXME. Needs documentation. */
5953 pa_next_subseg (space
)
5954 sd_chain_struct
*space
;
5957 space
->sd_last_subseg
++;
5958 return space
->sd_last_subseg
;
5961 /* Helper function for pa_stringer. Used to find the end of
5968 unsigned int c
= *s
& CHAR_MASK
;
5970 /* We must have a valid space and subspace. */
5971 pa_check_current_space_and_subspace ();
5984 /* Handle a .STRING type pseudo-op. */
5987 pa_stringer (append_zero
)
5990 char *s
, num_buf
[4];
5994 /* Preprocess the string to handle PA-specific escape sequences.
5995 For example, \xDD where DD is a hexidecimal number should be
5996 changed to \OOO where OOO is an octal number. */
5998 /* Skip the opening quote. */
5999 s
= input_line_pointer
+ 1;
6001 while (is_a_char (c
= pa_stringer_aux (s
++)))
6008 /* Handle \x<num>. */
6011 unsigned int number
;
6016 /* Get pas the 'x'. */
6018 for (num_digit
= 0, number
= 0, dg
= *s
;
6020 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6021 || (dg
>= 'A' && dg
<= 'F'));
6025 number
= number
* 16 + dg
- '0';
6026 else if (dg
>= 'a' && dg
<= 'f')
6027 number
= number
* 16 + dg
- 'a' + 10;
6029 number
= number
* 16 + dg
- 'A' + 10;
6039 sprintf (num_buf
, "%02o", number
);
6042 sprintf (num_buf
, "%03o", number
);
6045 for (i
= 0; i
<= num_digit
; i
++)
6046 s_start
[i
] = num_buf
[i
];
6050 /* This might be a "\"", skip over the escaped char. */
6057 stringer (append_zero
);
6058 pa_undefine_label ();
6061 /* Handle a .VERSION pseudo-op. */
6068 pa_undefine_label ();
6071 /* Handle a .COPYRIGHT pseudo-op. */
6074 pa_copyright (unused
)
6078 pa_undefine_label ();
6081 /* Just like a normal cons, but when finished we have to undefine
6082 the latest space label. */
6089 pa_undefine_label ();
6092 /* Switch to the data space. As usual delete our label. */
6098 current_space
= is_defined_space ("$PRIVATE$");
6100 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6102 pa_undefine_label ();
6105 /* Like float_cons, but we need to undefine our label. */
6108 pa_float_cons (float_type
)
6111 float_cons (float_type
);
6112 pa_undefine_label ();
6115 /* Like s_fill, but delete our label when finished. */
6121 /* We must have a valid space and subspace. */
6122 pa_check_current_space_and_subspace ();
6125 pa_undefine_label ();
6128 /* Like lcomm, but delete our label when finished. */
6131 pa_lcomm (needs_align
)
6134 /* We must have a valid space and subspace. */
6135 pa_check_current_space_and_subspace ();
6137 s_lcomm (needs_align
);
6138 pa_undefine_label ();
6141 /* Like lsym, but delete our label when finished. */
6147 /* We must have a valid space and subspace. */
6148 pa_check_current_space_and_subspace ();
6151 pa_undefine_label ();
6154 /* Switch to the text space. Like s_text, but delete our
6155 label when finished. */
6160 current_space
= is_defined_space ("$TEXT$");
6162 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6165 pa_undefine_label ();
6168 /* On the PA relocations which involve function symbols must not be
6169 adjusted. This so that the linker can know when/how to create argument
6170 relocation stubs for indirect calls and calls to static functions.
6172 "T" field selectors create DLT relative fixups for accessing
6173 globals and statics in PIC code; each DLT relative fixup creates
6174 an entry in the DLT table. The entries contain the address of
6175 the final target (eg accessing "foo" would create a DLT entry
6176 with the address of "foo").
6178 Unfortunately, the HP linker doesn't take into account any addend
6179 when generating the DLT; so accessing $LIT$+8 puts the address of
6180 $LIT$ into the DLT rather than the address of $LIT$+8.
6182 The end result is we can't perform relocation symbol reductions for
6183 any fixup which creates entries in the DLT (eg they use "T" field
6186 Reject reductions involving symbols with external scope; such
6187 reductions make life a living hell for object file editors.
6189 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6190 the code space. The SOM BFD backend doesn't know how to pull the
6191 right bits out of an instruction. */
6194 hppa_fix_adjustable (fixp
)
6197 struct hppa_fix_struct
*hppa_fix
;
6199 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6202 /* Reject reductions of symbols in 32bit relocs. */
6203 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6207 /* Reject reductions of symbols in DLT relative relocs,
6208 relocations with plabels. */
6209 if (hppa_fix
->fx_r_field
== e_tsel
6210 || hppa_fix
->fx_r_field
== e_ltsel
6211 || hppa_fix
->fx_r_field
== e_rtsel
6212 || hppa_fix
->fx_r_field
== e_psel
6213 || hppa_fix
->fx_r_field
== e_rpsel
6214 || hppa_fix
->fx_r_field
== e_lpsel
)
6217 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6220 /* Reject reductions of function symbols. */
6221 if (fixp
->fx_addsy
== 0
6222 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6228 /* Return nonzero if the fixup in FIXP will require a relocation,
6229 even it if appears that the fixup could be completely handled
6233 hppa_force_relocation (fixp
)
6236 struct hppa_fix_struct
*hppa_fixp
;
6239 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6241 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6245 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6246 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6248 /* It is necessary to force PC-relative calls/jumps to have a relocation
6249 entry if they're going to need either a argument relocation or long
6250 call stub. FIXME. Can't we need the same for absolute calls? */
6251 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6252 && (arg_reloc_stub_needed (((obj_symbol_type
*)
6253 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6255 hppa_fixp
->fx_arg_reloc
)))
6257 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
6258 - md_pcrel_from (fixp
));
6259 /* Now check and see if we're going to need a long-branch stub. */
6260 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
6261 && (distance
> 262143 || distance
< -262144))
6264 #undef arg_reloc_stub_needed
6266 /* No need (yet) to force another relocations to be emitted. */
6270 /* Now for some ELF specific code. FIXME. */
6272 /* Mark the end of a function so that it's possible to compute
6273 the size of the function in hppa_elf_final_processing. */
6276 hppa_elf_mark_end_of_function ()
6278 /* ELF does not have EXIT relocations. All we do is create a
6279 temporary symbol marking the end of the function. */
6280 char *name
= (char *)
6281 xmalloc (strlen ("L$\001end_") +
6282 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6288 strcpy (name
, "L$\001end_");
6289 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6291 /* If we have a .exit followed by a .procend, then the
6292 symbol will have already been defined. */
6293 symbolP
= symbol_find (name
);
6296 /* The symbol has already been defined! This can
6297 happen if we have a .exit followed by a .procend.
6299 This is *not* an error. All we want to do is free
6300 the memory we just allocated for the name and continue. */
6305 /* symbol value should be the offset of the
6306 last instruction of the function */
6307 symbolP
= symbol_new (name
, now_seg
,
6308 (valueT
) (obstack_next_free (&frags
)
6309 - frag_now
->fr_literal
- 4),
6313 symbolP
->bsym
->flags
= BSF_LOCAL
;
6314 symbol_table_insert (symbolP
);
6318 last_call_info
->end_symbol
= symbolP
;
6320 as_bad ("Symbol '%s' could not be created.", name
);
6324 as_bad ("No memory for symbol name.");
6328 /* For ELF, this function serves one purpose: to setup the st_size
6329 field of STT_FUNC symbols. To do this, we need to scan the
6330 call_info structure list, determining st_size in by taking the
6331 difference in the address of the beginning/end marker symbols. */
6334 elf_hppa_final_processing ()
6336 struct call_info
*call_info_pointer
;
6338 for (call_info_pointer
= call_info_root
;
6340 call_info_pointer
= call_info_pointer
->ci_next
)
6342 elf_symbol_type
*esym
6343 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6344 esym
->internal_elf_sym
.st_size
=
6345 S_GET_VALUE (call_info_pointer
->end_symbol
)
6346 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;