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 segment this fixup appears in. */
428 /* Structure to hold information about predefined registers. */
436 /* This structure defines the mapping from a FP condition string
437 to a condition number which can be recorded in an instruction. */
444 /* This structure defines a mapping from a field selector
445 string to a field selector type. */
446 struct selector_entry
452 /* Prototypes for functions local to tc-hppa.c. */
454 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
455 static void pa_cons
PARAMS ((int));
456 static void pa_data
PARAMS ((int));
457 static void pa_float_cons
PARAMS ((int));
458 static void pa_fill
PARAMS ((int));
459 static void pa_lcomm
PARAMS ((int));
460 static void pa_lsym
PARAMS ((int));
461 static void pa_stringer
PARAMS ((int));
462 static void pa_text
PARAMS ((int));
463 static void pa_version
PARAMS ((int));
464 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
465 static int get_expression
PARAMS ((char *));
466 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
467 static int evaluate_absolute
PARAMS ((struct pa_it
*));
468 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
469 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
470 static int pa_parse_nullif
PARAMS ((char **));
471 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
472 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
473 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
474 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
475 static void pa_align
PARAMS ((int));
476 static void pa_block
PARAMS ((int));
477 static void pa_call
PARAMS ((int));
478 static void pa_call_args
PARAMS ((struct call_desc
*));
479 static void pa_callinfo
PARAMS ((int));
480 static void pa_code
PARAMS ((int));
481 static void pa_comm
PARAMS ((int));
482 static void pa_copyright
PARAMS ((int));
483 static void pa_end
PARAMS ((int));
484 static void pa_enter
PARAMS ((int));
485 static void pa_entry
PARAMS ((int));
486 static void pa_equ
PARAMS ((int));
487 static void pa_exit
PARAMS ((int));
488 static void pa_export
PARAMS ((int));
489 static void pa_type_args
PARAMS ((symbolS
*, int));
490 static void pa_import
PARAMS ((int));
491 static void pa_label
PARAMS ((int));
492 static void pa_leave
PARAMS ((int));
493 static void pa_origin
PARAMS ((int));
494 static void pa_proc
PARAMS ((int));
495 static void pa_procend
PARAMS ((int));
496 static void pa_space
PARAMS ((int));
497 static void pa_spnum
PARAMS ((int));
498 static void pa_subspace
PARAMS ((int));
499 static void pa_param
PARAMS ((int));
500 static void pa_undefine_label
PARAMS ((void));
501 static int need_89_opcode
PARAMS ((struct pa_it
*,
502 struct pa_89_fp_reg_struct
*));
503 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
504 static label_symbol_struct
*pa_get_label
PARAMS ((void));
505 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
508 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
513 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
514 char *, int, int, int,
518 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
519 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
520 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
521 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
523 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
524 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
525 static void pa_ip
PARAMS ((char *));
526 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
527 long, expressionS
*, int,
528 bfd_reloc_code_real_type
,
529 enum hppa_reloc_field_selector_type
,
531 static int is_end_of_statement
PARAMS ((void));
532 static int reg_name_search
PARAMS ((char *));
533 static int pa_chk_field_selector
PARAMS ((char **));
534 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
535 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
536 static void process_exit
PARAMS ((void));
537 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
538 static int log2
PARAMS ((int));
539 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
540 static unsigned int pa_stringer_aux
PARAMS ((char *));
541 static void pa_spaces_begin
PARAMS ((void));
542 static void hppa_elf_mark_end_of_function
PARAMS ((void));
544 /* File and gloally scoped variable declarations. */
546 /* Root and final entry in the space chain. */
547 static sd_chain_struct
*space_dict_root
;
548 static sd_chain_struct
*space_dict_last
;
550 /* The current space and subspace. */
551 static sd_chain_struct
*current_space
;
552 static ssd_chain_struct
*current_subspace
;
554 /* Root of the call_info chain. */
555 static struct call_info
*call_info_root
;
557 /* The last call_info (for functions) structure
558 seen so it can be associated with fixups and
560 static struct call_info
*last_call_info
;
562 /* The last call description (for actual calls). */
563 static struct call_desc last_call_desc
;
565 /* Relaxation isn't supported for the PA yet. */
566 const relax_typeS md_relax_table
[] =
569 /* Jumps are always the same size -- one instruction. */
570 int md_short_jump_size
= 4;
571 int md_long_jump_size
= 4;
573 /* handle of the OPCODE hash table */
574 static struct hash_control
*op_hash
= NULL
;
576 /* This array holds the chars that always start a comment. If the
577 pre-processor is disabled, these aren't very useful. */
578 const char comment_chars
[] = ";";
580 /* Table of pseudo ops for the PA. FIXME -- how many of these
581 are now redundant with the overall GAS and the object file
583 const pseudo_typeS md_pseudo_table
[] =
585 /* align pseudo-ops on the PA specify the actual alignment requested,
586 not the log2 of the requested alignment. */
587 {"align", pa_align
, 8},
588 {"block", pa_block
, 1},
589 {"blockz", pa_block
, 0},
590 {"byte", pa_cons
, 1},
591 {"call", pa_call
, 0},
592 {"callinfo", pa_callinfo
, 0},
593 {"code", pa_code
, 0},
594 {"comm", pa_comm
, 0},
595 {"copyright", pa_copyright
, 0},
596 {"data", pa_data
, 0},
597 {"double", pa_float_cons
, 'd'},
599 {"enter", pa_enter
, 0},
600 {"entry", pa_entry
, 0},
602 {"exit", pa_exit
, 0},
603 {"export", pa_export
, 0},
604 {"fill", pa_fill
, 0},
605 {"float", pa_float_cons
, 'f'},
606 {"half", pa_cons
, 2},
607 {"import", pa_import
, 0},
609 {"label", pa_label
, 0},
610 {"lcomm", pa_lcomm
, 0},
611 {"leave", pa_leave
, 0},
612 {"long", pa_cons
, 4},
613 {"lsym", pa_lsym
, 0},
614 {"octa", pa_cons
, 16},
615 {"org", pa_origin
, 0},
616 {"origin", pa_origin
, 0},
617 {"param", pa_param
, 0},
618 {"proc", pa_proc
, 0},
619 {"procend", pa_procend
, 0},
620 {"quad", pa_cons
, 8},
622 {"short", pa_cons
, 2},
623 {"single", pa_float_cons
, 'f'},
624 {"space", pa_space
, 0},
625 {"spnum", pa_spnum
, 0},
626 {"string", pa_stringer
, 0},
627 {"stringz", pa_stringer
, 1},
628 {"subspa", pa_subspace
, 0},
629 {"text", pa_text
, 0},
630 {"version", pa_version
, 0},
631 {"word", pa_cons
, 4},
635 /* This array holds the chars that only start a comment at the beginning of
636 a line. If the line seems to have the form '# 123 filename'
637 .line and .file directives will appear in the pre-processed output.
639 Note that input_file.c hand checks for '#' at the beginning of the
640 first line of the input file. This is because the compiler outputs
641 #NO_APP at the beginning of its output.
643 Also note that '/*' will always start a comment. */
644 const char line_comment_chars
[] = "#";
646 /* This array holds the characters which act as line separators. */
647 const char line_separator_chars
[] = "!";
649 /* Chars that can be used to separate mant from exp in floating point nums. */
650 const char EXP_CHARS
[] = "eE";
652 /* Chars that mean this number is a floating point constant.
653 As in 0f12.456 or 0d1.2345e12.
655 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
656 changed in read.c. Ideally it shouldn't hae to know abou it at
657 all, but nothing is ideal around here. */
658 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
660 static struct pa_it the_insn
;
662 /* Points to the end of an expression just parsed by get_expressoin
663 and friends. FIXME. This shouldn't be handled with a file-global
665 static char *expr_end
;
667 /* Nonzero if a .callinfo appeared within the current procedure. */
668 static int callinfo_found
;
670 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
671 static int within_entry_exit
;
673 /* Nonzero if the assembler is currently within a procedure definition. */
674 static int within_procedure
;
676 /* Handle on strucutre which keep track of the last symbol
677 seen in each subspace. */
678 static label_symbol_struct
*label_symbols_rootp
= NULL
;
680 /* Holds the last field selector. */
681 static int hppa_field_selector
;
683 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
684 static symbolS
*dummy_symbol
;
686 /* Nonzero if errors are to be printed. */
687 static int print_errors
= 1;
689 /* List of registers that are pre-defined:
691 Each general register has one predefined name of the form
692 %r<REGNUM> which has the value <REGNUM>.
694 Space and control registers are handled in a similar manner,
695 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
697 Likewise for the floating point registers, but of the form
698 %fr<REGNUM>. Floating point registers have additional predefined
699 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
700 again have the value <REGNUM>.
702 Many registers also have synonyms:
704 %r26 - %r23 have %arg0 - %arg3 as synonyms
705 %r28 - %r29 have %ret0 - %ret1 as synonyms
706 %r30 has %sp as a synonym
707 %r27 has %dp as a synonym
708 %r2 has %rp as a synonym
710 Almost every control register has a synonym; they are not listed
713 The table is sorted. Suitable for searching by a binary search. */
715 static const struct pd_reg pre_defined_registers
[] =
915 /* This table is sorted by order of the length of the string. This is
916 so we check for <> before we check for <. If we had a <> and checked
917 for < first, we would get a false match. */
918 static const struct fp_cond_map fp_cond_map
[] =
954 static const struct selector_entry selector_table
[] =
973 /* default space and subspace dictionaries */
975 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
976 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
978 /* pre-defined subsegments (subspaces) for the HPPA. */
979 #define SUBSEG_CODE 0
980 #define SUBSEG_DATA 0
983 #define SUBSEG_UNWIND 3
984 #define SUBSEG_GDB_STRINGS 0
985 #define SUBSEG_GDB_SYMBOLS 1
987 static struct default_subspace_dict pa_def_subspaces
[] =
989 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
990 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
991 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
992 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
994 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
996 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
999 static struct default_space_dict pa_def_spaces
[] =
1001 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1002 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1003 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1006 /* Misc local definitions used by the assembler. */
1008 /* Return nonzero if the string pointed to by S potentially represents
1009 a right or left half of a FP register */
1010 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1011 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1013 /* These macros are used to maintain spaces/subspaces. */
1014 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1015 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1016 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1017 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1019 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1020 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1022 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1023 main loop after insertion. */
1025 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1027 ((OPCODE) |= (FIELD) << (START)); \
1031 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1032 IGNORE is used to suppress the error message. */
1034 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1036 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1039 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1045 #define is_DP_relative(exp) \
1046 ((exp).X_op == O_subtract \
1047 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1049 #define is_PC_relative(exp) \
1050 ((exp).X_op == O_subtract \
1051 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1053 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1054 always be able to reduce the expression to a constant, so we don't
1055 need real complex handling yet. */
1056 #define is_complex(exp) \
1057 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1059 /* Actual functions to implement the PA specific code for the assembler. */
1061 /* Returns a pointer to the label_symbol_struct for the current space.
1062 or NULL if no label_symbol_struct exists for the current space. */
1064 static label_symbol_struct
*
1067 label_symbol_struct
*label_chain
;
1068 sd_chain_struct
*space_chain
= current_space
;
1070 for (label_chain
= label_symbols_rootp
;
1072 label_chain
= label_chain
->lss_next
)
1073 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1079 /* Defines a label for the current space. If one is already defined,
1080 this function will replace it with the new label. */
1083 pa_define_label (symbol
)
1086 label_symbol_struct
*label_chain
= pa_get_label ();
1087 sd_chain_struct
*space_chain
= current_space
;
1090 label_chain
->lss_label
= symbol
;
1093 /* Create a new label entry and add it to the head of the chain. */
1095 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1096 label_chain
->lss_label
= symbol
;
1097 label_chain
->lss_space
= space_chain
;
1098 label_chain
->lss_next
= NULL
;
1100 if (label_symbols_rootp
)
1101 label_chain
->lss_next
= label_symbols_rootp
;
1103 label_symbols_rootp
= label_chain
;
1107 /* Removes a label definition for the current space.
1108 If there is no label_symbol_struct entry, then no action is taken. */
1111 pa_undefine_label ()
1113 label_symbol_struct
*label_chain
;
1114 label_symbol_struct
*prev_label_chain
= NULL
;
1115 sd_chain_struct
*space_chain
= current_space
;
1117 for (label_chain
= label_symbols_rootp
;
1119 label_chain
= label_chain
->lss_next
)
1121 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1123 /* Remove the label from the chain and free its memory. */
1124 if (prev_label_chain
)
1125 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1127 label_symbols_rootp
= label_chain
->lss_next
;
1132 prev_label_chain
= label_chain
;
1137 /* An HPPA-specific version of fix_new. This is required because the HPPA
1138 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1139 results in the creation of an instance of an hppa_fix_struct. An
1140 hppa_fix_struct stores the extra information along with a pointer to the
1141 original fixS. This is attached to the original fixup via the
1142 tc_fix_data field. */
1145 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1146 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1150 symbolS
*add_symbol
;
1154 bfd_reloc_code_real_type r_type
;
1155 enum hppa_reloc_field_selector_type r_field
;
1162 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1163 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1166 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1168 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1169 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1170 hppa_fix
->fx_r_type
= r_type
;
1171 hppa_fix
->fx_r_field
= r_field
;
1172 hppa_fix
->fx_r_format
= r_format
;
1173 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1174 hppa_fix
->segment
= now_seg
;
1176 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1177 new_fix
->fx_offset
= *unwind_bits
;
1180 /* foo-$global$ is used to access non-automatic storage. $global$
1181 is really just a marker and has served its purpose, so eliminate
1182 it now so as not to confuse write.c. */
1183 if (new_fix
->fx_subsy
1184 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1185 new_fix
->fx_subsy
= NULL
;
1188 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1189 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1192 parse_cons_expression_hppa (exp
)
1195 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1199 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1200 hppa_field_selector is set by the parse_cons_expression_hppa. */
1203 cons_fix_new_hppa (frag
, where
, size
, exp
)
1209 unsigned int rel_type
;
1211 /* Get a base relocation type. */
1212 if (is_DP_relative (*exp
))
1213 rel_type
= R_HPPA_GOTOFF
;
1214 else if (is_complex (*exp
))
1215 rel_type
= R_HPPA_COMPLEX
;
1219 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1220 as_warn ("Invalid field selector. Assuming F%%.");
1222 fix_new_hppa (frag
, where
, size
,
1223 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1224 hppa_field_selector
, 32, 0, NULL
);
1226 /* Reset field selector to its default state. */
1227 hppa_field_selector
= 0;
1230 /* This function is called once, at assembler startup time. It should
1231 set up all the tables, etc. that the MD part of the assembler will need. */
1236 const char *retval
= NULL
;
1240 last_call_info
= NULL
;
1241 call_info_root
= NULL
;
1243 /* Folding of text and data segments fails miserably on the PA.
1244 Warn user and disable "-R" option. */
1245 if (flag_readonly_data_in_text
)
1247 as_warn ("-R option not supported on this target.");
1248 flag_readonly_data_in_text
= 0;
1253 op_hash
= hash_new ();
1255 while (i
< NUMOPCODES
)
1257 const char *name
= pa_opcodes
[i
].name
;
1258 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1259 if (retval
!= NULL
&& *retval
!= '\0')
1261 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1266 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1267 != pa_opcodes
[i
].match
)
1269 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1270 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1275 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1279 as_fatal ("Broken assembler. No assembly attempted.");
1281 /* SOM will change text_section. To make sure we never put
1282 anything into the old one switch to the new one now. */
1283 subseg_set (text_section
, 0);
1285 dummy_symbol
= symbol_find_or_make ("L$dummy");
1286 S_SET_SEGMENT (dummy_symbol
, text_section
);
1289 /* Assemble a single instruction storing it into a frag. */
1296 /* The had better be something to assemble. */
1299 /* If we are within a procedure definition, make sure we've
1300 defined a label for the procedure; handle case where the
1301 label was defined after the .PROC directive.
1303 Note there's not need to diddle with the segment or fragment
1304 for the label symbol in this case. We have already switched
1305 into the new $CODE$ subspace at this point. */
1306 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1308 label_symbol_struct
*label_symbol
= pa_get_label ();
1312 if (label_symbol
->lss_label
)
1314 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1315 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1317 /* Also handle allocation of a fixup to hold the unwind
1318 information when the label appears after the proc/procend. */
1319 if (within_entry_exit
)
1321 char *where
= frag_more (0);
1323 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1324 NULL
, (offsetT
) 0, NULL
,
1325 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1326 (int *)&last_call_info
->ci_unwind
.descriptor
);
1331 as_bad ("Missing function name for .PROC (corrupted label chain)");
1334 as_bad ("Missing function name for .PROC");
1337 /* Assemble the instruction. Results are saved into "the_insn". */
1340 /* Get somewhere to put the assembled instrution. */
1343 /* Output the opcode. */
1344 md_number_to_chars (to
, the_insn
.opcode
, 4);
1346 /* If necessary output more stuff. */
1347 if (the_insn
.reloc
!= R_HPPA_NONE
)
1348 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1349 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1350 the_insn
.reloc
, the_insn
.field_selector
,
1351 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1354 /* Do the real work for assembling a single instruction. Store results
1355 into the global "the_insn" variable. */
1361 char *error_message
= "";
1362 char *s
, c
, *argstart
, *name
, *save_s
;
1366 int cmpltr
, nullif
, flag
, cond
, num
;
1367 unsigned long opcode
;
1368 struct pa_opcode
*insn
;
1370 /* Skip to something interesting. */
1371 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1390 as_fatal ("Unknown opcode: `%s'", str
);
1395 /* Convert everything into lower case. */
1398 if (isupper (*save_s
))
1399 *save_s
= tolower (*save_s
);
1403 /* Look up the opcode in the has table. */
1404 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1406 as_bad ("Unknown opcode: `%s'", str
);
1415 /* Mark the location where arguments for the instruction start, then
1416 start processing them. */
1420 /* Do some initialization. */
1421 opcode
= insn
->match
;
1422 bzero (&the_insn
, sizeof (the_insn
));
1424 the_insn
.reloc
= R_HPPA_NONE
;
1426 /* Build the opcode, checking as we go to make
1427 sure that the operands match. */
1428 for (args
= insn
->args
;; ++args
)
1433 /* End of arguments. */
1449 /* These must match exactly. */
1458 /* Handle a 5 bit register or control register field at 10. */
1461 num
= pa_parse_number (&s
, 0);
1462 CHECK_FIELD (num
, 31, 0, 0);
1463 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1465 /* Handle a 5 bit register field at 15. */
1467 num
= pa_parse_number (&s
, 0);
1468 CHECK_FIELD (num
, 31, 0, 0);
1469 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1471 /* Handle a 5 bit register field at 31. */
1474 num
= pa_parse_number (&s
, 0);
1475 CHECK_FIELD (num
, 31, 0, 0);
1476 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1478 /* Handle a 5 bit field length at 31. */
1480 num
= pa_get_absolute_expression (&the_insn
, &s
);
1482 CHECK_FIELD (num
, 32, 1, 0);
1483 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1485 /* Handle a 5 bit immediate at 15. */
1487 num
= pa_get_absolute_expression (&the_insn
, &s
);
1489 CHECK_FIELD (num
, 15, -16, 0);
1490 low_sign_unext (num
, 5, &num
);
1491 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1493 /* Handle a 5 bit immediate at 31. */
1495 num
= pa_get_absolute_expression (&the_insn
, &s
);
1497 CHECK_FIELD (num
, 15, -16, 0)
1498 low_sign_unext (num
, 5, &num
);
1499 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1501 /* Handle an unsigned 5 bit immediate at 31. */
1503 num
= pa_get_absolute_expression (&the_insn
, &s
);
1505 CHECK_FIELD (num
, 31, 0, 0);
1506 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1508 /* Handle an unsigned 5 bit immediate at 15. */
1510 num
= pa_get_absolute_expression (&the_insn
, &s
);
1512 CHECK_FIELD (num
, 31, 0, 0);
1513 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1515 /* Handle a 2 bit space identifier at 17. */
1517 num
= pa_parse_number (&s
, 0);
1518 CHECK_FIELD (num
, 3, 0, 1);
1519 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1521 /* Handle a 3 bit space identifier at 18. */
1523 num
= pa_parse_number (&s
, 0);
1524 CHECK_FIELD (num
, 7, 0, 1);
1525 dis_assemble_3 (num
, &num
);
1526 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1528 /* Handle a completer for an indexing load or store. */
1534 while (*s
== ',' && i
< 2)
1537 if (strncasecmp (s
, "sm", 2) == 0)
1544 else if (strncasecmp (s
, "m", 1) == 0)
1546 else if (strncasecmp (s
, "s", 1) == 0)
1549 as_bad ("Invalid Indexed Load Completer.");
1554 as_bad ("Invalid Indexed Load Completer Syntax.");
1556 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1559 /* Handle a short load/store completer. */
1567 if (strncasecmp (s
, "ma", 2) == 0)
1572 else if (strncasecmp (s
, "mb", 2) == 0)
1578 as_bad ("Invalid Short Load/Store Completer.");
1582 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1585 /* Handle a stbys completer. */
1591 while (*s
== ',' && i
< 2)
1594 if (strncasecmp (s
, "m", 1) == 0)
1596 else if (strncasecmp (s
, "b", 1) == 0)
1598 else if (strncasecmp (s
, "e", 1) == 0)
1601 as_bad ("Invalid Store Bytes Short Completer");
1606 as_bad ("Invalid Store Bytes Short Completer");
1608 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1611 /* Handle a non-negated compare/stubtract condition. */
1613 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1616 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1619 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1621 /* Handle a negated or non-negated compare/subtract condition. */
1624 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1628 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1631 as_bad ("Invalid Compare/Subtract Condition.");
1636 /* Negated condition requires an opcode change. */
1640 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1642 /* Handle non-negated add condition. */
1644 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1647 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1650 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1652 /* Handle a negated or non-negated add condition. */
1655 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1659 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1662 as_bad ("Invalid Compare/Subtract Condition");
1667 /* Negated condition requires an opcode change. */
1671 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1673 /* Handle a compare/subtract condition. */
1680 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1685 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1688 as_bad ("Invalid Compare/Subtract Condition");
1692 opcode
|= cmpltr
<< 13;
1693 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1695 /* Handle a non-negated add condition. */
1704 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1708 if (strcmp (name
, "=") == 0)
1710 else if (strcmp (name
, "<") == 0)
1712 else if (strcmp (name
, "<=") == 0)
1714 else if (strcasecmp (name
, "nuv") == 0)
1716 else if (strcasecmp (name
, "znv") == 0)
1718 else if (strcasecmp (name
, "sv") == 0)
1720 else if (strcasecmp (name
, "od") == 0)
1722 else if (strcasecmp (name
, "n") == 0)
1724 else if (strcasecmp (name
, "tr") == 0)
1729 else if (strcmp (name
, "<>") == 0)
1734 else if (strcmp (name
, ">=") == 0)
1739 else if (strcmp (name
, ">") == 0)
1744 else if (strcasecmp (name
, "uv") == 0)
1749 else if (strcasecmp (name
, "vnz") == 0)
1754 else if (strcasecmp (name
, "nsv") == 0)
1759 else if (strcasecmp (name
, "ev") == 0)
1765 as_bad ("Invalid Add Condition: %s", name
);
1768 nullif
= pa_parse_nullif (&s
);
1769 opcode
|= nullif
<< 1;
1770 opcode
|= cmpltr
<< 13;
1771 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1773 /* HANDLE a logical instruction condition. */
1781 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1785 if (strcmp (name
, "=") == 0)
1787 else if (strcmp (name
, "<") == 0)
1789 else if (strcmp (name
, "<=") == 0)
1791 else if (strcasecmp (name
, "od") == 0)
1793 else if (strcasecmp (name
, "tr") == 0)
1798 else if (strcmp (name
, "<>") == 0)
1803 else if (strcmp (name
, ">=") == 0)
1808 else if (strcmp (name
, ">") == 0)
1813 else if (strcasecmp (name
, "ev") == 0)
1819 as_bad ("Invalid Logical Instruction Condition.");
1822 opcode
|= cmpltr
<< 13;
1823 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1825 /* Handle a unit instruction condition. */
1832 if (strncasecmp (s
, "sbz", 3) == 0)
1837 else if (strncasecmp (s
, "shz", 3) == 0)
1842 else if (strncasecmp (s
, "sdc", 3) == 0)
1847 else if (strncasecmp (s
, "sbc", 3) == 0)
1852 else if (strncasecmp (s
, "shc", 3) == 0)
1857 else if (strncasecmp (s
, "tr", 2) == 0)
1863 else if (strncasecmp (s
, "nbz", 3) == 0)
1869 else if (strncasecmp (s
, "nhz", 3) == 0)
1875 else if (strncasecmp (s
, "ndc", 3) == 0)
1881 else if (strncasecmp (s
, "nbc", 3) == 0)
1887 else if (strncasecmp (s
, "nhc", 3) == 0)
1894 as_bad ("Invalid Logical Instruction Condition.");
1896 opcode
|= cmpltr
<< 13;
1897 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1899 /* Handle a shift/extract/deposit condition. */
1907 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1911 if (strcmp (name
, "=") == 0)
1913 else if (strcmp (name
, "<") == 0)
1915 else if (strcasecmp (name
, "od") == 0)
1917 else if (strcasecmp (name
, "tr") == 0)
1919 else if (strcmp (name
, "<>") == 0)
1921 else if (strcmp (name
, ">=") == 0)
1923 else if (strcasecmp (name
, "ev") == 0)
1925 /* Handle movb,n. Put things back the way they were.
1926 This includes moving s back to where it started. */
1927 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1934 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1937 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1939 /* Handle bvb and bb conditions. */
1945 if (strncmp (s
, "<", 1) == 0)
1950 else if (strncmp (s
, ">=", 2) == 0)
1956 as_bad ("Invalid Bit Branch Condition: %c", *s
);
1958 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1960 /* Handle a system control completer. */
1962 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
1970 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1972 /* Handle a nullification completer for branch instructions. */
1974 nullif
= pa_parse_nullif (&s
);
1975 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
1977 /* Handle a nullification completer for copr and spop insns. */
1979 nullif
= pa_parse_nullif (&s
);
1980 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
1982 /* Handle a 11 bit immediate at 31. */
1984 the_insn
.field_selector
= pa_chk_field_selector (&s
);
1987 if (the_insn
.exp
.X_op
== O_constant
)
1989 num
= evaluate_absolute (&the_insn
);
1990 CHECK_FIELD (num
, 1023, -1024, 0);
1991 low_sign_unext (num
, 11, &num
);
1992 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1996 if (is_DP_relative (the_insn
.exp
))
1997 the_insn
.reloc
= R_HPPA_GOTOFF
;
1998 else if (is_PC_relative (the_insn
.exp
))
1999 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2001 the_insn
.reloc
= R_HPPA
;
2002 the_insn
.format
= 11;
2006 /* Handle a 14 bit immediate at 31. */
2008 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2011 if (the_insn
.exp
.X_op
== O_constant
)
2013 num
= evaluate_absolute (&the_insn
);
2014 CHECK_FIELD (num
, 8191, -8192, 0);
2015 low_sign_unext (num
, 14, &num
);
2016 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2020 if (is_DP_relative (the_insn
.exp
))
2021 the_insn
.reloc
= R_HPPA_GOTOFF
;
2022 else if (is_PC_relative (the_insn
.exp
))
2023 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2025 the_insn
.reloc
= R_HPPA
;
2026 the_insn
.format
= 14;
2030 /* Handle a 21 bit immediate at 31. */
2032 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2035 if (the_insn
.exp
.X_op
== O_constant
)
2037 num
= evaluate_absolute (&the_insn
);
2038 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2039 dis_assemble_21 (num
, &num
);
2040 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2044 if (is_DP_relative (the_insn
.exp
))
2045 the_insn
.reloc
= R_HPPA_GOTOFF
;
2046 else if (is_PC_relative (the_insn
.exp
))
2047 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2049 the_insn
.reloc
= R_HPPA
;
2050 the_insn
.format
= 21;
2054 /* Handle a 12 bit branch displacement. */
2056 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2060 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2062 unsigned int w1
, w
, result
;
2064 num
= evaluate_absolute (&the_insn
);
2067 as_bad ("Branch to unaligned address");
2070 CHECK_FIELD (num
, 8191, -8192, 0);
2071 sign_unext ((num
- 8) >> 2, 12, &result
);
2072 dis_assemble_12 (result
, &w1
, &w
);
2073 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2077 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2078 the_insn
.format
= 12;
2079 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2080 bzero (&last_call_desc
, sizeof (struct call_desc
));
2085 /* Handle a 17 bit branch displacement. */
2087 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2091 if (!the_insn
.exp
.X_add_symbol
2092 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2095 unsigned int w2
, w1
, w
, result
;
2097 num
= evaluate_absolute (&the_insn
);
2100 as_bad ("Branch to unaligned address");
2103 CHECK_FIELD (num
, 262143, -262144, 0);
2105 if (the_insn
.exp
.X_add_symbol
)
2108 sign_unext (num
>> 2, 17, &result
);
2109 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2110 INSERT_FIELD_AND_CONTINUE (opcode
,
2111 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2115 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2116 the_insn
.format
= 17;
2117 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2118 bzero (&last_call_desc
, sizeof (struct call_desc
));
2122 /* Handle an absolute 17 bit branch target. */
2124 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2128 if (!the_insn
.exp
.X_add_symbol
2129 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2132 unsigned int w2
, w1
, w
, result
;
2134 num
= evaluate_absolute (&the_insn
);
2137 as_bad ("Branch to unaligned address");
2140 CHECK_FIELD (num
, 262143, -262144, 0);
2142 if (the_insn
.exp
.X_add_symbol
)
2145 sign_unext (num
>> 2, 17, &result
);
2146 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2147 INSERT_FIELD_AND_CONTINUE (opcode
,
2148 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2152 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2153 the_insn
.format
= 17;
2157 /* Handle a 5 bit shift count at 26. */
2159 num
= pa_get_absolute_expression (&the_insn
, &s
);
2161 CHECK_FIELD (num
, 31, 0, 0);
2162 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2164 /* Handle a 5 bit bit position at 26. */
2166 num
= pa_get_absolute_expression (&the_insn
, &s
);
2168 CHECK_FIELD (num
, 31, 0, 0);
2169 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2171 /* Handle a 5 bit immediate at 10. */
2173 num
= pa_get_absolute_expression (&the_insn
, &s
);
2175 CHECK_FIELD (num
, 31, 0, 0);
2176 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2178 /* Handle a 13 bit immediate at 18. */
2180 num
= pa_get_absolute_expression (&the_insn
, &s
);
2182 CHECK_FIELD (num
, 8191, 0, 0);
2183 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2185 /* Handle a 26 bit immediate at 31. */
2187 num
= pa_get_absolute_expression (&the_insn
, &s
);
2189 CHECK_FIELD (num
, 671108864, 0, 0);
2190 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2192 /* Handle a 3 bit SFU identifier at 25. */
2195 as_bad ("Invalid SFU identifier");
2196 num
= pa_get_absolute_expression (&the_insn
, &s
);
2198 CHECK_FIELD (num
, 7, 0, 0);
2199 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2201 /* Handle a 20 bit SOP field for spop0. */
2203 num
= pa_get_absolute_expression (&the_insn
, &s
);
2205 CHECK_FIELD (num
, 1048575, 0, 0);
2206 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2207 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2209 /* Handle a 15bit SOP field for spop1. */
2211 num
= pa_get_absolute_expression (&the_insn
, &s
);
2213 CHECK_FIELD (num
, 32767, 0, 0);
2214 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2216 /* Handle a 10bit SOP field for spop3. */
2218 num
= pa_get_absolute_expression (&the_insn
, &s
);
2220 CHECK_FIELD (num
, 1023, 0, 0);
2221 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2222 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2224 /* Handle a 15 bit SOP field for spop2. */
2226 num
= pa_get_absolute_expression (&the_insn
, &s
);
2228 CHECK_FIELD (num
, 32767, 0, 0);
2229 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2230 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2232 /* Handle a 3-bit co-processor ID field. */
2235 as_bad ("Invalid COPR identifier");
2236 num
= pa_get_absolute_expression (&the_insn
, &s
);
2238 CHECK_FIELD (num
, 7, 0, 0);
2239 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2241 /* Handle a 22bit SOP field for copr. */
2243 num
= pa_get_absolute_expression (&the_insn
, &s
);
2245 CHECK_FIELD (num
, 4194303, 0, 0);
2246 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2247 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2249 /* Handle a source FP operand format completer. */
2251 flag
= pa_parse_fp_format (&s
);
2252 the_insn
.fpof1
= flag
;
2253 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2255 /* Handle a destination FP operand format completer. */
2257 /* pa_parse_format needs the ',' prefix. */
2259 flag
= pa_parse_fp_format (&s
);
2260 the_insn
.fpof2
= flag
;
2261 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2263 /* Handle FP compare conditions. */
2265 cond
= pa_parse_fp_cmp_cond (&s
);
2266 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2268 /* Handle L/R register halves like 't'. */
2271 struct pa_89_fp_reg_struct result
;
2273 pa_parse_number (&s
, &result
);
2274 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2275 opcode
|= result
.number_part
;
2277 /* 0x30 opcodes are FP arithmetic operation opcodes
2278 and need to be turned into 0x38 opcodes. This
2279 is not necessary for loads/stores. */
2280 if (need_89_opcode (&the_insn
, &result
)
2281 && ((opcode
& 0xfc000000) == 0x30000000))
2284 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2287 /* Handle L/R register halves like 'b'. */
2290 struct pa_89_fp_reg_struct result
;
2292 pa_parse_number (&s
, &result
);
2293 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2294 opcode
|= result
.number_part
<< 21;
2295 if (need_89_opcode (&the_insn
, &result
))
2297 opcode
|= (result
.l_r_select
& 1) << 7;
2303 /* Handle L/R register halves like 'x'. */
2306 struct pa_89_fp_reg_struct result
;
2308 pa_parse_number (&s
, &result
);
2309 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2310 opcode
|= (result
.number_part
& 0x1f) << 16;
2311 if (need_89_opcode (&the_insn
, &result
))
2313 opcode
|= (result
.l_r_select
& 1) << 12;
2319 /* Handle a 5 bit register field at 10. */
2322 struct pa_89_fp_reg_struct result
;
2324 pa_parse_number (&s
, &result
);
2325 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2326 if (the_insn
.fpof1
== SGL
)
2328 result
.number_part
&= 0xF;
2329 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2331 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2334 /* Handle a 5 bit register field at 15. */
2337 struct pa_89_fp_reg_struct result
;
2339 pa_parse_number (&s
, &result
);
2340 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2341 if (the_insn
.fpof1
== SGL
)
2343 result
.number_part
&= 0xF;
2344 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2346 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2349 /* Handle a 5 bit register field at 31. */
2352 struct pa_89_fp_reg_struct result
;
2354 pa_parse_number (&s
, &result
);
2355 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2356 if (the_insn
.fpof1
== SGL
)
2358 result
.number_part
&= 0xF;
2359 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2361 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2364 /* Handle a 5 bit register field at 20. */
2367 struct pa_89_fp_reg_struct result
;
2369 pa_parse_number (&s
, &result
);
2370 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2371 if (the_insn
.fpof1
== SGL
)
2373 result
.number_part
&= 0xF;
2374 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2376 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2379 /* Handle a 5 bit register field at 25. */
2382 struct pa_89_fp_reg_struct result
;
2384 pa_parse_number (&s
, &result
);
2385 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2386 if (the_insn
.fpof1
== SGL
)
2388 result
.number_part
&= 0xF;
2389 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2391 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2394 /* Handle a floating point operand format at 26.
2395 Only allows single and double precision. */
2397 flag
= pa_parse_fp_format (&s
);
2403 the_insn
.fpof1
= flag
;
2409 as_bad ("Invalid Floating Point Operand Format.");
2419 /* Check if the args matched. */
2422 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2423 && !strcmp (insn
->name
, insn
[1].name
))
2431 as_bad ("Invalid operands %s", error_message
);
2438 the_insn
.opcode
= opcode
;
2441 /* Turn a string in input_line_pointer into a floating point constant of type
2442 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2443 emitted is stored in *sizeP . An error message or NULL is returned. */
2445 #define MAX_LITTLENUMS 6
2448 md_atof (type
, litP
, sizeP
)
2454 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2455 LITTLENUM_TYPE
*wordP
;
2487 return "Bad call to MD_ATOF()";
2489 t
= atof_ieee (input_line_pointer
, type
, words
);
2491 input_line_pointer
= t
;
2492 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2493 for (wordP
= words
; prec
--;)
2495 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2496 litP
+= sizeof (LITTLENUM_TYPE
);
2501 /* Write out big-endian. */
2504 md_number_to_chars (buf
, val
, n
)
2509 number_to_chars_bigendian (buf
, val
, n
);
2512 /* Translate internal representation of relocation info to BFD target
2516 tc_gen_reloc (section
, fixp
)
2521 struct hppa_fix_struct
*hppa_fixp
;
2522 bfd_reloc_code_real_type code
;
2523 static arelent
*no_relocs
= NULL
;
2525 bfd_reloc_code_real_type
**codes
;
2529 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2530 if (fixp
->fx_addsy
== 0)
2532 assert (hppa_fixp
!= 0);
2533 assert (section
!= 0);
2535 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2536 assert (reloc
!= 0);
2538 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2539 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2541 hppa_fixp
->fx_r_format
,
2542 hppa_fixp
->fx_r_field
);
2544 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2547 relocs
= (arelent
**)
2548 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2549 assert (relocs
!= 0);
2551 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2552 sizeof (arelent
) * n_relocs
);
2554 assert (reloc
!= 0);
2556 for (i
= 0; i
< n_relocs
; i
++)
2557 relocs
[i
] = &reloc
[i
];
2559 relocs
[n_relocs
] = NULL
;
2562 switch (fixp
->fx_r_type
)
2565 assert (n_relocs
== 1);
2569 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2570 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2571 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2572 reloc
->addend
= 0; /* default */
2574 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2576 /* Now, do any processing that is dependent on the relocation type. */
2579 case R_PARISC_DLTREL21L
:
2580 case R_PARISC_DLTREL14R
:
2581 case R_PARISC_DLTREL14F
:
2582 case R_PARISC_PLABEL32
:
2583 case R_PARISC_PLABEL21L
:
2584 case R_PARISC_PLABEL14R
:
2585 /* For plabel relocations, the addend of the
2586 relocation should be either 0 (no static link) or 2
2587 (static link required).
2589 FIXME: We always assume no static link!
2591 We also slam a zero addend into the DLT relative relocs;
2592 it doesn't make a lot of sense to use any addend since
2593 it gets you a different (eg unknown) DLT entry. */
2597 case R_PARISC_PCREL21L
:
2598 case R_PARISC_PCREL17R
:
2599 case R_PARISC_PCREL17F
:
2600 case R_PARISC_PCREL17C
:
2601 case R_PARISC_PCREL14R
:
2602 case R_PARISC_PCREL14F
:
2603 /* The constant is stored in the instruction. */
2604 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2607 reloc
->addend
= fixp
->fx_offset
;
2614 /* Walk over reach relocation returned by the BFD backend. */
2615 for (i
= 0; i
< n_relocs
; i
++)
2619 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2620 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2621 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2627 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2633 /* For plabel relocations, the addend of the
2634 relocation should be either 0 (no static link) or 2
2635 (static link required).
2637 FIXME: We always assume no static link!
2639 We also slam a zero addend into the DLT relative relocs;
2640 it doesn't make a lot of sense to use any addend since
2641 it gets you a different (eg unknown) DLT entry. */
2642 relocs
[i
]->addend
= 0;
2652 /* There is no symbol or addend associated with these fixups. */
2653 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2654 relocs
[i
]->addend
= 0;
2659 /* There is no symbol associated with these fixups. */
2660 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2661 relocs
[i
]->addend
= fixp
->fx_offset
;
2665 relocs
[i
]->addend
= fixp
->fx_offset
;
2673 /* Process any machine dependent frag types. */
2676 md_convert_frag (abfd
, sec
, fragP
)
2678 register asection
*sec
;
2679 register fragS
*fragP
;
2681 unsigned int address
;
2683 if (fragP
->fr_type
== rs_machine_dependent
)
2685 switch ((int) fragP
->fr_subtype
)
2688 fragP
->fr_type
= rs_fill
;
2689 know (fragP
->fr_var
== 1);
2690 know (fragP
->fr_next
);
2691 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2692 if (address
% fragP
->fr_offset
)
2695 fragP
->fr_next
->fr_address
2700 fragP
->fr_offset
= 0;
2706 /* Round up a section size to the appropriate boundary. */
2709 md_section_align (segment
, size
)
2713 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2714 int align2
= (1 << align
) - 1;
2716 return (size
+ align2
) & ~align2
;
2719 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2721 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2723 addressT from_addr
, to_addr
;
2727 fprintf (stderr
, "pa_create_short_jmp\n");
2731 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2733 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2735 addressT from_addr
, to_addr
;
2739 fprintf (stderr
, "pa_create_long_jump\n");
2743 /* Return the approximate size of a frag before relaxation has occurred. */
2745 md_estimate_size_before_relax (fragP
, segment
)
2746 register fragS
*fragP
;
2753 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2759 CONST
char *md_shortopts
= "";
2760 struct option md_longopts
[] = {
2761 {NULL
, no_argument
, NULL
, 0}
2763 size_t md_longopts_size
= sizeof(md_longopts
);
2766 md_parse_option (c
, arg
)
2774 md_show_usage (stream
)
2779 /* We have no need to default values of symbols. */
2782 md_undefined_symbol (name
)
2788 /* Parse an operand that is machine-specific.
2789 We just return without modifying the expression as we have nothing
2793 md_operand (expressionP
)
2794 expressionS
*expressionP
;
2798 /* Apply a fixup to an instruction. */
2801 md_apply_fix (fixP
, valp
)
2805 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2806 struct hppa_fix_struct
*hppa_fixP
;
2807 long new_val
, result
;
2808 unsigned int w1
, w2
, w
;
2810 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2811 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2812 never be "applied" (they are just markers). */
2814 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2815 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2819 /* There should have been an HPPA specific fixup associated
2820 with the GAS fixup. */
2823 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2824 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2826 /* If there is a symbol associated with this fixup, then it's something
2827 which will need a SOM relocation (except for some PC-relative relocs).
2828 In such cases we should treat the "val" or "addend" as zero since it
2829 will be added in as needed from fx_offset in tc_gen_reloc. */
2830 if (fixP
->fx_addsy
!= NULL
2831 || fixP
->fx_r_type
== R_HPPA_NONE
)
2832 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2834 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2836 /* Handle pc-relative exceptions from above. */
2837 #define stub_needed(CALLER, CALLEE) \
2838 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2839 if ((fmt
== 12 || fmt
== 17)
2842 && !stub_needed (((obj_symbol_type
*)
2843 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2844 hppa_fixP
->fx_arg_reloc
)
2845 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
2847 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2849 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2854 /* Handle all opcodes with the 'j' operand type. */
2856 CHECK_FIELD (new_val
, 8191, -8192, 0);
2858 /* Mask off 14 bits to be changed. */
2859 bfd_put_32 (stdoutput
,
2860 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2862 low_sign_unext (new_val
, 14, &result
);
2865 /* Handle all opcodes with the 'k' operand type. */
2867 CHECK_FIELD (new_val
, 2097152, 0, 0);
2869 /* Mask off 21 bits to be changed. */
2870 bfd_put_32 (stdoutput
,
2871 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2873 dis_assemble_21 (new_val
, &result
);
2876 /* Handle all the opcodes with the 'i' operand type. */
2878 CHECK_FIELD (new_val
, 1023, -1023, 0);
2880 /* Mask off 11 bits to be changed. */
2881 bfd_put_32 (stdoutput
,
2882 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2884 low_sign_unext (new_val
, 11, &result
);
2887 /* Handle all the opcodes with the 'w' operand type. */
2889 CHECK_FIELD (new_val
, 8191, -8192, 0)
2891 /* Mask off 11 bits to be changed. */
2892 sign_unext ((new_val
- 8) >> 2, 12, &result
);
2893 bfd_put_32 (stdoutput
,
2894 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
2897 dis_assemble_12 (result
, &w1
, &w
);
2898 result
= ((w1
<< 2) | w
);
2901 /* Handle some of the opcodes with the 'W' operand type. */
2903 CHECK_FIELD (new_val
, 262143, -262144, 0);
2905 /* Mask off 17 bits to be changed. */
2906 bfd_put_32 (stdoutput
,
2907 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
2909 sign_unext ((new_val
- 8) >> 2, 17, &result
);
2910 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2911 result
= ((w2
<< 2) | (w1
<< 16) | w
);
2916 bfd_put_32 (stdoutput
, new_val
, buf
);
2920 as_bad ("Unknown relocation encountered in md_apply_fix.");
2924 /* Insert the relocation. */
2925 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
2930 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
2931 (unsigned int) fixP
, fixP
->fx_r_type
);
2936 /* Exactly what point is a PC-relative offset relative TO?
2937 On the PA, they're relative to the address of the offset. */
2940 md_pcrel_from (fixP
)
2943 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2946 /* Return nonzero if the input line pointer is at the end of
2950 is_end_of_statement ()
2952 return ((*input_line_pointer
== '\n')
2953 || (*input_line_pointer
== ';')
2954 || (*input_line_pointer
== '!'));
2957 /* Read a number from S. The number might come in one of many forms,
2958 the most common will be a hex or decimal constant, but it could be
2959 a pre-defined register (Yuk!), or an absolute symbol.
2961 Return a number or -1 for failure.
2963 When parsing PA-89 FP register numbers RESULT will be
2964 the address of a structure to return information about
2965 L/R half of FP registers, store results there as appropriate.
2967 pa_parse_number can not handle negative constants and will fail
2968 horribly if it is passed such a constant. */
2971 pa_parse_number (s
, result
)
2973 struct pa_89_fp_reg_struct
*result
;
2982 /* Skip whitespace before the number. */
2983 while (*p
== ' ' || *p
== '\t')
2986 /* Store info in RESULT if requested by caller. */
2989 result
->number_part
= -1;
2990 result
->l_r_select
= -1;
2996 /* Looks like a number. */
2999 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3001 /* The number is specified in hex. */
3003 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3004 || ((*p
>= 'A') && (*p
<= 'F')))
3007 num
= num
* 16 + *p
- '0';
3008 else if (*p
>= 'a' && *p
<= 'f')
3009 num
= num
* 16 + *p
- 'a' + 10;
3011 num
= num
* 16 + *p
- 'A' + 10;
3017 /* The number is specified in decimal. */
3018 while (isdigit (*p
))
3020 num
= num
* 10 + *p
- '0';
3025 /* Store info in RESULT if requested by the caller. */
3028 result
->number_part
= num
;
3030 if (IS_R_SELECT (p
))
3032 result
->l_r_select
= 1;
3035 else if (IS_L_SELECT (p
))
3037 result
->l_r_select
= 0;
3041 result
->l_r_select
= 0;
3046 /* The number might be a predefined register. */
3051 /* Tege hack: Special case for general registers as the general
3052 code makes a binary search with case translation, and is VERY
3057 if (*p
== 'e' && *(p
+ 1) == 't'
3058 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3061 num
= *p
- '0' + 28;
3069 else if (!isdigit (*p
))
3072 as_bad ("Undefined register: '%s'.", name
);
3078 num
= num
* 10 + *p
++ - '0';
3079 while (isdigit (*p
));
3084 /* Do a normal register search. */
3085 while (is_part_of_name (c
))
3091 status
= reg_name_search (name
);
3097 as_bad ("Undefined register: '%s'.", name
);
3103 /* Store info in RESULT if requested by caller. */
3106 result
->number_part
= num
;
3107 if (IS_R_SELECT (p
- 1))
3108 result
->l_r_select
= 1;
3109 else if (IS_L_SELECT (p
- 1))
3110 result
->l_r_select
= 0;
3112 result
->l_r_select
= 0;
3117 /* And finally, it could be a symbol in the absolute section which
3118 is effectively a constant. */
3122 while (is_part_of_name (c
))
3128 if ((sym
= symbol_find (name
)) != NULL
)
3130 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3131 num
= S_GET_VALUE (sym
);
3135 as_bad ("Non-absolute symbol: '%s'.", name
);
3141 /* There is where we'd come for an undefined symbol
3142 or for an empty string. For an empty string we
3143 will return zero. That's a concession made for
3144 compatability with the braindamaged HP assemblers. */
3150 as_bad ("Undefined absolute constant: '%s'.", name
);
3156 /* Store info in RESULT if requested by caller. */
3159 result
->number_part
= num
;
3160 if (IS_R_SELECT (p
- 1))
3161 result
->l_r_select
= 1;
3162 else if (IS_L_SELECT (p
- 1))
3163 result
->l_r_select
= 0;
3165 result
->l_r_select
= 0;
3173 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3175 /* Given NAME, find the register number associated with that name, return
3176 the integer value associated with the given name or -1 on failure. */
3179 reg_name_search (name
)
3182 int middle
, low
, high
;
3186 high
= REG_NAME_CNT
- 1;
3190 middle
= (low
+ high
) / 2;
3191 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3197 return pre_defined_registers
[middle
].value
;
3199 while (low
<= high
);
3205 /* Return nonzero if the given INSN and L/R information will require
3206 a new PA-89 opcode. */
3209 need_89_opcode (insn
, result
)
3211 struct pa_89_fp_reg_struct
*result
;
3213 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3219 /* Parse a condition for a fcmp instruction. Return the numerical
3220 code associated with the condition. */
3223 pa_parse_fp_cmp_cond (s
)
3230 for (i
= 0; i
< 32; i
++)
3232 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3233 strlen (fp_cond_map
[i
].string
)) == 0)
3235 cond
= fp_cond_map
[i
].cond
;
3236 *s
+= strlen (fp_cond_map
[i
].string
);
3237 /* If not a complete match, back up the input string and
3239 if (**s
!= ' ' && **s
!= '\t')
3241 *s
-= strlen (fp_cond_map
[i
].string
);
3244 while (**s
== ' ' || **s
== '\t')
3250 as_bad ("Invalid FP Compare Condition: %s", *s
);
3252 /* Advance over the bogus completer. */
3253 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3259 /* Parse an FP operand format completer returning the completer
3262 static fp_operand_format
3263 pa_parse_fp_format (s
)
3272 if (strncasecmp (*s
, "sgl", 3) == 0)
3277 else if (strncasecmp (*s
, "dbl", 3) == 0)
3282 else if (strncasecmp (*s
, "quad", 4) == 0)
3289 format
= ILLEGAL_FMT
;
3290 as_bad ("Invalid FP Operand Format: %3s", *s
);
3297 /* Convert from a selector string into a selector type. */
3300 pa_chk_field_selector (str
)
3303 int middle
, low
, high
;
3307 /* Read past any whitespace. */
3308 /* FIXME: should we read past newlines and formfeeds??? */
3309 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3312 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3313 name
[0] = tolower ((*str
)[0]),
3315 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3316 name
[0] = tolower ((*str
)[0]),
3317 name
[1] = tolower ((*str
)[1]),
3323 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3327 middle
= (low
+ high
) / 2;
3328 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3335 *str
+= strlen (name
) + 1;
3336 return selector_table
[middle
].field_selector
;
3339 while (low
<= high
);
3344 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3347 get_expression (str
)
3353 save_in
= input_line_pointer
;
3354 input_line_pointer
= str
;
3355 seg
= expression (&the_insn
.exp
);
3356 if (!(seg
== absolute_section
3357 || seg
== undefined_section
3358 || SEG_NORMAL (seg
)))
3360 as_warn ("Bad segment in expression.");
3361 expr_end
= input_line_pointer
;
3362 input_line_pointer
= save_in
;
3365 expr_end
= input_line_pointer
;
3366 input_line_pointer
= save_in
;
3370 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3372 pa_get_absolute_expression (insn
, strp
)
3378 insn
->field_selector
= pa_chk_field_selector (strp
);
3379 save_in
= input_line_pointer
;
3380 input_line_pointer
= *strp
;
3381 expression (&insn
->exp
);
3382 if (insn
->exp
.X_op
!= O_constant
)
3384 as_bad ("Bad segment (should be absolute).");
3385 expr_end
= input_line_pointer
;
3386 input_line_pointer
= save_in
;
3389 expr_end
= input_line_pointer
;
3390 input_line_pointer
= save_in
;
3391 return evaluate_absolute (insn
);
3394 /* Evaluate an absolute expression EXP which may be modified by
3395 the selector FIELD_SELECTOR. Return the value of the expression. */
3397 evaluate_absolute (insn
)
3402 int field_selector
= insn
->field_selector
;
3405 value
= exp
.X_add_number
;
3407 switch (field_selector
)
3413 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3415 if (value
& 0x00000400)
3417 value
= (value
& 0xfffff800) >> 11;
3420 /* Sign extend from bit 21. */
3422 if (value
& 0x00000400)
3423 value
|= 0xfffff800;
3428 /* Arithmetic shift right 11 bits. */
3430 value
= (value
& 0xfffff800) >> 11;
3433 /* Set bits 0-20 to zero. */
3435 value
= value
& 0x7ff;
3438 /* Add 0x800 and arithmetic shift right 11 bits. */
3441 value
= (value
& 0xfffff800) >> 11;
3444 /* Set bitgs 0-21 to one. */
3446 value
|= 0xfffff800;
3449 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3451 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3455 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3460 BAD_CASE (field_selector
);
3466 /* Given an argument location specification return the associated
3467 argument location number. */
3470 pa_build_arg_reloc (type_name
)
3474 if (strncasecmp (type_name
, "no", 2) == 0)
3476 if (strncasecmp (type_name
, "gr", 2) == 0)
3478 else if (strncasecmp (type_name
, "fr", 2) == 0)
3480 else if (strncasecmp (type_name
, "fu", 2) == 0)
3483 as_bad ("Invalid argument location: %s\n", type_name
);
3488 /* Encode and return an argument relocation specification for
3489 the given register in the location specified by arg_reloc. */
3492 pa_align_arg_reloc (reg
, arg_reloc
)
3494 unsigned int arg_reloc
;
3496 unsigned int new_reloc
;
3498 new_reloc
= arg_reloc
;
3514 as_bad ("Invalid argument description: %d", reg
);
3520 /* Parse a PA nullification completer (,n). Return nonzero if the
3521 completer was found; return zero if no completer was found. */
3533 if (strncasecmp (*s
, "n", 1) == 0)
3537 as_bad ("Invalid Nullification: (%c)", **s
);
3546 /* Parse a non-negated compare/subtract completer returning the
3547 number (for encoding in instrutions) of the given completer.
3549 ISBRANCH specifies whether or not this is parsing a condition
3550 completer for a branch (vs a nullification completer for a
3551 computational instruction. */
3554 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3559 char *name
= *s
+ 1;
3567 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3571 if (strcmp (name
, "=") == 0)
3575 else if (strcmp (name
, "<") == 0)
3579 else if (strcmp (name
, "<=") == 0)
3583 else if (strcmp (name
, "<<") == 0)
3587 else if (strcmp (name
, "<<=") == 0)
3591 else if (strcasecmp (name
, "sv") == 0)
3595 else if (strcasecmp (name
, "od") == 0)
3599 /* If we have something like addb,n then there is no condition
3601 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3612 /* Reset pointers if this was really a ,n for a branch instruction. */
3613 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3619 /* Parse a negated compare/subtract completer returning the
3620 number (for encoding in instrutions) of the given completer.
3622 ISBRANCH specifies whether or not this is parsing a condition
3623 completer for a branch (vs a nullification completer for a
3624 computational instruction. */
3627 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3632 char *name
= *s
+ 1;
3640 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3644 if (strcasecmp (name
, "tr") == 0)
3648 else if (strcmp (name
, "<>") == 0)
3652 else if (strcmp (name
, ">=") == 0)
3656 else if (strcmp (name
, ">") == 0)
3660 else if (strcmp (name
, ">>=") == 0)
3664 else if (strcmp (name
, ">>") == 0)
3668 else if (strcasecmp (name
, "nsv") == 0)
3672 else if (strcasecmp (name
, "ev") == 0)
3676 /* If we have something like addb,n then there is no condition
3678 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3689 /* Reset pointers if this was really a ,n for a branch instruction. */
3690 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3696 /* Parse a non-negated addition completer returning the number
3697 (for encoding in instrutions) of the given completer.
3699 ISBRANCH specifies whether or not this is parsing a condition
3700 completer for a branch (vs a nullification completer for a
3701 computational instruction. */
3704 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3709 char *name
= *s
+ 1;
3717 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3721 if (strcmp (name
, "=") == 0)
3725 else if (strcmp (name
, "<") == 0)
3729 else if (strcmp (name
, "<=") == 0)
3733 else if (strcasecmp (name
, "nuv") == 0)
3737 else if (strcasecmp (name
, "znv") == 0)
3741 else if (strcasecmp (name
, "sv") == 0)
3745 else if (strcasecmp (name
, "od") == 0)
3749 /* If we have something like addb,n then there is no condition
3751 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3762 /* Reset pointers if this was really a ,n for a branch instruction. */
3763 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3769 /* Parse a negated addition completer returning the number
3770 (for encoding in instrutions) of the given completer.
3772 ISBRANCH specifies whether or not this is parsing a condition
3773 completer for a branch (vs a nullification completer for a
3774 computational instruction. */
3777 pa_parse_neg_add_cmpltr (s
, isbranch
)
3782 char *name
= *s
+ 1;
3790 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3794 if (strcasecmp (name
, "tr") == 0)
3798 else if (strcmp (name
, "<>") == 0)
3802 else if (strcmp (name
, ">=") == 0)
3806 else if (strcmp (name
, ">") == 0)
3810 else if (strcasecmp (name
, "uv") == 0)
3814 else if (strcasecmp (name
, "vnz") == 0)
3818 else if (strcasecmp (name
, "nsv") == 0)
3822 else if (strcasecmp (name
, "ev") == 0)
3826 /* If we have something like addb,n then there is no condition
3828 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3839 /* Reset pointers if this was really a ,n for a branch instruction. */
3840 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3846 /* Handle an alignment directive. Special so that we can update the
3847 alignment of the subspace if necessary. */
3851 /* Let the generic gas code do most of the work. */
3852 s_align_bytes (bytes
);
3854 /* If bytes is a power of 2, then update the current subspace's
3855 alignment if necessary. */
3856 if (log2 (bytes
) != -1)
3857 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
3860 /* Handle a .BLOCK type pseudo-op. */
3868 unsigned int temp_size
;
3871 temp_size
= get_absolute_expression ();
3873 /* Always fill with zeros, that's what the HP assembler does. */
3876 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
3877 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
3878 bzero (p
, temp_size
);
3880 /* Convert 2 bytes at a time. */
3882 for (i
= 0; i
< temp_size
; i
+= 2)
3884 md_number_to_chars (p
+ i
,
3886 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
3889 pa_undefine_label ();
3890 demand_empty_rest_of_line ();
3893 /* Handle a .CALL pseudo-op. This involves storing away information
3894 about where arguments are to be found so the linker can detect
3895 (and correct) argument location mismatches between caller and callee. */
3901 pa_call_args (&last_call_desc
);
3902 demand_empty_rest_of_line ();
3905 /* Do the dirty work of building a call descriptor which describes
3906 where the caller placed arguments to a function call. */
3909 pa_call_args (call_desc
)
3910 struct call_desc
*call_desc
;
3913 unsigned int temp
, arg_reloc
;
3915 while (!is_end_of_statement ())
3917 name
= input_line_pointer
;
3918 c
= get_symbol_end ();
3919 /* Process a source argument. */
3920 if ((strncasecmp (name
, "argw", 4) == 0))
3922 temp
= atoi (name
+ 4);
3923 p
= input_line_pointer
;
3925 input_line_pointer
++;
3926 name
= input_line_pointer
;
3927 c
= get_symbol_end ();
3928 arg_reloc
= pa_build_arg_reloc (name
);
3929 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
3931 /* Process a return value. */
3932 else if ((strncasecmp (name
, "rtnval", 6) == 0))
3934 p
= input_line_pointer
;
3936 input_line_pointer
++;
3937 name
= input_line_pointer
;
3938 c
= get_symbol_end ();
3939 arg_reloc
= pa_build_arg_reloc (name
);
3940 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
3944 as_bad ("Invalid .CALL argument: %s", name
);
3946 p
= input_line_pointer
;
3948 if (!is_end_of_statement ())
3949 input_line_pointer
++;
3953 /* Return TRUE if FRAG1 and FRAG2 are the same. */
3956 is_same_frag (frag1
, frag2
)
3963 else if (frag2
== NULL
)
3965 else if (frag1
== frag2
)
3967 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
3968 return (is_same_frag (frag1
, frag2
->fr_next
));
3974 /* Build an entry in the UNWIND subspace from the given function
3975 attributes in CALL_INFO. This is not needed for SOM as using
3976 R_ENTRY and R_EXIT relocations allow the linker to handle building
3977 of the unwind spaces. */
3980 pa_build_unwind_subspace (call_info
)
3981 struct call_info
*call_info
;
3984 asection
*seg
, *save_seg
;
3985 subsegT subseg
, save_subseg
;
3989 /* Get into the right seg/subseg. This may involve creating
3990 the seg the first time through. Make sure to have the
3991 old seg/subseg so that we can reset things when we are done. */
3992 subseg
= SUBSEG_UNWIND
;
3993 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
3994 if (seg
== ASEC_NULL
)
3996 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
3997 bfd_set_section_flags (stdoutput
, seg
,
3998 SEC_READONLY
| SEC_HAS_CONTENTS
3999 | SEC_LOAD
| SEC_RELOC
);
4003 save_subseg
= now_subseg
;
4004 subseg_set (seg
, subseg
);
4007 /* Get some space to hold relocation information for the unwind
4011 /* Relocation info. for start offset of the function. */
4012 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4013 call_info
->start_symbol
, (offsetT
) 0,
4014 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4018 /* Relocation info. for end offset of the function. */
4019 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4020 call_info
->end_symbol
, (offsetT
) 0,
4021 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4024 unwind
= (char *) &call_info
->ci_unwind
;
4025 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4029 FRAG_APPEND_1_CHAR (c
);
4033 /* Return back to the original segment/subsegment. */
4034 subseg_set (save_seg
, save_subseg
);
4038 /* Process a .CALLINFO pseudo-op. This information is used later
4039 to build unwind descriptors and maybe one day to support
4040 .ENTER and .LEAVE. */
4043 pa_callinfo (unused
)
4049 /* .CALLINFO must appear within a procedure definition. */
4050 if (!within_procedure
)
4051 as_bad (".callinfo is not within a procedure definition");
4053 /* Mark the fact that we found the .CALLINFO for the
4054 current procedure. */
4055 callinfo_found
= TRUE
;
4057 /* Iterate over the .CALLINFO arguments. */
4058 while (!is_end_of_statement ())
4060 name
= input_line_pointer
;
4061 c
= get_symbol_end ();
4062 /* Frame size specification. */
4063 if ((strncasecmp (name
, "frame", 5) == 0))
4065 p
= input_line_pointer
;
4067 input_line_pointer
++;
4068 temp
= get_absolute_expression ();
4069 if ((temp
& 0x3) != 0)
4071 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4075 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4076 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4079 /* Entry register (GR, GR and SR) specifications. */
4080 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4082 p
= input_line_pointer
;
4084 input_line_pointer
++;
4085 temp
= get_absolute_expression ();
4086 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4087 even though %r19 is caller saved. I think this is a bug in
4088 the HP assembler, and we are not going to emulate it. */
4089 if (temp
< 3 || temp
> 18)
4090 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4091 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4093 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4095 p
= input_line_pointer
;
4097 input_line_pointer
++;
4098 temp
= get_absolute_expression ();
4099 /* Similarly the HP assembler takes 31 as the high bound even
4100 though %fr21 is the last callee saved floating point register. */
4101 if (temp
< 12 || temp
> 21)
4102 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4103 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4105 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4107 p
= input_line_pointer
;
4109 input_line_pointer
++;
4110 temp
= get_absolute_expression ();
4112 as_bad ("Value for ENTRY_SR must be 3\n");
4114 /* Note whether or not this function performs any calls. */
4115 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4116 (strncasecmp (name
, "caller", 6) == 0))
4118 p
= input_line_pointer
;
4121 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4123 p
= input_line_pointer
;
4126 /* Should RP be saved into the stack. */
4127 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4129 p
= input_line_pointer
;
4131 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4133 /* Likewise for SP. */
4134 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4136 p
= input_line_pointer
;
4138 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4140 /* Is this an unwindable procedure. If so mark it so
4141 in the unwind descriptor. */
4142 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4144 p
= input_line_pointer
;
4146 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4148 /* Is this an interrupt routine. If so mark it in the
4149 unwind descriptor. */
4150 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4152 p
= input_line_pointer
;
4154 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4156 /* Is this a millicode routine. "millicode" isn't in my
4157 assembler manual, but my copy is old. The HP assembler
4158 accepts it, and there's a place in the unwind descriptor
4159 to drop the information, so we'll accept it too. */
4160 else if ((strncasecmp (name
, "millicode", 9) == 0))
4162 p
= input_line_pointer
;
4164 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4168 as_bad ("Invalid .CALLINFO argument: %s", name
);
4169 *input_line_pointer
= c
;
4171 if (!is_end_of_statement ())
4172 input_line_pointer
++;
4175 demand_empty_rest_of_line ();
4178 /* Switch into the code subspace. */
4184 sd_chain_struct
*sdchain
;
4186 /* First time through it might be necessary to create the
4188 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4190 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4191 pa_def_spaces
[0].spnum
,
4192 pa_def_spaces
[0].loadable
,
4193 pa_def_spaces
[0].defined
,
4194 pa_def_spaces
[0].private,
4195 pa_def_spaces
[0].sort
,
4196 pa_def_spaces
[0].segment
, 0);
4199 SPACE_DEFINED (sdchain
) = 1;
4200 subseg_set (text_section
, SUBSEG_CODE
);
4201 demand_empty_rest_of_line ();
4204 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4205 the .comm pseudo-op has the following symtax:
4207 <label> .comm <length>
4209 where <label> is optional and is a symbol whose address will be the start of
4210 a block of memory <length> bytes long. <length> must be an absolute
4211 expression. <length> bytes will be allocated in the current space
4220 label_symbol_struct
*label_symbol
= pa_get_label ();
4223 symbol
= label_symbol
->lss_label
;
4228 size
= get_absolute_expression ();
4232 /* It is incorrect to check S_IS_DEFINED at this point as
4233 the symbol will *always* be defined. FIXME. How to
4234 correctly determine when this label really as been
4236 if (S_GET_VALUE (symbol
))
4238 if (S_GET_VALUE (symbol
) != size
)
4240 as_warn ("Length of .comm \"%s\" is already %ld. Not changed.",
4241 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4247 S_SET_VALUE (symbol
, size
);
4248 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4249 S_SET_EXTERNAL (symbol
);
4251 /* colon() has already set the frag to the current location in the
4252 $BSS$ subspace; we need to reset the fragment to the zero address
4254 symbol
->sy_frag
= &zero_address_frag
;
4257 demand_empty_rest_of_line ();
4260 /* Process a .END pseudo-op. */
4266 demand_empty_rest_of_line ();
4269 /* Process a .ENTER pseudo-op. This is not supported. */
4277 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4283 if (!within_procedure
)
4284 as_bad ("Misplaced .entry. Ignored.");
4287 if (!callinfo_found
)
4288 as_bad ("Missing .callinfo.");
4290 demand_empty_rest_of_line ();
4291 within_entry_exit
= TRUE
;
4294 /* SOM defers building of unwind descriptors until the link phase.
4295 The assembler is responsible for creating an R_ENTRY relocation
4296 to mark the beginning of a region and hold the unwind bits, and
4297 for creating an R_EXIT relocation to mark the end of the region.
4299 FIXME. ELF should be using the same conventions! The problem
4300 is an unwind requires too much relocation space. Hmmm. Maybe
4301 if we split the unwind bits up between the relocations which
4302 denote the entry and exit points. */
4303 if (last_call_info
->start_symbol
!= NULL
)
4305 char *where
= frag_more (0);
4307 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4308 NULL
, (offsetT
) 0, NULL
,
4309 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4310 (int *) &last_call_info
->ci_unwind
.descriptor
);
4315 /* Handle a .EQU pseudo-op. */
4321 label_symbol_struct
*label_symbol
= pa_get_label ();
4326 symbol
= label_symbol
->lss_label
;
4328 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4330 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4331 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4336 as_bad (".REG must use a label");
4338 as_bad (".EQU must use a label");
4341 pa_undefine_label ();
4342 demand_empty_rest_of_line ();
4345 /* Helper function. Does processing for the end of a function. This
4346 usually involves creating some relocations or building special
4347 symbols to mark the end of the function. */
4354 where
= frag_more (0);
4357 /* Mark the end of the function, stuff away the location of the frag
4358 for the end of the function, and finally call pa_build_unwind_subspace
4359 to add an entry in the unwind table. */
4360 hppa_elf_mark_end_of_function ();
4361 pa_build_unwind_subspace (last_call_info
);
4363 /* SOM defers building of unwind descriptors until the link phase.
4364 The assembler is responsible for creating an R_ENTRY relocation
4365 to mark the beginning of a region and hold the unwind bits, and
4366 for creating an R_EXIT relocation to mark the end of the region.
4368 FIXME. ELF should be using the same conventions! The problem
4369 is an unwind requires too much relocation space. Hmmm. Maybe
4370 if we split the unwind bits up between the relocations which
4371 denote the entry and exit points. */
4372 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4374 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4375 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4379 /* Process a .EXIT pseudo-op. */
4385 if (!within_procedure
)
4386 as_bad (".EXIT must appear within a procedure");
4389 if (!callinfo_found
)
4390 as_bad ("Missing .callinfo");
4393 if (!within_entry_exit
)
4394 as_bad ("No .ENTRY for this .EXIT");
4397 within_entry_exit
= FALSE
;
4402 demand_empty_rest_of_line ();
4405 /* Process a .EXPORT directive. This makes functions external
4406 and provides information such as argument relocation entries
4416 name
= input_line_pointer
;
4417 c
= get_symbol_end ();
4418 /* Make sure the given symbol exists. */
4419 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4421 as_bad ("Cannot define export symbol: %s\n", name
);
4422 p
= input_line_pointer
;
4424 input_line_pointer
++;
4428 /* OK. Set the external bits and process argument relocations. */
4429 S_SET_EXTERNAL (symbol
);
4430 p
= input_line_pointer
;
4432 if (!is_end_of_statement ())
4434 input_line_pointer
++;
4435 pa_type_args (symbol
, 1);
4439 demand_empty_rest_of_line ();
4442 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4445 pa_type_args (symbolP
, is_export
)
4450 unsigned int temp
, arg_reloc
;
4451 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4452 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4454 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4457 input_line_pointer
+= 8;
4458 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4459 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4460 type
= SYMBOL_TYPE_ABSOLUTE
;
4462 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4464 input_line_pointer
+= 4;
4465 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4466 instead one should be IMPORTing/EXPORTing ENTRY types.
4468 Complain if one tries to EXPORT a CODE type since that's never
4469 done. Both GCC and HP C still try to IMPORT CODE types, so
4470 silently fix them to be ENTRY types. */
4471 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4474 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4476 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4477 type
= SYMBOL_TYPE_ENTRY
;
4481 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4482 type
= SYMBOL_TYPE_CODE
;
4485 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4487 input_line_pointer
+= 4;
4488 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4489 type
= SYMBOL_TYPE_DATA
;
4491 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4493 input_line_pointer
+= 5;
4494 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4495 type
= SYMBOL_TYPE_ENTRY
;
4497 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4499 input_line_pointer
+= 9;
4500 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4501 type
= SYMBOL_TYPE_MILLICODE
;
4503 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4505 input_line_pointer
+= 6;
4506 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4507 type
= SYMBOL_TYPE_PLABEL
;
4509 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4511 input_line_pointer
+= 8;
4512 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4513 type
= SYMBOL_TYPE_PRI_PROG
;
4515 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4517 input_line_pointer
+= 8;
4518 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4519 type
= SYMBOL_TYPE_SEC_PROG
;
4522 /* SOM requires much more information about symbol types
4523 than BFD understands. This is how we get this information
4524 to the SOM BFD backend. */
4525 #ifdef obj_set_symbol_type
4526 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4529 /* Now that the type of the exported symbol has been handled,
4530 handle any argument relocation information. */
4531 while (!is_end_of_statement ())
4533 if (*input_line_pointer
== ',')
4534 input_line_pointer
++;
4535 name
= input_line_pointer
;
4536 c
= get_symbol_end ();
4537 /* Argument sources. */
4538 if ((strncasecmp (name
, "argw", 4) == 0))
4540 p
= input_line_pointer
;
4542 input_line_pointer
++;
4543 temp
= atoi (name
+ 4);
4544 name
= input_line_pointer
;
4545 c
= get_symbol_end ();
4546 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4547 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4548 *input_line_pointer
= c
;
4550 /* The return value. */
4551 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4553 p
= input_line_pointer
;
4555 input_line_pointer
++;
4556 name
= input_line_pointer
;
4557 c
= get_symbol_end ();
4558 arg_reloc
= pa_build_arg_reloc (name
);
4559 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4560 *input_line_pointer
= c
;
4562 /* Privelege level. */
4563 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4565 p
= input_line_pointer
;
4567 input_line_pointer
++;
4568 temp
= atoi (input_line_pointer
);
4569 c
= get_symbol_end ();
4570 *input_line_pointer
= c
;
4574 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4575 p
= input_line_pointer
;
4578 if (!is_end_of_statement ())
4579 input_line_pointer
++;
4583 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4584 assembly file must either be defined in the assembly file, or
4585 explicitly IMPORTED from another. */
4594 name
= input_line_pointer
;
4595 c
= get_symbol_end ();
4597 symbol
= symbol_find (name
);
4598 /* Ugh. We might be importing a symbol defined earlier in the file,
4599 in which case all the code below will really screw things up
4600 (set the wrong segment, symbol flags & type, etc). */
4601 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4603 symbol
= symbol_find_or_make (name
);
4604 p
= input_line_pointer
;
4607 if (!is_end_of_statement ())
4609 input_line_pointer
++;
4610 pa_type_args (symbol
, 0);
4614 /* Sigh. To be compatable with the HP assembler and to help
4615 poorly written assembly code, we assign a type based on
4616 the the current segment. Note only BSF_FUNCTION really
4617 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4618 if (now_seg
== text_section
)
4619 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4621 /* If the section is undefined, then the symbol is undefined
4622 Since this is an import, leave the section undefined. */
4623 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4628 /* The symbol was already defined. Just eat everything up to
4629 the end of the current statement. */
4630 while (!is_end_of_statement ())
4631 input_line_pointer
++;
4634 demand_empty_rest_of_line ();
4637 /* Handle a .LABEL pseudo-op. */
4645 name
= input_line_pointer
;
4646 c
= get_symbol_end ();
4648 if (strlen (name
) > 0)
4651 p
= input_line_pointer
;
4656 as_warn ("Missing label name on .LABEL");
4659 if (!is_end_of_statement ())
4661 as_warn ("extra .LABEL arguments ignored.");
4662 ignore_rest_of_line ();
4664 demand_empty_rest_of_line ();
4667 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4676 /* Handle a .ORIGIN pseudo-op. */
4683 pa_undefine_label ();
4686 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4687 is for static functions. FIXME. Should share more code with .EXPORT. */
4696 name
= input_line_pointer
;
4697 c
= get_symbol_end ();
4699 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4701 as_bad ("Cannot define static symbol: %s\n", name
);
4702 p
= input_line_pointer
;
4704 input_line_pointer
++;
4708 S_CLEAR_EXTERNAL (symbol
);
4709 p
= input_line_pointer
;
4711 if (!is_end_of_statement ())
4713 input_line_pointer
++;
4714 pa_type_args (symbol
, 0);
4718 demand_empty_rest_of_line ();
4721 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4722 of a procedure from a syntatical point of view. */
4728 struct call_info
*call_info
;
4729 if (within_procedure
)
4730 as_fatal ("Nested procedures");
4732 /* Reset global variables for new procedure. */
4733 callinfo_found
= FALSE
;
4734 within_procedure
= TRUE
;
4736 /* Create another call_info structure. */
4737 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4740 as_fatal ("Cannot allocate unwind descriptor\n");
4742 bzero (call_info
, sizeof (struct call_info
));
4744 call_info
->ci_next
= NULL
;
4746 if (call_info_root
== NULL
)
4748 call_info_root
= call_info
;
4749 last_call_info
= call_info
;
4753 last_call_info
->ci_next
= call_info
;
4754 last_call_info
= call_info
;
4757 /* set up defaults on call_info structure */
4759 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4760 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4761 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4763 /* If we got a .PROC pseudo-op, we know that the function is defined
4764 locally. Make sure it gets into the symbol table. */
4766 label_symbol_struct
*label_symbol
= pa_get_label ();
4770 if (label_symbol
->lss_label
)
4772 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4773 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4776 as_bad ("Missing function name for .PROC (corrupted label chain)");
4779 last_call_info
->start_symbol
= NULL
;
4782 demand_empty_rest_of_line ();
4785 /* Process the syntatical end of a procedure. Make sure all the
4786 appropriate pseudo-ops were found within the procedure. */
4793 /* If we are within a procedure definition, make sure we've
4794 defined a label for the procedure; handle case where the
4795 label was defined after the .PROC directive.
4797 Note there's not need to diddle with the segment or fragment
4798 for the label symbol in this case. We have already switched
4799 into the new $CODE$ subspace at this point. */
4800 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4802 label_symbol_struct
*label_symbol
= pa_get_label ();
4806 if (label_symbol
->lss_label
)
4808 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4809 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4811 /* Also handle allocation of a fixup to hold the unwind
4812 information when the label appears after the proc/procend. */
4813 if (within_entry_exit
)
4815 char *where
= frag_more (0);
4817 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4818 NULL
, (offsetT
) 0, NULL
,
4819 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4820 (int *) &last_call_info
->ci_unwind
.descriptor
);
4825 as_bad ("Missing function name for .PROC (corrupted label chain)");
4828 as_bad ("Missing function name for .PROC");
4831 if (!within_procedure
)
4832 as_bad ("misplaced .procend");
4834 if (!callinfo_found
)
4835 as_bad ("Missing .callinfo for this procedure");
4837 if (within_entry_exit
)
4838 as_bad ("Missing .EXIT for a .ENTRY");
4841 /* ELF needs to mark the end of each function so that it can compute
4842 the size of the function (apparently its needed in the symbol table. */
4843 hppa_elf_mark_end_of_function ();
4846 within_procedure
= FALSE
;
4847 demand_empty_rest_of_line ();
4848 pa_undefine_label ();
4851 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4852 then create a new space entry to hold the information specified
4853 by the parameters to the .SPACE directive. */
4855 static sd_chain_struct
*
4856 pa_parse_space_stmt (space_name
, create_flag
)
4860 char *name
, *ptemp
, c
;
4861 char loadable
, defined
, private, sort
;
4863 asection
*seg
= NULL
;
4864 sd_chain_struct
*space
;
4866 /* load default values */
4872 if (strcmp (space_name
, "$TEXT$") == 0)
4874 seg
= pa_def_spaces
[0].segment
;
4875 defined
= pa_def_spaces
[0].defined
;
4876 private = pa_def_spaces
[0].private;
4877 sort
= pa_def_spaces
[0].sort
;
4878 spnum
= pa_def_spaces
[0].spnum
;
4880 else if (strcmp (space_name
, "$PRIVATE$") == 0)
4882 seg
= pa_def_spaces
[1].segment
;
4883 defined
= pa_def_spaces
[1].defined
;
4884 private = pa_def_spaces
[1].private;
4885 sort
= pa_def_spaces
[1].sort
;
4886 spnum
= pa_def_spaces
[1].spnum
;
4889 if (!is_end_of_statement ())
4891 print_errors
= FALSE
;
4892 ptemp
= input_line_pointer
+ 1;
4893 /* First see if the space was specified as a number rather than
4894 as a name. According to the PA assembly manual the rest of
4895 the line should be ignored. */
4896 temp
= pa_parse_number (&ptemp
, 0);
4900 input_line_pointer
= ptemp
;
4904 while (!is_end_of_statement ())
4906 input_line_pointer
++;
4907 name
= input_line_pointer
;
4908 c
= get_symbol_end ();
4909 if ((strncasecmp (name
, "spnum", 5) == 0))
4911 *input_line_pointer
= c
;
4912 input_line_pointer
++;
4913 spnum
= get_absolute_expression ();
4915 else if ((strncasecmp (name
, "sort", 4) == 0))
4917 *input_line_pointer
= c
;
4918 input_line_pointer
++;
4919 sort
= get_absolute_expression ();
4921 else if ((strncasecmp (name
, "unloadable", 10) == 0))
4923 *input_line_pointer
= c
;
4926 else if ((strncasecmp (name
, "notdefined", 10) == 0))
4928 *input_line_pointer
= c
;
4931 else if ((strncasecmp (name
, "private", 7) == 0))
4933 *input_line_pointer
= c
;
4938 as_bad ("Invalid .SPACE argument");
4939 *input_line_pointer
= c
;
4940 if (!is_end_of_statement ())
4941 input_line_pointer
++;
4945 print_errors
= TRUE
;
4948 if (create_flag
&& seg
== NULL
)
4949 seg
= subseg_new (space_name
, 0);
4951 /* If create_flag is nonzero, then create the new space with
4952 the attributes computed above. Else set the values in
4953 an already existing space -- this can only happen for
4954 the first occurence of a built-in space. */
4956 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
4957 private, sort
, seg
, 1);
4960 space
= is_defined_space (space_name
);
4961 SPACE_SPNUM (space
) = spnum
;
4962 SPACE_DEFINED (space
) = defined
& 1;
4963 SPACE_USER_DEFINED (space
) = 1;
4966 #ifdef obj_set_section_attributes
4967 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
4973 /* Handle a .SPACE pseudo-op; this switches the current space to the
4974 given space, creating the new space if necessary. */
4980 char *name
, c
, *space_name
, *save_s
;
4982 sd_chain_struct
*sd_chain
;
4984 if (within_procedure
)
4986 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
4987 ignore_rest_of_line ();
4991 /* Check for some of the predefined spaces. FIXME: most of the code
4992 below is repeated several times, can we extract the common parts
4993 and place them into a subroutine or something similar? */
4994 /* FIXME Is this (and the next IF stmt) really right?
4995 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
4996 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
4998 input_line_pointer
+= 6;
4999 sd_chain
= is_defined_space ("$TEXT$");
5000 if (sd_chain
== NULL
)
5001 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5002 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5003 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5005 current_space
= sd_chain
;
5006 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5008 = pa_subsegment_to_subspace (text_section
,
5009 sd_chain
->sd_last_subseg
);
5010 demand_empty_rest_of_line ();
5013 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5015 input_line_pointer
+= 9;
5016 sd_chain
= is_defined_space ("$PRIVATE$");
5017 if (sd_chain
== NULL
)
5018 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5019 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5020 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5022 current_space
= sd_chain
;
5023 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5025 = pa_subsegment_to_subspace (data_section
,
5026 sd_chain
->sd_last_subseg
);
5027 demand_empty_rest_of_line ();
5030 if (!strncasecmp (input_line_pointer
,
5031 GDB_DEBUG_SPACE_NAME
,
5032 strlen (GDB_DEBUG_SPACE_NAME
)))
5034 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5035 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5036 if (sd_chain
== NULL
)
5037 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5038 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5039 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5041 current_space
= sd_chain
;
5044 asection
*gdb_section
5045 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5047 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5049 = pa_subsegment_to_subspace (gdb_section
,
5050 sd_chain
->sd_last_subseg
);
5052 demand_empty_rest_of_line ();
5056 /* It could be a space specified by number. */
5058 save_s
= input_line_pointer
;
5059 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5061 if ((sd_chain
= pa_find_space_by_number (temp
)))
5063 current_space
= sd_chain
;
5065 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5067 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5068 sd_chain
->sd_last_subseg
);
5069 demand_empty_rest_of_line ();
5074 /* Not a number, attempt to create a new space. */
5076 input_line_pointer
= save_s
;
5077 name
= input_line_pointer
;
5078 c
= get_symbol_end ();
5079 space_name
= xmalloc (strlen (name
) + 1);
5080 strcpy (space_name
, name
);
5081 *input_line_pointer
= c
;
5083 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5084 current_space
= sd_chain
;
5086 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5087 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5088 sd_chain
->sd_last_subseg
);
5089 demand_empty_rest_of_line ();
5093 /* Switch to a new space. (I think). FIXME. */
5102 sd_chain_struct
*space
;
5104 name
= input_line_pointer
;
5105 c
= get_symbol_end ();
5106 space
= is_defined_space (name
);
5110 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5113 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5115 *input_line_pointer
= c
;
5116 demand_empty_rest_of_line ();
5119 /* If VALUE is an exact power of two between zero and 2^31, then
5120 return log2 (VALUE). Else return -1. */
5128 while ((1 << shift
) != value
&& shift
< 32)
5137 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5138 given subspace, creating the new subspace if necessary.
5140 FIXME. Should mirror pa_space more closely, in particular how
5141 they're broken up into subroutines. */
5144 pa_subspace (unused
)
5147 char *name
, *ss_name
, *alias
, c
;
5148 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5149 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5150 sd_chain_struct
*space
;
5151 ssd_chain_struct
*ssd
;
5154 if (within_procedure
)
5156 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5157 ignore_rest_of_line ();
5161 name
= input_line_pointer
;
5162 c
= get_symbol_end ();
5163 ss_name
= xmalloc (strlen (name
) + 1);
5164 strcpy (ss_name
, name
);
5165 *input_line_pointer
= c
;
5167 /* Load default values. */
5180 space
= current_space
;
5181 ssd
= is_defined_subspace (ss_name
);
5182 /* Allow user to override the builtin attributes of subspaces. But
5183 only allow the attributes to be changed once! */
5184 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5186 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5187 if (!is_end_of_statement ())
5188 as_warn ("Parameters of an existing subspace can\'t be modified");
5189 demand_empty_rest_of_line ();
5194 /* A new subspace. Load default values if it matches one of
5195 the builtin subspaces. */
5197 while (pa_def_subspaces
[i
].name
)
5199 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5201 loadable
= pa_def_subspaces
[i
].loadable
;
5202 common
= pa_def_subspaces
[i
].common
;
5203 dup_common
= pa_def_subspaces
[i
].dup_common
;
5204 code_only
= pa_def_subspaces
[i
].code_only
;
5205 zero
= pa_def_subspaces
[i
].zero
;
5206 space_index
= pa_def_subspaces
[i
].space_index
;
5207 alignment
= pa_def_subspaces
[i
].alignment
;
5208 quadrant
= pa_def_subspaces
[i
].quadrant
;
5209 access
= pa_def_subspaces
[i
].access
;
5210 sort
= pa_def_subspaces
[i
].sort
;
5211 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5212 alias
= pa_def_subspaces
[i
].alias
;
5219 /* We should be working with a new subspace now. Fill in
5220 any information as specified by the user. */
5221 if (!is_end_of_statement ())
5223 input_line_pointer
++;
5224 while (!is_end_of_statement ())
5226 name
= input_line_pointer
;
5227 c
= get_symbol_end ();
5228 if ((strncasecmp (name
, "quad", 4) == 0))
5230 *input_line_pointer
= c
;
5231 input_line_pointer
++;
5232 quadrant
= get_absolute_expression ();
5234 else if ((strncasecmp (name
, "align", 5) == 0))
5236 *input_line_pointer
= c
;
5237 input_line_pointer
++;
5238 alignment
= get_absolute_expression ();
5239 if (log2 (alignment
) == -1)
5241 as_bad ("Alignment must be a power of 2");
5245 else if ((strncasecmp (name
, "access", 6) == 0))
5247 *input_line_pointer
= c
;
5248 input_line_pointer
++;
5249 access
= get_absolute_expression ();
5251 else if ((strncasecmp (name
, "sort", 4) == 0))
5253 *input_line_pointer
= c
;
5254 input_line_pointer
++;
5255 sort
= get_absolute_expression ();
5257 else if ((strncasecmp (name
, "code_only", 9) == 0))
5259 *input_line_pointer
= c
;
5262 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5264 *input_line_pointer
= c
;
5267 else if ((strncasecmp (name
, "common", 6) == 0))
5269 *input_line_pointer
= c
;
5272 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5274 *input_line_pointer
= c
;
5277 else if ((strncasecmp (name
, "zero", 4) == 0))
5279 *input_line_pointer
= c
;
5282 else if ((strncasecmp (name
, "first", 5) == 0))
5283 as_bad ("FIRST not supported as a .SUBSPACE argument");
5285 as_bad ("Invalid .SUBSPACE argument");
5286 if (!is_end_of_statement ())
5287 input_line_pointer
++;
5291 /* Compute a reasonable set of BFD flags based on the information
5292 in the .subspace directive. */
5293 applicable
= bfd_applicable_section_flags (stdoutput
);
5296 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5299 if (common
|| dup_common
)
5300 flags
|= SEC_IS_COMMON
;
5302 /* This is a zero-filled subspace (eg BSS). */
5306 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5307 applicable
&= flags
;
5309 /* If this is an existing subspace, then we want to use the
5310 segment already associated with the subspace.
5312 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5313 lots of sections. It might be a problem in the PA ELF
5314 code, I do not know yet. For now avoid creating anything
5315 but the "standard" sections for ELF. */
5317 section
= ssd
->ssd_seg
;
5319 section
= subseg_new (alias
, 0);
5320 else if (!alias
&& USE_ALIASES
)
5322 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5323 demand_empty_rest_of_line ();
5327 section
= subseg_new (ss_name
, 0);
5329 /* Now set the flags. */
5330 bfd_set_section_flags (stdoutput
, section
, applicable
);
5332 /* Record any alignment request for this section. */
5333 record_alignment (section
, log2 (alignment
));
5335 /* Set the starting offset for this section. */
5336 bfd_set_section_vma (stdoutput
, section
,
5337 pa_subspace_start (space
, quadrant
));
5339 /* Now that all the flags are set, update an existing subspace,
5340 or create a new one. */
5343 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5344 code_only
, common
, dup_common
,
5345 sort
, zero
, access
, space_index
,
5346 alignment
, quadrant
,
5349 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5351 dup_common
, zero
, sort
,
5352 access
, space_index
,
5353 alignment
, quadrant
, section
);
5355 demand_empty_rest_of_line ();
5356 current_subspace
->ssd_seg
= section
;
5357 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5359 SUBSPACE_DEFINED (current_subspace
) = 1;
5363 /* Create default space and subspace dictionaries. */
5370 space_dict_root
= NULL
;
5371 space_dict_last
= NULL
;
5374 while (pa_def_spaces
[i
].name
)
5378 /* Pick the right name to use for the new section. */
5379 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5380 name
= pa_def_spaces
[i
].alias
;
5382 name
= pa_def_spaces
[i
].name
;
5384 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5385 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5386 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5387 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5388 pa_def_spaces
[i
].segment
, 0);
5393 while (pa_def_subspaces
[i
].name
)
5396 int applicable
, subsegment
;
5397 asection
*segment
= NULL
;
5398 sd_chain_struct
*space
;
5400 /* Pick the right name for the new section and pick the right
5401 subsegment number. */
5402 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5404 name
= pa_def_subspaces
[i
].alias
;
5405 subsegment
= pa_def_subspaces
[i
].subsegment
;
5409 name
= pa_def_subspaces
[i
].name
;
5413 /* Create the new section. */
5414 segment
= subseg_new (name
, subsegment
);
5417 /* For SOM we want to replace the standard .text, .data, and .bss
5418 sections with our own. We also want to set BFD flags for
5419 all the built-in subspaces. */
5420 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5422 text_section
= segment
;
5423 applicable
= bfd_applicable_section_flags (stdoutput
);
5424 bfd_set_section_flags (stdoutput
, segment
,
5425 applicable
& (SEC_ALLOC
| SEC_LOAD
5426 | SEC_RELOC
| SEC_CODE
5428 | SEC_HAS_CONTENTS
));
5430 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5432 data_section
= segment
;
5433 applicable
= bfd_applicable_section_flags (stdoutput
);
5434 bfd_set_section_flags (stdoutput
, segment
,
5435 applicable
& (SEC_ALLOC
| SEC_LOAD
5437 | SEC_HAS_CONTENTS
));
5441 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5443 bss_section
= segment
;
5444 applicable
= bfd_applicable_section_flags (stdoutput
);
5445 bfd_set_section_flags (stdoutput
, segment
,
5446 applicable
& SEC_ALLOC
);
5448 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5450 applicable
= bfd_applicable_section_flags (stdoutput
);
5451 bfd_set_section_flags (stdoutput
, segment
,
5452 applicable
& (SEC_ALLOC
| SEC_LOAD
5455 | SEC_HAS_CONTENTS
));
5457 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5459 applicable
= bfd_applicable_section_flags (stdoutput
);
5460 bfd_set_section_flags (stdoutput
, segment
,
5461 applicable
& (SEC_ALLOC
| SEC_LOAD
5464 | SEC_HAS_CONTENTS
));
5467 /* Find the space associated with this subspace. */
5468 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5469 def_space_index
].segment
);
5472 as_fatal ("Internal error: Unable to find containing space for %s.",
5473 pa_def_subspaces
[i
].name
);
5476 create_new_subspace (space
, name
,
5477 pa_def_subspaces
[i
].loadable
,
5478 pa_def_subspaces
[i
].code_only
,
5479 pa_def_subspaces
[i
].common
,
5480 pa_def_subspaces
[i
].dup_common
,
5481 pa_def_subspaces
[i
].zero
,
5482 pa_def_subspaces
[i
].sort
,
5483 pa_def_subspaces
[i
].access
,
5484 pa_def_subspaces
[i
].space_index
,
5485 pa_def_subspaces
[i
].alignment
,
5486 pa_def_subspaces
[i
].quadrant
,
5494 /* Create a new space NAME, with the appropriate flags as defined
5495 by the given parameters. */
5497 static sd_chain_struct
*
5498 create_new_space (name
, spnum
, loadable
, defined
, private,
5499 sort
, seg
, user_defined
)
5509 sd_chain_struct
*chain_entry
;
5511 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5513 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5516 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5517 strcpy (SPACE_NAME (chain_entry
), name
);
5518 SPACE_DEFINED (chain_entry
) = defined
;
5519 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5520 SPACE_SPNUM (chain_entry
) = spnum
;
5522 chain_entry
->sd_seg
= seg
;
5523 chain_entry
->sd_last_subseg
= -1;
5524 chain_entry
->sd_subspaces
= NULL
;
5525 chain_entry
->sd_next
= NULL
;
5527 /* Find spot for the new space based on its sort key. */
5528 if (!space_dict_last
)
5529 space_dict_last
= chain_entry
;
5531 if (space_dict_root
== NULL
)
5532 space_dict_root
= chain_entry
;
5535 sd_chain_struct
*chain_pointer
;
5536 sd_chain_struct
*prev_chain_pointer
;
5538 chain_pointer
= space_dict_root
;
5539 prev_chain_pointer
= NULL
;
5541 while (chain_pointer
)
5543 prev_chain_pointer
= chain_pointer
;
5544 chain_pointer
= chain_pointer
->sd_next
;
5547 /* At this point we've found the correct place to add the new
5548 entry. So add it and update the linked lists as appropriate. */
5549 if (prev_chain_pointer
)
5551 chain_entry
->sd_next
= chain_pointer
;
5552 prev_chain_pointer
->sd_next
= chain_entry
;
5556 space_dict_root
= chain_entry
;
5557 chain_entry
->sd_next
= chain_pointer
;
5560 if (chain_entry
->sd_next
== NULL
)
5561 space_dict_last
= chain_entry
;
5564 /* This is here to catch predefined spaces which do not get
5565 modified by the user's input. Another call is found at
5566 the bottom of pa_parse_space_stmt to handle cases where
5567 the user modifies a predefined space. */
5568 #ifdef obj_set_section_attributes
5569 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5575 /* Create a new subspace NAME, with the appropriate flags as defined
5576 by the given parameters.
5578 Add the new subspace to the subspace dictionary chain in numerical
5579 order as defined by the SORT entries. */
5581 static ssd_chain_struct
*
5582 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5583 dup_common
, is_zero
, sort
, access
, space_index
,
5584 alignment
, quadrant
, seg
)
5585 sd_chain_struct
*space
;
5587 int loadable
, code_only
, common
, dup_common
, is_zero
;
5595 ssd_chain_struct
*chain_entry
;
5597 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5599 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5601 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5602 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5604 /* Initialize subspace_defined. When we hit a .subspace directive
5605 we'll set it to 1 which "locks-in" the subspace attributes. */
5606 SUBSPACE_DEFINED (chain_entry
) = 0;
5608 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5609 chain_entry
->ssd_seg
= seg
;
5610 chain_entry
->ssd_next
= NULL
;
5612 /* Find spot for the new subspace based on its sort key. */
5613 if (space
->sd_subspaces
== NULL
)
5614 space
->sd_subspaces
= chain_entry
;
5617 ssd_chain_struct
*chain_pointer
;
5618 ssd_chain_struct
*prev_chain_pointer
;
5620 chain_pointer
= space
->sd_subspaces
;
5621 prev_chain_pointer
= NULL
;
5623 while (chain_pointer
)
5625 prev_chain_pointer
= chain_pointer
;
5626 chain_pointer
= chain_pointer
->ssd_next
;
5629 /* Now we have somewhere to put the new entry. Insert it and update
5631 if (prev_chain_pointer
)
5633 chain_entry
->ssd_next
= chain_pointer
;
5634 prev_chain_pointer
->ssd_next
= chain_entry
;
5638 space
->sd_subspaces
= chain_entry
;
5639 chain_entry
->ssd_next
= chain_pointer
;
5643 #ifdef obj_set_subsection_attributes
5644 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5651 /* Update the information for the given subspace based upon the
5652 various arguments. Return the modified subspace chain entry. */
5654 static ssd_chain_struct
*
5655 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5656 zero
, access
, space_index
, alignment
, quadrant
, section
)
5657 sd_chain_struct
*space
;
5671 ssd_chain_struct
*chain_entry
;
5673 chain_entry
= is_defined_subspace (name
);
5675 #ifdef obj_set_subsection_attributes
5676 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5683 /* Return the space chain entry for the space with the name NAME or
5684 NULL if no such space exists. */
5686 static sd_chain_struct
*
5687 is_defined_space (name
)
5690 sd_chain_struct
*chain_pointer
;
5692 for (chain_pointer
= space_dict_root
;
5694 chain_pointer
= chain_pointer
->sd_next
)
5696 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5697 return chain_pointer
;
5700 /* No mapping from segment to space was found. Return NULL. */
5704 /* Find and return the space associated with the given seg. If no mapping
5705 from the given seg to a space is found, then return NULL.
5707 Unlike subspaces, the number of spaces is not expected to grow much,
5708 so a linear exhaustive search is OK here. */
5710 static sd_chain_struct
*
5711 pa_segment_to_space (seg
)
5714 sd_chain_struct
*space_chain
;
5716 /* Walk through each space looking for the correct mapping. */
5717 for (space_chain
= space_dict_root
;
5719 space_chain
= space_chain
->sd_next
)
5721 if (space_chain
->sd_seg
== seg
)
5725 /* Mapping was not found. Return NULL. */
5729 /* Return the space chain entry for the subspace with the name NAME or
5730 NULL if no such subspace exists.
5732 Uses a linear search through all the spaces and subspaces, this may
5733 not be appropriate if we ever being placing each function in its
5736 static ssd_chain_struct
*
5737 is_defined_subspace (name
)
5740 sd_chain_struct
*space_chain
;
5741 ssd_chain_struct
*subspace_chain
;
5743 /* Walk through each space. */
5744 for (space_chain
= space_dict_root
;
5746 space_chain
= space_chain
->sd_next
)
5748 /* Walk through each subspace looking for a name which matches. */
5749 for (subspace_chain
= space_chain
->sd_subspaces
;
5751 subspace_chain
= subspace_chain
->ssd_next
)
5752 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5753 return subspace_chain
;
5756 /* Subspace wasn't found. Return NULL. */
5760 /* Find and return the subspace associated with the given seg. If no
5761 mapping from the given seg to a subspace is found, then return NULL.
5763 If we ever put each procedure/function within its own subspace
5764 (to make life easier on the compiler and linker), then this will have
5765 to become more efficient. */
5767 static ssd_chain_struct
*
5768 pa_subsegment_to_subspace (seg
, subseg
)
5772 sd_chain_struct
*space_chain
;
5773 ssd_chain_struct
*subspace_chain
;
5775 /* Walk through each space. */
5776 for (space_chain
= space_dict_root
;
5778 space_chain
= space_chain
->sd_next
)
5780 if (space_chain
->sd_seg
== seg
)
5782 /* Walk through each subspace within each space looking for
5783 the correct mapping. */
5784 for (subspace_chain
= space_chain
->sd_subspaces
;
5786 subspace_chain
= subspace_chain
->ssd_next
)
5787 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5788 return subspace_chain
;
5792 /* No mapping from subsegment to subspace found. Return NULL. */
5796 /* Given a number, try and find a space with the name number.
5798 Return a pointer to a space dictionary chain entry for the space
5799 that was found or NULL on failure. */
5801 static sd_chain_struct
*
5802 pa_find_space_by_number (number
)
5805 sd_chain_struct
*space_chain
;
5807 for (space_chain
= space_dict_root
;
5809 space_chain
= space_chain
->sd_next
)
5811 if (SPACE_SPNUM (space_chain
) == number
)
5815 /* No appropriate space found. Return NULL. */
5819 /* Return the starting address for the given subspace. If the starting
5820 address is unknown then return zero. */
5823 pa_subspace_start (space
, quadrant
)
5824 sd_chain_struct
*space
;
5827 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5828 is not correct for the PA OSF1 port. */
5829 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5831 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5837 /* FIXME. Needs documentation. */
5839 pa_next_subseg (space
)
5840 sd_chain_struct
*space
;
5843 space
->sd_last_subseg
++;
5844 return space
->sd_last_subseg
;
5847 /* Helper function for pa_stringer. Used to find the end of
5854 unsigned int c
= *s
& CHAR_MASK
;
5866 /* Handle a .STRING type pseudo-op. */
5869 pa_stringer (append_zero
)
5872 char *s
, num_buf
[4];
5876 /* Preprocess the string to handle PA-specific escape sequences.
5877 For example, \xDD where DD is a hexidecimal number should be
5878 changed to \OOO where OOO is an octal number. */
5880 /* Skip the opening quote. */
5881 s
= input_line_pointer
+ 1;
5883 while (is_a_char (c
= pa_stringer_aux (s
++)))
5890 /* Handle \x<num>. */
5893 unsigned int number
;
5898 /* Get pas the 'x'. */
5900 for (num_digit
= 0, number
= 0, dg
= *s
;
5902 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
5903 || (dg
>= 'A' && dg
<= 'F'));
5907 number
= number
* 16 + dg
- '0';
5908 else if (dg
>= 'a' && dg
<= 'f')
5909 number
= number
* 16 + dg
- 'a' + 10;
5911 number
= number
* 16 + dg
- 'A' + 10;
5921 sprintf (num_buf
, "%02o", number
);
5924 sprintf (num_buf
, "%03o", number
);
5927 for (i
= 0; i
<= num_digit
; i
++)
5928 s_start
[i
] = num_buf
[i
];
5932 /* This might be a "\"", skip over the escaped char. */
5939 stringer (append_zero
);
5940 pa_undefine_label ();
5943 /* Handle a .VERSION pseudo-op. */
5950 pa_undefine_label ();
5953 /* Handle a .COPYRIGHT pseudo-op. */
5956 pa_copyright (unused
)
5960 pa_undefine_label ();
5963 /* Just like a normal cons, but when finished we have to undefine
5964 the latest space label. */
5971 pa_undefine_label ();
5974 /* Switch to the data space. As usual delete our label. */
5981 pa_undefine_label ();
5984 /* Like float_cons, but we need to undefine our label. */
5987 pa_float_cons (float_type
)
5990 float_cons (float_type
);
5991 pa_undefine_label ();
5994 /* Like s_fill, but delete our label when finished. */
6001 pa_undefine_label ();
6004 /* Like lcomm, but delete our label when finished. */
6007 pa_lcomm (needs_align
)
6010 s_lcomm (needs_align
);
6011 pa_undefine_label ();
6014 /* Like lsym, but delete our label when finished. */
6021 pa_undefine_label ();
6024 /* Switch to the text space. Like s_text, but delete our
6025 label when finished. */
6031 pa_undefine_label ();
6034 /* On the PA relocations which involve function symbols must not be
6035 adjusted. This so that the linker can know when/how to create argument
6036 relocation stubs for indirect calls and calls to static functions.
6038 "T" field selectors create DLT relative fixups for accessing
6039 globals and statics in PIC code; each DLT relative fixup creates
6040 an entry in the DLT table. The entries contain the address of
6041 the final target (eg accessing "foo" would create a DLT entry
6042 with the address of "foo").
6044 Unfortunately, the HP linker doesn't take into account any addend
6045 when generating the DLT; so accessing $LIT$+8 puts the address of
6046 $LIT$ into the DLT rather than the address of $LIT$+8.
6048 The end result is we can't perform relocation symbol reductions for
6049 any fixup which creates entries in the DLT (eg they use "T" field
6052 Reject reductions involving symbols with external scope; such
6053 reductions make life a living hell for object file editors.
6055 FIXME. Also reject R_HPPA relocations which are 32 bits
6056 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6057 needs to generate relocations to push the addend and symbol value
6058 onto the stack, add them, then pop the value off the stack and
6059 use it in a relocation -- yuk. */
6062 hppa_fix_adjustable (fixp
)
6065 struct hppa_fix_struct
*hppa_fix
;
6067 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6069 /* Reject reductions of symbols in 32bit plabel relocs. */
6070 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6073 /* Reject reductions of symbols in DLT relative relocs. */
6074 if (hppa_fix
->fx_r_field
== e_tsel
6075 || hppa_fix
->fx_r_field
== e_ltsel
6076 || hppa_fix
->fx_r_field
== e_rtsel
)
6079 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6082 /* Reject reductions of function symbols. */
6083 if (fixp
->fx_addsy
== 0
6084 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6090 /* Return nonzero if the fixup in FIXP will require a relocation,
6091 even it if appears that the fixup could be completely handled
6095 hppa_force_relocation (fixp
)
6098 struct hppa_fix_struct
*hppa_fixp
;
6100 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6102 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6106 #define stub_needed(CALLER, CALLEE) \
6107 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6109 /* It is necessary to force PC-relative calls/jumps to have a relocation
6110 entry if they're going to need either a argument relocation or long
6111 call stub. FIXME. Can't we need the same for absolute calls? */
6112 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6113 && (stub_needed (((obj_symbol_type
*)
6114 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6115 hppa_fixp
->fx_arg_reloc
)))
6120 /* No need (yet) to force another relocations to be emitted. */
6124 /* Now for some ELF specific code. FIXME. */
6126 /* Mark the end of a function so that it's possible to compute
6127 the size of the function in hppa_elf_final_processing. */
6130 hppa_elf_mark_end_of_function ()
6132 /* ELF does not have EXIT relocations. All we do is create a
6133 temporary symbol marking the end of the function. */
6134 char *name
= (char *)
6135 xmalloc (strlen ("L$\001end_") +
6136 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6142 strcpy (name
, "L$\001end_");
6143 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6145 /* If we have a .exit followed by a .procend, then the
6146 symbol will have already been defined. */
6147 symbolP
= symbol_find (name
);
6150 /* The symbol has already been defined! This can
6151 happen if we have a .exit followed by a .procend.
6153 This is *not* an error. All we want to do is free
6154 the memory we just allocated for the name and continue. */
6159 /* symbol value should be the offset of the
6160 last instruction of the function */
6161 symbolP
= symbol_new (name
, now_seg
,
6162 (valueT
) (obstack_next_free (&frags
)
6163 - frag_now
->fr_literal
- 4),
6167 symbolP
->bsym
->flags
= BSF_LOCAL
;
6168 symbol_table_insert (symbolP
);
6172 last_call_info
->end_symbol
= symbolP
;
6174 as_bad ("Symbol '%s' could not be created.", name
);
6178 as_bad ("No memory for symbol name.");
6182 /* For ELF, this function serves one purpose: to setup the st_size
6183 field of STT_FUNC symbols. To do this, we need to scan the
6184 call_info structure list, determining st_size in by taking the
6185 difference in the address of the beginning/end marker symbols. */
6188 elf_hppa_final_processing ()
6190 struct call_info
*call_info_pointer
;
6192 for (call_info_pointer
= call_info_root
;
6194 call_info_pointer
= call_info_pointer
->ci_next
)
6196 elf_symbol_type
*esym
6197 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6198 esym
->internal_elf_sym
.st_size
=
6199 S_GET_VALUE (call_info_pointer
->end_symbol
)
6200 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;