1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989, 1996 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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
101 /* Various structures and types used internally in tc-hppa.c. */
103 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
107 unsigned int cannot_unwind
:1;
108 unsigned int millicode
:1;
109 unsigned int millicode_save_rest
:1;
110 unsigned int region_desc
:2;
111 unsigned int save_sr
:2;
112 unsigned int entry_fr
:4;
113 unsigned int entry_gr
:5;
114 unsigned int args_stored
:1;
115 unsigned int call_fr
:5;
116 unsigned int call_gr
:5;
117 unsigned int save_sp
:1;
118 unsigned int save_rp
:1;
119 unsigned int save_rp_in_frame
:1;
120 unsigned int extn_ptr_defined
:1;
121 unsigned int cleanup_defined
:1;
123 unsigned int hpe_interrupt_marker
:1;
124 unsigned int hpux_interrupt_marker
:1;
125 unsigned int reserved
:3;
126 unsigned int frame_size
:27;
131 /* Starting and ending offsets of the region described by
133 unsigned int start_offset
;
134 unsigned int end_offset
;
135 struct unwind_desc descriptor
;
138 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
139 control the entry and exit code they generate. It is also used in
140 creation of the correct stack unwind descriptors.
142 NOTE: GAS does not support .enter and .leave for the generation of
143 prologues and epilogues. FIXME.
145 The fields in structure roughly correspond to the arguments available on the
146 .callinfo pseudo-op. */
150 /* The unwind descriptor being built. */
151 struct unwind_table ci_unwind
;
153 /* Name of this function. */
154 symbolS
*start_symbol
;
156 /* (temporary) symbol used to mark the end of this function. */
159 /* Next entry in the chain. */
160 struct call_info
*ci_next
;
163 /* Operand formats for FP instructions. Note not all FP instructions
164 allow all four formats to be used (for example fmpysub only allows
168 SGL
, DBL
, ILLEGAL_FMT
, QUAD
172 /* This fully describes the symbol types which may be attached to
173 an EXPORT or IMPORT directive. Only SOM uses this formation
174 (ELF has no need for it). */
178 SYMBOL_TYPE_ABSOLUTE
,
182 SYMBOL_TYPE_MILLICODE
,
184 SYMBOL_TYPE_PRI_PROG
,
185 SYMBOL_TYPE_SEC_PROG
,
189 /* This structure contains information needed to assemble
190 individual instructions. */
193 /* Holds the opcode after parsing by pa_ip. */
194 unsigned long opcode
;
196 /* Holds an expression associated with the current instruction. */
199 /* Does this instruction use PC-relative addressing. */
202 /* Floating point formats for operand1 and operand2. */
203 fp_operand_format fpof1
;
204 fp_operand_format fpof2
;
206 /* Holds the field selector for this instruction
207 (for example L%, LR%, etc). */
210 /* Holds any argument relocation bits associated with this
211 instruction. (instruction should be some sort of call). */
214 /* The format specification for this instruction. */
217 /* The relocation (if any) associated with this instruction. */
221 /* PA-89 floating point registers are arranged like this:
224 +--------------+--------------+
225 | 0 or 16L | 16 or 16R |
226 +--------------+--------------+
227 | 1 or 17L | 17 or 17R |
228 +--------------+--------------+
236 +--------------+--------------+
237 | 14 or 30L | 30 or 30R |
238 +--------------+--------------+
239 | 15 or 31L | 31 or 31R |
240 +--------------+--------------+
243 The following is a version of pa_parse_number that
244 handles the L/R notation and returns the correct
245 value to put into the instruction register field.
246 The correct value to put into the instruction is
247 encoded in the structure 'pa_11_fp_reg_struct'. */
249 struct pa_11_fp_reg_struct
251 /* The register number. */
258 /* Additional information needed to build argument relocation stubs. */
261 /* The argument relocation specification. */
262 unsigned int arg_reloc
;
264 /* Number of arguments. */
265 unsigned int arg_count
;
268 /* This structure defines an entry in the subspace dictionary
271 struct subspace_dictionary_chain
273 /* Nonzero if this space has been defined by the user code. */
274 unsigned int ssd_defined
;
276 /* Name of this subspace. */
279 /* GAS segment and subsegment associated with this subspace. */
283 /* Next space in the subspace dictionary chain. */
284 struct subspace_dictionary_chain
*ssd_next
;
287 typedef struct subspace_dictionary_chain ssd_chain_struct
;
289 /* This structure defines an entry in the subspace dictionary
292 struct space_dictionary_chain
294 /* Nonzero if this space has been defined by the user code or
295 as a default space. */
296 unsigned int sd_defined
;
298 /* Nonzero if this spaces has been defined by the user code. */
299 unsigned int sd_user_defined
;
301 /* The space number (or index). */
302 unsigned int sd_spnum
;
304 /* The name of this subspace. */
307 /* GAS segment to which this subspace corresponds. */
310 /* Current subsegment number being used. */
313 /* The chain of subspaces contained within this space. */
314 ssd_chain_struct
*sd_subspaces
;
316 /* The next entry in the space dictionary chain. */
317 struct space_dictionary_chain
*sd_next
;
320 typedef struct space_dictionary_chain sd_chain_struct
;
322 /* Structure for previous label tracking. Needed so that alignments,
323 callinfo declarations, etc can be easily attached to a particular
325 typedef struct label_symbol_struct
327 struct symbol
*lss_label
;
328 sd_chain_struct
*lss_space
;
329 struct label_symbol_struct
*lss_next
;
333 /* This structure defines attributes of the default subspace
334 dictionary entries. */
336 struct default_subspace_dict
338 /* Name of the subspace. */
341 /* FIXME. Is this still needed? */
344 /* Nonzero if this subspace is loadable. */
347 /* Nonzero if this subspace contains only code. */
350 /* Nonzero if this is a common subspace. */
353 /* Nonzero if this is a common subspace which allows symbols
354 to be multiply defined. */
357 /* Nonzero if this subspace should be zero filled. */
360 /* Sort key for this subspace. */
363 /* Access control bits for this subspace. Can represent RWX access
364 as well as privilege level changes for gateways. */
367 /* Index of containing space. */
370 /* Alignment (in bytes) of this subspace. */
373 /* Quadrant within space where this subspace should be loaded. */
376 /* An index into the default spaces array. */
379 /* An alias for this section (or NULL if no alias exists). */
382 /* Subsegment associated with this subspace. */
386 /* This structure defines attributes of the default space
387 dictionary entries. */
389 struct default_space_dict
391 /* Name of the space. */
394 /* Space number. It is possible to identify spaces within
395 assembly code numerically! */
398 /* Nonzero if this space is loadable. */
401 /* Nonzero if this space is "defined". FIXME is still needed */
404 /* Nonzero if this space can not be shared. */
407 /* Sort key for this space. */
410 /* Segment associated with this space. */
413 /* An alias for this section (or NULL if no alias exists). */
417 /* Extra information needed to perform fixups (relocations) on the PA. */
418 struct hppa_fix_struct
420 /* The field selector. */
421 enum hppa_reloc_field_selector_type fx_r_field
;
426 /* Format of fixup. */
429 /* Argument relocation bits. */
432 /* The segment this fixup appears in. */
436 /* Structure to hold information about predefined registers. */
444 /* This structure defines the mapping from a FP condition string
445 to a condition number which can be recorded in an instruction. */
452 /* This structure defines a mapping from a field selector
453 string to a field selector type. */
454 struct selector_entry
460 /* Prototypes for functions local to tc-hppa.c. */
462 static void pa_check_current_space_and_subspace
PARAMS ((void));
463 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
464 static void pa_cons
PARAMS ((int));
465 static void pa_data
PARAMS ((int));
466 static void pa_float_cons
PARAMS ((int));
467 static void pa_fill
PARAMS ((int));
468 static void pa_lcomm
PARAMS ((int));
469 static void pa_lsym
PARAMS ((int));
470 static void pa_stringer
PARAMS ((int));
471 static void pa_text
PARAMS ((int));
472 static void pa_version
PARAMS ((int));
473 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
474 static int get_expression
PARAMS ((char *));
475 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
476 static int evaluate_absolute
PARAMS ((struct pa_it
*));
477 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
478 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
479 static int pa_parse_nullif
PARAMS ((char **));
480 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
481 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
482 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
483 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
484 static void pa_align
PARAMS ((int));
485 static void pa_block
PARAMS ((int));
486 static void pa_brtab
PARAMS ((int));
487 static void pa_try
PARAMS ((int));
488 static void pa_call
PARAMS ((int));
489 static void pa_call_args
PARAMS ((struct call_desc
*));
490 static void pa_callinfo
PARAMS ((int));
491 static void pa_code
PARAMS ((int));
492 static void pa_comm
PARAMS ((int));
493 static void pa_copyright
PARAMS ((int));
494 static void pa_end
PARAMS ((int));
495 static void pa_enter
PARAMS ((int));
496 static void pa_entry
PARAMS ((int));
497 static void pa_equ
PARAMS ((int));
498 static void pa_exit
PARAMS ((int));
499 static void pa_export
PARAMS ((int));
500 static void pa_type_args
PARAMS ((symbolS
*, int));
501 static void pa_import
PARAMS ((int));
502 static void pa_label
PARAMS ((int));
503 static void pa_leave
PARAMS ((int));
504 static void pa_level
PARAMS ((int));
505 static void pa_origin
PARAMS ((int));
506 static void pa_proc
PARAMS ((int));
507 static void pa_procend
PARAMS ((int));
508 static void pa_space
PARAMS ((int));
509 static void pa_spnum
PARAMS ((int));
510 static void pa_subspace
PARAMS ((int));
511 static void pa_param
PARAMS ((int));
512 static void pa_undefine_label
PARAMS ((void));
513 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
514 struct pa_11_fp_reg_struct
*));
515 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
516 static label_symbol_struct
*pa_get_label
PARAMS ((void));
517 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
520 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
525 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
526 char *, int, int, int,
530 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
531 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
532 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
533 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
535 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
536 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
537 static void pa_ip
PARAMS ((char *));
538 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
539 long, expressionS
*, int,
540 bfd_reloc_code_real_type
,
541 enum hppa_reloc_field_selector_type
,
543 static int is_end_of_statement
PARAMS ((void));
544 static int reg_name_search
PARAMS ((char *));
545 static int pa_chk_field_selector
PARAMS ((char **));
546 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
547 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
548 static void process_exit
PARAMS ((void));
549 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
550 static int log2
PARAMS ((int));
551 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
552 static unsigned int pa_stringer_aux
PARAMS ((char *));
553 static void pa_spaces_begin
PARAMS ((void));
554 static void hppa_elf_mark_end_of_function
PARAMS ((void));
556 /* File and gloally scoped variable declarations. */
558 /* Root and final entry in the space chain. */
559 static sd_chain_struct
*space_dict_root
;
560 static sd_chain_struct
*space_dict_last
;
562 /* The current space and subspace. */
563 static sd_chain_struct
*current_space
;
564 static ssd_chain_struct
*current_subspace
;
566 /* Root of the call_info chain. */
567 static struct call_info
*call_info_root
;
569 /* The last call_info (for functions) structure
570 seen so it can be associated with fixups and
572 static struct call_info
*last_call_info
;
574 /* The last call description (for actual calls). */
575 static struct call_desc last_call_desc
;
577 /* Jumps are always the same size -- one instruction. */
578 int md_short_jump_size
= 4;
579 int md_long_jump_size
= 4;
581 /* handle of the OPCODE hash table */
582 static struct hash_control
*op_hash
= NULL
;
584 /* This array holds the chars that always start a comment. If the
585 pre-processor is disabled, these aren't very useful. */
586 const char comment_chars
[] = ";";
588 /* Table of pseudo ops for the PA. FIXME -- how many of these
589 are now redundant with the overall GAS and the object file
591 const pseudo_typeS md_pseudo_table
[] =
593 /* align pseudo-ops on the PA specify the actual alignment requested,
594 not the log2 of the requested alignment. */
595 {"align", pa_align
, 8},
596 {"begin_brtab", pa_brtab
, 1},
597 {"begin_try", pa_try
, 1},
598 {"block", pa_block
, 1},
599 {"blockz", pa_block
, 0},
600 {"byte", pa_cons
, 1},
601 {"call", pa_call
, 0},
602 {"callinfo", pa_callinfo
, 0},
603 {"code", pa_code
, 0},
604 {"comm", pa_comm
, 0},
605 {"copyright", pa_copyright
, 0},
606 {"data", pa_data
, 0},
607 {"double", pa_float_cons
, 'd'},
609 {"end_brtab", pa_brtab
, 0},
610 {"end_try", pa_try
, 0},
611 {"enter", pa_enter
, 0},
612 {"entry", pa_entry
, 0},
614 {"exit", pa_exit
, 0},
615 {"export", pa_export
, 0},
616 {"fill", pa_fill
, 0},
617 {"float", pa_float_cons
, 'f'},
618 {"half", pa_cons
, 2},
619 {"import", pa_import
, 0},
621 {"label", pa_label
, 0},
622 {"lcomm", pa_lcomm
, 0},
623 {"leave", pa_leave
, 0},
624 {"level", pa_level
, 0},
625 {"long", pa_cons
, 4},
626 {"lsym", pa_lsym
, 0},
627 {"nsubspa", pa_subspace
, 1},
628 {"octa", pa_cons
, 16},
629 {"org", pa_origin
, 0},
630 {"origin", pa_origin
, 0},
631 {"param", pa_param
, 0},
632 {"proc", pa_proc
, 0},
633 {"procend", pa_procend
, 0},
634 {"quad", pa_cons
, 8},
636 {"short", pa_cons
, 2},
637 {"single", pa_float_cons
, 'f'},
638 {"space", pa_space
, 0},
639 {"spnum", pa_spnum
, 0},
640 {"string", pa_stringer
, 0},
641 {"stringz", pa_stringer
, 1},
642 {"subspa", pa_subspace
, 0},
643 {"text", pa_text
, 0},
644 {"version", pa_version
, 0},
645 {"word", pa_cons
, 4},
649 /* This array holds the chars that only start a comment at the beginning of
650 a line. If the line seems to have the form '# 123 filename'
651 .line and .file directives will appear in the pre-processed output.
653 Note that input_file.c hand checks for '#' at the beginning of the
654 first line of the input file. This is because the compiler outputs
655 #NO_APP at the beginning of its output.
657 Also note that C style comments will always work. */
658 const char line_comment_chars
[] = "#";
660 /* This array holds the characters which act as line separators. */
661 const char line_separator_chars
[] = "!";
663 /* Chars that can be used to separate mant from exp in floating point nums. */
664 const char EXP_CHARS
[] = "eE";
666 /* Chars that mean this number is a floating point constant.
667 As in 0f12.456 or 0d1.2345e12.
669 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
670 changed in read.c. Ideally it shouldn't hae to know abou it at
671 all, but nothing is ideal around here. */
672 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
674 static struct pa_it the_insn
;
676 /* Points to the end of an expression just parsed by get_expressoin
677 and friends. FIXME. This shouldn't be handled with a file-global
679 static char *expr_end
;
681 /* Nonzero if a .callinfo appeared within the current procedure. */
682 static int callinfo_found
;
684 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
685 static int within_entry_exit
;
687 /* Nonzero if the assembler is currently within a procedure definition. */
688 static int within_procedure
;
690 /* Handle on strucutre which keep track of the last symbol
691 seen in each subspace. */
692 static label_symbol_struct
*label_symbols_rootp
= NULL
;
694 /* Holds the last field selector. */
695 static int hppa_field_selector
;
697 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
698 static symbolS
*dummy_symbol
;
700 /* Nonzero if errors are to be printed. */
701 static int print_errors
= 1;
703 /* List of registers that are pre-defined:
705 Each general register has one predefined name of the form
706 %r<REGNUM> which has the value <REGNUM>.
708 Space and control registers are handled in a similar manner,
709 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
711 Likewise for the floating point registers, but of the form
712 %fr<REGNUM>. Floating point registers have additional predefined
713 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
714 again have the value <REGNUM>.
716 Many registers also have synonyms:
718 %r26 - %r23 have %arg0 - %arg3 as synonyms
719 %r28 - %r29 have %ret0 - %ret1 as synonyms
720 %r30 has %sp as a synonym
721 %r27 has %dp as a synonym
722 %r2 has %rp as a synonym
724 Almost every control register has a synonym; they are not listed
727 The table is sorted. Suitable for searching by a binary search. */
729 static const struct pd_reg pre_defined_registers
[] =
929 /* This table is sorted by order of the length of the string. This is
930 so we check for <> before we check for <. If we had a <> and checked
931 for < first, we would get a false match. */
932 static const struct fp_cond_map fp_cond_map
[] =
968 static const struct selector_entry selector_table
[] =
991 /* default space and subspace dictionaries */
993 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
994 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
996 /* pre-defined subsegments (subspaces) for the HPPA. */
997 #define SUBSEG_CODE 0
999 #define SUBSEG_MILLI 2
1000 #define SUBSEG_DATA 0
1001 #define SUBSEG_BSS 2
1002 #define SUBSEG_UNWIND 3
1003 #define SUBSEG_GDB_STRINGS 0
1004 #define SUBSEG_GDB_SYMBOLS 1
1006 static struct default_subspace_dict pa_def_subspaces
[] =
1008 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1009 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1010 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1011 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI
},
1012 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1014 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
1016 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1019 static struct default_space_dict pa_def_spaces
[] =
1021 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1022 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1023 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1026 /* Misc local definitions used by the assembler. */
1028 /* Return nonzero if the string pointed to by S potentially represents
1029 a right or left half of a FP register */
1030 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1031 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1033 /* These macros are used to maintain spaces/subspaces. */
1034 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1035 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1036 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1037 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1039 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1040 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1042 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1043 main loop after insertion. */
1045 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1047 ((OPCODE) |= (FIELD) << (START)); \
1051 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1052 IGNORE is used to suppress the error message. */
1054 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1056 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1059 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1065 #define is_DP_relative(exp) \
1066 ((exp).X_op == O_subtract \
1067 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1069 #define is_PC_relative(exp) \
1070 ((exp).X_op == O_subtract \
1071 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1073 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1074 always be able to reduce the expression to a constant, so we don't
1075 need real complex handling yet. */
1076 #define is_complex(exp) \
1077 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1079 /* Actual functions to implement the PA specific code for the assembler. */
1081 /* Called before writing the object file. Make sure entry/exit and
1082 proc/procend pairs match. */
1087 if (within_entry_exit
)
1088 as_fatal ("Missing .exit\n");
1090 if (within_procedure
)
1091 as_fatal ("Missing .procend\n");
1094 /* Check to make sure we have a valid space and subspace. */
1097 pa_check_current_space_and_subspace ()
1099 if (current_space
== NULL
)
1100 as_fatal ("Not in a space.\n");
1102 if (current_subspace
== NULL
)
1103 as_fatal ("Not in a subspace.\n");
1106 /* Returns a pointer to the label_symbol_struct for the current space.
1107 or NULL if no label_symbol_struct exists for the current space. */
1109 static label_symbol_struct
*
1112 label_symbol_struct
*label_chain
;
1113 sd_chain_struct
*space_chain
= current_space
;
1115 for (label_chain
= label_symbols_rootp
;
1117 label_chain
= label_chain
->lss_next
)
1118 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1124 /* Defines a label for the current space. If one is already defined,
1125 this function will replace it with the new label. */
1128 pa_define_label (symbol
)
1131 label_symbol_struct
*label_chain
= pa_get_label ();
1132 sd_chain_struct
*space_chain
= current_space
;
1135 label_chain
->lss_label
= symbol
;
1138 /* Create a new label entry and add it to the head of the chain. */
1140 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1141 label_chain
->lss_label
= symbol
;
1142 label_chain
->lss_space
= space_chain
;
1143 label_chain
->lss_next
= NULL
;
1145 if (label_symbols_rootp
)
1146 label_chain
->lss_next
= label_symbols_rootp
;
1148 label_symbols_rootp
= label_chain
;
1152 /* Removes a label definition for the current space.
1153 If there is no label_symbol_struct entry, then no action is taken. */
1156 pa_undefine_label ()
1158 label_symbol_struct
*label_chain
;
1159 label_symbol_struct
*prev_label_chain
= NULL
;
1160 sd_chain_struct
*space_chain
= current_space
;
1162 for (label_chain
= label_symbols_rootp
;
1164 label_chain
= label_chain
->lss_next
)
1166 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1168 /* Remove the label from the chain and free its memory. */
1169 if (prev_label_chain
)
1170 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1172 label_symbols_rootp
= label_chain
->lss_next
;
1177 prev_label_chain
= label_chain
;
1182 /* An HPPA-specific version of fix_new. This is required because the HPPA
1183 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1184 results in the creation of an instance of an hppa_fix_struct. An
1185 hppa_fix_struct stores the extra information along with a pointer to the
1186 original fixS. This is attached to the original fixup via the
1187 tc_fix_data field. */
1190 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1191 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1195 symbolS
*add_symbol
;
1199 bfd_reloc_code_real_type r_type
;
1200 enum hppa_reloc_field_selector_type r_field
;
1207 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1208 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1211 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1213 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1214 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1215 hppa_fix
->fx_r_type
= r_type
;
1216 hppa_fix
->fx_r_field
= r_field
;
1217 hppa_fix
->fx_r_format
= r_format
;
1218 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1219 hppa_fix
->segment
= now_seg
;
1221 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1222 new_fix
->fx_offset
= *unwind_bits
;
1225 /* foo-$global$ is used to access non-automatic storage. $global$
1226 is really just a marker and has served its purpose, so eliminate
1227 it now so as not to confuse write.c. */
1228 if (new_fix
->fx_subsy
1229 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1230 new_fix
->fx_subsy
= NULL
;
1233 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1234 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1237 parse_cons_expression_hppa (exp
)
1240 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1244 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1245 hppa_field_selector is set by the parse_cons_expression_hppa. */
1248 cons_fix_new_hppa (frag
, where
, size
, exp
)
1254 unsigned int rel_type
;
1256 /* Get a base relocation type. */
1257 if (is_DP_relative (*exp
))
1258 rel_type
= R_HPPA_GOTOFF
;
1259 else if (is_complex (*exp
))
1260 rel_type
= R_HPPA_COMPLEX
;
1264 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
1265 && hppa_field_selector
!= e_esel
)
1266 as_warn ("Invalid field selector. Assuming F%%.");
1268 fix_new_hppa (frag
, where
, size
,
1269 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1270 hppa_field_selector
, 32, 0, NULL
);
1272 /* Reset field selector to its default state. */
1273 hppa_field_selector
= 0;
1276 /* This function is called once, at assembler startup time. It should
1277 set up all the tables, etc. that the MD part of the assembler will need. */
1282 const char *retval
= NULL
;
1286 last_call_info
= NULL
;
1287 call_info_root
= NULL
;
1289 /* Set the default machine type. */
1290 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1291 as_warn ("could not set architecture and machine");
1293 /* Folding of text and data segments fails miserably on the PA.
1294 Warn user and disable "-R" option. */
1295 if (flag_readonly_data_in_text
)
1297 as_warn ("-R option not supported on this target.");
1298 flag_readonly_data_in_text
= 0;
1303 op_hash
= hash_new ();
1305 while (i
< NUMOPCODES
)
1307 const char *name
= pa_opcodes
[i
].name
;
1308 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1309 if (retval
!= NULL
&& *retval
!= '\0')
1311 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1316 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1317 != pa_opcodes
[i
].match
)
1319 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1320 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1325 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1329 as_fatal ("Broken assembler. No assembly attempted.");
1331 /* SOM will change text_section. To make sure we never put
1332 anything into the old one switch to the new one now. */
1333 subseg_set (text_section
, 0);
1335 dummy_symbol
= symbol_find_or_make ("L$dummy");
1336 S_SET_SEGMENT (dummy_symbol
, text_section
);
1339 /* Assemble a single instruction storing it into a frag. */
1346 /* The had better be something to assemble. */
1349 /* If we are within a procedure definition, make sure we've
1350 defined a label for the procedure; handle case where the
1351 label was defined after the .PROC directive.
1353 Note there's not need to diddle with the segment or fragment
1354 for the label symbol in this case. We have already switched
1355 into the new $CODE$ subspace at this point. */
1356 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1358 label_symbol_struct
*label_symbol
= pa_get_label ();
1362 if (label_symbol
->lss_label
)
1364 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1365 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1367 /* Also handle allocation of a fixup to hold the unwind
1368 information when the label appears after the proc/procend. */
1369 if (within_entry_exit
)
1371 char *where
= frag_more (0);
1373 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1374 NULL
, (offsetT
) 0, NULL
,
1375 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1376 (int *)&last_call_info
->ci_unwind
.descriptor
);
1381 as_bad ("Missing function name for .PROC (corrupted label chain)");
1384 as_bad ("Missing function name for .PROC");
1387 /* Assemble the instruction. Results are saved into "the_insn". */
1390 /* Get somewhere to put the assembled instrution. */
1393 /* Output the opcode. */
1394 md_number_to_chars (to
, the_insn
.opcode
, 4);
1396 /* If necessary output more stuff. */
1397 if (the_insn
.reloc
!= R_HPPA_NONE
)
1398 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1399 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1400 the_insn
.reloc
, the_insn
.field_selector
,
1401 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1404 /* Do the real work for assembling a single instruction. Store results
1405 into the global "the_insn" variable. */
1411 char *error_message
= "";
1412 char *s
, c
, *argstart
, *name
, *save_s
;
1416 int cmpltr
, nullif
, flag
, cond
, num
;
1417 unsigned long opcode
;
1418 struct pa_opcode
*insn
;
1420 /* We must have a valid space and subspace. */
1421 pa_check_current_space_and_subspace ();
1423 /* Skip to something interesting. */
1424 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1443 as_fatal ("Unknown opcode: `%s'", str
);
1448 /* Convert everything into lower case. */
1451 if (isupper (*save_s
))
1452 *save_s
= tolower (*save_s
);
1456 /* Look up the opcode in the has table. */
1457 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1459 as_bad ("Unknown opcode: `%s'", str
);
1468 /* Mark the location where arguments for the instruction start, then
1469 start processing them. */
1473 /* Do some initialization. */
1474 opcode
= insn
->match
;
1475 bzero (&the_insn
, sizeof (the_insn
));
1477 the_insn
.reloc
= R_HPPA_NONE
;
1479 /* If this instruction is specific to a particular architecture,
1480 then set a new architecture. */
1481 if (bfd_get_mach (stdoutput
) < insn
->arch
)
1483 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1484 as_warn ("could not update architecture and machine");
1487 /* Build the opcode, checking as we go to make
1488 sure that the operands match. */
1489 for (args
= insn
->args
;; ++args
)
1494 /* End of arguments. */
1510 /* These must match exactly. */
1519 /* Handle a 5 bit register or control register field at 10. */
1522 num
= pa_parse_number (&s
, 0);
1523 CHECK_FIELD (num
, 31, 0, 0);
1524 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1526 /* Handle a 5 bit register field at 15. */
1528 num
= pa_parse_number (&s
, 0);
1529 CHECK_FIELD (num
, 31, 0, 0);
1530 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1532 /* Handle a 5 bit register field at 31. */
1535 num
= pa_parse_number (&s
, 0);
1536 CHECK_FIELD (num
, 31, 0, 0);
1537 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1539 /* Handle a 5 bit field length at 31. */
1541 num
= pa_get_absolute_expression (&the_insn
, &s
);
1543 CHECK_FIELD (num
, 32, 1, 0);
1544 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1546 /* Handle a 5 bit immediate at 15. */
1548 num
= pa_get_absolute_expression (&the_insn
, &s
);
1550 CHECK_FIELD (num
, 15, -16, 0);
1551 low_sign_unext (num
, 5, &num
);
1552 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1554 /* Handle a 5 bit immediate at 31. */
1556 num
= pa_get_absolute_expression (&the_insn
, &s
);
1558 CHECK_FIELD (num
, 15, -16, 0)
1559 low_sign_unext (num
, 5, &num
);
1560 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1562 /* Handle an unsigned 5 bit immediate at 31. */
1564 num
= pa_get_absolute_expression (&the_insn
, &s
);
1566 CHECK_FIELD (num
, 31, 0, 0);
1567 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1569 /* Handle an unsigned 5 bit immediate at 15. */
1571 num
= pa_get_absolute_expression (&the_insn
, &s
);
1573 CHECK_FIELD (num
, 31, 0, 0);
1574 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1576 /* Handle a 2 bit space identifier at 17. */
1578 num
= pa_parse_number (&s
, 0);
1579 CHECK_FIELD (num
, 3, 0, 1);
1580 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1582 /* Handle a 3 bit space identifier at 18. */
1584 num
= pa_parse_number (&s
, 0);
1585 CHECK_FIELD (num
, 7, 0, 1);
1586 dis_assemble_3 (num
, &num
);
1587 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1589 /* Handle a completer for an indexing load or store. */
1595 while (*s
== ',' && i
< 2)
1598 if (strncasecmp (s
, "sm", 2) == 0)
1605 else if (strncasecmp (s
, "m", 1) == 0)
1607 else if (strncasecmp (s
, "s", 1) == 0)
1610 as_bad ("Invalid Indexed Load Completer.");
1615 as_bad ("Invalid Indexed Load Completer Syntax.");
1617 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1620 /* Handle a short load/store completer. */
1628 if (strncasecmp (s
, "ma", 2) == 0)
1633 else if (strncasecmp (s
, "mb", 2) == 0)
1639 as_bad ("Invalid Short Load/Store Completer.");
1643 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1646 /* Handle a stbys completer. */
1652 while (*s
== ',' && i
< 2)
1655 if (strncasecmp (s
, "m", 1) == 0)
1657 else if (strncasecmp (s
, "b", 1) == 0)
1659 else if (strncasecmp (s
, "e", 1) == 0)
1662 as_bad ("Invalid Store Bytes Short Completer");
1667 as_bad ("Invalid Store Bytes Short Completer");
1669 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1672 /* Handle a non-negated compare/stubtract condition. */
1674 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1677 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1680 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1682 /* Handle a negated or non-negated compare/subtract condition. */
1685 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1689 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1692 as_bad ("Invalid Compare/Subtract Condition.");
1697 /* Negated condition requires an opcode change. */
1701 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1703 /* Handle non-negated add condition. */
1705 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1708 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1711 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1713 /* Handle a negated or non-negated add condition. */
1716 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1720 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1723 as_bad ("Invalid Compare/Subtract Condition");
1728 /* Negated condition requires an opcode change. */
1732 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1734 /* Handle a compare/subtract condition. */
1741 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1746 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1749 as_bad ("Invalid Compare/Subtract Condition");
1753 opcode
|= cmpltr
<< 13;
1754 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1756 /* Handle a non-negated add condition. */
1765 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1769 if (strcmp (name
, "=") == 0)
1771 else if (strcmp (name
, "<") == 0)
1773 else if (strcmp (name
, "<=") == 0)
1775 else if (strcasecmp (name
, "nuv") == 0)
1777 else if (strcasecmp (name
, "znv") == 0)
1779 else if (strcasecmp (name
, "sv") == 0)
1781 else if (strcasecmp (name
, "od") == 0)
1783 else if (strcasecmp (name
, "n") == 0)
1785 else if (strcasecmp (name
, "tr") == 0)
1790 else if (strcmp (name
, "<>") == 0)
1795 else if (strcmp (name
, ">=") == 0)
1800 else if (strcmp (name
, ">") == 0)
1805 else if (strcasecmp (name
, "uv") == 0)
1810 else if (strcasecmp (name
, "vnz") == 0)
1815 else if (strcasecmp (name
, "nsv") == 0)
1820 else if (strcasecmp (name
, "ev") == 0)
1826 as_bad ("Invalid Add Condition: %s", name
);
1829 nullif
= pa_parse_nullif (&s
);
1830 opcode
|= nullif
<< 1;
1831 opcode
|= cmpltr
<< 13;
1832 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1834 /* HANDLE a logical instruction condition. */
1842 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1846 if (strcmp (name
, "=") == 0)
1848 else if (strcmp (name
, "<") == 0)
1850 else if (strcmp (name
, "<=") == 0)
1852 else if (strcasecmp (name
, "od") == 0)
1854 else if (strcasecmp (name
, "tr") == 0)
1859 else if (strcmp (name
, "<>") == 0)
1864 else if (strcmp (name
, ">=") == 0)
1869 else if (strcmp (name
, ">") == 0)
1874 else if (strcasecmp (name
, "ev") == 0)
1880 as_bad ("Invalid Logical Instruction Condition.");
1883 opcode
|= cmpltr
<< 13;
1884 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1886 /* Handle a unit instruction condition. */
1893 if (strncasecmp (s
, "sbz", 3) == 0)
1898 else if (strncasecmp (s
, "shz", 3) == 0)
1903 else if (strncasecmp (s
, "sdc", 3) == 0)
1908 else if (strncasecmp (s
, "sbc", 3) == 0)
1913 else if (strncasecmp (s
, "shc", 3) == 0)
1918 else if (strncasecmp (s
, "tr", 2) == 0)
1924 else if (strncasecmp (s
, "nbz", 3) == 0)
1930 else if (strncasecmp (s
, "nhz", 3) == 0)
1936 else if (strncasecmp (s
, "ndc", 3) == 0)
1942 else if (strncasecmp (s
, "nbc", 3) == 0)
1948 else if (strncasecmp (s
, "nhc", 3) == 0)
1955 as_bad ("Invalid Logical Instruction Condition.");
1957 opcode
|= cmpltr
<< 13;
1958 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1960 /* Handle a shift/extract/deposit condition. */
1968 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1972 if (strcmp (name
, "=") == 0)
1974 else if (strcmp (name
, "<") == 0)
1976 else if (strcasecmp (name
, "od") == 0)
1978 else if (strcasecmp (name
, "tr") == 0)
1980 else if (strcmp (name
, "<>") == 0)
1982 else if (strcmp (name
, ">=") == 0)
1984 else if (strcasecmp (name
, "ev") == 0)
1986 /* Handle movb,n. Put things back the way they were.
1987 This includes moving s back to where it started. */
1988 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1995 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1998 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2000 /* Handle bvb and bb conditions. */
2006 if (strncmp (s
, "<", 1) == 0)
2011 else if (strncmp (s
, ">=", 2) == 0)
2017 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2019 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2021 /* Handle a system control completer. */
2023 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2031 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2033 /* Handle a nullification completer for branch instructions. */
2035 nullif
= pa_parse_nullif (&s
);
2036 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2038 /* Handle a nullification completer for copr and spop insns. */
2040 nullif
= pa_parse_nullif (&s
);
2041 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2043 /* Handle a 11 bit immediate at 31. */
2045 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2048 if (the_insn
.exp
.X_op
== O_constant
)
2050 num
= evaluate_absolute (&the_insn
);
2051 CHECK_FIELD (num
, 1023, -1024, 0);
2052 low_sign_unext (num
, 11, &num
);
2053 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2057 if (is_DP_relative (the_insn
.exp
))
2058 the_insn
.reloc
= R_HPPA_GOTOFF
;
2059 else if (is_PC_relative (the_insn
.exp
))
2060 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2062 the_insn
.reloc
= R_HPPA
;
2063 the_insn
.format
= 11;
2067 /* Handle a 14 bit immediate at 31. */
2069 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2072 if (the_insn
.exp
.X_op
== O_constant
)
2074 num
= evaluate_absolute (&the_insn
);
2075 CHECK_FIELD (num
, 8191, -8192, 0);
2076 low_sign_unext (num
, 14, &num
);
2077 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2081 if (is_DP_relative (the_insn
.exp
))
2082 the_insn
.reloc
= R_HPPA_GOTOFF
;
2083 else if (is_PC_relative (the_insn
.exp
))
2084 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2086 the_insn
.reloc
= R_HPPA
;
2087 the_insn
.format
= 14;
2091 /* Handle a 21 bit immediate at 31. */
2093 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2096 if (the_insn
.exp
.X_op
== O_constant
)
2098 num
= evaluate_absolute (&the_insn
);
2099 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2100 dis_assemble_21 (num
, &num
);
2101 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2105 if (is_DP_relative (the_insn
.exp
))
2106 the_insn
.reloc
= R_HPPA_GOTOFF
;
2107 else if (is_PC_relative (the_insn
.exp
))
2108 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2110 the_insn
.reloc
= R_HPPA
;
2111 the_insn
.format
= 21;
2115 /* Handle a 12 bit branch displacement. */
2117 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2121 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2123 unsigned int w1
, w
, result
;
2125 num
= evaluate_absolute (&the_insn
);
2128 as_bad ("Branch to unaligned address");
2131 CHECK_FIELD (num
, 8199, -8184, 0);
2132 sign_unext ((num
- 8) >> 2, 12, &result
);
2133 dis_assemble_12 (result
, &w1
, &w
);
2134 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2138 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2139 the_insn
.format
= 12;
2140 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2141 bzero (&last_call_desc
, sizeof (struct call_desc
));
2146 /* Handle a 17 bit branch displacement. */
2148 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2152 if (!the_insn
.exp
.X_add_symbol
2153 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2156 unsigned int w2
, w1
, w
, result
;
2158 num
= evaluate_absolute (&the_insn
);
2161 as_bad ("Branch to unaligned address");
2164 CHECK_FIELD (num
, 262143, -262144, 0);
2166 if (the_insn
.exp
.X_add_symbol
)
2169 sign_unext (num
>> 2, 17, &result
);
2170 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2171 INSERT_FIELD_AND_CONTINUE (opcode
,
2172 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2176 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2177 the_insn
.format
= 17;
2178 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2179 bzero (&last_call_desc
, sizeof (struct call_desc
));
2183 /* Handle an absolute 17 bit branch target. */
2185 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2189 if (!the_insn
.exp
.X_add_symbol
2190 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2193 unsigned int w2
, w1
, w
, result
;
2195 num
= evaluate_absolute (&the_insn
);
2198 as_bad ("Branch to unaligned address");
2201 CHECK_FIELD (num
, 262143, -262144, 0);
2203 if (the_insn
.exp
.X_add_symbol
)
2206 sign_unext (num
>> 2, 17, &result
);
2207 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2208 INSERT_FIELD_AND_CONTINUE (opcode
,
2209 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2213 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2214 the_insn
.format
= 17;
2215 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2216 bzero (&last_call_desc
, sizeof (struct call_desc
));
2220 /* Handle a 5 bit shift count at 26. */
2222 num
= pa_get_absolute_expression (&the_insn
, &s
);
2224 CHECK_FIELD (num
, 31, 0, 0);
2225 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2227 /* Handle a 5 bit bit position at 26. */
2229 num
= pa_get_absolute_expression (&the_insn
, &s
);
2231 CHECK_FIELD (num
, 31, 0, 0);
2232 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2234 /* Handle a 5 bit immediate at 10. */
2236 num
= pa_get_absolute_expression (&the_insn
, &s
);
2238 CHECK_FIELD (num
, 31, 0, 0);
2239 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2241 /* Handle a 13 bit immediate at 18. */
2243 num
= pa_get_absolute_expression (&the_insn
, &s
);
2245 CHECK_FIELD (num
, 8191, 0, 0);
2246 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2248 /* Handle a 26 bit immediate at 31. */
2250 num
= pa_get_absolute_expression (&the_insn
, &s
);
2252 CHECK_FIELD (num
, 671108864, 0, 0);
2253 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2255 /* Handle a 3 bit SFU identifier at 25. */
2258 as_bad ("Invalid SFU identifier");
2259 num
= pa_get_absolute_expression (&the_insn
, &s
);
2261 CHECK_FIELD (num
, 7, 0, 0);
2262 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2264 /* Handle a 20 bit SOP field for spop0. */
2266 num
= pa_get_absolute_expression (&the_insn
, &s
);
2268 CHECK_FIELD (num
, 1048575, 0, 0);
2269 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2270 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2272 /* Handle a 15bit SOP field for spop1. */
2274 num
= pa_get_absolute_expression (&the_insn
, &s
);
2276 CHECK_FIELD (num
, 32767, 0, 0);
2277 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2279 /* Handle a 10bit SOP field for spop3. */
2281 num
= pa_get_absolute_expression (&the_insn
, &s
);
2283 CHECK_FIELD (num
, 1023, 0, 0);
2284 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2285 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2287 /* Handle a 15 bit SOP field for spop2. */
2289 num
= pa_get_absolute_expression (&the_insn
, &s
);
2291 CHECK_FIELD (num
, 32767, 0, 0);
2292 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2293 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2295 /* Handle a 3-bit co-processor ID field. */
2298 as_bad ("Invalid COPR identifier");
2299 num
= pa_get_absolute_expression (&the_insn
, &s
);
2301 CHECK_FIELD (num
, 7, 0, 0);
2302 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2304 /* Handle a 22bit SOP field for copr. */
2306 num
= pa_get_absolute_expression (&the_insn
, &s
);
2308 CHECK_FIELD (num
, 4194303, 0, 0);
2309 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2310 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2312 /* Handle a source FP operand format completer. */
2314 flag
= pa_parse_fp_format (&s
);
2315 the_insn
.fpof1
= flag
;
2316 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2318 /* Handle a destination FP operand format completer. */
2320 /* pa_parse_format needs the ',' prefix. */
2322 flag
= pa_parse_fp_format (&s
);
2323 the_insn
.fpof2
= flag
;
2324 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2326 /* Handle FP compare conditions. */
2328 cond
= pa_parse_fp_cmp_cond (&s
);
2329 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2331 /* Handle L/R register halves like 't'. */
2334 struct pa_11_fp_reg_struct result
;
2336 pa_parse_number (&s
, &result
);
2337 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2338 opcode
|= result
.number_part
;
2340 /* 0x30 opcodes are FP arithmetic operation opcodes
2341 and need to be turned into 0x38 opcodes. This
2342 is not necessary for loads/stores. */
2343 if (need_pa11_opcode (&the_insn
, &result
)
2344 && ((opcode
& 0xfc000000) == 0x30000000))
2347 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2350 /* Handle L/R register halves like 'b'. */
2353 struct pa_11_fp_reg_struct result
;
2355 pa_parse_number (&s
, &result
);
2356 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2357 opcode
|= result
.number_part
<< 21;
2358 if (need_pa11_opcode (&the_insn
, &result
))
2360 opcode
|= (result
.l_r_select
& 1) << 7;
2366 /* Handle L/R register halves like 'x'. */
2369 struct pa_11_fp_reg_struct result
;
2371 pa_parse_number (&s
, &result
);
2372 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2373 opcode
|= (result
.number_part
& 0x1f) << 16;
2374 if (need_pa11_opcode (&the_insn
, &result
))
2376 opcode
|= (result
.l_r_select
& 1) << 12;
2382 /* Handle a 5 bit register field at 10. */
2385 struct pa_11_fp_reg_struct result
;
2387 pa_parse_number (&s
, &result
);
2388 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2389 if (the_insn
.fpof1
== SGL
)
2391 if (result
.number_part
< 16)
2393 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2397 result
.number_part
&= 0xF;
2398 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2400 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2403 /* Handle a 5 bit register field at 15. */
2406 struct pa_11_fp_reg_struct result
;
2408 pa_parse_number (&s
, &result
);
2409 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2410 if (the_insn
.fpof1
== SGL
)
2412 if (result
.number_part
< 16)
2414 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2417 result
.number_part
&= 0xF;
2418 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2420 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2423 /* Handle a 5 bit register field at 31. */
2426 struct pa_11_fp_reg_struct result
;
2428 pa_parse_number (&s
, &result
);
2429 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2430 if (the_insn
.fpof1
== SGL
)
2432 if (result
.number_part
< 16)
2434 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2437 result
.number_part
&= 0xF;
2438 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2440 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2443 /* Handle a 5 bit register field at 20. */
2446 struct pa_11_fp_reg_struct result
;
2448 pa_parse_number (&s
, &result
);
2449 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2450 if (the_insn
.fpof1
== SGL
)
2452 if (result
.number_part
< 16)
2454 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2457 result
.number_part
&= 0xF;
2458 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2460 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2463 /* Handle a 5 bit register field at 25. */
2466 struct pa_11_fp_reg_struct result
;
2468 pa_parse_number (&s
, &result
);
2469 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2470 if (the_insn
.fpof1
== SGL
)
2472 if (result
.number_part
< 16)
2474 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2477 result
.number_part
&= 0xF;
2478 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2480 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2483 /* Handle a floating point operand format at 26.
2484 Only allows single and double precision. */
2486 flag
= pa_parse_fp_format (&s
);
2492 the_insn
.fpof1
= flag
;
2498 as_bad ("Invalid Floating Point Operand Format.");
2508 /* Check if the args matched. */
2511 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2512 && !strcmp (insn
->name
, insn
[1].name
))
2520 as_bad ("Invalid operands %s", error_message
);
2527 the_insn
.opcode
= opcode
;
2530 /* Turn a string in input_line_pointer into a floating point constant of type
2531 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2532 emitted is stored in *sizeP . An error message or NULL is returned. */
2534 #define MAX_LITTLENUMS 6
2537 md_atof (type
, litP
, sizeP
)
2543 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2544 LITTLENUM_TYPE
*wordP
;
2576 return "Bad call to MD_ATOF()";
2578 t
= atof_ieee (input_line_pointer
, type
, words
);
2580 input_line_pointer
= t
;
2581 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2582 for (wordP
= words
; prec
--;)
2584 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2585 litP
+= sizeof (LITTLENUM_TYPE
);
2590 /* Write out big-endian. */
2593 md_number_to_chars (buf
, val
, n
)
2598 number_to_chars_bigendian (buf
, val
, n
);
2601 /* Translate internal representation of relocation info to BFD target
2605 tc_gen_reloc (section
, fixp
)
2610 struct hppa_fix_struct
*hppa_fixp
;
2611 bfd_reloc_code_real_type code
;
2612 static arelent
*no_relocs
= NULL
;
2614 bfd_reloc_code_real_type
**codes
;
2618 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2619 if (fixp
->fx_addsy
== 0)
2621 assert (hppa_fixp
!= 0);
2622 assert (section
!= 0);
2624 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2625 assert (reloc
!= 0);
2627 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2628 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2630 hppa_fixp
->fx_r_format
,
2631 hppa_fixp
->fx_r_field
,
2632 fixp
->fx_subsy
!= NULL
);
2634 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2637 relocs
= (arelent
**)
2638 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2639 assert (relocs
!= 0);
2641 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2642 sizeof (arelent
) * n_relocs
);
2644 assert (reloc
!= 0);
2646 for (i
= 0; i
< n_relocs
; i
++)
2647 relocs
[i
] = &reloc
[i
];
2649 relocs
[n_relocs
] = NULL
;
2652 switch (fixp
->fx_r_type
)
2655 assert (n_relocs
== 1);
2659 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2660 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2661 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2662 reloc
->addend
= 0; /* default */
2664 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2666 /* Now, do any processing that is dependent on the relocation type. */
2669 case R_PARISC_DLTREL21L
:
2670 case R_PARISC_DLTREL14R
:
2671 case R_PARISC_DLTREL14F
:
2672 case R_PARISC_PLABEL32
:
2673 case R_PARISC_PLABEL21L
:
2674 case R_PARISC_PLABEL14R
:
2675 /* For plabel relocations, the addend of the
2676 relocation should be either 0 (no static link) or 2
2677 (static link required).
2679 FIXME: We always assume no static link!
2681 We also slam a zero addend into the DLT relative relocs;
2682 it doesn't make a lot of sense to use any addend since
2683 it gets you a different (eg unknown) DLT entry. */
2687 case R_PARISC_PCREL21L
:
2688 case R_PARISC_PCREL17R
:
2689 case R_PARISC_PCREL17F
:
2690 case R_PARISC_PCREL17C
:
2691 case R_PARISC_PCREL14R
:
2692 case R_PARISC_PCREL14F
:
2693 /* The constant is stored in the instruction. */
2694 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2697 reloc
->addend
= fixp
->fx_offset
;
2704 /* Walk over reach relocation returned by the BFD backend. */
2705 for (i
= 0; i
< n_relocs
; i
++)
2709 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2710 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2711 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2716 /* The only time we ever use a R_COMP2 fixup is for the difference
2717 of two symbols, or for an E% selector in exception handling
2718 tables. With that in mind we fill in all relocs here and break
2720 if (fixp
->fx_subsy
!= NULL
)
2723 relocs
[0]->sym_ptr_ptr
= &bfd_abs_symbol
;
2724 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
2725 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2726 relocs
[0]->addend
= 0;
2727 relocs
[1]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2728 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
2729 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2730 relocs
[1]->addend
= 0;
2731 relocs
[2]->sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2732 relocs
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[2]);
2733 relocs
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2734 relocs
[2]->addend
= 0;
2735 relocs
[3]->sym_ptr_ptr
= &bfd_abs_symbol
;
2736 relocs
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[3]);
2737 relocs
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2738 relocs
[3]->addend
= 0;
2739 relocs
[4]->sym_ptr_ptr
= &bfd_abs_symbol
;
2740 relocs
[4]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[4]);
2741 relocs
[4]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2742 relocs
[4]->addend
= 0;
2748 relocs
[0]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2749 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
2750 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2751 relocs
[0]->addend
= 0;
2752 relocs
[1]->sym_ptr_ptr
= &bfd_abs_symbol
;
2753 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
2754 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2755 relocs
[1]->addend
= 0;
2760 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2766 /* For plabel relocations, the addend of the
2767 relocation should be either 0 (no static link) or 2
2768 (static link required).
2770 FIXME: We always assume no static link!
2772 We also slam a zero addend into the DLT relative relocs;
2773 it doesn't make a lot of sense to use any addend since
2774 it gets you a different (eg unknown) DLT entry. */
2775 relocs
[i
]->addend
= 0;
2790 /* There is no symbol or addend associated with these fixups. */
2791 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2792 relocs
[i
]->addend
= 0;
2798 /* There is no symbol associated with these fixups. */
2799 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2800 relocs
[i
]->addend
= fixp
->fx_offset
;
2804 relocs
[i
]->addend
= fixp
->fx_offset
;
2814 /* Process any machine dependent frag types. */
2817 md_convert_frag (abfd
, sec
, fragP
)
2819 register asection
*sec
;
2820 register fragS
*fragP
;
2822 unsigned int address
;
2824 if (fragP
->fr_type
== rs_machine_dependent
)
2826 switch ((int) fragP
->fr_subtype
)
2829 fragP
->fr_type
= rs_fill
;
2830 know (fragP
->fr_var
== 1);
2831 know (fragP
->fr_next
);
2832 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2833 if (address
% fragP
->fr_offset
)
2836 fragP
->fr_next
->fr_address
2841 fragP
->fr_offset
= 0;
2847 /* Round up a section size to the appropriate boundary. */
2850 md_section_align (segment
, size
)
2854 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2855 int align2
= (1 << align
) - 1;
2857 return (size
+ align2
) & ~align2
;
2860 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2862 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2864 addressT from_addr
, to_addr
;
2868 fprintf (stderr
, "pa_create_short_jmp\n");
2872 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2874 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2876 addressT from_addr
, to_addr
;
2880 fprintf (stderr
, "pa_create_long_jump\n");
2884 /* Return the approximate size of a frag before relaxation has occurred. */
2886 md_estimate_size_before_relax (fragP
, segment
)
2887 register fragS
*fragP
;
2894 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2900 CONST
char *md_shortopts
= "";
2901 struct option md_longopts
[] = {
2902 {NULL
, no_argument
, NULL
, 0}
2904 size_t md_longopts_size
= sizeof(md_longopts
);
2907 md_parse_option (c
, arg
)
2915 md_show_usage (stream
)
2920 /* We have no need to default values of symbols. */
2923 md_undefined_symbol (name
)
2929 /* Apply a fixup to an instruction. */
2932 md_apply_fix (fixP
, valp
)
2936 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2937 struct hppa_fix_struct
*hppa_fixP
;
2938 long new_val
, result
;
2939 unsigned int w1
, w2
, w
, resulti
;
2941 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2942 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2943 never be "applied" (they are just markers). Likewise for
2944 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
2946 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2947 || fixP
->fx_r_type
== R_HPPA_EXIT
2948 || fixP
->fx_r_type
== R_HPPA_BEGIN_BRTAB
2949 || fixP
->fx_r_type
== R_HPPA_END_BRTAB
2950 || fixP
->fx_r_type
== R_HPPA_BEGIN_TRY
)
2953 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
2954 fixups are considered not adjustable, which in turn causes
2955 adjust_reloc_syms to not set fx_offset. Ugh. */
2956 if (fixP
->fx_r_type
== R_HPPA_END_TRY
)
2958 fixP
->fx_offset
= *valp
;
2963 /* There should have been an HPPA specific fixup associated
2964 with the GAS fixup. */
2967 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2968 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2970 /* If there is a symbol associated with this fixup, then it's something
2971 which will need a SOM relocation (except for some PC-relative relocs).
2972 In such cases we should treat the "val" or "addend" as zero since it
2973 will be added in as needed from fx_offset in tc_gen_reloc. */
2974 if ((fixP
->fx_addsy
!= NULL
2975 || fixP
->fx_r_type
== R_HPPA_NONE
)
2978 || hppa_fixP
->fx_r_field
== e_psel
2979 || hppa_fixP
->fx_r_field
== e_rpsel
2980 || hppa_fixP
->fx_r_field
== e_lpsel
2981 || hppa_fixP
->fx_r_field
== e_tsel
2982 || hppa_fixP
->fx_r_field
== e_rtsel
2983 || hppa_fixP
->fx_r_field
== e_ltsel
2984 || hppa_fixP
->fx_r_field
== e_esel
2987 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2989 /* This is truely disgusting. The machine independent code blindly
2990 adds in the value of the symbol being relocated against. Damn! */
2992 && fixP
->fx_addsy
!= NULL
2993 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
2994 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
2995 0, hppa_fixP
->fx_r_field
);
2998 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
3000 /* Handle pc-relative exceptions from above. */
3001 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3002 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3003 if ((fmt
== 12 || fmt
== 17)
3006 && !arg_reloc_stub_needed (((obj_symbol_type
*)
3007 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3008 hppa_fixP
->fx_arg_reloc
)
3009 && ((int)(*valp
) > -262144 && (int)(*valp
) < 262143)
3010 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
3012 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
3014 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
3015 #undef arg_reloc_stub_needed
3019 /* Handle all opcodes with the 'j' operand type. */
3021 CHECK_FIELD (new_val
, 8191, -8192, 0);
3023 /* Mask off 14 bits to be changed. */
3024 bfd_put_32 (stdoutput
,
3025 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3027 low_sign_unext (new_val
, 14, &resulti
);
3031 /* Handle all opcodes with the 'k' operand type. */
3033 CHECK_FIELD (new_val
, 2097152, 0, 0);
3035 /* Mask off 21 bits to be changed. */
3036 bfd_put_32 (stdoutput
,
3037 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3039 dis_assemble_21 (new_val
, &resulti
);
3043 /* Handle all the opcodes with the 'i' operand type. */
3045 CHECK_FIELD (new_val
, 1023, -1023, 0);
3047 /* Mask off 11 bits to be changed. */
3048 bfd_put_32 (stdoutput
,
3049 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3051 low_sign_unext (new_val
, 11, &resulti
);
3055 /* Handle all the opcodes with the 'w' operand type. */
3057 CHECK_FIELD (new_val
, 8199, -8184, 0);
3059 /* Mask off 11 bits to be changed. */
3060 sign_unext ((new_val
- 8) >> 2, 12, &resulti
);
3061 bfd_put_32 (stdoutput
,
3062 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3065 dis_assemble_12 (resulti
, &w1
, &w
);
3066 result
= ((w1
<< 2) | w
);
3069 /* Handle some of the opcodes with the 'W' operand type. */
3071 CHECK_FIELD (new_val
, 262143, -262144, 0);
3073 /* Mask off 17 bits to be changed. */
3074 bfd_put_32 (stdoutput
,
3075 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3077 sign_unext ((new_val
- 8) >> 2, 17, &resulti
);
3078 dis_assemble_17 (resulti
, &w1
, &w2
, &w
);
3079 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3084 bfd_put_32 (stdoutput
, new_val
, buf
);
3088 as_bad ("Unknown relocation encountered in md_apply_fix.");
3092 /* Insert the relocation. */
3093 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3098 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3099 (unsigned int) fixP
, fixP
->fx_r_type
);
3104 /* Exactly what point is a PC-relative offset relative TO?
3105 On the PA, they're relative to the address of the offset. */
3108 md_pcrel_from (fixP
)
3111 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3114 /* Return nonzero if the input line pointer is at the end of
3118 is_end_of_statement ()
3120 return ((*input_line_pointer
== '\n')
3121 || (*input_line_pointer
== ';')
3122 || (*input_line_pointer
== '!'));
3125 /* Read a number from S. The number might come in one of many forms,
3126 the most common will be a hex or decimal constant, but it could be
3127 a pre-defined register (Yuk!), or an absolute symbol.
3129 Return a number or -1 for failure.
3131 When parsing PA-89 FP register numbers RESULT will be
3132 the address of a structure to return information about
3133 L/R half of FP registers, store results there as appropriate.
3135 pa_parse_number can not handle negative constants and will fail
3136 horribly if it is passed such a constant. */
3139 pa_parse_number (s
, result
)
3141 struct pa_11_fp_reg_struct
*result
;
3150 /* Skip whitespace before the number. */
3151 while (*p
== ' ' || *p
== '\t')
3154 /* Store info in RESULT if requested by caller. */
3157 result
->number_part
= -1;
3158 result
->l_r_select
= -1;
3164 /* Looks like a number. */
3167 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3169 /* The number is specified in hex. */
3171 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3172 || ((*p
>= 'A') && (*p
<= 'F')))
3175 num
= num
* 16 + *p
- '0';
3176 else if (*p
>= 'a' && *p
<= 'f')
3177 num
= num
* 16 + *p
- 'a' + 10;
3179 num
= num
* 16 + *p
- 'A' + 10;
3185 /* The number is specified in decimal. */
3186 while (isdigit (*p
))
3188 num
= num
* 10 + *p
- '0';
3193 /* Store info in RESULT if requested by the caller. */
3196 result
->number_part
= num
;
3198 if (IS_R_SELECT (p
))
3200 result
->l_r_select
= 1;
3203 else if (IS_L_SELECT (p
))
3205 result
->l_r_select
= 0;
3209 result
->l_r_select
= 0;
3214 /* The number might be a predefined register. */
3219 /* Tege hack: Special case for general registers as the general
3220 code makes a binary search with case translation, and is VERY
3225 if (*p
== 'e' && *(p
+ 1) == 't'
3226 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3229 num
= *p
- '0' + 28;
3237 else if (!isdigit (*p
))
3240 as_bad ("Undefined register: '%s'.", name
);
3246 num
= num
* 10 + *p
++ - '0';
3247 while (isdigit (*p
));
3252 /* Do a normal register search. */
3253 while (is_part_of_name (c
))
3259 status
= reg_name_search (name
);
3265 as_bad ("Undefined register: '%s'.", name
);
3271 /* Store info in RESULT if requested by caller. */
3274 result
->number_part
= num
;
3275 if (IS_R_SELECT (p
- 1))
3276 result
->l_r_select
= 1;
3277 else if (IS_L_SELECT (p
- 1))
3278 result
->l_r_select
= 0;
3280 result
->l_r_select
= 0;
3285 /* And finally, it could be a symbol in the absolute section which
3286 is effectively a constant. */
3290 while (is_part_of_name (c
))
3296 if ((sym
= symbol_find (name
)) != NULL
)
3298 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3299 num
= S_GET_VALUE (sym
);
3303 as_bad ("Non-absolute symbol: '%s'.", name
);
3309 /* There is where we'd come for an undefined symbol
3310 or for an empty string. For an empty string we
3311 will return zero. That's a concession made for
3312 compatability with the braindamaged HP assemblers. */
3318 as_bad ("Undefined absolute constant: '%s'.", name
);
3324 /* Store info in RESULT if requested by caller. */
3327 result
->number_part
= num
;
3328 if (IS_R_SELECT (p
- 1))
3329 result
->l_r_select
= 1;
3330 else if (IS_L_SELECT (p
- 1))
3331 result
->l_r_select
= 0;
3333 result
->l_r_select
= 0;
3341 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3343 /* Given NAME, find the register number associated with that name, return
3344 the integer value associated with the given name or -1 on failure. */
3347 reg_name_search (name
)
3350 int middle
, low
, high
;
3354 high
= REG_NAME_CNT
- 1;
3358 middle
= (low
+ high
) / 2;
3359 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3365 return pre_defined_registers
[middle
].value
;
3367 while (low
<= high
);
3373 /* Return nonzero if the given INSN and L/R information will require
3374 a new PA-1.1 opcode. */
3377 need_pa11_opcode (insn
, result
)
3379 struct pa_11_fp_reg_struct
*result
;
3381 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3383 /* If this instruction is specific to a particular architecture,
3384 then set a new architecture. */
3385 if (bfd_get_mach (stdoutput
) < pa11
)
3387 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
3388 as_warn ("could not update architecture and machine");
3396 /* Parse a condition for a fcmp instruction. Return the numerical
3397 code associated with the condition. */
3400 pa_parse_fp_cmp_cond (s
)
3407 for (i
= 0; i
< 32; i
++)
3409 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3410 strlen (fp_cond_map
[i
].string
)) == 0)
3412 cond
= fp_cond_map
[i
].cond
;
3413 *s
+= strlen (fp_cond_map
[i
].string
);
3414 /* If not a complete match, back up the input string and
3416 if (**s
!= ' ' && **s
!= '\t')
3418 *s
-= strlen (fp_cond_map
[i
].string
);
3421 while (**s
== ' ' || **s
== '\t')
3427 as_bad ("Invalid FP Compare Condition: %s", *s
);
3429 /* Advance over the bogus completer. */
3430 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3436 /* Parse an FP operand format completer returning the completer
3439 static fp_operand_format
3440 pa_parse_fp_format (s
)
3449 if (strncasecmp (*s
, "sgl", 3) == 0)
3454 else if (strncasecmp (*s
, "dbl", 3) == 0)
3459 else if (strncasecmp (*s
, "quad", 4) == 0)
3466 format
= ILLEGAL_FMT
;
3467 as_bad ("Invalid FP Operand Format: %3s", *s
);
3474 /* Convert from a selector string into a selector type. */
3477 pa_chk_field_selector (str
)
3480 int middle
, low
, high
;
3484 /* Read past any whitespace. */
3485 /* FIXME: should we read past newlines and formfeeds??? */
3486 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3489 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3490 name
[0] = tolower ((*str
)[0]),
3492 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3493 name
[0] = tolower ((*str
)[0]),
3494 name
[1] = tolower ((*str
)[1]),
3497 else if ((*str
)[3] == '\'' || (*str
)[3] == '%')
3498 name
[0] = tolower ((*str
)[0]),
3499 name
[1] = tolower ((*str
)[1]),
3500 name
[2] = tolower ((*str
)[2]),
3507 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3511 middle
= (low
+ high
) / 2;
3512 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3519 *str
+= strlen (name
) + 1;
3521 if (selector_table
[middle
].field_selector
== e_nsel
)
3524 return selector_table
[middle
].field_selector
;
3527 while (low
<= high
);
3532 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3535 get_expression (str
)
3541 save_in
= input_line_pointer
;
3542 input_line_pointer
= str
;
3543 seg
= expression (&the_insn
.exp
);
3544 if (!(seg
== absolute_section
3545 || seg
== undefined_section
3546 || SEG_NORMAL (seg
)))
3548 as_warn ("Bad segment in expression.");
3549 expr_end
= input_line_pointer
;
3550 input_line_pointer
= save_in
;
3553 expr_end
= input_line_pointer
;
3554 input_line_pointer
= save_in
;
3558 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3560 pa_get_absolute_expression (insn
, strp
)
3566 insn
->field_selector
= pa_chk_field_selector (strp
);
3567 save_in
= input_line_pointer
;
3568 input_line_pointer
= *strp
;
3569 expression (&insn
->exp
);
3570 if (insn
->exp
.X_op
!= O_constant
)
3572 as_bad ("Bad segment (should be absolute).");
3573 expr_end
= input_line_pointer
;
3574 input_line_pointer
= save_in
;
3577 expr_end
= input_line_pointer
;
3578 input_line_pointer
= save_in
;
3579 return evaluate_absolute (insn
);
3582 /* Evaluate an absolute expression EXP which may be modified by
3583 the selector FIELD_SELECTOR. Return the value of the expression. */
3585 evaluate_absolute (insn
)
3590 int field_selector
= insn
->field_selector
;
3593 value
= exp
.X_add_number
;
3595 switch (field_selector
)
3601 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3603 if (value
& 0x00000400)
3605 value
= (value
& 0xfffff800) >> 11;
3608 /* Sign extend from bit 21. */
3610 if (value
& 0x00000400)
3611 value
|= 0xfffff800;
3616 /* Arithmetic shift right 11 bits. */
3618 value
= (value
& 0xfffff800) >> 11;
3621 /* Set bits 0-20 to zero. */
3623 value
= value
& 0x7ff;
3626 /* Add 0x800 and arithmetic shift right 11 bits. */
3629 value
= (value
& 0xfffff800) >> 11;
3632 /* Set bitgs 0-21 to one. */
3634 value
|= 0xfffff800;
3637 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3639 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3643 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3648 BAD_CASE (field_selector
);
3654 /* Given an argument location specification return the associated
3655 argument location number. */
3658 pa_build_arg_reloc (type_name
)
3662 if (strncasecmp (type_name
, "no", 2) == 0)
3664 if (strncasecmp (type_name
, "gr", 2) == 0)
3666 else if (strncasecmp (type_name
, "fr", 2) == 0)
3668 else if (strncasecmp (type_name
, "fu", 2) == 0)
3671 as_bad ("Invalid argument location: %s\n", type_name
);
3676 /* Encode and return an argument relocation specification for
3677 the given register in the location specified by arg_reloc. */
3680 pa_align_arg_reloc (reg
, arg_reloc
)
3682 unsigned int arg_reloc
;
3684 unsigned int new_reloc
;
3686 new_reloc
= arg_reloc
;
3702 as_bad ("Invalid argument description: %d", reg
);
3708 /* Parse a PA nullification completer (,n). Return nonzero if the
3709 completer was found; return zero if no completer was found. */
3721 if (strncasecmp (*s
, "n", 1) == 0)
3725 as_bad ("Invalid Nullification: (%c)", **s
);
3734 /* Parse a non-negated compare/subtract completer returning the
3735 number (for encoding in instrutions) of the given completer.
3737 ISBRANCH specifies whether or not this is parsing a condition
3738 completer for a branch (vs a nullification completer for a
3739 computational instruction. */
3742 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3747 char *name
= *s
+ 1;
3755 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3759 if (strcmp (name
, "=") == 0)
3763 else if (strcmp (name
, "<") == 0)
3767 else if (strcmp (name
, "<=") == 0)
3771 else if (strcmp (name
, "<<") == 0)
3775 else if (strcmp (name
, "<<=") == 0)
3779 else if (strcasecmp (name
, "sv") == 0)
3783 else if (strcasecmp (name
, "od") == 0)
3787 /* If we have something like addb,n then there is no condition
3789 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3800 /* Reset pointers if this was really a ,n for a branch instruction. */
3801 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3807 /* Parse a negated compare/subtract completer returning the
3808 number (for encoding in instrutions) of the given completer.
3810 ISBRANCH specifies whether or not this is parsing a condition
3811 completer for a branch (vs a nullification completer for a
3812 computational instruction. */
3815 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3820 char *name
= *s
+ 1;
3828 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3832 if (strcasecmp (name
, "tr") == 0)
3836 else if (strcmp (name
, "<>") == 0)
3840 else if (strcmp (name
, ">=") == 0)
3844 else if (strcmp (name
, ">") == 0)
3848 else if (strcmp (name
, ">>=") == 0)
3852 else if (strcmp (name
, ">>") == 0)
3856 else if (strcasecmp (name
, "nsv") == 0)
3860 else if (strcasecmp (name
, "ev") == 0)
3864 /* If we have something like addb,n then there is no condition
3866 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3877 /* Reset pointers if this was really a ,n for a branch instruction. */
3878 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3884 /* Parse a non-negated addition completer returning the number
3885 (for encoding in instrutions) of the given completer.
3887 ISBRANCH specifies whether or not this is parsing a condition
3888 completer for a branch (vs a nullification completer for a
3889 computational instruction. */
3892 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3897 char *name
= *s
+ 1;
3905 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3909 if (strcmp (name
, "=") == 0)
3913 else if (strcmp (name
, "<") == 0)
3917 else if (strcmp (name
, "<=") == 0)
3921 else if (strcasecmp (name
, "nuv") == 0)
3925 else if (strcasecmp (name
, "znv") == 0)
3929 else if (strcasecmp (name
, "sv") == 0)
3933 else if (strcasecmp (name
, "od") == 0)
3937 /* If we have something like addb,n then there is no condition
3939 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3950 /* Reset pointers if this was really a ,n for a branch instruction. */
3951 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3957 /* Parse a negated addition completer returning the number
3958 (for encoding in instrutions) of the given completer.
3960 ISBRANCH specifies whether or not this is parsing a condition
3961 completer for a branch (vs a nullification completer for a
3962 computational instruction). */
3965 pa_parse_neg_add_cmpltr (s
, isbranch
)
3970 char *name
= *s
+ 1;
3978 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3982 if (strcasecmp (name
, "tr") == 0)
3986 else if (strcmp (name
, "<>") == 0)
3990 else if (strcmp (name
, ">=") == 0)
3994 else if (strcmp (name
, ">") == 0)
3998 else if (strcasecmp (name
, "uv") == 0)
4002 else if (strcasecmp (name
, "vnz") == 0)
4006 else if (strcasecmp (name
, "nsv") == 0)
4010 else if (strcasecmp (name
, "ev") == 0)
4014 /* If we have something like addb,n then there is no condition
4016 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4027 /* Reset pointers if this was really a ,n for a branch instruction. */
4028 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4034 /* Handle an alignment directive. Special so that we can update the
4035 alignment of the subspace if necessary. */
4039 /* We must have a valid space and subspace. */
4040 pa_check_current_space_and_subspace ();
4042 /* Let the generic gas code do most of the work. */
4043 s_align_bytes (bytes
);
4045 /* If bytes is a power of 2, then update the current subspace's
4046 alignment if necessary. */
4047 if (log2 (bytes
) != -1)
4048 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
4051 /* Handle a .BLOCK type pseudo-op. */
4059 unsigned int temp_size
;
4062 /* We must have a valid space and subspace. */
4063 pa_check_current_space_and_subspace ();
4065 temp_size
= get_absolute_expression ();
4067 /* Always fill with zeros, that's what the HP assembler does. */
4070 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4071 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4072 bzero (p
, temp_size
);
4074 /* Convert 2 bytes at a time. */
4076 for (i
= 0; i
< temp_size
; i
+= 2)
4078 md_number_to_chars (p
+ i
,
4080 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4083 pa_undefine_label ();
4084 demand_empty_rest_of_line ();
4087 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4095 /* The BRTAB relocations are only availble in SOM (to denote
4096 the beginning and end of branch tables). */
4097 char *where
= frag_more (0);
4099 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4100 NULL
, (offsetT
) 0, NULL
,
4101 0, begin
? R_HPPA_BEGIN_BRTAB
: R_HPPA_END_BRTAB
,
4102 e_fsel
, 0, 0, NULL
);
4105 demand_empty_rest_of_line ();
4108 /* Handle a .begin_try and .end_try pseudo-op. */
4116 char *where
= frag_more (0);
4121 /* The TRY relocations are only availble in SOM (to denote
4122 the beginning and end of exception handling regions). */
4124 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4125 NULL
, (offsetT
) 0, begin
? NULL
: &exp
,
4126 0, begin
? R_HPPA_BEGIN_TRY
: R_HPPA_END_TRY
,
4127 e_fsel
, 0, 0, NULL
);
4130 demand_empty_rest_of_line ();
4133 /* Handle a .CALL pseudo-op. This involves storing away information
4134 about where arguments are to be found so the linker can detect
4135 (and correct) argument location mismatches between caller and callee. */
4141 /* We must have a valid space and subspace. */
4142 pa_check_current_space_and_subspace ();
4144 pa_call_args (&last_call_desc
);
4145 demand_empty_rest_of_line ();
4148 /* Do the dirty work of building a call descriptor which describes
4149 where the caller placed arguments to a function call. */
4152 pa_call_args (call_desc
)
4153 struct call_desc
*call_desc
;
4156 unsigned int temp
, arg_reloc
;
4158 while (!is_end_of_statement ())
4160 name
= input_line_pointer
;
4161 c
= get_symbol_end ();
4162 /* Process a source argument. */
4163 if ((strncasecmp (name
, "argw", 4) == 0))
4165 temp
= atoi (name
+ 4);
4166 p
= input_line_pointer
;
4168 input_line_pointer
++;
4169 name
= input_line_pointer
;
4170 c
= get_symbol_end ();
4171 arg_reloc
= pa_build_arg_reloc (name
);
4172 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4174 /* Process a return value. */
4175 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4177 p
= input_line_pointer
;
4179 input_line_pointer
++;
4180 name
= input_line_pointer
;
4181 c
= get_symbol_end ();
4182 arg_reloc
= pa_build_arg_reloc (name
);
4183 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4187 as_bad ("Invalid .CALL argument: %s", name
);
4189 p
= input_line_pointer
;
4191 if (!is_end_of_statement ())
4192 input_line_pointer
++;
4196 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4199 is_same_frag (frag1
, frag2
)
4206 else if (frag2
== NULL
)
4208 else if (frag1
== frag2
)
4210 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4211 return (is_same_frag (frag1
, frag2
->fr_next
));
4217 /* Build an entry in the UNWIND subspace from the given function
4218 attributes in CALL_INFO. This is not needed for SOM as using
4219 R_ENTRY and R_EXIT relocations allow the linker to handle building
4220 of the unwind spaces. */
4223 pa_build_unwind_subspace (call_info
)
4224 struct call_info
*call_info
;
4227 asection
*seg
, *save_seg
;
4228 subsegT subseg
, save_subseg
;
4232 /* Get into the right seg/subseg. This may involve creating
4233 the seg the first time through. Make sure to have the
4234 old seg/subseg so that we can reset things when we are done. */
4235 subseg
= SUBSEG_UNWIND
;
4236 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4237 if (seg
== ASEC_NULL
)
4239 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4240 bfd_set_section_flags (stdoutput
, seg
,
4241 SEC_READONLY
| SEC_HAS_CONTENTS
4242 | SEC_LOAD
| SEC_RELOC
);
4246 save_subseg
= now_subseg
;
4247 subseg_set (seg
, subseg
);
4250 /* Get some space to hold relocation information for the unwind
4253 md_number_to_chars (p
, 0, 4);
4255 /* Relocation info. for start offset of the function. */
4256 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4257 call_info
->start_symbol
, (offsetT
) 0,
4258 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4261 md_number_to_chars (p
, 0, 4);
4263 /* Relocation info. for end offset of the function.
4265 Because we allow reductions of 32bit relocations for ELF, this will be
4266 reduced to section_sym + offset which avoids putting the temporary
4267 symbol into the symbol table. It (should) end up giving the same
4268 value as call_info->start_symbol + function size once the linker is
4269 finished with its work. */
4271 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4272 call_info
->end_symbol
, (offsetT
) 0,
4273 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4276 unwind
= (char *) &call_info
->ci_unwind
;
4277 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4281 FRAG_APPEND_1_CHAR (c
);
4285 /* Return back to the original segment/subsegment. */
4286 subseg_set (save_seg
, save_subseg
);
4290 /* Process a .CALLINFO pseudo-op. This information is used later
4291 to build unwind descriptors and maybe one day to support
4292 .ENTER and .LEAVE. */
4295 pa_callinfo (unused
)
4301 /* We must have a valid space and subspace. */
4302 pa_check_current_space_and_subspace ();
4304 /* .CALLINFO must appear within a procedure definition. */
4305 if (!within_procedure
)
4306 as_bad (".callinfo is not within a procedure definition");
4308 /* Mark the fact that we found the .CALLINFO for the
4309 current procedure. */
4310 callinfo_found
= TRUE
;
4312 /* Iterate over the .CALLINFO arguments. */
4313 while (!is_end_of_statement ())
4315 name
= input_line_pointer
;
4316 c
= get_symbol_end ();
4317 /* Frame size specification. */
4318 if ((strncasecmp (name
, "frame", 5) == 0))
4320 p
= input_line_pointer
;
4322 input_line_pointer
++;
4323 temp
= get_absolute_expression ();
4324 if ((temp
& 0x3) != 0)
4326 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4330 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4331 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4334 /* Entry register (GR, GR and SR) specifications. */
4335 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4337 p
= input_line_pointer
;
4339 input_line_pointer
++;
4340 temp
= get_absolute_expression ();
4341 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4342 even though %r19 is caller saved. I think this is a bug in
4343 the HP assembler, and we are not going to emulate it. */
4344 if (temp
< 3 || temp
> 18)
4345 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4346 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4348 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4350 p
= input_line_pointer
;
4352 input_line_pointer
++;
4353 temp
= get_absolute_expression ();
4354 /* Similarly the HP assembler takes 31 as the high bound even
4355 though %fr21 is the last callee saved floating point register. */
4356 if (temp
< 12 || temp
> 21)
4357 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4358 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4360 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4362 p
= input_line_pointer
;
4364 input_line_pointer
++;
4365 temp
= get_absolute_expression ();
4367 as_bad ("Value for ENTRY_SR must be 3\n");
4369 /* Note whether or not this function performs any calls. */
4370 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4371 (strncasecmp (name
, "caller", 6) == 0))
4373 p
= input_line_pointer
;
4376 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4378 p
= input_line_pointer
;
4381 /* Should RP be saved into the stack. */
4382 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4384 p
= input_line_pointer
;
4386 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4388 /* Likewise for SP. */
4389 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4391 p
= input_line_pointer
;
4393 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4395 /* Is this an unwindable procedure. If so mark it so
4396 in the unwind descriptor. */
4397 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4399 p
= input_line_pointer
;
4401 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4403 /* Is this an interrupt routine. If so mark it in the
4404 unwind descriptor. */
4405 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4407 p
= input_line_pointer
;
4409 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4411 /* Is this a millicode routine. "millicode" isn't in my
4412 assembler manual, but my copy is old. The HP assembler
4413 accepts it, and there's a place in the unwind descriptor
4414 to drop the information, so we'll accept it too. */
4415 else if ((strncasecmp (name
, "millicode", 9) == 0))
4417 p
= input_line_pointer
;
4419 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4423 as_bad ("Invalid .CALLINFO argument: %s", name
);
4424 *input_line_pointer
= c
;
4426 if (!is_end_of_statement ())
4427 input_line_pointer
++;
4430 demand_empty_rest_of_line ();
4433 /* Switch into the code subspace. */
4439 current_space
= is_defined_space ("$TEXT$");
4441 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
4443 pa_undefine_label ();
4446 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4447 the .comm pseudo-op has the following symtax:
4449 <label> .comm <length>
4451 where <label> is optional and is a symbol whose address will be the start of
4452 a block of memory <length> bytes long. <length> must be an absolute
4453 expression. <length> bytes will be allocated in the current space
4456 Also note the label may not even be on the same line as the .comm.
4458 This difference in syntax means the colon function will be called
4459 on the symbol before we arrive in pa_comm. colon will set a number
4460 of attributes of the symbol that need to be fixed here. In particular
4461 the value, section pointer, fragment pointer, flags, etc. What
4464 This also makes error detection all but impossible. */
4472 label_symbol_struct
*label_symbol
= pa_get_label ();
4475 symbol
= label_symbol
->lss_label
;
4480 size
= get_absolute_expression ();
4484 S_SET_VALUE (symbol
, size
);
4485 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4486 S_SET_EXTERNAL (symbol
);
4488 /* colon() has already set the frag to the current location in the
4489 current subspace; we need to reset the fragment to the zero address
4490 fragment. We also need to reset the segment pointer. */
4491 symbol
->sy_frag
= &zero_address_frag
;
4493 demand_empty_rest_of_line ();
4496 /* Process a .END pseudo-op. */
4502 demand_empty_rest_of_line ();
4505 /* Process a .ENTER pseudo-op. This is not supported. */
4510 /* We must have a valid space and subspace. */
4511 pa_check_current_space_and_subspace ();
4516 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4522 /* We must have a valid space and subspace. */
4523 pa_check_current_space_and_subspace ();
4525 if (!within_procedure
)
4526 as_bad ("Misplaced .entry. Ignored.");
4529 if (!callinfo_found
)
4530 as_bad ("Missing .callinfo.");
4532 demand_empty_rest_of_line ();
4533 within_entry_exit
= TRUE
;
4536 /* SOM defers building of unwind descriptors until the link phase.
4537 The assembler is responsible for creating an R_ENTRY relocation
4538 to mark the beginning of a region and hold the unwind bits, and
4539 for creating an R_EXIT relocation to mark the end of the region.
4541 FIXME. ELF should be using the same conventions! The problem
4542 is an unwind requires too much relocation space. Hmmm. Maybe
4543 if we split the unwind bits up between the relocations which
4544 denote the entry and exit points. */
4545 if (last_call_info
->start_symbol
!= NULL
)
4547 char *where
= frag_more (0);
4549 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4550 NULL
, (offsetT
) 0, NULL
,
4551 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4552 (int *) &last_call_info
->ci_unwind
.descriptor
);
4557 /* Handle a .EQU pseudo-op. */
4563 label_symbol_struct
*label_symbol
= pa_get_label ();
4568 symbol
= label_symbol
->lss_label
;
4570 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4572 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4573 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4578 as_bad (".REG must use a label");
4580 as_bad (".EQU must use a label");
4583 pa_undefine_label ();
4584 demand_empty_rest_of_line ();
4587 /* Helper function. Does processing for the end of a function. This
4588 usually involves creating some relocations or building special
4589 symbols to mark the end of the function. */
4596 where
= frag_more (0);
4599 /* Mark the end of the function, stuff away the location of the frag
4600 for the end of the function, and finally call pa_build_unwind_subspace
4601 to add an entry in the unwind table. */
4602 hppa_elf_mark_end_of_function ();
4603 pa_build_unwind_subspace (last_call_info
);
4605 /* SOM defers building of unwind descriptors until the link phase.
4606 The assembler is responsible for creating an R_ENTRY relocation
4607 to mark the beginning of a region and hold the unwind bits, and
4608 for creating an R_EXIT relocation to mark the end of the region.
4610 FIXME. ELF should be using the same conventions! The problem
4611 is an unwind requires too much relocation space. Hmmm. Maybe
4612 if we split the unwind bits up between the relocations which
4613 denote the entry and exit points. */
4614 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4616 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4617 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4621 /* Process a .EXIT pseudo-op. */
4627 /* We must have a valid space and subspace. */
4628 pa_check_current_space_and_subspace ();
4630 if (!within_procedure
)
4631 as_bad (".EXIT must appear within a procedure");
4634 if (!callinfo_found
)
4635 as_bad ("Missing .callinfo");
4638 if (!within_entry_exit
)
4639 as_bad ("No .ENTRY for this .EXIT");
4642 within_entry_exit
= FALSE
;
4647 demand_empty_rest_of_line ();
4650 /* Process a .EXPORT directive. This makes functions external
4651 and provides information such as argument relocation entries
4661 name
= input_line_pointer
;
4662 c
= get_symbol_end ();
4663 /* Make sure the given symbol exists. */
4664 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4666 as_bad ("Cannot define export symbol: %s\n", name
);
4667 p
= input_line_pointer
;
4669 input_line_pointer
++;
4673 /* OK. Set the external bits and process argument relocations. */
4674 S_SET_EXTERNAL (symbol
);
4675 p
= input_line_pointer
;
4677 if (!is_end_of_statement ())
4679 input_line_pointer
++;
4680 pa_type_args (symbol
, 1);
4684 demand_empty_rest_of_line ();
4687 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4690 pa_type_args (symbolP
, is_export
)
4695 unsigned int temp
, arg_reloc
;
4696 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4697 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4699 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4702 input_line_pointer
+= 8;
4703 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4704 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4705 type
= SYMBOL_TYPE_ABSOLUTE
;
4707 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4709 input_line_pointer
+= 4;
4710 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4711 instead one should be IMPORTing/EXPORTing ENTRY types.
4713 Complain if one tries to EXPORT a CODE type since that's never
4714 done. Both GCC and HP C still try to IMPORT CODE types, so
4715 silently fix them to be ENTRY types. */
4716 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4719 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4721 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4722 type
= SYMBOL_TYPE_ENTRY
;
4726 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4727 type
= SYMBOL_TYPE_CODE
;
4730 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4732 input_line_pointer
+= 4;
4733 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4734 type
= SYMBOL_TYPE_DATA
;
4736 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4738 input_line_pointer
+= 5;
4739 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4740 type
= SYMBOL_TYPE_ENTRY
;
4742 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4744 input_line_pointer
+= 9;
4745 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4746 type
= SYMBOL_TYPE_MILLICODE
;
4748 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4750 input_line_pointer
+= 6;
4751 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4752 type
= SYMBOL_TYPE_PLABEL
;
4754 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4756 input_line_pointer
+= 8;
4757 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4758 type
= SYMBOL_TYPE_PRI_PROG
;
4760 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4762 input_line_pointer
+= 8;
4763 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4764 type
= SYMBOL_TYPE_SEC_PROG
;
4767 /* SOM requires much more information about symbol types
4768 than BFD understands. This is how we get this information
4769 to the SOM BFD backend. */
4770 #ifdef obj_set_symbol_type
4771 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4774 /* Now that the type of the exported symbol has been handled,
4775 handle any argument relocation information. */
4776 while (!is_end_of_statement ())
4778 if (*input_line_pointer
== ',')
4779 input_line_pointer
++;
4780 name
= input_line_pointer
;
4781 c
= get_symbol_end ();
4782 /* Argument sources. */
4783 if ((strncasecmp (name
, "argw", 4) == 0))
4785 p
= input_line_pointer
;
4787 input_line_pointer
++;
4788 temp
= atoi (name
+ 4);
4789 name
= input_line_pointer
;
4790 c
= get_symbol_end ();
4791 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4792 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4793 *input_line_pointer
= c
;
4795 /* The return value. */
4796 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4798 p
= input_line_pointer
;
4800 input_line_pointer
++;
4801 name
= input_line_pointer
;
4802 c
= get_symbol_end ();
4803 arg_reloc
= pa_build_arg_reloc (name
);
4804 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4805 *input_line_pointer
= c
;
4807 /* Privelege level. */
4808 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4810 p
= input_line_pointer
;
4812 input_line_pointer
++;
4813 temp
= atoi (input_line_pointer
);
4814 c
= get_symbol_end ();
4815 *input_line_pointer
= c
;
4819 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4820 p
= input_line_pointer
;
4823 if (!is_end_of_statement ())
4824 input_line_pointer
++;
4828 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4829 assembly file must either be defined in the assembly file, or
4830 explicitly IMPORTED from another. */
4839 name
= input_line_pointer
;
4840 c
= get_symbol_end ();
4842 symbol
= symbol_find (name
);
4843 /* Ugh. We might be importing a symbol defined earlier in the file,
4844 in which case all the code below will really screw things up
4845 (set the wrong segment, symbol flags & type, etc). */
4846 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4848 symbol
= symbol_find_or_make (name
);
4849 p
= input_line_pointer
;
4852 if (!is_end_of_statement ())
4854 input_line_pointer
++;
4855 pa_type_args (symbol
, 0);
4859 /* Sigh. To be compatable with the HP assembler and to help
4860 poorly written assembly code, we assign a type based on
4861 the the current segment. Note only BSF_FUNCTION really
4862 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4863 if (now_seg
== text_section
)
4864 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4866 /* If the section is undefined, then the symbol is undefined
4867 Since this is an import, leave the section undefined. */
4868 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4873 /* The symbol was already defined. Just eat everything up to
4874 the end of the current statement. */
4875 while (!is_end_of_statement ())
4876 input_line_pointer
++;
4879 demand_empty_rest_of_line ();
4882 /* Handle a .LABEL pseudo-op. */
4890 name
= input_line_pointer
;
4891 c
= get_symbol_end ();
4893 if (strlen (name
) > 0)
4896 p
= input_line_pointer
;
4901 as_warn ("Missing label name on .LABEL");
4904 if (!is_end_of_statement ())
4906 as_warn ("extra .LABEL arguments ignored.");
4907 ignore_rest_of_line ();
4909 demand_empty_rest_of_line ();
4912 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4918 /* We must have a valid space and subspace. */
4919 pa_check_current_space_and_subspace ();
4924 /* Handle a .LEVEL pseudo-op. */
4932 level
= input_line_pointer
;
4933 if (strncmp (level
, "1.0", 3) == 0)
4935 input_line_pointer
+= 3;
4936 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
4937 as_warn ("could not set architecture and machine");
4939 else if (strncmp (level
, "1.1", 3) == 0)
4941 input_line_pointer
+= 3;
4942 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 11))
4943 as_warn ("could not set architecture and machine");
4947 as_bad ("Unrecognized .LEVEL argument\n");
4948 ignore_rest_of_line ();
4950 demand_empty_rest_of_line ();
4953 /* Handle a .ORIGIN pseudo-op. */
4959 /* We must have a valid space and subspace. */
4960 pa_check_current_space_and_subspace ();
4963 pa_undefine_label ();
4966 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4967 is for static functions. FIXME. Should share more code with .EXPORT. */
4976 name
= input_line_pointer
;
4977 c
= get_symbol_end ();
4979 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4981 as_bad ("Cannot define static symbol: %s\n", name
);
4982 p
= input_line_pointer
;
4984 input_line_pointer
++;
4988 S_CLEAR_EXTERNAL (symbol
);
4989 p
= input_line_pointer
;
4991 if (!is_end_of_statement ())
4993 input_line_pointer
++;
4994 pa_type_args (symbol
, 0);
4998 demand_empty_rest_of_line ();
5001 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5002 of a procedure from a syntatical point of view. */
5008 struct call_info
*call_info
;
5010 /* We must have a valid space and subspace. */
5011 pa_check_current_space_and_subspace ();
5013 if (within_procedure
)
5014 as_fatal ("Nested procedures");
5016 /* Reset global variables for new procedure. */
5017 callinfo_found
= FALSE
;
5018 within_procedure
= TRUE
;
5020 /* Create another call_info structure. */
5021 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5024 as_fatal ("Cannot allocate unwind descriptor\n");
5026 bzero (call_info
, sizeof (struct call_info
));
5028 call_info
->ci_next
= NULL
;
5030 if (call_info_root
== NULL
)
5032 call_info_root
= call_info
;
5033 last_call_info
= call_info
;
5037 last_call_info
->ci_next
= call_info
;
5038 last_call_info
= call_info
;
5041 /* set up defaults on call_info structure */
5043 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5044 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5045 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5047 /* If we got a .PROC pseudo-op, we know that the function is defined
5048 locally. Make sure it gets into the symbol table. */
5050 label_symbol_struct
*label_symbol
= pa_get_label ();
5054 if (label_symbol
->lss_label
)
5056 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5057 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5060 as_bad ("Missing function name for .PROC (corrupted label chain)");
5063 last_call_info
->start_symbol
= NULL
;
5066 demand_empty_rest_of_line ();
5069 /* Process the syntatical end of a procedure. Make sure all the
5070 appropriate pseudo-ops were found within the procedure. */
5077 /* We must have a valid space and subspace. */
5078 pa_check_current_space_and_subspace ();
5080 /* If we are within a procedure definition, make sure we've
5081 defined a label for the procedure; handle case where the
5082 label was defined after the .PROC directive.
5084 Note there's not need to diddle with the segment or fragment
5085 for the label symbol in this case. We have already switched
5086 into the new $CODE$ subspace at this point. */
5087 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
5089 label_symbol_struct
*label_symbol
= pa_get_label ();
5093 if (label_symbol
->lss_label
)
5095 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5096 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5098 /* Also handle allocation of a fixup to hold the unwind
5099 information when the label appears after the proc/procend. */
5100 if (within_entry_exit
)
5102 char *where
= frag_more (0);
5104 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5105 NULL
, (offsetT
) 0, NULL
,
5106 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
5107 (int *) &last_call_info
->ci_unwind
.descriptor
);
5112 as_bad ("Missing function name for .PROC (corrupted label chain)");
5115 as_bad ("Missing function name for .PROC");
5118 if (!within_procedure
)
5119 as_bad ("misplaced .procend");
5121 if (!callinfo_found
)
5122 as_bad ("Missing .callinfo for this procedure");
5124 if (within_entry_exit
)
5125 as_bad ("Missing .EXIT for a .ENTRY");
5128 /* ELF needs to mark the end of each function so that it can compute
5129 the size of the function (apparently its needed in the symbol table). */
5130 hppa_elf_mark_end_of_function ();
5133 within_procedure
= FALSE
;
5134 demand_empty_rest_of_line ();
5135 pa_undefine_label ();
5138 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5139 then create a new space entry to hold the information specified
5140 by the parameters to the .SPACE directive. */
5142 static sd_chain_struct
*
5143 pa_parse_space_stmt (space_name
, create_flag
)
5147 char *name
, *ptemp
, c
;
5148 char loadable
, defined
, private, sort
;
5150 asection
*seg
= NULL
;
5151 sd_chain_struct
*space
;
5153 /* load default values */
5159 if (strcmp (space_name
, "$TEXT$") == 0)
5161 seg
= pa_def_spaces
[0].segment
;
5162 defined
= pa_def_spaces
[0].defined
;
5163 private = pa_def_spaces
[0].private;
5164 sort
= pa_def_spaces
[0].sort
;
5165 spnum
= pa_def_spaces
[0].spnum
;
5167 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5169 seg
= pa_def_spaces
[1].segment
;
5170 defined
= pa_def_spaces
[1].defined
;
5171 private = pa_def_spaces
[1].private;
5172 sort
= pa_def_spaces
[1].sort
;
5173 spnum
= pa_def_spaces
[1].spnum
;
5176 if (!is_end_of_statement ())
5178 print_errors
= FALSE
;
5179 ptemp
= input_line_pointer
+ 1;
5180 /* First see if the space was specified as a number rather than
5181 as a name. According to the PA assembly manual the rest of
5182 the line should be ignored. */
5183 temp
= pa_parse_number (&ptemp
, 0);
5187 input_line_pointer
= ptemp
;
5191 while (!is_end_of_statement ())
5193 input_line_pointer
++;
5194 name
= input_line_pointer
;
5195 c
= get_symbol_end ();
5196 if ((strncasecmp (name
, "spnum", 5) == 0))
5198 *input_line_pointer
= c
;
5199 input_line_pointer
++;
5200 spnum
= get_absolute_expression ();
5202 else if ((strncasecmp (name
, "sort", 4) == 0))
5204 *input_line_pointer
= c
;
5205 input_line_pointer
++;
5206 sort
= get_absolute_expression ();
5208 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5210 *input_line_pointer
= c
;
5213 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5215 *input_line_pointer
= c
;
5218 else if ((strncasecmp (name
, "private", 7) == 0))
5220 *input_line_pointer
= c
;
5225 as_bad ("Invalid .SPACE argument");
5226 *input_line_pointer
= c
;
5227 if (!is_end_of_statement ())
5228 input_line_pointer
++;
5232 print_errors
= TRUE
;
5235 if (create_flag
&& seg
== NULL
)
5236 seg
= subseg_new (space_name
, 0);
5238 /* If create_flag is nonzero, then create the new space with
5239 the attributes computed above. Else set the values in
5240 an already existing space -- this can only happen for
5241 the first occurence of a built-in space. */
5243 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5244 private, sort
, seg
, 1);
5247 space
= is_defined_space (space_name
);
5248 SPACE_SPNUM (space
) = spnum
;
5249 SPACE_DEFINED (space
) = defined
& 1;
5250 SPACE_USER_DEFINED (space
) = 1;
5253 #ifdef obj_set_section_attributes
5254 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5260 /* Handle a .SPACE pseudo-op; this switches the current space to the
5261 given space, creating the new space if necessary. */
5267 char *name
, c
, *space_name
, *save_s
;
5269 sd_chain_struct
*sd_chain
;
5271 if (within_procedure
)
5273 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5274 ignore_rest_of_line ();
5278 /* Check for some of the predefined spaces. FIXME: most of the code
5279 below is repeated several times, can we extract the common parts
5280 and place them into a subroutine or something similar? */
5281 /* FIXME Is this (and the next IF stmt) really right?
5282 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5283 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5285 input_line_pointer
+= 6;
5286 sd_chain
= is_defined_space ("$TEXT$");
5287 if (sd_chain
== NULL
)
5288 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5289 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5290 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5292 current_space
= sd_chain
;
5293 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5295 = pa_subsegment_to_subspace (text_section
,
5296 sd_chain
->sd_last_subseg
);
5297 demand_empty_rest_of_line ();
5300 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5302 input_line_pointer
+= 9;
5303 sd_chain
= is_defined_space ("$PRIVATE$");
5304 if (sd_chain
== NULL
)
5305 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5306 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5307 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5309 current_space
= sd_chain
;
5310 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5312 = pa_subsegment_to_subspace (data_section
,
5313 sd_chain
->sd_last_subseg
);
5314 demand_empty_rest_of_line ();
5317 if (!strncasecmp (input_line_pointer
,
5318 GDB_DEBUG_SPACE_NAME
,
5319 strlen (GDB_DEBUG_SPACE_NAME
)))
5321 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5322 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5323 if (sd_chain
== NULL
)
5324 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5325 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5326 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5328 current_space
= sd_chain
;
5331 asection
*gdb_section
5332 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5334 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5336 = pa_subsegment_to_subspace (gdb_section
,
5337 sd_chain
->sd_last_subseg
);
5339 demand_empty_rest_of_line ();
5343 /* It could be a space specified by number. */
5345 save_s
= input_line_pointer
;
5346 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5348 if ((sd_chain
= pa_find_space_by_number (temp
)))
5350 current_space
= sd_chain
;
5352 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5354 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5355 sd_chain
->sd_last_subseg
);
5356 demand_empty_rest_of_line ();
5361 /* Not a number, attempt to create a new space. */
5363 input_line_pointer
= save_s
;
5364 name
= input_line_pointer
;
5365 c
= get_symbol_end ();
5366 space_name
= xmalloc (strlen (name
) + 1);
5367 strcpy (space_name
, name
);
5368 *input_line_pointer
= c
;
5370 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5371 current_space
= sd_chain
;
5373 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5374 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5375 sd_chain
->sd_last_subseg
);
5376 demand_empty_rest_of_line ();
5380 /* Switch to a new space. (I think). FIXME. */
5389 sd_chain_struct
*space
;
5391 name
= input_line_pointer
;
5392 c
= get_symbol_end ();
5393 space
= is_defined_space (name
);
5397 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5400 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5402 *input_line_pointer
= c
;
5403 demand_empty_rest_of_line ();
5406 /* If VALUE is an exact power of two between zero and 2^31, then
5407 return log2 (VALUE). Else return -1. */
5415 while ((1 << shift
) != value
&& shift
< 32)
5424 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5425 given subspace, creating the new subspace if necessary.
5427 FIXME. Should mirror pa_space more closely, in particular how
5428 they're broken up into subroutines. */
5431 pa_subspace (create_new
)
5434 char *name
, *ss_name
, *alias
, c
;
5435 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5436 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5437 sd_chain_struct
*space
;
5438 ssd_chain_struct
*ssd
;
5441 if (current_space
== NULL
)
5442 as_fatal ("Must be in a space before changing or declaring subspaces.\n");
5444 if (within_procedure
)
5446 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5447 ignore_rest_of_line ();
5451 name
= input_line_pointer
;
5452 c
= get_symbol_end ();
5453 ss_name
= xmalloc (strlen (name
) + 1);
5454 strcpy (ss_name
, name
);
5455 *input_line_pointer
= c
;
5457 /* Load default values. */
5470 space
= current_space
;
5474 ssd
= is_defined_subspace (ss_name
);
5475 /* Allow user to override the builtin attributes of subspaces. But
5476 only allow the attributes to be changed once! */
5477 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5479 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5480 current_subspace
= ssd
;
5481 if (!is_end_of_statement ())
5482 as_warn ("Parameters of an existing subspace can\'t be modified");
5483 demand_empty_rest_of_line ();
5488 /* A new subspace. Load default values if it matches one of
5489 the builtin subspaces. */
5491 while (pa_def_subspaces
[i
].name
)
5493 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5495 loadable
= pa_def_subspaces
[i
].loadable
;
5496 common
= pa_def_subspaces
[i
].common
;
5497 dup_common
= pa_def_subspaces
[i
].dup_common
;
5498 code_only
= pa_def_subspaces
[i
].code_only
;
5499 zero
= pa_def_subspaces
[i
].zero
;
5500 space_index
= pa_def_subspaces
[i
].space_index
;
5501 alignment
= pa_def_subspaces
[i
].alignment
;
5502 quadrant
= pa_def_subspaces
[i
].quadrant
;
5503 access
= pa_def_subspaces
[i
].access
;
5504 sort
= pa_def_subspaces
[i
].sort
;
5505 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5506 alias
= pa_def_subspaces
[i
].alias
;
5513 /* We should be working with a new subspace now. Fill in
5514 any information as specified by the user. */
5515 if (!is_end_of_statement ())
5517 input_line_pointer
++;
5518 while (!is_end_of_statement ())
5520 name
= input_line_pointer
;
5521 c
= get_symbol_end ();
5522 if ((strncasecmp (name
, "quad", 4) == 0))
5524 *input_line_pointer
= c
;
5525 input_line_pointer
++;
5526 quadrant
= get_absolute_expression ();
5528 else if ((strncasecmp (name
, "align", 5) == 0))
5530 *input_line_pointer
= c
;
5531 input_line_pointer
++;
5532 alignment
= get_absolute_expression ();
5533 if (log2 (alignment
) == -1)
5535 as_bad ("Alignment must be a power of 2");
5539 else if ((strncasecmp (name
, "access", 6) == 0))
5541 *input_line_pointer
= c
;
5542 input_line_pointer
++;
5543 access
= get_absolute_expression ();
5545 else if ((strncasecmp (name
, "sort", 4) == 0))
5547 *input_line_pointer
= c
;
5548 input_line_pointer
++;
5549 sort
= get_absolute_expression ();
5551 else if ((strncasecmp (name
, "code_only", 9) == 0))
5553 *input_line_pointer
= c
;
5556 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5558 *input_line_pointer
= c
;
5561 else if ((strncasecmp (name
, "common", 6) == 0))
5563 *input_line_pointer
= c
;
5566 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5568 *input_line_pointer
= c
;
5571 else if ((strncasecmp (name
, "zero", 4) == 0))
5573 *input_line_pointer
= c
;
5576 else if ((strncasecmp (name
, "first", 5) == 0))
5577 as_bad ("FIRST not supported as a .SUBSPACE argument");
5579 as_bad ("Invalid .SUBSPACE argument");
5580 if (!is_end_of_statement ())
5581 input_line_pointer
++;
5585 /* Compute a reasonable set of BFD flags based on the information
5586 in the .subspace directive. */
5587 applicable
= bfd_applicable_section_flags (stdoutput
);
5590 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5593 if (common
|| dup_common
)
5594 flags
|= SEC_IS_COMMON
;
5596 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5598 /* This is a zero-filled subspace (eg BSS). */
5600 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
5602 applicable
&= flags
;
5604 /* If this is an existing subspace, then we want to use the
5605 segment already associated with the subspace.
5607 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5608 lots of sections. It might be a problem in the PA ELF
5609 code, I do not know yet. For now avoid creating anything
5610 but the "standard" sections for ELF. */
5612 section
= subseg_force_new (ss_name
, 0);
5614 section
= ssd
->ssd_seg
;
5616 section
= subseg_new (alias
, 0);
5617 else if (!alias
&& USE_ALIASES
)
5619 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5620 demand_empty_rest_of_line ();
5624 section
= subseg_new (ss_name
, 0);
5627 seg_info (section
)->bss
= 1;
5629 /* Now set the flags. */
5630 bfd_set_section_flags (stdoutput
, section
, applicable
);
5632 /* Record any alignment request for this section. */
5633 record_alignment (section
, log2 (alignment
));
5635 /* Set the starting offset for this section. */
5636 bfd_set_section_vma (stdoutput
, section
,
5637 pa_subspace_start (space
, quadrant
));
5639 /* Now that all the flags are set, update an existing subspace,
5640 or create a new one. */
5643 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5644 code_only
, common
, dup_common
,
5645 sort
, zero
, access
, space_index
,
5646 alignment
, quadrant
,
5649 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5651 dup_common
, zero
, sort
,
5652 access
, space_index
,
5653 alignment
, quadrant
, section
);
5655 demand_empty_rest_of_line ();
5656 current_subspace
->ssd_seg
= section
;
5657 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5659 SUBSPACE_DEFINED (current_subspace
) = 1;
5663 /* Create default space and subspace dictionaries. */
5670 space_dict_root
= NULL
;
5671 space_dict_last
= NULL
;
5674 while (pa_def_spaces
[i
].name
)
5678 /* Pick the right name to use for the new section. */
5679 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5680 name
= pa_def_spaces
[i
].alias
;
5682 name
= pa_def_spaces
[i
].name
;
5684 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5685 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5686 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5687 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5688 pa_def_spaces
[i
].segment
, 0);
5693 while (pa_def_subspaces
[i
].name
)
5696 int applicable
, subsegment
;
5697 asection
*segment
= NULL
;
5698 sd_chain_struct
*space
;
5700 /* Pick the right name for the new section and pick the right
5701 subsegment number. */
5702 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5704 name
= pa_def_subspaces
[i
].alias
;
5705 subsegment
= pa_def_subspaces
[i
].subsegment
;
5709 name
= pa_def_subspaces
[i
].name
;
5713 /* Create the new section. */
5714 segment
= subseg_new (name
, subsegment
);
5717 /* For SOM we want to replace the standard .text, .data, and .bss
5718 sections with our own. We also want to set BFD flags for
5719 all the built-in subspaces. */
5720 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5722 text_section
= segment
;
5723 applicable
= bfd_applicable_section_flags (stdoutput
);
5724 bfd_set_section_flags (stdoutput
, segment
,
5725 applicable
& (SEC_ALLOC
| SEC_LOAD
5726 | SEC_RELOC
| SEC_CODE
5728 | SEC_HAS_CONTENTS
));
5730 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5732 data_section
= segment
;
5733 applicable
= bfd_applicable_section_flags (stdoutput
);
5734 bfd_set_section_flags (stdoutput
, segment
,
5735 applicable
& (SEC_ALLOC
| SEC_LOAD
5737 | SEC_HAS_CONTENTS
));
5741 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5743 bss_section
= segment
;
5744 applicable
= bfd_applicable_section_flags (stdoutput
);
5745 bfd_set_section_flags (stdoutput
, segment
,
5746 applicable
& SEC_ALLOC
);
5748 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5750 applicable
= bfd_applicable_section_flags (stdoutput
);
5751 bfd_set_section_flags (stdoutput
, segment
,
5752 applicable
& (SEC_ALLOC
| SEC_LOAD
5755 | SEC_HAS_CONTENTS
));
5757 else if (!strcmp (pa_def_subspaces
[i
].name
, "$MILLICODE$")
5760 applicable
= bfd_applicable_section_flags (stdoutput
);
5761 bfd_set_section_flags (stdoutput
, segment
,
5762 applicable
& (SEC_ALLOC
| SEC_LOAD
5765 | SEC_HAS_CONTENTS
));
5767 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5769 applicable
= bfd_applicable_section_flags (stdoutput
);
5770 bfd_set_section_flags (stdoutput
, segment
,
5771 applicable
& (SEC_ALLOC
| SEC_LOAD
5774 | SEC_HAS_CONTENTS
));
5777 /* Find the space associated with this subspace. */
5778 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5779 def_space_index
].segment
);
5782 as_fatal ("Internal error: Unable to find containing space for %s.",
5783 pa_def_subspaces
[i
].name
);
5786 create_new_subspace (space
, name
,
5787 pa_def_subspaces
[i
].loadable
,
5788 pa_def_subspaces
[i
].code_only
,
5789 pa_def_subspaces
[i
].common
,
5790 pa_def_subspaces
[i
].dup_common
,
5791 pa_def_subspaces
[i
].zero
,
5792 pa_def_subspaces
[i
].sort
,
5793 pa_def_subspaces
[i
].access
,
5794 pa_def_subspaces
[i
].space_index
,
5795 pa_def_subspaces
[i
].alignment
,
5796 pa_def_subspaces
[i
].quadrant
,
5804 /* Create a new space NAME, with the appropriate flags as defined
5805 by the given parameters. */
5807 static sd_chain_struct
*
5808 create_new_space (name
, spnum
, loadable
, defined
, private,
5809 sort
, seg
, user_defined
)
5819 sd_chain_struct
*chain_entry
;
5821 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5823 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5826 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5827 strcpy (SPACE_NAME (chain_entry
), name
);
5828 SPACE_DEFINED (chain_entry
) = defined
;
5829 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5830 SPACE_SPNUM (chain_entry
) = spnum
;
5832 chain_entry
->sd_seg
= seg
;
5833 chain_entry
->sd_last_subseg
= -1;
5834 chain_entry
->sd_subspaces
= NULL
;
5835 chain_entry
->sd_next
= NULL
;
5837 /* Find spot for the new space based on its sort key. */
5838 if (!space_dict_last
)
5839 space_dict_last
= chain_entry
;
5841 if (space_dict_root
== NULL
)
5842 space_dict_root
= chain_entry
;
5845 sd_chain_struct
*chain_pointer
;
5846 sd_chain_struct
*prev_chain_pointer
;
5848 chain_pointer
= space_dict_root
;
5849 prev_chain_pointer
= NULL
;
5851 while (chain_pointer
)
5853 prev_chain_pointer
= chain_pointer
;
5854 chain_pointer
= chain_pointer
->sd_next
;
5857 /* At this point we've found the correct place to add the new
5858 entry. So add it and update the linked lists as appropriate. */
5859 if (prev_chain_pointer
)
5861 chain_entry
->sd_next
= chain_pointer
;
5862 prev_chain_pointer
->sd_next
= chain_entry
;
5866 space_dict_root
= chain_entry
;
5867 chain_entry
->sd_next
= chain_pointer
;
5870 if (chain_entry
->sd_next
== NULL
)
5871 space_dict_last
= chain_entry
;
5874 /* This is here to catch predefined spaces which do not get
5875 modified by the user's input. Another call is found at
5876 the bottom of pa_parse_space_stmt to handle cases where
5877 the user modifies a predefined space. */
5878 #ifdef obj_set_section_attributes
5879 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5885 /* Create a new subspace NAME, with the appropriate flags as defined
5886 by the given parameters.
5888 Add the new subspace to the subspace dictionary chain in numerical
5889 order as defined by the SORT entries. */
5891 static ssd_chain_struct
*
5892 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5893 dup_common
, is_zero
, sort
, access
, space_index
,
5894 alignment
, quadrant
, seg
)
5895 sd_chain_struct
*space
;
5897 int loadable
, code_only
, common
, dup_common
, is_zero
;
5905 ssd_chain_struct
*chain_entry
;
5907 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5909 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5911 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5912 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5914 /* Initialize subspace_defined. When we hit a .subspace directive
5915 we'll set it to 1 which "locks-in" the subspace attributes. */
5916 SUBSPACE_DEFINED (chain_entry
) = 0;
5918 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5919 chain_entry
->ssd_seg
= seg
;
5920 chain_entry
->ssd_next
= NULL
;
5922 /* Find spot for the new subspace based on its sort key. */
5923 if (space
->sd_subspaces
== NULL
)
5924 space
->sd_subspaces
= chain_entry
;
5927 ssd_chain_struct
*chain_pointer
;
5928 ssd_chain_struct
*prev_chain_pointer
;
5930 chain_pointer
= space
->sd_subspaces
;
5931 prev_chain_pointer
= NULL
;
5933 while (chain_pointer
)
5935 prev_chain_pointer
= chain_pointer
;
5936 chain_pointer
= chain_pointer
->ssd_next
;
5939 /* Now we have somewhere to put the new entry. Insert it and update
5941 if (prev_chain_pointer
)
5943 chain_entry
->ssd_next
= chain_pointer
;
5944 prev_chain_pointer
->ssd_next
= chain_entry
;
5948 space
->sd_subspaces
= chain_entry
;
5949 chain_entry
->ssd_next
= chain_pointer
;
5953 #ifdef obj_set_subsection_attributes
5954 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5961 /* Update the information for the given subspace based upon the
5962 various arguments. Return the modified subspace chain entry. */
5964 static ssd_chain_struct
*
5965 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5966 zero
, access
, space_index
, alignment
, quadrant
, section
)
5967 sd_chain_struct
*space
;
5981 ssd_chain_struct
*chain_entry
;
5983 chain_entry
= is_defined_subspace (name
);
5985 #ifdef obj_set_subsection_attributes
5986 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5993 /* Return the space chain entry for the space with the name NAME or
5994 NULL if no such space exists. */
5996 static sd_chain_struct
*
5997 is_defined_space (name
)
6000 sd_chain_struct
*chain_pointer
;
6002 for (chain_pointer
= space_dict_root
;
6004 chain_pointer
= chain_pointer
->sd_next
)
6006 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6007 return chain_pointer
;
6010 /* No mapping from segment to space was found. Return NULL. */
6014 /* Find and return the space associated with the given seg. If no mapping
6015 from the given seg to a space is found, then return NULL.
6017 Unlike subspaces, the number of spaces is not expected to grow much,
6018 so a linear exhaustive search is OK here. */
6020 static sd_chain_struct
*
6021 pa_segment_to_space (seg
)
6024 sd_chain_struct
*space_chain
;
6026 /* Walk through each space looking for the correct mapping. */
6027 for (space_chain
= space_dict_root
;
6029 space_chain
= space_chain
->sd_next
)
6031 if (space_chain
->sd_seg
== seg
)
6035 /* Mapping was not found. Return NULL. */
6039 /* Return the space chain entry for the subspace with the name NAME or
6040 NULL if no such subspace exists.
6042 Uses a linear search through all the spaces and subspaces, this may
6043 not be appropriate if we ever being placing each function in its
6046 static ssd_chain_struct
*
6047 is_defined_subspace (name
)
6050 sd_chain_struct
*space_chain
;
6051 ssd_chain_struct
*subspace_chain
;
6053 /* Walk through each space. */
6054 for (space_chain
= space_dict_root
;
6056 space_chain
= space_chain
->sd_next
)
6058 /* Walk through each subspace looking for a name which matches. */
6059 for (subspace_chain
= space_chain
->sd_subspaces
;
6061 subspace_chain
= subspace_chain
->ssd_next
)
6062 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6063 return subspace_chain
;
6066 /* Subspace wasn't found. Return NULL. */
6070 /* Find and return the subspace associated with the given seg. If no
6071 mapping from the given seg to a subspace is found, then return NULL.
6073 If we ever put each procedure/function within its own subspace
6074 (to make life easier on the compiler and linker), then this will have
6075 to become more efficient. */
6077 static ssd_chain_struct
*
6078 pa_subsegment_to_subspace (seg
, subseg
)
6082 sd_chain_struct
*space_chain
;
6083 ssd_chain_struct
*subspace_chain
;
6085 /* Walk through each space. */
6086 for (space_chain
= space_dict_root
;
6088 space_chain
= space_chain
->sd_next
)
6090 if (space_chain
->sd_seg
== seg
)
6092 /* Walk through each subspace within each space looking for
6093 the correct mapping. */
6094 for (subspace_chain
= space_chain
->sd_subspaces
;
6096 subspace_chain
= subspace_chain
->ssd_next
)
6097 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6098 return subspace_chain
;
6102 /* No mapping from subsegment to subspace found. Return NULL. */
6106 /* Given a number, try and find a space with the name number.
6108 Return a pointer to a space dictionary chain entry for the space
6109 that was found or NULL on failure. */
6111 static sd_chain_struct
*
6112 pa_find_space_by_number (number
)
6115 sd_chain_struct
*space_chain
;
6117 for (space_chain
= space_dict_root
;
6119 space_chain
= space_chain
->sd_next
)
6121 if (SPACE_SPNUM (space_chain
) == number
)
6125 /* No appropriate space found. Return NULL. */
6129 /* Return the starting address for the given subspace. If the starting
6130 address is unknown then return zero. */
6133 pa_subspace_start (space
, quadrant
)
6134 sd_chain_struct
*space
;
6137 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6138 is not correct for the PA OSF1 port. */
6139 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6141 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6147 /* FIXME. Needs documentation. */
6149 pa_next_subseg (space
)
6150 sd_chain_struct
*space
;
6153 space
->sd_last_subseg
++;
6154 return space
->sd_last_subseg
;
6157 /* Helper function for pa_stringer. Used to find the end of
6164 unsigned int c
= *s
& CHAR_MASK
;
6166 /* We must have a valid space and subspace. */
6167 pa_check_current_space_and_subspace ();
6180 /* Handle a .STRING type pseudo-op. */
6183 pa_stringer (append_zero
)
6186 char *s
, num_buf
[4];
6190 /* Preprocess the string to handle PA-specific escape sequences.
6191 For example, \xDD where DD is a hexidecimal number should be
6192 changed to \OOO where OOO is an octal number. */
6194 /* Skip the opening quote. */
6195 s
= input_line_pointer
+ 1;
6197 while (is_a_char (c
= pa_stringer_aux (s
++)))
6204 /* Handle \x<num>. */
6207 unsigned int number
;
6212 /* Get pas the 'x'. */
6214 for (num_digit
= 0, number
= 0, dg
= *s
;
6216 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6217 || (dg
>= 'A' && dg
<= 'F'));
6221 number
= number
* 16 + dg
- '0';
6222 else if (dg
>= 'a' && dg
<= 'f')
6223 number
= number
* 16 + dg
- 'a' + 10;
6225 number
= number
* 16 + dg
- 'A' + 10;
6235 sprintf (num_buf
, "%02o", number
);
6238 sprintf (num_buf
, "%03o", number
);
6241 for (i
= 0; i
<= num_digit
; i
++)
6242 s_start
[i
] = num_buf
[i
];
6246 /* This might be a "\"", skip over the escaped char. */
6253 stringer (append_zero
);
6254 pa_undefine_label ();
6257 /* Handle a .VERSION pseudo-op. */
6264 pa_undefine_label ();
6267 /* Handle a .COPYRIGHT pseudo-op. */
6270 pa_copyright (unused
)
6274 pa_undefine_label ();
6277 /* Just like a normal cons, but when finished we have to undefine
6278 the latest space label. */
6285 pa_undefine_label ();
6288 /* Switch to the data space. As usual delete our label. */
6294 current_space
= is_defined_space ("$PRIVATE$");
6296 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6298 pa_undefine_label ();
6301 /* Like float_cons, but we need to undefine our label. */
6304 pa_float_cons (float_type
)
6307 float_cons (float_type
);
6308 pa_undefine_label ();
6311 /* Like s_fill, but delete our label when finished. */
6317 /* We must have a valid space and subspace. */
6318 pa_check_current_space_and_subspace ();
6321 pa_undefine_label ();
6324 /* Like lcomm, but delete our label when finished. */
6327 pa_lcomm (needs_align
)
6330 /* We must have a valid space and subspace. */
6331 pa_check_current_space_and_subspace ();
6333 s_lcomm (needs_align
);
6334 pa_undefine_label ();
6337 /* Like lsym, but delete our label when finished. */
6343 /* We must have a valid space and subspace. */
6344 pa_check_current_space_and_subspace ();
6347 pa_undefine_label ();
6350 /* Switch to the text space. Like s_text, but delete our
6351 label when finished. */
6356 current_space
= is_defined_space ("$TEXT$");
6358 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6361 pa_undefine_label ();
6364 /* On the PA relocations which involve function symbols must not be
6365 adjusted. This so that the linker can know when/how to create argument
6366 relocation stubs for indirect calls and calls to static functions.
6368 "T" field selectors create DLT relative fixups for accessing
6369 globals and statics in PIC code; each DLT relative fixup creates
6370 an entry in the DLT table. The entries contain the address of
6371 the final target (eg accessing "foo" would create a DLT entry
6372 with the address of "foo").
6374 Unfortunately, the HP linker doesn't take into account any addend
6375 when generating the DLT; so accessing $LIT$+8 puts the address of
6376 $LIT$ into the DLT rather than the address of $LIT$+8.
6378 The end result is we can't perform relocation symbol reductions for
6379 any fixup which creates entries in the DLT (eg they use "T" field
6382 Reject reductions involving symbols with external scope; such
6383 reductions make life a living hell for object file editors.
6385 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6386 the code space. The SOM BFD backend doesn't know how to pull the
6387 right bits out of an instruction. */
6390 hppa_fix_adjustable (fixp
)
6393 struct hppa_fix_struct
*hppa_fix
;
6395 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6398 /* Reject reductions of symbols in 32bit relocs. */
6399 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6402 /* Reject reductions of symbols in sym1-sym2 expressions when
6403 the fixup will occur in a CODE subspace.
6405 XXX FIXME: Long term we probably want to reject all of these;
6406 for example reducing in the debug section would lose if we ever
6407 supported using the optimizing hp linker. */
6410 && (hppa_fix
->segment
->flags
& SEC_CODE
))
6412 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6413 fixp
->fx_subsy
->sy_used_in_reloc
= 1;
6417 /* We can't adjust any relocs that use LR% and RR% field selectors.
6418 That confuses the HP linker. */
6419 if (hppa_fix
->fx_r_field
== e_lrsel
6420 || hppa_fix
->fx_r_field
== e_rrsel
6421 || hppa_fix
->fx_r_field
== e_nlrsel
)
6425 /* Reject reductions of symbols in DLT relative relocs,
6426 relocations with plabels. */
6427 if (hppa_fix
->fx_r_field
== e_tsel
6428 || hppa_fix
->fx_r_field
== e_ltsel
6429 || hppa_fix
->fx_r_field
== e_rtsel
6430 || hppa_fix
->fx_r_field
== e_psel
6431 || hppa_fix
->fx_r_field
== e_esel
6432 || hppa_fix
->fx_r_field
== e_rpsel
6433 || hppa_fix
->fx_r_field
== e_lpsel
)
6436 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6439 /* Reject reductions of function symbols. */
6440 if (fixp
->fx_addsy
== 0
6441 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6447 /* Return nonzero if the fixup in FIXP will require a relocation,
6448 even it if appears that the fixup could be completely handled
6452 hppa_force_relocation (fixp
)
6455 struct hppa_fix_struct
*hppa_fixp
;
6458 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6460 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
6461 || fixp
->fx_r_type
== R_HPPA_BEGIN_BRTAB
6462 || fixp
->fx_r_type
== R_HPPA_END_BRTAB
6463 || fixp
->fx_r_type
== R_HPPA_BEGIN_TRY
6464 || fixp
->fx_r_type
== R_HPPA_END_TRY
6465 || (fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
6466 && (hppa_fixp
->segment
->flags
& SEC_CODE
) != 0))
6470 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6471 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6473 /* It is necessary to force PC-relative calls/jumps to have a relocation
6474 entry if they're going to need either a argument relocation or long
6475 call stub. FIXME. Can't we need the same for absolute calls? */
6476 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6477 && (arg_reloc_stub_needed (((obj_symbol_type
*)
6478 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6480 hppa_fixp
->fx_arg_reloc
)))
6482 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
6483 - md_pcrel_from (fixp
));
6484 /* Now check and see if we're going to need a long-branch stub. */
6485 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
6486 && (distance
> 262143 || distance
< -262144))
6489 #undef arg_reloc_stub_needed
6491 /* No need (yet) to force another relocations to be emitted. */
6495 /* Now for some ELF specific code. FIXME. */
6497 /* Mark the end of a function so that it's possible to compute
6498 the size of the function in hppa_elf_final_processing. */
6501 hppa_elf_mark_end_of_function ()
6503 /* ELF does not have EXIT relocations. All we do is create a
6504 temporary symbol marking the end of the function. */
6505 char *name
= (char *)
6506 xmalloc (strlen ("L$\001end_") +
6507 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6513 strcpy (name
, "L$\001end_");
6514 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6516 /* If we have a .exit followed by a .procend, then the
6517 symbol will have already been defined. */
6518 symbolP
= symbol_find (name
);
6521 /* The symbol has already been defined! This can
6522 happen if we have a .exit followed by a .procend.
6524 This is *not* an error. All we want to do is free
6525 the memory we just allocated for the name and continue. */
6530 /* symbol value should be the offset of the
6531 last instruction of the function */
6532 symbolP
= symbol_new (name
, now_seg
, (valueT
) (frag_now_fix () - 4),
6536 symbolP
->bsym
->flags
= BSF_LOCAL
;
6537 symbol_table_insert (symbolP
);
6541 last_call_info
->end_symbol
= symbolP
;
6543 as_bad ("Symbol '%s' could not be created.", name
);
6547 as_bad ("No memory for symbol name.");
6551 /* For ELF, this function serves one purpose: to setup the st_size
6552 field of STT_FUNC symbols. To do this, we need to scan the
6553 call_info structure list, determining st_size in by taking the
6554 difference in the address of the beginning/end marker symbols. */
6557 elf_hppa_final_processing ()
6559 struct call_info
*call_info_pointer
;
6561 for (call_info_pointer
= call_info_root
;
6563 call_info_pointer
= call_info_pointer
->ci_next
)
6565 elf_symbol_type
*esym
6566 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6567 esym
->internal_elf_sym
.st_size
=
6568 S_GET_VALUE (call_info_pointer
->end_symbol
)
6569 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;