1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989, 1996, 1997 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_alt fx_r_field
;
426 /* Format of fixup. */
429 /* Argument relocation bits. */
432 /* The segment this fixup appears in. */
436 /* Structure to hold information about predefined registers. */
444 /* This structure defines the mapping from a FP condition string
445 to a condition number which can be recorded in an instruction. */
452 /* This structure defines a mapping from a field selector
453 string to a field selector type. */
454 struct selector_entry
460 /* Prototypes for functions local to tc-hppa.c. */
462 static void pa_check_current_space_and_subspace
PARAMS ((void));
463 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
464 static void pa_cons
PARAMS ((int));
465 static void pa_data
PARAMS ((int));
466 static void pa_float_cons
PARAMS ((int));
467 static void pa_fill
PARAMS ((int));
468 static void pa_lcomm
PARAMS ((int));
469 static void pa_lsym
PARAMS ((int));
470 static void pa_stringer
PARAMS ((int));
471 static void pa_text
PARAMS ((int));
472 static void pa_version
PARAMS ((int));
473 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
474 static int get_expression
PARAMS ((char *));
475 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
476 static int evaluate_absolute
PARAMS ((struct pa_it
*));
477 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
478 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
479 static int pa_parse_nullif
PARAMS ((char **));
480 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
481 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
482 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
483 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
484 static void pa_align
PARAMS ((int));
485 static void pa_block
PARAMS ((int));
486 static void pa_brtab
PARAMS ((int));
487 static void pa_try
PARAMS ((int));
488 static void pa_call
PARAMS ((int));
489 static void pa_call_args
PARAMS ((struct call_desc
*));
490 static void pa_callinfo
PARAMS ((int));
491 static void pa_code
PARAMS ((int));
492 static void pa_comm
PARAMS ((int));
493 static void pa_copyright
PARAMS ((int));
494 static void pa_end
PARAMS ((int));
495 static void pa_enter
PARAMS ((int));
496 static void pa_entry
PARAMS ((int));
497 static void pa_equ
PARAMS ((int));
498 static void pa_exit
PARAMS ((int));
499 static void pa_export
PARAMS ((int));
500 static void pa_type_args
PARAMS ((symbolS
*, int));
501 static void pa_import
PARAMS ((int));
502 static void pa_label
PARAMS ((int));
503 static void pa_leave
PARAMS ((int));
504 static void pa_level
PARAMS ((int));
505 static void pa_origin
PARAMS ((int));
506 static void pa_proc
PARAMS ((int));
507 static void pa_procend
PARAMS ((int));
508 static void pa_space
PARAMS ((int));
509 static void pa_spnum
PARAMS ((int));
510 static void pa_subspace
PARAMS ((int));
511 static void pa_param
PARAMS ((int));
512 static void pa_undefine_label
PARAMS ((void));
513 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
514 struct pa_11_fp_reg_struct
*));
515 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
516 static label_symbol_struct
*pa_get_label
PARAMS ((void));
517 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
520 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
525 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
526 char *, int, int, int,
530 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
531 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
532 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
533 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
535 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
536 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
537 static void pa_ip
PARAMS ((char *));
538 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
539 long, expressionS
*, int,
540 bfd_reloc_code_real_type
,
541 enum hppa_reloc_field_selector_type
,
543 static int is_end_of_statement
PARAMS ((void));
544 static int reg_name_search
PARAMS ((char *));
545 static int pa_chk_field_selector
PARAMS ((char **));
546 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
547 static void 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));
555 static void hppa_elf_mark_end_of_function
PARAMS ((void));
556 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
559 /* File and gloally scoped variable declarations. */
561 /* Root and final entry in the space chain. */
562 static sd_chain_struct
*space_dict_root
;
563 static sd_chain_struct
*space_dict_last
;
565 /* The current space and subspace. */
566 static sd_chain_struct
*current_space
;
567 static ssd_chain_struct
*current_subspace
;
569 /* Root of the call_info chain. */
570 static struct call_info
*call_info_root
;
572 /* The last call_info (for functions) structure
573 seen so it can be associated with fixups and
575 static struct call_info
*last_call_info
;
577 /* The last call description (for actual calls). */
578 static struct call_desc last_call_desc
;
580 /* Jumps are always the same size -- one instruction. */
581 int md_short_jump_size
= 4;
582 int md_long_jump_size
= 4;
584 /* handle of the OPCODE hash table */
585 static struct hash_control
*op_hash
= NULL
;
587 /* This array holds the chars that always start a comment. If the
588 pre-processor is disabled, these aren't very useful. */
589 const char comment_chars
[] = ";";
591 /* Table of pseudo ops for the PA. FIXME -- how many of these
592 are now redundant with the overall GAS and the object file
594 const pseudo_typeS md_pseudo_table
[] =
596 /* align pseudo-ops on the PA specify the actual alignment requested,
597 not the log2 of the requested alignment. */
598 {"align", pa_align
, 8},
599 {"begin_brtab", pa_brtab
, 1},
600 {"begin_try", pa_try
, 1},
601 {"block", pa_block
, 1},
602 {"blockz", pa_block
, 0},
603 {"byte", pa_cons
, 1},
604 {"call", pa_call
, 0},
605 {"callinfo", pa_callinfo
, 0},
606 {"code", pa_code
, 0},
607 {"comm", pa_comm
, 0},
608 {"copyright", pa_copyright
, 0},
609 {"data", pa_data
, 0},
610 {"double", pa_float_cons
, 'd'},
612 {"end_brtab", pa_brtab
, 0},
613 {"end_try", pa_try
, 0},
614 {"enter", pa_enter
, 0},
615 {"entry", pa_entry
, 0},
617 {"exit", pa_exit
, 0},
618 {"export", pa_export
, 0},
619 {"fill", pa_fill
, 0},
620 {"float", pa_float_cons
, 'f'},
621 {"half", pa_cons
, 2},
622 {"import", pa_import
, 0},
624 {"label", pa_label
, 0},
625 {"lcomm", pa_lcomm
, 0},
626 {"leave", pa_leave
, 0},
627 {"level", pa_level
, 0},
628 {"long", pa_cons
, 4},
629 {"lsym", pa_lsym
, 0},
630 {"nsubspa", pa_subspace
, 1},
631 {"octa", pa_cons
, 16},
632 {"org", pa_origin
, 0},
633 {"origin", pa_origin
, 0},
634 {"param", pa_param
, 0},
635 {"proc", pa_proc
, 0},
636 {"procend", pa_procend
, 0},
637 {"quad", pa_cons
, 8},
639 {"short", pa_cons
, 2},
640 {"single", pa_float_cons
, 'f'},
641 {"space", pa_space
, 0},
642 {"spnum", pa_spnum
, 0},
643 {"string", pa_stringer
, 0},
644 {"stringz", pa_stringer
, 1},
645 {"subspa", pa_subspace
, 0},
646 {"text", pa_text
, 0},
647 {"version", pa_version
, 0},
648 {"word", pa_cons
, 4},
652 /* This array holds the chars that only start a comment at the beginning of
653 a line. If the line seems to have the form '# 123 filename'
654 .line and .file directives will appear in the pre-processed output.
656 Note that input_file.c hand checks for '#' at the beginning of the
657 first line of the input file. This is because the compiler outputs
658 #NO_APP at the beginning of its output.
660 Also note that C style comments will always work. */
661 const char line_comment_chars
[] = "#";
663 /* This array holds the characters which act as line separators. */
664 const char line_separator_chars
[] = "!";
666 /* Chars that can be used to separate mant from exp in floating point nums. */
667 const char EXP_CHARS
[] = "eE";
669 /* Chars that mean this number is a floating point constant.
670 As in 0f12.456 or 0d1.2345e12.
672 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
673 changed in read.c. Ideally it shouldn't hae to know abou it at
674 all, but nothing is ideal around here. */
675 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
677 static struct pa_it the_insn
;
679 /* Points to the end of an expression just parsed by get_expressoin
680 and friends. FIXME. This shouldn't be handled with a file-global
682 static char *expr_end
;
684 /* Nonzero if a .callinfo appeared within the current procedure. */
685 static int callinfo_found
;
687 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
688 static int within_entry_exit
;
690 /* Nonzero if the assembler is currently within a procedure definition. */
691 static int within_procedure
;
693 /* Handle on strucutre which keep track of the last symbol
694 seen in each subspace. */
695 static label_symbol_struct
*label_symbols_rootp
= NULL
;
697 /* Holds the last field selector. */
698 static int hppa_field_selector
;
700 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
701 static symbolS
*dummy_symbol
;
703 /* Nonzero if errors are to be printed. */
704 static int print_errors
= 1;
706 /* List of registers that are pre-defined:
708 Each general register has one predefined name of the form
709 %r<REGNUM> which has the value <REGNUM>.
711 Space and control registers are handled in a similar manner,
712 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
714 Likewise for the floating point registers, but of the form
715 %fr<REGNUM>. Floating point registers have additional predefined
716 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
717 again have the value <REGNUM>.
719 Many registers also have synonyms:
721 %r26 - %r23 have %arg0 - %arg3 as synonyms
722 %r28 - %r29 have %ret0 - %ret1 as synonyms
723 %r30 has %sp as a synonym
724 %r27 has %dp as a synonym
725 %r2 has %rp as a synonym
727 Almost every control register has a synonym; they are not listed
730 The table is sorted. Suitable for searching by a binary search. */
732 static const struct pd_reg pre_defined_registers
[] =
932 /* This table is sorted by order of the length of the string. This is
933 so we check for <> before we check for <. If we had a <> and checked
934 for < first, we would get a false match. */
935 static const struct fp_cond_map fp_cond_map
[] =
971 static const struct selector_entry selector_table
[] =
993 /* default space and subspace dictionaries */
995 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
996 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
998 /* pre-defined subsegments (subspaces) for the HPPA. */
999 #define SUBSEG_CODE 0
1000 #define SUBSEG_LIT 1
1001 #define SUBSEG_MILLI 2
1002 #define SUBSEG_DATA 0
1003 #define SUBSEG_BSS 2
1004 #define SUBSEG_UNWIND 3
1005 #define SUBSEG_GDB_STRINGS 0
1006 #define SUBSEG_GDB_SYMBOLS 1
1008 static struct default_subspace_dict pa_def_subspaces
[] =
1010 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1011 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1012 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1013 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI
},
1014 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1016 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND
},
1018 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1021 static struct default_space_dict pa_def_spaces
[] =
1023 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1024 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1025 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1028 /* Misc local definitions used by the assembler. */
1030 /* Return nonzero if the string pointed to by S potentially represents
1031 a right or left half of a FP register */
1032 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1033 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1035 /* These macros are used to maintain spaces/subspaces. */
1036 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1037 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1038 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1039 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1041 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1042 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1044 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1045 main loop after insertion. */
1047 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1049 ((OPCODE) |= (FIELD) << (START)); \
1053 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1054 IGNORE is used to suppress the error message. */
1056 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1058 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1061 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1067 #define is_DP_relative(exp) \
1068 ((exp).X_op == O_subtract \
1069 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1071 #define is_PC_relative(exp) \
1072 ((exp).X_op == O_subtract \
1073 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1075 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1076 always be able to reduce the expression to a constant, so we don't
1077 need real complex handling yet. */
1078 #define is_complex(exp) \
1079 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1081 /* Actual functions to implement the PA specific code for the assembler. */
1083 /* Called before writing the object file. Make sure entry/exit and
1084 proc/procend pairs match. */
1089 if (within_entry_exit
)
1090 as_fatal ("Missing .exit\n");
1092 if (within_procedure
)
1093 as_fatal ("Missing .procend\n");
1096 /* Check to make sure we have a valid space and subspace. */
1099 pa_check_current_space_and_subspace ()
1101 if (current_space
== NULL
)
1102 as_fatal ("Not in a space.\n");
1104 if (current_subspace
== NULL
)
1105 as_fatal ("Not in a subspace.\n");
1108 /* Returns a pointer to the label_symbol_struct for the current space.
1109 or NULL if no label_symbol_struct exists for the current space. */
1111 static label_symbol_struct
*
1114 label_symbol_struct
*label_chain
;
1115 sd_chain_struct
*space_chain
= current_space
;
1117 for (label_chain
= label_symbols_rootp
;
1119 label_chain
= label_chain
->lss_next
)
1120 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1126 /* Defines a label for the current space. If one is already defined,
1127 this function will replace it with the new label. */
1130 pa_define_label (symbol
)
1133 label_symbol_struct
*label_chain
= pa_get_label ();
1134 sd_chain_struct
*space_chain
= current_space
;
1137 label_chain
->lss_label
= symbol
;
1140 /* Create a new label entry and add it to the head of the chain. */
1142 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1143 label_chain
->lss_label
= symbol
;
1144 label_chain
->lss_space
= space_chain
;
1145 label_chain
->lss_next
= NULL
;
1147 if (label_symbols_rootp
)
1148 label_chain
->lss_next
= label_symbols_rootp
;
1150 label_symbols_rootp
= label_chain
;
1154 /* Removes a label definition for the current space.
1155 If there is no label_symbol_struct entry, then no action is taken. */
1158 pa_undefine_label ()
1160 label_symbol_struct
*label_chain
;
1161 label_symbol_struct
*prev_label_chain
= NULL
;
1162 sd_chain_struct
*space_chain
= current_space
;
1164 for (label_chain
= label_symbols_rootp
;
1166 label_chain
= label_chain
->lss_next
)
1168 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1170 /* Remove the label from the chain and free its memory. */
1171 if (prev_label_chain
)
1172 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1174 label_symbols_rootp
= label_chain
->lss_next
;
1179 prev_label_chain
= label_chain
;
1184 /* An HPPA-specific version of fix_new. This is required because the HPPA
1185 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1186 results in the creation of an instance of an hppa_fix_struct. An
1187 hppa_fix_struct stores the extra information along with a pointer to the
1188 original fixS. This is attached to the original fixup via the
1189 tc_fix_data field. */
1192 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1193 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1197 symbolS
*add_symbol
;
1201 bfd_reloc_code_real_type r_type
;
1202 enum hppa_reloc_field_selector_type_alt r_field
;
1209 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1210 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1213 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1215 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1216 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1217 hppa_fix
->fx_r_type
= r_type
;
1218 hppa_fix
->fx_r_field
= r_field
;
1219 hppa_fix
->fx_r_format
= r_format
;
1220 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1221 hppa_fix
->segment
= now_seg
;
1223 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1224 new_fix
->fx_offset
= *unwind_bits
;
1227 /* foo-$global$ is used to access non-automatic storage. $global$
1228 is really just a marker and has served its purpose, so eliminate
1229 it now so as not to confuse write.c. */
1230 if (new_fix
->fx_subsy
1231 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1232 new_fix
->fx_subsy
= NULL
;
1235 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1236 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1239 parse_cons_expression_hppa (exp
)
1242 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1246 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1247 hppa_field_selector is set by the parse_cons_expression_hppa. */
1250 cons_fix_new_hppa (frag
, where
, size
, exp
)
1256 unsigned int rel_type
;
1258 /* Get a base relocation type. */
1259 if (is_DP_relative (*exp
))
1260 rel_type
= R_HPPA_GOTOFF
;
1261 else if (is_complex (*exp
))
1262 rel_type
= R_HPPA_COMPLEX
;
1266 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1267 as_warn ("Invalid field selector. Assuming F%%.");
1269 fix_new_hppa (frag
, where
, size
,
1270 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1271 hppa_field_selector
, 32, 0, NULL
);
1273 /* Reset field selector to its default state. */
1274 hppa_field_selector
= 0;
1277 /* This function is called once, at assembler startup time. It should
1278 set up all the tables, etc. that the MD part of the assembler will need. */
1283 const char *retval
= NULL
;
1287 last_call_info
= NULL
;
1288 call_info_root
= NULL
;
1290 /* Set the default machine type. */
1291 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1292 as_warn ("could not set architecture and machine");
1294 /* Folding of text and data segments fails miserably on the PA.
1295 Warn user and disable "-R" option. */
1296 if (flag_readonly_data_in_text
)
1298 as_warn ("-R option not supported on this target.");
1299 flag_readonly_data_in_text
= 0;
1304 op_hash
= hash_new ();
1306 while (i
< NUMOPCODES
)
1308 const char *name
= pa_opcodes
[i
].name
;
1309 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1310 if (retval
!= NULL
&& *retval
!= '\0')
1312 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1317 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1318 != pa_opcodes
[i
].match
)
1320 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1321 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1326 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1330 as_fatal ("Broken assembler. No assembly attempted.");
1332 /* SOM will change text_section. To make sure we never put
1333 anything into the old one switch to the new one now. */
1334 subseg_set (text_section
, 0);
1336 dummy_symbol
= symbol_find_or_make ("L$dummy");
1337 S_SET_SEGMENT (dummy_symbol
, text_section
);
1340 /* Assemble a single instruction storing it into a frag. */
1347 /* The had better be something to assemble. */
1350 /* If we are within a procedure definition, make sure we've
1351 defined a label for the procedure; handle case where the
1352 label was defined after the .PROC directive.
1354 Note there's not need to diddle with the segment or fragment
1355 for the label symbol in this case. We have already switched
1356 into the new $CODE$ subspace at this point. */
1357 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1359 label_symbol_struct
*label_symbol
= pa_get_label ();
1363 if (label_symbol
->lss_label
)
1365 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1366 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
1368 /* Also handle allocation of a fixup to hold the unwind
1369 information when the label appears after the proc/procend. */
1370 if (within_entry_exit
)
1372 char *where
= frag_more (0);
1374 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1375 NULL
, (offsetT
) 0, NULL
,
1376 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1377 (int *)&last_call_info
->ci_unwind
.descriptor
);
1382 as_bad ("Missing function name for .PROC (corrupted label chain)");
1385 as_bad ("Missing function name for .PROC");
1388 /* Assemble the instruction. Results are saved into "the_insn". */
1391 /* Get somewhere to put the assembled instrution. */
1394 /* Output the opcode. */
1395 md_number_to_chars (to
, the_insn
.opcode
, 4);
1397 /* If necessary output more stuff. */
1398 if (the_insn
.reloc
!= R_HPPA_NONE
)
1399 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1400 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1401 the_insn
.reloc
, the_insn
.field_selector
,
1402 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1405 /* Do the real work for assembling a single instruction. Store results
1406 into the global "the_insn" variable. */
1412 char *error_message
= "";
1413 char *s
, c
, *argstart
, *name
, *save_s
;
1417 int cmpltr
, nullif
, flag
, cond
, num
;
1418 unsigned long opcode
;
1419 struct pa_opcode
*insn
;
1421 /* We must have a valid space and subspace. */
1422 pa_check_current_space_and_subspace ();
1424 /* Skip to something interesting. */
1425 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1444 as_fatal ("Unknown opcode: `%s'", str
);
1449 /* Convert everything into lower case. */
1452 if (isupper (*save_s
))
1453 *save_s
= tolower (*save_s
);
1457 /* Look up the opcode in the has table. */
1458 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1460 as_bad ("Unknown opcode: `%s'", str
);
1469 /* Mark the location where arguments for the instruction start, then
1470 start processing them. */
1474 /* Do some initialization. */
1475 opcode
= insn
->match
;
1476 bzero (&the_insn
, sizeof (the_insn
));
1478 the_insn
.reloc
= R_HPPA_NONE
;
1480 /* If this instruction is specific to a particular architecture,
1481 then set a new architecture. */
1482 if (bfd_get_mach (stdoutput
) < insn
->arch
)
1484 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1485 as_warn ("could not update architecture and machine");
1488 /* Build the opcode, checking as we go to make
1489 sure that the operands match. */
1490 for (args
= insn
->args
;; ++args
)
1495 /* End of arguments. */
1511 /* These must match exactly. */
1520 /* Handle a 5 bit register or control register field at 10. */
1523 num
= pa_parse_number (&s
, 0);
1524 CHECK_FIELD (num
, 31, 0, 0);
1525 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1527 /* Handle a 5 bit register field at 15. */
1529 num
= pa_parse_number (&s
, 0);
1530 CHECK_FIELD (num
, 31, 0, 0);
1531 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1533 /* Handle a 5 bit register field at 31. */
1536 num
= pa_parse_number (&s
, 0);
1537 CHECK_FIELD (num
, 31, 0, 0);
1538 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1540 /* Handle a 5 bit field length at 31. */
1542 num
= pa_get_absolute_expression (&the_insn
, &s
);
1544 CHECK_FIELD (num
, 32, 1, 0);
1545 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1547 /* Handle a 5 bit immediate at 15. */
1549 num
= pa_get_absolute_expression (&the_insn
, &s
);
1551 CHECK_FIELD (num
, 15, -16, 0);
1552 low_sign_unext (num
, 5, &num
);
1553 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1555 /* Handle a 5 bit immediate at 31. */
1557 num
= pa_get_absolute_expression (&the_insn
, &s
);
1559 CHECK_FIELD (num
, 15, -16, 0)
1560 low_sign_unext (num
, 5, &num
);
1561 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1563 /* Handle an unsigned 5 bit immediate at 31. */
1565 num
= pa_get_absolute_expression (&the_insn
, &s
);
1567 CHECK_FIELD (num
, 31, 0, 0);
1568 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1570 /* Handle an unsigned 5 bit immediate at 15. */
1572 num
= pa_get_absolute_expression (&the_insn
, &s
);
1574 CHECK_FIELD (num
, 31, 0, 0);
1575 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1577 /* Handle a 2 bit space identifier at 17. */
1579 num
= pa_parse_number (&s
, 0);
1580 CHECK_FIELD (num
, 3, 0, 1);
1581 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1583 /* Handle a 3 bit space identifier at 18. */
1585 num
= pa_parse_number (&s
, 0);
1586 CHECK_FIELD (num
, 7, 0, 1);
1587 dis_assemble_3 (num
, &num
);
1588 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1590 /* Handle a completer for an indexing load or store. */
1596 while (*s
== ',' && i
< 2)
1599 if (strncasecmp (s
, "sm", 2) == 0)
1606 else if (strncasecmp (s
, "m", 1) == 0)
1608 else if (strncasecmp (s
, "s", 1) == 0)
1611 as_bad ("Invalid Indexed Load Completer.");
1616 as_bad ("Invalid Indexed Load Completer Syntax.");
1618 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1621 /* Handle a short load/store completer. */
1629 if (strncasecmp (s
, "ma", 2) == 0)
1634 else if (strncasecmp (s
, "mb", 2) == 0)
1640 as_bad ("Invalid Short Load/Store Completer.");
1644 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1647 /* Handle a stbys completer. */
1653 while (*s
== ',' && i
< 2)
1656 if (strncasecmp (s
, "m", 1) == 0)
1658 else if (strncasecmp (s
, "b", 1) == 0)
1660 else if (strncasecmp (s
, "e", 1) == 0)
1663 as_bad ("Invalid Store Bytes Short Completer");
1668 as_bad ("Invalid Store Bytes Short Completer");
1670 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1673 /* Handle a non-negated compare/stubtract condition. */
1675 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1678 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1681 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1683 /* Handle a negated or non-negated compare/subtract condition. */
1686 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1690 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1693 as_bad ("Invalid Compare/Subtract Condition.");
1698 /* Negated condition requires an opcode change. */
1702 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1704 /* Handle non-negated add condition. */
1706 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1709 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1712 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1714 /* Handle a negated or non-negated add condition. */
1717 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1721 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1724 as_bad ("Invalid Compare/Subtract Condition");
1729 /* Negated condition requires an opcode change. */
1733 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1735 /* Handle a compare/subtract condition. */
1742 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1747 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1750 as_bad ("Invalid Compare/Subtract Condition");
1754 opcode
|= cmpltr
<< 13;
1755 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1757 /* Handle a non-negated add condition. */
1766 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1770 if (strcmp (name
, "=") == 0)
1772 else if (strcmp (name
, "<") == 0)
1774 else if (strcmp (name
, "<=") == 0)
1776 else if (strcasecmp (name
, "nuv") == 0)
1778 else if (strcasecmp (name
, "znv") == 0)
1780 else if (strcasecmp (name
, "sv") == 0)
1782 else if (strcasecmp (name
, "od") == 0)
1784 else if (strcasecmp (name
, "n") == 0)
1786 else if (strcasecmp (name
, "tr") == 0)
1791 else if (strcmp (name
, "<>") == 0)
1796 else if (strcmp (name
, ">=") == 0)
1801 else if (strcmp (name
, ">") == 0)
1806 else if (strcasecmp (name
, "uv") == 0)
1811 else if (strcasecmp (name
, "vnz") == 0)
1816 else if (strcasecmp (name
, "nsv") == 0)
1821 else if (strcasecmp (name
, "ev") == 0)
1827 as_bad ("Invalid Add Condition: %s", name
);
1830 nullif
= pa_parse_nullif (&s
);
1831 opcode
|= nullif
<< 1;
1832 opcode
|= cmpltr
<< 13;
1833 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1835 /* HANDLE a logical instruction condition. */
1843 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1847 if (strcmp (name
, "=") == 0)
1849 else if (strcmp (name
, "<") == 0)
1851 else if (strcmp (name
, "<=") == 0)
1853 else if (strcasecmp (name
, "od") == 0)
1855 else if (strcasecmp (name
, "tr") == 0)
1860 else if (strcmp (name
, "<>") == 0)
1865 else if (strcmp (name
, ">=") == 0)
1870 else if (strcmp (name
, ">") == 0)
1875 else if (strcasecmp (name
, "ev") == 0)
1881 as_bad ("Invalid Logical Instruction Condition.");
1884 opcode
|= cmpltr
<< 13;
1885 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1887 /* Handle a unit instruction condition. */
1894 if (strncasecmp (s
, "sbz", 3) == 0)
1899 else if (strncasecmp (s
, "shz", 3) == 0)
1904 else if (strncasecmp (s
, "sdc", 3) == 0)
1909 else if (strncasecmp (s
, "sbc", 3) == 0)
1914 else if (strncasecmp (s
, "shc", 3) == 0)
1919 else if (strncasecmp (s
, "tr", 2) == 0)
1925 else if (strncasecmp (s
, "nbz", 3) == 0)
1931 else if (strncasecmp (s
, "nhz", 3) == 0)
1937 else if (strncasecmp (s
, "ndc", 3) == 0)
1943 else if (strncasecmp (s
, "nbc", 3) == 0)
1949 else if (strncasecmp (s
, "nhc", 3) == 0)
1956 as_bad ("Invalid Logical Instruction Condition.");
1958 opcode
|= cmpltr
<< 13;
1959 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1961 /* Handle a shift/extract/deposit condition. */
1969 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1973 if (strcmp (name
, "=") == 0)
1975 else if (strcmp (name
, "<") == 0)
1977 else if (strcasecmp (name
, "od") == 0)
1979 else if (strcasecmp (name
, "tr") == 0)
1981 else if (strcmp (name
, "<>") == 0)
1983 else if (strcmp (name
, ">=") == 0)
1985 else if (strcasecmp (name
, "ev") == 0)
1987 /* Handle movb,n. Put things back the way they were.
1988 This includes moving s back to where it started. */
1989 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
1996 as_bad ("Invalid Shift/Extract/Deposit Condition.");
1999 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2001 /* Handle bvb and bb conditions. */
2007 if (strncmp (s
, "<", 1) == 0)
2012 else if (strncmp (s
, ">=", 2) == 0)
2018 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2020 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2022 /* Handle a system control completer. */
2024 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2032 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2034 /* Handle a nullification completer for branch instructions. */
2036 nullif
= pa_parse_nullif (&s
);
2037 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2039 /* Handle a nullification completer for copr and spop insns. */
2041 nullif
= pa_parse_nullif (&s
);
2042 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2044 /* Handle a 11 bit immediate at 31. */
2046 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2049 if (the_insn
.exp
.X_op
== O_constant
)
2051 num
= evaluate_absolute (&the_insn
);
2052 CHECK_FIELD (num
, 1023, -1024, 0);
2053 low_sign_unext (num
, 11, &num
);
2054 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2058 if (is_DP_relative (the_insn
.exp
))
2059 the_insn
.reloc
= R_HPPA_GOTOFF
;
2060 else if (is_PC_relative (the_insn
.exp
))
2061 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2063 the_insn
.reloc
= R_HPPA
;
2064 the_insn
.format
= 11;
2068 /* Handle a 14 bit immediate at 31. */
2070 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2073 if (the_insn
.exp
.X_op
== O_constant
)
2075 num
= evaluate_absolute (&the_insn
);
2076 CHECK_FIELD (num
, 8191, -8192, 0);
2077 low_sign_unext (num
, 14, &num
);
2078 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2082 if (is_DP_relative (the_insn
.exp
))
2083 the_insn
.reloc
= R_HPPA_GOTOFF
;
2084 else if (is_PC_relative (the_insn
.exp
))
2085 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2087 the_insn
.reloc
= R_HPPA
;
2088 the_insn
.format
= 14;
2092 /* Handle a 21 bit immediate at 31. */
2094 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2097 if (the_insn
.exp
.X_op
== O_constant
)
2099 num
= evaluate_absolute (&the_insn
);
2100 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2101 dis_assemble_21 (num
, &num
);
2102 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2106 if (is_DP_relative (the_insn
.exp
))
2107 the_insn
.reloc
= R_HPPA_GOTOFF
;
2108 else if (is_PC_relative (the_insn
.exp
))
2109 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2111 the_insn
.reloc
= R_HPPA
;
2112 the_insn
.format
= 21;
2116 /* Handle a 12 bit branch displacement. */
2118 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2122 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2124 unsigned int w1
, w
, result
;
2126 num
= evaluate_absolute (&the_insn
);
2129 as_bad ("Branch to unaligned address");
2132 CHECK_FIELD (num
, 8199, -8184, 0);
2133 sign_unext ((num
- 8) >> 2, 12, &result
);
2134 dis_assemble_12 (result
, &w1
, &w
);
2135 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2139 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2140 the_insn
.format
= 12;
2141 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2142 bzero (&last_call_desc
, sizeof (struct call_desc
));
2147 /* Handle a 17 bit branch displacement. */
2149 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2153 if (!the_insn
.exp
.X_add_symbol
2154 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2157 unsigned int w2
, w1
, w
, result
;
2159 num
= evaluate_absolute (&the_insn
);
2162 as_bad ("Branch to unaligned address");
2165 CHECK_FIELD (num
, 262143, -262144, 0);
2167 if (the_insn
.exp
.X_add_symbol
)
2170 sign_unext (num
>> 2, 17, &result
);
2171 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2172 INSERT_FIELD_AND_CONTINUE (opcode
,
2173 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2177 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2178 the_insn
.format
= 17;
2179 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2180 bzero (&last_call_desc
, sizeof (struct call_desc
));
2184 /* Handle an absolute 17 bit branch target. */
2186 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2190 if (!the_insn
.exp
.X_add_symbol
2191 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2194 unsigned int w2
, w1
, w
, result
;
2196 num
= evaluate_absolute (&the_insn
);
2199 as_bad ("Branch to unaligned address");
2202 CHECK_FIELD (num
, 262143, -262144, 0);
2204 if (the_insn
.exp
.X_add_symbol
)
2207 sign_unext (num
>> 2, 17, &result
);
2208 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2209 INSERT_FIELD_AND_CONTINUE (opcode
,
2210 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2214 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2215 the_insn
.format
= 17;
2216 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2217 bzero (&last_call_desc
, sizeof (struct call_desc
));
2221 /* Handle a 5 bit shift count at 26. */
2223 num
= pa_get_absolute_expression (&the_insn
, &s
);
2225 CHECK_FIELD (num
, 31, 0, 0);
2226 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2228 /* Handle a 5 bit bit position at 26. */
2230 num
= pa_get_absolute_expression (&the_insn
, &s
);
2232 CHECK_FIELD (num
, 31, 0, 0);
2233 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2235 /* Handle a 5 bit immediate at 10. */
2237 num
= pa_get_absolute_expression (&the_insn
, &s
);
2239 CHECK_FIELD (num
, 31, 0, 0);
2240 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2242 /* Handle a 13 bit immediate at 18. */
2244 num
= pa_get_absolute_expression (&the_insn
, &s
);
2246 CHECK_FIELD (num
, 8191, 0, 0);
2247 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2249 /* Handle a 26 bit immediate at 31. */
2251 num
= pa_get_absolute_expression (&the_insn
, &s
);
2253 CHECK_FIELD (num
, 671108864, 0, 0);
2254 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2256 /* Handle a 3 bit SFU identifier at 25. */
2259 as_bad ("Invalid SFU identifier");
2260 num
= pa_get_absolute_expression (&the_insn
, &s
);
2262 CHECK_FIELD (num
, 7, 0, 0);
2263 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2265 /* Handle a 20 bit SOP field for spop0. */
2267 num
= pa_get_absolute_expression (&the_insn
, &s
);
2269 CHECK_FIELD (num
, 1048575, 0, 0);
2270 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2271 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2273 /* Handle a 15bit SOP field for spop1. */
2275 num
= pa_get_absolute_expression (&the_insn
, &s
);
2277 CHECK_FIELD (num
, 32767, 0, 0);
2278 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2280 /* Handle a 10bit SOP field for spop3. */
2282 num
= pa_get_absolute_expression (&the_insn
, &s
);
2284 CHECK_FIELD (num
, 1023, 0, 0);
2285 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2286 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2288 /* Handle a 15 bit SOP field for spop2. */
2290 num
= pa_get_absolute_expression (&the_insn
, &s
);
2292 CHECK_FIELD (num
, 32767, 0, 0);
2293 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
2294 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2296 /* Handle a 3-bit co-processor ID field. */
2299 as_bad ("Invalid COPR identifier");
2300 num
= pa_get_absolute_expression (&the_insn
, &s
);
2302 CHECK_FIELD (num
, 7, 0, 0);
2303 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2305 /* Handle a 22bit SOP field for copr. */
2307 num
= pa_get_absolute_expression (&the_insn
, &s
);
2309 CHECK_FIELD (num
, 4194303, 0, 0);
2310 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
2311 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2313 /* Handle a source FP operand format completer. */
2315 flag
= pa_parse_fp_format (&s
);
2316 the_insn
.fpof1
= flag
;
2317 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2319 /* Handle a destination FP operand format completer. */
2321 /* pa_parse_format needs the ',' prefix. */
2323 flag
= pa_parse_fp_format (&s
);
2324 the_insn
.fpof2
= flag
;
2325 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2327 /* Handle FP compare conditions. */
2329 cond
= pa_parse_fp_cmp_cond (&s
);
2330 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2332 /* Handle L/R register halves like 't'. */
2335 struct pa_11_fp_reg_struct result
;
2337 pa_parse_number (&s
, &result
);
2338 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2339 opcode
|= result
.number_part
;
2341 /* 0x30 opcodes are FP arithmetic operation opcodes
2342 and need to be turned into 0x38 opcodes. This
2343 is not necessary for loads/stores. */
2344 if (need_pa11_opcode (&the_insn
, &result
)
2345 && ((opcode
& 0xfc000000) == 0x30000000))
2348 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2351 /* Handle L/R register halves like 'b'. */
2354 struct pa_11_fp_reg_struct result
;
2356 pa_parse_number (&s
, &result
);
2357 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2358 opcode
|= result
.number_part
<< 21;
2359 if (need_pa11_opcode (&the_insn
, &result
))
2361 opcode
|= (result
.l_r_select
& 1) << 7;
2367 /* Handle L/R register halves like 'x'. */
2370 struct pa_11_fp_reg_struct result
;
2372 pa_parse_number (&s
, &result
);
2373 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2374 opcode
|= (result
.number_part
& 0x1f) << 16;
2375 if (need_pa11_opcode (&the_insn
, &result
))
2377 opcode
|= (result
.l_r_select
& 1) << 12;
2383 /* Handle a 5 bit register field at 10. */
2386 struct pa_11_fp_reg_struct result
;
2388 pa_parse_number (&s
, &result
);
2389 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2390 if (the_insn
.fpof1
== SGL
)
2392 if (result
.number_part
< 16)
2394 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2398 result
.number_part
&= 0xF;
2399 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2401 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2404 /* Handle a 5 bit register field at 15. */
2407 struct pa_11_fp_reg_struct result
;
2409 pa_parse_number (&s
, &result
);
2410 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2411 if (the_insn
.fpof1
== SGL
)
2413 if (result
.number_part
< 16)
2415 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2418 result
.number_part
&= 0xF;
2419 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2421 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2424 /* Handle a 5 bit register field at 31. */
2427 struct pa_11_fp_reg_struct result
;
2429 pa_parse_number (&s
, &result
);
2430 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2431 if (the_insn
.fpof1
== SGL
)
2433 if (result
.number_part
< 16)
2435 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2438 result
.number_part
&= 0xF;
2439 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2441 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2444 /* Handle a 5 bit register field at 20. */
2447 struct pa_11_fp_reg_struct result
;
2449 pa_parse_number (&s
, &result
);
2450 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2451 if (the_insn
.fpof1
== SGL
)
2453 if (result
.number_part
< 16)
2455 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2458 result
.number_part
&= 0xF;
2459 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2461 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2464 /* Handle a 5 bit register field at 25. */
2467 struct pa_11_fp_reg_struct result
;
2469 pa_parse_number (&s
, &result
);
2470 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2471 if (the_insn
.fpof1
== SGL
)
2473 if (result
.number_part
< 16)
2475 as_bad ("Invalid register for single precision fmpyadd or fmpysub");
2478 result
.number_part
&= 0xF;
2479 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2481 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2484 /* Handle a floating point operand format at 26.
2485 Only allows single and double precision. */
2487 flag
= pa_parse_fp_format (&s
);
2493 the_insn
.fpof1
= flag
;
2499 as_bad ("Invalid Floating Point Operand Format.");
2509 /* Check if the args matched. */
2512 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2513 && !strcmp (insn
->name
, insn
[1].name
))
2521 as_bad ("Invalid operands %s", error_message
);
2528 the_insn
.opcode
= opcode
;
2531 /* Turn a string in input_line_pointer into a floating point constant of type
2532 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2533 emitted is stored in *sizeP . An error message or NULL is returned. */
2535 #define MAX_LITTLENUMS 6
2538 md_atof (type
, litP
, sizeP
)
2544 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2545 LITTLENUM_TYPE
*wordP
;
2577 return "Bad call to MD_ATOF()";
2579 t
= atof_ieee (input_line_pointer
, type
, words
);
2581 input_line_pointer
= t
;
2582 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2583 for (wordP
= words
; prec
--;)
2585 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2586 litP
+= sizeof (LITTLENUM_TYPE
);
2591 /* Write out big-endian. */
2594 md_number_to_chars (buf
, val
, n
)
2599 number_to_chars_bigendian (buf
, val
, n
);
2602 /* Translate internal representation of relocation info to BFD target
2606 tc_gen_reloc (section
, fixp
)
2611 struct hppa_fix_struct
*hppa_fixp
;
2612 bfd_reloc_code_real_type code
;
2613 static arelent
*no_relocs
= NULL
;
2615 bfd_reloc_code_real_type
**codes
;
2619 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
2620 if (fixp
->fx_addsy
== 0)
2622 assert (hppa_fixp
!= 0);
2623 assert (section
!= 0);
2625 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2627 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2628 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
2630 hppa_fixp
->fx_r_format
,
2631 hppa_fixp
->fx_r_field
,
2632 fixp
->fx_subsy
!= NULL
,
2633 fixp
->fx_addsy
->bsym
);
2638 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2641 relocs
= (arelent
**) xmalloc (sizeof (arelent
*) * n_relocs
+ 1);
2642 reloc
= (arelent
*) xmalloc (sizeof (arelent
) * n_relocs
);
2643 for (i
= 0; i
< n_relocs
; i
++)
2644 relocs
[i
] = &reloc
[i
];
2646 relocs
[n_relocs
] = NULL
;
2649 switch (fixp
->fx_r_type
)
2652 assert (n_relocs
== 1);
2656 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2657 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2658 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2659 reloc
->addend
= 0; /* default */
2661 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2663 /* Now, do any processing that is dependent on the relocation type. */
2666 case R_PARISC_DLTREL21L
:
2667 case R_PARISC_DLTREL14R
:
2668 case R_PARISC_DLTREL14F
:
2669 case R_PARISC_PLABEL32
:
2670 case R_PARISC_PLABEL21L
:
2671 case R_PARISC_PLABEL14R
:
2672 /* For plabel relocations, the addend of the
2673 relocation should be either 0 (no static link) or 2
2674 (static link required).
2676 FIXME: We always assume no static link!
2678 We also slam a zero addend into the DLT relative relocs;
2679 it doesn't make a lot of sense to use any addend since
2680 it gets you a different (eg unknown) DLT entry. */
2684 case R_PARISC_PCREL21L
:
2685 case R_PARISC_PCREL17R
:
2686 case R_PARISC_PCREL17F
:
2687 case R_PARISC_PCREL17C
:
2688 case R_PARISC_PCREL14R
:
2689 case R_PARISC_PCREL14F
:
2690 /* The constant is stored in the instruction. */
2691 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2694 reloc
->addend
= fixp
->fx_offset
;
2701 /* Walk over reach relocation returned by the BFD backend. */
2702 for (i
= 0; i
< n_relocs
; i
++)
2706 relocs
[i
]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2707 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2708 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2713 /* The only time we ever use a R_COMP2 fixup is for the difference
2714 of two symbols. With that in mind we fill in all four
2715 relocs now and break out of the loop. */
2717 relocs
[0]->sym_ptr_ptr
= &bfd_abs_symbol
;
2718 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
2719 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2720 relocs
[0]->addend
= 0;
2721 relocs
[1]->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2722 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
2723 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2724 relocs
[1]->addend
= 0;
2725 relocs
[2]->sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2726 relocs
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[2]);
2727 relocs
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2728 relocs
[2]->addend
= 0;
2729 relocs
[3]->sym_ptr_ptr
= &bfd_abs_symbol
;
2730 relocs
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[3]);
2731 relocs
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2732 relocs
[3]->addend
= 0;
2733 relocs
[4]->sym_ptr_ptr
= &bfd_abs_symbol
;
2734 relocs
[4]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[4]);
2735 relocs
[4]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2736 relocs
[4]->addend
= 0;
2740 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2746 /* For plabel relocations, the addend of the
2747 relocation should be either 0 (no static link) or 2
2748 (static link required).
2750 FIXME: We always assume no static link!
2752 We also slam a zero addend into the DLT relative relocs;
2753 it doesn't make a lot of sense to use any addend since
2754 it gets you a different (eg unknown) DLT entry. */
2755 relocs
[i
]->addend
= 0;
2770 /* There is no symbol or addend associated with these fixups. */
2771 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2772 relocs
[i
]->addend
= 0;
2778 /* There is no symbol associated with these fixups. */
2779 relocs
[i
]->sym_ptr_ptr
= &dummy_symbol
->bsym
;
2780 relocs
[i
]->addend
= fixp
->fx_offset
;
2784 relocs
[i
]->addend
= fixp
->fx_offset
;
2794 /* Process any machine dependent frag types. */
2797 md_convert_frag (abfd
, sec
, fragP
)
2799 register asection
*sec
;
2800 register fragS
*fragP
;
2802 unsigned int address
;
2804 if (fragP
->fr_type
== rs_machine_dependent
)
2806 switch ((int) fragP
->fr_subtype
)
2809 fragP
->fr_type
= rs_fill
;
2810 know (fragP
->fr_var
== 1);
2811 know (fragP
->fr_next
);
2812 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2813 if (address
% fragP
->fr_offset
)
2816 fragP
->fr_next
->fr_address
2821 fragP
->fr_offset
= 0;
2827 /* Round up a section size to the appropriate boundary. */
2830 md_section_align (segment
, size
)
2834 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2835 int align2
= (1 << align
) - 1;
2837 return (size
+ align2
) & ~align2
;
2840 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2842 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2844 addressT from_addr
, to_addr
;
2848 fprintf (stderr
, "pa_create_short_jmp\n");
2852 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2854 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2856 addressT from_addr
, to_addr
;
2860 fprintf (stderr
, "pa_create_long_jump\n");
2864 /* Return the approximate size of a frag before relaxation has occurred. */
2866 md_estimate_size_before_relax (fragP
, segment
)
2867 register fragS
*fragP
;
2874 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2880 CONST
char *md_shortopts
= "";
2881 struct option md_longopts
[] = {
2882 {NULL
, no_argument
, NULL
, 0}
2884 size_t md_longopts_size
= sizeof(md_longopts
);
2887 md_parse_option (c
, arg
)
2895 md_show_usage (stream
)
2900 /* We have no need to default values of symbols. */
2903 md_undefined_symbol (name
)
2909 /* Apply a fixup to an instruction. */
2912 md_apply_fix (fixP
, valp
)
2916 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2917 struct hppa_fix_struct
*hppa_fixP
;
2918 long new_val
, result
= 0;
2919 unsigned int w1
, w2
, w
, resulti
;
2921 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
2922 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
2923 never be "applied" (they are just markers). Likewise for
2924 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
2926 if (fixP
->fx_r_type
== R_HPPA_ENTRY
2927 || fixP
->fx_r_type
== R_HPPA_EXIT
2928 || fixP
->fx_r_type
== R_HPPA_BEGIN_BRTAB
2929 || fixP
->fx_r_type
== R_HPPA_END_BRTAB
2930 || fixP
->fx_r_type
== R_HPPA_BEGIN_TRY
)
2933 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
2934 fixups are considered not adjustable, which in turn causes
2935 adjust_reloc_syms to not set fx_offset. Ugh. */
2936 if (fixP
->fx_r_type
== R_HPPA_END_TRY
)
2938 fixP
->fx_offset
= *valp
;
2943 /* There should have been an HPPA specific fixup associated
2944 with the GAS fixup. */
2947 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
2948 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
2950 /* If there is a symbol associated with this fixup, then it's something
2951 which will need a SOM relocation (except for some PC-relative relocs).
2952 In such cases we should treat the "val" or "addend" as zero since it
2953 will be added in as needed from fx_offset in tc_gen_reloc. */
2954 if ((fixP
->fx_addsy
!= NULL
2955 || fixP
->fx_r_type
== R_HPPA_NONE
)
2958 || hppa_fixP
->fx_r_field
== e_psel
2959 || hppa_fixP
->fx_r_field
== e_rpsel
2960 || hppa_fixP
->fx_r_field
== e_lpsel
2961 || hppa_fixP
->fx_r_field
== e_tsel
2962 || hppa_fixP
->fx_r_field
== e_rtsel
2963 || hppa_fixP
->fx_r_field
== e_ltsel
2966 new_val
= ((fmt
== 12 || fmt
== 17) ? 8 : 0);
2968 /* This is truely disgusting. The machine independent code blindly
2969 adds in the value of the symbol being relocated against. Damn! */
2971 && fixP
->fx_addsy
!= NULL
2972 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
2973 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
2974 0, hppa_fixP
->fx_r_field
);
2977 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2979 /* Handle pc-relative exceptions from above. */
2980 #define arg_reloc_stub_needed(CALLER, CALLEE) \
2981 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
2982 if ((fmt
== 12 || fmt
== 17)
2985 && !arg_reloc_stub_needed (((obj_symbol_type
*)
2986 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
2987 hppa_fixP
->fx_arg_reloc
)
2988 && ((int)(*valp
) > -262144 && (int)(*valp
) < 262143)
2989 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
2991 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
2993 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
2994 #undef arg_reloc_stub_needed
2998 /* Handle all opcodes with the 'j' operand type. */
3000 CHECK_FIELD (new_val
, 8191, -8192, 0);
3002 /* Mask off 14 bits to be changed. */
3003 bfd_put_32 (stdoutput
,
3004 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3006 low_sign_unext (new_val
, 14, &resulti
);
3010 /* Handle all opcodes with the 'k' operand type. */
3012 CHECK_FIELD (new_val
, 2097152, 0, 0);
3014 /* Mask off 21 bits to be changed. */
3015 bfd_put_32 (stdoutput
,
3016 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3018 dis_assemble_21 (new_val
, &resulti
);
3022 /* Handle all the opcodes with the 'i' operand type. */
3024 CHECK_FIELD (new_val
, 1023, -1023, 0);
3026 /* Mask off 11 bits to be changed. */
3027 bfd_put_32 (stdoutput
,
3028 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3030 low_sign_unext (new_val
, 11, &resulti
);
3034 /* Handle all the opcodes with the 'w' operand type. */
3036 CHECK_FIELD (new_val
, 8199, -8184, 0);
3038 /* Mask off 11 bits to be changed. */
3039 sign_unext ((new_val
- 8) >> 2, 12, &resulti
);
3040 bfd_put_32 (stdoutput
,
3041 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3044 dis_assemble_12 (resulti
, &w1
, &w
);
3045 result
= ((w1
<< 2) | w
);
3048 /* Handle some of the opcodes with the 'W' operand type. */
3050 CHECK_FIELD (new_val
, 262143, -262144, 0);
3052 /* Mask off 17 bits to be changed. */
3053 bfd_put_32 (stdoutput
,
3054 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3056 sign_unext ((new_val
- 8) >> 2, 17, &resulti
);
3057 dis_assemble_17 (resulti
, &w1
, &w2
, &w
);
3058 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3063 bfd_put_32 (stdoutput
, new_val
, buf
);
3067 as_bad ("Unknown relocation encountered in md_apply_fix.");
3071 /* Insert the relocation. */
3072 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3077 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3078 (unsigned int) fixP
, fixP
->fx_r_type
);
3083 /* Exactly what point is a PC-relative offset relative TO?
3084 On the PA, they're relative to the address of the offset. */
3087 md_pcrel_from (fixP
)
3090 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3093 /* Return nonzero if the input line pointer is at the end of
3097 is_end_of_statement ()
3099 return ((*input_line_pointer
== '\n')
3100 || (*input_line_pointer
== ';')
3101 || (*input_line_pointer
== '!'));
3104 /* Read a number from S. The number might come in one of many forms,
3105 the most common will be a hex or decimal constant, but it could be
3106 a pre-defined register (Yuk!), or an absolute symbol.
3108 Return a number or -1 for failure.
3110 When parsing PA-89 FP register numbers RESULT will be
3111 the address of a structure to return information about
3112 L/R half of FP registers, store results there as appropriate.
3114 pa_parse_number can not handle negative constants and will fail
3115 horribly if it is passed such a constant. */
3118 pa_parse_number (s
, result
)
3120 struct pa_11_fp_reg_struct
*result
;
3129 /* Skip whitespace before the number. */
3130 while (*p
== ' ' || *p
== '\t')
3133 /* Store info in RESULT if requested by caller. */
3136 result
->number_part
= -1;
3137 result
->l_r_select
= -1;
3143 /* Looks like a number. */
3146 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3148 /* The number is specified in hex. */
3150 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3151 || ((*p
>= 'A') && (*p
<= 'F')))
3154 num
= num
* 16 + *p
- '0';
3155 else if (*p
>= 'a' && *p
<= 'f')
3156 num
= num
* 16 + *p
- 'a' + 10;
3158 num
= num
* 16 + *p
- 'A' + 10;
3164 /* The number is specified in decimal. */
3165 while (isdigit (*p
))
3167 num
= num
* 10 + *p
- '0';
3172 /* Store info in RESULT if requested by the caller. */
3175 result
->number_part
= num
;
3177 if (IS_R_SELECT (p
))
3179 result
->l_r_select
= 1;
3182 else if (IS_L_SELECT (p
))
3184 result
->l_r_select
= 0;
3188 result
->l_r_select
= 0;
3193 /* The number might be a predefined register. */
3198 /* Tege hack: Special case for general registers as the general
3199 code makes a binary search with case translation, and is VERY
3204 if (*p
== 'e' && *(p
+ 1) == 't'
3205 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3208 num
= *p
- '0' + 28;
3216 else if (!isdigit (*p
))
3219 as_bad ("Undefined register: '%s'.", name
);
3225 num
= num
* 10 + *p
++ - '0';
3226 while (isdigit (*p
));
3231 /* Do a normal register search. */
3232 while (is_part_of_name (c
))
3238 status
= reg_name_search (name
);
3244 as_bad ("Undefined register: '%s'.", name
);
3250 /* Store info in RESULT if requested by caller. */
3253 result
->number_part
= num
;
3254 if (IS_R_SELECT (p
- 1))
3255 result
->l_r_select
= 1;
3256 else if (IS_L_SELECT (p
- 1))
3257 result
->l_r_select
= 0;
3259 result
->l_r_select
= 0;
3264 /* And finally, it could be a symbol in the absolute section which
3265 is effectively a constant. */
3269 while (is_part_of_name (c
))
3275 if ((sym
= symbol_find (name
)) != NULL
)
3277 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3278 num
= S_GET_VALUE (sym
);
3282 as_bad ("Non-absolute symbol: '%s'.", name
);
3288 /* There is where we'd come for an undefined symbol
3289 or for an empty string. For an empty string we
3290 will return zero. That's a concession made for
3291 compatability with the braindamaged HP assemblers. */
3297 as_bad ("Undefined absolute constant: '%s'.", name
);
3303 /* Store info in RESULT if requested by caller. */
3306 result
->number_part
= num
;
3307 if (IS_R_SELECT (p
- 1))
3308 result
->l_r_select
= 1;
3309 else if (IS_L_SELECT (p
- 1))
3310 result
->l_r_select
= 0;
3312 result
->l_r_select
= 0;
3320 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3322 /* Given NAME, find the register number associated with that name, return
3323 the integer value associated with the given name or -1 on failure. */
3326 reg_name_search (name
)
3329 int middle
, low
, high
;
3333 high
= REG_NAME_CNT
- 1;
3337 middle
= (low
+ high
) / 2;
3338 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
3344 return pre_defined_registers
[middle
].value
;
3346 while (low
<= high
);
3352 /* Return nonzero if the given INSN and L/R information will require
3353 a new PA-1.1 opcode. */
3356 need_pa11_opcode (insn
, result
)
3358 struct pa_11_fp_reg_struct
*result
;
3360 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3362 /* If this instruction is specific to a particular architecture,
3363 then set a new architecture. */
3364 if (bfd_get_mach (stdoutput
) < pa11
)
3366 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
3367 as_warn ("could not update architecture and machine");
3375 /* Parse a condition for a fcmp instruction. Return the numerical
3376 code associated with the condition. */
3379 pa_parse_fp_cmp_cond (s
)
3386 for (i
= 0; i
< 32; i
++)
3388 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3389 strlen (fp_cond_map
[i
].string
)) == 0)
3391 cond
= fp_cond_map
[i
].cond
;
3392 *s
+= strlen (fp_cond_map
[i
].string
);
3393 /* If not a complete match, back up the input string and
3395 if (**s
!= ' ' && **s
!= '\t')
3397 *s
-= strlen (fp_cond_map
[i
].string
);
3400 while (**s
== ' ' || **s
== '\t')
3406 as_bad ("Invalid FP Compare Condition: %s", *s
);
3408 /* Advance over the bogus completer. */
3409 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3415 /* Parse an FP operand format completer returning the completer
3418 static fp_operand_format
3419 pa_parse_fp_format (s
)
3428 if (strncasecmp (*s
, "sgl", 3) == 0)
3433 else if (strncasecmp (*s
, "dbl", 3) == 0)
3438 else if (strncasecmp (*s
, "quad", 4) == 0)
3445 format
= ILLEGAL_FMT
;
3446 as_bad ("Invalid FP Operand Format: %3s", *s
);
3453 /* Convert from a selector string into a selector type. */
3456 pa_chk_field_selector (str
)
3459 int middle
, low
, high
;
3463 /* Read past any whitespace. */
3464 /* FIXME: should we read past newlines and formfeeds??? */
3465 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3468 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
3469 name
[0] = tolower ((*str
)[0]),
3471 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
3472 name
[0] = tolower ((*str
)[0]),
3473 name
[1] = tolower ((*str
)[1]),
3476 else if ((*str
)[3] == '\'' || (*str
)[3] == '%')
3477 name
[0] = tolower ((*str
)[0]),
3478 name
[1] = tolower ((*str
)[1]),
3479 name
[2] = tolower ((*str
)[2]),
3486 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
3490 middle
= (low
+ high
) / 2;
3491 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
3498 *str
+= strlen (name
) + 1;
3500 if (selector_table
[middle
].field_selector
== e_nsel
)
3503 return selector_table
[middle
].field_selector
;
3506 while (low
<= high
);
3511 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3514 get_expression (str
)
3520 save_in
= input_line_pointer
;
3521 input_line_pointer
= str
;
3522 seg
= expression (&the_insn
.exp
);
3523 if (!(seg
== absolute_section
3524 || seg
== undefined_section
3525 || SEG_NORMAL (seg
)))
3527 as_warn ("Bad segment in expression.");
3528 expr_end
= input_line_pointer
;
3529 input_line_pointer
= save_in
;
3532 expr_end
= input_line_pointer
;
3533 input_line_pointer
= save_in
;
3537 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3539 pa_get_absolute_expression (insn
, strp
)
3545 insn
->field_selector
= pa_chk_field_selector (strp
);
3546 save_in
= input_line_pointer
;
3547 input_line_pointer
= *strp
;
3548 expression (&insn
->exp
);
3549 if (insn
->exp
.X_op
!= O_constant
)
3551 as_bad ("Bad segment (should be absolute).");
3552 expr_end
= input_line_pointer
;
3553 input_line_pointer
= save_in
;
3556 expr_end
= input_line_pointer
;
3557 input_line_pointer
= save_in
;
3558 return evaluate_absolute (insn
);
3561 /* Evaluate an absolute expression EXP which may be modified by
3562 the selector FIELD_SELECTOR. Return the value of the expression. */
3564 evaluate_absolute (insn
)
3569 int field_selector
= insn
->field_selector
;
3572 value
= exp
.X_add_number
;
3574 switch (field_selector
)
3580 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3582 if (value
& 0x00000400)
3584 value
= (value
& 0xfffff800) >> 11;
3587 /* Sign extend from bit 21. */
3589 if (value
& 0x00000400)
3590 value
|= 0xfffff800;
3595 /* Arithmetic shift right 11 bits. */
3597 value
= (value
& 0xfffff800) >> 11;
3600 /* Set bits 0-20 to zero. */
3602 value
= value
& 0x7ff;
3605 /* Add 0x800 and arithmetic shift right 11 bits. */
3608 value
= (value
& 0xfffff800) >> 11;
3611 /* Set bitgs 0-21 to one. */
3613 value
|= 0xfffff800;
3616 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3618 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3622 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3627 BAD_CASE (field_selector
);
3633 /* Given an argument location specification return the associated
3634 argument location number. */
3637 pa_build_arg_reloc (type_name
)
3641 if (strncasecmp (type_name
, "no", 2) == 0)
3643 if (strncasecmp (type_name
, "gr", 2) == 0)
3645 else if (strncasecmp (type_name
, "fr", 2) == 0)
3647 else if (strncasecmp (type_name
, "fu", 2) == 0)
3650 as_bad ("Invalid argument location: %s\n", type_name
);
3655 /* Encode and return an argument relocation specification for
3656 the given register in the location specified by arg_reloc. */
3659 pa_align_arg_reloc (reg
, arg_reloc
)
3661 unsigned int arg_reloc
;
3663 unsigned int new_reloc
;
3665 new_reloc
= arg_reloc
;
3681 as_bad ("Invalid argument description: %d", reg
);
3687 /* Parse a PA nullification completer (,n). Return nonzero if the
3688 completer was found; return zero if no completer was found. */
3700 if (strncasecmp (*s
, "n", 1) == 0)
3704 as_bad ("Invalid Nullification: (%c)", **s
);
3713 /* Parse a non-negated compare/subtract completer returning the
3714 number (for encoding in instrutions) of the given completer.
3716 ISBRANCH specifies whether or not this is parsing a condition
3717 completer for a branch (vs a nullification completer for a
3718 computational instruction. */
3721 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3726 char *name
= *s
+ 1;
3734 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3738 if (strcmp (name
, "=") == 0)
3742 else if (strcmp (name
, "<") == 0)
3746 else if (strcmp (name
, "<=") == 0)
3750 else if (strcmp (name
, "<<") == 0)
3754 else if (strcmp (name
, "<<=") == 0)
3758 else if (strcasecmp (name
, "sv") == 0)
3762 else if (strcasecmp (name
, "od") == 0)
3766 /* If we have something like addb,n then there is no condition
3768 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3779 /* Reset pointers if this was really a ,n for a branch instruction. */
3780 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3786 /* Parse a negated compare/subtract completer returning the
3787 number (for encoding in instrutions) of the given completer.
3789 ISBRANCH specifies whether or not this is parsing a condition
3790 completer for a branch (vs a nullification completer for a
3791 computational instruction. */
3794 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3799 char *name
= *s
+ 1;
3807 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3811 if (strcasecmp (name
, "tr") == 0)
3815 else if (strcmp (name
, "<>") == 0)
3819 else if (strcmp (name
, ">=") == 0)
3823 else if (strcmp (name
, ">") == 0)
3827 else if (strcmp (name
, ">>=") == 0)
3831 else if (strcmp (name
, ">>") == 0)
3835 else if (strcasecmp (name
, "nsv") == 0)
3839 else if (strcasecmp (name
, "ev") == 0)
3843 /* If we have something like addb,n then there is no condition
3845 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3856 /* Reset pointers if this was really a ,n for a branch instruction. */
3857 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3863 /* Parse a non-negated addition completer returning the number
3864 (for encoding in instrutions) of the given completer.
3866 ISBRANCH specifies whether or not this is parsing a condition
3867 completer for a branch (vs a nullification completer for a
3868 computational instruction. */
3871 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3876 char *name
= *s
+ 1;
3884 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3888 if (strcmp (name
, "=") == 0)
3892 else if (strcmp (name
, "<") == 0)
3896 else if (strcmp (name
, "<=") == 0)
3900 else if (strcasecmp (name
, "nuv") == 0)
3904 else if (strcasecmp (name
, "znv") == 0)
3908 else if (strcasecmp (name
, "sv") == 0)
3912 else if (strcasecmp (name
, "od") == 0)
3916 /* If we have something like addb,n then there is no condition
3918 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3929 /* Reset pointers if this was really a ,n for a branch instruction. */
3930 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3936 /* Parse a negated addition completer returning the number
3937 (for encoding in instrutions) of the given completer.
3939 ISBRANCH specifies whether or not this is parsing a condition
3940 completer for a branch (vs a nullification completer for a
3941 computational instruction). */
3944 pa_parse_neg_add_cmpltr (s
, isbranch
)
3949 char *name
= *s
+ 1;
3957 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3961 if (strcasecmp (name
, "tr") == 0)
3965 else if (strcmp (name
, "<>") == 0)
3969 else if (strcmp (name
, ">=") == 0)
3973 else if (strcmp (name
, ">") == 0)
3977 else if (strcasecmp (name
, "uv") == 0)
3981 else if (strcasecmp (name
, "vnz") == 0)
3985 else if (strcasecmp (name
, "nsv") == 0)
3989 else if (strcasecmp (name
, "ev") == 0)
3993 /* If we have something like addb,n then there is no condition
3995 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4006 /* Reset pointers if this was really a ,n for a branch instruction. */
4007 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4013 /* Handle an alignment directive. Special so that we can update the
4014 alignment of the subspace if necessary. */
4018 /* We must have a valid space and subspace. */
4019 pa_check_current_space_and_subspace ();
4021 /* Let the generic gas code do most of the work. */
4022 s_align_bytes (bytes
);
4024 /* If bytes is a power of 2, then update the current subspace's
4025 alignment if necessary. */
4026 if (log2 (bytes
) != -1)
4027 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
4030 /* Handle a .BLOCK type pseudo-op. */
4038 unsigned int temp_size
;
4041 /* We must have a valid space and subspace. */
4042 pa_check_current_space_and_subspace ();
4044 temp_size
= get_absolute_expression ();
4046 /* Always fill with zeros, that's what the HP assembler does. */
4049 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4050 (relax_substateT
) 0, (symbolS
*) 0, (offsetT
) 1, NULL
);
4051 bzero (p
, temp_size
);
4053 /* Convert 2 bytes at a time. */
4055 for (i
= 0; i
< temp_size
; i
+= 2)
4057 md_number_to_chars (p
+ i
,
4059 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4062 pa_undefine_label ();
4063 demand_empty_rest_of_line ();
4066 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4074 /* The BRTAB relocations are only availble in SOM (to denote
4075 the beginning and end of branch tables). */
4076 char *where
= frag_more (0);
4078 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4079 NULL
, (offsetT
) 0, NULL
,
4080 0, begin
? R_HPPA_BEGIN_BRTAB
: R_HPPA_END_BRTAB
,
4081 e_fsel
, 0, 0, NULL
);
4084 demand_empty_rest_of_line ();
4087 /* Handle a .begin_try and .end_try pseudo-op. */
4095 char *where
= frag_more (0);
4100 /* The TRY relocations are only availble in SOM (to denote
4101 the beginning and end of exception handling regions). */
4103 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4104 NULL
, (offsetT
) 0, begin
? NULL
: &exp
,
4105 0, begin
? R_HPPA_BEGIN_TRY
: R_HPPA_END_TRY
,
4106 e_fsel
, 0, 0, NULL
);
4109 demand_empty_rest_of_line ();
4112 /* Handle a .CALL pseudo-op. This involves storing away information
4113 about where arguments are to be found so the linker can detect
4114 (and correct) argument location mismatches between caller and callee. */
4120 /* We must have a valid space and subspace. */
4121 pa_check_current_space_and_subspace ();
4123 pa_call_args (&last_call_desc
);
4124 demand_empty_rest_of_line ();
4127 /* Do the dirty work of building a call descriptor which describes
4128 where the caller placed arguments to a function call. */
4131 pa_call_args (call_desc
)
4132 struct call_desc
*call_desc
;
4135 unsigned int temp
, arg_reloc
;
4137 while (!is_end_of_statement ())
4139 name
= input_line_pointer
;
4140 c
= get_symbol_end ();
4141 /* Process a source argument. */
4142 if ((strncasecmp (name
, "argw", 4) == 0))
4144 temp
= atoi (name
+ 4);
4145 p
= input_line_pointer
;
4147 input_line_pointer
++;
4148 name
= input_line_pointer
;
4149 c
= get_symbol_end ();
4150 arg_reloc
= pa_build_arg_reloc (name
);
4151 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4153 /* Process a return value. */
4154 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4156 p
= input_line_pointer
;
4158 input_line_pointer
++;
4159 name
= input_line_pointer
;
4160 c
= get_symbol_end ();
4161 arg_reloc
= pa_build_arg_reloc (name
);
4162 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4166 as_bad ("Invalid .CALL argument: %s", name
);
4168 p
= input_line_pointer
;
4170 if (!is_end_of_statement ())
4171 input_line_pointer
++;
4175 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4178 is_same_frag (frag1
, frag2
)
4185 else if (frag2
== NULL
)
4187 else if (frag1
== frag2
)
4189 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4190 return (is_same_frag (frag1
, frag2
->fr_next
));
4196 /* Build an entry in the UNWIND subspace from the given function
4197 attributes in CALL_INFO. This is not needed for SOM as using
4198 R_ENTRY and R_EXIT relocations allow the linker to handle building
4199 of the unwind spaces. */
4202 pa_build_unwind_subspace (call_info
)
4203 struct call_info
*call_info
;
4206 asection
*seg
, *save_seg
;
4207 subsegT subseg
, save_subseg
;
4211 /* Get into the right seg/subseg. This may involve creating
4212 the seg the first time through. Make sure to have the
4213 old seg/subseg so that we can reset things when we are done. */
4214 subseg
= SUBSEG_UNWIND
;
4215 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4216 if (seg
== ASEC_NULL
)
4218 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4219 bfd_set_section_flags (stdoutput
, seg
,
4220 SEC_READONLY
| SEC_HAS_CONTENTS
4221 | SEC_LOAD
| SEC_RELOC
);
4225 save_subseg
= now_subseg
;
4226 subseg_set (seg
, subseg
);
4229 /* Get some space to hold relocation information for the unwind
4232 md_number_to_chars (p
, 0, 4);
4234 /* Relocation info. for start offset of the function. */
4235 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4236 call_info
->start_symbol
, (offsetT
) 0,
4237 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4240 md_number_to_chars (p
, 0, 4);
4242 /* Relocation info. for end offset of the function.
4244 Because we allow reductions of 32bit relocations for ELF, this will be
4245 reduced to section_sym + offset which avoids putting the temporary
4246 symbol into the symbol table. It (should) end up giving the same
4247 value as call_info->start_symbol + function size once the linker is
4248 finished with its work. */
4250 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4251 call_info
->end_symbol
, (offsetT
) 0,
4252 (expressionS
*) NULL
, 0, R_PARISC_DIR32
, e_fsel
, 32, 0, NULL
);
4255 unwind
= (char *) &call_info
->ci_unwind
;
4256 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4260 FRAG_APPEND_1_CHAR (c
);
4264 /* Return back to the original segment/subsegment. */
4265 subseg_set (save_seg
, save_subseg
);
4269 /* Process a .CALLINFO pseudo-op. This information is used later
4270 to build unwind descriptors and maybe one day to support
4271 .ENTER and .LEAVE. */
4274 pa_callinfo (unused
)
4280 /* We must have a valid space and subspace. */
4281 pa_check_current_space_and_subspace ();
4283 /* .CALLINFO must appear within a procedure definition. */
4284 if (!within_procedure
)
4285 as_bad (".callinfo is not within a procedure definition");
4287 /* Mark the fact that we found the .CALLINFO for the
4288 current procedure. */
4289 callinfo_found
= TRUE
;
4291 /* Iterate over the .CALLINFO arguments. */
4292 while (!is_end_of_statement ())
4294 name
= input_line_pointer
;
4295 c
= get_symbol_end ();
4296 /* Frame size specification. */
4297 if ((strncasecmp (name
, "frame", 5) == 0))
4299 p
= input_line_pointer
;
4301 input_line_pointer
++;
4302 temp
= get_absolute_expression ();
4303 if ((temp
& 0x3) != 0)
4305 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4309 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4310 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4313 /* Entry register (GR, GR and SR) specifications. */
4314 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4316 p
= input_line_pointer
;
4318 input_line_pointer
++;
4319 temp
= get_absolute_expression ();
4320 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4321 even though %r19 is caller saved. I think this is a bug in
4322 the HP assembler, and we are not going to emulate it. */
4323 if (temp
< 3 || temp
> 18)
4324 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4325 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4327 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4329 p
= input_line_pointer
;
4331 input_line_pointer
++;
4332 temp
= get_absolute_expression ();
4333 /* Similarly the HP assembler takes 31 as the high bound even
4334 though %fr21 is the last callee saved floating point register. */
4335 if (temp
< 12 || temp
> 21)
4336 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4337 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4339 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4341 p
= input_line_pointer
;
4343 input_line_pointer
++;
4344 temp
= get_absolute_expression ();
4346 as_bad ("Value for ENTRY_SR must be 3\n");
4348 /* Note whether or not this function performs any calls. */
4349 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4350 (strncasecmp (name
, "caller", 6) == 0))
4352 p
= input_line_pointer
;
4355 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4357 p
= input_line_pointer
;
4360 /* Should RP be saved into the stack. */
4361 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4363 p
= input_line_pointer
;
4365 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4367 /* Likewise for SP. */
4368 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4370 p
= input_line_pointer
;
4372 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4374 /* Is this an unwindable procedure. If so mark it so
4375 in the unwind descriptor. */
4376 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4378 p
= input_line_pointer
;
4380 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4382 /* Is this an interrupt routine. If so mark it in the
4383 unwind descriptor. */
4384 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4386 p
= input_line_pointer
;
4388 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4390 /* Is this a millicode routine. "millicode" isn't in my
4391 assembler manual, but my copy is old. The HP assembler
4392 accepts it, and there's a place in the unwind descriptor
4393 to drop the information, so we'll accept it too. */
4394 else if ((strncasecmp (name
, "millicode", 9) == 0))
4396 p
= input_line_pointer
;
4398 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
4402 as_bad ("Invalid .CALLINFO argument: %s", name
);
4403 *input_line_pointer
= c
;
4405 if (!is_end_of_statement ())
4406 input_line_pointer
++;
4409 demand_empty_rest_of_line ();
4412 /* Switch into the code subspace. */
4418 current_space
= is_defined_space ("$TEXT$");
4420 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
4422 pa_undefine_label ();
4425 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4426 the .comm pseudo-op has the following symtax:
4428 <label> .comm <length>
4430 where <label> is optional and is a symbol whose address will be the start of
4431 a block of memory <length> bytes long. <length> must be an absolute
4432 expression. <length> bytes will be allocated in the current space
4435 Also note the label may not even be on the same line as the .comm.
4437 This difference in syntax means the colon function will be called
4438 on the symbol before we arrive in pa_comm. colon will set a number
4439 of attributes of the symbol that need to be fixed here. In particular
4440 the value, section pointer, fragment pointer, flags, etc. What
4443 This also makes error detection all but impossible. */
4451 label_symbol_struct
*label_symbol
= pa_get_label ();
4454 symbol
= label_symbol
->lss_label
;
4459 size
= get_absolute_expression ();
4463 S_SET_VALUE (symbol
, size
);
4464 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4465 S_SET_EXTERNAL (symbol
);
4467 /* colon() has already set the frag to the current location in the
4468 current subspace; we need to reset the fragment to the zero address
4469 fragment. We also need to reset the segment pointer. */
4470 symbol
->sy_frag
= &zero_address_frag
;
4472 demand_empty_rest_of_line ();
4475 /* Process a .END pseudo-op. */
4481 demand_empty_rest_of_line ();
4484 /* Process a .ENTER pseudo-op. This is not supported. */
4489 /* We must have a valid space and subspace. */
4490 pa_check_current_space_and_subspace ();
4495 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4501 /* We must have a valid space and subspace. */
4502 pa_check_current_space_and_subspace ();
4504 if (!within_procedure
)
4505 as_bad ("Misplaced .entry. Ignored.");
4508 if (!callinfo_found
)
4509 as_bad ("Missing .callinfo.");
4511 demand_empty_rest_of_line ();
4512 within_entry_exit
= TRUE
;
4515 /* SOM defers building of unwind descriptors until the link phase.
4516 The assembler is responsible for creating an R_ENTRY relocation
4517 to mark the beginning of a region and hold the unwind bits, and
4518 for creating an R_EXIT relocation to mark the end of the region.
4520 FIXME. ELF should be using the same conventions! The problem
4521 is an unwind requires too much relocation space. Hmmm. Maybe
4522 if we split the unwind bits up between the relocations which
4523 denote the entry and exit points. */
4524 if (last_call_info
->start_symbol
!= NULL
)
4526 char *where
= frag_more (0);
4528 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4529 NULL
, (offsetT
) 0, NULL
,
4530 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4531 (int *) &last_call_info
->ci_unwind
.descriptor
);
4536 /* Handle a .EQU pseudo-op. */
4542 label_symbol_struct
*label_symbol
= pa_get_label ();
4547 symbol
= label_symbol
->lss_label
;
4549 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
4551 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4552 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
4557 as_bad (".REG must use a label");
4559 as_bad (".EQU must use a label");
4562 pa_undefine_label ();
4563 demand_empty_rest_of_line ();
4566 /* Helper function. Does processing for the end of a function. This
4567 usually involves creating some relocations or building special
4568 symbols to mark the end of the function. */
4575 where
= frag_more (0);
4578 /* Mark the end of the function, stuff away the location of the frag
4579 for the end of the function, and finally call pa_build_unwind_subspace
4580 to add an entry in the unwind table. */
4581 hppa_elf_mark_end_of_function ();
4582 pa_build_unwind_subspace (last_call_info
);
4584 /* SOM defers building of unwind descriptors until the link phase.
4585 The assembler is responsible for creating an R_ENTRY relocation
4586 to mark the beginning of a region and hold the unwind bits, and
4587 for creating an R_EXIT relocation to mark the end of the region.
4589 FIXME. ELF should be using the same conventions! The problem
4590 is an unwind requires too much relocation space. Hmmm. Maybe
4591 if we split the unwind bits up between the relocations which
4592 denote the entry and exit points. */
4593 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4595 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
4596 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
4600 /* Process a .EXIT pseudo-op. */
4606 /* We must have a valid space and subspace. */
4607 pa_check_current_space_and_subspace ();
4609 if (!within_procedure
)
4610 as_bad (".EXIT must appear within a procedure");
4613 if (!callinfo_found
)
4614 as_bad ("Missing .callinfo");
4617 if (!within_entry_exit
)
4618 as_bad ("No .ENTRY for this .EXIT");
4621 within_entry_exit
= FALSE
;
4626 demand_empty_rest_of_line ();
4629 /* Process a .EXPORT directive. This makes functions external
4630 and provides information such as argument relocation entries
4640 name
= input_line_pointer
;
4641 c
= get_symbol_end ();
4642 /* Make sure the given symbol exists. */
4643 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4645 as_bad ("Cannot define export symbol: %s\n", name
);
4646 p
= input_line_pointer
;
4648 input_line_pointer
++;
4652 /* OK. Set the external bits and process argument relocations. */
4653 S_SET_EXTERNAL (symbol
);
4654 p
= input_line_pointer
;
4656 if (!is_end_of_statement ())
4658 input_line_pointer
++;
4659 pa_type_args (symbol
, 1);
4663 demand_empty_rest_of_line ();
4666 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4669 pa_type_args (symbolP
, is_export
)
4674 unsigned int temp
, arg_reloc
;
4675 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4676 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4678 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4681 input_line_pointer
+= 8;
4682 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4683 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
4684 type
= SYMBOL_TYPE_ABSOLUTE
;
4686 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4688 input_line_pointer
+= 4;
4689 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4690 instead one should be IMPORTing/EXPORTing ENTRY types.
4692 Complain if one tries to EXPORT a CODE type since that's never
4693 done. Both GCC and HP C still try to IMPORT CODE types, so
4694 silently fix them to be ENTRY types. */
4695 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4698 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4700 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4701 type
= SYMBOL_TYPE_ENTRY
;
4705 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4706 type
= SYMBOL_TYPE_CODE
;
4709 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4711 input_line_pointer
+= 4;
4712 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4713 type
= SYMBOL_TYPE_DATA
;
4715 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4717 input_line_pointer
+= 5;
4718 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4719 type
= SYMBOL_TYPE_ENTRY
;
4721 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4723 input_line_pointer
+= 9;
4724 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4725 type
= SYMBOL_TYPE_MILLICODE
;
4727 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4729 input_line_pointer
+= 6;
4730 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4731 type
= SYMBOL_TYPE_PLABEL
;
4733 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4735 input_line_pointer
+= 8;
4736 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4737 type
= SYMBOL_TYPE_PRI_PROG
;
4739 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4741 input_line_pointer
+= 8;
4742 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4743 type
= SYMBOL_TYPE_SEC_PROG
;
4746 /* SOM requires much more information about symbol types
4747 than BFD understands. This is how we get this information
4748 to the SOM BFD backend. */
4749 #ifdef obj_set_symbol_type
4750 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4753 /* Now that the type of the exported symbol has been handled,
4754 handle any argument relocation information. */
4755 while (!is_end_of_statement ())
4757 if (*input_line_pointer
== ',')
4758 input_line_pointer
++;
4759 name
= input_line_pointer
;
4760 c
= get_symbol_end ();
4761 /* Argument sources. */
4762 if ((strncasecmp (name
, "argw", 4) == 0))
4764 p
= input_line_pointer
;
4766 input_line_pointer
++;
4767 temp
= atoi (name
+ 4);
4768 name
= input_line_pointer
;
4769 c
= get_symbol_end ();
4770 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4771 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4772 *input_line_pointer
= c
;
4774 /* The return value. */
4775 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4777 p
= input_line_pointer
;
4779 input_line_pointer
++;
4780 name
= input_line_pointer
;
4781 c
= get_symbol_end ();
4782 arg_reloc
= pa_build_arg_reloc (name
);
4783 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4784 *input_line_pointer
= c
;
4786 /* Privelege level. */
4787 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4789 p
= input_line_pointer
;
4791 input_line_pointer
++;
4792 temp
= atoi (input_line_pointer
);
4793 c
= get_symbol_end ();
4794 *input_line_pointer
= c
;
4798 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4799 p
= input_line_pointer
;
4802 if (!is_end_of_statement ())
4803 input_line_pointer
++;
4807 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4808 assembly file must either be defined in the assembly file, or
4809 explicitly IMPORTED from another. */
4818 name
= input_line_pointer
;
4819 c
= get_symbol_end ();
4821 symbol
= symbol_find (name
);
4822 /* Ugh. We might be importing a symbol defined earlier in the file,
4823 in which case all the code below will really screw things up
4824 (set the wrong segment, symbol flags & type, etc). */
4825 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
4827 symbol
= symbol_find_or_make (name
);
4828 p
= input_line_pointer
;
4831 if (!is_end_of_statement ())
4833 input_line_pointer
++;
4834 pa_type_args (symbol
, 0);
4838 /* Sigh. To be compatable with the HP assembler and to help
4839 poorly written assembly code, we assign a type based on
4840 the the current segment. Note only BSF_FUNCTION really
4841 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4842 if (now_seg
== text_section
)
4843 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4845 /* If the section is undefined, then the symbol is undefined
4846 Since this is an import, leave the section undefined. */
4847 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
4852 /* The symbol was already defined. Just eat everything up to
4853 the end of the current statement. */
4854 while (!is_end_of_statement ())
4855 input_line_pointer
++;
4858 demand_empty_rest_of_line ();
4861 /* Handle a .LABEL pseudo-op. */
4869 name
= input_line_pointer
;
4870 c
= get_symbol_end ();
4872 if (strlen (name
) > 0)
4875 p
= input_line_pointer
;
4880 as_warn ("Missing label name on .LABEL");
4883 if (!is_end_of_statement ())
4885 as_warn ("extra .LABEL arguments ignored.");
4886 ignore_rest_of_line ();
4888 demand_empty_rest_of_line ();
4891 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4897 /* We must have a valid space and subspace. */
4898 pa_check_current_space_and_subspace ();
4903 /* Handle a .LEVEL pseudo-op. */
4911 level
= input_line_pointer
;
4912 if (strncmp (level
, "1.0", 3) == 0)
4914 input_line_pointer
+= 3;
4915 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
4916 as_warn ("could not set architecture and machine");
4918 else if (strncmp (level
, "1.1", 3) == 0)
4920 input_line_pointer
+= 3;
4921 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 11))
4922 as_warn ("could not set architecture and machine");
4926 as_bad ("Unrecognized .LEVEL argument\n");
4927 ignore_rest_of_line ();
4929 demand_empty_rest_of_line ();
4932 /* Handle a .ORIGIN pseudo-op. */
4938 /* We must have a valid space and subspace. */
4939 pa_check_current_space_and_subspace ();
4942 pa_undefine_label ();
4945 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4946 is for static functions. FIXME. Should share more code with .EXPORT. */
4955 name
= input_line_pointer
;
4956 c
= get_symbol_end ();
4958 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4960 as_bad ("Cannot define static symbol: %s\n", name
);
4961 p
= input_line_pointer
;
4963 input_line_pointer
++;
4967 S_CLEAR_EXTERNAL (symbol
);
4968 p
= input_line_pointer
;
4970 if (!is_end_of_statement ())
4972 input_line_pointer
++;
4973 pa_type_args (symbol
, 0);
4977 demand_empty_rest_of_line ();
4980 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4981 of a procedure from a syntatical point of view. */
4987 struct call_info
*call_info
;
4989 /* We must have a valid space and subspace. */
4990 pa_check_current_space_and_subspace ();
4992 if (within_procedure
)
4993 as_fatal ("Nested procedures");
4995 /* Reset global variables for new procedure. */
4996 callinfo_found
= FALSE
;
4997 within_procedure
= TRUE
;
4999 /* Create another call_info structure. */
5000 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5003 as_fatal ("Cannot allocate unwind descriptor\n");
5005 bzero (call_info
, sizeof (struct call_info
));
5007 call_info
->ci_next
= NULL
;
5009 if (call_info_root
== NULL
)
5011 call_info_root
= call_info
;
5012 last_call_info
= call_info
;
5016 last_call_info
->ci_next
= call_info
;
5017 last_call_info
= call_info
;
5020 /* set up defaults on call_info structure */
5022 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5023 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5024 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5026 /* If we got a .PROC pseudo-op, we know that the function is defined
5027 locally. Make sure it gets into the symbol table. */
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
;
5039 as_bad ("Missing function name for .PROC (corrupted label chain)");
5042 last_call_info
->start_symbol
= NULL
;
5045 demand_empty_rest_of_line ();
5048 /* Process the syntatical end of a procedure. Make sure all the
5049 appropriate pseudo-ops were found within the procedure. */
5056 /* We must have a valid space and subspace. */
5057 pa_check_current_space_and_subspace ();
5059 /* If we are within a procedure definition, make sure we've
5060 defined a label for the procedure; handle case where the
5061 label was defined after the .PROC directive.
5063 Note there's not need to diddle with the segment or fragment
5064 for the label symbol in this case. We have already switched
5065 into the new $CODE$ subspace at this point. */
5066 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
5068 label_symbol_struct
*label_symbol
= pa_get_label ();
5072 if (label_symbol
->lss_label
)
5074 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5075 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5077 /* Also handle allocation of a fixup to hold the unwind
5078 information when the label appears after the proc/procend. */
5079 if (within_entry_exit
)
5081 char *where
= frag_more (0);
5083 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5084 NULL
, (offsetT
) 0, NULL
,
5085 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
5086 (int *) &last_call_info
->ci_unwind
.descriptor
);
5091 as_bad ("Missing function name for .PROC (corrupted label chain)");
5094 as_bad ("Missing function name for .PROC");
5097 if (!within_procedure
)
5098 as_bad ("misplaced .procend");
5100 if (!callinfo_found
)
5101 as_bad ("Missing .callinfo for this procedure");
5103 if (within_entry_exit
)
5104 as_bad ("Missing .EXIT for a .ENTRY");
5107 /* ELF needs to mark the end of each function so that it can compute
5108 the size of the function (apparently its needed in the symbol table). */
5109 hppa_elf_mark_end_of_function ();
5112 within_procedure
= FALSE
;
5113 demand_empty_rest_of_line ();
5114 pa_undefine_label ();
5117 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5118 then create a new space entry to hold the information specified
5119 by the parameters to the .SPACE directive. */
5121 static sd_chain_struct
*
5122 pa_parse_space_stmt (space_name
, create_flag
)
5126 char *name
, *ptemp
, c
;
5127 char loadable
, defined
, private, sort
;
5129 asection
*seg
= NULL
;
5130 sd_chain_struct
*space
;
5132 /* load default values */
5138 if (strcmp (space_name
, "$TEXT$") == 0)
5140 seg
= pa_def_spaces
[0].segment
;
5141 defined
= pa_def_spaces
[0].defined
;
5142 private = pa_def_spaces
[0].private;
5143 sort
= pa_def_spaces
[0].sort
;
5144 spnum
= pa_def_spaces
[0].spnum
;
5146 else if (strcmp (space_name
, "$PRIVATE$") == 0)
5148 seg
= pa_def_spaces
[1].segment
;
5149 defined
= pa_def_spaces
[1].defined
;
5150 private = pa_def_spaces
[1].private;
5151 sort
= pa_def_spaces
[1].sort
;
5152 spnum
= pa_def_spaces
[1].spnum
;
5155 if (!is_end_of_statement ())
5157 print_errors
= FALSE
;
5158 ptemp
= input_line_pointer
+ 1;
5159 /* First see if the space was specified as a number rather than
5160 as a name. According to the PA assembly manual the rest of
5161 the line should be ignored. */
5162 temp
= pa_parse_number (&ptemp
, 0);
5166 input_line_pointer
= ptemp
;
5170 while (!is_end_of_statement ())
5172 input_line_pointer
++;
5173 name
= input_line_pointer
;
5174 c
= get_symbol_end ();
5175 if ((strncasecmp (name
, "spnum", 5) == 0))
5177 *input_line_pointer
= c
;
5178 input_line_pointer
++;
5179 spnum
= get_absolute_expression ();
5181 else if ((strncasecmp (name
, "sort", 4) == 0))
5183 *input_line_pointer
= c
;
5184 input_line_pointer
++;
5185 sort
= get_absolute_expression ();
5187 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5189 *input_line_pointer
= c
;
5192 else if ((strncasecmp (name
, "notdefined", 10) == 0))
5194 *input_line_pointer
= c
;
5197 else if ((strncasecmp (name
, "private", 7) == 0))
5199 *input_line_pointer
= c
;
5204 as_bad ("Invalid .SPACE argument");
5205 *input_line_pointer
= c
;
5206 if (!is_end_of_statement ())
5207 input_line_pointer
++;
5211 print_errors
= TRUE
;
5214 if (create_flag
&& seg
== NULL
)
5215 seg
= subseg_new (space_name
, 0);
5217 /* If create_flag is nonzero, then create the new space with
5218 the attributes computed above. Else set the values in
5219 an already existing space -- this can only happen for
5220 the first occurence of a built-in space. */
5222 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5223 private, sort
, seg
, 1);
5226 space
= is_defined_space (space_name
);
5227 SPACE_SPNUM (space
) = spnum
;
5228 SPACE_DEFINED (space
) = defined
& 1;
5229 SPACE_USER_DEFINED (space
) = 1;
5232 #ifdef obj_set_section_attributes
5233 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5239 /* Handle a .SPACE pseudo-op; this switches the current space to the
5240 given space, creating the new space if necessary. */
5246 char *name
, c
, *space_name
, *save_s
;
5248 sd_chain_struct
*sd_chain
;
5250 if (within_procedure
)
5252 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5253 ignore_rest_of_line ();
5257 /* Check for some of the predefined spaces. FIXME: most of the code
5258 below is repeated several times, can we extract the common parts
5259 and place them into a subroutine or something similar? */
5260 /* FIXME Is this (and the next IF stmt) really right?
5261 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5262 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
5264 input_line_pointer
+= 6;
5265 sd_chain
= is_defined_space ("$TEXT$");
5266 if (sd_chain
== NULL
)
5267 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5268 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5269 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5271 current_space
= sd_chain
;
5272 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5274 = pa_subsegment_to_subspace (text_section
,
5275 sd_chain
->sd_last_subseg
);
5276 demand_empty_rest_of_line ();
5279 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
5281 input_line_pointer
+= 9;
5282 sd_chain
= is_defined_space ("$PRIVATE$");
5283 if (sd_chain
== NULL
)
5284 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5285 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5286 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5288 current_space
= sd_chain
;
5289 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5291 = pa_subsegment_to_subspace (data_section
,
5292 sd_chain
->sd_last_subseg
);
5293 demand_empty_rest_of_line ();
5296 if (!strncasecmp (input_line_pointer
,
5297 GDB_DEBUG_SPACE_NAME
,
5298 strlen (GDB_DEBUG_SPACE_NAME
)))
5300 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5301 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5302 if (sd_chain
== NULL
)
5303 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5304 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5305 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5307 current_space
= sd_chain
;
5310 asection
*gdb_section
5311 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5313 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5315 = pa_subsegment_to_subspace (gdb_section
,
5316 sd_chain
->sd_last_subseg
);
5318 demand_empty_rest_of_line ();
5322 /* It could be a space specified by number. */
5324 save_s
= input_line_pointer
;
5325 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5327 if ((sd_chain
= pa_find_space_by_number (temp
)))
5329 current_space
= sd_chain
;
5331 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5333 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5334 sd_chain
->sd_last_subseg
);
5335 demand_empty_rest_of_line ();
5340 /* Not a number, attempt to create a new space. */
5342 input_line_pointer
= save_s
;
5343 name
= input_line_pointer
;
5344 c
= get_symbol_end ();
5345 space_name
= xmalloc (strlen (name
) + 1);
5346 strcpy (space_name
, name
);
5347 *input_line_pointer
= c
;
5349 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5350 current_space
= sd_chain
;
5352 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5353 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5354 sd_chain
->sd_last_subseg
);
5355 demand_empty_rest_of_line ();
5359 /* Switch to a new space. (I think). FIXME. */
5368 sd_chain_struct
*space
;
5370 name
= input_line_pointer
;
5371 c
= get_symbol_end ();
5372 space
= is_defined_space (name
);
5376 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5379 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5381 *input_line_pointer
= c
;
5382 demand_empty_rest_of_line ();
5385 /* If VALUE is an exact power of two between zero and 2^31, then
5386 return log2 (VALUE). Else return -1. */
5394 while ((1 << shift
) != value
&& shift
< 32)
5403 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5404 given subspace, creating the new subspace if necessary.
5406 FIXME. Should mirror pa_space more closely, in particular how
5407 they're broken up into subroutines. */
5410 pa_subspace (create_new
)
5413 char *name
, *ss_name
, *alias
, c
;
5414 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5415 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5416 sd_chain_struct
*space
;
5417 ssd_chain_struct
*ssd
;
5420 if (current_space
== NULL
)
5421 as_fatal ("Must be in a space before changing or declaring subspaces.\n");
5423 if (within_procedure
)
5425 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5426 ignore_rest_of_line ();
5430 name
= input_line_pointer
;
5431 c
= get_symbol_end ();
5432 ss_name
= xmalloc (strlen (name
) + 1);
5433 strcpy (ss_name
, name
);
5434 *input_line_pointer
= c
;
5436 /* Load default values. */
5449 space
= current_space
;
5453 ssd
= is_defined_subspace (ss_name
);
5454 /* Allow user to override the builtin attributes of subspaces. But
5455 only allow the attributes to be changed once! */
5456 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5458 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5459 current_subspace
= ssd
;
5460 if (!is_end_of_statement ())
5461 as_warn ("Parameters of an existing subspace can\'t be modified");
5462 demand_empty_rest_of_line ();
5467 /* A new subspace. Load default values if it matches one of
5468 the builtin subspaces. */
5470 while (pa_def_subspaces
[i
].name
)
5472 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5474 loadable
= pa_def_subspaces
[i
].loadable
;
5475 common
= pa_def_subspaces
[i
].common
;
5476 dup_common
= pa_def_subspaces
[i
].dup_common
;
5477 code_only
= pa_def_subspaces
[i
].code_only
;
5478 zero
= pa_def_subspaces
[i
].zero
;
5479 space_index
= pa_def_subspaces
[i
].space_index
;
5480 alignment
= pa_def_subspaces
[i
].alignment
;
5481 quadrant
= pa_def_subspaces
[i
].quadrant
;
5482 access
= pa_def_subspaces
[i
].access
;
5483 sort
= pa_def_subspaces
[i
].sort
;
5484 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5485 alias
= pa_def_subspaces
[i
].alias
;
5492 /* We should be working with a new subspace now. Fill in
5493 any information as specified by the user. */
5494 if (!is_end_of_statement ())
5496 input_line_pointer
++;
5497 while (!is_end_of_statement ())
5499 name
= input_line_pointer
;
5500 c
= get_symbol_end ();
5501 if ((strncasecmp (name
, "quad", 4) == 0))
5503 *input_line_pointer
= c
;
5504 input_line_pointer
++;
5505 quadrant
= get_absolute_expression ();
5507 else if ((strncasecmp (name
, "align", 5) == 0))
5509 *input_line_pointer
= c
;
5510 input_line_pointer
++;
5511 alignment
= get_absolute_expression ();
5512 if (log2 (alignment
) == -1)
5514 as_bad ("Alignment must be a power of 2");
5518 else if ((strncasecmp (name
, "access", 6) == 0))
5520 *input_line_pointer
= c
;
5521 input_line_pointer
++;
5522 access
= get_absolute_expression ();
5524 else if ((strncasecmp (name
, "sort", 4) == 0))
5526 *input_line_pointer
= c
;
5527 input_line_pointer
++;
5528 sort
= get_absolute_expression ();
5530 else if ((strncasecmp (name
, "code_only", 9) == 0))
5532 *input_line_pointer
= c
;
5535 else if ((strncasecmp (name
, "unloadable", 10) == 0))
5537 *input_line_pointer
= c
;
5540 else if ((strncasecmp (name
, "common", 6) == 0))
5542 *input_line_pointer
= c
;
5545 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
5547 *input_line_pointer
= c
;
5550 else if ((strncasecmp (name
, "zero", 4) == 0))
5552 *input_line_pointer
= c
;
5555 else if ((strncasecmp (name
, "first", 5) == 0))
5556 as_bad ("FIRST not supported as a .SUBSPACE argument");
5558 as_bad ("Invalid .SUBSPACE argument");
5559 if (!is_end_of_statement ())
5560 input_line_pointer
++;
5564 /* Compute a reasonable set of BFD flags based on the information
5565 in the .subspace directive. */
5566 applicable
= bfd_applicable_section_flags (stdoutput
);
5569 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5572 if (common
|| dup_common
)
5573 flags
|= SEC_IS_COMMON
;
5575 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5577 /* This is a zero-filled subspace (eg BSS). */
5579 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
5581 applicable
&= flags
;
5583 /* If this is an existing subspace, then we want to use the
5584 segment already associated with the subspace.
5586 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5587 lots of sections. It might be a problem in the PA ELF
5588 code, I do not know yet. For now avoid creating anything
5589 but the "standard" sections for ELF. */
5591 section
= subseg_force_new (ss_name
, 0);
5593 section
= ssd
->ssd_seg
;
5595 section
= subseg_new (alias
, 0);
5596 else if (!alias
&& USE_ALIASES
)
5598 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5599 demand_empty_rest_of_line ();
5603 section
= subseg_new (ss_name
, 0);
5606 seg_info (section
)->bss
= 1;
5608 /* Now set the flags. */
5609 bfd_set_section_flags (stdoutput
, section
, applicable
);
5611 /* Record any alignment request for this section. */
5612 record_alignment (section
, log2 (alignment
));
5614 /* Set the starting offset for this section. */
5615 bfd_set_section_vma (stdoutput
, section
,
5616 pa_subspace_start (space
, quadrant
));
5618 /* Now that all the flags are set, update an existing subspace,
5619 or create a new one. */
5622 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5623 code_only
, common
, dup_common
,
5624 sort
, zero
, access
, space_index
,
5625 alignment
, quadrant
,
5628 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5630 dup_common
, zero
, sort
,
5631 access
, space_index
,
5632 alignment
, quadrant
, section
);
5634 demand_empty_rest_of_line ();
5635 current_subspace
->ssd_seg
= section
;
5636 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5638 SUBSPACE_DEFINED (current_subspace
) = 1;
5642 /* Create default space and subspace dictionaries. */
5649 space_dict_root
= NULL
;
5650 space_dict_last
= NULL
;
5653 while (pa_def_spaces
[i
].name
)
5657 /* Pick the right name to use for the new section. */
5658 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5659 name
= pa_def_spaces
[i
].alias
;
5661 name
= pa_def_spaces
[i
].name
;
5663 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5664 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5665 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5666 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5667 pa_def_spaces
[i
].segment
, 0);
5672 while (pa_def_subspaces
[i
].name
)
5675 int applicable
, subsegment
;
5676 asection
*segment
= NULL
;
5677 sd_chain_struct
*space
;
5679 /* Pick the right name for the new section and pick the right
5680 subsegment number. */
5681 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5683 name
= pa_def_subspaces
[i
].alias
;
5684 subsegment
= pa_def_subspaces
[i
].subsegment
;
5688 name
= pa_def_subspaces
[i
].name
;
5692 /* Create the new section. */
5693 segment
= subseg_new (name
, subsegment
);
5696 /* For SOM we want to replace the standard .text, .data, and .bss
5697 sections with our own. We also want to set BFD flags for
5698 all the built-in subspaces. */
5699 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5701 text_section
= segment
;
5702 applicable
= bfd_applicable_section_flags (stdoutput
);
5703 bfd_set_section_flags (stdoutput
, segment
,
5704 applicable
& (SEC_ALLOC
| SEC_LOAD
5705 | SEC_RELOC
| SEC_CODE
5707 | SEC_HAS_CONTENTS
));
5709 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5711 data_section
= segment
;
5712 applicable
= bfd_applicable_section_flags (stdoutput
);
5713 bfd_set_section_flags (stdoutput
, segment
,
5714 applicable
& (SEC_ALLOC
| SEC_LOAD
5716 | SEC_HAS_CONTENTS
));
5720 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5722 bss_section
= segment
;
5723 applicable
= bfd_applicable_section_flags (stdoutput
);
5724 bfd_set_section_flags (stdoutput
, segment
,
5725 applicable
& SEC_ALLOC
);
5727 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$") && !USE_ALIASES
)
5729 applicable
= bfd_applicable_section_flags (stdoutput
);
5730 bfd_set_section_flags (stdoutput
, segment
,
5731 applicable
& (SEC_ALLOC
| SEC_LOAD
5734 | SEC_HAS_CONTENTS
));
5736 else if (!strcmp (pa_def_subspaces
[i
].name
, "$MILLICODE$")
5739 applicable
= bfd_applicable_section_flags (stdoutput
);
5740 bfd_set_section_flags (stdoutput
, segment
,
5741 applicable
& (SEC_ALLOC
| SEC_LOAD
5744 | SEC_HAS_CONTENTS
));
5746 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$") && !USE_ALIASES
)
5748 applicable
= bfd_applicable_section_flags (stdoutput
);
5749 bfd_set_section_flags (stdoutput
, segment
,
5750 applicable
& (SEC_ALLOC
| SEC_LOAD
5753 | SEC_HAS_CONTENTS
));
5756 /* Find the space associated with this subspace. */
5757 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5758 def_space_index
].segment
);
5761 as_fatal ("Internal error: Unable to find containing space for %s.",
5762 pa_def_subspaces
[i
].name
);
5765 create_new_subspace (space
, name
,
5766 pa_def_subspaces
[i
].loadable
,
5767 pa_def_subspaces
[i
].code_only
,
5768 pa_def_subspaces
[i
].common
,
5769 pa_def_subspaces
[i
].dup_common
,
5770 pa_def_subspaces
[i
].zero
,
5771 pa_def_subspaces
[i
].sort
,
5772 pa_def_subspaces
[i
].access
,
5773 pa_def_subspaces
[i
].space_index
,
5774 pa_def_subspaces
[i
].alignment
,
5775 pa_def_subspaces
[i
].quadrant
,
5783 /* Create a new space NAME, with the appropriate flags as defined
5784 by the given parameters. */
5786 static sd_chain_struct
*
5787 create_new_space (name
, spnum
, loadable
, defined
, private,
5788 sort
, seg
, user_defined
)
5798 sd_chain_struct
*chain_entry
;
5800 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5802 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5805 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5806 strcpy (SPACE_NAME (chain_entry
), name
);
5807 SPACE_DEFINED (chain_entry
) = defined
;
5808 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5809 SPACE_SPNUM (chain_entry
) = spnum
;
5811 chain_entry
->sd_seg
= seg
;
5812 chain_entry
->sd_last_subseg
= -1;
5813 chain_entry
->sd_subspaces
= NULL
;
5814 chain_entry
->sd_next
= NULL
;
5816 /* Find spot for the new space based on its sort key. */
5817 if (!space_dict_last
)
5818 space_dict_last
= chain_entry
;
5820 if (space_dict_root
== NULL
)
5821 space_dict_root
= chain_entry
;
5824 sd_chain_struct
*chain_pointer
;
5825 sd_chain_struct
*prev_chain_pointer
;
5827 chain_pointer
= space_dict_root
;
5828 prev_chain_pointer
= NULL
;
5830 while (chain_pointer
)
5832 prev_chain_pointer
= chain_pointer
;
5833 chain_pointer
= chain_pointer
->sd_next
;
5836 /* At this point we've found the correct place to add the new
5837 entry. So add it and update the linked lists as appropriate. */
5838 if (prev_chain_pointer
)
5840 chain_entry
->sd_next
= chain_pointer
;
5841 prev_chain_pointer
->sd_next
= chain_entry
;
5845 space_dict_root
= chain_entry
;
5846 chain_entry
->sd_next
= chain_pointer
;
5849 if (chain_entry
->sd_next
== NULL
)
5850 space_dict_last
= chain_entry
;
5853 /* This is here to catch predefined spaces which do not get
5854 modified by the user's input. Another call is found at
5855 the bottom of pa_parse_space_stmt to handle cases where
5856 the user modifies a predefined space. */
5857 #ifdef obj_set_section_attributes
5858 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5864 /* Create a new subspace NAME, with the appropriate flags as defined
5865 by the given parameters.
5867 Add the new subspace to the subspace dictionary chain in numerical
5868 order as defined by the SORT entries. */
5870 static ssd_chain_struct
*
5871 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5872 dup_common
, is_zero
, sort
, access
, space_index
,
5873 alignment
, quadrant
, seg
)
5874 sd_chain_struct
*space
;
5876 int loadable
, code_only
, common
, dup_common
, is_zero
;
5884 ssd_chain_struct
*chain_entry
;
5886 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5888 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5890 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5891 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5893 /* Initialize subspace_defined. When we hit a .subspace directive
5894 we'll set it to 1 which "locks-in" the subspace attributes. */
5895 SUBSPACE_DEFINED (chain_entry
) = 0;
5897 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5898 chain_entry
->ssd_seg
= seg
;
5899 chain_entry
->ssd_next
= NULL
;
5901 /* Find spot for the new subspace based on its sort key. */
5902 if (space
->sd_subspaces
== NULL
)
5903 space
->sd_subspaces
= chain_entry
;
5906 ssd_chain_struct
*chain_pointer
;
5907 ssd_chain_struct
*prev_chain_pointer
;
5909 chain_pointer
= space
->sd_subspaces
;
5910 prev_chain_pointer
= NULL
;
5912 while (chain_pointer
)
5914 prev_chain_pointer
= chain_pointer
;
5915 chain_pointer
= chain_pointer
->ssd_next
;
5918 /* Now we have somewhere to put the new entry. Insert it and update
5920 if (prev_chain_pointer
)
5922 chain_entry
->ssd_next
= chain_pointer
;
5923 prev_chain_pointer
->ssd_next
= chain_entry
;
5927 space
->sd_subspaces
= chain_entry
;
5928 chain_entry
->ssd_next
= chain_pointer
;
5932 #ifdef obj_set_subsection_attributes
5933 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5940 /* Update the information for the given subspace based upon the
5941 various arguments. Return the modified subspace chain entry. */
5943 static ssd_chain_struct
*
5944 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5945 zero
, access
, space_index
, alignment
, quadrant
, section
)
5946 sd_chain_struct
*space
;
5960 ssd_chain_struct
*chain_entry
;
5962 chain_entry
= is_defined_subspace (name
);
5964 #ifdef obj_set_subsection_attributes
5965 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5972 /* Return the space chain entry for the space with the name NAME or
5973 NULL if no such space exists. */
5975 static sd_chain_struct
*
5976 is_defined_space (name
)
5979 sd_chain_struct
*chain_pointer
;
5981 for (chain_pointer
= space_dict_root
;
5983 chain_pointer
= chain_pointer
->sd_next
)
5985 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5986 return chain_pointer
;
5989 /* No mapping from segment to space was found. Return NULL. */
5993 /* Find and return the space associated with the given seg. If no mapping
5994 from the given seg to a space is found, then return NULL.
5996 Unlike subspaces, the number of spaces is not expected to grow much,
5997 so a linear exhaustive search is OK here. */
5999 static sd_chain_struct
*
6000 pa_segment_to_space (seg
)
6003 sd_chain_struct
*space_chain
;
6005 /* Walk through each space looking for the correct mapping. */
6006 for (space_chain
= space_dict_root
;
6008 space_chain
= space_chain
->sd_next
)
6010 if (space_chain
->sd_seg
== seg
)
6014 /* Mapping was not found. Return NULL. */
6018 /* Return the space chain entry for the subspace with the name NAME or
6019 NULL if no such subspace exists.
6021 Uses a linear search through all the spaces and subspaces, this may
6022 not be appropriate if we ever being placing each function in its
6025 static ssd_chain_struct
*
6026 is_defined_subspace (name
)
6029 sd_chain_struct
*space_chain
;
6030 ssd_chain_struct
*subspace_chain
;
6032 /* Walk through each space. */
6033 for (space_chain
= space_dict_root
;
6035 space_chain
= space_chain
->sd_next
)
6037 /* Walk through each subspace looking for a name which matches. */
6038 for (subspace_chain
= space_chain
->sd_subspaces
;
6040 subspace_chain
= subspace_chain
->ssd_next
)
6041 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6042 return subspace_chain
;
6045 /* Subspace wasn't found. Return NULL. */
6049 /* Find and return the subspace associated with the given seg. If no
6050 mapping from the given seg to a subspace is found, then return NULL.
6052 If we ever put each procedure/function within its own subspace
6053 (to make life easier on the compiler and linker), then this will have
6054 to become more efficient. */
6056 static ssd_chain_struct
*
6057 pa_subsegment_to_subspace (seg
, subseg
)
6061 sd_chain_struct
*space_chain
;
6062 ssd_chain_struct
*subspace_chain
;
6064 /* Walk through each space. */
6065 for (space_chain
= space_dict_root
;
6067 space_chain
= space_chain
->sd_next
)
6069 if (space_chain
->sd_seg
== seg
)
6071 /* Walk through each subspace within each space looking for
6072 the correct mapping. */
6073 for (subspace_chain
= space_chain
->sd_subspaces
;
6075 subspace_chain
= subspace_chain
->ssd_next
)
6076 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6077 return subspace_chain
;
6081 /* No mapping from subsegment to subspace found. Return NULL. */
6085 /* Given a number, try and find a space with the name number.
6087 Return a pointer to a space dictionary chain entry for the space
6088 that was found or NULL on failure. */
6090 static sd_chain_struct
*
6091 pa_find_space_by_number (number
)
6094 sd_chain_struct
*space_chain
;
6096 for (space_chain
= space_dict_root
;
6098 space_chain
= space_chain
->sd_next
)
6100 if (SPACE_SPNUM (space_chain
) == number
)
6104 /* No appropriate space found. Return NULL. */
6108 /* Return the starting address for the given subspace. If the starting
6109 address is unknown then return zero. */
6112 pa_subspace_start (space
, quadrant
)
6113 sd_chain_struct
*space
;
6116 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6117 is not correct for the PA OSF1 port. */
6118 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6120 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6126 /* FIXME. Needs documentation. */
6128 pa_next_subseg (space
)
6129 sd_chain_struct
*space
;
6132 space
->sd_last_subseg
++;
6133 return space
->sd_last_subseg
;
6136 /* Helper function for pa_stringer. Used to find the end of
6143 unsigned int c
= *s
& CHAR_MASK
;
6145 /* We must have a valid space and subspace. */
6146 pa_check_current_space_and_subspace ();
6159 /* Handle a .STRING type pseudo-op. */
6162 pa_stringer (append_zero
)
6165 char *s
, num_buf
[4];
6169 /* Preprocess the string to handle PA-specific escape sequences.
6170 For example, \xDD where DD is a hexidecimal number should be
6171 changed to \OOO where OOO is an octal number. */
6173 /* Skip the opening quote. */
6174 s
= input_line_pointer
+ 1;
6176 while (is_a_char (c
= pa_stringer_aux (s
++)))
6183 /* Handle \x<num>. */
6186 unsigned int number
;
6191 /* Get pas the 'x'. */
6193 for (num_digit
= 0, number
= 0, dg
= *s
;
6195 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6196 || (dg
>= 'A' && dg
<= 'F'));
6200 number
= number
* 16 + dg
- '0';
6201 else if (dg
>= 'a' && dg
<= 'f')
6202 number
= number
* 16 + dg
- 'a' + 10;
6204 number
= number
* 16 + dg
- 'A' + 10;
6214 sprintf (num_buf
, "%02o", number
);
6217 sprintf (num_buf
, "%03o", number
);
6220 for (i
= 0; i
<= num_digit
; i
++)
6221 s_start
[i
] = num_buf
[i
];
6225 /* This might be a "\"", skip over the escaped char. */
6232 stringer (append_zero
);
6233 pa_undefine_label ();
6236 /* Handle a .VERSION pseudo-op. */
6243 pa_undefine_label ();
6246 /* Handle a .COPYRIGHT pseudo-op. */
6249 pa_copyright (unused
)
6253 pa_undefine_label ();
6256 /* Just like a normal cons, but when finished we have to undefine
6257 the latest space label. */
6264 pa_undefine_label ();
6267 /* Switch to the data space. As usual delete our label. */
6273 current_space
= is_defined_space ("$PRIVATE$");
6275 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6277 pa_undefine_label ();
6280 /* Like float_cons, but we need to undefine our label. */
6283 pa_float_cons (float_type
)
6286 float_cons (float_type
);
6287 pa_undefine_label ();
6290 /* Like s_fill, but delete our label when finished. */
6296 /* We must have a valid space and subspace. */
6297 pa_check_current_space_and_subspace ();
6300 pa_undefine_label ();
6303 /* Like lcomm, but delete our label when finished. */
6306 pa_lcomm (needs_align
)
6309 /* We must have a valid space and subspace. */
6310 pa_check_current_space_and_subspace ();
6312 s_lcomm (needs_align
);
6313 pa_undefine_label ();
6316 /* Like lsym, but delete our label when finished. */
6322 /* We must have a valid space and subspace. */
6323 pa_check_current_space_and_subspace ();
6326 pa_undefine_label ();
6329 /* Switch to the text space. Like s_text, but delete our
6330 label when finished. */
6335 current_space
= is_defined_space ("$TEXT$");
6337 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
6340 pa_undefine_label ();
6343 /* On the PA relocations which involve function symbols must not be
6344 adjusted. This so that the linker can know when/how to create argument
6345 relocation stubs for indirect calls and calls to static functions.
6347 "T" field selectors create DLT relative fixups for accessing
6348 globals and statics in PIC code; each DLT relative fixup creates
6349 an entry in the DLT table. The entries contain the address of
6350 the final target (eg accessing "foo" would create a DLT entry
6351 with the address of "foo").
6353 Unfortunately, the HP linker doesn't take into account any addend
6354 when generating the DLT; so accessing $LIT$+8 puts the address of
6355 $LIT$ into the DLT rather than the address of $LIT$+8.
6357 The end result is we can't perform relocation symbol reductions for
6358 any fixup which creates entries in the DLT (eg they use "T" field
6361 Reject reductions involving symbols with external scope; such
6362 reductions make life a living hell for object file editors.
6364 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6365 the code space. The SOM BFD backend doesn't know how to pull the
6366 right bits out of an instruction. */
6369 hppa_fix_adjustable (fixp
)
6372 struct hppa_fix_struct
*hppa_fix
;
6374 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6377 /* Reject reductions of symbols in 32bit relocs. */
6378 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6381 /* Reject reductions of symbols in sym1-sym2 expressions when
6382 the fixup will occur in a CODE subspace.
6384 XXX FIXME: Long term we probably want to reject all of these;
6385 for example reducing in the debug section would lose if we ever
6386 supported using the optimizing hp linker. */
6389 && (hppa_fix
->segment
->flags
& SEC_CODE
))
6391 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6392 fixp
->fx_subsy
->sy_used_in_reloc
= 1;
6396 /* We can't adjust any relocs that use LR% and RR% field selectors.
6397 That confuses the HP linker. */
6398 if (hppa_fix
->fx_r_field
== e_lrsel
6399 || hppa_fix
->fx_r_field
== e_rrsel
6400 || hppa_fix
->fx_r_field
== e_nlrsel
)
6404 /* Reject reductions of symbols in DLT relative relocs,
6405 relocations with plabels. */
6406 if (hppa_fix
->fx_r_field
== e_tsel
6407 || hppa_fix
->fx_r_field
== e_ltsel
6408 || hppa_fix
->fx_r_field
== e_rtsel
6409 || hppa_fix
->fx_r_field
== e_psel
6410 || hppa_fix
->fx_r_field
== e_rpsel
6411 || hppa_fix
->fx_r_field
== e_lpsel
)
6414 if (fixp
->fx_addsy
&& fixp
->fx_addsy
->bsym
->flags
& BSF_GLOBAL
)
6417 /* Reject reductions of function symbols. */
6418 if (fixp
->fx_addsy
== 0
6419 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6425 /* Return nonzero if the fixup in FIXP will require a relocation,
6426 even it if appears that the fixup could be completely handled
6430 hppa_force_relocation (fixp
)
6433 struct hppa_fix_struct
*hppa_fixp
;
6436 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
6438 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
6439 || fixp
->fx_r_type
== R_HPPA_BEGIN_BRTAB
6440 || fixp
->fx_r_type
== R_HPPA_END_BRTAB
6441 || fixp
->fx_r_type
== R_HPPA_BEGIN_TRY
6442 || fixp
->fx_r_type
== R_HPPA_END_TRY
6443 || (fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
6444 && (hppa_fixp
->segment
->flags
& SEC_CODE
) != 0))
6448 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6449 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6451 /* It is necessary to force PC-relative calls/jumps to have a relocation
6452 entry if they're going to need either a argument relocation or long
6453 call stub. FIXME. Can't we need the same for absolute calls? */
6454 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6455 && (arg_reloc_stub_needed (((obj_symbol_type
*)
6456 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6458 hppa_fixp
->fx_arg_reloc
)))
6460 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
6461 - md_pcrel_from (fixp
));
6462 /* Now check and see if we're going to need a long-branch stub. */
6463 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
6464 && (distance
> 262143 || distance
< -262144))
6467 #undef arg_reloc_stub_needed
6469 /* No need (yet) to force another relocations to be emitted. */
6473 /* Now for some ELF specific code. FIXME. */
6475 /* Mark the end of a function so that it's possible to compute
6476 the size of the function in hppa_elf_final_processing. */
6479 hppa_elf_mark_end_of_function ()
6481 /* ELF does not have EXIT relocations. All we do is create a
6482 temporary symbol marking the end of the function. */
6483 char *name
= (char *)
6484 xmalloc (strlen ("L$\001end_") +
6485 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6491 strcpy (name
, "L$\001end_");
6492 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6494 /* If we have a .exit followed by a .procend, then the
6495 symbol will have already been defined. */
6496 symbolP
= symbol_find (name
);
6499 /* The symbol has already been defined! This can
6500 happen if we have a .exit followed by a .procend.
6502 This is *not* an error. All we want to do is free
6503 the memory we just allocated for the name and continue. */
6508 /* symbol value should be the offset of the
6509 last instruction of the function */
6510 symbolP
= symbol_new (name
, now_seg
, (valueT
) (frag_now_fix () - 4),
6514 symbolP
->bsym
->flags
= BSF_LOCAL
;
6515 symbol_table_insert (symbolP
);
6519 last_call_info
->end_symbol
= symbolP
;
6521 as_bad ("Symbol '%s' could not be created.", name
);
6525 as_bad ("No memory for symbol name.");
6529 /* For ELF, this function serves one purpose: to setup the st_size
6530 field of STT_FUNC symbols. To do this, we need to scan the
6531 call_info structure list, determining st_size in by taking the
6532 difference in the address of the beginning/end marker symbols. */
6535 elf_hppa_final_processing ()
6537 struct call_info
*call_info_pointer
;
6539 for (call_info_pointer
= call_info_root
;
6541 call_info_pointer
= call_info_pointer
->ci_next
)
6543 elf_symbol_type
*esym
6544 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6545 esym
->internal_elf_sym
.st_size
=
6546 S_GET_VALUE (call_info_pointer
->end_symbol
)
6547 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;