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_89_fp_reg_struct'. */
241 struct pa_89_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 unwind descriptor associated with this fixup. */
427 /* The segment this fixup appears in. */
431 /* Structure to hold information about predefined registers. */
439 /* This structure defines the mapping from a FP condition string
440 to a condition number which can be recorded in an instruction. */
447 /* This structure defines a mapping from a field selector
448 string to a field selector type. */
449 struct selector_entry
455 /* Prototypes for functions local to tc-hppa.c. */
457 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
458 static void pa_cons
PARAMS ((int));
459 static void pa_data
PARAMS ((int));
460 static void pa_float_cons
PARAMS ((int));
461 static void pa_fill
PARAMS ((int));
462 static void pa_lcomm
PARAMS ((int));
463 static void pa_lsym
PARAMS ((int));
464 static void pa_stringer
PARAMS ((int));
465 static void pa_text
PARAMS ((int));
466 static void pa_version
PARAMS ((int));
467 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
468 static int get_expression
PARAMS ((char *));
469 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
470 static int evaluate_absolute
PARAMS ((struct pa_it
*));
471 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
472 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
473 static int pa_parse_nullif
PARAMS ((char **));
474 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
475 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
476 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
477 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
478 static void pa_block
PARAMS ((int));
479 static void pa_call
PARAMS ((int));
480 static void pa_call_args
PARAMS ((struct call_desc
*));
481 static void pa_callinfo
PARAMS ((int));
482 static void pa_code
PARAMS ((int));
483 static void pa_comm
PARAMS ((int));
484 static void pa_copyright
PARAMS ((int));
485 static void pa_end
PARAMS ((int));
486 static void pa_enter
PARAMS ((int));
487 static void pa_entry
PARAMS ((int));
488 static void pa_equ
PARAMS ((int));
489 static void pa_exit
PARAMS ((int));
490 static void pa_export
PARAMS ((int));
491 static void pa_type_args
PARAMS ((symbolS
*, int));
492 static void pa_import
PARAMS ((int));
493 static void pa_label
PARAMS ((int));
494 static void pa_leave
PARAMS ((int));
495 static void pa_origin
PARAMS ((int));
496 static void pa_proc
PARAMS ((int));
497 static void pa_procend
PARAMS ((int));
498 static void pa_space
PARAMS ((int));
499 static void pa_spnum
PARAMS ((int));
500 static void pa_subspace
PARAMS ((int));
501 static void pa_param
PARAMS ((int));
502 static void pa_undefine_label
PARAMS ((void));
503 static int need_89_opcode
PARAMS ((struct pa_it
*,
504 struct pa_89_fp_reg_struct
*));
505 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
506 static label_symbol_struct
*pa_get_label
PARAMS ((void));
507 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
510 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
515 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
516 char *, int, int, int,
520 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
521 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
522 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
523 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
525 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
526 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
527 static void pa_ip
PARAMS ((char *));
528 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
529 long, expressionS
*, int,
530 bfd_reloc_code_real_type
,
531 enum hppa_reloc_field_selector_type
,
533 static int is_end_of_statement
PARAMS ((void));
534 static int reg_name_search
PARAMS ((char *));
535 static int pa_chk_field_selector
PARAMS ((char **));
536 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
537 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
538 static void process_exit
PARAMS ((void));
539 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
540 static int log2
PARAMS ((int));
541 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
542 static unsigned int pa_stringer_aux
PARAMS ((char *));
543 static void pa_spaces_begin
PARAMS ((void));
544 static void hppa_elf_mark_end_of_function
PARAMS ((void));
546 /* File and gloally scoped variable declarations. */
548 /* Root and final entry in the space chain. */
549 static sd_chain_struct
*space_dict_root
;
550 static sd_chain_struct
*space_dict_last
;
552 /* The current space and subspace. */
553 static sd_chain_struct
*current_space
;
554 static ssd_chain_struct
*current_subspace
;
556 /* Root of the call_info chain. */
557 static struct call_info
*call_info_root
;
559 /* The last call_info (for functions) structure
560 seen so it can be associated with fixups and
562 static struct call_info
*last_call_info
;
564 /* The last call description (for actual calls). */
565 static struct call_desc last_call_desc
;
567 /* Relaxation isn't supported for the PA yet. */
568 const relax_typeS md_relax_table
[] =
571 /* Jumps are always the same size -- one instruction. */
572 int md_short_jump_size
= 4;
573 int md_long_jump_size
= 4;
575 /* handle of the OPCODE hash table */
576 static struct hash_control
*op_hash
= NULL
;
578 /* This array holds the chars that always start a comment. If the
579 pre-processor is disabled, these aren't very useful. */
580 const char comment_chars
[] = ";";
582 /* Table of pseudo ops for the PA. FIXME -- how many of these
583 are now redundant with the overall GAS and the object file
585 const pseudo_typeS md_pseudo_table
[] =
587 /* align pseudo-ops on the PA specify the actual alignment requested,
588 not the log2 of the requested alignment. */
589 {"align", s_align_bytes
, 8},
590 {"block", pa_block
, 1},
591 {"blockz", pa_block
, 0},
592 {"byte", pa_cons
, 1},
593 {"call", pa_call
, 0},
594 {"callinfo", pa_callinfo
, 0},
595 {"code", pa_code
, 0},
596 {"comm", pa_comm
, 0},
597 {"copyright", pa_copyright
, 0},
598 {"data", pa_data
, 0},
599 {"double", pa_float_cons
, 'd'},
601 {"enter", pa_enter
, 0},
602 {"entry", pa_entry
, 0},
604 {"exit", pa_exit
, 0},
605 {"export", pa_export
, 0},
606 {"fill", pa_fill
, 0},
607 {"float", pa_float_cons
, 'f'},
608 {"half", pa_cons
, 2},
609 {"import", pa_import
, 0},
611 {"label", pa_label
, 0},
612 {"lcomm", pa_lcomm
, 0},
613 {"leave", pa_leave
, 0},
614 {"long", pa_cons
, 4},
615 {"lsym", pa_lsym
, 0},
616 {"octa", pa_cons
, 16},
617 {"org", pa_origin
, 0},
618 {"origin", pa_origin
, 0},
619 {"param", pa_param
, 0},
620 {"proc", pa_proc
, 0},
621 {"procend", pa_procend
, 0},
622 {"quad", pa_cons
, 8},
624 {"short", pa_cons
, 2},
625 {"single", pa_float_cons
, 'f'},
626 {"space", pa_space
, 0},
627 {"spnum", pa_spnum
, 0},
628 {"string", pa_stringer
, 0},
629 {"stringz", pa_stringer
, 1},
630 {"subspa", pa_subspace
, 0},
631 {"text", pa_text
, 0},
632 {"version", pa_version
, 0},
633 {"word", pa_cons
, 4},
637 /* This array holds the chars that only start a comment at the beginning of
638 a line. If the line seems to have the form '# 123 filename'
639 .line and .file directives will appear in the pre-processed output.
641 Note that input_file.c hand checks for '#' at the beginning of the
642 first line of the input file. This is because the compiler outputs
643 #NO_APP at the beginning of its output.
645 Also note that '/*' will always start a comment. */
646 const char line_comment_chars
[] = "#";
648 /* This array holds the characters which act as line separators. */
649 const char line_separator_chars
[] = "!";
651 /* Chars that can be used to separate mant from exp in floating point nums. */
652 const char EXP_CHARS
[] = "eE";
654 /* Chars that mean this number is a floating point constant.
655 As in 0f12.456 or 0d1.2345e12.
657 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
658 changed in read.c. Ideally it shouldn't hae to know abou it at
659 all, but nothing is ideal around here. */
660 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
662 static struct pa_it the_insn
;
664 /* Points to the end of an expression just parsed by get_expressoin
665 and friends. FIXME. This shouldn't be handled with a file-global
667 static char *expr_end
;
669 /* Nonzero if a .callinfo appeared within the current procedure. */
670 static int callinfo_found
;
672 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
673 static int within_entry_exit
;
675 /* Nonzero if the assembler is currently within a procedure definition. */
676 static int within_procedure
;
678 /* Handle on strucutre which keep track of the last symbol
679 seen in each subspace. */
680 static label_symbol_struct
*label_symbols_rootp
= NULL
;
682 /* Holds the last field selector. */
683 static int hppa_field_selector
;
685 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
686 static symbolS
*dummy_symbol
;
688 /* Nonzero if errors are to be printed. */
689 static int print_errors
= 1;
691 /* List of registers that are pre-defined:
693 Each general register has one predefined name of the form
694 %r<REGNUM> which has the value <REGNUM>.
696 Space and control registers are handled in a similar manner,
697 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
699 Likewise for the floating point registers, but of the form
700 %fr<REGNUM>. Floating point registers have additional predefined
701 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
702 again have the value <REGNUM>.
704 Many registers also have synonyms:
706 %r26 - %r23 have %arg0 - %arg3 as synonyms
707 %r28 - %r29 have %ret0 - %ret1 as synonyms
708 %r30 has %sp as a synonym
709 %r27 has %dp as a synonym
710 %r2 has %rp as a synonym
712 Almost every control register has a synonym; they are not listed
715 The table is sorted. Suitable for searching by a binary search. */
717 static const struct pd_reg pre_defined_registers
[] =
917 /* This table is sorted by order of the length of the string. This is
918 so we check for <> before we check for <. If we had a <> and checked
919 for < first, we would get a false match. */
920 static const struct fp_cond_map fp_cond_map
[] =
956 static const struct selector_entry selector_table
[] =
975 /* default space and subspace dictionaries */
977 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
978 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
980 /* pre-defined subsegments (subspaces) for the HPPA. */
981 #define SUBSEG_CODE 0
982 #define SUBSEG_DATA 0
985 #define SUBSEG_UNWIND 3
986 #define SUBSEG_GDB_STRINGS 0
987 #define SUBSEG_GDB_SYMBOLS 1
989 static struct default_subspace_dict pa_def_subspaces
[] =
991 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
992 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
993 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
994 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
996 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
998 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1001 static struct default_space_dict pa_def_spaces
[] =
1003 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1004 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1005 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1008 /* Misc local definitions used by the assembler. */
1010 /* Return nonzero if the string pointed to by S potentially represents
1011 a right or left half of a FP register */
1012 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1013 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1015 /* These macros are used to maintain spaces/subspaces. */
1016 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1017 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1018 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1019 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1021 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1022 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1024 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1025 main loop after insertion. */
1027 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1029 ((OPCODE) |= (FIELD) << (START)); \
1033 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1034 IGNORE is used to suppress the error message. */
1036 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1038 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1041 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1047 #define is_DP_relative(exp) \
1048 ((exp).X_op == O_subtract \
1049 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1051 #define is_PC_relative(exp) \
1052 ((exp).X_op == O_subtract \
1053 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1055 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1056 always be able to reduce the expression to a constant, so we don't
1057 need real complex handling yet. */
1058 #define is_complex(exp) \
1059 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1061 /* Actual functions to implement the PA specific code for the assembler. */
1063 /* Returns a pointer to the label_symbol_struct for the current space.
1064 or NULL if no label_symbol_struct exists for the current space. */
1066 static label_symbol_struct
*
1069 label_symbol_struct
*label_chain
;
1070 sd_chain_struct
*space_chain
= current_space
;
1072 for (label_chain
= label_symbols_rootp
;
1074 label_chain
= label_chain
->lss_next
)
1075 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1081 /* Defines a label for the current space. If one is already defined,
1082 this function will replace it with the new label. */
1085 pa_define_label (symbol
)
1088 label_symbol_struct
*label_chain
= pa_get_label ();
1089 sd_chain_struct
*space_chain
= current_space
;
1092 label_chain
->lss_label
= symbol
;
1095 /* Create a new label entry and add it to the head of the chain. */
1097 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1098 label_chain
->lss_label
= symbol
;
1099 label_chain
->lss_space
= space_chain
;
1100 label_chain
->lss_next
= NULL
;
1102 if (label_symbols_rootp
)
1103 label_chain
->lss_next
= label_symbols_rootp
;
1105 label_symbols_rootp
= label_chain
;
1109 /* Removes a label definition for the current space.
1110 If there is no label_symbol_struct entry, then no action is taken. */
1113 pa_undefine_label ()
1115 label_symbol_struct
*label_chain
;
1116 label_symbol_struct
*prev_label_chain
= NULL
;
1117 sd_chain_struct
*space_chain
= current_space
;
1119 for (label_chain
= label_symbols_rootp
;
1121 label_chain
= label_chain
->lss_next
)
1123 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1125 /* Remove the label from the chain and free its memory. */
1126 if (prev_label_chain
)
1127 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1129 label_symbols_rootp
= label_chain
->lss_next
;
1134 prev_label_chain
= label_chain
;
1139 /* An HPPA-specific version of fix_new. This is required because the HPPA
1140 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1141 results in the creation of an instance of an hppa_fix_struct. An
1142 hppa_fix_struct stores the extra information along with a pointer to the
1143 original fixS. This is attached to the original fixup via the
1144 tc_fix_data field. */
1147 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1148 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1152 symbolS
*add_symbol
;
1156 bfd_reloc_code_real_type r_type
;
1157 enum hppa_reloc_field_selector_type r_field
;
1164 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1165 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1168 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1170 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1171 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1172 hppa_fix
->fx_r_type
= r_type
;
1173 hppa_fix
->fx_r_field
= r_field
;
1174 hppa_fix
->fx_r_format
= r_format
;
1175 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1176 hppa_fix
->segment
= now_seg
;
1179 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1181 /* If necessary call BFD backend function to attach the
1182 unwind bits to the target dependent parts of a BFD symbol.
1184 #ifdef obj_attach_unwind_info
1185 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1189 /* foo-$global$ is used to access non-automatic storage. $global$
1190 is really just a marker and has served its purpose, so eliminate
1191 it now so as not to confuse write.c. */
1192 if (new_fix
->fx_subsy
1193 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1194 new_fix
->fx_subsy
= NULL
;
1197 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1198 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1201 parse_cons_expression_hppa (exp
)
1204 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1208 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1209 hppa_field_selector is set by the parse_cons_expression_hppa. */
1212 cons_fix_new_hppa (frag
, where
, size
, exp
)
1218 unsigned int rel_type
;
1220 /* Get a base relocation type. */
1221 if (is_DP_relative (*exp
))
1222 rel_type
= R_HPPA_GOTOFF
;
1223 else if (is_complex (*exp
))
1224 rel_type
= R_HPPA_COMPLEX
;
1228 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1229 as_warn ("Invalid field selector. Assuming F%%.");
1231 fix_new_hppa (frag
, where
, size
,
1232 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1233 hppa_field_selector
, 32, 0, (char *) 0);
1235 /* Reset field selector to its default state. */
1236 hppa_field_selector
= 0;
1239 /* This function is called once, at assembler startup time. It should
1240 set up all the tables, etc. that the MD part of the assembler will need. */
1245 const char *retval
= NULL
;
1249 last_call_info
= NULL
;
1250 call_info_root
= NULL
;
1252 /* Folding of text and data segments fails miserably on the PA.
1253 Warn user and disable "-R" option. */
1254 if (flag_readonly_data_in_text
)
1256 as_warn ("-R option not supported on this target.");
1257 flag_readonly_data_in_text
= 0;
1262 op_hash
= hash_new ();
1264 while (i
< NUMOPCODES
)
1266 const char *name
= pa_opcodes
[i
].name
;
1267 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1268 if (retval
!= NULL
&& *retval
!= '\0')
1270 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1275 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1276 != pa_opcodes
[i
].match
)
1278 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1279 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1284 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1288 as_fatal ("Broken assembler. No assembly attempted.");
1290 /* SOM will change text_section. To make sure we never put
1291 anything into the old one switch to the new one now. */
1292 subseg_set (text_section
, 0);
1294 dummy_symbol
= symbol_find_or_make ("L$dummy");
1295 S_SET_SEGMENT (dummy_symbol
, text_section
);
1298 /* Assemble a single instruction storing it into a frag. */
1305 /* The had better be something to assemble. */
1308 /* If we are within a procedure definition, make sure we've
1309 defined a label for the procedure; handle case where the
1310 label was defined after the .PROC directive.
1312 Note there's not need to diddle with the segment or fragment
1313 for the label symbol in this case. We have already switched
1314 into the new $CODE$ subspace at this point. */
1315 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1317 label_symbol_struct
*label_symbol
= pa_get_label ();
1321 if (label_symbol
->lss_label
)
1323 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1324 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1326 /* Also handle allocation of a fixup to hold the unwind
1327 information when the label appears after the proc/procend. */
1328 if (within_entry_exit
)
1330 char *where
= frag_more (0);
1332 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1333 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
1334 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1335 (char *) &last_call_info
->ci_unwind
.descriptor
);
1340 as_bad ("Missing function name for .PROC (corrupted label chain)");
1343 as_bad ("Missing function name for .PROC");
1346 /* Assemble the instruction. Results are saved into "the_insn". */
1349 /* Get somewhere to put the assembled instrution. */
1352 /* Output the opcode. */
1353 md_number_to_chars (to
, the_insn
.opcode
, 4);
1355 /* If necessary output more stuff. */
1356 if (the_insn
.reloc
!= R_HPPA_NONE
)
1357 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1358 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1359 the_insn
.reloc
, the_insn
.field_selector
,
1360 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1363 /* Do the real work for assembling a single instruction. Store results
1364 into the global "the_insn" variable. */
1370 char *error_message
= "";
1371 char *s
, c
, *argstart
, *name
, *save_s
;
1375 int cmpltr
, nullif
, flag
, cond
, num
;
1376 unsigned long opcode
;
1377 struct pa_opcode
*insn
;
1379 /* Skip to something interesting. */
1380 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1399 as_bad ("Unknown opcode: `%s'", str
);
1405 /* Convert everything into lower case. */
1408 if (isupper (*save_s
))
1409 *save_s
= tolower (*save_s
);
1413 /* Look up the opcode in the has table. */
1414 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1416 as_bad ("Unknown opcode: `%s'", str
);
1425 /* Mark the location where arguments for the instruction start, then
1426 start processing them. */
1430 /* Do some initialization. */
1431 opcode
= insn
->match
;
1432 bzero (&the_insn
, sizeof (the_insn
));
1434 the_insn
.reloc
= R_HPPA_NONE
;
1436 /* Build the opcode, checking as we go to make
1437 sure that the operands match. */
1438 for (args
= insn
->args
;; ++args
)
1443 /* End of arguments. */
1459 /* These must match exactly. */
1468 /* Handle a 5 bit register or control register field at 10. */
1471 num
= pa_parse_number (&s
, 0);
1472 CHECK_FIELD (num
, 31, 0, 0);
1473 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1475 /* Handle a 5 bit register field at 15. */
1477 num
= pa_parse_number (&s
, 0);
1478 CHECK_FIELD (num
, 31, 0, 0);
1479 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1481 /* Handle a 5 bit register field at 31. */
1484 num
= pa_parse_number (&s
, 0);
1485 CHECK_FIELD (num
, 31, 0, 0);
1486 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1488 /* Handle a 5 bit field length at 31. */
1490 num
= pa_get_absolute_expression (&the_insn
, &s
);
1492 CHECK_FIELD (num
, 32, 1, 0);
1493 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1495 /* Handle a 5 bit immediate at 15. */
1497 num
= pa_get_absolute_expression (&the_insn
, &s
);
1499 CHECK_FIELD (num
, 15, -16, 0);
1500 low_sign_unext (num
, 5, &num
);
1501 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1503 /* Handle a 5 bit immediate at 31. */
1505 num
= pa_get_absolute_expression (&the_insn
, &s
);
1507 CHECK_FIELD (num
, 15, -16, 0)
1508 low_sign_unext (num
, 5, &num
);
1509 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1511 /* Handle an unsigned 5 bit immediate at 31. */
1513 num
= pa_get_absolute_expression (&the_insn
, &s
);
1515 CHECK_FIELD (num
, 31, 0, 0);
1516 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1518 /* Handle an unsigned 5 bit immediate at 15. */
1520 num
= pa_get_absolute_expression (&the_insn
, &s
);
1522 CHECK_FIELD (num
, 31, 0, 0);
1523 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1525 /* Handle a 2 bit space identifier at 17. */
1527 num
= pa_parse_number (&s
, 0);
1528 CHECK_FIELD (num
, 3, 0, 1);
1529 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1531 /* Handle a 3 bit space identifier at 18. */
1533 num
= pa_parse_number (&s
, 0);
1534 CHECK_FIELD (num
, 7, 0, 1);
1535 dis_assemble_3 (num
, &num
);
1536 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1538 /* Handle a completer for an indexing load or store. */
1544 while (*s
== ',' && i
< 2)
1547 if (strncasecmp (s
, "sm", 2) == 0)
1554 else if (strncasecmp (s
, "m", 1) == 0)
1556 else if (strncasecmp (s
, "s", 1) == 0)
1559 as_bad ("Invalid Indexed Load Completer.");
1564 as_bad ("Invalid Indexed Load Completer Syntax.");
1566 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1569 /* Handle a short load/store completer. */
1577 if (strncasecmp (s
, "ma", 2) == 0)
1582 else if (strncasecmp (s
, "mb", 2) == 0)
1588 as_bad ("Invalid Short Load/Store Completer.");
1592 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1595 /* Handle a stbys completer. */
1601 while (*s
== ',' && i
< 2)
1604 if (strncasecmp (s
, "m", 1) == 0)
1606 else if (strncasecmp (s
, "b", 1) == 0)
1608 else if (strncasecmp (s
, "e", 1) == 0)
1611 as_bad ("Invalid Store Bytes Short Completer");
1616 as_bad ("Invalid Store Bytes Short Completer");
1618 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1621 /* Handle a non-negated compare/stubtract condition. */
1623 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1626 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1629 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1631 /* Handle a negated or non-negated compare/subtract condition. */
1634 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1638 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1641 as_bad ("Invalid Compare/Subtract Condition.");
1646 /* Negated condition requires an opcode change. */
1650 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1652 /* Handle non-negated add condition. */
1654 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1657 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1660 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1662 /* Handle a negated or non-negated add condition. */
1665 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1669 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1672 as_bad ("Invalid Compare/Subtract Condition");
1677 /* Negated condition requires an opcode change. */
1681 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1683 /* Handle a compare/subtract condition. */
1690 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1695 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1698 as_bad ("Invalid Compare/Subtract Condition");
1702 opcode
|= cmpltr
<< 13;
1703 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1705 /* Handle a non-negated add condition. */
1714 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1718 if (strcmp (name
, "=") == 0)
1720 else if (strcmp (name
, "<") == 0)
1722 else if (strcmp (name
, "<=") == 0)
1724 else if (strcasecmp (name
, "nuv") == 0)
1726 else if (strcasecmp (name
, "znv") == 0)
1728 else if (strcasecmp (name
, "sv") == 0)
1730 else if (strcasecmp (name
, "od") == 0)
1732 else if (strcasecmp (name
, "n") == 0)
1734 else if (strcasecmp (name
, "tr") == 0)
1739 else if (strcmp (name
, "<>") == 0)
1744 else if (strcmp (name
, ">=") == 0)
1749 else if (strcmp (name
, ">") == 0)
1754 else if (strcasecmp (name
, "uv") == 0)
1759 else if (strcasecmp (name
, "vnz") == 0)
1764 else if (strcasecmp (name
, "nsv") == 0)
1769 else if (strcasecmp (name
, "ev") == 0)
1775 as_bad ("Invalid Add Condition: %s", name
);
1778 nullif
= pa_parse_nullif (&s
);
1779 opcode
|= nullif
<< 1;
1780 opcode
|= cmpltr
<< 13;
1781 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1783 /* HANDLE a logical instruction condition. */
1791 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1795 if (strcmp (name
, "=") == 0)
1797 else if (strcmp (name
, "<") == 0)
1799 else if (strcmp (name
, "<=") == 0)
1801 else if (strcasecmp (name
, "od") == 0)
1803 else if (strcasecmp (name
, "tr") == 0)
1808 else if (strcmp (name
, "<>") == 0)
1813 else if (strcmp (name
, ">=") == 0)
1818 else if (strcmp (name
, ">") == 0)
1823 else if (strcasecmp (name
, "ev") == 0)
1829 as_bad ("Invalid Logical Instruction Condition.");
1832 opcode
|= cmpltr
<< 13;
1833 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1835 /* Handle a unit instruction condition. */
1842 if (strncasecmp (s
, "sbz", 3) == 0)
1847 else if (strncasecmp (s
, "shz", 3) == 0)
1852 else if (strncasecmp (s
, "sdc", 3) == 0)
1857 else if (strncasecmp (s
, "sbc", 3) == 0)
1862 else if (strncasecmp (s
, "shc", 3) == 0)
1867 else if (strncasecmp (s
, "tr", 2) == 0)
1873 else if (strncasecmp (s
, "nbz", 3) == 0)
1879 else if (strncasecmp (s
, "nhz", 3) == 0)
1885 else if (strncasecmp (s
, "ndc", 3) == 0)
1891 else if (strncasecmp (s
, "nbc", 3) == 0)
1897 else if (strncasecmp (s
, "nhc", 3) == 0)
1904 as_bad ("Invalid Logical Instruction Condition.");
1906 opcode
|= cmpltr
<< 13;
1907 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1909 /* Handle a shift/extract/deposit condition. */
1917 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1921 if (strcmp (name
, "=") == 0)
1923 else if (strcmp (name
, "<") == 0)
1925 else if (strcasecmp (name
, "od") == 0)
1927 else if (strcasecmp (name
, "tr") == 0)
1929 else if (strcmp (name
, "<>") == 0)
1931 else if (strcmp (name
, ">=") == 0)
1933 else if (strcasecmp (name
, "ev") == 0)
1935 /* Handle movb,n. Put things back the way they were.
1936 This includes moving s back to where it started. */
1937 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1944 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1947 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1949 /* Handle bvb and bb conditions. */
1955 if (strncmp (s
, "<", 1) == 0)
1960 else if (strncmp (s
, ">=", 2) == 0)
1966 as_bad ("Invalid Bit Branch Condition: %c", *s
);
1968 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1970 /* Handle a system control completer. */
1972 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
1980 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1982 /* Handle a nullification completer for branch instructions. */
1984 nullif
= pa_parse_nullif (&s
);
1985 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
1987 /* Handle a nullification completer for copr and spop insns. */
1989 nullif
= pa_parse_nullif (&s
);
1990 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
1992 /* Handle a 11 bit immediate at 31. */
1994 the_insn
.field_selector
= pa_chk_field_selector (&s
);
1997 if (the_insn
.exp
.X_op
== O_constant
)
1999 num
= evaluate_absolute (&the_insn
);
2000 CHECK_FIELD (num
, 1023, -1024, 0);
2001 low_sign_unext (num
, 11, &num
);
2002 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2006 if (is_DP_relative (the_insn
.exp
))
2007 the_insn
.reloc
= R_HPPA_GOTOFF
;
2008 else if (is_PC_relative (the_insn
.exp
))
2009 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2011 the_insn
.reloc
= R_HPPA
;
2012 the_insn
.format
= 11;
2016 /* Handle a 14 bit immediate at 31. */
2018 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2021 if (the_insn
.exp
.X_op
== O_constant
)
2023 num
= evaluate_absolute (&the_insn
);
2024 CHECK_FIELD (num
, 8191, -8192, 0);
2025 low_sign_unext (num
, 14, &num
);
2026 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2030 if (is_DP_relative (the_insn
.exp
))
2031 the_insn
.reloc
= R_HPPA_GOTOFF
;
2032 else if (is_PC_relative (the_insn
.exp
))
2033 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2035 the_insn
.reloc
= R_HPPA
;
2036 the_insn
.format
= 14;
2040 /* Handle a 21 bit immediate at 31. */
2042 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2045 if (the_insn
.exp
.X_op
== O_constant
)
2047 num
= evaluate_absolute (&the_insn
);
2048 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2049 dis_assemble_21 (num
, &num
);
2050 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2054 if (is_DP_relative (the_insn
.exp
))
2055 the_insn
.reloc
= R_HPPA_GOTOFF
;
2056 else if (is_PC_relative (the_insn
.exp
))
2057 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2059 the_insn
.reloc
= R_HPPA
;
2060 the_insn
.format
= 21;
2064 /* Handle a 12 bit branch displacement. */
2066 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2070 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2072 unsigned int w1
, w
, result
;
2074 num
= evaluate_absolute (&the_insn
);
2077 as_bad ("Branch to unaligned address");
2080 CHECK_FIELD (num
, 8191, -8192, 0);
2081 sign_unext ((num
- 8) >> 2, 12, &result
);
2082 dis_assemble_12 (result
, &w1
, &w
);
2083 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2087 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2088 the_insn
.format
= 12;
2089 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2090 bzero (&last_call_desc
, sizeof (struct call_desc
));
2095 /* Handle a 17 bit branch displacement. */
2097 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2101 if (!the_insn
.exp
.X_add_symbol
2102 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2105 unsigned int w2
, w1
, w
, result
;
2107 num
= evaluate_absolute (&the_insn
);
2110 as_bad ("Branch to unaligned address");
2113 CHECK_FIELD (num
, 262143, -262144, 0);
2115 if (the_insn
.exp
.X_add_symbol
)
2118 sign_unext (num
>> 2, 17, &result
);
2119 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2120 INSERT_FIELD_AND_CONTINUE (opcode
,
2121 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2125 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2126 the_insn
.format
= 17;
2127 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2128 bzero (&last_call_desc
, sizeof (struct call_desc
));
2132 /* Handle an absolute 17 bit branch target. */
2134 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2138 if (!the_insn
.exp
.X_add_symbol
2139 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2142 unsigned int w2
, w1
, w
, result
;
2144 num
= evaluate_absolute (&the_insn
);
2147 as_bad ("Branch to unaligned address");
2150 CHECK_FIELD (num
, 262143, -262144, 0);
2152 if (the_insn
.exp
.X_add_symbol
)
2155 sign_unext (num
>> 2, 17, &result
);
2156 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2157 INSERT_FIELD_AND_CONTINUE (opcode
,
2158 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2162 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2163 the_insn
.format
= 17;
2167 /* Handle a 5 bit shift count at 26. */
2169 num
= pa_get_absolute_expression (&the_insn
, &s
);
2171 CHECK_FIELD (num
, 31, 0, 0);
2172 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2174 /* Handle a 5 bit bit position at 26. */
2176 num
= pa_get_absolute_expression (&the_insn
, &s
);
2178 CHECK_FIELD (num
, 31, 0, 0);
2179 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2181 /* Handle a 5 bit immediate at 10. */
2183 num
= pa_get_absolute_expression (&the_insn
, &s
);
2185 CHECK_FIELD (num
, 31, 0, 0);
2186 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2188 /* Handle a 13 bit immediate at 18. */
2190 num
= pa_get_absolute_expression (&the_insn
, &s
);
2192 CHECK_FIELD (num
, 8191, 0, 0);
2193 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2195 /* Handle a 26 bit immediate at 31. */
2197 num
= pa_get_absolute_expression (&the_insn
, &s
);
2199 CHECK_FIELD (num
, 671108864, 0, 0);
2200 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2202 /* Handle a 3 bit SFU identifier at 25. */
2205 as_bad ("Invalid SFU identifier");
2206 num
= pa_get_absolute_expression (&the_insn
, &s
);
2208 CHECK_FIELD (num
, 7, 0, 0);
2209 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2211 /* Handle a 20 bit SOP field for spop0. */
2213 num
= pa_get_absolute_expression (&the_insn
, &s
);
2215 CHECK_FIELD (num
, 1048575, 0, 0);
2216 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2217 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2219 /* Handle a 15bit SOP field for spop1. */
2221 num
= pa_get_absolute_expression (&the_insn
, &s
);
2223 CHECK_FIELD (num
, 32767, 0, 0);
2224 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2226 /* Handle a 10bit SOP field for spop3. */
2228 num
= pa_get_absolute_expression (&the_insn
, &s
);
2230 CHECK_FIELD (num
, 1023, 0, 0);
2231 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2232 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2234 /* Handle a 15 bit SOP field for spop2. */
2236 num
= pa_get_absolute_expression (&the_insn
, &s
);
2238 CHECK_FIELD (num
, 32767, 0, 0);
2239 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2240 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2242 /* Handle a 3-bit co-processor ID field. */
2245 as_bad ("Invalid COPR identifier");
2246 num
= pa_get_absolute_expression (&the_insn
, &s
);
2248 CHECK_FIELD (num
, 7, 0, 0);
2249 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2251 /* Handle a 22bit SOP field for copr. */
2253 num
= pa_get_absolute_expression (&the_insn
, &s
);
2255 CHECK_FIELD (num
, 4194303, 0, 0);
2256 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2257 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2259 /* Handle a source FP operand format completer. */
2261 flag
= pa_parse_fp_format (&s
);
2262 the_insn
.fpof1
= flag
;
2263 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2265 /* Handle a destination FP operand format completer. */
2267 /* pa_parse_format needs the ',' prefix. */
2269 flag
= pa_parse_fp_format (&s
);
2270 the_insn
.fpof2
= flag
;
2271 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2273 /* Handle FP compare conditions. */
2275 cond
= pa_parse_fp_cmp_cond (&s
);
2276 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2278 /* Handle L/R register halves like 't'. */
2281 struct pa_89_fp_reg_struct result
;
2283 pa_parse_number (&s
, &result
);
2284 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2285 opcode
|= result
.number_part
;
2287 /* 0x30 opcodes are FP arithmetic operation opcodes
2288 and need to be turned into 0x38 opcodes. This
2289 is not necessary for loads/stores. */
2290 if (need_89_opcode (&the_insn
, &result
)
2291 && ((opcode
& 0xfc000000) == 0x30000000))
2294 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2297 /* Handle L/R register halves like 'b'. */
2300 struct pa_89_fp_reg_struct result
;
2302 pa_parse_number (&s
, &result
);
2303 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2304 opcode
|= result
.number_part
<< 21;
2305 if (need_89_opcode (&the_insn
, &result
))
2307 opcode
|= (result
.l_r_select
& 1) << 7;
2313 /* Handle L/R register halves like 'x'. */
2316 struct pa_89_fp_reg_struct result
;
2318 pa_parse_number (&s
, &result
);
2319 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2320 opcode
|= (result
.number_part
& 0x1f) << 16;
2321 if (need_89_opcode (&the_insn
, &result
))
2323 opcode
|= (result
.l_r_select
& 1) << 12;
2329 /* Handle a 5 bit register field at 10. */
2332 struct pa_89_fp_reg_struct result
;
2334 pa_parse_number (&s
, &result
);
2335 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2336 if (the_insn
.fpof1
== SGL
)
2338 result
.number_part
&= 0xF;
2339 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2341 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2344 /* Handle a 5 bit register field at 15. */
2347 struct pa_89_fp_reg_struct result
;
2349 pa_parse_number (&s
, &result
);
2350 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2351 if (the_insn
.fpof1
== SGL
)
2353 result
.number_part
&= 0xF;
2354 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2356 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2359 /* Handle a 5 bit register field at 31. */
2362 struct pa_89_fp_reg_struct result
;
2364 pa_parse_number (&s
, &result
);
2365 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2366 if (the_insn
.fpof1
== SGL
)
2368 result
.number_part
&= 0xF;
2369 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2371 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2374 /* Handle a 5 bit register field at 20. */
2377 struct pa_89_fp_reg_struct result
;
2379 pa_parse_number (&s
, &result
);
2380 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2381 if (the_insn
.fpof1
== SGL
)
2383 result
.number_part
&= 0xF;
2384 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2386 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2389 /* Handle a 5 bit register field at 25. */
2392 struct pa_89_fp_reg_struct result
;
2394 pa_parse_number (&s
, &result
);
2395 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2396 if (the_insn
.fpof1
== SGL
)
2398 result
.number_part
&= 0xF;
2399 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2401 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2404 /* Handle a floating point operand format at 26.
2405 Only allows single and double precision. */
2407 flag
= pa_parse_fp_format (&s
);
2413 the_insn
.fpof1
= flag
;
2419 as_bad ("Invalid Floating Point Operand Format.");
2429 /* Check if the args matched. */
2432 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2433 && !strcmp (insn
->name
, insn
[1].name
))
2441 as_bad ("Invalid operands %s", error_message
);
2448 the_insn
.opcode
= opcode
;
2451 /* Turn a string in input_line_pointer into a floating point constant of type
2452 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2453 emitted is stored in *sizeP . An error message or NULL is returned. */
2455 #define MAX_LITTLENUMS 6
2458 md_atof (type
, litP
, sizeP
)
2464 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2465 LITTLENUM_TYPE
*wordP
;
2497 return "Bad call to MD_ATOF()";
2499 t
= atof_ieee (input_line_pointer
, type
, words
);
2501 input_line_pointer
= t
;
2502 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2503 for (wordP
= words
; prec
--;)
2505 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2506 litP
+= sizeof (LITTLENUM_TYPE
);
2511 /* Write out big-endian. */
2514 md_number_to_chars (buf
, val
, n
)
2519 number_to_chars_bigendian (buf
, val
, n
);
2522 /* Translate internal representation of relocation info to BFD target
2526 tc_gen_reloc (section
, fixp
)
2531 struct hppa_fix_struct
*hppa_fixp
;
2532 bfd_reloc_code_real_type code
;
2533 static arelent
*no_relocs
= NULL
;
2535 bfd_reloc_code_real_type
**codes
;
2539 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2540 if (fixp
->fx_addsy
== 0)
2542 assert (hppa_fixp
!= 0);
2543 assert (section
!= 0);
2545 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2546 assert (reloc
!= 0);
2548 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2549 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2551 hppa_fixp
->fx_r_format
,
2552 hppa_fixp
->fx_r_field
);
2554 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2557 relocs
= (arelent
**)
2558 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2559 assert (relocs
!= 0);
2561 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2562 sizeof (arelent
) * n_relocs
);
2564 assert (reloc
!= 0);
2566 for (i
= 0; i
< n_relocs
; i
++)
2567 relocs
[i
] = &reloc
[i
];
2569 relocs
[n_relocs
] = NULL
;
2572 switch (fixp
->fx_r_type
)
2575 assert (n_relocs
== 1);
2579 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2580 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2581 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2582 reloc
->addend
= 0; /* default */
2584 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2586 /* Now, do any processing that is dependent on the relocation type. */
2589 case R_PARISC_DLTREL21L
:
2590 case R_PARISC_DLTREL14R
:
2591 case R_PARISC_DLTREL14F
:
2592 case R_PARISC_PLABEL32
:
2593 case R_PARISC_PLABEL21L
:
2594 case R_PARISC_PLABEL14R
:
2595 /* For plabel relocations, the addend of the
2596 relocation should be either 0 (no static link) or 2
2597 (static link required).
2599 FIXME: We always assume no static link!
2601 We also slam a zero addend into the DLT relative relocs;
2602 it doesn't make a lot of sense to use any addend since
2603 it gets you a different (eg unknown) DLT entry. */
2607 case R_PARISC_PCREL21L
:
2608 case R_PARISC_PCREL17R
:
2609 case R_PARISC_PCREL17F
:
2610 case R_PARISC_PCREL17C
:
2611 case R_PARISC_PCREL14R
:
2612 case R_PARISC_PCREL14F
:
2613 /* The constant is stored in the instruction. */
2614 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2617 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2620 reloc
->addend
= fixp
->fx_addnumber
;
2627 /* Walk over reach relocation returned by the BFD backend. */
2628 for (i
= 0; i
< n_relocs
; i
++)
2632 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2633 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2634 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2640 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2646 /* For plabel relocations, the addend of the
2647 relocation should be either 0 (no static link) or 2
2648 (static link required).
2650 FIXME: We always assume no static link!
2652 We also slam a zero addend into the DLT relative relocs;
2653 it doesn't make a lot of sense to use any addend since
2654 it gets you a different (eg unknown) DLT entry. */
2655 relocs
[i
]->addend
= 0;
2666 /* There is no symbol or addend associated with these fixups. */
2667 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2668 relocs
[i
]->addend
= 0;
2672 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2673 relocs
[i
]->addend
= 0;
2675 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2684 /* Process any machine dependent frag types. */
2687 md_convert_frag (abfd
, sec
, fragP
)
2689 register asection
*sec
;
2690 register fragS
*fragP
;
2692 unsigned int address
;
2694 if (fragP
->fr_type
== rs_machine_dependent
)
2696 switch ((int) fragP
->fr_subtype
)
2699 fragP
->fr_type
= rs_fill
;
2700 know (fragP
->fr_var
== 1);
2701 know (fragP
->fr_next
);
2702 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2703 if (address
% fragP
->fr_offset
)
2706 fragP
->fr_next
->fr_address
2711 fragP
->fr_offset
= 0;
2717 /* Round up a section size to the appropriate boundary. */
2720 md_section_align (segment
, size
)
2724 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2725 int align2
= (1 << align
) - 1;
2727 return (size
+ align2
) & ~align2
;
2730 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2732 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2734 addressT from_addr
, to_addr
;
2738 fprintf (stderr
, "pa_create_short_jmp\n");
2742 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2744 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2746 addressT from_addr
, to_addr
;
2750 fprintf (stderr
, "pa_create_long_jump\n");
2754 /* Return the approximate size of a frag before relaxation has occurred. */
2756 md_estimate_size_before_relax (fragP
, segment
)
2757 register fragS
*fragP
;
2764 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2770 CONST
char *md_shortopts
= "";
2771 struct option md_longopts
[] = {
2772 {NULL
, no_argument
, NULL
, 0}
2774 size_t md_longopts_size
= sizeof(md_longopts
);
2777 md_parse_option (c
, arg
)
2785 md_show_usage (stream
)
2790 /* We have no need to default values of symbols. */
2793 md_undefined_symbol (name
)
2799 /* Parse an operand that is machine-specific.
2800 We just return without modifying the expression as we have nothing
2804 md_operand (expressionP
)
2805 expressionS
*expressionP
;
2809 /* Apply a fixup to an instruction. */
2812 md_apply_fix (fixP
, valp
)
2816 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2817 struct hppa_fix_struct
*hppa_fixP
;
2818 long new_val
, result
;
2819 unsigned int w1
, w2
, w
;
2822 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2823 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2824 never be "applied" (they are just markers). */
2826 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2827 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2831 /* There should have been an HPPA specific fixup associated
2832 with the GAS fixup. */
2835 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2836 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2838 if (fixP
->fx_r_type
== R_HPPA_NONE
)
2841 /* Remember this value for emit_reloc. FIXME, is this braindamage
2842 documented anywhere!?! */
2843 fixP
->fx_addnumber
= val
;
2845 /* Check if this is an undefined symbol. No relocation can
2846 possibly be performed in this case.
2848 Also avoid doing anything for pc-relative fixups in which the
2849 fixup is in a different space than the symbol it references. */
2850 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
2852 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
)
2855 && S_GET_SEGMENT (fixP
->fx_addsy
) != hppa_fixP
->segment
)
2858 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2861 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
2862 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
2863 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
2864 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
2865 && hppa_fixP
->fx_r_field
!= R_HPPA_TSEL
2866 && hppa_fixP
->fx_r_field
!= R_HPPA_LTSEL
2867 && hppa_fixP
->fx_r_field
!= R_HPPA_RTSEL
2868 && !(fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
))
2869 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
2875 /* Handle all opcodes with the 'j' operand type. */
2877 CHECK_FIELD (new_val
, 8191, -8192, 0);
2879 /* Mask off 14 bits to be changed. */
2880 bfd_put_32 (stdoutput
,
2881 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2883 low_sign_unext (new_val
, 14, &result
);
2886 /* Handle all opcodes with the 'k' operand type. */
2888 CHECK_FIELD (new_val
, 2097152, 0, 0);
2890 /* Mask off 21 bits to be changed. */
2891 bfd_put_32 (stdoutput
,
2892 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2894 dis_assemble_21 (new_val
, &result
);
2897 /* Handle all the opcodes with the 'i' operand type. */
2899 CHECK_FIELD (new_val
, 1023, -1023, 0);
2901 /* Mask off 11 bits to be changed. */
2902 bfd_put_32 (stdoutput
,
2903 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2905 low_sign_unext (new_val
, 11, &result
);
2908 /* Handle all the opcodes with the 'w' operand type. */
2910 CHECK_FIELD (new_val
, 8191, -8192, 0)
2912 /* Mask off 11 bits to be changed. */
2913 sign_unext ((new_val
- 8) >> 2, 12, &result
);
2914 bfd_put_32 (stdoutput
,
2915 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
2918 dis_assemble_12 (result
, &w1
, &w
);
2919 result
= ((w1
<< 2) | w
);
2922 /* Handle some of the opcodes with the 'W' operand type. */
2925 #define stub_needed(CALLER, CALLEE) \
2926 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2927 /* It is necessary to force PC-relative calls/jumps to have a
2928 relocation entry if they're going to need either a argument
2929 relocation or long call stub. FIXME. Can't we need the same
2930 for absolute calls? */
2932 && (stub_needed (((obj_symbol_type
*)
2933 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2934 hppa_fixP
->fx_arg_reloc
)))
2938 CHECK_FIELD (new_val
, 262143, -262144, 0);
2940 /* Mask off 17 bits to be changed. */
2941 bfd_put_32 (stdoutput
,
2942 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
2944 sign_unext ((new_val
- 8) >> 2, 17, &result
);
2945 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2946 result
= ((w2
<< 2) | (w1
<< 16) | w
);
2951 fixP
->fx_addnumber
= fixP
->fx_offset
;
2952 /* If we have a real relocation, then we want zero to
2953 be stored in the object file. If no relocation is going
2954 to be emitted, then we need to store new_val into the
2957 bfd_put_32 (stdoutput
, 0, buf
);
2959 bfd_put_32 (stdoutput
, new_val
, buf
);
2967 as_bad ("Unknown relocation encountered in md_apply_fix.");
2971 /* Insert the relocation. */
2972 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
2977 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
2978 (unsigned int) fixP
, fixP
->fx_r_type
);
2983 /* Exactly what point is a PC-relative offset relative TO?
2984 On the PA, they're relative to the address of the offset. */
2987 md_pcrel_from (fixP
)
2990 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2993 /* Return nonzero if the input line pointer is at the end of
2997 is_end_of_statement ()
2999 return ((*input_line_pointer
== '\n')
3000 || (*input_line_pointer
== ';')
3001 || (*input_line_pointer
== '!'));
3004 /* Read a number from S. The number might come in one of many forms,
3005 the most common will be a hex or decimal constant, but it could be
3006 a pre-defined register (Yuk!), or an absolute symbol.
3008 Return a number or -1 for failure.
3010 When parsing PA-89 FP register numbers RESULT will be
3011 the address of a structure to return information about
3012 L/R half of FP registers, store results there as appropriate.
3014 pa_parse_number can not handle negative constants and will fail
3015 horribly if it is passed such a constant. */
3018 pa_parse_number (s
, result
)
3020 struct pa_89_fp_reg_struct
*result
;
3029 /* Skip whitespace before the number. */
3030 while (*p
== ' ' || *p
== '\t')
3033 /* Store info in RESULT if requested by caller. */
3036 result
->number_part
= -1;
3037 result
->l_r_select
= -1;
3043 /* Looks like a number. */
3046 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3048 /* The number is specified in hex. */
3050 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3051 || ((*p
>= 'A') && (*p
<= 'F')))
3054 num
= num
* 16 + *p
- '0';
3055 else if (*p
>= 'a' && *p
<= 'f')
3056 num
= num
* 16 + *p
- 'a' + 10;
3058 num
= num
* 16 + *p
- 'A' + 10;
3064 /* The number is specified in decimal. */
3065 while (isdigit (*p
))
3067 num
= num
* 10 + *p
- '0';
3072 /* Store info in RESULT if requested by the caller. */
3075 result
->number_part
= num
;
3077 if (IS_R_SELECT (p
))
3079 result
->l_r_select
= 1;
3082 else if (IS_L_SELECT (p
))
3084 result
->l_r_select
= 0;
3088 result
->l_r_select
= 0;
3093 /* The number might be a predefined register. */
3098 /* Tege hack: Special case for general registers as the general
3099 code makes a binary search with case translation, and is VERY
3104 if (*p
== 'e' && *(p
+ 1) == 't'
3105 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3108 num
= *p
- '0' + 28;
3116 else if (!isdigit (*p
))
3119 as_bad ("Undefined register: '%s'.", name
);
3125 num
= num
* 10 + *p
++ - '0';
3126 while (isdigit (*p
));
3131 /* Do a normal register search. */
3132 while (is_part_of_name (c
))
3138 status
= reg_name_search (name
);
3144 as_bad ("Undefined register: '%s'.", name
);
3150 /* Store info in RESULT if requested by caller. */
3153 result
->number_part
= num
;
3154 if (IS_R_SELECT (p
- 1))
3155 result
->l_r_select
= 1;
3156 else if (IS_L_SELECT (p
- 1))
3157 result
->l_r_select
= 0;
3159 result
->l_r_select
= 0;
3164 /* And finally, it could be a symbol in the absolute section which
3165 is effectively a constant. */
3169 while (is_part_of_name (c
))
3175 if ((sym
= symbol_find (name
)) != NULL
)
3177 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3178 num
= S_GET_VALUE (sym
);
3182 as_bad ("Non-absolute symbol: '%s'.", name
);
3188 /* There is where we'd come for an undefined symbol
3189 or for an empty string. For an empty string we
3190 will return zero. That's a concession made for
3191 compatability with the braindamaged HP assemblers. */
3197 as_bad ("Undefined absolute constant: '%s'.", name
);
3203 /* Store info in RESULT if requested by caller. */
3206 result
->number_part
= num
;
3207 if (IS_R_SELECT (p
- 1))
3208 result
->l_r_select
= 1;
3209 else if (IS_L_SELECT (p
- 1))
3210 result
->l_r_select
= 0;
3212 result
->l_r_select
= 0;
3220 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3222 /* Given NAME, find the register number associated with that name, return
3223 the integer value associated with the given name or -1 on failure. */
3226 reg_name_search (name
)
3229 int middle
, low
, high
;
3233 high
= REG_NAME_CNT
- 1;
3237 middle
= (low
+ high
) / 2;
3238 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3244 return pre_defined_registers
[middle
].value
;
3246 while (low
<= high
);
3252 /* Return nonzero if the given INSN and L/R information will require
3253 a new PA-89 opcode. */
3256 need_89_opcode (insn
, result
)
3258 struct pa_89_fp_reg_struct
*result
;
3260 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3266 /* Parse a condition for a fcmp instruction. Return the numerical
3267 code associated with the condition. */
3270 pa_parse_fp_cmp_cond (s
)
3277 for (i
= 0; i
< 32; i
++)
3279 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3280 strlen (fp_cond_map
[i
].string
)) == 0)
3282 cond
= fp_cond_map
[i
].cond
;
3283 *s
+= strlen (fp_cond_map
[i
].string
);
3284 /* If not a complete match, back up the input string and
3286 if (**s
!= ' ' && **s
!= '\t')
3288 *s
-= strlen (fp_cond_map
[i
].string
);
3291 while (**s
== ' ' || **s
== '\t')
3297 as_bad ("Invalid FP Compare Condition: %s", *s
);
3299 /* Advance over the bogus completer. */
3300 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3306 /* Parse an FP operand format completer returning the completer
3309 static fp_operand_format
3310 pa_parse_fp_format (s
)
3319 if (strncasecmp (*s
, "sgl", 3) == 0)
3324 else if (strncasecmp (*s
, "dbl", 3) == 0)
3329 else if (strncasecmp (*s
, "quad", 4) == 0)
3336 format
= ILLEGAL_FMT
;
3337 as_bad ("Invalid FP Operand Format: %3s", *s
);
3344 /* Convert from a selector string into a selector type. */
3347 pa_chk_field_selector (str
)
3350 int middle
, low
, high
;
3354 /* Read past any whitespace. */
3355 /* FIXME: should we read past newlines and formfeeds??? */
3356 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3359 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3360 name
[0] = tolower ((*str
)[0]),
3362 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3363 name
[0] = tolower ((*str
)[0]),
3364 name
[1] = tolower ((*str
)[1]),
3370 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3374 middle
= (low
+ high
) / 2;
3375 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3382 *str
+= strlen (name
) + 1;
3383 return selector_table
[middle
].field_selector
;
3386 while (low
<= high
);
3391 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3394 get_expression (str
)
3400 save_in
= input_line_pointer
;
3401 input_line_pointer
= str
;
3402 seg
= expression (&the_insn
.exp
);
3403 if (!(seg
== absolute_section
3404 || seg
== undefined_section
3405 || SEG_NORMAL (seg
)))
3407 as_warn ("Bad segment in expression.");
3408 expr_end
= input_line_pointer
;
3409 input_line_pointer
= save_in
;
3412 expr_end
= input_line_pointer
;
3413 input_line_pointer
= save_in
;
3417 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3419 pa_get_absolute_expression (insn
, strp
)
3425 insn
->field_selector
= pa_chk_field_selector (strp
);
3426 save_in
= input_line_pointer
;
3427 input_line_pointer
= *strp
;
3428 expression (&insn
->exp
);
3429 if (insn
->exp
.X_op
!= O_constant
)
3431 as_bad ("Bad segment (should be absolute).");
3432 expr_end
= input_line_pointer
;
3433 input_line_pointer
= save_in
;
3436 expr_end
= input_line_pointer
;
3437 input_line_pointer
= save_in
;
3438 return evaluate_absolute (insn
);
3441 /* Evaluate an absolute expression EXP which may be modified by
3442 the selector FIELD_SELECTOR. Return the value of the expression. */
3444 evaluate_absolute (insn
)
3449 int field_selector
= insn
->field_selector
;
3452 value
= exp
.X_add_number
;
3454 switch (field_selector
)
3460 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3462 if (value
& 0x00000400)
3464 value
= (value
& 0xfffff800) >> 11;
3467 /* Sign extend from bit 21. */
3469 if (value
& 0x00000400)
3470 value
|= 0xfffff800;
3475 /* Arithmetic shift right 11 bits. */
3477 value
= (value
& 0xfffff800) >> 11;
3480 /* Set bits 0-20 to zero. */
3482 value
= value
& 0x7ff;
3485 /* Add 0x800 and arithmetic shift right 11 bits. */
3488 value
= (value
& 0xfffff800) >> 11;
3491 /* Set bitgs 0-21 to one. */
3493 value
|= 0xfffff800;
3496 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3498 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3502 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3507 BAD_CASE (field_selector
);
3513 /* Given an argument location specification return the associated
3514 argument location number. */
3517 pa_build_arg_reloc (type_name
)
3521 if (strncasecmp (type_name
, "no", 2) == 0)
3523 if (strncasecmp (type_name
, "gr", 2) == 0)
3525 else if (strncasecmp (type_name
, "fr", 2) == 0)
3527 else if (strncasecmp (type_name
, "fu", 2) == 0)
3530 as_bad ("Invalid argument location: %s\n", type_name
);
3535 /* Encode and return an argument relocation specification for
3536 the given register in the location specified by arg_reloc. */
3539 pa_align_arg_reloc (reg
, arg_reloc
)
3541 unsigned int arg_reloc
;
3543 unsigned int new_reloc
;
3545 new_reloc
= arg_reloc
;
3561 as_bad ("Invalid argument description: %d", reg
);
3567 /* Parse a PA nullification completer (,n). Return nonzero if the
3568 completer was found; return zero if no completer was found. */
3580 if (strncasecmp (*s
, "n", 1) == 0)
3584 as_bad ("Invalid Nullification: (%c)", **s
);
3593 /* Parse a non-negated compare/subtract completer returning the
3594 number (for encoding in instrutions) of the given completer.
3596 ISBRANCH specifies whether or not this is parsing a condition
3597 completer for a branch (vs a nullification completer for a
3598 computational instruction. */
3601 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3606 char *name
= *s
+ 1;
3614 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3618 if (strcmp (name
, "=") == 0)
3622 else if (strcmp (name
, "<") == 0)
3626 else if (strcmp (name
, "<=") == 0)
3630 else if (strcmp (name
, "<<") == 0)
3634 else if (strcmp (name
, "<<=") == 0)
3638 else if (strcasecmp (name
, "sv") == 0)
3642 else if (strcasecmp (name
, "od") == 0)
3646 /* If we have something like addb,n then there is no condition
3648 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3659 /* Reset pointers if this was really a ,n for a branch instruction. */
3660 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3666 /* Parse a negated compare/subtract completer returning the
3667 number (for encoding in instrutions) of the given completer.
3669 ISBRANCH specifies whether or not this is parsing a condition
3670 completer for a branch (vs a nullification completer for a
3671 computational instruction. */
3674 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3679 char *name
= *s
+ 1;
3687 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3691 if (strcasecmp (name
, "tr") == 0)
3695 else if (strcmp (name
, "<>") == 0)
3699 else if (strcmp (name
, ">=") == 0)
3703 else if (strcmp (name
, ">") == 0)
3707 else if (strcmp (name
, ">>=") == 0)
3711 else if (strcmp (name
, ">>") == 0)
3715 else if (strcasecmp (name
, "nsv") == 0)
3719 else if (strcasecmp (name
, "ev") == 0)
3723 /* If we have something like addb,n then there is no condition
3725 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3736 /* Reset pointers if this was really a ,n for a branch instruction. */
3737 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3743 /* Parse a non-negated addition completer returning the number
3744 (for encoding in instrutions) of the given completer.
3746 ISBRANCH specifies whether or not this is parsing a condition
3747 completer for a branch (vs a nullification completer for a
3748 computational instruction. */
3751 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3756 char *name
= *s
+ 1;
3764 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3768 if (strcmp (name
, "=") == 0)
3772 else if (strcmp (name
, "<") == 0)
3776 else if (strcmp (name
, "<=") == 0)
3780 else if (strcasecmp (name
, "nuv") == 0)
3784 else if (strcasecmp (name
, "znv") == 0)
3788 else if (strcasecmp (name
, "sv") == 0)
3792 else if (strcasecmp (name
, "od") == 0)
3796 /* If we have something like addb,n then there is no condition
3798 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3809 /* Reset pointers if this was really a ,n for a branch instruction. */
3810 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3816 /* Parse a negated addition completer returning the number
3817 (for encoding in instrutions) of the given completer.
3819 ISBRANCH specifies whether or not this is parsing a condition
3820 completer for a branch (vs a nullification completer for a
3821 computational instruction. */
3824 pa_parse_neg_add_cmpltr (s
, isbranch
)
3829 char *name
= *s
+ 1;
3837 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3841 if (strcasecmp (name
, "tr") == 0)
3845 else if (strcmp (name
, "<>") == 0)
3849 else if (strcmp (name
, ">=") == 0)
3853 else if (strcmp (name
, ">") == 0)
3857 else if (strcasecmp (name
, "uv") == 0)
3861 else if (strcasecmp (name
, "vnz") == 0)
3865 else if (strcasecmp (name
, "nsv") == 0)
3869 else if (strcasecmp (name
, "ev") == 0)
3873 /* If we have something like addb,n then there is no condition
3875 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3886 /* Reset pointers if this was really a ,n for a branch instruction. */
3887 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3893 /* Handle a .BLOCK type pseudo-op. */
3901 unsigned int temp_size
;
3904 temp_size
= get_absolute_expression ();
3906 /* Always fill with zeros, that's what the HP assembler does. */
3909 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
3910 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
3911 bzero (p
, temp_size
);
3913 /* Convert 2 bytes at a time. */
3915 for (i
= 0; i
< temp_size
; i
+= 2)
3917 md_number_to_chars (p
+ i
,
3919 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
3922 pa_undefine_label ();
3923 demand_empty_rest_of_line ();
3926 /* Handle a .CALL pseudo-op. This involves storing away information
3927 about where arguments are to be found so the linker can detect
3928 (and correct) argument location mismatches between caller and callee. */
3934 pa_call_args (&last_call_desc
);
3935 demand_empty_rest_of_line ();
3938 /* Do the dirty work of building a call descriptor which describes
3939 where the caller placed arguments to a function call. */
3942 pa_call_args (call_desc
)
3943 struct call_desc
*call_desc
;
3946 unsigned int temp
, arg_reloc
;
3948 while (!is_end_of_statement ())
3950 name
= input_line_pointer
;
3951 c
= get_symbol_end ();
3952 /* Process a source argument. */
3953 if ((strncasecmp (name
, "argw", 4) == 0))
3955 temp
= atoi (name
+ 4);
3956 p
= input_line_pointer
;
3958 input_line_pointer
++;
3959 name
= input_line_pointer
;
3960 c
= get_symbol_end ();
3961 arg_reloc
= pa_build_arg_reloc (name
);
3962 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
3964 /* Process a return value. */
3965 else if ((strncasecmp (name
, "rtnval", 6) == 0))
3967 p
= input_line_pointer
;
3969 input_line_pointer
++;
3970 name
= input_line_pointer
;
3971 c
= get_symbol_end ();
3972 arg_reloc
= pa_build_arg_reloc (name
);
3973 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
3977 as_bad ("Invalid .CALL argument: %s", name
);
3979 p
= input_line_pointer
;
3981 if (!is_end_of_statement ())
3982 input_line_pointer
++;
3986 /* Return TRUE if FRAG1 and FRAG2 are the same. */
3989 is_same_frag (frag1
, frag2
)
3996 else if (frag2
== NULL
)
3998 else if (frag1
== frag2
)
4000 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4001 return (is_same_frag (frag1
, frag2
->fr_next
));
4007 /* Build an entry in the UNWIND subspace from the given function
4008 attributes in CALL_INFO. This is not needed for SOM as using
4009 R_ENTRY and R_EXIT relocations allow the linker to handle building
4010 of the unwind spaces. */
4013 pa_build_unwind_subspace (call_info
)
4014 struct call_info
*call_info
;
4017 asection
*seg
, *save_seg
;
4018 subsegT subseg
, save_subseg
;
4022 /* Get into the right seg/subseg. This may involve creating
4023 the seg the first time through. Make sure to have the
4024 old seg/subseg so that we can reset things when we are done. */
4025 subseg
= SUBSEG_UNWIND
;
4026 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4027 if (seg
== ASEC_NULL
)
4029 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4030 bfd_set_section_flags (stdoutput
, seg
,
4031 SEC_READONLY
| SEC_HAS_CONTENTS
4032 | SEC_LOAD
| SEC_RELOC
);
4036 save_subseg
= now_subseg
;
4037 subseg_set (seg
, subseg
);
4040 /* Get some space to hold relocation information for the unwind
4044 /* Relocation info. for start offset of the function. */
4045 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4046 call_info
->start_symbol
, (offsetT
) 0,
4047 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0,
4052 /* Relocation info. for end offset of the function. */
4053 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4054 call_info
->end_symbol
, (offsetT
) 0,
4055 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0,
4059 unwind
= (char *) &call_info
->ci_unwind
;
4060 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4064 FRAG_APPEND_1_CHAR (c
);
4068 /* Return back to the original segment/subsegment. */
4069 subseg_set (save_seg
, save_subseg
);
4073 /* Process a .CALLINFO pseudo-op. This information is used later
4074 to build unwind descriptors and maybe one day to support
4075 .ENTER and .LEAVE. */
4078 pa_callinfo (unused
)
4084 /* .CALLINFO must appear within a procedure definition. */
4085 if (!within_procedure
)
4086 as_bad (".callinfo is not within a procedure definition");
4088 /* Mark the fact that we found the .CALLINFO for the
4089 current procedure. */
4090 callinfo_found
= TRUE
;
4092 /* Iterate over the .CALLINFO arguments. */
4093 while (!is_end_of_statement ())
4095 name
= input_line_pointer
;
4096 c
= get_symbol_end ();
4097 /* Frame size specification. */
4098 if ((strncasecmp (name
, "frame", 5) == 0))
4100 p
= input_line_pointer
;
4102 input_line_pointer
++;
4103 temp
= get_absolute_expression ();
4104 if ((temp
& 0x3) != 0)
4106 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4110 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4111 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4114 /* Entry register (GR, GR and SR) specifications. */
4115 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4117 p
= input_line_pointer
;
4119 input_line_pointer
++;
4120 temp
= get_absolute_expression ();
4121 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4122 even though %r19 is caller saved. I think this is a bug in
4123 the HP assembler, and we are not going to emulate it. */
4124 if (temp
< 3 || temp
> 18)
4125 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4126 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4128 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4130 p
= input_line_pointer
;
4132 input_line_pointer
++;
4133 temp
= get_absolute_expression ();
4134 /* Similarly the HP assembler takes 31 as the high bound even
4135 though %fr21 is the last callee saved floating point register. */
4136 if (temp
< 12 || temp
> 21)
4137 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4138 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4140 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4142 p
= input_line_pointer
;
4144 input_line_pointer
++;
4145 temp
= get_absolute_expression ();
4147 as_bad ("Value for ENTRY_SR must be 3\n");
4149 /* Note whether or not this function performs any calls. */
4150 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4151 (strncasecmp (name
, "caller", 6) == 0))
4153 p
= input_line_pointer
;
4156 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4158 p
= input_line_pointer
;
4161 /* Should RP be saved into the stack. */
4162 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4164 p
= input_line_pointer
;
4166 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4168 /* Likewise for SP. */
4169 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4171 p
= input_line_pointer
;
4173 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4175 /* Is this an unwindable procedure. If so mark it so
4176 in the unwind descriptor. */
4177 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4179 p
= input_line_pointer
;
4181 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4183 /* Is this an interrupt routine. If so mark it in the
4184 unwind descriptor. */
4185 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4187 p
= input_line_pointer
;
4189 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4191 /* Is this a millicode routine. "millicode" isn't in my
4192 assembler manual, but my copy is old. The HP assembler
4193 accepts it, and there's a place in the unwind descriptor
4194 to drop the information, so we'll accept it too. */
4195 else if ((strncasecmp (name
, "millicode", 9) == 0))
4197 p
= input_line_pointer
;
4199 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4203 as_bad ("Invalid .CALLINFO argument: %s", name
);
4204 *input_line_pointer
= c
;
4206 if (!is_end_of_statement ())
4207 input_line_pointer
++;
4210 demand_empty_rest_of_line ();
4213 /* Switch into the code subspace. */
4219 sd_chain_struct
*sdchain
;
4221 /* First time through it might be necessary to create the
4223 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4225 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4226 pa_def_spaces
[0].spnum
,
4227 pa_def_spaces
[0].loadable
,
4228 pa_def_spaces
[0].defined
,
4229 pa_def_spaces
[0].private,
4230 pa_def_spaces
[0].sort
,
4231 pa_def_spaces
[0].segment
, 0);
4234 SPACE_DEFINED (sdchain
) = 1;
4235 subseg_set (text_section
, SUBSEG_CODE
);
4236 demand_empty_rest_of_line ();
4239 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4240 the .comm pseudo-op has the following symtax:
4242 <label> .comm <length>
4244 where <label> is optional and is a symbol whose address will be the start of
4245 a block of memory <length> bytes long. <length> must be an absolute
4246 expression. <length> bytes will be allocated in the current space
4255 label_symbol_struct
*label_symbol
= pa_get_label ();
4258 symbol
= label_symbol
->lss_label
;
4263 size
= get_absolute_expression ();
4267 /* It is incorrect to check S_IS_DEFINED at this point as
4268 the symbol will *always* be defined. FIXME. How to
4269 correctly determine when this label really as been
4271 if (S_GET_VALUE (symbol
))
4273 if (S_GET_VALUE (symbol
) != size
)
4275 as_warn ("Length of .comm \"%s\" is already %ld. Not changed.",
4276 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4282 S_SET_VALUE (symbol
, size
);
4283 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4284 S_SET_EXTERNAL (symbol
);
4286 /* Keep this until we verify that the generic resolving
4287 code in write.c is fixed. */
4288 symbol
->sy_resolved
= 1;
4292 demand_empty_rest_of_line ();
4295 /* Process a .END pseudo-op. */
4301 demand_empty_rest_of_line ();
4304 /* Process a .ENTER pseudo-op. This is not supported. */
4312 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4318 if (!within_procedure
)
4319 as_bad ("Misplaced .entry. Ignored.");
4322 if (!callinfo_found
)
4323 as_bad ("Missing .callinfo.");
4325 demand_empty_rest_of_line ();
4326 within_entry_exit
= TRUE
;
4329 /* SOM defers building of unwind descriptors until the link phase.
4330 The assembler is responsible for creating an R_ENTRY relocation
4331 to mark the beginning of a region and hold the unwind bits, and
4332 for creating an R_EXIT relocation to mark the end of the region.
4334 FIXME. ELF should be using the same conventions! The problem
4335 is an unwind requires too much relocation space. Hmmm. Maybe
4336 if we split the unwind bits up between the relocations which
4337 denote the entry and exit points. */
4338 if (last_call_info
->start_symbol
!= NULL
)
4340 char *where
= frag_more (0);
4342 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4343 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4344 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4345 (char *) &last_call_info
->ci_unwind
.descriptor
);
4350 /* Handle a .EQU pseudo-op. */
4356 label_symbol_struct
*label_symbol
= pa_get_label ();
4361 symbol
= label_symbol
->lss_label
;
4363 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4365 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4366 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4371 as_bad (".REG must use a label");
4373 as_bad (".EQU must use a label");
4376 pa_undefine_label ();
4377 demand_empty_rest_of_line ();
4380 /* Helper function. Does processing for the end of a function. This
4381 usually involves creating some relocations or building special
4382 symbols to mark the end of the function. */
4389 where
= frag_more (0);
4392 /* Mark the end of the function, stuff away the location of the frag
4393 for the end of the function, and finally call pa_build_unwind_subspace
4394 to add an entry in the unwind table. */
4395 hppa_elf_mark_end_of_function ();
4396 pa_build_unwind_subspace (last_call_info
);
4398 /* SOM defers building of unwind descriptors until the link phase.
4399 The assembler is responsible for creating an R_ENTRY relocation
4400 to mark the beginning of a region and hold the unwind bits, and
4401 for creating an R_EXIT relocation to mark the end of the region.
4403 FIXME. ELF should be using the same conventions! The problem
4404 is an unwind requires too much relocation space. Hmmm. Maybe
4405 if we split the unwind bits up between the relocations which
4406 denote the entry and exit points. */
4407 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4408 last_call_info
->start_symbol
, (offsetT
) 0,
4409 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4413 /* Process a .EXIT pseudo-op. */
4419 if (!within_procedure
)
4420 as_bad (".EXIT must appear within a procedure");
4423 if (!callinfo_found
)
4424 as_bad ("Missing .callinfo");
4427 if (!within_entry_exit
)
4428 as_bad ("No .ENTRY for this .EXIT");
4431 within_entry_exit
= FALSE
;
4436 demand_empty_rest_of_line ();
4439 /* Process a .EXPORT directive. This makes functions external
4440 and provides information such as argument relocation entries
4450 name
= input_line_pointer
;
4451 c
= get_symbol_end ();
4452 /* Make sure the given symbol exists. */
4453 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4455 as_bad ("Cannot define export symbol: %s\n", name
);
4456 p
= input_line_pointer
;
4458 input_line_pointer
++;
4462 /* OK. Set the external bits and process argument relocations. */
4463 S_SET_EXTERNAL (symbol
);
4464 p
= input_line_pointer
;
4466 if (!is_end_of_statement ())
4468 input_line_pointer
++;
4469 pa_type_args (symbol
, 1);
4473 demand_empty_rest_of_line ();
4476 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4479 pa_type_args (symbolP
, is_export
)
4484 unsigned int temp
, arg_reloc
;
4485 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4486 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4488 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4491 input_line_pointer
+= 8;
4492 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4493 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4494 type
= SYMBOL_TYPE_ABSOLUTE
;
4496 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4498 input_line_pointer
+= 4;
4499 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4500 instead one should be IMPORTing/EXPORTing ENTRY types.
4502 Complain if one tries to EXPORT a CODE type since that's never
4503 done. Both GCC and HP C still try to IMPORT CODE types, so
4504 silently fix them to be ENTRY types. */
4505 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4508 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4510 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4511 type
= SYMBOL_TYPE_ENTRY
;
4515 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4516 type
= SYMBOL_TYPE_CODE
;
4519 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4521 input_line_pointer
+= 4;
4522 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4523 type
= SYMBOL_TYPE_DATA
;
4525 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4527 input_line_pointer
+= 5;
4528 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4529 type
= SYMBOL_TYPE_ENTRY
;
4531 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4533 input_line_pointer
+= 9;
4534 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4535 type
= SYMBOL_TYPE_MILLICODE
;
4537 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4539 input_line_pointer
+= 6;
4540 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4541 type
= SYMBOL_TYPE_PLABEL
;
4543 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4545 input_line_pointer
+= 8;
4546 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4547 type
= SYMBOL_TYPE_PRI_PROG
;
4549 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4551 input_line_pointer
+= 8;
4552 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4553 type
= SYMBOL_TYPE_SEC_PROG
;
4556 /* SOM requires much more information about symbol types
4557 than BFD understands. This is how we get this information
4558 to the SOM BFD backend. */
4559 #ifdef obj_set_symbol_type
4560 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4563 /* Now that the type of the exported symbol has been handled,
4564 handle any argument relocation information. */
4565 while (!is_end_of_statement ())
4567 if (*input_line_pointer
== ',')
4568 input_line_pointer
++;
4569 name
= input_line_pointer
;
4570 c
= get_symbol_end ();
4571 /* Argument sources. */
4572 if ((strncasecmp (name
, "argw", 4) == 0))
4574 p
= input_line_pointer
;
4576 input_line_pointer
++;
4577 temp
= atoi (name
+ 4);
4578 name
= input_line_pointer
;
4579 c
= get_symbol_end ();
4580 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4581 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4582 *input_line_pointer
= c
;
4584 /* The return value. */
4585 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4587 p
= input_line_pointer
;
4589 input_line_pointer
++;
4590 name
= input_line_pointer
;
4591 c
= get_symbol_end ();
4592 arg_reloc
= pa_build_arg_reloc (name
);
4593 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4594 *input_line_pointer
= c
;
4596 /* Privelege level. */
4597 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4599 p
= input_line_pointer
;
4601 input_line_pointer
++;
4602 temp
= atoi (input_line_pointer
);
4603 c
= get_symbol_end ();
4604 *input_line_pointer
= c
;
4608 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4609 p
= input_line_pointer
;
4612 if (!is_end_of_statement ())
4613 input_line_pointer
++;
4617 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4618 assembly file must either be defined in the assembly file, or
4619 explicitly IMPORTED from another. */
4628 name
= input_line_pointer
;
4629 c
= get_symbol_end ();
4631 symbol
= symbol_find (name
);
4632 /* Ugh. We might be importing a symbol defined earlier in the file,
4633 in which case all the code below will really screw things up
4634 (set the wrong segment, symbol flags & type, etc). */
4635 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4637 symbol
= symbol_find_or_make (name
);
4638 p
= input_line_pointer
;
4641 if (!is_end_of_statement ())
4643 input_line_pointer
++;
4644 pa_type_args (symbol
, 0);
4648 /* Sigh. To be compatable with the HP assembler and to help
4649 poorly written assembly code, we assign a type based on
4650 the the current segment. Note only BSF_FUNCTION really
4651 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4652 if (now_seg
== text_section
)
4653 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4655 /* If the section is undefined, then the symbol is undefined
4656 Since this is an import, leave the section undefined. */
4657 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4662 /* The symbol was already defined. Just eat everything up to
4663 the end of the current statement. */
4664 while (!is_end_of_statement ())
4665 input_line_pointer
++;
4668 demand_empty_rest_of_line ();
4671 /* Handle a .LABEL pseudo-op. */
4679 name
= input_line_pointer
;
4680 c
= get_symbol_end ();
4682 if (strlen (name
) > 0)
4685 p
= input_line_pointer
;
4690 as_warn ("Missing label name on .LABEL");
4693 if (!is_end_of_statement ())
4695 as_warn ("extra .LABEL arguments ignored.");
4696 ignore_rest_of_line ();
4698 demand_empty_rest_of_line ();
4701 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4710 /* Handle a .ORIGIN pseudo-op. */
4717 pa_undefine_label ();
4720 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4721 is for static functions. FIXME. Should share more code with .EXPORT. */
4730 name
= input_line_pointer
;
4731 c
= get_symbol_end ();
4733 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4735 as_bad ("Cannot define static symbol: %s\n", name
);
4736 p
= input_line_pointer
;
4738 input_line_pointer
++;
4742 S_CLEAR_EXTERNAL (symbol
);
4743 p
= input_line_pointer
;
4745 if (!is_end_of_statement ())
4747 input_line_pointer
++;
4748 pa_type_args (symbol
, 0);
4752 demand_empty_rest_of_line ();
4755 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4756 of a procedure from a syntatical point of view. */
4762 struct call_info
*call_info
;
4763 if (within_procedure
)
4764 as_fatal ("Nested procedures");
4766 /* Reset global variables for new procedure. */
4767 callinfo_found
= FALSE
;
4768 within_procedure
= TRUE
;
4771 Enabling
this code creates severe problems with GDB
. It appears as
if
4772 inserting linker stubs between functions within a single
.o makes GDB
4775 /* Create a new CODE subspace for each procedure if we are not
4776 using space/subspace aliases. */
4777 if (!USE_ALIASES
&& call_info_root
!= NULL
)
4781 /* Force creation of a new $CODE$ subspace; inherit attributes from
4782 the first $CODE$ subspace. */
4783 seg
= subseg_force_new ("$CODE$", 0);
4785 /* Now set the flags. */
4786 bfd_set_section_flags (stdoutput
, seg
,
4787 bfd_get_section_flags (abfd
, text_section
));
4789 /* Record any alignment request for this section. */
4790 record_alignment (seg
,
4791 bfd_get_section_alignment (stdoutput
, text_section
));
4793 /* Change the "text_section" to be our new $CODE$ subspace. */
4795 subseg_set (text_section
, 0);
4797 #ifdef obj_set_subsection_attributes
4798 /* Need a way to inherit the the access bits, sort key and quadrant
4799 from the first $CODE$ subspace. FIXME. */
4800 obj_set_subsection_attributes (seg
, current_space
->sd_seg
, 0x2c, 24, 0);
4805 /* Create another call_info structure. */
4806 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4809 as_fatal ("Cannot allocate unwind descriptor\n");
4811 bzero (call_info
, sizeof (struct call_info
));
4813 call_info
->ci_next
= NULL
;
4815 if (call_info_root
== NULL
)
4817 call_info_root
= call_info
;
4818 last_call_info
= call_info
;
4822 last_call_info
->ci_next
= call_info
;
4823 last_call_info
= call_info
;
4826 /* set up defaults on call_info structure */
4828 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4829 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4830 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4832 /* If we got a .PROC pseudo-op, we know that the function is defined
4833 locally. Make sure it gets into the symbol table. */
4835 label_symbol_struct
*label_symbol
= pa_get_label ();
4839 if (label_symbol
->lss_label
)
4841 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4842 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4846 /* The label was defined in a different segment. Fix that
4847 along with the value and associated fragment. */
4848 S_SET_SEGMENT (last_call_info
->start_symbol
, now_seg
);
4849 S_SET_VALUE (last_call_info
->start_symbol
,
4850 ((char*)obstack_next_free (&frags
)
4851 - frag_now
->fr_literal
));
4852 last_call_info
->start_symbol
->sy_frag
= frag_now
;
4857 as_bad ("Missing function name for .PROC (corrupted label chain)");
4860 last_call_info
->start_symbol
= NULL
;
4863 demand_empty_rest_of_line ();
4866 /* Process the syntatical end of a procedure. Make sure all the
4867 appropriate pseudo-ops were found within the procedure. */
4874 /* If we are within a procedure definition, make sure we've
4875 defined a label for the procedure; handle case where the
4876 label was defined after the .PROC directive.
4878 Note there's not need to diddle with the segment or fragment
4879 for the label symbol in this case. We have already switched
4880 into the new $CODE$ subspace at this point. */
4881 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4883 label_symbol_struct
*label_symbol
= pa_get_label ();
4887 if (label_symbol
->lss_label
)
4889 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4890 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4892 /* Also handle allocation of a fixup to hold the unwind
4893 information when the label appears after the proc/procend. */
4894 if (within_entry_exit
)
4896 char *where
= frag_more (0);
4898 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4899 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4900 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4901 (char *) &last_call_info
->ci_unwind
.descriptor
);
4906 as_bad ("Missing function name for .PROC (corrupted label chain)");
4909 as_bad ("Missing function name for .PROC");
4912 if (!within_procedure
)
4913 as_bad ("misplaced .procend");
4915 if (!callinfo_found
)
4916 as_bad ("Missing .callinfo for this procedure");
4918 if (within_entry_exit
)
4919 as_bad ("Missing .EXIT for a .ENTRY");
4922 /* ELF needs to mark the end of each function so that it can compute
4923 the size of the function (apparently its needed in the symbol table. */
4924 hppa_elf_mark_end_of_function ();
4927 within_procedure
= FALSE
;
4928 demand_empty_rest_of_line ();
4929 pa_undefine_label ();
4932 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4933 then create a new space entry to hold the information specified
4934 by the parameters to the .SPACE directive. */
4936 static sd_chain_struct
*
4937 pa_parse_space_stmt (space_name
, create_flag
)
4941 char *name
, *ptemp
, c
;
4942 char loadable
, defined
, private, sort
;
4944 asection
*seg
= NULL
;
4945 sd_chain_struct
*space
;
4947 /* load default values */
4953 if (strcmp (space_name
, "$TEXT$") == 0)
4955 seg
= pa_def_spaces
[0].segment
;
4956 defined
= pa_def_spaces
[0].defined
;
4957 private = pa_def_spaces
[0].private;
4958 sort
= pa_def_spaces
[0].sort
;
4959 spnum
= pa_def_spaces
[0].spnum
;
4961 else if (strcmp (space_name
, "$PRIVATE$") == 0)
4963 seg
= pa_def_spaces
[1].segment
;
4964 defined
= pa_def_spaces
[1].defined
;
4965 private = pa_def_spaces
[1].private;
4966 sort
= pa_def_spaces
[1].sort
;
4967 spnum
= pa_def_spaces
[1].spnum
;
4970 if (!is_end_of_statement ())
4972 print_errors
= FALSE
;
4973 ptemp
= input_line_pointer
+ 1;
4974 /* First see if the space was specified as a number rather than
4975 as a name. According to the PA assembly manual the rest of
4976 the line should be ignored. */
4977 temp
= pa_parse_number (&ptemp
, 0);
4981 input_line_pointer
= ptemp
;
4985 while (!is_end_of_statement ())
4987 input_line_pointer
++;
4988 name
= input_line_pointer
;
4989 c
= get_symbol_end ();
4990 if ((strncasecmp (name
, "spnum", 5) == 0))
4992 *input_line_pointer
= c
;
4993 input_line_pointer
++;
4994 spnum
= get_absolute_expression ();
4996 else if ((strncasecmp (name
, "sort", 4) == 0))
4998 *input_line_pointer
= c
;
4999 input_line_pointer
++;
5000 sort
= get_absolute_expression ();
5002 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5004 *input_line_pointer
= c
;
5007 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5009 *input_line_pointer
= c
;
5012 else if ((strncasecmp (name
, "private", 7) == 0))
5014 *input_line_pointer
= c
;
5019 as_bad ("Invalid .SPACE argument");
5020 *input_line_pointer
= c
;
5021 if (!is_end_of_statement ())
5022 input_line_pointer
++;
5026 print_errors
= TRUE
;
5029 if (create_flag
&& seg
== NULL
)
5030 seg
= subseg_new (space_name
, 0);
5032 /* If create_flag is nonzero, then create the new space with
5033 the attributes computed above. Else set the values in
5034 an already existing space -- this can only happen for
5035 the first occurence of a built-in space. */
5037 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5038 private, sort
, seg
, 1);
5041 space
= is_defined_space (space_name
);
5042 SPACE_SPNUM (space
) = spnum
;
5043 SPACE_DEFINED (space
) = defined
& 1;
5044 SPACE_USER_DEFINED (space
) = 1;
5047 #ifdef obj_set_section_attributes
5048 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5054 /* Handle a .SPACE pseudo-op; this switches the current space to the
5055 given space, creating the new space if necessary. */
5061 char *name
, c
, *space_name
, *save_s
;
5063 sd_chain_struct
*sd_chain
;
5065 if (within_procedure
)
5067 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5068 ignore_rest_of_line ();
5072 /* Check for some of the predefined spaces. FIXME: most of the code
5073 below is repeated several times, can we extract the common parts
5074 and place them into a subroutine or something similar? */
5075 /* FIXME Is this (and the next IF stmt) really right?
5076 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5077 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5079 input_line_pointer
+= 6;
5080 sd_chain
= is_defined_space ("$TEXT$");
5081 if (sd_chain
== NULL
)
5082 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5083 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5084 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5086 current_space
= sd_chain
;
5087 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5089 = pa_subsegment_to_subspace (text_section
,
5090 sd_chain
->sd_last_subseg
);
5091 demand_empty_rest_of_line ();
5094 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5096 input_line_pointer
+= 9;
5097 sd_chain
= is_defined_space ("$PRIVATE$");
5098 if (sd_chain
== NULL
)
5099 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5100 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5101 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5103 current_space
= sd_chain
;
5104 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5106 = pa_subsegment_to_subspace (data_section
,
5107 sd_chain
->sd_last_subseg
);
5108 demand_empty_rest_of_line ();
5111 if (!strncasecmp (input_line_pointer
,
5112 GDB_DEBUG_SPACE_NAME
,
5113 strlen (GDB_DEBUG_SPACE_NAME
)))
5115 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5116 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5117 if (sd_chain
== NULL
)
5118 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5119 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5120 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5122 current_space
= sd_chain
;
5125 asection
*gdb_section
5126 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5128 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5130 = pa_subsegment_to_subspace (gdb_section
,
5131 sd_chain
->sd_last_subseg
);
5133 demand_empty_rest_of_line ();
5137 /* It could be a space specified by number. */
5139 save_s
= input_line_pointer
;
5140 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5142 if ((sd_chain
= pa_find_space_by_number (temp
)))
5144 current_space
= sd_chain
;
5146 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5148 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5149 sd_chain
->sd_last_subseg
);
5150 demand_empty_rest_of_line ();
5155 /* Not a number, attempt to create a new space. */
5157 input_line_pointer
= save_s
;
5158 name
= input_line_pointer
;
5159 c
= get_symbol_end ();
5160 space_name
= xmalloc (strlen (name
) + 1);
5161 strcpy (space_name
, name
);
5162 *input_line_pointer
= c
;
5164 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5165 current_space
= sd_chain
;
5167 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5168 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5169 sd_chain
->sd_last_subseg
);
5170 demand_empty_rest_of_line ();
5174 /* Switch to a new space. (I think). FIXME. */
5183 sd_chain_struct
*space
;
5185 name
= input_line_pointer
;
5186 c
= get_symbol_end ();
5187 space
= is_defined_space (name
);
5191 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5194 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5196 *input_line_pointer
= c
;
5197 demand_empty_rest_of_line ();
5200 /* If VALUE is an exact power of two between zero and 2^31, then
5201 return log2 (VALUE). Else return -1. */
5209 while ((1 << shift
) != value
&& shift
< 32)
5218 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5219 given subspace, creating the new subspace if necessary.
5221 FIXME. Should mirror pa_space more closely, in particular how
5222 they're broken up into subroutines. */
5225 pa_subspace (unused
)
5228 char *name
, *ss_name
, *alias
, c
;
5229 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5230 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5231 sd_chain_struct
*space
;
5232 ssd_chain_struct
*ssd
;
5235 if (within_procedure
)
5237 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5238 ignore_rest_of_line ();
5242 name
= input_line_pointer
;
5243 c
= get_symbol_end ();
5244 ss_name
= xmalloc (strlen (name
) + 1);
5245 strcpy (ss_name
, name
);
5246 *input_line_pointer
= c
;
5248 /* Load default values. */
5261 space
= current_space
;
5262 ssd
= is_defined_subspace (ss_name
);
5263 /* Allow user to override the builtin attributes of subspaces. But
5264 only allow the attributes to be changed once! */
5265 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5267 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5268 if (!is_end_of_statement ())
5269 as_warn ("Parameters of an existing subspace can\'t be modified");
5270 demand_empty_rest_of_line ();
5275 /* A new subspace. Load default values if it matches one of
5276 the builtin subspaces. */
5278 while (pa_def_subspaces
[i
].name
)
5280 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5282 loadable
= pa_def_subspaces
[i
].loadable
;
5283 common
= pa_def_subspaces
[i
].common
;
5284 dup_common
= pa_def_subspaces
[i
].dup_common
;
5285 code_only
= pa_def_subspaces
[i
].code_only
;
5286 zero
= pa_def_subspaces
[i
].zero
;
5287 space_index
= pa_def_subspaces
[i
].space_index
;
5288 alignment
= pa_def_subspaces
[i
].alignment
;
5289 quadrant
= pa_def_subspaces
[i
].quadrant
;
5290 access
= pa_def_subspaces
[i
].access
;
5291 sort
= pa_def_subspaces
[i
].sort
;
5292 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5293 alias
= pa_def_subspaces
[i
].alias
;
5300 /* We should be working with a new subspace now. Fill in
5301 any information as specified by the user. */
5302 if (!is_end_of_statement ())
5304 input_line_pointer
++;
5305 while (!is_end_of_statement ())
5307 name
= input_line_pointer
;
5308 c
= get_symbol_end ();
5309 if ((strncasecmp (name
, "quad", 4) == 0))
5311 *input_line_pointer
= c
;
5312 input_line_pointer
++;
5313 quadrant
= get_absolute_expression ();
5315 else if ((strncasecmp (name
, "align", 5) == 0))
5317 *input_line_pointer
= c
;
5318 input_line_pointer
++;
5319 alignment
= get_absolute_expression ();
5320 if (log2 (alignment
) == -1)
5322 as_bad ("Alignment must be a power of 2");
5326 else if ((strncasecmp (name
, "access", 6) == 0))
5328 *input_line_pointer
= c
;
5329 input_line_pointer
++;
5330 access
= get_absolute_expression ();
5332 else if ((strncasecmp (name
, "sort", 4) == 0))
5334 *input_line_pointer
= c
;
5335 input_line_pointer
++;
5336 sort
= get_absolute_expression ();
5338 else if ((strncasecmp (name
, "code_only", 9) == 0))
5340 *input_line_pointer
= c
;
5343 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5345 *input_line_pointer
= c
;
5348 else if ((strncasecmp (name
, "common", 6) == 0))
5350 *input_line_pointer
= c
;
5353 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5355 *input_line_pointer
= c
;
5358 else if ((strncasecmp (name
, "zero", 4) == 0))
5360 *input_line_pointer
= c
;
5363 else if ((strncasecmp (name
, "first", 5) == 0))
5364 as_bad ("FIRST not supported as a .SUBSPACE argument");
5366 as_bad ("Invalid .SUBSPACE argument");
5367 if (!is_end_of_statement ())
5368 input_line_pointer
++;
5372 /* Compute a reasonable set of BFD flags based on the information
5373 in the .subspace directive. */
5374 applicable
= bfd_applicable_section_flags (stdoutput
);
5377 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5380 if (common
|| dup_common
)
5381 flags
|= SEC_IS_COMMON
;
5383 /* This is a zero-filled subspace (eg BSS). */
5387 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5388 applicable
&= flags
;
5390 /* If this is an existing subspace, then we want to use the
5391 segment already associated with the subspace.
5393 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5394 lots of sections. It might be a problem in the PA ELF
5395 code, I do not know yet. For now avoid creating anything
5396 but the "standard" sections for ELF. */
5398 section
= ssd
->ssd_seg
;
5400 section
= subseg_new (alias
, 0);
5401 else if (!alias
&& USE_ALIASES
)
5403 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5404 demand_empty_rest_of_line ();
5408 section
= subseg_new (ss_name
, 0);
5410 /* Now set the flags. */
5411 bfd_set_section_flags (stdoutput
, section
, applicable
);
5413 /* Record any alignment request for this section. */
5414 record_alignment (section
, log2 (alignment
));
5416 /* Set the starting offset for this section. */
5417 bfd_set_section_vma (stdoutput
, section
,
5418 pa_subspace_start (space
, quadrant
));
5420 /* Now that all the flags are set, update an existing subspace,
5421 or create a new one. */
5424 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5425 code_only
, common
, dup_common
,
5426 sort
, zero
, access
, space_index
,
5427 alignment
, quadrant
,
5430 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5432 dup_common
, zero
, sort
,
5433 access
, space_index
,
5434 alignment
, quadrant
, section
);
5436 demand_empty_rest_of_line ();
5437 current_subspace
->ssd_seg
= section
;
5438 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5440 SUBSPACE_DEFINED (current_subspace
) = 1;
5444 /* Create default space and subspace dictionaries. */
5451 space_dict_root
= NULL
;
5452 space_dict_last
= NULL
;
5455 while (pa_def_spaces
[i
].name
)
5459 /* Pick the right name to use for the new section. */
5460 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5461 name
= pa_def_spaces
[i
].alias
;
5463 name
= pa_def_spaces
[i
].name
;
5465 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5466 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5467 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5468 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5469 pa_def_spaces
[i
].segment
, 0);
5474 while (pa_def_subspaces
[i
].name
)
5477 int applicable
, subsegment
;
5478 asection
*segment
= NULL
;
5479 sd_chain_struct
*space
;
5481 /* Pick the right name for the new section and pick the right
5482 subsegment number. */
5483 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5485 name
= pa_def_subspaces
[i
].alias
;
5486 subsegment
= pa_def_subspaces
[i
].subsegment
;
5490 name
= pa_def_subspaces
[i
].name
;
5494 /* Create the new section. */
5495 segment
= subseg_new (name
, subsegment
);
5498 /* For SOM we want to replace the standard .text, .data, and .bss
5499 sections with our own. We also want to set BFD flags for
5500 all the built-in subspaces. */
5501 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5503 text_section
= segment
;
5504 applicable
= bfd_applicable_section_flags (stdoutput
);
5505 bfd_set_section_flags (stdoutput
, segment
,
5506 applicable
& (SEC_ALLOC
| SEC_LOAD
5507 | SEC_RELOC
| SEC_CODE
5509 | SEC_HAS_CONTENTS
));
5511 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5513 data_section
= segment
;
5514 applicable
= bfd_applicable_section_flags (stdoutput
);
5515 bfd_set_section_flags (stdoutput
, segment
,
5516 applicable
& (SEC_ALLOC
| SEC_LOAD
5518 | SEC_HAS_CONTENTS
));
5522 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5524 bss_section
= segment
;
5525 applicable
= bfd_applicable_section_flags (stdoutput
);
5526 bfd_set_section_flags (stdoutput
, segment
,
5527 applicable
& SEC_ALLOC
);
5529 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5531 applicable
= bfd_applicable_section_flags (stdoutput
);
5532 bfd_set_section_flags (stdoutput
, segment
,
5533 applicable
& (SEC_ALLOC
| SEC_LOAD
5536 | SEC_HAS_CONTENTS
));
5538 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5540 applicable
= bfd_applicable_section_flags (stdoutput
);
5541 bfd_set_section_flags (stdoutput
, segment
,
5542 applicable
& (SEC_ALLOC
| SEC_LOAD
5545 | SEC_HAS_CONTENTS
));
5548 /* Find the space associated with this subspace. */
5549 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5550 def_space_index
].segment
);
5553 as_fatal ("Internal error: Unable to find containing space for %s.",
5554 pa_def_subspaces
[i
].name
);
5557 create_new_subspace (space
, name
,
5558 pa_def_subspaces
[i
].loadable
,
5559 pa_def_subspaces
[i
].code_only
,
5560 pa_def_subspaces
[i
].common
,
5561 pa_def_subspaces
[i
].dup_common
,
5562 pa_def_subspaces
[i
].zero
,
5563 pa_def_subspaces
[i
].sort
,
5564 pa_def_subspaces
[i
].access
,
5565 pa_def_subspaces
[i
].space_index
,
5566 pa_def_subspaces
[i
].alignment
,
5567 pa_def_subspaces
[i
].quadrant
,
5575 /* Create a new space NAME, with the appropriate flags as defined
5576 by the given parameters. */
5578 static sd_chain_struct
*
5579 create_new_space (name
, spnum
, loadable
, defined
, private,
5580 sort
, seg
, user_defined
)
5590 sd_chain_struct
*chain_entry
;
5592 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5594 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5597 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5598 strcpy (SPACE_NAME (chain_entry
), name
);
5599 SPACE_DEFINED (chain_entry
) = defined
;
5600 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5601 SPACE_SPNUM (chain_entry
) = spnum
;
5603 chain_entry
->sd_seg
= seg
;
5604 chain_entry
->sd_last_subseg
= -1;
5605 chain_entry
->sd_subspaces
= NULL
;
5606 chain_entry
->sd_next
= NULL
;
5608 /* Find spot for the new space based on its sort key. */
5609 if (!space_dict_last
)
5610 space_dict_last
= chain_entry
;
5612 if (space_dict_root
== NULL
)
5613 space_dict_root
= chain_entry
;
5616 sd_chain_struct
*chain_pointer
;
5617 sd_chain_struct
*prev_chain_pointer
;
5619 chain_pointer
= space_dict_root
;
5620 prev_chain_pointer
= NULL
;
5622 while (chain_pointer
)
5624 prev_chain_pointer
= chain_pointer
;
5625 chain_pointer
= chain_pointer
->sd_next
;
5628 /* At this point we've found the correct place to add the new
5629 entry. So add it and update the linked lists as appropriate. */
5630 if (prev_chain_pointer
)
5632 chain_entry
->sd_next
= chain_pointer
;
5633 prev_chain_pointer
->sd_next
= chain_entry
;
5637 space_dict_root
= chain_entry
;
5638 chain_entry
->sd_next
= chain_pointer
;
5641 if (chain_entry
->sd_next
== NULL
)
5642 space_dict_last
= chain_entry
;
5645 /* This is here to catch predefined spaces which do not get
5646 modified by the user's input. Another call is found at
5647 the bottom of pa_parse_space_stmt to handle cases where
5648 the user modifies a predefined space. */
5649 #ifdef obj_set_section_attributes
5650 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5656 /* Create a new subspace NAME, with the appropriate flags as defined
5657 by the given parameters.
5659 Add the new subspace to the subspace dictionary chain in numerical
5660 order as defined by the SORT entries. */
5662 static ssd_chain_struct
*
5663 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5664 dup_common
, is_zero
, sort
, access
, space_index
,
5665 alignment
, quadrant
, seg
)
5666 sd_chain_struct
*space
;
5668 int loadable
, code_only
, common
, dup_common
, is_zero
;
5676 ssd_chain_struct
*chain_entry
;
5678 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5680 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5682 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5683 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5685 /* Initialize subspace_defined. When we hit a .subspace directive
5686 we'll set it to 1 which "locks-in" the subspace attributes. */
5687 SUBSPACE_DEFINED (chain_entry
) = 0;
5689 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5690 chain_entry
->ssd_seg
= seg
;
5691 chain_entry
->ssd_next
= NULL
;
5693 /* Find spot for the new subspace based on its sort key. */
5694 if (space
->sd_subspaces
== NULL
)
5695 space
->sd_subspaces
= chain_entry
;
5698 ssd_chain_struct
*chain_pointer
;
5699 ssd_chain_struct
*prev_chain_pointer
;
5701 chain_pointer
= space
->sd_subspaces
;
5702 prev_chain_pointer
= NULL
;
5704 while (chain_pointer
)
5706 prev_chain_pointer
= chain_pointer
;
5707 chain_pointer
= chain_pointer
->ssd_next
;
5710 /* Now we have somewhere to put the new entry. Insert it and update
5712 if (prev_chain_pointer
)
5714 chain_entry
->ssd_next
= chain_pointer
;
5715 prev_chain_pointer
->ssd_next
= chain_entry
;
5719 space
->sd_subspaces
= chain_entry
;
5720 chain_entry
->ssd_next
= chain_pointer
;
5724 #ifdef obj_set_subsection_attributes
5725 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5732 /* Update the information for the given subspace based upon the
5733 various arguments. Return the modified subspace chain entry. */
5735 static ssd_chain_struct
*
5736 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5737 zero
, access
, space_index
, alignment
, quadrant
, section
)
5738 sd_chain_struct
*space
;
5752 ssd_chain_struct
*chain_entry
;
5754 chain_entry
= is_defined_subspace (name
);
5756 #ifdef obj_set_subsection_attributes
5757 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5764 /* Return the space chain entry for the space with the name NAME or
5765 NULL if no such space exists. */
5767 static sd_chain_struct
*
5768 is_defined_space (name
)
5771 sd_chain_struct
*chain_pointer
;
5773 for (chain_pointer
= space_dict_root
;
5775 chain_pointer
= chain_pointer
->sd_next
)
5777 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5778 return chain_pointer
;
5781 /* No mapping from segment to space was found. Return NULL. */
5785 /* Find and return the space associated with the given seg. If no mapping
5786 from the given seg to a space is found, then return NULL.
5788 Unlike subspaces, the number of spaces is not expected to grow much,
5789 so a linear exhaustive search is OK here. */
5791 static sd_chain_struct
*
5792 pa_segment_to_space (seg
)
5795 sd_chain_struct
*space_chain
;
5797 /* Walk through each space looking for the correct mapping. */
5798 for (space_chain
= space_dict_root
;
5800 space_chain
= space_chain
->sd_next
)
5802 if (space_chain
->sd_seg
== seg
)
5806 /* Mapping was not found. Return NULL. */
5810 /* Return the space chain entry for the subspace with the name NAME or
5811 NULL if no such subspace exists.
5813 Uses a linear search through all the spaces and subspaces, this may
5814 not be appropriate if we ever being placing each function in its
5817 static ssd_chain_struct
*
5818 is_defined_subspace (name
)
5821 sd_chain_struct
*space_chain
;
5822 ssd_chain_struct
*subspace_chain
;
5824 /* Walk through each space. */
5825 for (space_chain
= space_dict_root
;
5827 space_chain
= space_chain
->sd_next
)
5829 /* Walk through each subspace looking for a name which matches. */
5830 for (subspace_chain
= space_chain
->sd_subspaces
;
5832 subspace_chain
= subspace_chain
->ssd_next
)
5833 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5834 return subspace_chain
;
5837 /* Subspace wasn't found. Return NULL. */
5841 /* Find and return the subspace associated with the given seg. If no
5842 mapping from the given seg to a subspace is found, then return NULL.
5844 If we ever put each procedure/function within its own subspace
5845 (to make life easier on the compiler and linker), then this will have
5846 to become more efficient. */
5848 static ssd_chain_struct
*
5849 pa_subsegment_to_subspace (seg
, subseg
)
5853 sd_chain_struct
*space_chain
;
5854 ssd_chain_struct
*subspace_chain
;
5856 /* Walk through each space. */
5857 for (space_chain
= space_dict_root
;
5859 space_chain
= space_chain
->sd_next
)
5861 if (space_chain
->sd_seg
== seg
)
5863 /* Walk through each subspace within each space looking for
5864 the correct mapping. */
5865 for (subspace_chain
= space_chain
->sd_subspaces
;
5867 subspace_chain
= subspace_chain
->ssd_next
)
5868 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5869 return subspace_chain
;
5873 /* No mapping from subsegment to subspace found. Return NULL. */
5877 /* Given a number, try and find a space with the name number.
5879 Return a pointer to a space dictionary chain entry for the space
5880 that was found or NULL on failure. */
5882 static sd_chain_struct
*
5883 pa_find_space_by_number (number
)
5886 sd_chain_struct
*space_chain
;
5888 for (space_chain
= space_dict_root
;
5890 space_chain
= space_chain
->sd_next
)
5892 if (SPACE_SPNUM (space_chain
) == number
)
5896 /* No appropriate space found. Return NULL. */
5900 /* Return the starting address for the given subspace. If the starting
5901 address is unknown then return zero. */
5904 pa_subspace_start (space
, quadrant
)
5905 sd_chain_struct
*space
;
5908 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5909 is not correct for the PA OSF1 port. */
5910 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5912 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5918 /* FIXME. Needs documentation. */
5920 pa_next_subseg (space
)
5921 sd_chain_struct
*space
;
5924 space
->sd_last_subseg
++;
5925 return space
->sd_last_subseg
;
5928 /* Helper function for pa_stringer. Used to find the end of
5935 unsigned int c
= *s
& CHAR_MASK
;
5947 /* Handle a .STRING type pseudo-op. */
5950 pa_stringer (append_zero
)
5953 char *s
, num_buf
[4];
5957 /* Preprocess the string to handle PA-specific escape sequences.
5958 For example, \xDD where DD is a hexidecimal number should be
5959 changed to \OOO where OOO is an octal number. */
5961 /* Skip the opening quote. */
5962 s
= input_line_pointer
+ 1;
5964 while (is_a_char (c
= pa_stringer_aux (s
++)))
5971 /* Handle \x<num>. */
5974 unsigned int number
;
5979 /* Get pas the 'x'. */
5981 for (num_digit
= 0, number
= 0, dg
= *s
;
5983 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
5984 || (dg
>= 'A' && dg
<= 'F'));
5988 number
= number
* 16 + dg
- '0';
5989 else if (dg
>= 'a' && dg
<= 'f')
5990 number
= number
* 16 + dg
- 'a' + 10;
5992 number
= number
* 16 + dg
- 'A' + 10;
6002 sprintf (num_buf
, "%02o", number
);
6005 sprintf (num_buf
, "%03o", number
);
6008 for (i
= 0; i
<= num_digit
; i
++)
6009 s_start
[i
] = num_buf
[i
];
6013 /* This might be a "\"", skip over the escaped char. */
6020 stringer (append_zero
);
6021 pa_undefine_label ();
6024 /* Handle a .VERSION pseudo-op. */
6031 pa_undefine_label ();
6034 /* Handle a .COPYRIGHT pseudo-op. */
6037 pa_copyright (unused
)
6041 pa_undefine_label ();
6044 /* Just like a normal cons, but when finished we have to undefine
6045 the latest space label. */
6052 pa_undefine_label ();
6055 /* Switch to the data space. As usual delete our label. */
6062 pa_undefine_label ();
6065 /* Like float_cons, but we need to undefine our label. */
6068 pa_float_cons (float_type
)
6071 float_cons (float_type
);
6072 pa_undefine_label ();
6075 /* Like s_fill, but delete our label when finished. */
6082 pa_undefine_label ();
6085 /* Like lcomm, but delete our label when finished. */
6088 pa_lcomm (needs_align
)
6091 s_lcomm (needs_align
);
6092 pa_undefine_label ();
6095 /* Like lsym, but delete our label when finished. */
6102 pa_undefine_label ();
6105 /* Switch to the text space. Like s_text, but delete our
6106 label when finished. */
6112 pa_undefine_label ();
6115 /* On the PA relocations which involve function symbols must not be
6116 adjusted. This so that the linker can know when/how to create argument
6117 relocation stubs for indirect calls and calls to static functions.
6119 "T" field selectors create DLT relative fixups for accessing
6120 globals and statics in PIC code; each DLT relative fixup creates
6121 an entry in the DLT table. The entries contain the address of
6122 the final target (eg accessing "foo" would create a DLT entry
6123 with the address of "foo").
6125 Unfortunately, the HP linker doesn't take into account any addend
6126 when generating the DLT; so accessing $LIT$+8 puts the address of
6127 $LIT$ into the DLT rather than the address of $LIT$+8.
6129 The end result is we can't perform relocation symbol reductions for
6130 any fixup which creates entries in the DLT (eg they use "T" field
6133 FIXME. Also reject R_HPPA relocations which are 32 bits
6134 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6135 needs to generate relocations to push the addend and symbol value
6136 onto the stack, add them, then pop the value off the stack and
6137 use it in a relocation -- yuk. */
6140 hppa_fix_adjustable (fixp
)
6143 struct hppa_fix_struct
*hppa_fix
;
6145 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6147 /* Reject reductions of symbols in 32bit plabel relocs. */
6148 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6151 /* Reject reductions of symbols in DLT relative relocs. */
6152 if (hppa_fix
->fx_r_field
== e_tsel
6153 || hppa_fix
->fx_r_field
== e_ltsel
6154 || hppa_fix
->fx_r_field
== e_rtsel
)
6157 /* Reject reductions of function symbols. */
6158 if (fixp
->fx_addsy
== 0
6159 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6165 /* Return nonzero if the fixup in FIXP will require a relocation,
6166 even it if appears that the fixup could be completely handled
6170 hppa_force_relocation (fixp
)
6173 struct hppa_fix_struct
*hppa_fixp
;
6175 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6177 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6181 #define stub_needed(CALLER, CALLEE) \
6182 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6184 /* It is necessary to force PC-relative calls/jumps to have a relocation
6185 entry if they're going to need either a argument relocation or long
6186 call stub. FIXME. Can't we need the same for absolute calls? */
6187 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6188 && (stub_needed (((obj_symbol_type
*)
6189 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6190 hppa_fixp
->fx_arg_reloc
)))
6195 /* No need (yet) to force another relocations to be emitted. */
6199 /* Now for some ELF specific code. FIXME. */
6201 /* Mark the end of a function so that it's possible to compute
6202 the size of the function in hppa_elf_final_processing. */
6205 hppa_elf_mark_end_of_function ()
6207 /* ELF does not have EXIT relocations. All we do is create a
6208 temporary symbol marking the end of the function. */
6209 char *name
= (char *)
6210 xmalloc (strlen ("L$\001end_") +
6211 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6217 strcpy (name
, "L$\001end_");
6218 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6220 /* If we have a .exit followed by a .procend, then the
6221 symbol will have already been defined. */
6222 symbolP
= symbol_find (name
);
6225 /* The symbol has already been defined! This can
6226 happen if we have a .exit followed by a .procend.
6228 This is *not* an error. All we want to do is free
6229 the memory we just allocated for the name and continue. */
6234 /* symbol value should be the offset of the
6235 last instruction of the function */
6236 symbolP
= symbol_new (name
, now_seg
,
6237 (valueT
) (obstack_next_free (&frags
)
6238 - frag_now
->fr_literal
- 4),
6242 symbolP
->bsym
->flags
= BSF_LOCAL
;
6243 symbol_table_insert (symbolP
);
6247 last_call_info
->end_symbol
= symbolP
;
6249 as_bad ("Symbol '%s' could not be created.", name
);
6253 as_bad ("No memory for symbol name.");
6257 /* For ELF, this function serves one purpose: to setup the st_size
6258 field of STT_FUNC symbols. To do this, we need to scan the
6259 call_info structure list, determining st_size in by taking the
6260 difference in the address of the beginning/end marker symbols. */
6263 elf_hppa_final_processing ()
6265 struct call_info
*call_info_pointer
;
6267 for (call_info_pointer
= call_info_root
;
6269 call_info_pointer
= call_info_pointer
->ci_next
)
6271 elf_symbol_type
*esym
6272 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6273 esym
->internal_elf_sym
.st_size
=
6274 S_GET_VALUE (call_info_pointer
->end_symbol
)
6275 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;