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_block
PARAMS ((int));
476 static void pa_call
PARAMS ((int));
477 static void pa_call_args
PARAMS ((struct call_desc
*));
478 static void pa_callinfo
PARAMS ((int));
479 static void pa_code
PARAMS ((int));
480 static void pa_comm
PARAMS ((int));
481 static void pa_copyright
PARAMS ((int));
482 static void pa_end
PARAMS ((int));
483 static void pa_enter
PARAMS ((int));
484 static void pa_entry
PARAMS ((int));
485 static void pa_equ
PARAMS ((int));
486 static void pa_exit
PARAMS ((int));
487 static void pa_export
PARAMS ((int));
488 static void pa_type_args
PARAMS ((symbolS
*, int));
489 static void pa_import
PARAMS ((int));
490 static void pa_label
PARAMS ((int));
491 static void pa_leave
PARAMS ((int));
492 static void pa_origin
PARAMS ((int));
493 static void pa_proc
PARAMS ((int));
494 static void pa_procend
PARAMS ((int));
495 static void pa_space
PARAMS ((int));
496 static void pa_spnum
PARAMS ((int));
497 static void pa_subspace
PARAMS ((int));
498 static void pa_param
PARAMS ((int));
499 static void pa_undefine_label
PARAMS ((void));
500 static int need_89_opcode
PARAMS ((struct pa_it
*,
501 struct pa_89_fp_reg_struct
*));
502 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
503 static label_symbol_struct
*pa_get_label
PARAMS ((void));
504 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
507 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
512 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
513 char *, int, int, int,
517 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
518 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
519 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
520 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
522 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
523 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
524 static void pa_ip
PARAMS ((char *));
525 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
526 long, expressionS
*, int,
527 bfd_reloc_code_real_type
,
528 enum hppa_reloc_field_selector_type
,
530 static int is_end_of_statement
PARAMS ((void));
531 static int reg_name_search
PARAMS ((char *));
532 static int pa_chk_field_selector
PARAMS ((char **));
533 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
534 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
535 static void process_exit
PARAMS ((void));
536 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
537 static int log2
PARAMS ((int));
538 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
539 static unsigned int pa_stringer_aux
PARAMS ((char *));
540 static void pa_spaces_begin
PARAMS ((void));
541 static void hppa_elf_mark_end_of_function
PARAMS ((void));
543 /* File and gloally scoped variable declarations. */
545 /* Root and final entry in the space chain. */
546 static sd_chain_struct
*space_dict_root
;
547 static sd_chain_struct
*space_dict_last
;
549 /* The current space and subspace. */
550 static sd_chain_struct
*current_space
;
551 static ssd_chain_struct
*current_subspace
;
553 /* Root of the call_info chain. */
554 static struct call_info
*call_info_root
;
556 /* The last call_info (for functions) structure
557 seen so it can be associated with fixups and
559 static struct call_info
*last_call_info
;
561 /* The last call description (for actual calls). */
562 static struct call_desc last_call_desc
;
564 /* Relaxation isn't supported for the PA yet. */
565 const relax_typeS md_relax_table
[] =
568 /* Jumps are always the same size -- one instruction. */
569 int md_short_jump_size
= 4;
570 int md_long_jump_size
= 4;
572 /* handle of the OPCODE hash table */
573 static struct hash_control
*op_hash
= NULL
;
575 /* This array holds the chars that always start a comment. If the
576 pre-processor is disabled, these aren't very useful. */
577 const char comment_chars
[] = ";";
579 /* Table of pseudo ops for the PA. FIXME -- how many of these
580 are now redundant with the overall GAS and the object file
582 const pseudo_typeS md_pseudo_table
[] =
584 /* align pseudo-ops on the PA specify the actual alignment requested,
585 not the log2 of the requested alignment. */
586 {"align", s_align_bytes
, 8},
587 {"block", pa_block
, 1},
588 {"blockz", pa_block
, 0},
589 {"byte", pa_cons
, 1},
590 {"call", pa_call
, 0},
591 {"callinfo", pa_callinfo
, 0},
592 {"code", pa_code
, 0},
593 {"comm", pa_comm
, 0},
594 {"copyright", pa_copyright
, 0},
595 {"data", pa_data
, 0},
596 {"double", pa_float_cons
, 'd'},
598 {"enter", pa_enter
, 0},
599 {"entry", pa_entry
, 0},
601 {"exit", pa_exit
, 0},
602 {"export", pa_export
, 0},
603 {"fill", pa_fill
, 0},
604 {"float", pa_float_cons
, 'f'},
605 {"half", pa_cons
, 2},
606 {"import", pa_import
, 0},
608 {"label", pa_label
, 0},
609 {"lcomm", pa_lcomm
, 0},
610 {"leave", pa_leave
, 0},
611 {"long", pa_cons
, 4},
612 {"lsym", pa_lsym
, 0},
613 {"octa", pa_cons
, 16},
614 {"org", pa_origin
, 0},
615 {"origin", pa_origin
, 0},
616 {"param", pa_param
, 0},
617 {"proc", pa_proc
, 0},
618 {"procend", pa_procend
, 0},
619 {"quad", pa_cons
, 8},
621 {"short", pa_cons
, 2},
622 {"single", pa_float_cons
, 'f'},
623 {"space", pa_space
, 0},
624 {"spnum", pa_spnum
, 0},
625 {"string", pa_stringer
, 0},
626 {"stringz", pa_stringer
, 1},
627 {"subspa", pa_subspace
, 0},
628 {"text", pa_text
, 0},
629 {"version", pa_version
, 0},
630 {"word", pa_cons
, 4},
634 /* This array holds the chars that only start a comment at the beginning of
635 a line. If the line seems to have the form '# 123 filename'
636 .line and .file directives will appear in the pre-processed output.
638 Note that input_file.c hand checks for '#' at the beginning of the
639 first line of the input file. This is because the compiler outputs
640 #NO_APP at the beginning of its output.
642 Also note that '/*' will always start a comment. */
643 const char line_comment_chars
[] = "#";
645 /* This array holds the characters which act as line separators. */
646 const char line_separator_chars
[] = "!";
648 /* Chars that can be used to separate mant from exp in floating point nums. */
649 const char EXP_CHARS
[] = "eE";
651 /* Chars that mean this number is a floating point constant.
652 As in 0f12.456 or 0d1.2345e12.
654 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
655 changed in read.c. Ideally it shouldn't hae to know abou it at
656 all, but nothing is ideal around here. */
657 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
659 static struct pa_it the_insn
;
661 /* Points to the end of an expression just parsed by get_expressoin
662 and friends. FIXME. This shouldn't be handled with a file-global
664 static char *expr_end
;
666 /* Nonzero if a .callinfo appeared within the current procedure. */
667 static int callinfo_found
;
669 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
670 static int within_entry_exit
;
672 /* Nonzero if the assembler is currently within a procedure definition. */
673 static int within_procedure
;
675 /* Handle on strucutre which keep track of the last symbol
676 seen in each subspace. */
677 static label_symbol_struct
*label_symbols_rootp
= NULL
;
679 /* Holds the last field selector. */
680 static int hppa_field_selector
;
682 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
683 static symbolS
*dummy_symbol
;
685 /* Nonzero if errors are to be printed. */
686 static int print_errors
= 1;
688 /* List of registers that are pre-defined:
690 Each general register has one predefined name of the form
691 %r<REGNUM> which has the value <REGNUM>.
693 Space and control registers are handled in a similar manner,
694 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
696 Likewise for the floating point registers, but of the form
697 %fr<REGNUM>. Floating point registers have additional predefined
698 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
699 again have the value <REGNUM>.
701 Many registers also have synonyms:
703 %r26 - %r23 have %arg0 - %arg3 as synonyms
704 %r28 - %r29 have %ret0 - %ret1 as synonyms
705 %r30 has %sp as a synonym
706 %r27 has %dp as a synonym
707 %r2 has %rp as a synonym
709 Almost every control register has a synonym; they are not listed
712 The table is sorted. Suitable for searching by a binary search. */
714 static const struct pd_reg pre_defined_registers
[] =
914 /* This table is sorted by order of the length of the string. This is
915 so we check for <> before we check for <. If we had a <> and checked
916 for < first, we would get a false match. */
917 static const struct fp_cond_map fp_cond_map
[] =
953 static const struct selector_entry selector_table
[] =
972 /* default space and subspace dictionaries */
974 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
975 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
977 /* pre-defined subsegments (subspaces) for the HPPA. */
978 #define SUBSEG_CODE 0
979 #define SUBSEG_DATA 0
982 #define SUBSEG_UNWIND 3
983 #define SUBSEG_GDB_STRINGS 0
984 #define SUBSEG_GDB_SYMBOLS 1
986 static struct default_subspace_dict pa_def_subspaces
[] =
988 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
989 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
990 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
991 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
993 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
995 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
998 static struct default_space_dict pa_def_spaces
[] =
1000 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1001 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1002 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1005 /* Misc local definitions used by the assembler. */
1007 /* Return nonzero if the string pointed to by S potentially represents
1008 a right or left half of a FP register */
1009 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1010 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1012 /* These macros are used to maintain spaces/subspaces. */
1013 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1014 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1015 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1016 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1018 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1019 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1021 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1022 main loop after insertion. */
1024 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1026 ((OPCODE) |= (FIELD) << (START)); \
1030 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1031 IGNORE is used to suppress the error message. */
1033 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1035 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1038 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1044 #define is_DP_relative(exp) \
1045 ((exp).X_op == O_subtract \
1046 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1048 #define is_PC_relative(exp) \
1049 ((exp).X_op == O_subtract \
1050 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1052 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1053 always be able to reduce the expression to a constant, so we don't
1054 need real complex handling yet. */
1055 #define is_complex(exp) \
1056 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1058 /* Actual functions to implement the PA specific code for the assembler. */
1060 /* Returns a pointer to the label_symbol_struct for the current space.
1061 or NULL if no label_symbol_struct exists for the current space. */
1063 static label_symbol_struct
*
1066 label_symbol_struct
*label_chain
;
1067 sd_chain_struct
*space_chain
= current_space
;
1069 for (label_chain
= label_symbols_rootp
;
1071 label_chain
= label_chain
->lss_next
)
1072 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1078 /* Defines a label for the current space. If one is already defined,
1079 this function will replace it with the new label. */
1082 pa_define_label (symbol
)
1085 label_symbol_struct
*label_chain
= pa_get_label ();
1086 sd_chain_struct
*space_chain
= current_space
;
1089 label_chain
->lss_label
= symbol
;
1092 /* Create a new label entry and add it to the head of the chain. */
1094 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1095 label_chain
->lss_label
= symbol
;
1096 label_chain
->lss_space
= space_chain
;
1097 label_chain
->lss_next
= NULL
;
1099 if (label_symbols_rootp
)
1100 label_chain
->lss_next
= label_symbols_rootp
;
1102 label_symbols_rootp
= label_chain
;
1106 /* Removes a label definition for the current space.
1107 If there is no label_symbol_struct entry, then no action is taken. */
1110 pa_undefine_label ()
1112 label_symbol_struct
*label_chain
;
1113 label_symbol_struct
*prev_label_chain
= NULL
;
1114 sd_chain_struct
*space_chain
= current_space
;
1116 for (label_chain
= label_symbols_rootp
;
1118 label_chain
= label_chain
->lss_next
)
1120 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1122 /* Remove the label from the chain and free its memory. */
1123 if (prev_label_chain
)
1124 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1126 label_symbols_rootp
= label_chain
->lss_next
;
1131 prev_label_chain
= label_chain
;
1136 /* An HPPA-specific version of fix_new. This is required because the HPPA
1137 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1138 results in the creation of an instance of an hppa_fix_struct. An
1139 hppa_fix_struct stores the extra information along with a pointer to the
1140 original fixS. This is attached to the original fixup via the
1141 tc_fix_data field. */
1144 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1145 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1149 symbolS
*add_symbol
;
1153 bfd_reloc_code_real_type r_type
;
1154 enum hppa_reloc_field_selector_type r_field
;
1161 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1162 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1165 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1167 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1168 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1169 hppa_fix
->fx_r_type
= r_type
;
1170 hppa_fix
->fx_r_field
= r_field
;
1171 hppa_fix
->fx_r_format
= r_format
;
1172 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1173 hppa_fix
->segment
= now_seg
;
1175 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1176 new_fix
->fx_addnumber
= *unwind_bits
;
1179 /* foo-$global$ is used to access non-automatic storage. $global$
1180 is really just a marker and has served its purpose, so eliminate
1181 it now so as not to confuse write.c. */
1182 if (new_fix
->fx_subsy
1183 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1184 new_fix
->fx_subsy
= NULL
;
1187 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1188 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1191 parse_cons_expression_hppa (exp
)
1194 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1198 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1199 hppa_field_selector is set by the parse_cons_expression_hppa. */
1202 cons_fix_new_hppa (frag
, where
, size
, exp
)
1208 unsigned int rel_type
;
1210 /* Get a base relocation type. */
1211 if (is_DP_relative (*exp
))
1212 rel_type
= R_HPPA_GOTOFF
;
1213 else if (is_complex (*exp
))
1214 rel_type
= R_HPPA_COMPLEX
;
1218 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1219 as_warn ("Invalid field selector. Assuming F%%.");
1221 fix_new_hppa (frag
, where
, size
,
1222 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1223 hppa_field_selector
, 32, 0, NULL
);
1225 /* Reset field selector to its default state. */
1226 hppa_field_selector
= 0;
1229 /* This function is called once, at assembler startup time. It should
1230 set up all the tables, etc. that the MD part of the assembler will need. */
1235 const char *retval
= NULL
;
1239 last_call_info
= NULL
;
1240 call_info_root
= NULL
;
1242 /* Folding of text and data segments fails miserably on the PA.
1243 Warn user and disable "-R" option. */
1244 if (flag_readonly_data_in_text
)
1246 as_warn ("-R option not supported on this target.");
1247 flag_readonly_data_in_text
= 0;
1252 op_hash
= hash_new ();
1254 while (i
< NUMOPCODES
)
1256 const char *name
= pa_opcodes
[i
].name
;
1257 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1258 if (retval
!= NULL
&& *retval
!= '\0')
1260 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1265 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1266 != pa_opcodes
[i
].match
)
1268 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1269 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1274 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1278 as_fatal ("Broken assembler. No assembly attempted.");
1280 /* SOM will change text_section. To make sure we never put
1281 anything into the old one switch to the new one now. */
1282 subseg_set (text_section
, 0);
1284 dummy_symbol
= symbol_find_or_make ("L$dummy");
1285 S_SET_SEGMENT (dummy_symbol
, text_section
);
1288 /* Assemble a single instruction storing it into a frag. */
1295 /* The had better be something to assemble. */
1298 /* If we are within a procedure definition, make sure we've
1299 defined a label for the procedure; handle case where the
1300 label was defined after the .PROC directive.
1302 Note there's not need to diddle with the segment or fragment
1303 for the label symbol in this case. We have already switched
1304 into the new $CODE$ subspace at this point. */
1305 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1307 label_symbol_struct
*label_symbol
= pa_get_label ();
1311 if (label_symbol
->lss_label
)
1313 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1314 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1316 /* Also handle allocation of a fixup to hold the unwind
1317 information when the label appears after the proc/procend. */
1318 if (within_entry_exit
)
1320 char *where
= frag_more (0);
1322 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1323 NULL
, (offsetT
) 0, NULL
,
1324 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1325 (int *)&last_call_info
->ci_unwind
.descriptor
);
1330 as_bad ("Missing function name for .PROC (corrupted label chain)");
1333 as_bad ("Missing function name for .PROC");
1336 /* Assemble the instruction. Results are saved into "the_insn". */
1339 /* Get somewhere to put the assembled instrution. */
1342 /* Output the opcode. */
1343 md_number_to_chars (to
, the_insn
.opcode
, 4);
1345 /* If necessary output more stuff. */
1346 if (the_insn
.reloc
!= R_HPPA_NONE
)
1347 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1348 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1349 the_insn
.reloc
, the_insn
.field_selector
,
1350 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1353 /* Do the real work for assembling a single instruction. Store results
1354 into the global "the_insn" variable. */
1360 char *error_message
= "";
1361 char *s
, c
, *argstart
, *name
, *save_s
;
1365 int cmpltr
, nullif
, flag
, cond
, num
;
1366 unsigned long opcode
;
1367 struct pa_opcode
*insn
;
1369 /* Skip to something interesting. */
1370 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1389 as_fatal ("Unknown opcode: `%s'", str
);
1394 /* Convert everything into lower case. */
1397 if (isupper (*save_s
))
1398 *save_s
= tolower (*save_s
);
1402 /* Look up the opcode in the has table. */
1403 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1405 as_bad ("Unknown opcode: `%s'", str
);
1414 /* Mark the location where arguments for the instruction start, then
1415 start processing them. */
1419 /* Do some initialization. */
1420 opcode
= insn
->match
;
1421 bzero (&the_insn
, sizeof (the_insn
));
1423 the_insn
.reloc
= R_HPPA_NONE
;
1425 /* Build the opcode, checking as we go to make
1426 sure that the operands match. */
1427 for (args
= insn
->args
;; ++args
)
1432 /* End of arguments. */
1448 /* These must match exactly. */
1457 /* Handle a 5 bit register or control register field at 10. */
1460 num
= pa_parse_number (&s
, 0);
1461 CHECK_FIELD (num
, 31, 0, 0);
1462 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1464 /* Handle a 5 bit register field at 15. */
1466 num
= pa_parse_number (&s
, 0);
1467 CHECK_FIELD (num
, 31, 0, 0);
1468 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1470 /* Handle a 5 bit register field at 31. */
1473 num
= pa_parse_number (&s
, 0);
1474 CHECK_FIELD (num
, 31, 0, 0);
1475 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1477 /* Handle a 5 bit field length at 31. */
1479 num
= pa_get_absolute_expression (&the_insn
, &s
);
1481 CHECK_FIELD (num
, 32, 1, 0);
1482 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1484 /* Handle a 5 bit immediate at 15. */
1486 num
= pa_get_absolute_expression (&the_insn
, &s
);
1488 CHECK_FIELD (num
, 15, -16, 0);
1489 low_sign_unext (num
, 5, &num
);
1490 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1492 /* Handle a 5 bit immediate at 31. */
1494 num
= pa_get_absolute_expression (&the_insn
, &s
);
1496 CHECK_FIELD (num
, 15, -16, 0)
1497 low_sign_unext (num
, 5, &num
);
1498 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1500 /* Handle an unsigned 5 bit immediate at 31. */
1502 num
= pa_get_absolute_expression (&the_insn
, &s
);
1504 CHECK_FIELD (num
, 31, 0, 0);
1505 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1507 /* Handle an unsigned 5 bit immediate at 15. */
1509 num
= pa_get_absolute_expression (&the_insn
, &s
);
1511 CHECK_FIELD (num
, 31, 0, 0);
1512 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1514 /* Handle a 2 bit space identifier at 17. */
1516 num
= pa_parse_number (&s
, 0);
1517 CHECK_FIELD (num
, 3, 0, 1);
1518 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1520 /* Handle a 3 bit space identifier at 18. */
1522 num
= pa_parse_number (&s
, 0);
1523 CHECK_FIELD (num
, 7, 0, 1);
1524 dis_assemble_3 (num
, &num
);
1525 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1527 /* Handle a completer for an indexing load or store. */
1533 while (*s
== ',' && i
< 2)
1536 if (strncasecmp (s
, "sm", 2) == 0)
1543 else if (strncasecmp (s
, "m", 1) == 0)
1545 else if (strncasecmp (s
, "s", 1) == 0)
1548 as_bad ("Invalid Indexed Load Completer.");
1553 as_bad ("Invalid Indexed Load Completer Syntax.");
1555 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1558 /* Handle a short load/store completer. */
1566 if (strncasecmp (s
, "ma", 2) == 0)
1571 else if (strncasecmp (s
, "mb", 2) == 0)
1577 as_bad ("Invalid Short Load/Store Completer.");
1581 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1584 /* Handle a stbys completer. */
1590 while (*s
== ',' && i
< 2)
1593 if (strncasecmp (s
, "m", 1) == 0)
1595 else if (strncasecmp (s
, "b", 1) == 0)
1597 else if (strncasecmp (s
, "e", 1) == 0)
1600 as_bad ("Invalid Store Bytes Short Completer");
1605 as_bad ("Invalid Store Bytes Short Completer");
1607 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1610 /* Handle a non-negated compare/stubtract condition. */
1612 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1615 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1618 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1620 /* Handle a negated or non-negated compare/subtract condition. */
1623 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1627 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1630 as_bad ("Invalid Compare/Subtract Condition.");
1635 /* Negated condition requires an opcode change. */
1639 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1641 /* Handle non-negated add condition. */
1643 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1646 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1649 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1651 /* Handle a negated or non-negated add condition. */
1654 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1658 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1661 as_bad ("Invalid Compare/Subtract Condition");
1666 /* Negated condition requires an opcode change. */
1670 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1672 /* Handle a compare/subtract condition. */
1679 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1684 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1687 as_bad ("Invalid Compare/Subtract Condition");
1691 opcode
|= cmpltr
<< 13;
1692 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1694 /* Handle a non-negated add condition. */
1703 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1707 if (strcmp (name
, "=") == 0)
1709 else if (strcmp (name
, "<") == 0)
1711 else if (strcmp (name
, "<=") == 0)
1713 else if (strcasecmp (name
, "nuv") == 0)
1715 else if (strcasecmp (name
, "znv") == 0)
1717 else if (strcasecmp (name
, "sv") == 0)
1719 else if (strcasecmp (name
, "od") == 0)
1721 else if (strcasecmp (name
, "n") == 0)
1723 else if (strcasecmp (name
, "tr") == 0)
1728 else if (strcmp (name
, "<>") == 0)
1733 else if (strcmp (name
, ">=") == 0)
1738 else if (strcmp (name
, ">") == 0)
1743 else if (strcasecmp (name
, "uv") == 0)
1748 else if (strcasecmp (name
, "vnz") == 0)
1753 else if (strcasecmp (name
, "nsv") == 0)
1758 else if (strcasecmp (name
, "ev") == 0)
1764 as_bad ("Invalid Add Condition: %s", name
);
1767 nullif
= pa_parse_nullif (&s
);
1768 opcode
|= nullif
<< 1;
1769 opcode
|= cmpltr
<< 13;
1770 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1772 /* HANDLE a logical instruction condition. */
1780 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1784 if (strcmp (name
, "=") == 0)
1786 else if (strcmp (name
, "<") == 0)
1788 else if (strcmp (name
, "<=") == 0)
1790 else if (strcasecmp (name
, "od") == 0)
1792 else if (strcasecmp (name
, "tr") == 0)
1797 else if (strcmp (name
, "<>") == 0)
1802 else if (strcmp (name
, ">=") == 0)
1807 else if (strcmp (name
, ">") == 0)
1812 else if (strcasecmp (name
, "ev") == 0)
1818 as_bad ("Invalid Logical Instruction Condition.");
1821 opcode
|= cmpltr
<< 13;
1822 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1824 /* Handle a unit instruction condition. */
1831 if (strncasecmp (s
, "sbz", 3) == 0)
1836 else if (strncasecmp (s
, "shz", 3) == 0)
1841 else if (strncasecmp (s
, "sdc", 3) == 0)
1846 else if (strncasecmp (s
, "sbc", 3) == 0)
1851 else if (strncasecmp (s
, "shc", 3) == 0)
1856 else if (strncasecmp (s
, "tr", 2) == 0)
1862 else if (strncasecmp (s
, "nbz", 3) == 0)
1868 else if (strncasecmp (s
, "nhz", 3) == 0)
1874 else if (strncasecmp (s
, "ndc", 3) == 0)
1880 else if (strncasecmp (s
, "nbc", 3) == 0)
1886 else if (strncasecmp (s
, "nhc", 3) == 0)
1893 as_bad ("Invalid Logical Instruction Condition.");
1895 opcode
|= cmpltr
<< 13;
1896 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1898 /* Handle a shift/extract/deposit condition. */
1906 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1910 if (strcmp (name
, "=") == 0)
1912 else if (strcmp (name
, "<") == 0)
1914 else if (strcasecmp (name
, "od") == 0)
1916 else if (strcasecmp (name
, "tr") == 0)
1918 else if (strcmp (name
, "<>") == 0)
1920 else if (strcmp (name
, ">=") == 0)
1922 else if (strcasecmp (name
, "ev") == 0)
1924 /* Handle movb,n. Put things back the way they were.
1925 This includes moving s back to where it started. */
1926 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1933 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1936 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1938 /* Handle bvb and bb conditions. */
1944 if (strncmp (s
, "<", 1) == 0)
1949 else if (strncmp (s
, ">=", 2) == 0)
1955 as_bad ("Invalid Bit Branch Condition: %c", *s
);
1957 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1959 /* Handle a system control completer. */
1961 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
1969 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1971 /* Handle a nullification completer for branch instructions. */
1973 nullif
= pa_parse_nullif (&s
);
1974 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
1976 /* Handle a nullification completer for copr and spop insns. */
1978 nullif
= pa_parse_nullif (&s
);
1979 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
1981 /* Handle a 11 bit immediate at 31. */
1983 the_insn
.field_selector
= pa_chk_field_selector (&s
);
1986 if (the_insn
.exp
.X_op
== O_constant
)
1988 num
= evaluate_absolute (&the_insn
);
1989 CHECK_FIELD (num
, 1023, -1024, 0);
1990 low_sign_unext (num
, 11, &num
);
1991 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1995 if (is_DP_relative (the_insn
.exp
))
1996 the_insn
.reloc
= R_HPPA_GOTOFF
;
1997 else if (is_PC_relative (the_insn
.exp
))
1998 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2000 the_insn
.reloc
= R_HPPA
;
2001 the_insn
.format
= 11;
2005 /* Handle a 14 bit immediate at 31. */
2007 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2010 if (the_insn
.exp
.X_op
== O_constant
)
2012 num
= evaluate_absolute (&the_insn
);
2013 CHECK_FIELD (num
, 8191, -8192, 0);
2014 low_sign_unext (num
, 14, &num
);
2015 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2019 if (is_DP_relative (the_insn
.exp
))
2020 the_insn
.reloc
= R_HPPA_GOTOFF
;
2021 else if (is_PC_relative (the_insn
.exp
))
2022 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2024 the_insn
.reloc
= R_HPPA
;
2025 the_insn
.format
= 14;
2029 /* Handle a 21 bit immediate at 31. */
2031 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2034 if (the_insn
.exp
.X_op
== O_constant
)
2036 num
= evaluate_absolute (&the_insn
);
2037 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2038 dis_assemble_21 (num
, &num
);
2039 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2043 if (is_DP_relative (the_insn
.exp
))
2044 the_insn
.reloc
= R_HPPA_GOTOFF
;
2045 else if (is_PC_relative (the_insn
.exp
))
2046 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2048 the_insn
.reloc
= R_HPPA
;
2049 the_insn
.format
= 21;
2053 /* Handle a 12 bit branch displacement. */
2055 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2059 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2061 unsigned int w1
, w
, result
;
2063 num
= evaluate_absolute (&the_insn
);
2066 as_bad ("Branch to unaligned address");
2069 CHECK_FIELD (num
, 8191, -8192, 0);
2070 sign_unext ((num
- 8) >> 2, 12, &result
);
2071 dis_assemble_12 (result
, &w1
, &w
);
2072 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2076 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2077 the_insn
.format
= 12;
2078 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2079 bzero (&last_call_desc
, sizeof (struct call_desc
));
2084 /* Handle a 17 bit branch displacement. */
2086 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2090 if (!the_insn
.exp
.X_add_symbol
2091 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2094 unsigned int w2
, w1
, w
, result
;
2096 num
= evaluate_absolute (&the_insn
);
2099 as_bad ("Branch to unaligned address");
2102 CHECK_FIELD (num
, 262143, -262144, 0);
2104 if (the_insn
.exp
.X_add_symbol
)
2107 sign_unext (num
>> 2, 17, &result
);
2108 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2109 INSERT_FIELD_AND_CONTINUE (opcode
,
2110 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2114 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2115 the_insn
.format
= 17;
2116 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2117 bzero (&last_call_desc
, sizeof (struct call_desc
));
2121 /* Handle an absolute 17 bit branch target. */
2123 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2127 if (!the_insn
.exp
.X_add_symbol
2128 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2131 unsigned int w2
, w1
, w
, result
;
2133 num
= evaluate_absolute (&the_insn
);
2136 as_bad ("Branch to unaligned address");
2139 CHECK_FIELD (num
, 262143, -262144, 0);
2141 if (the_insn
.exp
.X_add_symbol
)
2144 sign_unext (num
>> 2, 17, &result
);
2145 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2146 INSERT_FIELD_AND_CONTINUE (opcode
,
2147 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2151 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2152 the_insn
.format
= 17;
2156 /* Handle a 5 bit shift count at 26. */
2158 num
= pa_get_absolute_expression (&the_insn
, &s
);
2160 CHECK_FIELD (num
, 31, 0, 0);
2161 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2163 /* Handle a 5 bit bit position at 26. */
2165 num
= pa_get_absolute_expression (&the_insn
, &s
);
2167 CHECK_FIELD (num
, 31, 0, 0);
2168 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2170 /* Handle a 5 bit immediate at 10. */
2172 num
= pa_get_absolute_expression (&the_insn
, &s
);
2174 CHECK_FIELD (num
, 31, 0, 0);
2175 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2177 /* Handle a 13 bit immediate at 18. */
2179 num
= pa_get_absolute_expression (&the_insn
, &s
);
2181 CHECK_FIELD (num
, 8191, 0, 0);
2182 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2184 /* Handle a 26 bit immediate at 31. */
2186 num
= pa_get_absolute_expression (&the_insn
, &s
);
2188 CHECK_FIELD (num
, 671108864, 0, 0);
2189 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2191 /* Handle a 3 bit SFU identifier at 25. */
2194 as_bad ("Invalid SFU identifier");
2195 num
= pa_get_absolute_expression (&the_insn
, &s
);
2197 CHECK_FIELD (num
, 7, 0, 0);
2198 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2200 /* Handle a 20 bit SOP field for spop0. */
2202 num
= pa_get_absolute_expression (&the_insn
, &s
);
2204 CHECK_FIELD (num
, 1048575, 0, 0);
2205 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2206 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2208 /* Handle a 15bit SOP field for spop1. */
2210 num
= pa_get_absolute_expression (&the_insn
, &s
);
2212 CHECK_FIELD (num
, 32767, 0, 0);
2213 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2215 /* Handle a 10bit SOP field for spop3. */
2217 num
= pa_get_absolute_expression (&the_insn
, &s
);
2219 CHECK_FIELD (num
, 1023, 0, 0);
2220 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2221 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2223 /* Handle a 15 bit SOP field for spop2. */
2225 num
= pa_get_absolute_expression (&the_insn
, &s
);
2227 CHECK_FIELD (num
, 32767, 0, 0);
2228 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2229 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2231 /* Handle a 3-bit co-processor ID field. */
2234 as_bad ("Invalid COPR identifier");
2235 num
= pa_get_absolute_expression (&the_insn
, &s
);
2237 CHECK_FIELD (num
, 7, 0, 0);
2238 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2240 /* Handle a 22bit SOP field for copr. */
2242 num
= pa_get_absolute_expression (&the_insn
, &s
);
2244 CHECK_FIELD (num
, 4194303, 0, 0);
2245 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2246 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2248 /* Handle a source FP operand format completer. */
2250 flag
= pa_parse_fp_format (&s
);
2251 the_insn
.fpof1
= flag
;
2252 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2254 /* Handle a destination FP operand format completer. */
2256 /* pa_parse_format needs the ',' prefix. */
2258 flag
= pa_parse_fp_format (&s
);
2259 the_insn
.fpof2
= flag
;
2260 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2262 /* Handle FP compare conditions. */
2264 cond
= pa_parse_fp_cmp_cond (&s
);
2265 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2267 /* Handle L/R register halves like 't'. */
2270 struct pa_89_fp_reg_struct result
;
2272 pa_parse_number (&s
, &result
);
2273 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2274 opcode
|= result
.number_part
;
2276 /* 0x30 opcodes are FP arithmetic operation opcodes
2277 and need to be turned into 0x38 opcodes. This
2278 is not necessary for loads/stores. */
2279 if (need_89_opcode (&the_insn
, &result
)
2280 && ((opcode
& 0xfc000000) == 0x30000000))
2283 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2286 /* Handle L/R register halves like 'b'. */
2289 struct pa_89_fp_reg_struct result
;
2291 pa_parse_number (&s
, &result
);
2292 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2293 opcode
|= result
.number_part
<< 21;
2294 if (need_89_opcode (&the_insn
, &result
))
2296 opcode
|= (result
.l_r_select
& 1) << 7;
2302 /* Handle L/R register halves like 'x'. */
2305 struct pa_89_fp_reg_struct result
;
2307 pa_parse_number (&s
, &result
);
2308 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2309 opcode
|= (result
.number_part
& 0x1f) << 16;
2310 if (need_89_opcode (&the_insn
, &result
))
2312 opcode
|= (result
.l_r_select
& 1) << 12;
2318 /* Handle a 5 bit register field at 10. */
2321 struct pa_89_fp_reg_struct result
;
2323 pa_parse_number (&s
, &result
);
2324 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2325 if (the_insn
.fpof1
== SGL
)
2327 result
.number_part
&= 0xF;
2328 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2330 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2333 /* Handle a 5 bit register field at 15. */
2336 struct pa_89_fp_reg_struct result
;
2338 pa_parse_number (&s
, &result
);
2339 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2340 if (the_insn
.fpof1
== SGL
)
2342 result
.number_part
&= 0xF;
2343 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2345 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2348 /* Handle a 5 bit register field at 31. */
2351 struct pa_89_fp_reg_struct result
;
2353 pa_parse_number (&s
, &result
);
2354 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2355 if (the_insn
.fpof1
== SGL
)
2357 result
.number_part
&= 0xF;
2358 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2360 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2363 /* Handle a 5 bit register field at 20. */
2366 struct pa_89_fp_reg_struct result
;
2368 pa_parse_number (&s
, &result
);
2369 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2370 if (the_insn
.fpof1
== SGL
)
2372 result
.number_part
&= 0xF;
2373 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2375 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2378 /* Handle a 5 bit register field at 25. */
2381 struct pa_89_fp_reg_struct result
;
2383 pa_parse_number (&s
, &result
);
2384 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2385 if (the_insn
.fpof1
== SGL
)
2387 result
.number_part
&= 0xF;
2388 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2390 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2393 /* Handle a floating point operand format at 26.
2394 Only allows single and double precision. */
2396 flag
= pa_parse_fp_format (&s
);
2402 the_insn
.fpof1
= flag
;
2408 as_bad ("Invalid Floating Point Operand Format.");
2418 /* Check if the args matched. */
2421 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2422 && !strcmp (insn
->name
, insn
[1].name
))
2430 as_bad ("Invalid operands %s", error_message
);
2437 the_insn
.opcode
= opcode
;
2440 /* Turn a string in input_line_pointer into a floating point constant of type
2441 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2442 emitted is stored in *sizeP . An error message or NULL is returned. */
2444 #define MAX_LITTLENUMS 6
2447 md_atof (type
, litP
, sizeP
)
2453 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2454 LITTLENUM_TYPE
*wordP
;
2486 return "Bad call to MD_ATOF()";
2488 t
= atof_ieee (input_line_pointer
, type
, words
);
2490 input_line_pointer
= t
;
2491 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2492 for (wordP
= words
; prec
--;)
2494 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2495 litP
+= sizeof (LITTLENUM_TYPE
);
2500 /* Write out big-endian. */
2503 md_number_to_chars (buf
, val
, n
)
2508 number_to_chars_bigendian (buf
, val
, n
);
2511 /* Translate internal representation of relocation info to BFD target
2515 tc_gen_reloc (section
, fixp
)
2520 struct hppa_fix_struct
*hppa_fixp
;
2521 bfd_reloc_code_real_type code
;
2522 static arelent
*no_relocs
= NULL
;
2524 bfd_reloc_code_real_type
**codes
;
2528 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2529 if (fixp
->fx_addsy
== 0)
2531 assert (hppa_fixp
!= 0);
2532 assert (section
!= 0);
2534 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2535 assert (reloc
!= 0);
2537 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2538 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2540 hppa_fixp
->fx_r_format
,
2541 hppa_fixp
->fx_r_field
);
2543 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2546 relocs
= (arelent
**)
2547 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2548 assert (relocs
!= 0);
2550 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2551 sizeof (arelent
) * n_relocs
);
2553 assert (reloc
!= 0);
2555 for (i
= 0; i
< n_relocs
; i
++)
2556 relocs
[i
] = &reloc
[i
];
2558 relocs
[n_relocs
] = NULL
;
2561 switch (fixp
->fx_r_type
)
2564 assert (n_relocs
== 1);
2568 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2569 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2570 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2571 reloc
->addend
= 0; /* default */
2573 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2575 /* Now, do any processing that is dependent on the relocation type. */
2578 case R_PARISC_DLTREL21L
:
2579 case R_PARISC_DLTREL14R
:
2580 case R_PARISC_DLTREL14F
:
2581 case R_PARISC_PLABEL32
:
2582 case R_PARISC_PLABEL21L
:
2583 case R_PARISC_PLABEL14R
:
2584 /* For plabel relocations, the addend of the
2585 relocation should be either 0 (no static link) or 2
2586 (static link required).
2588 FIXME: We always assume no static link!
2590 We also slam a zero addend into the DLT relative relocs;
2591 it doesn't make a lot of sense to use any addend since
2592 it gets you a different (eg unknown) DLT entry. */
2596 case R_PARISC_PCREL21L
:
2597 case R_PARISC_PCREL17R
:
2598 case R_PARISC_PCREL17F
:
2599 case R_PARISC_PCREL17C
:
2600 case R_PARISC_PCREL14R
:
2601 case R_PARISC_PCREL14F
:
2602 /* The constant is stored in the instruction. */
2603 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2606 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2609 reloc
->addend
= fixp
->fx_addnumber
;
2616 /* Walk over reach relocation returned by the BFD backend. */
2617 for (i
= 0; i
< n_relocs
; i
++)
2621 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2622 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2623 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2629 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2635 /* For plabel relocations, the addend of the
2636 relocation should be either 0 (no static link) or 2
2637 (static link required).
2639 FIXME: We always assume no static link!
2641 We also slam a zero addend into the DLT relative relocs;
2642 it doesn't make a lot of sense to use any addend since
2643 it gets you a different (eg unknown) DLT entry. */
2644 relocs
[i
]->addend
= 0;
2654 /* There is no symbol or addend associated with these fixups. */
2655 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2656 relocs
[i
]->addend
= 0;
2661 /* There is no symbol associated with these fixups. */
2662 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2663 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2667 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
)
2668 relocs
[i
]->addend
= 0;
2670 relocs
[i
]->addend
= fixp
->fx_addnumber
;
2679 /* Process any machine dependent frag types. */
2682 md_convert_frag (abfd
, sec
, fragP
)
2684 register asection
*sec
;
2685 register fragS
*fragP
;
2687 unsigned int address
;
2689 if (fragP
->fr_type
== rs_machine_dependent
)
2691 switch ((int) fragP
->fr_subtype
)
2694 fragP
->fr_type
= rs_fill
;
2695 know (fragP
->fr_var
== 1);
2696 know (fragP
->fr_next
);
2697 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2698 if (address
% fragP
->fr_offset
)
2701 fragP
->fr_next
->fr_address
2706 fragP
->fr_offset
= 0;
2712 /* Round up a section size to the appropriate boundary. */
2715 md_section_align (segment
, size
)
2719 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2720 int align2
= (1 << align
) - 1;
2722 return (size
+ align2
) & ~align2
;
2725 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2727 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2729 addressT from_addr
, to_addr
;
2733 fprintf (stderr
, "pa_create_short_jmp\n");
2737 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2739 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2741 addressT from_addr
, to_addr
;
2745 fprintf (stderr
, "pa_create_long_jump\n");
2749 /* Return the approximate size of a frag before relaxation has occurred. */
2751 md_estimate_size_before_relax (fragP
, segment
)
2752 register fragS
*fragP
;
2759 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2765 CONST
char *md_shortopts
= "";
2766 struct option md_longopts
[] = {
2767 {NULL
, no_argument
, NULL
, 0}
2769 size_t md_longopts_size
= sizeof(md_longopts
);
2772 md_parse_option (c
, arg
)
2780 md_show_usage (stream
)
2785 /* We have no need to default values of symbols. */
2788 md_undefined_symbol (name
)
2794 /* Parse an operand that is machine-specific.
2795 We just return without modifying the expression as we have nothing
2799 md_operand (expressionP
)
2800 expressionS
*expressionP
;
2804 /* Apply a fixup to an instruction. */
2807 md_apply_fix (fixP
, valp
)
2811 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2812 struct hppa_fix_struct
*hppa_fixP
;
2813 long new_val
, result
;
2814 unsigned int w1
, w2
, w
;
2817 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2818 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2819 never be "applied" (they are just markers). */
2821 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2822 || fixP
->fx_r_type
== R_HPPA_EXIT
)
2826 /* There should have been an HPPA specific fixup associated
2827 with the GAS fixup. */
2830 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2831 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2833 if (fixP
->fx_r_type
== R_HPPA_NONE
)
2836 /* Remember this value for emit_reloc. FIXME, is this braindamage
2837 documented anywhere!?! */
2838 fixP
->fx_addnumber
= val
;
2840 /* Check if this is an undefined symbol. No relocation can
2841 possibly be performed in this case.
2843 Also avoid doing anything for pc-relative fixups in which the
2844 fixup is in a different space than the symbol it references. */
2845 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
2847 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
)
2850 && S_GET_SEGMENT (fixP
->fx_addsy
) != hppa_fixP
->segment
)
2853 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2856 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
2857 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
2858 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
2859 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
2860 && hppa_fixP
->fx_r_field
!= R_HPPA_TSEL
2861 && hppa_fixP
->fx_r_field
!= R_HPPA_LTSEL
2862 && hppa_fixP
->fx_r_field
!= R_HPPA_RTSEL
2863 && !(fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
))
2864 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
2870 /* Handle all opcodes with the 'j' operand type. */
2872 CHECK_FIELD (new_val
, 8191, -8192, 0);
2874 /* Mask off 14 bits to be changed. */
2875 bfd_put_32 (stdoutput
,
2876 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2878 low_sign_unext (new_val
, 14, &result
);
2881 /* Handle all opcodes with the 'k' operand type. */
2883 CHECK_FIELD (new_val
, 2097152, 0, 0);
2885 /* Mask off 21 bits to be changed. */
2886 bfd_put_32 (stdoutput
,
2887 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
2889 dis_assemble_21 (new_val
, &result
);
2892 /* Handle all the opcodes with the 'i' operand type. */
2894 CHECK_FIELD (new_val
, 1023, -1023, 0);
2896 /* Mask off 11 bits to be changed. */
2897 bfd_put_32 (stdoutput
,
2898 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
2900 low_sign_unext (new_val
, 11, &result
);
2903 /* Handle all the opcodes with the 'w' operand type. */
2905 CHECK_FIELD (new_val
, 8191, -8192, 0)
2907 /* Mask off 11 bits to be changed. */
2908 sign_unext ((new_val
- 8) >> 2, 12, &result
);
2909 bfd_put_32 (stdoutput
,
2910 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
2913 dis_assemble_12 (result
, &w1
, &w
);
2914 result
= ((w1
<< 2) | w
);
2917 /* Handle some of the opcodes with the 'W' operand type. */
2920 #define stub_needed(CALLER, CALLEE) \
2921 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2922 /* It is necessary to force PC-relative calls/jumps to have a
2923 relocation entry if they're going to need either a argument
2924 relocation or long call stub. FIXME. Can't we need the same
2925 for absolute calls? */
2927 && (stub_needed (((obj_symbol_type
*)
2928 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2929 hppa_fixP
->fx_arg_reloc
)))
2933 CHECK_FIELD (new_val
, 262143, -262144, 0);
2935 /* Mask off 17 bits to be changed. */
2936 bfd_put_32 (stdoutput
,
2937 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
2939 sign_unext ((new_val
- 8) >> 2, 17, &result
);
2940 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2941 result
= ((w2
<< 2) | (w1
<< 16) | w
);
2946 fixP
->fx_addnumber
= fixP
->fx_offset
;
2947 /* If we have a real relocation, then we want zero to
2948 be stored in the object file. If no relocation is going
2949 to be emitted, then we need to store new_val into the
2952 bfd_put_32 (stdoutput
, 0, buf
);
2954 bfd_put_32 (stdoutput
, new_val
, buf
);
2962 as_bad ("Unknown relocation encountered in md_apply_fix.");
2966 /* Insert the relocation. */
2967 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
2972 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
2973 (unsigned int) fixP
, fixP
->fx_r_type
);
2978 /* Exactly what point is a PC-relative offset relative TO?
2979 On the PA, they're relative to the address of the offset. */
2982 md_pcrel_from (fixP
)
2985 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2988 /* Return nonzero if the input line pointer is at the end of
2992 is_end_of_statement ()
2994 return ((*input_line_pointer
== '\n')
2995 || (*input_line_pointer
== ';')
2996 || (*input_line_pointer
== '!'));
2999 /* Read a number from S. The number might come in one of many forms,
3000 the most common will be a hex or decimal constant, but it could be
3001 a pre-defined register (Yuk!), or an absolute symbol.
3003 Return a number or -1 for failure.
3005 When parsing PA-89 FP register numbers RESULT will be
3006 the address of a structure to return information about
3007 L/R half of FP registers, store results there as appropriate.
3009 pa_parse_number can not handle negative constants and will fail
3010 horribly if it is passed such a constant. */
3013 pa_parse_number (s
, result
)
3015 struct pa_89_fp_reg_struct
*result
;
3024 /* Skip whitespace before the number. */
3025 while (*p
== ' ' || *p
== '\t')
3028 /* Store info in RESULT if requested by caller. */
3031 result
->number_part
= -1;
3032 result
->l_r_select
= -1;
3038 /* Looks like a number. */
3041 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3043 /* The number is specified in hex. */
3045 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3046 || ((*p
>= 'A') && (*p
<= 'F')))
3049 num
= num
* 16 + *p
- '0';
3050 else if (*p
>= 'a' && *p
<= 'f')
3051 num
= num
* 16 + *p
- 'a' + 10;
3053 num
= num
* 16 + *p
- 'A' + 10;
3059 /* The number is specified in decimal. */
3060 while (isdigit (*p
))
3062 num
= num
* 10 + *p
- '0';
3067 /* Store info in RESULT if requested by the caller. */
3070 result
->number_part
= num
;
3072 if (IS_R_SELECT (p
))
3074 result
->l_r_select
= 1;
3077 else if (IS_L_SELECT (p
))
3079 result
->l_r_select
= 0;
3083 result
->l_r_select
= 0;
3088 /* The number might be a predefined register. */
3093 /* Tege hack: Special case for general registers as the general
3094 code makes a binary search with case translation, and is VERY
3099 if (*p
== 'e' && *(p
+ 1) == 't'
3100 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3103 num
= *p
- '0' + 28;
3111 else if (!isdigit (*p
))
3114 as_bad ("Undefined register: '%s'.", name
);
3120 num
= num
* 10 + *p
++ - '0';
3121 while (isdigit (*p
));
3126 /* Do a normal register search. */
3127 while (is_part_of_name (c
))
3133 status
= reg_name_search (name
);
3139 as_bad ("Undefined register: '%s'.", name
);
3145 /* Store info in RESULT if requested by caller. */
3148 result
->number_part
= num
;
3149 if (IS_R_SELECT (p
- 1))
3150 result
->l_r_select
= 1;
3151 else if (IS_L_SELECT (p
- 1))
3152 result
->l_r_select
= 0;
3154 result
->l_r_select
= 0;
3159 /* And finally, it could be a symbol in the absolute section which
3160 is effectively a constant. */
3164 while (is_part_of_name (c
))
3170 if ((sym
= symbol_find (name
)) != NULL
)
3172 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3173 num
= S_GET_VALUE (sym
);
3177 as_bad ("Non-absolute symbol: '%s'.", name
);
3183 /* There is where we'd come for an undefined symbol
3184 or for an empty string. For an empty string we
3185 will return zero. That's a concession made for
3186 compatability with the braindamaged HP assemblers. */
3192 as_bad ("Undefined absolute constant: '%s'.", name
);
3198 /* Store info in RESULT if requested by caller. */
3201 result
->number_part
= num
;
3202 if (IS_R_SELECT (p
- 1))
3203 result
->l_r_select
= 1;
3204 else if (IS_L_SELECT (p
- 1))
3205 result
->l_r_select
= 0;
3207 result
->l_r_select
= 0;
3215 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3217 /* Given NAME, find the register number associated with that name, return
3218 the integer value associated with the given name or -1 on failure. */
3221 reg_name_search (name
)
3224 int middle
, low
, high
;
3228 high
= REG_NAME_CNT
- 1;
3232 middle
= (low
+ high
) / 2;
3233 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3239 return pre_defined_registers
[middle
].value
;
3241 while (low
<= high
);
3247 /* Return nonzero if the given INSN and L/R information will require
3248 a new PA-89 opcode. */
3251 need_89_opcode (insn
, result
)
3253 struct pa_89_fp_reg_struct
*result
;
3255 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3261 /* Parse a condition for a fcmp instruction. Return the numerical
3262 code associated with the condition. */
3265 pa_parse_fp_cmp_cond (s
)
3272 for (i
= 0; i
< 32; i
++)
3274 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3275 strlen (fp_cond_map
[i
].string
)) == 0)
3277 cond
= fp_cond_map
[i
].cond
;
3278 *s
+= strlen (fp_cond_map
[i
].string
);
3279 /* If not a complete match, back up the input string and
3281 if (**s
!= ' ' && **s
!= '\t')
3283 *s
-= strlen (fp_cond_map
[i
].string
);
3286 while (**s
== ' ' || **s
== '\t')
3292 as_bad ("Invalid FP Compare Condition: %s", *s
);
3294 /* Advance over the bogus completer. */
3295 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3301 /* Parse an FP operand format completer returning the completer
3304 static fp_operand_format
3305 pa_parse_fp_format (s
)
3314 if (strncasecmp (*s
, "sgl", 3) == 0)
3319 else if (strncasecmp (*s
, "dbl", 3) == 0)
3324 else if (strncasecmp (*s
, "quad", 4) == 0)
3331 format
= ILLEGAL_FMT
;
3332 as_bad ("Invalid FP Operand Format: %3s", *s
);
3339 /* Convert from a selector string into a selector type. */
3342 pa_chk_field_selector (str
)
3345 int middle
, low
, high
;
3349 /* Read past any whitespace. */
3350 /* FIXME: should we read past newlines and formfeeds??? */
3351 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3354 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3355 name
[0] = tolower ((*str
)[0]),
3357 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3358 name
[0] = tolower ((*str
)[0]),
3359 name
[1] = tolower ((*str
)[1]),
3365 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3369 middle
= (low
+ high
) / 2;
3370 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3377 *str
+= strlen (name
) + 1;
3378 return selector_table
[middle
].field_selector
;
3381 while (low
<= high
);
3386 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3389 get_expression (str
)
3395 save_in
= input_line_pointer
;
3396 input_line_pointer
= str
;
3397 seg
= expression (&the_insn
.exp
);
3398 if (!(seg
== absolute_section
3399 || seg
== undefined_section
3400 || SEG_NORMAL (seg
)))
3402 as_warn ("Bad segment in expression.");
3403 expr_end
= input_line_pointer
;
3404 input_line_pointer
= save_in
;
3407 expr_end
= input_line_pointer
;
3408 input_line_pointer
= save_in
;
3412 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3414 pa_get_absolute_expression (insn
, strp
)
3420 insn
->field_selector
= pa_chk_field_selector (strp
);
3421 save_in
= input_line_pointer
;
3422 input_line_pointer
= *strp
;
3423 expression (&insn
->exp
);
3424 if (insn
->exp
.X_op
!= O_constant
)
3426 as_bad ("Bad segment (should be absolute).");
3427 expr_end
= input_line_pointer
;
3428 input_line_pointer
= save_in
;
3431 expr_end
= input_line_pointer
;
3432 input_line_pointer
= save_in
;
3433 return evaluate_absolute (insn
);
3436 /* Evaluate an absolute expression EXP which may be modified by
3437 the selector FIELD_SELECTOR. Return the value of the expression. */
3439 evaluate_absolute (insn
)
3444 int field_selector
= insn
->field_selector
;
3447 value
= exp
.X_add_number
;
3449 switch (field_selector
)
3455 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3457 if (value
& 0x00000400)
3459 value
= (value
& 0xfffff800) >> 11;
3462 /* Sign extend from bit 21. */
3464 if (value
& 0x00000400)
3465 value
|= 0xfffff800;
3470 /* Arithmetic shift right 11 bits. */
3472 value
= (value
& 0xfffff800) >> 11;
3475 /* Set bits 0-20 to zero. */
3477 value
= value
& 0x7ff;
3480 /* Add 0x800 and arithmetic shift right 11 bits. */
3483 value
= (value
& 0xfffff800) >> 11;
3486 /* Set bitgs 0-21 to one. */
3488 value
|= 0xfffff800;
3491 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3493 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3497 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3502 BAD_CASE (field_selector
);
3508 /* Given an argument location specification return the associated
3509 argument location number. */
3512 pa_build_arg_reloc (type_name
)
3516 if (strncasecmp (type_name
, "no", 2) == 0)
3518 if (strncasecmp (type_name
, "gr", 2) == 0)
3520 else if (strncasecmp (type_name
, "fr", 2) == 0)
3522 else if (strncasecmp (type_name
, "fu", 2) == 0)
3525 as_bad ("Invalid argument location: %s\n", type_name
);
3530 /* Encode and return an argument relocation specification for
3531 the given register in the location specified by arg_reloc. */
3534 pa_align_arg_reloc (reg
, arg_reloc
)
3536 unsigned int arg_reloc
;
3538 unsigned int new_reloc
;
3540 new_reloc
= arg_reloc
;
3556 as_bad ("Invalid argument description: %d", reg
);
3562 /* Parse a PA nullification completer (,n). Return nonzero if the
3563 completer was found; return zero if no completer was found. */
3575 if (strncasecmp (*s
, "n", 1) == 0)
3579 as_bad ("Invalid Nullification: (%c)", **s
);
3588 /* Parse a non-negated compare/subtract completer returning the
3589 number (for encoding in instrutions) of the given completer.
3591 ISBRANCH specifies whether or not this is parsing a condition
3592 completer for a branch (vs a nullification completer for a
3593 computational instruction. */
3596 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3601 char *name
= *s
+ 1;
3609 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3613 if (strcmp (name
, "=") == 0)
3617 else if (strcmp (name
, "<") == 0)
3621 else if (strcmp (name
, "<=") == 0)
3625 else if (strcmp (name
, "<<") == 0)
3629 else if (strcmp (name
, "<<=") == 0)
3633 else if (strcasecmp (name
, "sv") == 0)
3637 else if (strcasecmp (name
, "od") == 0)
3641 /* If we have something like addb,n then there is no condition
3643 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3654 /* Reset pointers if this was really a ,n for a branch instruction. */
3655 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3661 /* Parse a negated compare/subtract completer returning the
3662 number (for encoding in instrutions) of the given completer.
3664 ISBRANCH specifies whether or not this is parsing a condition
3665 completer for a branch (vs a nullification completer for a
3666 computational instruction. */
3669 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3674 char *name
= *s
+ 1;
3682 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3686 if (strcasecmp (name
, "tr") == 0)
3690 else if (strcmp (name
, "<>") == 0)
3694 else if (strcmp (name
, ">=") == 0)
3698 else if (strcmp (name
, ">") == 0)
3702 else if (strcmp (name
, ">>=") == 0)
3706 else if (strcmp (name
, ">>") == 0)
3710 else if (strcasecmp (name
, "nsv") == 0)
3714 else if (strcasecmp (name
, "ev") == 0)
3718 /* If we have something like addb,n then there is no condition
3720 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3731 /* Reset pointers if this was really a ,n for a branch instruction. */
3732 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3738 /* Parse a non-negated addition completer returning the number
3739 (for encoding in instrutions) of the given completer.
3741 ISBRANCH specifies whether or not this is parsing a condition
3742 completer for a branch (vs a nullification completer for a
3743 computational instruction. */
3746 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3751 char *name
= *s
+ 1;
3759 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3763 if (strcmp (name
, "=") == 0)
3767 else if (strcmp (name
, "<") == 0)
3771 else if (strcmp (name
, "<=") == 0)
3775 else if (strcasecmp (name
, "nuv") == 0)
3779 else if (strcasecmp (name
, "znv") == 0)
3783 else if (strcasecmp (name
, "sv") == 0)
3787 else if (strcasecmp (name
, "od") == 0)
3791 /* If we have something like addb,n then there is no condition
3793 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3804 /* Reset pointers if this was really a ,n for a branch instruction. */
3805 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3811 /* Parse a negated addition completer returning the number
3812 (for encoding in instrutions) of the given completer.
3814 ISBRANCH specifies whether or not this is parsing a condition
3815 completer for a branch (vs a nullification completer for a
3816 computational instruction. */
3819 pa_parse_neg_add_cmpltr (s
, isbranch
)
3824 char *name
= *s
+ 1;
3832 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3836 if (strcasecmp (name
, "tr") == 0)
3840 else if (strcmp (name
, "<>") == 0)
3844 else if (strcmp (name
, ">=") == 0)
3848 else if (strcmp (name
, ">") == 0)
3852 else if (strcasecmp (name
, "uv") == 0)
3856 else if (strcasecmp (name
, "vnz") == 0)
3860 else if (strcasecmp (name
, "nsv") == 0)
3864 else if (strcasecmp (name
, "ev") == 0)
3868 /* If we have something like addb,n then there is no condition
3870 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3881 /* Reset pointers if this was really a ,n for a branch instruction. */
3882 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3888 /* Handle a .BLOCK type pseudo-op. */
3896 unsigned int temp_size
;
3899 temp_size
= get_absolute_expression ();
3901 /* Always fill with zeros, that's what the HP assembler does. */
3904 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
3905 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
3906 bzero (p
, temp_size
);
3908 /* Convert 2 bytes at a time. */
3910 for (i
= 0; i
< temp_size
; i
+= 2)
3912 md_number_to_chars (p
+ i
,
3914 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
3917 pa_undefine_label ();
3918 demand_empty_rest_of_line ();
3921 /* Handle a .CALL pseudo-op. This involves storing away information
3922 about where arguments are to be found so the linker can detect
3923 (and correct) argument location mismatches between caller and callee. */
3929 pa_call_args (&last_call_desc
);
3930 demand_empty_rest_of_line ();
3933 /* Do the dirty work of building a call descriptor which describes
3934 where the caller placed arguments to a function call. */
3937 pa_call_args (call_desc
)
3938 struct call_desc
*call_desc
;
3941 unsigned int temp
, arg_reloc
;
3943 while (!is_end_of_statement ())
3945 name
= input_line_pointer
;
3946 c
= get_symbol_end ();
3947 /* Process a source argument. */
3948 if ((strncasecmp (name
, "argw", 4) == 0))
3950 temp
= atoi (name
+ 4);
3951 p
= input_line_pointer
;
3953 input_line_pointer
++;
3954 name
= input_line_pointer
;
3955 c
= get_symbol_end ();
3956 arg_reloc
= pa_build_arg_reloc (name
);
3957 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
3959 /* Process a return value. */
3960 else if ((strncasecmp (name
, "rtnval", 6) == 0))
3962 p
= input_line_pointer
;
3964 input_line_pointer
++;
3965 name
= input_line_pointer
;
3966 c
= get_symbol_end ();
3967 arg_reloc
= pa_build_arg_reloc (name
);
3968 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
3972 as_bad ("Invalid .CALL argument: %s", name
);
3974 p
= input_line_pointer
;
3976 if (!is_end_of_statement ())
3977 input_line_pointer
++;
3981 /* Return TRUE if FRAG1 and FRAG2 are the same. */
3984 is_same_frag (frag1
, frag2
)
3991 else if (frag2
== NULL
)
3993 else if (frag1
== frag2
)
3995 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
3996 return (is_same_frag (frag1
, frag2
->fr_next
));
4002 /* Build an entry in the UNWIND subspace from the given function
4003 attributes in CALL_INFO. This is not needed for SOM as using
4004 R_ENTRY and R_EXIT relocations allow the linker to handle building
4005 of the unwind spaces. */
4008 pa_build_unwind_subspace (call_info
)
4009 struct call_info
*call_info
;
4012 asection
*seg
, *save_seg
;
4013 subsegT subseg
, save_subseg
;
4017 /* Get into the right seg/subseg. This may involve creating
4018 the seg the first time through. Make sure to have the
4019 old seg/subseg so that we can reset things when we are done. */
4020 subseg
= SUBSEG_UNWIND
;
4021 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4022 if (seg
== ASEC_NULL
)
4024 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4025 bfd_set_section_flags (stdoutput
, seg
,
4026 SEC_READONLY
| SEC_HAS_CONTENTS
4027 | SEC_LOAD
| SEC_RELOC
);
4031 save_subseg
= now_subseg
;
4032 subseg_set (seg
, subseg
);
4035 /* Get some space to hold relocation information for the unwind
4039 /* Relocation info. for start offset of the function. */
4040 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4041 call_info
->start_symbol
, (offsetT
) 0,
4042 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4046 /* Relocation info. for end offset of the function. */
4047 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4048 call_info
->end_symbol
, (offsetT
) 0,
4049 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4052 unwind
= (char *) &call_info
->ci_unwind
;
4053 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4057 FRAG_APPEND_1_CHAR (c
);
4061 /* Return back to the original segment/subsegment. */
4062 subseg_set (save_seg
, save_subseg
);
4066 /* Process a .CALLINFO pseudo-op. This information is used later
4067 to build unwind descriptors and maybe one day to support
4068 .ENTER and .LEAVE. */
4071 pa_callinfo (unused
)
4077 /* .CALLINFO must appear within a procedure definition. */
4078 if (!within_procedure
)
4079 as_bad (".callinfo is not within a procedure definition");
4081 /* Mark the fact that we found the .CALLINFO for the
4082 current procedure. */
4083 callinfo_found
= TRUE
;
4085 /* Iterate over the .CALLINFO arguments. */
4086 while (!is_end_of_statement ())
4088 name
= input_line_pointer
;
4089 c
= get_symbol_end ();
4090 /* Frame size specification. */
4091 if ((strncasecmp (name
, "frame", 5) == 0))
4093 p
= input_line_pointer
;
4095 input_line_pointer
++;
4096 temp
= get_absolute_expression ();
4097 if ((temp
& 0x3) != 0)
4099 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4103 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4104 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4107 /* Entry register (GR, GR and SR) specifications. */
4108 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4110 p
= input_line_pointer
;
4112 input_line_pointer
++;
4113 temp
= get_absolute_expression ();
4114 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4115 even though %r19 is caller saved. I think this is a bug in
4116 the HP assembler, and we are not going to emulate it. */
4117 if (temp
< 3 || temp
> 18)
4118 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4119 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4121 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4123 p
= input_line_pointer
;
4125 input_line_pointer
++;
4126 temp
= get_absolute_expression ();
4127 /* Similarly the HP assembler takes 31 as the high bound even
4128 though %fr21 is the last callee saved floating point register. */
4129 if (temp
< 12 || temp
> 21)
4130 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4131 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4133 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4135 p
= input_line_pointer
;
4137 input_line_pointer
++;
4138 temp
= get_absolute_expression ();
4140 as_bad ("Value for ENTRY_SR must be 3\n");
4142 /* Note whether or not this function performs any calls. */
4143 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4144 (strncasecmp (name
, "caller", 6) == 0))
4146 p
= input_line_pointer
;
4149 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4151 p
= input_line_pointer
;
4154 /* Should RP be saved into the stack. */
4155 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4157 p
= input_line_pointer
;
4159 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4161 /* Likewise for SP. */
4162 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4164 p
= input_line_pointer
;
4166 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4168 /* Is this an unwindable procedure. If so mark it so
4169 in the unwind descriptor. */
4170 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4172 p
= input_line_pointer
;
4174 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4176 /* Is this an interrupt routine. If so mark it in the
4177 unwind descriptor. */
4178 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4180 p
= input_line_pointer
;
4182 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4184 /* Is this a millicode routine. "millicode" isn't in my
4185 assembler manual, but my copy is old. The HP assembler
4186 accepts it, and there's a place in the unwind descriptor
4187 to drop the information, so we'll accept it too. */
4188 else if ((strncasecmp (name
, "millicode", 9) == 0))
4190 p
= input_line_pointer
;
4192 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4196 as_bad ("Invalid .CALLINFO argument: %s", name
);
4197 *input_line_pointer
= c
;
4199 if (!is_end_of_statement ())
4200 input_line_pointer
++;
4203 demand_empty_rest_of_line ();
4206 /* Switch into the code subspace. */
4212 sd_chain_struct
*sdchain
;
4214 /* First time through it might be necessary to create the
4216 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4218 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4219 pa_def_spaces
[0].spnum
,
4220 pa_def_spaces
[0].loadable
,
4221 pa_def_spaces
[0].defined
,
4222 pa_def_spaces
[0].private,
4223 pa_def_spaces
[0].sort
,
4224 pa_def_spaces
[0].segment
, 0);
4227 SPACE_DEFINED (sdchain
) = 1;
4228 subseg_set (text_section
, SUBSEG_CODE
);
4229 demand_empty_rest_of_line ();
4232 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4233 the .comm pseudo-op has the following symtax:
4235 <label> .comm <length>
4237 where <label> is optional and is a symbol whose address will be the start of
4238 a block of memory <length> bytes long. <length> must be an absolute
4239 expression. <length> bytes will be allocated in the current space
4248 label_symbol_struct
*label_symbol
= pa_get_label ();
4251 symbol
= label_symbol
->lss_label
;
4256 size
= get_absolute_expression ();
4260 /* It is incorrect to check S_IS_DEFINED at this point as
4261 the symbol will *always* be defined. FIXME. How to
4262 correctly determine when this label really as been
4264 if (S_GET_VALUE (symbol
))
4266 if (S_GET_VALUE (symbol
) != size
)
4268 as_warn ("Length of .comm \"%s\" is already %ld. Not changed.",
4269 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4275 S_SET_VALUE (symbol
, size
);
4276 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4277 S_SET_EXTERNAL (symbol
);
4279 /* colon() has already set the frag to the current location in the
4280 $BSS$ subspace; we need to reset the fragment to the zero address
4282 symbol
->sy_frag
= &zero_address_frag
;
4285 demand_empty_rest_of_line ();
4288 /* Process a .END pseudo-op. */
4294 demand_empty_rest_of_line ();
4297 /* Process a .ENTER pseudo-op. This is not supported. */
4305 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4311 if (!within_procedure
)
4312 as_bad ("Misplaced .entry. Ignored.");
4315 if (!callinfo_found
)
4316 as_bad ("Missing .callinfo.");
4318 demand_empty_rest_of_line ();
4319 within_entry_exit
= TRUE
;
4322 /* SOM defers building of unwind descriptors until the link phase.
4323 The assembler is responsible for creating an R_ENTRY relocation
4324 to mark the beginning of a region and hold the unwind bits, and
4325 for creating an R_EXIT relocation to mark the end of the region.
4327 FIXME. ELF should be using the same conventions! The problem
4328 is an unwind requires too much relocation space. Hmmm. Maybe
4329 if we split the unwind bits up between the relocations which
4330 denote the entry and exit points. */
4331 if (last_call_info
->start_symbol
!= NULL
)
4333 char *where
= frag_more (0);
4335 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4336 NULL
, (offsetT
) 0, NULL
,
4337 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4338 (int *) &last_call_info
->ci_unwind
.descriptor
);
4343 /* Handle a .EQU pseudo-op. */
4349 label_symbol_struct
*label_symbol
= pa_get_label ();
4354 symbol
= label_symbol
->lss_label
;
4356 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4358 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4359 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4364 as_bad (".REG must use a label");
4366 as_bad (".EQU must use a label");
4369 pa_undefine_label ();
4370 demand_empty_rest_of_line ();
4373 /* Helper function. Does processing for the end of a function. This
4374 usually involves creating some relocations or building special
4375 symbols to mark the end of the function. */
4382 where
= frag_more (0);
4385 /* Mark the end of the function, stuff away the location of the frag
4386 for the end of the function, and finally call pa_build_unwind_subspace
4387 to add an entry in the unwind table. */
4388 hppa_elf_mark_end_of_function ();
4389 pa_build_unwind_subspace (last_call_info
);
4391 /* SOM defers building of unwind descriptors until the link phase.
4392 The assembler is responsible for creating an R_ENTRY relocation
4393 to mark the beginning of a region and hold the unwind bits, and
4394 for creating an R_EXIT relocation to mark the end of the region.
4396 FIXME. ELF should be using the same conventions! The problem
4397 is an unwind requires too much relocation space. Hmmm. Maybe
4398 if we split the unwind bits up between the relocations which
4399 denote the entry and exit points. */
4400 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4402 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4403 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4407 /* Process a .EXIT pseudo-op. */
4413 if (!within_procedure
)
4414 as_bad (".EXIT must appear within a procedure");
4417 if (!callinfo_found
)
4418 as_bad ("Missing .callinfo");
4421 if (!within_entry_exit
)
4422 as_bad ("No .ENTRY for this .EXIT");
4425 within_entry_exit
= FALSE
;
4430 demand_empty_rest_of_line ();
4433 /* Process a .EXPORT directive. This makes functions external
4434 and provides information such as argument relocation entries
4444 name
= input_line_pointer
;
4445 c
= get_symbol_end ();
4446 /* Make sure the given symbol exists. */
4447 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4449 as_bad ("Cannot define export symbol: %s\n", name
);
4450 p
= input_line_pointer
;
4452 input_line_pointer
++;
4456 /* OK. Set the external bits and process argument relocations. */
4457 S_SET_EXTERNAL (symbol
);
4458 p
= input_line_pointer
;
4460 if (!is_end_of_statement ())
4462 input_line_pointer
++;
4463 pa_type_args (symbol
, 1);
4467 demand_empty_rest_of_line ();
4470 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4473 pa_type_args (symbolP
, is_export
)
4478 unsigned int temp
, arg_reloc
;
4479 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4480 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4482 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4485 input_line_pointer
+= 8;
4486 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4487 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4488 type
= SYMBOL_TYPE_ABSOLUTE
;
4490 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4492 input_line_pointer
+= 4;
4493 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4494 instead one should be IMPORTing/EXPORTing ENTRY types.
4496 Complain if one tries to EXPORT a CODE type since that's never
4497 done. Both GCC and HP C still try to IMPORT CODE types, so
4498 silently fix them to be ENTRY types. */
4499 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4502 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4504 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4505 type
= SYMBOL_TYPE_ENTRY
;
4509 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4510 type
= SYMBOL_TYPE_CODE
;
4513 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4515 input_line_pointer
+= 4;
4516 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4517 type
= SYMBOL_TYPE_DATA
;
4519 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4521 input_line_pointer
+= 5;
4522 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4523 type
= SYMBOL_TYPE_ENTRY
;
4525 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4527 input_line_pointer
+= 9;
4528 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4529 type
= SYMBOL_TYPE_MILLICODE
;
4531 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4533 input_line_pointer
+= 6;
4534 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4535 type
= SYMBOL_TYPE_PLABEL
;
4537 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4539 input_line_pointer
+= 8;
4540 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4541 type
= SYMBOL_TYPE_PRI_PROG
;
4543 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4545 input_line_pointer
+= 8;
4546 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4547 type
= SYMBOL_TYPE_SEC_PROG
;
4550 /* SOM requires much more information about symbol types
4551 than BFD understands. This is how we get this information
4552 to the SOM BFD backend. */
4553 #ifdef obj_set_symbol_type
4554 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4557 /* Now that the type of the exported symbol has been handled,
4558 handle any argument relocation information. */
4559 while (!is_end_of_statement ())
4561 if (*input_line_pointer
== ',')
4562 input_line_pointer
++;
4563 name
= input_line_pointer
;
4564 c
= get_symbol_end ();
4565 /* Argument sources. */
4566 if ((strncasecmp (name
, "argw", 4) == 0))
4568 p
= input_line_pointer
;
4570 input_line_pointer
++;
4571 temp
= atoi (name
+ 4);
4572 name
= input_line_pointer
;
4573 c
= get_symbol_end ();
4574 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4575 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4576 *input_line_pointer
= c
;
4578 /* The return value. */
4579 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4581 p
= input_line_pointer
;
4583 input_line_pointer
++;
4584 name
= input_line_pointer
;
4585 c
= get_symbol_end ();
4586 arg_reloc
= pa_build_arg_reloc (name
);
4587 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4588 *input_line_pointer
= c
;
4590 /* Privelege level. */
4591 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4593 p
= input_line_pointer
;
4595 input_line_pointer
++;
4596 temp
= atoi (input_line_pointer
);
4597 c
= get_symbol_end ();
4598 *input_line_pointer
= c
;
4602 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4603 p
= input_line_pointer
;
4606 if (!is_end_of_statement ())
4607 input_line_pointer
++;
4611 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4612 assembly file must either be defined in the assembly file, or
4613 explicitly IMPORTED from another. */
4622 name
= input_line_pointer
;
4623 c
= get_symbol_end ();
4625 symbol
= symbol_find (name
);
4626 /* Ugh. We might be importing a symbol defined earlier in the file,
4627 in which case all the code below will really screw things up
4628 (set the wrong segment, symbol flags & type, etc). */
4629 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4631 symbol
= symbol_find_or_make (name
);
4632 p
= input_line_pointer
;
4635 if (!is_end_of_statement ())
4637 input_line_pointer
++;
4638 pa_type_args (symbol
, 0);
4642 /* Sigh. To be compatable with the HP assembler and to help
4643 poorly written assembly code, we assign a type based on
4644 the the current segment. Note only BSF_FUNCTION really
4645 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4646 if (now_seg
== text_section
)
4647 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4649 /* If the section is undefined, then the symbol is undefined
4650 Since this is an import, leave the section undefined. */
4651 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4656 /* The symbol was already defined. Just eat everything up to
4657 the end of the current statement. */
4658 while (!is_end_of_statement ())
4659 input_line_pointer
++;
4662 demand_empty_rest_of_line ();
4665 /* Handle a .LABEL pseudo-op. */
4673 name
= input_line_pointer
;
4674 c
= get_symbol_end ();
4676 if (strlen (name
) > 0)
4679 p
= input_line_pointer
;
4684 as_warn ("Missing label name on .LABEL");
4687 if (!is_end_of_statement ())
4689 as_warn ("extra .LABEL arguments ignored.");
4690 ignore_rest_of_line ();
4692 demand_empty_rest_of_line ();
4695 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4704 /* Handle a .ORIGIN pseudo-op. */
4711 pa_undefine_label ();
4714 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4715 is for static functions. FIXME. Should share more code with .EXPORT. */
4724 name
= input_line_pointer
;
4725 c
= get_symbol_end ();
4727 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4729 as_bad ("Cannot define static symbol: %s\n", name
);
4730 p
= input_line_pointer
;
4732 input_line_pointer
++;
4736 S_CLEAR_EXTERNAL (symbol
);
4737 p
= input_line_pointer
;
4739 if (!is_end_of_statement ())
4741 input_line_pointer
++;
4742 pa_type_args (symbol
, 0);
4746 demand_empty_rest_of_line ();
4749 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4750 of a procedure from a syntatical point of view. */
4756 struct call_info
*call_info
;
4757 if (within_procedure
)
4758 as_fatal ("Nested procedures");
4760 /* Reset global variables for new procedure. */
4761 callinfo_found
= FALSE
;
4762 within_procedure
= TRUE
;
4765 Enabling
this code creates severe problems with GDB
. It appears as
if
4766 inserting linker stubs between functions within a single
.o makes GDB
4769 /* Create a new CODE subspace for each procedure if we are not
4770 using space/subspace aliases. */
4771 if (!USE_ALIASES
&& call_info_root
!= NULL
)
4775 /* Force creation of a new $CODE$ subspace; inherit attributes from
4776 the first $CODE$ subspace. */
4777 seg
= subseg_force_new ("$CODE$", 0);
4779 /* Now set the flags. */
4780 bfd_set_section_flags (stdoutput
, seg
,
4781 bfd_get_section_flags (abfd
, text_section
));
4783 /* Record any alignment request for this section. */
4784 record_alignment (seg
,
4785 bfd_get_section_alignment (stdoutput
, text_section
));
4787 /* Change the "text_section" to be our new $CODE$ subspace. */
4789 subseg_set (text_section
, 0);
4791 #ifdef obj_set_subsection_attributes
4792 /* Need a way to inherit the the access bits, sort key and quadrant
4793 from the first $CODE$ subspace. FIXME. */
4794 obj_set_subsection_attributes (seg
, current_space
->sd_seg
, 0x2c, 24, 0);
4799 /* Create another call_info structure. */
4800 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4803 as_fatal ("Cannot allocate unwind descriptor\n");
4805 bzero (call_info
, sizeof (struct call_info
));
4807 call_info
->ci_next
= NULL
;
4809 if (call_info_root
== NULL
)
4811 call_info_root
= call_info
;
4812 last_call_info
= call_info
;
4816 last_call_info
->ci_next
= call_info
;
4817 last_call_info
= call_info
;
4820 /* set up defaults on call_info structure */
4822 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4823 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4824 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4826 /* If we got a .PROC pseudo-op, we know that the function is defined
4827 locally. Make sure it gets into the symbol table. */
4829 label_symbol_struct
*label_symbol
= pa_get_label ();
4833 if (label_symbol
->lss_label
)
4835 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4836 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4840 /* The label was defined in a different segment. Fix that
4841 along with the value and associated fragment. */
4842 S_SET_SEGMENT (last_call_info
->start_symbol
, now_seg
);
4843 S_SET_VALUE (last_call_info
->start_symbol
,
4844 ((char*)obstack_next_free (&frags
)
4845 - frag_now
->fr_literal
));
4846 last_call_info
->start_symbol
->sy_frag
= frag_now
;
4851 as_bad ("Missing function name for .PROC (corrupted label chain)");
4854 last_call_info
->start_symbol
= NULL
;
4857 demand_empty_rest_of_line ();
4860 /* Process the syntatical end of a procedure. Make sure all the
4861 appropriate pseudo-ops were found within the procedure. */
4868 /* If we are within a procedure definition, make sure we've
4869 defined a label for the procedure; handle case where the
4870 label was defined after the .PROC directive.
4872 Note there's not need to diddle with the segment or fragment
4873 for the label symbol in this case. We have already switched
4874 into the new $CODE$ subspace at this point. */
4875 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
4877 label_symbol_struct
*label_symbol
= pa_get_label ();
4881 if (label_symbol
->lss_label
)
4883 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4884 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
4886 /* Also handle allocation of a fixup to hold the unwind
4887 information when the label appears after the proc/procend. */
4888 if (within_entry_exit
)
4890 char *where
= frag_more (0);
4892 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4893 NULL
, (offsetT
) 0, NULL
,
4894 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4895 (int *) &last_call_info
->ci_unwind
.descriptor
);
4900 as_bad ("Missing function name for .PROC (corrupted label chain)");
4903 as_bad ("Missing function name for .PROC");
4906 if (!within_procedure
)
4907 as_bad ("misplaced .procend");
4909 if (!callinfo_found
)
4910 as_bad ("Missing .callinfo for this procedure");
4912 if (within_entry_exit
)
4913 as_bad ("Missing .EXIT for a .ENTRY");
4916 /* ELF needs to mark the end of each function so that it can compute
4917 the size of the function (apparently its needed in the symbol table. */
4918 hppa_elf_mark_end_of_function ();
4921 within_procedure
= FALSE
;
4922 demand_empty_rest_of_line ();
4923 pa_undefine_label ();
4926 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
4927 then create a new space entry to hold the information specified
4928 by the parameters to the .SPACE directive. */
4930 static sd_chain_struct
*
4931 pa_parse_space_stmt (space_name
, create_flag
)
4935 char *name
, *ptemp
, c
;
4936 char loadable
, defined
, private, sort
;
4938 asection
*seg
= NULL
;
4939 sd_chain_struct
*space
;
4941 /* load default values */
4947 if (strcmp (space_name
, "$TEXT$") == 0)
4949 seg
= pa_def_spaces
[0].segment
;
4950 defined
= pa_def_spaces
[0].defined
;
4951 private = pa_def_spaces
[0].private;
4952 sort
= pa_def_spaces
[0].sort
;
4953 spnum
= pa_def_spaces
[0].spnum
;
4955 else if (strcmp (space_name
, "$PRIVATE$") == 0)
4957 seg
= pa_def_spaces
[1].segment
;
4958 defined
= pa_def_spaces
[1].defined
;
4959 private = pa_def_spaces
[1].private;
4960 sort
= pa_def_spaces
[1].sort
;
4961 spnum
= pa_def_spaces
[1].spnum
;
4964 if (!is_end_of_statement ())
4966 print_errors
= FALSE
;
4967 ptemp
= input_line_pointer
+ 1;
4968 /* First see if the space was specified as a number rather than
4969 as a name. According to the PA assembly manual the rest of
4970 the line should be ignored. */
4971 temp
= pa_parse_number (&ptemp
, 0);
4975 input_line_pointer
= ptemp
;
4979 while (!is_end_of_statement ())
4981 input_line_pointer
++;
4982 name
= input_line_pointer
;
4983 c
= get_symbol_end ();
4984 if ((strncasecmp (name
, "spnum", 5) == 0))
4986 *input_line_pointer
= c
;
4987 input_line_pointer
++;
4988 spnum
= get_absolute_expression ();
4990 else if ((strncasecmp (name
, "sort", 4) == 0))
4992 *input_line_pointer
= c
;
4993 input_line_pointer
++;
4994 sort
= get_absolute_expression ();
4996 else if ((strncasecmp (name
, "unloadable", 10) == 0))
4998 *input_line_pointer
= c
;
5001 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5003 *input_line_pointer
= c
;
5006 else if ((strncasecmp (name
, "private", 7) == 0))
5008 *input_line_pointer
= c
;
5013 as_bad ("Invalid .SPACE argument");
5014 *input_line_pointer
= c
;
5015 if (!is_end_of_statement ())
5016 input_line_pointer
++;
5020 print_errors
= TRUE
;
5023 if (create_flag
&& seg
== NULL
)
5024 seg
= subseg_new (space_name
, 0);
5026 /* If create_flag is nonzero, then create the new space with
5027 the attributes computed above. Else set the values in
5028 an already existing space -- this can only happen for
5029 the first occurence of a built-in space. */
5031 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5032 private, sort
, seg
, 1);
5035 space
= is_defined_space (space_name
);
5036 SPACE_SPNUM (space
) = spnum
;
5037 SPACE_DEFINED (space
) = defined
& 1;
5038 SPACE_USER_DEFINED (space
) = 1;
5041 #ifdef obj_set_section_attributes
5042 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5048 /* Handle a .SPACE pseudo-op; this switches the current space to the
5049 given space, creating the new space if necessary. */
5055 char *name
, c
, *space_name
, *save_s
;
5057 sd_chain_struct
*sd_chain
;
5059 if (within_procedure
)
5061 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5062 ignore_rest_of_line ();
5066 /* Check for some of the predefined spaces. FIXME: most of the code
5067 below is repeated several times, can we extract the common parts
5068 and place them into a subroutine or something similar? */
5069 /* FIXME Is this (and the next IF stmt) really right?
5070 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5071 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5073 input_line_pointer
+= 6;
5074 sd_chain
= is_defined_space ("$TEXT$");
5075 if (sd_chain
== NULL
)
5076 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5077 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5078 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5080 current_space
= sd_chain
;
5081 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5083 = pa_subsegment_to_subspace (text_section
,
5084 sd_chain
->sd_last_subseg
);
5085 demand_empty_rest_of_line ();
5088 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5090 input_line_pointer
+= 9;
5091 sd_chain
= is_defined_space ("$PRIVATE$");
5092 if (sd_chain
== NULL
)
5093 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5094 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5095 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5097 current_space
= sd_chain
;
5098 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5100 = pa_subsegment_to_subspace (data_section
,
5101 sd_chain
->sd_last_subseg
);
5102 demand_empty_rest_of_line ();
5105 if (!strncasecmp (input_line_pointer
,
5106 GDB_DEBUG_SPACE_NAME
,
5107 strlen (GDB_DEBUG_SPACE_NAME
)))
5109 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5110 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5111 if (sd_chain
== NULL
)
5112 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5113 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5114 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5116 current_space
= sd_chain
;
5119 asection
*gdb_section
5120 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5122 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5124 = pa_subsegment_to_subspace (gdb_section
,
5125 sd_chain
->sd_last_subseg
);
5127 demand_empty_rest_of_line ();
5131 /* It could be a space specified by number. */
5133 save_s
= input_line_pointer
;
5134 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5136 if ((sd_chain
= pa_find_space_by_number (temp
)))
5138 current_space
= sd_chain
;
5140 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5142 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5143 sd_chain
->sd_last_subseg
);
5144 demand_empty_rest_of_line ();
5149 /* Not a number, attempt to create a new space. */
5151 input_line_pointer
= save_s
;
5152 name
= input_line_pointer
;
5153 c
= get_symbol_end ();
5154 space_name
= xmalloc (strlen (name
) + 1);
5155 strcpy (space_name
, name
);
5156 *input_line_pointer
= c
;
5158 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5159 current_space
= sd_chain
;
5161 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5162 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5163 sd_chain
->sd_last_subseg
);
5164 demand_empty_rest_of_line ();
5168 /* Switch to a new space. (I think). FIXME. */
5177 sd_chain_struct
*space
;
5179 name
= input_line_pointer
;
5180 c
= get_symbol_end ();
5181 space
= is_defined_space (name
);
5185 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5188 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5190 *input_line_pointer
= c
;
5191 demand_empty_rest_of_line ();
5194 /* If VALUE is an exact power of two between zero and 2^31, then
5195 return log2 (VALUE). Else return -1. */
5203 while ((1 << shift
) != value
&& shift
< 32)
5212 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5213 given subspace, creating the new subspace if necessary.
5215 FIXME. Should mirror pa_space more closely, in particular how
5216 they're broken up into subroutines. */
5219 pa_subspace (unused
)
5222 char *name
, *ss_name
, *alias
, c
;
5223 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5224 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5225 sd_chain_struct
*space
;
5226 ssd_chain_struct
*ssd
;
5229 if (within_procedure
)
5231 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5232 ignore_rest_of_line ();
5236 name
= input_line_pointer
;
5237 c
= get_symbol_end ();
5238 ss_name
= xmalloc (strlen (name
) + 1);
5239 strcpy (ss_name
, name
);
5240 *input_line_pointer
= c
;
5242 /* Load default values. */
5255 space
= current_space
;
5256 ssd
= is_defined_subspace (ss_name
);
5257 /* Allow user to override the builtin attributes of subspaces. But
5258 only allow the attributes to be changed once! */
5259 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5261 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5262 if (!is_end_of_statement ())
5263 as_warn ("Parameters of an existing subspace can\'t be modified");
5264 demand_empty_rest_of_line ();
5269 /* A new subspace. Load default values if it matches one of
5270 the builtin subspaces. */
5272 while (pa_def_subspaces
[i
].name
)
5274 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5276 loadable
= pa_def_subspaces
[i
].loadable
;
5277 common
= pa_def_subspaces
[i
].common
;
5278 dup_common
= pa_def_subspaces
[i
].dup_common
;
5279 code_only
= pa_def_subspaces
[i
].code_only
;
5280 zero
= pa_def_subspaces
[i
].zero
;
5281 space_index
= pa_def_subspaces
[i
].space_index
;
5282 alignment
= pa_def_subspaces
[i
].alignment
;
5283 quadrant
= pa_def_subspaces
[i
].quadrant
;
5284 access
= pa_def_subspaces
[i
].access
;
5285 sort
= pa_def_subspaces
[i
].sort
;
5286 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5287 alias
= pa_def_subspaces
[i
].alias
;
5294 /* We should be working with a new subspace now. Fill in
5295 any information as specified by the user. */
5296 if (!is_end_of_statement ())
5298 input_line_pointer
++;
5299 while (!is_end_of_statement ())
5301 name
= input_line_pointer
;
5302 c
= get_symbol_end ();
5303 if ((strncasecmp (name
, "quad", 4) == 0))
5305 *input_line_pointer
= c
;
5306 input_line_pointer
++;
5307 quadrant
= get_absolute_expression ();
5309 else if ((strncasecmp (name
, "align", 5) == 0))
5311 *input_line_pointer
= c
;
5312 input_line_pointer
++;
5313 alignment
= get_absolute_expression ();
5314 if (log2 (alignment
) == -1)
5316 as_bad ("Alignment must be a power of 2");
5320 else if ((strncasecmp (name
, "access", 6) == 0))
5322 *input_line_pointer
= c
;
5323 input_line_pointer
++;
5324 access
= get_absolute_expression ();
5326 else if ((strncasecmp (name
, "sort", 4) == 0))
5328 *input_line_pointer
= c
;
5329 input_line_pointer
++;
5330 sort
= get_absolute_expression ();
5332 else if ((strncasecmp (name
, "code_only", 9) == 0))
5334 *input_line_pointer
= c
;
5337 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5339 *input_line_pointer
= c
;
5342 else if ((strncasecmp (name
, "common", 6) == 0))
5344 *input_line_pointer
= c
;
5347 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5349 *input_line_pointer
= c
;
5352 else if ((strncasecmp (name
, "zero", 4) == 0))
5354 *input_line_pointer
= c
;
5357 else if ((strncasecmp (name
, "first", 5) == 0))
5358 as_bad ("FIRST not supported as a .SUBSPACE argument");
5360 as_bad ("Invalid .SUBSPACE argument");
5361 if (!is_end_of_statement ())
5362 input_line_pointer
++;
5366 /* Compute a reasonable set of BFD flags based on the information
5367 in the .subspace directive. */
5368 applicable
= bfd_applicable_section_flags (stdoutput
);
5371 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5374 if (common
|| dup_common
)
5375 flags
|= SEC_IS_COMMON
;
5377 /* This is a zero-filled subspace (eg BSS). */
5381 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5382 applicable
&= flags
;
5384 /* If this is an existing subspace, then we want to use the
5385 segment already associated with the subspace.
5387 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5388 lots of sections. It might be a problem in the PA ELF
5389 code, I do not know yet. For now avoid creating anything
5390 but the "standard" sections for ELF. */
5392 section
= ssd
->ssd_seg
;
5394 section
= subseg_new (alias
, 0);
5395 else if (!alias
&& USE_ALIASES
)
5397 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5398 demand_empty_rest_of_line ();
5402 section
= subseg_new (ss_name
, 0);
5404 /* Now set the flags. */
5405 bfd_set_section_flags (stdoutput
, section
, applicable
);
5407 /* Record any alignment request for this section. */
5408 record_alignment (section
, log2 (alignment
));
5410 /* Set the starting offset for this section. */
5411 bfd_set_section_vma (stdoutput
, section
,
5412 pa_subspace_start (space
, quadrant
));
5414 /* Now that all the flags are set, update an existing subspace,
5415 or create a new one. */
5418 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5419 code_only
, common
, dup_common
,
5420 sort
, zero
, access
, space_index
,
5421 alignment
, quadrant
,
5424 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5426 dup_common
, zero
, sort
,
5427 access
, space_index
,
5428 alignment
, quadrant
, section
);
5430 demand_empty_rest_of_line ();
5431 current_subspace
->ssd_seg
= section
;
5432 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5434 SUBSPACE_DEFINED (current_subspace
) = 1;
5438 /* Create default space and subspace dictionaries. */
5445 space_dict_root
= NULL
;
5446 space_dict_last
= NULL
;
5449 while (pa_def_spaces
[i
].name
)
5453 /* Pick the right name to use for the new section. */
5454 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5455 name
= pa_def_spaces
[i
].alias
;
5457 name
= pa_def_spaces
[i
].name
;
5459 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5460 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5461 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5462 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5463 pa_def_spaces
[i
].segment
, 0);
5468 while (pa_def_subspaces
[i
].name
)
5471 int applicable
, subsegment
;
5472 asection
*segment
= NULL
;
5473 sd_chain_struct
*space
;
5475 /* Pick the right name for the new section and pick the right
5476 subsegment number. */
5477 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5479 name
= pa_def_subspaces
[i
].alias
;
5480 subsegment
= pa_def_subspaces
[i
].subsegment
;
5484 name
= pa_def_subspaces
[i
].name
;
5488 /* Create the new section. */
5489 segment
= subseg_new (name
, subsegment
);
5492 /* For SOM we want to replace the standard .text, .data, and .bss
5493 sections with our own. We also want to set BFD flags for
5494 all the built-in subspaces. */
5495 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5497 text_section
= segment
;
5498 applicable
= bfd_applicable_section_flags (stdoutput
);
5499 bfd_set_section_flags (stdoutput
, segment
,
5500 applicable
& (SEC_ALLOC
| SEC_LOAD
5501 | SEC_RELOC
| SEC_CODE
5503 | SEC_HAS_CONTENTS
));
5505 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5507 data_section
= segment
;
5508 applicable
= bfd_applicable_section_flags (stdoutput
);
5509 bfd_set_section_flags (stdoutput
, segment
,
5510 applicable
& (SEC_ALLOC
| SEC_LOAD
5512 | SEC_HAS_CONTENTS
));
5516 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5518 bss_section
= segment
;
5519 applicable
= bfd_applicable_section_flags (stdoutput
);
5520 bfd_set_section_flags (stdoutput
, segment
,
5521 applicable
& SEC_ALLOC
);
5523 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5525 applicable
= bfd_applicable_section_flags (stdoutput
);
5526 bfd_set_section_flags (stdoutput
, segment
,
5527 applicable
& (SEC_ALLOC
| SEC_LOAD
5530 | SEC_HAS_CONTENTS
));
5532 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5534 applicable
= bfd_applicable_section_flags (stdoutput
);
5535 bfd_set_section_flags (stdoutput
, segment
,
5536 applicable
& (SEC_ALLOC
| SEC_LOAD
5539 | SEC_HAS_CONTENTS
));
5542 /* Find the space associated with this subspace. */
5543 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5544 def_space_index
].segment
);
5547 as_fatal ("Internal error: Unable to find containing space for %s.",
5548 pa_def_subspaces
[i
].name
);
5551 create_new_subspace (space
, name
,
5552 pa_def_subspaces
[i
].loadable
,
5553 pa_def_subspaces
[i
].code_only
,
5554 pa_def_subspaces
[i
].common
,
5555 pa_def_subspaces
[i
].dup_common
,
5556 pa_def_subspaces
[i
].zero
,
5557 pa_def_subspaces
[i
].sort
,
5558 pa_def_subspaces
[i
].access
,
5559 pa_def_subspaces
[i
].space_index
,
5560 pa_def_subspaces
[i
].alignment
,
5561 pa_def_subspaces
[i
].quadrant
,
5569 /* Create a new space NAME, with the appropriate flags as defined
5570 by the given parameters. */
5572 static sd_chain_struct
*
5573 create_new_space (name
, spnum
, loadable
, defined
, private,
5574 sort
, seg
, user_defined
)
5584 sd_chain_struct
*chain_entry
;
5586 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5588 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5591 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5592 strcpy (SPACE_NAME (chain_entry
), name
);
5593 SPACE_DEFINED (chain_entry
) = defined
;
5594 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5595 SPACE_SPNUM (chain_entry
) = spnum
;
5597 chain_entry
->sd_seg
= seg
;
5598 chain_entry
->sd_last_subseg
= -1;
5599 chain_entry
->sd_subspaces
= NULL
;
5600 chain_entry
->sd_next
= NULL
;
5602 /* Find spot for the new space based on its sort key. */
5603 if (!space_dict_last
)
5604 space_dict_last
= chain_entry
;
5606 if (space_dict_root
== NULL
)
5607 space_dict_root
= chain_entry
;
5610 sd_chain_struct
*chain_pointer
;
5611 sd_chain_struct
*prev_chain_pointer
;
5613 chain_pointer
= space_dict_root
;
5614 prev_chain_pointer
= NULL
;
5616 while (chain_pointer
)
5618 prev_chain_pointer
= chain_pointer
;
5619 chain_pointer
= chain_pointer
->sd_next
;
5622 /* At this point we've found the correct place to add the new
5623 entry. So add it and update the linked lists as appropriate. */
5624 if (prev_chain_pointer
)
5626 chain_entry
->sd_next
= chain_pointer
;
5627 prev_chain_pointer
->sd_next
= chain_entry
;
5631 space_dict_root
= chain_entry
;
5632 chain_entry
->sd_next
= chain_pointer
;
5635 if (chain_entry
->sd_next
== NULL
)
5636 space_dict_last
= chain_entry
;
5639 /* This is here to catch predefined spaces which do not get
5640 modified by the user's input. Another call is found at
5641 the bottom of pa_parse_space_stmt to handle cases where
5642 the user modifies a predefined space. */
5643 #ifdef obj_set_section_attributes
5644 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5650 /* Create a new subspace NAME, with the appropriate flags as defined
5651 by the given parameters.
5653 Add the new subspace to the subspace dictionary chain in numerical
5654 order as defined by the SORT entries. */
5656 static ssd_chain_struct
*
5657 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5658 dup_common
, is_zero
, sort
, access
, space_index
,
5659 alignment
, quadrant
, seg
)
5660 sd_chain_struct
*space
;
5662 int loadable
, code_only
, common
, dup_common
, is_zero
;
5670 ssd_chain_struct
*chain_entry
;
5672 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5674 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5676 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5677 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5679 /* Initialize subspace_defined. When we hit a .subspace directive
5680 we'll set it to 1 which "locks-in" the subspace attributes. */
5681 SUBSPACE_DEFINED (chain_entry
) = 0;
5683 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5684 chain_entry
->ssd_seg
= seg
;
5685 chain_entry
->ssd_next
= NULL
;
5687 /* Find spot for the new subspace based on its sort key. */
5688 if (space
->sd_subspaces
== NULL
)
5689 space
->sd_subspaces
= chain_entry
;
5692 ssd_chain_struct
*chain_pointer
;
5693 ssd_chain_struct
*prev_chain_pointer
;
5695 chain_pointer
= space
->sd_subspaces
;
5696 prev_chain_pointer
= NULL
;
5698 while (chain_pointer
)
5700 prev_chain_pointer
= chain_pointer
;
5701 chain_pointer
= chain_pointer
->ssd_next
;
5704 /* Now we have somewhere to put the new entry. Insert it and update
5706 if (prev_chain_pointer
)
5708 chain_entry
->ssd_next
= chain_pointer
;
5709 prev_chain_pointer
->ssd_next
= chain_entry
;
5713 space
->sd_subspaces
= chain_entry
;
5714 chain_entry
->ssd_next
= chain_pointer
;
5718 #ifdef obj_set_subsection_attributes
5719 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5726 /* Update the information for the given subspace based upon the
5727 various arguments. Return the modified subspace chain entry. */
5729 static ssd_chain_struct
*
5730 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5731 zero
, access
, space_index
, alignment
, quadrant
, section
)
5732 sd_chain_struct
*space
;
5746 ssd_chain_struct
*chain_entry
;
5748 chain_entry
= is_defined_subspace (name
);
5750 #ifdef obj_set_subsection_attributes
5751 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5758 /* Return the space chain entry for the space with the name NAME or
5759 NULL if no such space exists. */
5761 static sd_chain_struct
*
5762 is_defined_space (name
)
5765 sd_chain_struct
*chain_pointer
;
5767 for (chain_pointer
= space_dict_root
;
5769 chain_pointer
= chain_pointer
->sd_next
)
5771 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5772 return chain_pointer
;
5775 /* No mapping from segment to space was found. Return NULL. */
5779 /* Find and return the space associated with the given seg. If no mapping
5780 from the given seg to a space is found, then return NULL.
5782 Unlike subspaces, the number of spaces is not expected to grow much,
5783 so a linear exhaustive search is OK here. */
5785 static sd_chain_struct
*
5786 pa_segment_to_space (seg
)
5789 sd_chain_struct
*space_chain
;
5791 /* Walk through each space looking for the correct mapping. */
5792 for (space_chain
= space_dict_root
;
5794 space_chain
= space_chain
->sd_next
)
5796 if (space_chain
->sd_seg
== seg
)
5800 /* Mapping was not found. Return NULL. */
5804 /* Return the space chain entry for the subspace with the name NAME or
5805 NULL if no such subspace exists.
5807 Uses a linear search through all the spaces and subspaces, this may
5808 not be appropriate if we ever being placing each function in its
5811 static ssd_chain_struct
*
5812 is_defined_subspace (name
)
5815 sd_chain_struct
*space_chain
;
5816 ssd_chain_struct
*subspace_chain
;
5818 /* Walk through each space. */
5819 for (space_chain
= space_dict_root
;
5821 space_chain
= space_chain
->sd_next
)
5823 /* Walk through each subspace looking for a name which matches. */
5824 for (subspace_chain
= space_chain
->sd_subspaces
;
5826 subspace_chain
= subspace_chain
->ssd_next
)
5827 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5828 return subspace_chain
;
5831 /* Subspace wasn't found. Return NULL. */
5835 /* Find and return the subspace associated with the given seg. If no
5836 mapping from the given seg to a subspace is found, then return NULL.
5838 If we ever put each procedure/function within its own subspace
5839 (to make life easier on the compiler and linker), then this will have
5840 to become more efficient. */
5842 static ssd_chain_struct
*
5843 pa_subsegment_to_subspace (seg
, subseg
)
5847 sd_chain_struct
*space_chain
;
5848 ssd_chain_struct
*subspace_chain
;
5850 /* Walk through each space. */
5851 for (space_chain
= space_dict_root
;
5853 space_chain
= space_chain
->sd_next
)
5855 if (space_chain
->sd_seg
== seg
)
5857 /* Walk through each subspace within each space looking for
5858 the correct mapping. */
5859 for (subspace_chain
= space_chain
->sd_subspaces
;
5861 subspace_chain
= subspace_chain
->ssd_next
)
5862 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5863 return subspace_chain
;
5867 /* No mapping from subsegment to subspace found. Return NULL. */
5871 /* Given a number, try and find a space with the name number.
5873 Return a pointer to a space dictionary chain entry for the space
5874 that was found or NULL on failure. */
5876 static sd_chain_struct
*
5877 pa_find_space_by_number (number
)
5880 sd_chain_struct
*space_chain
;
5882 for (space_chain
= space_dict_root
;
5884 space_chain
= space_chain
->sd_next
)
5886 if (SPACE_SPNUM (space_chain
) == number
)
5890 /* No appropriate space found. Return NULL. */
5894 /* Return the starting address for the given subspace. If the starting
5895 address is unknown then return zero. */
5898 pa_subspace_start (space
, quadrant
)
5899 sd_chain_struct
*space
;
5902 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
5903 is not correct for the PA OSF1 port. */
5904 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
5906 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
5912 /* FIXME. Needs documentation. */
5914 pa_next_subseg (space
)
5915 sd_chain_struct
*space
;
5918 space
->sd_last_subseg
++;
5919 return space
->sd_last_subseg
;
5922 /* Helper function for pa_stringer. Used to find the end of
5929 unsigned int c
= *s
& CHAR_MASK
;
5941 /* Handle a .STRING type pseudo-op. */
5944 pa_stringer (append_zero
)
5947 char *s
, num_buf
[4];
5951 /* Preprocess the string to handle PA-specific escape sequences.
5952 For example, \xDD where DD is a hexidecimal number should be
5953 changed to \OOO where OOO is an octal number. */
5955 /* Skip the opening quote. */
5956 s
= input_line_pointer
+ 1;
5958 while (is_a_char (c
= pa_stringer_aux (s
++)))
5965 /* Handle \x<num>. */
5968 unsigned int number
;
5973 /* Get pas the 'x'. */
5975 for (num_digit
= 0, number
= 0, dg
= *s
;
5977 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
5978 || (dg
>= 'A' && dg
<= 'F'));
5982 number
= number
* 16 + dg
- '0';
5983 else if (dg
>= 'a' && dg
<= 'f')
5984 number
= number
* 16 + dg
- 'a' + 10;
5986 number
= number
* 16 + dg
- 'A' + 10;
5996 sprintf (num_buf
, "%02o", number
);
5999 sprintf (num_buf
, "%03o", number
);
6002 for (i
= 0; i
<= num_digit
; i
++)
6003 s_start
[i
] = num_buf
[i
];
6007 /* This might be a "\"", skip over the escaped char. */
6014 stringer (append_zero
);
6015 pa_undefine_label ();
6018 /* Handle a .VERSION pseudo-op. */
6025 pa_undefine_label ();
6028 /* Handle a .COPYRIGHT pseudo-op. */
6031 pa_copyright (unused
)
6035 pa_undefine_label ();
6038 /* Just like a normal cons, but when finished we have to undefine
6039 the latest space label. */
6046 pa_undefine_label ();
6049 /* Switch to the data space. As usual delete our label. */
6056 pa_undefine_label ();
6059 /* Like float_cons, but we need to undefine our label. */
6062 pa_float_cons (float_type
)
6065 float_cons (float_type
);
6066 pa_undefine_label ();
6069 /* Like s_fill, but delete our label when finished. */
6076 pa_undefine_label ();
6079 /* Like lcomm, but delete our label when finished. */
6082 pa_lcomm (needs_align
)
6085 s_lcomm (needs_align
);
6086 pa_undefine_label ();
6089 /* Like lsym, but delete our label when finished. */
6096 pa_undefine_label ();
6099 /* Switch to the text space. Like s_text, but delete our
6100 label when finished. */
6106 pa_undefine_label ();
6109 /* On the PA relocations which involve function symbols must not be
6110 adjusted. This so that the linker can know when/how to create argument
6111 relocation stubs for indirect calls and calls to static functions.
6113 "T" field selectors create DLT relative fixups for accessing
6114 globals and statics in PIC code; each DLT relative fixup creates
6115 an entry in the DLT table. The entries contain the address of
6116 the final target (eg accessing "foo" would create a DLT entry
6117 with the address of "foo").
6119 Unfortunately, the HP linker doesn't take into account any addend
6120 when generating the DLT; so accessing $LIT$+8 puts the address of
6121 $LIT$ into the DLT rather than the address of $LIT$+8.
6123 The end result is we can't perform relocation symbol reductions for
6124 any fixup which creates entries in the DLT (eg they use "T" field
6127 FIXME. Also reject R_HPPA relocations which are 32 bits
6128 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6129 needs to generate relocations to push the addend and symbol value
6130 onto the stack, add them, then pop the value off the stack and
6131 use it in a relocation -- yuk. */
6134 hppa_fix_adjustable (fixp
)
6137 struct hppa_fix_struct
*hppa_fix
;
6139 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6141 /* Reject reductions of symbols in 32bit plabel relocs. */
6142 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6145 /* Reject reductions of symbols in DLT relative relocs. */
6146 if (hppa_fix
->fx_r_field
== e_tsel
6147 || hppa_fix
->fx_r_field
== e_ltsel
6148 || hppa_fix
->fx_r_field
== e_rtsel
)
6151 /* Reject reductions of function symbols. */
6152 if (fixp
->fx_addsy
== 0
6153 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6159 /* Return nonzero if the fixup in FIXP will require a relocation,
6160 even it if appears that the fixup could be completely handled
6164 hppa_force_relocation (fixp
)
6167 struct hppa_fix_struct
*hppa_fixp
;
6169 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6171 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6175 #define stub_needed(CALLER, CALLEE) \
6176 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6178 /* It is necessary to force PC-relative calls/jumps to have a relocation
6179 entry if they're going to need either a argument relocation or long
6180 call stub. FIXME. Can't we need the same for absolute calls? */
6181 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6182 && (stub_needed (((obj_symbol_type
*)
6183 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6184 hppa_fixp
->fx_arg_reloc
)))
6189 /* No need (yet) to force another relocations to be emitted. */
6193 /* Now for some ELF specific code. FIXME. */
6195 /* Mark the end of a function so that it's possible to compute
6196 the size of the function in hppa_elf_final_processing. */
6199 hppa_elf_mark_end_of_function ()
6201 /* ELF does not have EXIT relocations. All we do is create a
6202 temporary symbol marking the end of the function. */
6203 char *name
= (char *)
6204 xmalloc (strlen ("L$\001end_") +
6205 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6211 strcpy (name
, "L$\001end_");
6212 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6214 /* If we have a .exit followed by a .procend, then the
6215 symbol will have already been defined. */
6216 symbolP
= symbol_find (name
);
6219 /* The symbol has already been defined! This can
6220 happen if we have a .exit followed by a .procend.
6222 This is *not* an error. All we want to do is free
6223 the memory we just allocated for the name and continue. */
6228 /* symbol value should be the offset of the
6229 last instruction of the function */
6230 symbolP
= symbol_new (name
, now_seg
,
6231 (valueT
) (obstack_next_free (&frags
)
6232 - frag_now
->fr_literal
- 4),
6236 symbolP
->bsym
->flags
= BSF_LOCAL
;
6237 symbol_table_insert (symbolP
);
6241 last_call_info
->end_symbol
= symbolP
;
6243 as_bad ("Symbol '%s' could not be created.", name
);
6247 as_bad ("No memory for symbol name.");
6251 /* For ELF, this function serves one purpose: to setup the st_size
6252 field of STT_FUNC symbols. To do this, we need to scan the
6253 call_info structure list, determining st_size in by taking the
6254 difference in the address of the beginning/end marker symbols. */
6257 elf_hppa_final_processing ()
6259 struct call_info
*call_info_pointer
;
6261 for (call_info_pointer
= call_info_root
;
6263 call_info_pointer
= call_info_pointer
->ci_next
)
6265 elf_symbol_type
*esym
6266 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6267 esym
->internal_elf_sym
.st_size
=
6268 S_GET_VALUE (call_info_pointer
->end_symbol
)
6269 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;