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_call
PARAMS ((int));
488 static void pa_call_args
PARAMS ((struct call_desc
*));
489 static void pa_callinfo
PARAMS ((int));
490 static void pa_code
PARAMS ((int));
491 static void pa_comm
PARAMS ((int));
492 static void pa_copyright
PARAMS ((int));
493 static void pa_end
PARAMS ((int));
494 static void pa_enter
PARAMS ((int));
495 static void pa_entry
PARAMS ((int));
496 static void pa_equ
PARAMS ((int));
497 static void pa_exit
PARAMS ((int));
498 static void pa_export
PARAMS ((int));
499 static void pa_type_args
PARAMS ((symbolS
*, int));
500 static void pa_import
PARAMS ((int));
501 static void pa_label
PARAMS ((int));
502 static void pa_leave
PARAMS ((int));
503 static void pa_level
PARAMS ((int));
504 static void pa_origin
PARAMS ((int));
505 static void pa_proc
PARAMS ((int));
506 static void pa_procend
PARAMS ((int));
507 static void pa_space
PARAMS ((int));
508 static void pa_spnum
PARAMS ((int));
509 static void pa_subspace
PARAMS ((int));
510 static void pa_param
PARAMS ((int));
511 static void pa_undefine_label
PARAMS ((void));
512 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
513 struct pa_11_fp_reg_struct
*));
514 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
515 static label_symbol_struct
*pa_get_label
PARAMS ((void));
516 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
519 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
524 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
525 char *, int, int, int,
529 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
530 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
531 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
532 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
534 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
535 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
536 static void pa_ip
PARAMS ((char *));
537 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
538 long, expressionS
*, int,
539 bfd_reloc_code_real_type
,
540 enum hppa_reloc_field_selector_type
,
542 static int is_end_of_statement
PARAMS ((void));
543 static int reg_name_search
PARAMS ((char *));
544 static int pa_chk_field_selector
PARAMS ((char **));
545 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
546 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
547 static void process_exit
PARAMS ((void));
548 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
549 static int log2
PARAMS ((int));
550 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
551 static unsigned int pa_stringer_aux
PARAMS ((char *));
552 static void pa_spaces_begin
PARAMS ((void));
553 static void hppa_elf_mark_end_of_function
PARAMS ((void));
555 /* File and gloally scoped variable declarations. */
557 /* Root and final entry in the space chain. */
558 static sd_chain_struct
*space_dict_root
;
559 static sd_chain_struct
*space_dict_last
;
561 /* The current space and subspace. */
562 static sd_chain_struct
*current_space
;
563 static ssd_chain_struct
*current_subspace
;
565 /* Root of the call_info chain. */
566 static struct call_info
*call_info_root
;
568 /* The last call_info (for functions) structure
569 seen so it can be associated with fixups and
571 static struct call_info
*last_call_info
;
573 /* The last call description (for actual calls). */
574 static struct call_desc last_call_desc
;
576 /* Jumps are always the same size -- one instruction. */
577 int md_short_jump_size
= 4;
578 int md_long_jump_size
= 4;
580 /* handle of the OPCODE hash table */
581 static struct hash_control
*op_hash
= NULL
;
583 /* This array holds the chars that always start a comment. If the
584 pre-processor is disabled, these aren't very useful. */
585 const char comment_chars
[] = ";";
587 /* Table of pseudo ops for the PA. FIXME -- how many of these
588 are now redundant with the overall GAS and the object file
590 const pseudo_typeS md_pseudo_table
[] =
592 /* align pseudo-ops on the PA specify the actual alignment requested,
593 not the log2 of the requested alignment. */
594 {"align", pa_align
, 8},
595 {"begin_brtab", pa_brtab
, 1},
596 {"block", pa_block
, 1},
597 {"blockz", pa_block
, 0},
598 {"byte", pa_cons
, 1},
599 {"call", pa_call
, 0},
600 {"callinfo", pa_callinfo
, 0},
601 {"code", pa_code
, 0},
602 {"comm", pa_comm
, 0},
603 {"copyright", pa_copyright
, 0},
604 {"data", pa_data
, 0},
605 {"double", pa_float_cons
, 'd'},
607 {"end_brtab", pa_brtab
, 0},
608 {"enter", pa_enter
, 0},
609 {"entry", pa_entry
, 0},
611 {"exit", pa_exit
, 0},
612 {"export", pa_export
, 0},
613 {"fill", pa_fill
, 0},
614 {"float", pa_float_cons
, 'f'},
615 {"half", pa_cons
, 2},
616 {"import", pa_import
, 0},
618 {"label", pa_label
, 0},
619 {"lcomm", pa_lcomm
, 0},
620 {"leave", pa_leave
, 0},
621 {"level", pa_level
, 0},
622 {"long", pa_cons
, 4},
623 {"lsym", pa_lsym
, 0},
624 {"nsubspa", pa_subspace
, 1},
625 {"octa", pa_cons
, 16},
626 {"org", pa_origin
, 0},
627 {"origin", pa_origin
, 0},
628 {"param", pa_param
, 0},
629 {"proc", pa_proc
, 0},
630 {"procend", pa_procend
, 0},
631 {"quad", pa_cons
, 8},
633 {"short", pa_cons
, 2},
634 {"single", pa_float_cons
, 'f'},
635 {"space", pa_space
, 0},
636 {"spnum", pa_spnum
, 0},
637 {"string", pa_stringer
, 0},
638 {"stringz", pa_stringer
, 1},
639 {"subspa", pa_subspace
, 0},
640 {"text", pa_text
, 0},
641 {"version", pa_version
, 0},
642 {"word", pa_cons
, 4},
646 /* This array holds the chars that only start a comment at the beginning of
647 a line. If the line seems to have the form '# 123 filename'
648 .line and .file directives will appear in the pre-processed output.
650 Note that input_file.c hand checks for '#' at the beginning of the
651 first line of the input file. This is because the compiler outputs
652 #NO_APP at the beginning of its output.
654 Also note that C style comments will always work. */
655 const char line_comment_chars
[] = "#";
657 /* This array holds the characters which act as line separators. */
658 const char line_separator_chars
[] = "!";
660 /* Chars that can be used to separate mant from exp in floating point nums. */
661 const char EXP_CHARS
[] = "eE";
663 /* Chars that mean this number is a floating point constant.
664 As in 0f12.456 or 0d1.2345e12.
666 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
667 changed in read.c. Ideally it shouldn't hae to know abou it at
668 all, but nothing is ideal around here. */
669 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
671 static struct pa_it the_insn
;
673 /* Points to the end of an expression just parsed by get_expressoin
674 and friends. FIXME. This shouldn't be handled with a file-global
676 static char *expr_end
;
678 /* Nonzero if a .callinfo appeared within the current procedure. */
679 static int callinfo_found
;
681 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
682 static int within_entry_exit
;
684 /* Nonzero if the assembler is currently within a procedure definition. */
685 static int within_procedure
;
687 /* Handle on strucutre which keep track of the last symbol
688 seen in each subspace. */
689 static label_symbol_struct
*label_symbols_rootp
= NULL
;
691 /* Holds the last field selector. */
692 static int hppa_field_selector
;
694 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
695 static symbolS
*dummy_symbol
;
697 /* Nonzero if errors are to be printed. */
698 static int print_errors
= 1;
700 /* List of registers that are pre-defined:
702 Each general register has one predefined name of the form
703 %r<REGNUM> which has the value <REGNUM>.
705 Space and control registers are handled in a similar manner,
706 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
708 Likewise for the floating point registers, but of the form
709 %fr<REGNUM>. Floating point registers have additional predefined
710 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
711 again have the value <REGNUM>.
713 Many registers also have synonyms:
715 %r26 - %r23 have %arg0 - %arg3 as synonyms
716 %r28 - %r29 have %ret0 - %ret1 as synonyms
717 %r30 has %sp as a synonym
718 %r27 has %dp as a synonym
719 %r2 has %rp as a synonym
721 Almost every control register has a synonym; they are not listed
724 The table is sorted. Suitable for searching by a binary search. */
726 static const struct pd_reg pre_defined_registers
[] =
926 /* This table is sorted by order of the length of the string. This is
927 so we check for <> before we check for <. If we had a <> and checked
928 for < first, we would get a false match. */
929 static const struct fp_cond_map fp_cond_map
[] =
965 static const struct selector_entry selector_table
[] =
987 /* default space and subspace dictionaries */
989 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
990 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
992 /* pre-defined subsegments (subspaces) for the HPPA. */
993 #define SUBSEG_CODE 0
995 #define SUBSEG_MILLI 2
996 #define SUBSEG_DATA 0
998 #define SUBSEG_UNWIND 3
999 #define SUBSEG_GDB_STRINGS 0
1000 #define SUBSEG_GDB_SYMBOLS 1
1002 static struct default_subspace_dict pa_def_subspaces
[] =
1004 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1005 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1006 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1007 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI
},
1008 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1010 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
1012 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1015 static struct default_space_dict pa_def_spaces
[] =
1017 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1018 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1019 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1022 /* Misc local definitions used by the assembler. */
1024 /* Return nonzero if the string pointed to by S potentially represents
1025 a right or left half of a FP register */
1026 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1027 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1029 /* These macros are used to maintain spaces/subspaces. */
1030 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1031 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1032 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1033 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1035 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1036 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1038 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1039 main loop after insertion. */
1041 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1043 ((OPCODE) |= (FIELD) << (START)); \
1047 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1048 IGNORE is used to suppress the error message. */
1050 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1052 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1055 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1061 #define is_DP_relative(exp) \
1062 ((exp).X_op == O_subtract \
1063 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1065 #define is_PC_relative(exp) \
1066 ((exp).X_op == O_subtract \
1067 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1069 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1070 always be able to reduce the expression to a constant, so we don't
1071 need real complex handling yet. */
1072 #define is_complex(exp) \
1073 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1075 /* Actual functions to implement the PA specific code for the assembler. */
1077 /* Called before writing the object file. Make sure entry/exit and
1078 proc/procend pairs match. */
1083 if (within_entry_exit
)
1084 as_fatal ("Missing .exit\n");
1086 if (within_procedure
)
1087 as_fatal ("Missing .procend\n");
1090 /* Check to make sure we have a valid space and subspace. */
1093 pa_check_current_space_and_subspace ()
1095 if (current_space
== NULL
)
1096 as_fatal ("Not in a space.\n");
1098 if (current_subspace
== NULL
)
1099 as_fatal ("Not in a subspace.\n");
1102 /* Returns a pointer to the label_symbol_struct for the current space.
1103 or NULL if no label_symbol_struct exists for the current space. */
1105 static label_symbol_struct
*
1108 label_symbol_struct
*label_chain
;
1109 sd_chain_struct
*space_chain
= current_space
;
1111 for (label_chain
= label_symbols_rootp
;
1113 label_chain
= label_chain
->lss_next
)
1114 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1120 /* Defines a label for the current space. If one is already defined,
1121 this function will replace it with the new label. */
1124 pa_define_label (symbol
)
1127 label_symbol_struct
*label_chain
= pa_get_label ();
1128 sd_chain_struct
*space_chain
= current_space
;
1131 label_chain
->lss_label
= symbol
;
1134 /* Create a new label entry and add it to the head of the chain. */
1136 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1137 label_chain
->lss_label
= symbol
;
1138 label_chain
->lss_space
= space_chain
;
1139 label_chain
->lss_next
= NULL
;
1141 if (label_symbols_rootp
)
1142 label_chain
->lss_next
= label_symbols_rootp
;
1144 label_symbols_rootp
= label_chain
;
1148 /* Removes a label definition for the current space.
1149 If there is no label_symbol_struct entry, then no action is taken. */
1152 pa_undefine_label ()
1154 label_symbol_struct
*label_chain
;
1155 label_symbol_struct
*prev_label_chain
= NULL
;
1156 sd_chain_struct
*space_chain
= current_space
;
1158 for (label_chain
= label_symbols_rootp
;
1160 label_chain
= label_chain
->lss_next
)
1162 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1164 /* Remove the label from the chain and free its memory. */
1165 if (prev_label_chain
)
1166 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1168 label_symbols_rootp
= label_chain
->lss_next
;
1173 prev_label_chain
= label_chain
;
1178 /* An HPPA-specific version of fix_new. This is required because the HPPA
1179 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1180 results in the creation of an instance of an hppa_fix_struct. An
1181 hppa_fix_struct stores the extra information along with a pointer to the
1182 original fixS. This is attached to the original fixup via the
1183 tc_fix_data field. */
1186 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1187 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1191 symbolS
*add_symbol
;
1195 bfd_reloc_code_real_type r_type
;
1196 enum hppa_reloc_field_selector_type r_field
;
1203 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1204 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1207 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1209 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1210 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1211 hppa_fix
->fx_r_type
= r_type
;
1212 hppa_fix
->fx_r_field
= r_field
;
1213 hppa_fix
->fx_r_format
= r_format
;
1214 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1215 hppa_fix
->segment
= now_seg
;
1217 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1218 new_fix
->fx_offset
= *unwind_bits
;
1221 /* foo-$global$ is used to access non-automatic storage. $global$
1222 is really just a marker and has served its purpose, so eliminate
1223 it now so as not to confuse write.c. */
1224 if (new_fix
->fx_subsy
1225 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1226 new_fix
->fx_subsy
= NULL
;
1229 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1230 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1233 parse_cons_expression_hppa (exp
)
1236 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1240 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1241 hppa_field_selector is set by the parse_cons_expression_hppa. */
1244 cons_fix_new_hppa (frag
, where
, size
, exp
)
1250 unsigned int rel_type
;
1252 /* Get a base relocation type. */
1253 if (is_DP_relative (*exp
))
1254 rel_type
= R_HPPA_GOTOFF
;
1255 else if (is_complex (*exp
))
1256 rel_type
= R_HPPA_COMPLEX
;
1260 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1261 as_warn ("Invalid field selector. Assuming F%%.");
1263 fix_new_hppa (frag
, where
, size
,
1264 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1265 hppa_field_selector
, 32, 0, NULL
);
1267 /* Reset field selector to its default state. */
1268 hppa_field_selector
= 0;
1271 /* This function is called once, at assembler startup time. It should
1272 set up all the tables, etc. that the MD part of the assembler will need. */
1277 const char *retval
= NULL
;
1281 last_call_info
= NULL
;
1282 call_info_root
= NULL
;
1284 /* Set the default machine type. */
1285 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1286 as_warn ("could not set architecture and machine");
1288 /* Folding of text and data segments fails miserably on the PA.
1289 Warn user and disable "-R" option. */
1290 if (flag_readonly_data_in_text
)
1292 as_warn ("-R option not supported on this target.");
1293 flag_readonly_data_in_text
= 0;
1298 op_hash
= hash_new ();
1300 while (i
< NUMOPCODES
)
1302 const char *name
= pa_opcodes
[i
].name
;
1303 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1304 if (retval
!= NULL
&& *retval
!= '\0')
1306 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1311 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1312 != pa_opcodes
[i
].match
)
1314 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1315 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1320 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1324 as_fatal ("Broken assembler. No assembly attempted.");
1326 /* SOM will change text_section. To make sure we never put
1327 anything into the old one switch to the new one now. */
1328 subseg_set (text_section
, 0);
1330 dummy_symbol
= symbol_find_or_make ("L$dummy");
1331 S_SET_SEGMENT (dummy_symbol
, text_section
);
1334 /* Assemble a single instruction storing it into a frag. */
1341 /* The had better be something to assemble. */
1344 /* If we are within a procedure definition, make sure we've
1345 defined a label for the procedure; handle case where the
1346 label was defined after the .PROC directive.
1348 Note there's not need to diddle with the segment or fragment
1349 for the label symbol in this case. We have already switched
1350 into the new $CODE$ subspace at this point. */
1351 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1353 label_symbol_struct
*label_symbol
= pa_get_label ();
1357 if (label_symbol
->lss_label
)
1359 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1360 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1362 /* Also handle allocation of a fixup to hold the unwind
1363 information when the label appears after the proc/procend. */
1364 if (within_entry_exit
)
1366 char *where
= frag_more (0);
1368 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1369 NULL
, (offsetT
) 0, NULL
,
1370 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1371 (int *)&last_call_info
->ci_unwind
.descriptor
);
1376 as_bad ("Missing function name for .PROC (corrupted label chain)");
1379 as_bad ("Missing function name for .PROC");
1382 /* Assemble the instruction. Results are saved into "the_insn". */
1385 /* Get somewhere to put the assembled instrution. */
1388 /* Output the opcode. */
1389 md_number_to_chars (to
, the_insn
.opcode
, 4);
1391 /* If necessary output more stuff. */
1392 if (the_insn
.reloc
!= R_HPPA_NONE
)
1393 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1394 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1395 the_insn
.reloc
, the_insn
.field_selector
,
1396 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1399 /* Do the real work for assembling a single instruction. Store results
1400 into the global "the_insn" variable. */
1406 char *error_message
= "";
1407 char *s
, c
, *argstart
, *name
, *save_s
;
1411 int cmpltr
, nullif
, flag
, cond
, num
;
1412 unsigned long opcode
;
1413 struct pa_opcode
*insn
;
1415 /* We must have a valid space and subspace. */
1416 pa_check_current_space_and_subspace ();
1418 /* Skip to something interesting. */
1419 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1438 as_fatal ("Unknown opcode: `%s'", str
);
1443 /* Convert everything into lower case. */
1446 if (isupper (*save_s
))
1447 *save_s
= tolower (*save_s
);
1451 /* Look up the opcode in the has table. */
1452 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1454 as_bad ("Unknown opcode: `%s'", str
);
1463 /* Mark the location where arguments for the instruction start, then
1464 start processing them. */
1468 /* Do some initialization. */
1469 opcode
= insn
->match
;
1470 bzero (&the_insn
, sizeof (the_insn
));
1472 the_insn
.reloc
= R_HPPA_NONE
;
1474 /* If this instruction is specific to a particular architecture,
1475 then set a new architecture. */
1476 if (bfd_get_mach (stdoutput
) < insn
->arch
)
1478 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1479 as_warn ("could not update architecture and machine");
1482 /* Build the opcode, checking as we go to make
1483 sure that the operands match. */
1484 for (args
= insn
->args
;; ++args
)
1489 /* End of arguments. */
1505 /* These must match exactly. */
1514 /* Handle a 5 bit register or control register field at 10. */
1517 num
= pa_parse_number (&s
, 0);
1518 CHECK_FIELD (num
, 31, 0, 0);
1519 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1521 /* Handle a 5 bit register field at 15. */
1523 num
= pa_parse_number (&s
, 0);
1524 CHECK_FIELD (num
, 31, 0, 0);
1525 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1527 /* Handle a 5 bit register field at 31. */
1530 num
= pa_parse_number (&s
, 0);
1531 CHECK_FIELD (num
, 31, 0, 0);
1532 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1534 /* Handle a 5 bit field length at 31. */
1536 num
= pa_get_absolute_expression (&the_insn
, &s
);
1538 CHECK_FIELD (num
, 32, 1, 0);
1539 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1541 /* Handle a 5 bit immediate at 15. */
1543 num
= pa_get_absolute_expression (&the_insn
, &s
);
1545 CHECK_FIELD (num
, 15, -16, 0);
1546 low_sign_unext (num
, 5, &num
);
1547 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1549 /* Handle a 5 bit immediate at 31. */
1551 num
= pa_get_absolute_expression (&the_insn
, &s
);
1553 CHECK_FIELD (num
, 15, -16, 0)
1554 low_sign_unext (num
, 5, &num
);
1555 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1557 /* Handle an unsigned 5 bit immediate at 31. */
1559 num
= pa_get_absolute_expression (&the_insn
, &s
);
1561 CHECK_FIELD (num
, 31, 0, 0);
1562 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1564 /* Handle an unsigned 5 bit immediate at 15. */
1566 num
= pa_get_absolute_expression (&the_insn
, &s
);
1568 CHECK_FIELD (num
, 31, 0, 0);
1569 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1571 /* Handle a 2 bit space identifier at 17. */
1573 num
= pa_parse_number (&s
, 0);
1574 CHECK_FIELD (num
, 3, 0, 1);
1575 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1577 /* Handle a 3 bit space identifier at 18. */
1579 num
= pa_parse_number (&s
, 0);
1580 CHECK_FIELD (num
, 7, 0, 1);
1581 dis_assemble_3 (num
, &num
);
1582 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1584 /* Handle a completer for an indexing load or store. */
1590 while (*s
== ',' && i
< 2)
1593 if (strncasecmp (s
, "sm", 2) == 0)
1600 else if (strncasecmp (s
, "m", 1) == 0)
1602 else if (strncasecmp (s
, "s", 1) == 0)
1605 as_bad ("Invalid Indexed Load Completer.");
1610 as_bad ("Invalid Indexed Load Completer Syntax.");
1612 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1615 /* Handle a short load/store completer. */
1623 if (strncasecmp (s
, "ma", 2) == 0)
1628 else if (strncasecmp (s
, "mb", 2) == 0)
1634 as_bad ("Invalid Short Load/Store Completer.");
1638 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1641 /* Handle a stbys completer. */
1647 while (*s
== ',' && i
< 2)
1650 if (strncasecmp (s
, "m", 1) == 0)
1652 else if (strncasecmp (s
, "b", 1) == 0)
1654 else if (strncasecmp (s
, "e", 1) == 0)
1657 as_bad ("Invalid Store Bytes Short Completer");
1662 as_bad ("Invalid Store Bytes Short Completer");
1664 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1667 /* Handle a non-negated compare/stubtract condition. */
1669 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1672 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1675 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1677 /* Handle a negated or non-negated compare/subtract condition. */
1680 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1684 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1687 as_bad ("Invalid Compare/Subtract Condition.");
1692 /* Negated condition requires an opcode change. */
1696 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1698 /* Handle non-negated add condition. */
1700 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1703 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1706 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1708 /* Handle a negated or non-negated add condition. */
1711 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1715 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1718 as_bad ("Invalid Compare/Subtract Condition");
1723 /* Negated condition requires an opcode change. */
1727 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1729 /* Handle a compare/subtract condition. */
1736 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1741 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1744 as_bad ("Invalid Compare/Subtract Condition");
1748 opcode
|= cmpltr
<< 13;
1749 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1751 /* Handle a non-negated add condition. */
1760 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1764 if (strcmp (name
, "=") == 0)
1766 else if (strcmp (name
, "<") == 0)
1768 else if (strcmp (name
, "<=") == 0)
1770 else if (strcasecmp (name
, "nuv") == 0)
1772 else if (strcasecmp (name
, "znv") == 0)
1774 else if (strcasecmp (name
, "sv") == 0)
1776 else if (strcasecmp (name
, "od") == 0)
1778 else if (strcasecmp (name
, "n") == 0)
1780 else if (strcasecmp (name
, "tr") == 0)
1785 else if (strcmp (name
, "<>") == 0)
1790 else if (strcmp (name
, ">=") == 0)
1795 else if (strcmp (name
, ">") == 0)
1800 else if (strcasecmp (name
, "uv") == 0)
1805 else if (strcasecmp (name
, "vnz") == 0)
1810 else if (strcasecmp (name
, "nsv") == 0)
1815 else if (strcasecmp (name
, "ev") == 0)
1821 as_bad ("Invalid Add Condition: %s", name
);
1824 nullif
= pa_parse_nullif (&s
);
1825 opcode
|= nullif
<< 1;
1826 opcode
|= cmpltr
<< 13;
1827 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1829 /* HANDLE a logical instruction condition. */
1837 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1841 if (strcmp (name
, "=") == 0)
1843 else if (strcmp (name
, "<") == 0)
1845 else if (strcmp (name
, "<=") == 0)
1847 else if (strcasecmp (name
, "od") == 0)
1849 else if (strcasecmp (name
, "tr") == 0)
1854 else if (strcmp (name
, "<>") == 0)
1859 else if (strcmp (name
, ">=") == 0)
1864 else if (strcmp (name
, ">") == 0)
1869 else if (strcasecmp (name
, "ev") == 0)
1875 as_bad ("Invalid Logical Instruction Condition.");
1878 opcode
|= cmpltr
<< 13;
1879 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1881 /* Handle a unit instruction condition. */
1888 if (strncasecmp (s
, "sbz", 3) == 0)
1893 else if (strncasecmp (s
, "shz", 3) == 0)
1898 else if (strncasecmp (s
, "sdc", 3) == 0)
1903 else if (strncasecmp (s
, "sbc", 3) == 0)
1908 else if (strncasecmp (s
, "shc", 3) == 0)
1913 else if (strncasecmp (s
, "tr", 2) == 0)
1919 else if (strncasecmp (s
, "nbz", 3) == 0)
1925 else if (strncasecmp (s
, "nhz", 3) == 0)
1931 else if (strncasecmp (s
, "ndc", 3) == 0)
1937 else if (strncasecmp (s
, "nbc", 3) == 0)
1943 else if (strncasecmp (s
, "nhc", 3) == 0)
1950 as_bad ("Invalid Logical Instruction Condition.");
1952 opcode
|= cmpltr
<< 13;
1953 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1955 /* Handle a shift/extract/deposit condition. */
1963 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1967 if (strcmp (name
, "=") == 0)
1969 else if (strcmp (name
, "<") == 0)
1971 else if (strcasecmp (name
, "od") == 0)
1973 else if (strcasecmp (name
, "tr") == 0)
1975 else if (strcmp (name
, "<>") == 0)
1977 else if (strcmp (name
, ">=") == 0)
1979 else if (strcasecmp (name
, "ev") == 0)
1981 /* Handle movb,n. Put things back the way they were.
1982 This includes moving s back to where it started. */
1983 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1990 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1993 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1995 /* Handle bvb and bb conditions. */
2001 if (strncmp (s
, "<", 1) == 0)
2006 else if (strncmp (s
, ">=", 2) == 0)
2012 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2014 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2016 /* Handle a system control completer. */
2018 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2026 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2028 /* Handle a nullification completer for branch instructions. */
2030 nullif
= pa_parse_nullif (&s
);
2031 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2033 /* Handle a nullification completer for copr and spop insns. */
2035 nullif
= pa_parse_nullif (&s
);
2036 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2038 /* Handle a 11 bit immediate at 31. */
2040 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2043 if (the_insn
.exp
.X_op
== O_constant
)
2045 num
= evaluate_absolute (&the_insn
);
2046 CHECK_FIELD (num
, 1023, -1024, 0);
2047 low_sign_unext (num
, 11, &num
);
2048 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2052 if (is_DP_relative (the_insn
.exp
))
2053 the_insn
.reloc
= R_HPPA_GOTOFF
;
2054 else if (is_PC_relative (the_insn
.exp
))
2055 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2057 the_insn
.reloc
= R_HPPA
;
2058 the_insn
.format
= 11;
2062 /* Handle a 14 bit immediate at 31. */
2064 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2067 if (the_insn
.exp
.X_op
== O_constant
)
2069 num
= evaluate_absolute (&the_insn
);
2070 CHECK_FIELD (num
, 8191, -8192, 0);
2071 low_sign_unext (num
, 14, &num
);
2072 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2076 if (is_DP_relative (the_insn
.exp
))
2077 the_insn
.reloc
= R_HPPA_GOTOFF
;
2078 else if (is_PC_relative (the_insn
.exp
))
2079 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2081 the_insn
.reloc
= R_HPPA
;
2082 the_insn
.format
= 14;
2086 /* Handle a 21 bit immediate at 31. */
2088 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2091 if (the_insn
.exp
.X_op
== O_constant
)
2093 num
= evaluate_absolute (&the_insn
);
2094 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2095 dis_assemble_21 (num
, &num
);
2096 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2100 if (is_DP_relative (the_insn
.exp
))
2101 the_insn
.reloc
= R_HPPA_GOTOFF
;
2102 else if (is_PC_relative (the_insn
.exp
))
2103 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2105 the_insn
.reloc
= R_HPPA
;
2106 the_insn
.format
= 21;
2110 /* Handle a 12 bit branch displacement. */
2112 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2116 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2118 unsigned int w1
, w
, result
;
2120 num
= evaluate_absolute (&the_insn
);
2123 as_bad ("Branch to unaligned address");
2126 CHECK_FIELD (num
, 8199, -8184, 0);
2127 sign_unext ((num
- 8) >> 2, 12, &result
);
2128 dis_assemble_12 (result
, &w1
, &w
);
2129 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2133 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2134 the_insn
.format
= 12;
2135 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2136 bzero (&last_call_desc
, sizeof (struct call_desc
));
2141 /* Handle a 17 bit branch displacement. */
2143 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2147 if (!the_insn
.exp
.X_add_symbol
2148 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2151 unsigned int w2
, w1
, w
, result
;
2153 num
= evaluate_absolute (&the_insn
);
2156 as_bad ("Branch to unaligned address");
2159 CHECK_FIELD (num
, 262143, -262144, 0);
2161 if (the_insn
.exp
.X_add_symbol
)
2164 sign_unext (num
>> 2, 17, &result
);
2165 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2166 INSERT_FIELD_AND_CONTINUE (opcode
,
2167 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2171 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2172 the_insn
.format
= 17;
2173 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2174 bzero (&last_call_desc
, sizeof (struct call_desc
));
2178 /* Handle an absolute 17 bit branch target. */
2180 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2184 if (!the_insn
.exp
.X_add_symbol
2185 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2188 unsigned int w2
, w1
, w
, result
;
2190 num
= evaluate_absolute (&the_insn
);
2193 as_bad ("Branch to unaligned address");
2196 CHECK_FIELD (num
, 262143, -262144, 0);
2198 if (the_insn
.exp
.X_add_symbol
)
2201 sign_unext (num
>> 2, 17, &result
);
2202 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2203 INSERT_FIELD_AND_CONTINUE (opcode
,
2204 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2208 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2209 the_insn
.format
= 17;
2210 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2211 bzero (&last_call_desc
, sizeof (struct call_desc
));
2215 /* Handle a 5 bit shift count at 26. */
2217 num
= pa_get_absolute_expression (&the_insn
, &s
);
2219 CHECK_FIELD (num
, 31, 0, 0);
2220 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2222 /* Handle a 5 bit bit position at 26. */
2224 num
= pa_get_absolute_expression (&the_insn
, &s
);
2226 CHECK_FIELD (num
, 31, 0, 0);
2227 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2229 /* Handle a 5 bit immediate at 10. */
2231 num
= pa_get_absolute_expression (&the_insn
, &s
);
2233 CHECK_FIELD (num
, 31, 0, 0);
2234 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2236 /* Handle a 13 bit immediate at 18. */
2238 num
= pa_get_absolute_expression (&the_insn
, &s
);
2240 CHECK_FIELD (num
, 8191, 0, 0);
2241 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2243 /* Handle a 26 bit immediate at 31. */
2245 num
= pa_get_absolute_expression (&the_insn
, &s
);
2247 CHECK_FIELD (num
, 671108864, 0, 0);
2248 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2250 /* Handle a 3 bit SFU identifier at 25. */
2253 as_bad ("Invalid SFU identifier");
2254 num
= pa_get_absolute_expression (&the_insn
, &s
);
2256 CHECK_FIELD (num
, 7, 0, 0);
2257 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2259 /* Handle a 20 bit SOP field for spop0. */
2261 num
= pa_get_absolute_expression (&the_insn
, &s
);
2263 CHECK_FIELD (num
, 1048575, 0, 0);
2264 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2265 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2267 /* Handle a 15bit SOP field for spop1. */
2269 num
= pa_get_absolute_expression (&the_insn
, &s
);
2271 CHECK_FIELD (num
, 32767, 0, 0);
2272 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2274 /* Handle a 10bit SOP field for spop3. */
2276 num
= pa_get_absolute_expression (&the_insn
, &s
);
2278 CHECK_FIELD (num
, 1023, 0, 0);
2279 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2280 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2282 /* Handle a 15 bit SOP field for spop2. */
2284 num
= pa_get_absolute_expression (&the_insn
, &s
);
2286 CHECK_FIELD (num
, 32767, 0, 0);
2287 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2288 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2290 /* Handle a 3-bit co-processor ID field. */
2293 as_bad ("Invalid COPR identifier");
2294 num
= pa_get_absolute_expression (&the_insn
, &s
);
2296 CHECK_FIELD (num
, 7, 0, 0);
2297 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2299 /* Handle a 22bit SOP field for copr. */
2301 num
= pa_get_absolute_expression (&the_insn
, &s
);
2303 CHECK_FIELD (num
, 4194303, 0, 0);
2304 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2305 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2307 /* Handle a source FP operand format completer. */
2309 flag
= pa_parse_fp_format (&s
);
2310 the_insn
.fpof1
= flag
;
2311 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2313 /* Handle a destination FP operand format completer. */
2315 /* pa_parse_format needs the ',' prefix. */
2317 flag
= pa_parse_fp_format (&s
);
2318 the_insn
.fpof2
= flag
;
2319 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2321 /* Handle FP compare conditions. */
2323 cond
= pa_parse_fp_cmp_cond (&s
);
2324 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2326 /* Handle L/R register halves like 't'. */
2329 struct pa_11_fp_reg_struct result
;
2331 pa_parse_number (&s
, &result
);
2332 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2333 opcode
|= result
.number_part
;
2335 /* 0x30 opcodes are FP arithmetic operation opcodes
2336 and need to be turned into 0x38 opcodes. This
2337 is not necessary for loads/stores. */
2338 if (need_pa11_opcode (&the_insn
, &result
)
2339 && ((opcode
& 0xfc000000) == 0x30000000))
2342 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2345 /* Handle L/R register halves like 'b'. */
2348 struct pa_11_fp_reg_struct result
;
2350 pa_parse_number (&s
, &result
);
2351 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2352 opcode
|= result
.number_part
<< 21;
2353 if (need_pa11_opcode (&the_insn
, &result
))
2355 opcode
|= (result
.l_r_select
& 1) << 7;
2361 /* Handle L/R register halves like 'x'. */
2364 struct pa_11_fp_reg_struct result
;
2366 pa_parse_number (&s
, &result
);
2367 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2368 opcode
|= (result
.number_part
& 0x1f) << 16;
2369 if (need_pa11_opcode (&the_insn
, &result
))
2371 opcode
|= (result
.l_r_select
& 1) << 12;
2377 /* Handle a 5 bit register field at 10. */
2380 struct pa_11_fp_reg_struct result
;
2382 pa_parse_number (&s
, &result
);
2383 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2384 if (the_insn
.fpof1
== SGL
)
2386 if (result
.number_part
< 16)
2388 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2392 result
.number_part
&= 0xF;
2393 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2395 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2398 /* Handle a 5 bit register field at 15. */
2401 struct pa_11_fp_reg_struct result
;
2403 pa_parse_number (&s
, &result
);
2404 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2405 if (the_insn
.fpof1
== SGL
)
2407 if (result
.number_part
< 16)
2409 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2412 result
.number_part
&= 0xF;
2413 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2415 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2418 /* Handle a 5 bit register field at 31. */
2421 struct pa_11_fp_reg_struct result
;
2423 pa_parse_number (&s
, &result
);
2424 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2425 if (the_insn
.fpof1
== SGL
)
2427 if (result
.number_part
< 16)
2429 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2432 result
.number_part
&= 0xF;
2433 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2435 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2438 /* Handle a 5 bit register field at 20. */
2441 struct pa_11_fp_reg_struct result
;
2443 pa_parse_number (&s
, &result
);
2444 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2445 if (the_insn
.fpof1
== SGL
)
2447 if (result
.number_part
< 16)
2449 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2452 result
.number_part
&= 0xF;
2453 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2455 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2458 /* Handle a 5 bit register field at 25. */
2461 struct pa_11_fp_reg_struct result
;
2463 pa_parse_number (&s
, &result
);
2464 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2465 if (the_insn
.fpof1
== SGL
)
2467 if (result
.number_part
< 16)
2469 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2472 result
.number_part
&= 0xF;
2473 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2475 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2478 /* Handle a floating point operand format at 26.
2479 Only allows single and double precision. */
2481 flag
= pa_parse_fp_format (&s
);
2487 the_insn
.fpof1
= flag
;
2493 as_bad ("Invalid Floating Point Operand Format.");
2503 /* Check if the args matched. */
2506 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2507 && !strcmp (insn
->name
, insn
[1].name
))
2515 as_bad ("Invalid operands %s", error_message
);
2522 the_insn
.opcode
= opcode
;
2525 /* Turn a string in input_line_pointer into a floating point constant of type
2526 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2527 emitted is stored in *sizeP . An error message or NULL is returned. */
2529 #define MAX_LITTLENUMS 6
2532 md_atof (type
, litP
, sizeP
)
2538 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2539 LITTLENUM_TYPE
*wordP
;
2571 return "Bad call to MD_ATOF()";
2573 t
= atof_ieee (input_line_pointer
, type
, words
);
2575 input_line_pointer
= t
;
2576 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2577 for (wordP
= words
; prec
--;)
2579 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2580 litP
+= sizeof (LITTLENUM_TYPE
);
2585 /* Write out big-endian. */
2588 md_number_to_chars (buf
, val
, n
)
2593 number_to_chars_bigendian (buf
, val
, n
);
2596 /* Translate internal representation of relocation info to BFD target
2600 tc_gen_reloc (section
, fixp
)
2605 struct hppa_fix_struct
*hppa_fixp
;
2606 bfd_reloc_code_real_type code
;
2607 static arelent
*no_relocs
= NULL
;
2609 bfd_reloc_code_real_type
**codes
;
2613 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2614 if (fixp
->fx_addsy
== 0)
2616 assert (hppa_fixp
!= 0);
2617 assert (section
!= 0);
2619 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2620 assert (reloc
!= 0);
2622 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2623 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2625 hppa_fixp
->fx_r_format
,
2626 hppa_fixp
->fx_r_field
,
2627 fixp
->fx_subsy
!= NULL
);
2629 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2632 relocs
= (arelent
**)
2633 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2634 assert (relocs
!= 0);
2636 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2637 sizeof (arelent
) * n_relocs
);
2639 assert (reloc
!= 0);
2641 for (i
= 0; i
< n_relocs
; i
++)
2642 relocs
[i
] = &reloc
[i
];
2644 relocs
[n_relocs
] = NULL
;
2647 switch (fixp
->fx_r_type
)
2650 assert (n_relocs
== 1);
2654 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2655 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2656 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2657 reloc
->addend
= 0; /* default */
2659 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2661 /* Now, do any processing that is dependent on the relocation type. */
2664 case R_PARISC_DLTREL21L
:
2665 case R_PARISC_DLTREL14R
:
2666 case R_PARISC_DLTREL14F
:
2667 case R_PARISC_PLABEL32
:
2668 case R_PARISC_PLABEL21L
:
2669 case R_PARISC_PLABEL14R
:
2670 /* For plabel relocations, the addend of the
2671 relocation should be either 0 (no static link) or 2
2672 (static link required).
2674 FIXME: We always assume no static link!
2676 We also slam a zero addend into the DLT relative relocs;
2677 it doesn't make a lot of sense to use any addend since
2678 it gets you a different (eg unknown) DLT entry. */
2682 case R_PARISC_PCREL21L
:
2683 case R_PARISC_PCREL17R
:
2684 case R_PARISC_PCREL17F
:
2685 case R_PARISC_PCREL17C
:
2686 case R_PARISC_PCREL14R
:
2687 case R_PARISC_PCREL14F
:
2688 /* The constant is stored in the instruction. */
2689 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2692 reloc
->addend
= fixp
->fx_offset
;
2699 /* Walk over reach relocation returned by the BFD backend. */
2700 for (i
= 0; i
< n_relocs
; i
++)
2704 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2705 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2706 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2711 /* The only time we ever use a R_COMP2 fixup is for the difference
2712 of two symbols. With that in mind we fill in all four
2713 relocs now and break out of the loop. */
2715 relocs
[0]->sym_ptr_ptr
= &bfd_abs_symbol
;
2716 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
2717 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2718 relocs
[0]->addend
= 0;
2719 relocs
[1]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2720 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
2721 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2722 relocs
[1]->addend
= 0;
2723 relocs
[2]->sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2724 relocs
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[2]);
2725 relocs
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2726 relocs
[2]->addend
= 0;
2727 relocs
[3]->sym_ptr_ptr
= &bfd_abs_symbol
;
2728 relocs
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[3]);
2729 relocs
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2730 relocs
[3]->addend
= 0;
2731 relocs
[4]->sym_ptr_ptr
= &bfd_abs_symbol
;
2732 relocs
[4]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[4]);
2733 relocs
[4]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2734 relocs
[4]->addend
= 0;
2738 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2744 /* For plabel relocations, the addend of the
2745 relocation should be either 0 (no static link) or 2
2746 (static link required).
2748 FIXME: We always assume no static link!
2750 We also slam a zero addend into the DLT relative relocs;
2751 it doesn't make a lot of sense to use any addend since
2752 it gets you a different (eg unknown) DLT entry. */
2753 relocs
[i
]->addend
= 0;
2767 /* There is no symbol or addend associated with these fixups. */
2768 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2769 relocs
[i
]->addend
= 0;
2774 /* There is no symbol associated with these fixups. */
2775 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2776 relocs
[i
]->addend
= fixp
->fx_offset
;
2780 relocs
[i
]->addend
= fixp
->fx_offset
;
2790 /* Process any machine dependent frag types. */
2793 md_convert_frag (abfd
, sec
, fragP
)
2795 register asection
*sec
;
2796 register fragS
*fragP
;
2798 unsigned int address
;
2800 if (fragP
->fr_type
== rs_machine_dependent
)
2802 switch ((int) fragP
->fr_subtype
)
2805 fragP
->fr_type
= rs_fill
;
2806 know (fragP
->fr_var
== 1);
2807 know (fragP
->fr_next
);
2808 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2809 if (address
% fragP
->fr_offset
)
2812 fragP
->fr_next
->fr_address
2817 fragP
->fr_offset
= 0;
2823 /* Round up a section size to the appropriate boundary. */
2826 md_section_align (segment
, size
)
2830 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2831 int align2
= (1 << align
) - 1;
2833 return (size
+ align2
) & ~align2
;
2836 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2838 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2840 addressT from_addr
, to_addr
;
2844 fprintf (stderr
, "pa_create_short_jmp\n");
2848 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2850 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2852 addressT from_addr
, to_addr
;
2856 fprintf (stderr
, "pa_create_long_jump\n");
2860 /* Return the approximate size of a frag before relaxation has occurred. */
2862 md_estimate_size_before_relax (fragP
, segment
)
2863 register fragS
*fragP
;
2870 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2876 CONST
char *md_shortopts
= "";
2877 struct option md_longopts
[] = {
2878 {NULL
, no_argument
, NULL
, 0}
2880 size_t md_longopts_size
= sizeof(md_longopts
);
2883 md_parse_option (c
, arg
)
2891 md_show_usage (stream
)
2896 /* We have no need to default values of symbols. */
2899 md_undefined_symbol (name
)
2905 /* Apply a fixup to an instruction. */
2908 md_apply_fix (fixP
, valp
)
2912 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2913 struct hppa_fix_struct
*hppa_fixP
;
2914 long new_val
, result
;
2915 unsigned int w1
, w2
, w
, resulti
;
2917 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2918 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2919 never be "applied" (they are just markers). Likewise for
2920 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
2922 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2923 || fixP
->fx_r_type
== R_HPPA_EXIT
2924 || fixP
->fx_r_type
== R_HPPA_BEGIN_BRTAB
2925 || fixP
->fx_r_type
== R_HPPA_END_BRTAB
)
2929 /* There should have been an HPPA specific fixup associated
2930 with the GAS fixup. */
2933 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2934 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2936 /* If there is a symbol associated with this fixup, then it's something
2937 which will need a SOM relocation (except for some PC-relative relocs).
2938 In such cases we should treat the "val" or "addend" as zero since it
2939 will be added in as needed from fx_offset in tc_gen_reloc. */
2940 if ((fixP
->fx_addsy
!= NULL
2941 || fixP
->fx_r_type
== R_HPPA_NONE
)
2944 || hppa_fixP
->fx_r_field
== e_psel
2945 || hppa_fixP
->fx_r_field
== e_rpsel
2946 || hppa_fixP
->fx_r_field
== e_lpsel
2947 || hppa_fixP
->fx_r_field
== e_tsel
2948 || hppa_fixP
->fx_r_field
== e_rtsel
2949 || hppa_fixP
->fx_r_field
== e_ltsel
2952 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2954 /* This is truely disgusting. The machine independent code blindly
2955 adds in the value of the symbol being relocated against. Damn! */
2957 && fixP
->fx_addsy
!= NULL
2958 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
2959 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
2960 0, hppa_fixP
->fx_r_field
);
2963 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2965 /* Handle pc-relative exceptions from above. */
2966 #define arg_reloc_stub_needed(CALLER, CALLEE) \
2967 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2968 if ((fmt
== 12 || fmt
== 17)
2971 && !arg_reloc_stub_needed (((obj_symbol_type
*)
2972 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2973 hppa_fixP
->fx_arg_reloc
)
2974 && ((int)(*valp
) > -262144 && (int)(*valp
) < 262143)
2975 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
2977 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2979 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2980 #undef arg_reloc_stub_needed
2984 /* Handle all opcodes with the 'j' operand type. */
2986 CHECK_FIELD (new_val
, 8191, -8192, 0);
2988 /* Mask off 14 bits to be changed. */
2989 bfd_put_32 (stdoutput
,
2990 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
2992 low_sign_unext (new_val
, 14, &resulti
);
2996 /* Handle all opcodes with the 'k' operand type. */
2998 CHECK_FIELD (new_val
, 2097152, 0, 0);
3000 /* Mask off 21 bits to be changed. */
3001 bfd_put_32 (stdoutput
,
3002 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3004 dis_assemble_21 (new_val
, &resulti
);
3008 /* Handle all the opcodes with the 'i' operand type. */
3010 CHECK_FIELD (new_val
, 1023, -1023, 0);
3012 /* Mask off 11 bits to be changed. */
3013 bfd_put_32 (stdoutput
,
3014 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3016 low_sign_unext (new_val
, 11, &resulti
);
3020 /* Handle all the opcodes with the 'w' operand type. */
3022 CHECK_FIELD (new_val
, 8199, -8184, 0);
3024 /* Mask off 11 bits to be changed. */
3025 sign_unext ((new_val
- 8) >> 2, 12, &resulti
);
3026 bfd_put_32 (stdoutput
,
3027 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3030 dis_assemble_12 (resulti
, &w1
, &w
);
3031 result
= ((w1
<< 2) | w
);
3034 /* Handle some of the opcodes with the 'W' operand type. */
3036 CHECK_FIELD (new_val
, 262143, -262144, 0);
3038 /* Mask off 17 bits to be changed. */
3039 bfd_put_32 (stdoutput
,
3040 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3042 sign_unext ((new_val
- 8) >> 2, 17, &resulti
);
3043 dis_assemble_17 (resulti
, &w1
, &w2
, &w
);
3044 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3049 bfd_put_32 (stdoutput
, new_val
, buf
);
3053 as_bad ("Unknown relocation encountered in md_apply_fix.");
3057 /* Insert the relocation. */
3058 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3063 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3064 (unsigned int) fixP
, fixP
->fx_r_type
);
3069 /* Exactly what point is a PC-relative offset relative TO?
3070 On the PA, they're relative to the address of the offset. */
3073 md_pcrel_from (fixP
)
3076 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3079 /* Return nonzero if the input line pointer is at the end of
3083 is_end_of_statement ()
3085 return ((*input_line_pointer
== '\n')
3086 || (*input_line_pointer
== ';')
3087 || (*input_line_pointer
== '!'));
3090 /* Read a number from S. The number might come in one of many forms,
3091 the most common will be a hex or decimal constant, but it could be
3092 a pre-defined register (Yuk!), or an absolute symbol.
3094 Return a number or -1 for failure.
3096 When parsing PA-89 FP register numbers RESULT will be
3097 the address of a structure to return information about
3098 L/R half of FP registers, store results there as appropriate.
3100 pa_parse_number can not handle negative constants and will fail
3101 horribly if it is passed such a constant. */
3104 pa_parse_number (s
, result
)
3106 struct pa_11_fp_reg_struct
*result
;
3115 /* Skip whitespace before the number. */
3116 while (*p
== ' ' || *p
== '\t')
3119 /* Store info in RESULT if requested by caller. */
3122 result
->number_part
= -1;
3123 result
->l_r_select
= -1;
3129 /* Looks like a number. */
3132 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3134 /* The number is specified in hex. */
3136 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3137 || ((*p
>= 'A') && (*p
<= 'F')))
3140 num
= num
* 16 + *p
- '0';
3141 else if (*p
>= 'a' && *p
<= 'f')
3142 num
= num
* 16 + *p
- 'a' + 10;
3144 num
= num
* 16 + *p
- 'A' + 10;
3150 /* The number is specified in decimal. */
3151 while (isdigit (*p
))
3153 num
= num
* 10 + *p
- '0';
3158 /* Store info in RESULT if requested by the caller. */
3161 result
->number_part
= num
;
3163 if (IS_R_SELECT (p
))
3165 result
->l_r_select
= 1;
3168 else if (IS_L_SELECT (p
))
3170 result
->l_r_select
= 0;
3174 result
->l_r_select
= 0;
3179 /* The number might be a predefined register. */
3184 /* Tege hack: Special case for general registers as the general
3185 code makes a binary search with case translation, and is VERY
3190 if (*p
== 'e' && *(p
+ 1) == 't'
3191 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3194 num
= *p
- '0' + 28;
3202 else if (!isdigit (*p
))
3205 as_bad ("Undefined register: '%s'.", name
);
3211 num
= num
* 10 + *p
++ - '0';
3212 while (isdigit (*p
));
3217 /* Do a normal register search. */
3218 while (is_part_of_name (c
))
3224 status
= reg_name_search (name
);
3230 as_bad ("Undefined register: '%s'.", name
);
3236 /* Store info in RESULT if requested by caller. */
3239 result
->number_part
= num
;
3240 if (IS_R_SELECT (p
- 1))
3241 result
->l_r_select
= 1;
3242 else if (IS_L_SELECT (p
- 1))
3243 result
->l_r_select
= 0;
3245 result
->l_r_select
= 0;
3250 /* And finally, it could be a symbol in the absolute section which
3251 is effectively a constant. */
3255 while (is_part_of_name (c
))
3261 if ((sym
= symbol_find (name
)) != NULL
)
3263 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3264 num
= S_GET_VALUE (sym
);
3268 as_bad ("Non-absolute symbol: '%s'.", name
);
3274 /* There is where we'd come for an undefined symbol
3275 or for an empty string. For an empty string we
3276 will return zero. That's a concession made for
3277 compatability with the braindamaged HP assemblers. */
3283 as_bad ("Undefined absolute constant: '%s'.", name
);
3289 /* Store info in RESULT if requested by caller. */
3292 result
->number_part
= num
;
3293 if (IS_R_SELECT (p
- 1))
3294 result
->l_r_select
= 1;
3295 else if (IS_L_SELECT (p
- 1))
3296 result
->l_r_select
= 0;
3298 result
->l_r_select
= 0;
3306 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3308 /* Given NAME, find the register number associated with that name, return
3309 the integer value associated with the given name or -1 on failure. */
3312 reg_name_search (name
)
3315 int middle
, low
, high
;
3319 high
= REG_NAME_CNT
- 1;
3323 middle
= (low
+ high
) / 2;
3324 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3330 return pre_defined_registers
[middle
].value
;
3332 while (low
<= high
);
3338 /* Return nonzero if the given INSN and L/R information will require
3339 a new PA-1.1 opcode. */
3342 need_pa11_opcode (insn
, result
)
3344 struct pa_11_fp_reg_struct
*result
;
3346 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3348 /* If this instruction is specific to a particular architecture,
3349 then set a new architecture. */
3350 if (bfd_get_mach (stdoutput
) < pa11
)
3352 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
3353 as_warn ("could not update architecture and machine");
3361 /* Parse a condition for a fcmp instruction. Return the numerical
3362 code associated with the condition. */
3365 pa_parse_fp_cmp_cond (s
)
3372 for (i
= 0; i
< 32; i
++)
3374 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3375 strlen (fp_cond_map
[i
].string
)) == 0)
3377 cond
= fp_cond_map
[i
].cond
;
3378 *s
+= strlen (fp_cond_map
[i
].string
);
3379 /* If not a complete match, back up the input string and
3381 if (**s
!= ' ' && **s
!= '\t')
3383 *s
-= strlen (fp_cond_map
[i
].string
);
3386 while (**s
== ' ' || **s
== '\t')
3392 as_bad ("Invalid FP Compare Condition: %s", *s
);
3394 /* Advance over the bogus completer. */
3395 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3401 /* Parse an FP operand format completer returning the completer
3404 static fp_operand_format
3405 pa_parse_fp_format (s
)
3414 if (strncasecmp (*s
, "sgl", 3) == 0)
3419 else if (strncasecmp (*s
, "dbl", 3) == 0)
3424 else if (strncasecmp (*s
, "quad", 4) == 0)
3431 format
= ILLEGAL_FMT
;
3432 as_bad ("Invalid FP Operand Format: %3s", *s
);
3439 /* Convert from a selector string into a selector type. */
3442 pa_chk_field_selector (str
)
3445 int middle
, low
, high
;
3449 /* Read past any whitespace. */
3450 /* FIXME: should we read past newlines and formfeeds??? */
3451 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3454 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3455 name
[0] = tolower ((*str
)[0]),
3457 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3458 name
[0] = tolower ((*str
)[0]),
3459 name
[1] = tolower ((*str
)[1]),
3462 else if ((*str
)[3] == '\'' || (*str
)[3] == '%')
3463 name
[0] = tolower ((*str
)[0]),
3464 name
[1] = tolower ((*str
)[1]),
3465 name
[2] = tolower ((*str
)[2]),
3472 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3476 middle
= (low
+ high
) / 2;
3477 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3484 *str
+= strlen (name
) + 1;
3486 if (selector_table
[middle
].field_selector
== e_nsel
)
3489 return selector_table
[middle
].field_selector
;
3492 while (low
<= high
);
3497 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3500 get_expression (str
)
3506 save_in
= input_line_pointer
;
3507 input_line_pointer
= str
;
3508 seg
= expression (&the_insn
.exp
);
3509 if (!(seg
== absolute_section
3510 || seg
== undefined_section
3511 || SEG_NORMAL (seg
)))
3513 as_warn ("Bad segment in expression.");
3514 expr_end
= input_line_pointer
;
3515 input_line_pointer
= save_in
;
3518 expr_end
= input_line_pointer
;
3519 input_line_pointer
= save_in
;
3523 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3525 pa_get_absolute_expression (insn
, strp
)
3531 insn
->field_selector
= pa_chk_field_selector (strp
);
3532 save_in
= input_line_pointer
;
3533 input_line_pointer
= *strp
;
3534 expression (&insn
->exp
);
3535 if (insn
->exp
.X_op
!= O_constant
)
3537 as_bad ("Bad segment (should be absolute).");
3538 expr_end
= input_line_pointer
;
3539 input_line_pointer
= save_in
;
3542 expr_end
= input_line_pointer
;
3543 input_line_pointer
= save_in
;
3544 return evaluate_absolute (insn
);
3547 /* Evaluate an absolute expression EXP which may be modified by
3548 the selector FIELD_SELECTOR. Return the value of the expression. */
3550 evaluate_absolute (insn
)
3555 int field_selector
= insn
->field_selector
;
3558 value
= exp
.X_add_number
;
3560 switch (field_selector
)
3566 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3568 if (value
& 0x00000400)
3570 value
= (value
& 0xfffff800) >> 11;
3573 /* Sign extend from bit 21. */
3575 if (value
& 0x00000400)
3576 value
|= 0xfffff800;
3581 /* Arithmetic shift right 11 bits. */
3583 value
= (value
& 0xfffff800) >> 11;
3586 /* Set bits 0-20 to zero. */
3588 value
= value
& 0x7ff;
3591 /* Add 0x800 and arithmetic shift right 11 bits. */
3594 value
= (value
& 0xfffff800) >> 11;
3597 /* Set bitgs 0-21 to one. */
3599 value
|= 0xfffff800;
3602 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3604 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3608 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3613 BAD_CASE (field_selector
);
3619 /* Given an argument location specification return the associated
3620 argument location number. */
3623 pa_build_arg_reloc (type_name
)
3627 if (strncasecmp (type_name
, "no", 2) == 0)
3629 if (strncasecmp (type_name
, "gr", 2) == 0)
3631 else if (strncasecmp (type_name
, "fr", 2) == 0)
3633 else if (strncasecmp (type_name
, "fu", 2) == 0)
3636 as_bad ("Invalid argument location: %s\n", type_name
);
3641 /* Encode and return an argument relocation specification for
3642 the given register in the location specified by arg_reloc. */
3645 pa_align_arg_reloc (reg
, arg_reloc
)
3647 unsigned int arg_reloc
;
3649 unsigned int new_reloc
;
3651 new_reloc
= arg_reloc
;
3667 as_bad ("Invalid argument description: %d", reg
);
3673 /* Parse a PA nullification completer (,n). Return nonzero if the
3674 completer was found; return zero if no completer was found. */
3686 if (strncasecmp (*s
, "n", 1) == 0)
3690 as_bad ("Invalid Nullification: (%c)", **s
);
3699 /* Parse a non-negated compare/subtract completer returning the
3700 number (for encoding in instrutions) of the given completer.
3702 ISBRANCH specifies whether or not this is parsing a condition
3703 completer for a branch (vs a nullification completer for a
3704 computational instruction. */
3707 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3712 char *name
= *s
+ 1;
3720 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3724 if (strcmp (name
, "=") == 0)
3728 else if (strcmp (name
, "<") == 0)
3732 else if (strcmp (name
, "<=") == 0)
3736 else if (strcmp (name
, "<<") == 0)
3740 else if (strcmp (name
, "<<=") == 0)
3744 else if (strcasecmp (name
, "sv") == 0)
3748 else if (strcasecmp (name
, "od") == 0)
3752 /* If we have something like addb,n then there is no condition
3754 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3765 /* Reset pointers if this was really a ,n for a branch instruction. */
3766 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3772 /* Parse a negated compare/subtract completer returning the
3773 number (for encoding in instrutions) of the given completer.
3775 ISBRANCH specifies whether or not this is parsing a condition
3776 completer for a branch (vs a nullification completer for a
3777 computational instruction. */
3780 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3785 char *name
= *s
+ 1;
3793 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3797 if (strcasecmp (name
, "tr") == 0)
3801 else if (strcmp (name
, "<>") == 0)
3805 else if (strcmp (name
, ">=") == 0)
3809 else if (strcmp (name
, ">") == 0)
3813 else if (strcmp (name
, ">>=") == 0)
3817 else if (strcmp (name
, ">>") == 0)
3821 else if (strcasecmp (name
, "nsv") == 0)
3825 else if (strcasecmp (name
, "ev") == 0)
3829 /* If we have something like addb,n then there is no condition
3831 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3842 /* Reset pointers if this was really a ,n for a branch instruction. */
3843 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3849 /* Parse a non-negated addition completer returning the number
3850 (for encoding in instrutions) of the given completer.
3852 ISBRANCH specifies whether or not this is parsing a condition
3853 completer for a branch (vs a nullification completer for a
3854 computational instruction. */
3857 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3862 char *name
= *s
+ 1;
3870 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3874 if (strcmp (name
, "=") == 0)
3878 else if (strcmp (name
, "<") == 0)
3882 else if (strcmp (name
, "<=") == 0)
3886 else if (strcasecmp (name
, "nuv") == 0)
3890 else if (strcasecmp (name
, "znv") == 0)
3894 else if (strcasecmp (name
, "sv") == 0)
3898 else if (strcasecmp (name
, "od") == 0)
3902 /* If we have something like addb,n then there is no condition
3904 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3915 /* Reset pointers if this was really a ,n for a branch instruction. */
3916 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3922 /* Parse a negated addition completer returning the number
3923 (for encoding in instrutions) of the given completer.
3925 ISBRANCH specifies whether or not this is parsing a condition
3926 completer for a branch (vs a nullification completer for a
3927 computational instruction). */
3930 pa_parse_neg_add_cmpltr (s
, isbranch
)
3935 char *name
= *s
+ 1;
3943 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3947 if (strcasecmp (name
, "tr") == 0)
3951 else if (strcmp (name
, "<>") == 0)
3955 else if (strcmp (name
, ">=") == 0)
3959 else if (strcmp (name
, ">") == 0)
3963 else if (strcasecmp (name
, "uv") == 0)
3967 else if (strcasecmp (name
, "vnz") == 0)
3971 else if (strcasecmp (name
, "nsv") == 0)
3975 else if (strcasecmp (name
, "ev") == 0)
3979 /* If we have something like addb,n then there is no condition
3981 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3992 /* Reset pointers if this was really a ,n for a branch instruction. */
3993 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3999 /* Handle an alignment directive. Special so that we can update the
4000 alignment of the subspace if necessary. */
4004 /* We must have a valid space and subspace. */
4005 pa_check_current_space_and_subspace ();
4007 /* Let the generic gas code do most of the work. */
4008 s_align_bytes (bytes
);
4010 /* If bytes is a power of 2, then update the current subspace's
4011 alignment if necessary. */
4012 if (log2 (bytes
) != -1)
4013 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
4016 /* Handle a .BLOCK type pseudo-op. */
4024 unsigned int temp_size
;
4027 /* We must have a valid space and subspace. */
4028 pa_check_current_space_and_subspace ();
4030 temp_size
= get_absolute_expression ();
4032 /* Always fill with zeros, that's what the HP assembler does. */
4035 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4036 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4037 bzero (p
, temp_size
);
4039 /* Convert 2 bytes at a time. */
4041 for (i
= 0; i
< temp_size
; i
+= 2)
4043 md_number_to_chars (p
+ i
,
4045 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4048 pa_undefine_label ();
4049 demand_empty_rest_of_line ();
4052 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4060 /* The BRTAB relocations are only availble in SOM (to denote
4061 the beginning and end of branch tables). */
4062 char *where
= frag_more (0);
4064 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4065 NULL
, (offsetT
) 0, NULL
,
4066 0, begin
? R_HPPA_BEGIN_BRTAB
: R_HPPA_END_BRTAB
,
4067 e_fsel
, 0, 0, NULL
);
4070 demand_empty_rest_of_line ();
4073 /* Handle a .CALL pseudo-op. This involves storing away information
4074 about where arguments are to be found so the linker can detect
4075 (and correct) argument location mismatches between caller and callee. */
4081 /* We must have a valid space and subspace. */
4082 pa_check_current_space_and_subspace ();
4084 pa_call_args (&last_call_desc
);
4085 demand_empty_rest_of_line ();
4088 /* Do the dirty work of building a call descriptor which describes
4089 where the caller placed arguments to a function call. */
4092 pa_call_args (call_desc
)
4093 struct call_desc
*call_desc
;
4096 unsigned int temp
, arg_reloc
;
4098 while (!is_end_of_statement ())
4100 name
= input_line_pointer
;
4101 c
= get_symbol_end ();
4102 /* Process a source argument. */
4103 if ((strncasecmp (name
, "argw", 4) == 0))
4105 temp
= atoi (name
+ 4);
4106 p
= input_line_pointer
;
4108 input_line_pointer
++;
4109 name
= input_line_pointer
;
4110 c
= get_symbol_end ();
4111 arg_reloc
= pa_build_arg_reloc (name
);
4112 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4114 /* Process a return value. */
4115 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4117 p
= input_line_pointer
;
4119 input_line_pointer
++;
4120 name
= input_line_pointer
;
4121 c
= get_symbol_end ();
4122 arg_reloc
= pa_build_arg_reloc (name
);
4123 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4127 as_bad ("Invalid .CALL argument: %s", name
);
4129 p
= input_line_pointer
;
4131 if (!is_end_of_statement ())
4132 input_line_pointer
++;
4136 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4139 is_same_frag (frag1
, frag2
)
4146 else if (frag2
== NULL
)
4148 else if (frag1
== frag2
)
4150 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4151 return (is_same_frag (frag1
, frag2
->fr_next
));
4157 /* Build an entry in the UNWIND subspace from the given function
4158 attributes in CALL_INFO. This is not needed for SOM as using
4159 R_ENTRY and R_EXIT relocations allow the linker to handle building
4160 of the unwind spaces. */
4163 pa_build_unwind_subspace (call_info
)
4164 struct call_info
*call_info
;
4167 asection
*seg
, *save_seg
;
4168 subsegT subseg
, save_subseg
;
4172 /* Get into the right seg/subseg. This may involve creating
4173 the seg the first time through. Make sure to have the
4174 old seg/subseg so that we can reset things when we are done. */
4175 subseg
= SUBSEG_UNWIND
;
4176 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4177 if (seg
== ASEC_NULL
)
4179 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4180 bfd_set_section_flags (stdoutput
, seg
,
4181 SEC_READONLY
| SEC_HAS_CONTENTS
4182 | SEC_LOAD
| SEC_RELOC
);
4186 save_subseg
= now_subseg
;
4187 subseg_set (seg
, subseg
);
4190 /* Get some space to hold relocation information for the unwind
4193 md_number_to_chars (p
, 0, 4);
4195 /* Relocation info. for start offset of the function. */
4196 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4197 call_info
->start_symbol
, (offsetT
) 0,
4198 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4201 md_number_to_chars (p
, 0, 4);
4203 /* Relocation info. for end offset of the function.
4205 Because we allow reductions of 32bit relocations for ELF, this will be
4206 reduced to section_sym + offset which avoids putting the temporary
4207 symbol into the symbol table. It (should) end up giving the same
4208 value as call_info->start_symbol + function size once the linker is
4209 finished with its work. */
4211 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4212 call_info
->end_symbol
, (offsetT
) 0,
4213 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4216 unwind
= (char *) &call_info
->ci_unwind
;
4217 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4221 FRAG_APPEND_1_CHAR (c
);
4225 /* Return back to the original segment/subsegment. */
4226 subseg_set (save_seg
, save_subseg
);
4230 /* Process a .CALLINFO pseudo-op. This information is used later
4231 to build unwind descriptors and maybe one day to support
4232 .ENTER and .LEAVE. */
4235 pa_callinfo (unused
)
4241 /* We must have a valid space and subspace. */
4242 pa_check_current_space_and_subspace ();
4244 /* .CALLINFO must appear within a procedure definition. */
4245 if (!within_procedure
)
4246 as_bad (".callinfo is not within a procedure definition");
4248 /* Mark the fact that we found the .CALLINFO for the
4249 current procedure. */
4250 callinfo_found
= TRUE
;
4252 /* Iterate over the .CALLINFO arguments. */
4253 while (!is_end_of_statement ())
4255 name
= input_line_pointer
;
4256 c
= get_symbol_end ();
4257 /* Frame size specification. */
4258 if ((strncasecmp (name
, "frame", 5) == 0))
4260 p
= input_line_pointer
;
4262 input_line_pointer
++;
4263 temp
= get_absolute_expression ();
4264 if ((temp
& 0x3) != 0)
4266 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4270 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4271 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4274 /* Entry register (GR, GR and SR) specifications. */
4275 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4277 p
= input_line_pointer
;
4279 input_line_pointer
++;
4280 temp
= get_absolute_expression ();
4281 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4282 even though %r19 is caller saved. I think this is a bug in
4283 the HP assembler, and we are not going to emulate it. */
4284 if (temp
< 3 || temp
> 18)
4285 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4286 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4288 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4290 p
= input_line_pointer
;
4292 input_line_pointer
++;
4293 temp
= get_absolute_expression ();
4294 /* Similarly the HP assembler takes 31 as the high bound even
4295 though %fr21 is the last callee saved floating point register. */
4296 if (temp
< 12 || temp
> 21)
4297 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4298 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4300 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4302 p
= input_line_pointer
;
4304 input_line_pointer
++;
4305 temp
= get_absolute_expression ();
4307 as_bad ("Value for ENTRY_SR must be 3\n");
4309 /* Note whether or not this function performs any calls. */
4310 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4311 (strncasecmp (name
, "caller", 6) == 0))
4313 p
= input_line_pointer
;
4316 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4318 p
= input_line_pointer
;
4321 /* Should RP be saved into the stack. */
4322 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4324 p
= input_line_pointer
;
4326 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4328 /* Likewise for SP. */
4329 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4331 p
= input_line_pointer
;
4333 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4335 /* Is this an unwindable procedure. If so mark it so
4336 in the unwind descriptor. */
4337 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4339 p
= input_line_pointer
;
4341 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4343 /* Is this an interrupt routine. If so mark it in the
4344 unwind descriptor. */
4345 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4347 p
= input_line_pointer
;
4349 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4351 /* Is this a millicode routine. "millicode" isn't in my
4352 assembler manual, but my copy is old. The HP assembler
4353 accepts it, and there's a place in the unwind descriptor
4354 to drop the information, so we'll accept it too. */
4355 else if ((strncasecmp (name
, "millicode", 9) == 0))
4357 p
= input_line_pointer
;
4359 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4363 as_bad ("Invalid .CALLINFO argument: %s", name
);
4364 *input_line_pointer
= c
;
4366 if (!is_end_of_statement ())
4367 input_line_pointer
++;
4370 demand_empty_rest_of_line ();
4373 /* Switch into the code subspace. */
4379 current_space
= is_defined_space ("$TEXT$");
4381 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
4383 pa_undefine_label ();
4386 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4387 the .comm pseudo-op has the following symtax:
4389 <label> .comm <length>
4391 where <label> is optional and is a symbol whose address will be the start of
4392 a block of memory <length> bytes long. <length> must be an absolute
4393 expression. <length> bytes will be allocated in the current space
4396 Also note the label may not even be on the same line as the .comm.
4398 This difference in syntax means the colon function will be called
4399 on the symbol before we arrive in pa_comm. colon will set a number
4400 of attributes of the symbol that need to be fixed here. In particular
4401 the value, section pointer, fragment pointer, flags, etc. What
4404 This also makes error detection all but impossible. */
4412 label_symbol_struct
*label_symbol
= pa_get_label ();
4415 symbol
= label_symbol
->lss_label
;
4420 size
= get_absolute_expression ();
4424 S_SET_VALUE (symbol
, size
);
4425 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4426 S_SET_EXTERNAL (symbol
);
4428 /* colon() has already set the frag to the current location in the
4429 current subspace; we need to reset the fragment to the zero address
4430 fragment. We also need to reset the segment pointer. */
4431 symbol
->sy_frag
= &zero_address_frag
;
4433 demand_empty_rest_of_line ();
4436 /* Process a .END pseudo-op. */
4442 demand_empty_rest_of_line ();
4445 /* Process a .ENTER pseudo-op. This is not supported. */
4450 /* We must have a valid space and subspace. */
4451 pa_check_current_space_and_subspace ();
4456 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4462 /* We must have a valid space and subspace. */
4463 pa_check_current_space_and_subspace ();
4465 if (!within_procedure
)
4466 as_bad ("Misplaced .entry. Ignored.");
4469 if (!callinfo_found
)
4470 as_bad ("Missing .callinfo.");
4472 demand_empty_rest_of_line ();
4473 within_entry_exit
= TRUE
;
4476 /* SOM defers building of unwind descriptors until the link phase.
4477 The assembler is responsible for creating an R_ENTRY relocation
4478 to mark the beginning of a region and hold the unwind bits, and
4479 for creating an R_EXIT relocation to mark the end of the region.
4481 FIXME. ELF should be using the same conventions! The problem
4482 is an unwind requires too much relocation space. Hmmm. Maybe
4483 if we split the unwind bits up between the relocations which
4484 denote the entry and exit points. */
4485 if (last_call_info
->start_symbol
!= NULL
)
4487 char *where
= frag_more (0);
4489 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4490 NULL
, (offsetT
) 0, NULL
,
4491 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4492 (int *) &last_call_info
->ci_unwind
.descriptor
);
4497 /* Handle a .EQU pseudo-op. */
4503 label_symbol_struct
*label_symbol
= pa_get_label ();
4508 symbol
= label_symbol
->lss_label
;
4510 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4512 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4513 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4518 as_bad (".REG must use a label");
4520 as_bad (".EQU must use a label");
4523 pa_undefine_label ();
4524 demand_empty_rest_of_line ();
4527 /* Helper function. Does processing for the end of a function. This
4528 usually involves creating some relocations or building special
4529 symbols to mark the end of the function. */
4536 where
= frag_more (0);
4539 /* Mark the end of the function, stuff away the location of the frag
4540 for the end of the function, and finally call pa_build_unwind_subspace
4541 to add an entry in the unwind table. */
4542 hppa_elf_mark_end_of_function ();
4543 pa_build_unwind_subspace (last_call_info
);
4545 /* SOM defers building of unwind descriptors until the link phase.
4546 The assembler is responsible for creating an R_ENTRY relocation
4547 to mark the beginning of a region and hold the unwind bits, and
4548 for creating an R_EXIT relocation to mark the end of the region.
4550 FIXME. ELF should be using the same conventions! The problem
4551 is an unwind requires too much relocation space. Hmmm. Maybe
4552 if we split the unwind bits up between the relocations which
4553 denote the entry and exit points. */
4554 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4556 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4557 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4561 /* Process a .EXIT pseudo-op. */
4567 /* We must have a valid space and subspace. */
4568 pa_check_current_space_and_subspace ();
4570 if (!within_procedure
)
4571 as_bad (".EXIT must appear within a procedure");
4574 if (!callinfo_found
)
4575 as_bad ("Missing .callinfo");
4578 if (!within_entry_exit
)
4579 as_bad ("No .ENTRY for this .EXIT");
4582 within_entry_exit
= FALSE
;
4587 demand_empty_rest_of_line ();
4590 /* Process a .EXPORT directive. This makes functions external
4591 and provides information such as argument relocation entries
4601 name
= input_line_pointer
;
4602 c
= get_symbol_end ();
4603 /* Make sure the given symbol exists. */
4604 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4606 as_bad ("Cannot define export symbol: %s\n", name
);
4607 p
= input_line_pointer
;
4609 input_line_pointer
++;
4613 /* OK. Set the external bits and process argument relocations. */
4614 S_SET_EXTERNAL (symbol
);
4615 p
= input_line_pointer
;
4617 if (!is_end_of_statement ())
4619 input_line_pointer
++;
4620 pa_type_args (symbol
, 1);
4624 demand_empty_rest_of_line ();
4627 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4630 pa_type_args (symbolP
, is_export
)
4635 unsigned int temp
, arg_reloc
;
4636 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4637 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4639 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4642 input_line_pointer
+= 8;
4643 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4644 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4645 type
= SYMBOL_TYPE_ABSOLUTE
;
4647 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4649 input_line_pointer
+= 4;
4650 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4651 instead one should be IMPORTing/EXPORTing ENTRY types.
4653 Complain if one tries to EXPORT a CODE type since that's never
4654 done. Both GCC and HP C still try to IMPORT CODE types, so
4655 silently fix them to be ENTRY types. */
4656 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4659 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4661 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4662 type
= SYMBOL_TYPE_ENTRY
;
4666 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4667 type
= SYMBOL_TYPE_CODE
;
4670 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4672 input_line_pointer
+= 4;
4673 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4674 type
= SYMBOL_TYPE_DATA
;
4676 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4678 input_line_pointer
+= 5;
4679 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4680 type
= SYMBOL_TYPE_ENTRY
;
4682 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4684 input_line_pointer
+= 9;
4685 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4686 type
= SYMBOL_TYPE_MILLICODE
;
4688 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4690 input_line_pointer
+= 6;
4691 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4692 type
= SYMBOL_TYPE_PLABEL
;
4694 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4696 input_line_pointer
+= 8;
4697 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4698 type
= SYMBOL_TYPE_PRI_PROG
;
4700 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4702 input_line_pointer
+= 8;
4703 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4704 type
= SYMBOL_TYPE_SEC_PROG
;
4707 /* SOM requires much more information about symbol types
4708 than BFD understands. This is how we get this information
4709 to the SOM BFD backend. */
4710 #ifdef obj_set_symbol_type
4711 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4714 /* Now that the type of the exported symbol has been handled,
4715 handle any argument relocation information. */
4716 while (!is_end_of_statement ())
4718 if (*input_line_pointer
== ',')
4719 input_line_pointer
++;
4720 name
= input_line_pointer
;
4721 c
= get_symbol_end ();
4722 /* Argument sources. */
4723 if ((strncasecmp (name
, "argw", 4) == 0))
4725 p
= input_line_pointer
;
4727 input_line_pointer
++;
4728 temp
= atoi (name
+ 4);
4729 name
= input_line_pointer
;
4730 c
= get_symbol_end ();
4731 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4732 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4733 *input_line_pointer
= c
;
4735 /* The return value. */
4736 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4738 p
= input_line_pointer
;
4740 input_line_pointer
++;
4741 name
= input_line_pointer
;
4742 c
= get_symbol_end ();
4743 arg_reloc
= pa_build_arg_reloc (name
);
4744 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4745 *input_line_pointer
= c
;
4747 /* Privelege level. */
4748 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4750 p
= input_line_pointer
;
4752 input_line_pointer
++;
4753 temp
= atoi (input_line_pointer
);
4754 c
= get_symbol_end ();
4755 *input_line_pointer
= c
;
4759 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4760 p
= input_line_pointer
;
4763 if (!is_end_of_statement ())
4764 input_line_pointer
++;
4768 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4769 assembly file must either be defined in the assembly file, or
4770 explicitly IMPORTED from another. */
4779 name
= input_line_pointer
;
4780 c
= get_symbol_end ();
4782 symbol
= symbol_find (name
);
4783 /* Ugh. We might be importing a symbol defined earlier in the file,
4784 in which case all the code below will really screw things up
4785 (set the wrong segment, symbol flags & type, etc). */
4786 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4788 symbol
= symbol_find_or_make (name
);
4789 p
= input_line_pointer
;
4792 if (!is_end_of_statement ())
4794 input_line_pointer
++;
4795 pa_type_args (symbol
, 0);
4799 /* Sigh. To be compatable with the HP assembler and to help
4800 poorly written assembly code, we assign a type based on
4801 the the current segment. Note only BSF_FUNCTION really
4802 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4803 if (now_seg
== text_section
)
4804 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4806 /* If the section is undefined, then the symbol is undefined
4807 Since this is an import, leave the section undefined. */
4808 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4813 /* The symbol was already defined. Just eat everything up to
4814 the end of the current statement. */
4815 while (!is_end_of_statement ())
4816 input_line_pointer
++;
4819 demand_empty_rest_of_line ();
4822 /* Handle a .LABEL pseudo-op. */
4830 name
= input_line_pointer
;
4831 c
= get_symbol_end ();
4833 if (strlen (name
) > 0)
4836 p
= input_line_pointer
;
4841 as_warn ("Missing label name on .LABEL");
4844 if (!is_end_of_statement ())
4846 as_warn ("extra .LABEL arguments ignored.");
4847 ignore_rest_of_line ();
4849 demand_empty_rest_of_line ();
4852 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4858 /* We must have a valid space and subspace. */
4859 pa_check_current_space_and_subspace ();
4864 /* Handle a .LEVEL pseudo-op. */
4872 level
= input_line_pointer
;
4873 if (strncmp (level
, "1.0", 3) == 0)
4875 input_line_pointer
+= 3;
4876 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
4877 as_warn ("could not set architecture and machine");
4879 else if (strncmp (level
, "1.1", 3) == 0)
4881 input_line_pointer
+= 3;
4882 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 11))
4883 as_warn ("could not set architecture and machine");
4887 as_bad ("Unrecognized .LEVEL argument\n");
4888 ignore_rest_of_line ();
4890 demand_empty_rest_of_line ();
4893 /* Handle a .ORIGIN pseudo-op. */
4899 /* We must have a valid space and subspace. */
4900 pa_check_current_space_and_subspace ();
4903 pa_undefine_label ();
4906 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4907 is for static functions. FIXME. Should share more code with .EXPORT. */
4916 name
= input_line_pointer
;
4917 c
= get_symbol_end ();
4919 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4921 as_bad ("Cannot define static symbol: %s\n", name
);
4922 p
= input_line_pointer
;
4924 input_line_pointer
++;
4928 S_CLEAR_EXTERNAL (symbol
);
4929 p
= input_line_pointer
;
4931 if (!is_end_of_statement ())
4933 input_line_pointer
++;
4934 pa_type_args (symbol
, 0);
4938 demand_empty_rest_of_line ();
4941 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4942 of a procedure from a syntatical point of view. */
4948 struct call_info
*call_info
;
4950 /* We must have a valid space and subspace. */
4951 pa_check_current_space_and_subspace ();
4953 if (within_procedure
)
4954 as_fatal ("Nested procedures");
4956 /* Reset global variables for new procedure. */
4957 callinfo_found
= FALSE
;
4958 within_procedure
= TRUE
;
4960 /* Create another call_info structure. */
4961 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4964 as_fatal ("Cannot allocate unwind descriptor\n");
4966 bzero (call_info
, sizeof (struct call_info
));
4968 call_info
->ci_next
= NULL
;
4970 if (call_info_root
== NULL
)
4972 call_info_root
= call_info
;
4973 last_call_info
= call_info
;
4977 last_call_info
->ci_next
= call_info
;
4978 last_call_info
= call_info
;
4981 /* set up defaults on call_info structure */
4983 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
4984 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
4985 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
4987 /* If we got a .PROC pseudo-op, we know that the function is defined
4988 locally. Make sure it gets into the symbol table. */
4990 label_symbol_struct
*label_symbol
= pa_get_label ();
4994 if (label_symbol
->lss_label
)
4996 last_call_info
->start_symbol
= label_symbol
->lss_label
;
4997 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5000 as_bad ("Missing function name for .PROC (corrupted label chain)");
5003 last_call_info
->start_symbol
= NULL
;
5006 demand_empty_rest_of_line ();
5009 /* Process the syntatical end of a procedure. Make sure all the
5010 appropriate pseudo-ops were found within the procedure. */
5017 /* We must have a valid space and subspace. */
5018 pa_check_current_space_and_subspace ();
5020 /* If we are within a procedure definition, make sure we've
5021 defined a label for the procedure; handle case where the
5022 label was defined after the .PROC directive.
5024 Note there's not need to diddle with the segment or fragment
5025 for the label symbol in this case. We have already switched
5026 into the new $CODE$ subspace at this point. */
5027 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
5029 label_symbol_struct
*label_symbol
= pa_get_label ();
5033 if (label_symbol
->lss_label
)
5035 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5036 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5038 /* Also handle allocation of a fixup to hold the unwind
5039 information when the label appears after the proc/procend. */
5040 if (within_entry_exit
)
5042 char *where
= frag_more (0);
5044 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5045 NULL
, (offsetT
) 0, NULL
,
5046 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
5047 (int *) &last_call_info
->ci_unwind
.descriptor
);
5052 as_bad ("Missing function name for .PROC (corrupted label chain)");
5055 as_bad ("Missing function name for .PROC");
5058 if (!within_procedure
)
5059 as_bad ("misplaced .procend");
5061 if (!callinfo_found
)
5062 as_bad ("Missing .callinfo for this procedure");
5064 if (within_entry_exit
)
5065 as_bad ("Missing .EXIT for a .ENTRY");
5068 /* ELF needs to mark the end of each function so that it can compute
5069 the size of the function (apparently its needed in the symbol table). */
5070 hppa_elf_mark_end_of_function ();
5073 within_procedure
= FALSE
;
5074 demand_empty_rest_of_line ();
5075 pa_undefine_label ();
5078 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5079 then create a new space entry to hold the information specified
5080 by the parameters to the .SPACE directive. */
5082 static sd_chain_struct
*
5083 pa_parse_space_stmt (space_name
, create_flag
)
5087 char *name
, *ptemp
, c
;
5088 char loadable
, defined
, private, sort
;
5090 asection
*seg
= NULL
;
5091 sd_chain_struct
*space
;
5093 /* load default values */
5099 if (strcmp (space_name
, "$TEXT$") == 0)
5101 seg
= pa_def_spaces
[0].segment
;
5102 defined
= pa_def_spaces
[0].defined
;
5103 private = pa_def_spaces
[0].private;
5104 sort
= pa_def_spaces
[0].sort
;
5105 spnum
= pa_def_spaces
[0].spnum
;
5107 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5109 seg
= pa_def_spaces
[1].segment
;
5110 defined
= pa_def_spaces
[1].defined
;
5111 private = pa_def_spaces
[1].private;
5112 sort
= pa_def_spaces
[1].sort
;
5113 spnum
= pa_def_spaces
[1].spnum
;
5116 if (!is_end_of_statement ())
5118 print_errors
= FALSE
;
5119 ptemp
= input_line_pointer
+ 1;
5120 /* First see if the space was specified as a number rather than
5121 as a name. According to the PA assembly manual the rest of
5122 the line should be ignored. */
5123 temp
= pa_parse_number (&ptemp
, 0);
5127 input_line_pointer
= ptemp
;
5131 while (!is_end_of_statement ())
5133 input_line_pointer
++;
5134 name
= input_line_pointer
;
5135 c
= get_symbol_end ();
5136 if ((strncasecmp (name
, "spnum", 5) == 0))
5138 *input_line_pointer
= c
;
5139 input_line_pointer
++;
5140 spnum
= get_absolute_expression ();
5142 else if ((strncasecmp (name
, "sort", 4) == 0))
5144 *input_line_pointer
= c
;
5145 input_line_pointer
++;
5146 sort
= get_absolute_expression ();
5148 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5150 *input_line_pointer
= c
;
5153 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5155 *input_line_pointer
= c
;
5158 else if ((strncasecmp (name
, "private", 7) == 0))
5160 *input_line_pointer
= c
;
5165 as_bad ("Invalid .SPACE argument");
5166 *input_line_pointer
= c
;
5167 if (!is_end_of_statement ())
5168 input_line_pointer
++;
5172 print_errors
= TRUE
;
5175 if (create_flag
&& seg
== NULL
)
5176 seg
= subseg_new (space_name
, 0);
5178 /* If create_flag is nonzero, then create the new space with
5179 the attributes computed above. Else set the values in
5180 an already existing space -- this can only happen for
5181 the first occurence of a built-in space. */
5183 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5184 private, sort
, seg
, 1);
5187 space
= is_defined_space (space_name
);
5188 SPACE_SPNUM (space
) = spnum
;
5189 SPACE_DEFINED (space
) = defined
& 1;
5190 SPACE_USER_DEFINED (space
) = 1;
5193 #ifdef obj_set_section_attributes
5194 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5200 /* Handle a .SPACE pseudo-op; this switches the current space to the
5201 given space, creating the new space if necessary. */
5207 char *name
, c
, *space_name
, *save_s
;
5209 sd_chain_struct
*sd_chain
;
5211 if (within_procedure
)
5213 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5214 ignore_rest_of_line ();
5218 /* Check for some of the predefined spaces. FIXME: most of the code
5219 below is repeated several times, can we extract the common parts
5220 and place them into a subroutine or something similar? */
5221 /* FIXME Is this (and the next IF stmt) really right?
5222 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5223 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5225 input_line_pointer
+= 6;
5226 sd_chain
= is_defined_space ("$TEXT$");
5227 if (sd_chain
== NULL
)
5228 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5229 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5230 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5232 current_space
= sd_chain
;
5233 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5235 = pa_subsegment_to_subspace (text_section
,
5236 sd_chain
->sd_last_subseg
);
5237 demand_empty_rest_of_line ();
5240 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5242 input_line_pointer
+= 9;
5243 sd_chain
= is_defined_space ("$PRIVATE$");
5244 if (sd_chain
== NULL
)
5245 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5246 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5247 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5249 current_space
= sd_chain
;
5250 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5252 = pa_subsegment_to_subspace (data_section
,
5253 sd_chain
->sd_last_subseg
);
5254 demand_empty_rest_of_line ();
5257 if (!strncasecmp (input_line_pointer
,
5258 GDB_DEBUG_SPACE_NAME
,
5259 strlen (GDB_DEBUG_SPACE_NAME
)))
5261 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5262 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5263 if (sd_chain
== NULL
)
5264 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5265 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5266 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5268 current_space
= sd_chain
;
5271 asection
*gdb_section
5272 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5274 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5276 = pa_subsegment_to_subspace (gdb_section
,
5277 sd_chain
->sd_last_subseg
);
5279 demand_empty_rest_of_line ();
5283 /* It could be a space specified by number. */
5285 save_s
= input_line_pointer
;
5286 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5288 if ((sd_chain
= pa_find_space_by_number (temp
)))
5290 current_space
= sd_chain
;
5292 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5294 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5295 sd_chain
->sd_last_subseg
);
5296 demand_empty_rest_of_line ();
5301 /* Not a number, attempt to create a new space. */
5303 input_line_pointer
= save_s
;
5304 name
= input_line_pointer
;
5305 c
= get_symbol_end ();
5306 space_name
= xmalloc (strlen (name
) + 1);
5307 strcpy (space_name
, name
);
5308 *input_line_pointer
= c
;
5310 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5311 current_space
= sd_chain
;
5313 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5314 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5315 sd_chain
->sd_last_subseg
);
5316 demand_empty_rest_of_line ();
5320 /* Switch to a new space. (I think). FIXME. */
5329 sd_chain_struct
*space
;
5331 name
= input_line_pointer
;
5332 c
= get_symbol_end ();
5333 space
= is_defined_space (name
);
5337 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5340 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5342 *input_line_pointer
= c
;
5343 demand_empty_rest_of_line ();
5346 /* If VALUE is an exact power of two between zero and 2^31, then
5347 return log2 (VALUE). Else return -1. */
5355 while ((1 << shift
) != value
&& shift
< 32)
5364 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5365 given subspace, creating the new subspace if necessary.
5367 FIXME. Should mirror pa_space more closely, in particular how
5368 they're broken up into subroutines. */
5371 pa_subspace (create_new
)
5374 char *name
, *ss_name
, *alias
, c
;
5375 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5376 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5377 sd_chain_struct
*space
;
5378 ssd_chain_struct
*ssd
;
5381 if (current_space
== NULL
)
5382 as_fatal ("Must be in a space before changing or declaring subspaces.\n");
5384 if (within_procedure
)
5386 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5387 ignore_rest_of_line ();
5391 name
= input_line_pointer
;
5392 c
= get_symbol_end ();
5393 ss_name
= xmalloc (strlen (name
) + 1);
5394 strcpy (ss_name
, name
);
5395 *input_line_pointer
= c
;
5397 /* Load default values. */
5410 space
= current_space
;
5414 ssd
= is_defined_subspace (ss_name
);
5415 /* Allow user to override the builtin attributes of subspaces. But
5416 only allow the attributes to be changed once! */
5417 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5419 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5420 current_subspace
= ssd
;
5421 if (!is_end_of_statement ())
5422 as_warn ("Parameters of an existing subspace can\'t be modified");
5423 demand_empty_rest_of_line ();
5428 /* A new subspace. Load default values if it matches one of
5429 the builtin subspaces. */
5431 while (pa_def_subspaces
[i
].name
)
5433 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5435 loadable
= pa_def_subspaces
[i
].loadable
;
5436 common
= pa_def_subspaces
[i
].common
;
5437 dup_common
= pa_def_subspaces
[i
].dup_common
;
5438 code_only
= pa_def_subspaces
[i
].code_only
;
5439 zero
= pa_def_subspaces
[i
].zero
;
5440 space_index
= pa_def_subspaces
[i
].space_index
;
5441 alignment
= pa_def_subspaces
[i
].alignment
;
5442 quadrant
= pa_def_subspaces
[i
].quadrant
;
5443 access
= pa_def_subspaces
[i
].access
;
5444 sort
= pa_def_subspaces
[i
].sort
;
5445 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5446 alias
= pa_def_subspaces
[i
].alias
;
5453 /* We should be working with a new subspace now. Fill in
5454 any information as specified by the user. */
5455 if (!is_end_of_statement ())
5457 input_line_pointer
++;
5458 while (!is_end_of_statement ())
5460 name
= input_line_pointer
;
5461 c
= get_symbol_end ();
5462 if ((strncasecmp (name
, "quad", 4) == 0))
5464 *input_line_pointer
= c
;
5465 input_line_pointer
++;
5466 quadrant
= get_absolute_expression ();
5468 else if ((strncasecmp (name
, "align", 5) == 0))
5470 *input_line_pointer
= c
;
5471 input_line_pointer
++;
5472 alignment
= get_absolute_expression ();
5473 if (log2 (alignment
) == -1)
5475 as_bad ("Alignment must be a power of 2");
5479 else if ((strncasecmp (name
, "access", 6) == 0))
5481 *input_line_pointer
= c
;
5482 input_line_pointer
++;
5483 access
= get_absolute_expression ();
5485 else if ((strncasecmp (name
, "sort", 4) == 0))
5487 *input_line_pointer
= c
;
5488 input_line_pointer
++;
5489 sort
= get_absolute_expression ();
5491 else if ((strncasecmp (name
, "code_only", 9) == 0))
5493 *input_line_pointer
= c
;
5496 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5498 *input_line_pointer
= c
;
5501 else if ((strncasecmp (name
, "common", 6) == 0))
5503 *input_line_pointer
= c
;
5506 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5508 *input_line_pointer
= c
;
5511 else if ((strncasecmp (name
, "zero", 4) == 0))
5513 *input_line_pointer
= c
;
5516 else if ((strncasecmp (name
, "first", 5) == 0))
5517 as_bad ("FIRST not supported as a .SUBSPACE argument");
5519 as_bad ("Invalid .SUBSPACE argument");
5520 if (!is_end_of_statement ())
5521 input_line_pointer
++;
5525 /* Compute a reasonable set of BFD flags based on the information
5526 in the .subspace directive. */
5527 applicable
= bfd_applicable_section_flags (stdoutput
);
5530 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5533 if (common
|| dup_common
)
5534 flags
|= SEC_IS_COMMON
;
5536 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5538 /* This is a zero-filled subspace (eg BSS). */
5540 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
5542 applicable
&= flags
;
5544 /* If this is an existing subspace, then we want to use the
5545 segment already associated with the subspace.
5547 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5548 lots of sections. It might be a problem in the PA ELF
5549 code, I do not know yet. For now avoid creating anything
5550 but the "standard" sections for ELF. */
5552 section
= subseg_force_new (ss_name
, 0);
5554 section
= ssd
->ssd_seg
;
5556 section
= subseg_new (alias
, 0);
5557 else if (!alias
&& USE_ALIASES
)
5559 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5560 demand_empty_rest_of_line ();
5564 section
= subseg_new (ss_name
, 0);
5567 seg_info (section
)->bss
= 1;
5569 /* Now set the flags. */
5570 bfd_set_section_flags (stdoutput
, section
, applicable
);
5572 /* Record any alignment request for this section. */
5573 record_alignment (section
, log2 (alignment
));
5575 /* Set the starting offset for this section. */
5576 bfd_set_section_vma (stdoutput
, section
,
5577 pa_subspace_start (space
, quadrant
));
5579 /* Now that all the flags are set, update an existing subspace,
5580 or create a new one. */
5583 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5584 code_only
, common
, dup_common
,
5585 sort
, zero
, access
, space_index
,
5586 alignment
, quadrant
,
5589 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5591 dup_common
, zero
, sort
,
5592 access
, space_index
,
5593 alignment
, quadrant
, section
);
5595 demand_empty_rest_of_line ();
5596 current_subspace
->ssd_seg
= section
;
5597 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5599 SUBSPACE_DEFINED (current_subspace
) = 1;
5603 /* Create default space and subspace dictionaries. */
5610 space_dict_root
= NULL
;
5611 space_dict_last
= NULL
;
5614 while (pa_def_spaces
[i
].name
)
5618 /* Pick the right name to use for the new section. */
5619 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5620 name
= pa_def_spaces
[i
].alias
;
5622 name
= pa_def_spaces
[i
].name
;
5624 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5625 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5626 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5627 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5628 pa_def_spaces
[i
].segment
, 0);
5633 while (pa_def_subspaces
[i
].name
)
5636 int applicable
, subsegment
;
5637 asection
*segment
= NULL
;
5638 sd_chain_struct
*space
;
5640 /* Pick the right name for the new section and pick the right
5641 subsegment number. */
5642 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5644 name
= pa_def_subspaces
[i
].alias
;
5645 subsegment
= pa_def_subspaces
[i
].subsegment
;
5649 name
= pa_def_subspaces
[i
].name
;
5653 /* Create the new section. */
5654 segment
= subseg_new (name
, subsegment
);
5657 /* For SOM we want to replace the standard .text, .data, and .bss
5658 sections with our own. We also want to set BFD flags for
5659 all the built-in subspaces. */
5660 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5662 text_section
= segment
;
5663 applicable
= bfd_applicable_section_flags (stdoutput
);
5664 bfd_set_section_flags (stdoutput
, segment
,
5665 applicable
& (SEC_ALLOC
| SEC_LOAD
5666 | SEC_RELOC
| SEC_CODE
5668 | SEC_HAS_CONTENTS
));
5670 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5672 data_section
= segment
;
5673 applicable
= bfd_applicable_section_flags (stdoutput
);
5674 bfd_set_section_flags (stdoutput
, segment
,
5675 applicable
& (SEC_ALLOC
| SEC_LOAD
5677 | SEC_HAS_CONTENTS
));
5681 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5683 bss_section
= segment
;
5684 applicable
= bfd_applicable_section_flags (stdoutput
);
5685 bfd_set_section_flags (stdoutput
, segment
,
5686 applicable
& SEC_ALLOC
);
5688 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5690 applicable
= bfd_applicable_section_flags (stdoutput
);
5691 bfd_set_section_flags (stdoutput
, segment
,
5692 applicable
& (SEC_ALLOC
| SEC_LOAD
5695 | SEC_HAS_CONTENTS
));
5697 else if (!strcmp (pa_def_subspaces
[i
].name
, "$MILLICODE$")
5700 applicable
= bfd_applicable_section_flags (stdoutput
);
5701 bfd_set_section_flags (stdoutput
, segment
,
5702 applicable
& (SEC_ALLOC
| SEC_LOAD
5705 | SEC_HAS_CONTENTS
));
5707 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5709 applicable
= bfd_applicable_section_flags (stdoutput
);
5710 bfd_set_section_flags (stdoutput
, segment
,
5711 applicable
& (SEC_ALLOC
| SEC_LOAD
5714 | SEC_HAS_CONTENTS
));
5717 /* Find the space associated with this subspace. */
5718 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5719 def_space_index
].segment
);
5722 as_fatal ("Internal error: Unable to find containing space for %s.",
5723 pa_def_subspaces
[i
].name
);
5726 create_new_subspace (space
, name
,
5727 pa_def_subspaces
[i
].loadable
,
5728 pa_def_subspaces
[i
].code_only
,
5729 pa_def_subspaces
[i
].common
,
5730 pa_def_subspaces
[i
].dup_common
,
5731 pa_def_subspaces
[i
].zero
,
5732 pa_def_subspaces
[i
].sort
,
5733 pa_def_subspaces
[i
].access
,
5734 pa_def_subspaces
[i
].space_index
,
5735 pa_def_subspaces
[i
].alignment
,
5736 pa_def_subspaces
[i
].quadrant
,
5744 /* Create a new space NAME, with the appropriate flags as defined
5745 by the given parameters. */
5747 static sd_chain_struct
*
5748 create_new_space (name
, spnum
, loadable
, defined
, private,
5749 sort
, seg
, user_defined
)
5759 sd_chain_struct
*chain_entry
;
5761 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5763 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5766 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5767 strcpy (SPACE_NAME (chain_entry
), name
);
5768 SPACE_DEFINED (chain_entry
) = defined
;
5769 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5770 SPACE_SPNUM (chain_entry
) = spnum
;
5772 chain_entry
->sd_seg
= seg
;
5773 chain_entry
->sd_last_subseg
= -1;
5774 chain_entry
->sd_subspaces
= NULL
;
5775 chain_entry
->sd_next
= NULL
;
5777 /* Find spot for the new space based on its sort key. */
5778 if (!space_dict_last
)
5779 space_dict_last
= chain_entry
;
5781 if (space_dict_root
== NULL
)
5782 space_dict_root
= chain_entry
;
5785 sd_chain_struct
*chain_pointer
;
5786 sd_chain_struct
*prev_chain_pointer
;
5788 chain_pointer
= space_dict_root
;
5789 prev_chain_pointer
= NULL
;
5791 while (chain_pointer
)
5793 prev_chain_pointer
= chain_pointer
;
5794 chain_pointer
= chain_pointer
->sd_next
;
5797 /* At this point we've found the correct place to add the new
5798 entry. So add it and update the linked lists as appropriate. */
5799 if (prev_chain_pointer
)
5801 chain_entry
->sd_next
= chain_pointer
;
5802 prev_chain_pointer
->sd_next
= chain_entry
;
5806 space_dict_root
= chain_entry
;
5807 chain_entry
->sd_next
= chain_pointer
;
5810 if (chain_entry
->sd_next
== NULL
)
5811 space_dict_last
= chain_entry
;
5814 /* This is here to catch predefined spaces which do not get
5815 modified by the user's input. Another call is found at
5816 the bottom of pa_parse_space_stmt to handle cases where
5817 the user modifies a predefined space. */
5818 #ifdef obj_set_section_attributes
5819 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5825 /* Create a new subspace NAME, with the appropriate flags as defined
5826 by the given parameters.
5828 Add the new subspace to the subspace dictionary chain in numerical
5829 order as defined by the SORT entries. */
5831 static ssd_chain_struct
*
5832 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5833 dup_common
, is_zero
, sort
, access
, space_index
,
5834 alignment
, quadrant
, seg
)
5835 sd_chain_struct
*space
;
5837 int loadable
, code_only
, common
, dup_common
, is_zero
;
5845 ssd_chain_struct
*chain_entry
;
5847 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5849 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5851 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5852 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5854 /* Initialize subspace_defined. When we hit a .subspace directive
5855 we'll set it to 1 which "locks-in" the subspace attributes. */
5856 SUBSPACE_DEFINED (chain_entry
) = 0;
5858 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5859 chain_entry
->ssd_seg
= seg
;
5860 chain_entry
->ssd_next
= NULL
;
5862 /* Find spot for the new subspace based on its sort key. */
5863 if (space
->sd_subspaces
== NULL
)
5864 space
->sd_subspaces
= chain_entry
;
5867 ssd_chain_struct
*chain_pointer
;
5868 ssd_chain_struct
*prev_chain_pointer
;
5870 chain_pointer
= space
->sd_subspaces
;
5871 prev_chain_pointer
= NULL
;
5873 while (chain_pointer
)
5875 prev_chain_pointer
= chain_pointer
;
5876 chain_pointer
= chain_pointer
->ssd_next
;
5879 /* Now we have somewhere to put the new entry. Insert it and update
5881 if (prev_chain_pointer
)
5883 chain_entry
->ssd_next
= chain_pointer
;
5884 prev_chain_pointer
->ssd_next
= chain_entry
;
5888 space
->sd_subspaces
= chain_entry
;
5889 chain_entry
->ssd_next
= chain_pointer
;
5893 #ifdef obj_set_subsection_attributes
5894 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5901 /* Update the information for the given subspace based upon the
5902 various arguments. Return the modified subspace chain entry. */
5904 static ssd_chain_struct
*
5905 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5906 zero
, access
, space_index
, alignment
, quadrant
, section
)
5907 sd_chain_struct
*space
;
5921 ssd_chain_struct
*chain_entry
;
5923 chain_entry
= is_defined_subspace (name
);
5925 #ifdef obj_set_subsection_attributes
5926 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5933 /* Return the space chain entry for the space with the name NAME or
5934 NULL if no such space exists. */
5936 static sd_chain_struct
*
5937 is_defined_space (name
)
5940 sd_chain_struct
*chain_pointer
;
5942 for (chain_pointer
= space_dict_root
;
5944 chain_pointer
= chain_pointer
->sd_next
)
5946 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5947 return chain_pointer
;
5950 /* No mapping from segment to space was found. Return NULL. */
5954 /* Find and return the space associated with the given seg. If no mapping
5955 from the given seg to a space is found, then return NULL.
5957 Unlike subspaces, the number of spaces is not expected to grow much,
5958 so a linear exhaustive search is OK here. */
5960 static sd_chain_struct
*
5961 pa_segment_to_space (seg
)
5964 sd_chain_struct
*space_chain
;
5966 /* Walk through each space looking for the correct mapping. */
5967 for (space_chain
= space_dict_root
;
5969 space_chain
= space_chain
->sd_next
)
5971 if (space_chain
->sd_seg
== seg
)
5975 /* Mapping was not found. Return NULL. */
5979 /* Return the space chain entry for the subspace with the name NAME or
5980 NULL if no such subspace exists.
5982 Uses a linear search through all the spaces and subspaces, this may
5983 not be appropriate if we ever being placing each function in its
5986 static ssd_chain_struct
*
5987 is_defined_subspace (name
)
5990 sd_chain_struct
*space_chain
;
5991 ssd_chain_struct
*subspace_chain
;
5993 /* Walk through each space. */
5994 for (space_chain
= space_dict_root
;
5996 space_chain
= space_chain
->sd_next
)
5998 /* Walk through each subspace looking for a name which matches. */
5999 for (subspace_chain
= space_chain
->sd_subspaces
;
6001 subspace_chain
= subspace_chain
->ssd_next
)
6002 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6003 return subspace_chain
;
6006 /* Subspace wasn't found. Return NULL. */
6010 /* Find and return the subspace associated with the given seg. If no
6011 mapping from the given seg to a subspace is found, then return NULL.
6013 If we ever put each procedure/function within its own subspace
6014 (to make life easier on the compiler and linker), then this will have
6015 to become more efficient. */
6017 static ssd_chain_struct
*
6018 pa_subsegment_to_subspace (seg
, subseg
)
6022 sd_chain_struct
*space_chain
;
6023 ssd_chain_struct
*subspace_chain
;
6025 /* Walk through each space. */
6026 for (space_chain
= space_dict_root
;
6028 space_chain
= space_chain
->sd_next
)
6030 if (space_chain
->sd_seg
== seg
)
6032 /* Walk through each subspace within each space looking for
6033 the correct mapping. */
6034 for (subspace_chain
= space_chain
->sd_subspaces
;
6036 subspace_chain
= subspace_chain
->ssd_next
)
6037 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6038 return subspace_chain
;
6042 /* No mapping from subsegment to subspace found. Return NULL. */
6046 /* Given a number, try and find a space with the name number.
6048 Return a pointer to a space dictionary chain entry for the space
6049 that was found or NULL on failure. */
6051 static sd_chain_struct
*
6052 pa_find_space_by_number (number
)
6055 sd_chain_struct
*space_chain
;
6057 for (space_chain
= space_dict_root
;
6059 space_chain
= space_chain
->sd_next
)
6061 if (SPACE_SPNUM (space_chain
) == number
)
6065 /* No appropriate space found. Return NULL. */
6069 /* Return the starting address for the given subspace. If the starting
6070 address is unknown then return zero. */
6073 pa_subspace_start (space
, quadrant
)
6074 sd_chain_struct
*space
;
6077 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6078 is not correct for the PA OSF1 port. */
6079 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6081 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6087 /* FIXME. Needs documentation. */
6089 pa_next_subseg (space
)
6090 sd_chain_struct
*space
;
6093 space
->sd_last_subseg
++;
6094 return space
->sd_last_subseg
;
6097 /* Helper function for pa_stringer. Used to find the end of
6104 unsigned int c
= *s
& CHAR_MASK
;
6106 /* We must have a valid space and subspace. */
6107 pa_check_current_space_and_subspace ();
6120 /* Handle a .STRING type pseudo-op. */
6123 pa_stringer (append_zero
)
6126 char *s
, num_buf
[4];
6130 /* Preprocess the string to handle PA-specific escape sequences.
6131 For example, \xDD where DD is a hexidecimal number should be
6132 changed to \OOO where OOO is an octal number. */
6134 /* Skip the opening quote. */
6135 s
= input_line_pointer
+ 1;
6137 while (is_a_char (c
= pa_stringer_aux (s
++)))
6144 /* Handle \x<num>. */
6147 unsigned int number
;
6152 /* Get pas the 'x'. */
6154 for (num_digit
= 0, number
= 0, dg
= *s
;
6156 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6157 || (dg
>= 'A' && dg
<= 'F'));
6161 number
= number
* 16 + dg
- '0';
6162 else if (dg
>= 'a' && dg
<= 'f')
6163 number
= number
* 16 + dg
- 'a' + 10;
6165 number
= number
* 16 + dg
- 'A' + 10;
6175 sprintf (num_buf
, "%02o", number
);
6178 sprintf (num_buf
, "%03o", number
);
6181 for (i
= 0; i
<= num_digit
; i
++)
6182 s_start
[i
] = num_buf
[i
];
6186 /* This might be a "\"", skip over the escaped char. */
6193 stringer (append_zero
);
6194 pa_undefine_label ();
6197 /* Handle a .VERSION pseudo-op. */
6204 pa_undefine_label ();
6207 /* Handle a .COPYRIGHT pseudo-op. */
6210 pa_copyright (unused
)
6214 pa_undefine_label ();
6217 /* Just like a normal cons, but when finished we have to undefine
6218 the latest space label. */
6225 pa_undefine_label ();
6228 /* Switch to the data space. As usual delete our label. */
6234 current_space
= is_defined_space ("$PRIVATE$");
6236 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6238 pa_undefine_label ();
6241 /* Like float_cons, but we need to undefine our label. */
6244 pa_float_cons (float_type
)
6247 float_cons (float_type
);
6248 pa_undefine_label ();
6251 /* Like s_fill, but delete our label when finished. */
6257 /* We must have a valid space and subspace. */
6258 pa_check_current_space_and_subspace ();
6261 pa_undefine_label ();
6264 /* Like lcomm, but delete our label when finished. */
6267 pa_lcomm (needs_align
)
6270 /* We must have a valid space and subspace. */
6271 pa_check_current_space_and_subspace ();
6273 s_lcomm (needs_align
);
6274 pa_undefine_label ();
6277 /* Like lsym, but delete our label when finished. */
6283 /* We must have a valid space and subspace. */
6284 pa_check_current_space_and_subspace ();
6287 pa_undefine_label ();
6290 /* Switch to the text space. Like s_text, but delete our
6291 label when finished. */
6296 current_space
= is_defined_space ("$TEXT$");
6298 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6301 pa_undefine_label ();
6304 /* On the PA relocations which involve function symbols must not be
6305 adjusted. This so that the linker can know when/how to create argument
6306 relocation stubs for indirect calls and calls to static functions.
6308 "T" field selectors create DLT relative fixups for accessing
6309 globals and statics in PIC code; each DLT relative fixup creates
6310 an entry in the DLT table. The entries contain the address of
6311 the final target (eg accessing "foo" would create a DLT entry
6312 with the address of "foo").
6314 Unfortunately, the HP linker doesn't take into account any addend
6315 when generating the DLT; so accessing $LIT$+8 puts the address of
6316 $LIT$ into the DLT rather than the address of $LIT$+8.
6318 The end result is we can't perform relocation symbol reductions for
6319 any fixup which creates entries in the DLT (eg they use "T" field
6322 Reject reductions involving symbols with external scope; such
6323 reductions make life a living hell for object file editors.
6325 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6326 the code space. The SOM BFD backend doesn't know how to pull the
6327 right bits out of an instruction. */
6330 hppa_fix_adjustable (fixp
)
6333 struct hppa_fix_struct
*hppa_fix
;
6335 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6338 /* Reject reductions of symbols in 32bit relocs. */
6339 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6342 /* Reject reductions of symbols in sym1-sym2 expressions when
6343 the fixup will occur in a CODE subspace.
6345 XXX FIXME: Long term we probably want to reject all of these;
6346 for example reducing in the debug section would lose if we ever
6347 supported using the optimizing hp linker. */
6350 && (hppa_fix
->segment
->flags
& SEC_CODE
))
6352 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6353 fixp
->fx_subsy
->sy_used_in_reloc
= 1;
6357 /* We can't adjust any relocs that use LR% and RR% field selectors.
6358 That confuses the HP linker. */
6359 if (hppa_fix
->fx_r_field
== e_lrsel
6360 || hppa_fix
->fx_r_field
== e_rrsel
6361 || hppa_fix
->fx_r_field
== e_nlrsel
)
6365 /* Reject reductions of symbols in DLT relative relocs,
6366 relocations with plabels. */
6367 if (hppa_fix
->fx_r_field
== e_tsel
6368 || hppa_fix
->fx_r_field
== e_ltsel
6369 || hppa_fix
->fx_r_field
== e_rtsel
6370 || hppa_fix
->fx_r_field
== e_psel
6371 || hppa_fix
->fx_r_field
== e_rpsel
6372 || hppa_fix
->fx_r_field
== e_lpsel
)
6375 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6378 /* Reject reductions of function symbols. */
6379 if (fixp
->fx_addsy
== 0
6380 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6386 /* Return nonzero if the fixup in FIXP will require a relocation,
6387 even it if appears that the fixup could be completely handled
6391 hppa_force_relocation (fixp
)
6394 struct hppa_fix_struct
*hppa_fixp
;
6397 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6399 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
6400 || fixp
->fx_r_type
== R_HPPA_BEGIN_BRTAB
6401 || fixp
->fx_r_type
== R_HPPA_END_BRTAB
6402 || (fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
6403 && (hppa_fixp
->segment
->flags
& SEC_CODE
) != 0))
6407 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6408 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6410 /* It is necessary to force PC-relative calls/jumps to have a relocation
6411 entry if they're going to need either a argument relocation or long
6412 call stub. FIXME. Can't we need the same for absolute calls? */
6413 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6414 && (arg_reloc_stub_needed (((obj_symbol_type
*)
6415 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6417 hppa_fixp
->fx_arg_reloc
)))
6419 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
6420 - md_pcrel_from (fixp
));
6421 /* Now check and see if we're going to need a long-branch stub. */
6422 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
6423 && (distance
> 262143 || distance
< -262144))
6426 #undef arg_reloc_stub_needed
6428 /* No need (yet) to force another relocations to be emitted. */
6432 /* Now for some ELF specific code. FIXME. */
6434 /* Mark the end of a function so that it's possible to compute
6435 the size of the function in hppa_elf_final_processing. */
6438 hppa_elf_mark_end_of_function ()
6440 /* ELF does not have EXIT relocations. All we do is create a
6441 temporary symbol marking the end of the function. */
6442 char *name
= (char *)
6443 xmalloc (strlen ("L$\001end_") +
6444 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6450 strcpy (name
, "L$\001end_");
6451 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6453 /* If we have a .exit followed by a .procend, then the
6454 symbol will have already been defined. */
6455 symbolP
= symbol_find (name
);
6458 /* The symbol has already been defined! This can
6459 happen if we have a .exit followed by a .procend.
6461 This is *not* an error. All we want to do is free
6462 the memory we just allocated for the name and continue. */
6467 /* symbol value should be the offset of the
6468 last instruction of the function */
6469 symbolP
= symbol_new (name
, now_seg
, (valueT
) (frag_now_fix () - 4),
6473 symbolP
->bsym
->flags
= BSF_LOCAL
;
6474 symbol_table_insert (symbolP
);
6478 last_call_info
->end_symbol
= symbolP
;
6480 as_bad ("Symbol '%s' could not be created.", name
);
6484 as_bad ("No memory for symbol name.");
6488 /* For ELF, this function serves one purpose: to setup the st_size
6489 field of STT_FUNC symbols. To do this, we need to scan the
6490 call_info structure list, determining st_size in by taking the
6491 difference in the address of the beginning/end marker symbols. */
6494 elf_hppa_final_processing ()
6496 struct call_info
*call_info_pointer
;
6498 for (call_info_pointer
= call_info_root
;
6500 call_info_pointer
= call_info_pointer
->ci_next
)
6502 elf_symbol_type
*esym
6503 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6504 esym
->internal_elf_sym
.st_size
=
6505 S_GET_VALUE (call_info_pointer
->end_symbol
)
6506 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;