1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
34 - labels are wrong if automatic alignment is introduced
35 (e.g., checkout the second real10 definition in test-data.s)
37 <reg>.safe_across_calls and any other DV-related directives I don't
38 have documentation for.
39 verify mod-sched-brs reads/writes are checked/marked (and other
45 #include "safe-ctype.h"
46 #include "dwarf2dbg.h"
49 #include "opcode/ia64.h"
53 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
54 #define MIN(a,b) ((a) < (b) ? (a) : (b))
57 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
58 #define CURR_SLOT md.slot[md.curr_slot]
60 #define O_pseudo_fixup (O_max + 1)
64 /* IA-64 ABI section pseudo-ops. */
65 SPECIAL_SECTION_BSS = 0,
67 SPECIAL_SECTION_SDATA,
68 SPECIAL_SECTION_RODATA,
69 SPECIAL_SECTION_COMMENT,
70 SPECIAL_SECTION_UNWIND,
71 SPECIAL_SECTION_UNWIND_INFO,
72 /* HPUX specific section pseudo-ops. */
73 SPECIAL_SECTION_INIT_ARRAY,
74 SPECIAL_SECTION_FINI_ARRAY,
91 FUNC_LT_FPTR_RELATIVE,
101 REG_FR = (REG_GR + 128),
102 REG_AR = (REG_FR + 128),
103 REG_CR = (REG_AR + 128),
104 REG_P = (REG_CR + 128),
105 REG_BR = (REG_P + 64),
106 REG_IP = (REG_BR + 8),
113 /* The following are pseudo-registers for use by gas only. */
125 /* The following pseudo-registers are used for unwind directives only: */
133 DYNREG_GR = 0, /* dynamic general purpose register */
134 DYNREG_FR, /* dynamic floating point register */
135 DYNREG_PR, /* dynamic predicate register */
139 enum operand_match_result
142 OPERAND_OUT_OF_RANGE,
146 /* On the ia64, we can't know the address of a text label until the
147 instructions are packed into a bundle. To handle this, we keep
148 track of the list of labels that appear in front of each
152 struct label_fix *next;
156 extern int target_big_endian;
158 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
160 static void ia64_float_to_chars_bigendian
161 PARAMS ((char *, LITTLENUM_TYPE *, int));
162 static void ia64_float_to_chars_littleendian
163 PARAMS ((char *, LITTLENUM_TYPE *, int));
164 static void (*ia64_float_to_chars)
165 PARAMS ((char *, LITTLENUM_TYPE *, int));
167 static struct hash_control *alias_hash;
168 static struct hash_control *alias_name_hash;
169 static struct hash_control *secalias_hash;
170 static struct hash_control *secalias_name_hash;
172 /* Characters which always start a comment. */
173 const char comment_chars[] = "";
175 /* Characters which start a comment at the beginning of a line. */
176 const char line_comment_chars[] = "#";
178 /* Characters which may be used to separate multiple commands on a
180 const char line_separator_chars[] = ";";
182 /* Characters which are used to indicate an exponent in a floating
184 const char EXP_CHARS[] = "eE";
186 /* Characters which mean that a number is a floating point constant,
188 const char FLT_CHARS[] = "rRsSfFdDxXpP";
190 /* ia64-specific option processing: */
192 const char *md_shortopts = "m:N:x::";
194 struct option md_longopts[] =
196 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
197 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
198 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
199 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
202 size_t md_longopts_size = sizeof (md_longopts);
206 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
207 struct hash_control *reg_hash; /* register name hash table */
208 struct hash_control *dynreg_hash; /* dynamic register hash table */
209 struct hash_control *const_hash; /* constant hash table */
210 struct hash_control *entry_hash; /* code entry hint hash table */
212 symbolS *regsym[REG_NUM];
214 /* If X_op is != O_absent, the registername for the instruction's
215 qualifying predicate. If NULL, p0 is assumed for instructions
216 that are predicatable. */
223 explicit_mode : 1, /* which mode we're in */
224 default_explicit_mode : 1, /* which mode is the default */
225 mode_explicitly_set : 1, /* was the current mode explicitly set? */
227 keep_pending_output : 1;
229 /* Each bundle consists of up to three instructions. We keep
230 track of four most recent instructions so we can correctly set
231 the end_of_insn_group for the last instruction in a bundle. */
233 int num_slots_in_use;
237 end_of_insn_group : 1,
238 manual_bundling_on : 1,
239 manual_bundling_off : 1;
240 signed char user_template; /* user-selected template, if any */
241 unsigned char qp_regno; /* qualifying predicate */
242 /* This duplicates a good fraction of "struct fix" but we
243 can't use a "struct fix" instead since we can't call
244 fix_new_exp() until we know the address of the instruction. */
248 bfd_reloc_code_real_type code;
249 enum ia64_opnd opnd; /* type of operand in need of fix */
250 unsigned int is_pcrel : 1; /* is operand pc-relative? */
251 expressionS expr; /* the value to be inserted */
253 fixup[2]; /* at most two fixups per insn */
254 struct ia64_opcode *idesc;
255 struct label_fix *label_fixups;
256 struct label_fix *tag_fixups;
257 struct unw_rec_list *unwind_record; /* Unwind directive. */
260 unsigned int src_line;
261 struct dwarf2_line_info debug_line;
269 struct dynreg *next; /* next dynamic register */
271 unsigned short base; /* the base register number */
272 unsigned short num_regs; /* # of registers in this set */
274 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
276 flagword flags; /* ELF-header flags */
279 unsigned hint:1; /* is this hint currently valid? */
280 bfd_vma offset; /* mem.offset offset */
281 bfd_vma base; /* mem.offset base */
284 int path; /* number of alt. entry points seen */
285 const char **entry_labels; /* labels of all alternate paths in
286 the current DV-checking block. */
287 int maxpaths; /* size currently allocated for
289 /* Support for hardware errata workarounds. */
291 /* Record data about the last three insn groups. */
294 /* B-step workaround.
295 For each predicate register, this is set if the corresponding insn
296 group conditionally sets this register with one of the affected
299 /* B-step workaround.
300 For each general register, this is set if the corresponding insn
301 a) is conditional one one of the predicate registers for which
302 P_REG_SET is 1 in the corresponding entry of the previous group,
303 b) sets this general register with one of the affected
305 int g_reg_set_conditionally[128];
309 int pointer_size; /* size in bytes of a pointer */
310 int pointer_size_shift; /* shift size of a pointer for alignment */
314 /* application registers: */
320 #define AR_BSPSTORE 18
335 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
336 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
337 {"ar.rsc", 16}, {"ar.bsp", 17},
338 {"ar.bspstore", 18}, {"ar.rnat", 19},
339 {"ar.fcr", 21}, {"ar.eflag", 24},
340 {"ar.csd", 25}, {"ar.ssd", 26},
341 {"ar.cflg", 27}, {"ar.fsr", 28},
342 {"ar.fir", 29}, {"ar.fdr", 30},
343 {"ar.ccv", 32}, {"ar.unat", 36},
344 {"ar.fpsr", 40}, {"ar.itc", 44},
345 {"ar.pfs", 64}, {"ar.lc", 65},
366 /* control registers: */
408 static const struct const_desc
415 /* PSR constant masks: */
418 {"psr.be", ((valueT) 1) << 1},
419 {"psr.up", ((valueT) 1) << 2},
420 {"psr.ac", ((valueT) 1) << 3},
421 {"psr.mfl", ((valueT) 1) << 4},
422 {"psr.mfh", ((valueT) 1) << 5},
424 {"psr.ic", ((valueT) 1) << 13},
425 {"psr.i", ((valueT) 1) << 14},
426 {"psr.pk", ((valueT) 1) << 15},
428 {"psr.dt", ((valueT) 1) << 17},
429 {"psr.dfl", ((valueT) 1) << 18},
430 {"psr.dfh", ((valueT) 1) << 19},
431 {"psr.sp", ((valueT) 1) << 20},
432 {"psr.pp", ((valueT) 1) << 21},
433 {"psr.di", ((valueT) 1) << 22},
434 {"psr.si", ((valueT) 1) << 23},
435 {"psr.db", ((valueT) 1) << 24},
436 {"psr.lp", ((valueT) 1) << 25},
437 {"psr.tb", ((valueT) 1) << 26},
438 {"psr.rt", ((valueT) 1) << 27},
439 /* 28-31: reserved */
440 /* 32-33: cpl (current privilege level) */
441 {"psr.is", ((valueT) 1) << 34},
442 {"psr.mc", ((valueT) 1) << 35},
443 {"psr.it", ((valueT) 1) << 36},
444 {"psr.id", ((valueT) 1) << 37},
445 {"psr.da", ((valueT) 1) << 38},
446 {"psr.dd", ((valueT) 1) << 39},
447 {"psr.ss", ((valueT) 1) << 40},
448 /* 41-42: ri (restart instruction) */
449 {"psr.ed", ((valueT) 1) << 43},
450 {"psr.bn", ((valueT) 1) << 44},
453 /* indirect register-sets/memory: */
462 { "CPUID", IND_CPUID },
463 { "cpuid", IND_CPUID },
475 /* Pseudo functions used to indicate relocation types (these functions
476 start with an at sign (@). */
498 /* reloc pseudo functions (these must come first!): */
499 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
500 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
501 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
502 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
503 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
504 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
505 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
506 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
507 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
508 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
509 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
510 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
511 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
512 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
513 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
514 { "", 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
515 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
517 /* mbtype4 constants: */
518 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
519 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
520 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
521 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
522 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
524 /* fclass constants: */
525 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
526 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
527 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
528 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
529 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
530 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
531 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
532 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
533 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
535 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
537 /* hint constants: */
538 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
540 /* unwind-related constants: */
541 { "svr4", PSEUDO_FUNC_CONST, { 0 } },
542 { "hpux", PSEUDO_FUNC_CONST, { 1 } },
543 { "nt", PSEUDO_FUNC_CONST, { 2 } },
545 /* unwind-related registers: */
546 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
549 /* 41-bit nop opcodes (one per unit): */
550 static const bfd_vma nop[IA64_NUM_UNITS] =
552 0x0000000000LL, /* NIL => break 0 */
553 0x0008000000LL, /* I-unit nop */
554 0x0008000000LL, /* M-unit nop */
555 0x4000000000LL, /* B-unit nop */
556 0x0008000000LL, /* F-unit nop */
557 0x0008000000LL, /* L-"unit" nop */
558 0x0008000000LL, /* X-unit nop */
561 /* Can't be `const' as it's passed to input routines (which have the
562 habit of setting temporary sentinels. */
563 static char special_section_name[][20] =
565 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
566 {".IA_64.unwind"}, {".IA_64.unwind_info"},
567 {".init_array"}, {".fini_array"}
570 static char *special_linkonce_name[] =
572 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
575 /* The best template for a particular sequence of up to three
577 #define N IA64_NUM_TYPES
578 static unsigned char best_template[N][N][N];
581 /* Resource dependencies currently in effect */
583 int depind; /* dependency index */
584 const struct ia64_dependency *dependency; /* actual dependency */
585 unsigned specific:1, /* is this a specific bit/regno? */
586 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
587 int index; /* specific regno/bit within dependency */
588 int note; /* optional qualifying note (0 if none) */
592 int insn_srlz; /* current insn serialization state */
593 int data_srlz; /* current data serialization state */
594 int qp_regno; /* qualifying predicate for this usage */
595 char *file; /* what file marked this dependency */
596 unsigned int line; /* what line marked this dependency */
597 struct mem_offset mem_offset; /* optional memory offset hint */
598 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
599 int path; /* corresponding code entry index */
601 static int regdepslen = 0;
602 static int regdepstotlen = 0;
603 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
604 static const char *dv_sem[] = { "none", "implied", "impliedf",
605 "data", "instr", "specific", "stop", "other" };
606 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
608 /* Current state of PR mutexation */
609 static struct qpmutex {
612 } *qp_mutexes = NULL; /* QP mutex bitmasks */
613 static int qp_mutexeslen = 0;
614 static int qp_mutexestotlen = 0;
615 static valueT qp_safe_across_calls = 0;
617 /* Current state of PR implications */
618 static struct qp_imply {
621 unsigned p2_branched:1;
623 } *qp_implies = NULL;
624 static int qp_implieslen = 0;
625 static int qp_impliestotlen = 0;
627 /* Keep track of static GR values so that indirect register usage can
628 sometimes be tracked. */
633 } gr_values[128] = {{ 1, 0, 0 }};
635 /* These are the routines required to output the various types of
638 /* A slot_number is a frag address plus the slot index (0-2). We use the
639 frag address here so that if there is a section switch in the middle of
640 a function, then instructions emitted to a different section are not
641 counted. Since there may be more than one frag for a function, this
642 means we also need to keep track of which frag this address belongs to
643 so we can compute inter-frag distances. This also nicely solves the
644 problem with nops emitted for align directives, which can't easily be
645 counted, but can easily be derived from frag sizes. */
647 typedef struct unw_rec_list {
649 unsigned long slot_number;
651 struct unw_rec_list *next;
654 #define SLOT_NUM_NOT_SET (unsigned)-1
656 /* Linked list of saved prologue counts. A very poor
657 implementation of a map from label numbers to prologue counts. */
658 typedef struct label_prologue_count
660 struct label_prologue_count *next;
661 unsigned long label_number;
662 unsigned int prologue_count;
663 } label_prologue_count;
667 unsigned long next_slot_number;
668 fragS *next_slot_frag;
670 /* Maintain a list of unwind entries for the current function. */
674 /* Any unwind entires that should be attached to the current slot
675 that an insn is being constructed for. */
676 unw_rec_list *current_entry;
678 /* These are used to create the unwind table entry for this function. */
681 symbolS *info; /* pointer to unwind info */
682 symbolS *personality_routine;
684 subsegT saved_text_subseg;
685 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
687 /* TRUE if processing unwind directives in a prologue region. */
690 unsigned int prologue_count; /* number of .prologues seen so far */
691 /* Prologue counts at previous .label_state directives. */
692 struct label_prologue_count * saved_prologue_counts;
695 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
697 /* Forward delarations: */
698 static int ar_is_in_integer_unit PARAMS ((int regnum));
699 static void set_section PARAMS ((char *name));
700 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
701 unsigned int, unsigned int));
702 static void dot_radix PARAMS ((int));
703 static void dot_special_section PARAMS ((int));
704 static void dot_proc PARAMS ((int));
705 static void dot_fframe PARAMS ((int));
706 static void dot_vframe PARAMS ((int));
707 static void dot_vframesp PARAMS ((int));
708 static void dot_vframepsp PARAMS ((int));
709 static void dot_save PARAMS ((int));
710 static void dot_restore PARAMS ((int));
711 static void dot_restorereg PARAMS ((int));
712 static void dot_restorereg_p PARAMS ((int));
713 static void dot_handlerdata PARAMS ((int));
714 static void dot_unwentry PARAMS ((int));
715 static void dot_altrp PARAMS ((int));
716 static void dot_savemem PARAMS ((int));
717 static void dot_saveg PARAMS ((int));
718 static void dot_savef PARAMS ((int));
719 static void dot_saveb PARAMS ((int));
720 static void dot_savegf PARAMS ((int));
721 static void dot_spill PARAMS ((int));
722 static void dot_spillreg PARAMS ((int));
723 static void dot_spillmem PARAMS ((int));
724 static void dot_spillreg_p PARAMS ((int));
725 static void dot_spillmem_p PARAMS ((int));
726 static void dot_label_state PARAMS ((int));
727 static void dot_copy_state PARAMS ((int));
728 static void dot_unwabi PARAMS ((int));
729 static void dot_personality PARAMS ((int));
730 static void dot_body PARAMS ((int));
731 static void dot_prologue PARAMS ((int));
732 static void dot_endp PARAMS ((int));
733 static void dot_template PARAMS ((int));
734 static void dot_regstk PARAMS ((int));
735 static void dot_rot PARAMS ((int));
736 static void dot_byteorder PARAMS ((int));
737 static void dot_psr PARAMS ((int));
738 static void dot_alias PARAMS ((int));
739 static void dot_ln PARAMS ((int));
740 static char *parse_section_name PARAMS ((void));
741 static void dot_xdata PARAMS ((int));
742 static void stmt_float_cons PARAMS ((int));
743 static void stmt_cons_ua PARAMS ((int));
744 static void dot_xfloat_cons PARAMS ((int));
745 static void dot_xstringer PARAMS ((int));
746 static void dot_xdata_ua PARAMS ((int));
747 static void dot_xfloat_cons_ua PARAMS ((int));
748 static void print_prmask PARAMS ((valueT mask));
749 static void dot_pred_rel PARAMS ((int));
750 static void dot_reg_val PARAMS ((int));
751 static void dot_dv_mode PARAMS ((int));
752 static void dot_entry PARAMS ((int));
753 static void dot_mem_offset PARAMS ((int));
754 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
755 static symbolS *declare_register PARAMS ((const char *name, int regnum));
756 static void declare_register_set PARAMS ((const char *, int, int));
757 static unsigned int operand_width PARAMS ((enum ia64_opnd));
758 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
761 static int parse_operand PARAMS ((expressionS *e));
762 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
763 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
764 static void build_insn PARAMS ((struct slot *, bfd_vma *));
765 static void emit_one_bundle PARAMS ((void));
766 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
767 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
768 bfd_reloc_code_real_type r_type));
769 static void insn_group_break PARAMS ((int, int, int));
770 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
771 struct rsrc *, int depind, int path));
772 static void add_qp_mutex PARAMS((valueT mask));
773 static void add_qp_imply PARAMS((int p1, int p2));
774 static void clear_qp_branch_flag PARAMS((valueT mask));
775 static void clear_qp_mutex PARAMS((valueT mask));
776 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
777 static int has_suffix_p PARAMS((const char *, const char *));
778 static void clear_register_values PARAMS ((void));
779 static void print_dependency PARAMS ((const char *action, int depind));
780 static void instruction_serialization PARAMS ((void));
781 static void data_serialization PARAMS ((void));
782 static void remove_marked_resource PARAMS ((struct rsrc *));
783 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
784 static int is_taken_branch PARAMS ((struct ia64_opcode *));
785 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
786 static int depends_on PARAMS ((int, struct ia64_opcode *));
787 static int specify_resource PARAMS ((const struct ia64_dependency *,
788 struct ia64_opcode *, int, struct rsrc [], int, int));
789 static int check_dv PARAMS((struct ia64_opcode *idesc));
790 static void check_dependencies PARAMS((struct ia64_opcode *));
791 static void mark_resources PARAMS((struct ia64_opcode *));
792 static void update_dependencies PARAMS((struct ia64_opcode *));
793 static void note_register_values PARAMS((struct ia64_opcode *));
794 static int qp_mutex PARAMS ((int, int, int));
795 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
796 static void output_vbyte_mem PARAMS ((int, char *, char *));
797 static void count_output PARAMS ((int, char *, char *));
798 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
799 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
800 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
801 static void output_P1_format PARAMS ((vbyte_func, int));
802 static void output_P2_format PARAMS ((vbyte_func, int, int));
803 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
804 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
805 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
806 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
807 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
808 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
809 static void output_P9_format PARAMS ((vbyte_func, int, int));
810 static void output_P10_format PARAMS ((vbyte_func, int, int));
811 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
812 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
813 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
814 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
815 static char format_ab_reg PARAMS ((int, int));
816 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
818 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
819 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
821 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
822 static void free_list_records PARAMS ((unw_rec_list *));
823 static unw_rec_list *output_prologue PARAMS ((void));
824 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
825 static unw_rec_list *output_body PARAMS ((void));
826 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
827 static unw_rec_list *output_mem_stack_v PARAMS ((void));
828 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
829 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
830 static unw_rec_list *output_rp_when PARAMS ((void));
831 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
832 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
833 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
834 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
835 static unw_rec_list *output_pfs_when PARAMS ((void));
836 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
837 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
838 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
839 static unw_rec_list *output_preds_when PARAMS ((void));
840 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
841 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
842 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
843 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
844 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
845 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
846 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
847 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
848 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
849 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
850 static unw_rec_list *output_unat_when PARAMS ((void));
851 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
852 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
853 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
854 static unw_rec_list *output_lc_when PARAMS ((void));
855 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
856 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
857 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
858 static unw_rec_list *output_fpsr_when PARAMS ((void));
859 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
860 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
861 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
862 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
863 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
864 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
865 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
866 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
867 static unw_rec_list *output_bsp_when PARAMS ((void));
868 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
869 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
870 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
871 static unw_rec_list *output_bspstore_when PARAMS ((void));
872 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
873 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
874 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
875 static unw_rec_list *output_rnat_when PARAMS ((void));
876 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
877 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
878 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
879 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
880 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
881 static unw_rec_list *output_label_state PARAMS ((unsigned long));
882 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
883 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
884 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
885 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
887 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
889 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
891 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
892 unsigned int, unsigned int));
893 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
894 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
895 static int calc_record_size PARAMS ((unw_rec_list *));
896 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
897 static int count_bits PARAMS ((unsigned long));
898 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
899 unsigned long, fragS *));
900 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
901 static void fixup_unw_records PARAMS ((unw_rec_list *));
902 static int output_unw_records PARAMS ((unw_rec_list *, void **));
903 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
904 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
905 static int generate_unwind_image PARAMS ((const char *));
906 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
907 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
908 static void free_saved_prologue_counts PARAMS ((void));
910 /* Build the unwind section name by appending the (possibly stripped)
911 text section NAME to the unwind PREFIX. The resulting string
912 pointer is assigned to RESULT. The string is allocated on the
913 stack, so this must be a macro... */
914 #define make_unw_section_name(special, text_name, result) \
916 const char *_prefix = special_section_name[special]; \
917 const char *_suffix = text_name; \
918 size_t _prefix_len, _suffix_len; \
920 if (strncmp (text_name, ".gnu.linkonce.t.", \
921 sizeof (".gnu.linkonce.t.") - 1) == 0) \
923 _prefix = special_linkonce_name[special - SPECIAL_SECTION_UNWIND]; \
924 _suffix += sizeof (".gnu.linkonce.t.") - 1; \
926 _prefix_len = strlen (_prefix), _suffix_len = strlen (_suffix); \
927 _result = alloca (_prefix_len + _suffix_len + 1); \
928 memcpy (_result, _prefix, _prefix_len); \
929 memcpy (_result + _prefix_len, _suffix, _suffix_len); \
930 _result[_prefix_len + _suffix_len] = '\0'; \
935 /* Determine if application register REGNUM resides in the integer
936 unit (as opposed to the memory unit). */
938 ar_is_in_integer_unit (reg)
943 return (reg == 64 /* pfs */
944 || reg == 65 /* lc */
945 || reg == 66 /* ec */
946 /* ??? ias accepts and puts these in the integer unit. */
947 || (reg >= 112 && reg <= 127));
950 /* Switch to section NAME and create section if necessary. It's
951 rather ugly that we have to manipulate input_line_pointer but I
952 don't see any other way to accomplish the same thing without
953 changing obj-elf.c (which may be the Right Thing, in the end). */
958 char *saved_input_line_pointer;
960 saved_input_line_pointer = input_line_pointer;
961 input_line_pointer = name;
963 input_line_pointer = saved_input_line_pointer;
966 /* Map 's' to SHF_IA_64_SHORT. */
969 ia64_elf_section_letter (letter, ptr_msg)
974 return SHF_IA_64_SHORT;
975 else if (letter == 'o')
976 return SHF_LINK_ORDER;
978 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
982 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
985 ia64_elf_section_flags (flags, attr, type)
987 int attr, type ATTRIBUTE_UNUSED;
989 if (attr & SHF_IA_64_SHORT)
990 flags |= SEC_SMALL_DATA;
995 ia64_elf_section_type (str, len)
999 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
1001 if (STREQ (ELF_STRING_ia64_unwind_info))
1002 return SHT_PROGBITS;
1004 if (STREQ (ELF_STRING_ia64_unwind_info_once))
1005 return SHT_PROGBITS;
1007 if (STREQ (ELF_STRING_ia64_unwind))
1008 return SHT_IA_64_UNWIND;
1010 if (STREQ (ELF_STRING_ia64_unwind_once))
1011 return SHT_IA_64_UNWIND;
1013 if (STREQ ("unwind"))
1014 return SHT_IA_64_UNWIND;
1016 if (STREQ ("init_array"))
1017 return SHT_INIT_ARRAY;
1019 if (STREQ ("fini_array"))
1020 return SHT_FINI_ARRAY;
1027 set_regstack (ins, locs, outs, rots)
1028 unsigned int ins, locs, outs, rots;
1030 /* Size of frame. */
1033 sof = ins + locs + outs;
1036 as_bad ("Size of frame exceeds maximum of 96 registers");
1041 as_warn ("Size of rotating registers exceeds frame size");
1044 md.in.base = REG_GR + 32;
1045 md.loc.base = md.in.base + ins;
1046 md.out.base = md.loc.base + locs;
1048 md.in.num_regs = ins;
1049 md.loc.num_regs = locs;
1050 md.out.num_regs = outs;
1051 md.rot.num_regs = rots;
1058 struct label_fix *lfix;
1060 subsegT saved_subseg;
1063 if (!md.last_text_seg)
1066 saved_seg = now_seg;
1067 saved_subseg = now_subseg;
1069 subseg_set (md.last_text_seg, 0);
1071 while (md.num_slots_in_use > 0)
1072 emit_one_bundle (); /* force out queued instructions */
1074 /* In case there are labels following the last instruction, resolve
1076 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1078 S_SET_VALUE (lfix->sym, frag_now_fix ());
1079 symbol_set_frag (lfix->sym, frag_now);
1081 CURR_SLOT.label_fixups = 0;
1082 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1084 S_SET_VALUE (lfix->sym, frag_now_fix ());
1085 symbol_set_frag (lfix->sym, frag_now);
1087 CURR_SLOT.tag_fixups = 0;
1089 /* In case there are unwind directives following the last instruction,
1090 resolve those now. We only handle body and prologue directives here.
1091 Give an error for others. */
1092 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1094 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
1095 || ptr->r.type == body)
1097 ptr->slot_number = (unsigned long) frag_more (0);
1098 ptr->slot_frag = frag_now;
1101 as_bad (_("Unwind directive not followed by an instruction."));
1103 unwind.current_entry = NULL;
1105 subseg_set (saved_seg, saved_subseg);
1107 if (md.qp.X_op == O_register)
1108 as_bad ("qualifying predicate not followed by instruction");
1112 ia64_do_align (nbytes)
1115 char *saved_input_line_pointer = input_line_pointer;
1117 input_line_pointer = "";
1118 s_align_bytes (nbytes);
1119 input_line_pointer = saved_input_line_pointer;
1123 ia64_cons_align (nbytes)
1128 char *saved_input_line_pointer = input_line_pointer;
1129 input_line_pointer = "";
1130 s_align_bytes (nbytes);
1131 input_line_pointer = saved_input_line_pointer;
1135 /* Output COUNT bytes to a memory location. */
1136 static unsigned char *vbyte_mem_ptr = NULL;
1139 output_vbyte_mem (count, ptr, comment)
1142 char *comment ATTRIBUTE_UNUSED;
1145 if (vbyte_mem_ptr == NULL)
1150 for (x = 0; x < count; x++)
1151 *(vbyte_mem_ptr++) = ptr[x];
1154 /* Count the number of bytes required for records. */
1155 static int vbyte_count = 0;
1157 count_output (count, ptr, comment)
1159 char *ptr ATTRIBUTE_UNUSED;
1160 char *comment ATTRIBUTE_UNUSED;
1162 vbyte_count += count;
1166 output_R1_format (f, rtype, rlen)
1168 unw_record_type rtype;
1175 output_R3_format (f, rtype, rlen);
1181 else if (rtype != prologue)
1182 as_bad ("record type is not valid");
1184 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1185 (*f) (1, &byte, NULL);
1189 output_R2_format (f, mask, grsave, rlen)
1196 mask = (mask & 0x0f);
1197 grsave = (grsave & 0x7f);
1199 bytes[0] = (UNW_R2 | (mask >> 1));
1200 bytes[1] = (((mask & 0x01) << 7) | grsave);
1201 count += output_leb128 (bytes + 2, rlen, 0);
1202 (*f) (count, bytes, NULL);
1206 output_R3_format (f, rtype, rlen)
1208 unw_record_type rtype;
1215 output_R1_format (f, rtype, rlen);
1221 else if (rtype != prologue)
1222 as_bad ("record type is not valid");
1223 bytes[0] = (UNW_R3 | r);
1224 count = output_leb128 (bytes + 1, rlen, 0);
1225 (*f) (count + 1, bytes, NULL);
1229 output_P1_format (f, brmask)
1234 byte = UNW_P1 | (brmask & 0x1f);
1235 (*f) (1, &byte, NULL);
1239 output_P2_format (f, brmask, gr)
1245 brmask = (brmask & 0x1f);
1246 bytes[0] = UNW_P2 | (brmask >> 1);
1247 bytes[1] = (((brmask & 1) << 7) | gr);
1248 (*f) (2, bytes, NULL);
1252 output_P3_format (f, rtype, reg)
1254 unw_record_type rtype;
1299 as_bad ("Invalid record type for P3 format.");
1301 bytes[0] = (UNW_P3 | (r >> 1));
1302 bytes[1] = (((r & 1) << 7) | reg);
1303 (*f) (2, bytes, NULL);
1307 output_P4_format (f, imask, imask_size)
1309 unsigned char *imask;
1310 unsigned long imask_size;
1313 (*f) (imask_size, imask, NULL);
1317 output_P5_format (f, grmask, frmask)
1320 unsigned long frmask;
1323 grmask = (grmask & 0x0f);
1326 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1327 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1328 bytes[3] = (frmask & 0x000000ff);
1329 (*f) (4, bytes, NULL);
1333 output_P6_format (f, rtype, rmask)
1335 unw_record_type rtype;
1341 if (rtype == gr_mem)
1343 else if (rtype != fr_mem)
1344 as_bad ("Invalid record type for format P6");
1345 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1346 (*f) (1, &byte, NULL);
1350 output_P7_format (f, rtype, w1, w2)
1352 unw_record_type rtype;
1359 count += output_leb128 (bytes + 1, w1, 0);
1364 count += output_leb128 (bytes + count, w2 >> 4, 0);
1414 bytes[0] = (UNW_P7 | r);
1415 (*f) (count, bytes, NULL);
1419 output_P8_format (f, rtype, t)
1421 unw_record_type rtype;
1460 case bspstore_psprel:
1463 case bspstore_sprel:
1475 case priunat_when_gr:
1478 case priunat_psprel:
1484 case priunat_when_mem:
1491 count += output_leb128 (bytes + 2, t, 0);
1492 (*f) (count, bytes, NULL);
1496 output_P9_format (f, grmask, gr)
1503 bytes[1] = (grmask & 0x0f);
1504 bytes[2] = (gr & 0x7f);
1505 (*f) (3, bytes, NULL);
1509 output_P10_format (f, abi, context)
1516 bytes[1] = (abi & 0xff);
1517 bytes[2] = (context & 0xff);
1518 (*f) (3, bytes, NULL);
1522 output_B1_format (f, rtype, label)
1524 unw_record_type rtype;
1525 unsigned long label;
1531 output_B4_format (f, rtype, label);
1534 if (rtype == copy_state)
1536 else if (rtype != label_state)
1537 as_bad ("Invalid record type for format B1");
1539 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1540 (*f) (1, &byte, NULL);
1544 output_B2_format (f, ecount, t)
1546 unsigned long ecount;
1553 output_B3_format (f, ecount, t);
1556 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1557 count += output_leb128 (bytes + 1, t, 0);
1558 (*f) (count, bytes, NULL);
1562 output_B3_format (f, ecount, t)
1564 unsigned long ecount;
1571 output_B2_format (f, ecount, t);
1575 count += output_leb128 (bytes + 1, t, 0);
1576 count += output_leb128 (bytes + count, ecount, 0);
1577 (*f) (count, bytes, NULL);
1581 output_B4_format (f, rtype, label)
1583 unw_record_type rtype;
1584 unsigned long label;
1591 output_B1_format (f, rtype, label);
1595 if (rtype == copy_state)
1597 else if (rtype != label_state)
1598 as_bad ("Invalid record type for format B1");
1600 bytes[0] = (UNW_B4 | (r << 3));
1601 count += output_leb128 (bytes + 1, label, 0);
1602 (*f) (count, bytes, NULL);
1606 format_ab_reg (ab, reg)
1613 ret = (ab << 5) | reg;
1618 output_X1_format (f, rtype, ab, reg, t, w1)
1620 unw_record_type rtype;
1630 if (rtype == spill_sprel)
1632 else if (rtype != spill_psprel)
1633 as_bad ("Invalid record type for format X1");
1634 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1635 count += output_leb128 (bytes + 2, t, 0);
1636 count += output_leb128 (bytes + count, w1, 0);
1637 (*f) (count, bytes, NULL);
1641 output_X2_format (f, ab, reg, x, y, treg, t)
1650 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1651 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1652 count += output_leb128 (bytes + 3, t, 0);
1653 (*f) (count, bytes, NULL);
1657 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1659 unw_record_type rtype;
1670 if (rtype == spill_sprel_p)
1672 else if (rtype != spill_psprel_p)
1673 as_bad ("Invalid record type for format X3");
1674 bytes[1] = ((r << 7) | (qp & 0x3f));
1675 bytes[2] = format_ab_reg (ab, reg);
1676 count += output_leb128 (bytes + 3, t, 0);
1677 count += output_leb128 (bytes + count, w1, 0);
1678 (*f) (count, bytes, NULL);
1682 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1692 bytes[1] = (qp & 0x3f);
1693 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1694 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1695 count += output_leb128 (bytes + 4, t, 0);
1696 (*f) (count, bytes, NULL);
1699 /* This function allocates a record list structure, and initializes fields. */
1701 static unw_rec_list *
1702 alloc_record (unw_record_type t)
1705 ptr = xmalloc (sizeof (*ptr));
1707 ptr->slot_number = SLOT_NUM_NOT_SET;
1712 /* This function frees an entire list of record structures. */
1715 free_list_records (unw_rec_list *first)
1718 for (ptr = first; ptr != NULL;)
1720 unw_rec_list *tmp = ptr;
1722 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1723 && tmp->r.record.r.mask.i)
1724 free (tmp->r.record.r.mask.i);
1731 static unw_rec_list *
1734 unw_rec_list *ptr = alloc_record (prologue);
1735 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1739 static unw_rec_list *
1740 output_prologue_gr (saved_mask, reg)
1741 unsigned int saved_mask;
1744 unw_rec_list *ptr = alloc_record (prologue_gr);
1745 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1746 ptr->r.record.r.grmask = saved_mask;
1747 ptr->r.record.r.grsave = reg;
1751 static unw_rec_list *
1754 unw_rec_list *ptr = alloc_record (body);
1758 static unw_rec_list *
1759 output_mem_stack_f (size)
1762 unw_rec_list *ptr = alloc_record (mem_stack_f);
1763 ptr->r.record.p.size = size;
1767 static unw_rec_list *
1768 output_mem_stack_v ()
1770 unw_rec_list *ptr = alloc_record (mem_stack_v);
1774 static unw_rec_list *
1778 unw_rec_list *ptr = alloc_record (psp_gr);
1779 ptr->r.record.p.gr = gr;
1783 static unw_rec_list *
1784 output_psp_sprel (offset)
1785 unsigned int offset;
1787 unw_rec_list *ptr = alloc_record (psp_sprel);
1788 ptr->r.record.p.spoff = offset / 4;
1792 static unw_rec_list *
1795 unw_rec_list *ptr = alloc_record (rp_when);
1799 static unw_rec_list *
1803 unw_rec_list *ptr = alloc_record (rp_gr);
1804 ptr->r.record.p.gr = gr;
1808 static unw_rec_list *
1812 unw_rec_list *ptr = alloc_record (rp_br);
1813 ptr->r.record.p.br = br;
1817 static unw_rec_list *
1818 output_rp_psprel (offset)
1819 unsigned int offset;
1821 unw_rec_list *ptr = alloc_record (rp_psprel);
1822 ptr->r.record.p.pspoff = offset / 4;
1826 static unw_rec_list *
1827 output_rp_sprel (offset)
1828 unsigned int offset;
1830 unw_rec_list *ptr = alloc_record (rp_sprel);
1831 ptr->r.record.p.spoff = offset / 4;
1835 static unw_rec_list *
1838 unw_rec_list *ptr = alloc_record (pfs_when);
1842 static unw_rec_list *
1846 unw_rec_list *ptr = alloc_record (pfs_gr);
1847 ptr->r.record.p.gr = gr;
1851 static unw_rec_list *
1852 output_pfs_psprel (offset)
1853 unsigned int offset;
1855 unw_rec_list *ptr = alloc_record (pfs_psprel);
1856 ptr->r.record.p.pspoff = offset / 4;
1860 static unw_rec_list *
1861 output_pfs_sprel (offset)
1862 unsigned int offset;
1864 unw_rec_list *ptr = alloc_record (pfs_sprel);
1865 ptr->r.record.p.spoff = offset / 4;
1869 static unw_rec_list *
1870 output_preds_when ()
1872 unw_rec_list *ptr = alloc_record (preds_when);
1876 static unw_rec_list *
1877 output_preds_gr (gr)
1880 unw_rec_list *ptr = alloc_record (preds_gr);
1881 ptr->r.record.p.gr = gr;
1885 static unw_rec_list *
1886 output_preds_psprel (offset)
1887 unsigned int offset;
1889 unw_rec_list *ptr = alloc_record (preds_psprel);
1890 ptr->r.record.p.pspoff = offset / 4;
1894 static unw_rec_list *
1895 output_preds_sprel (offset)
1896 unsigned int offset;
1898 unw_rec_list *ptr = alloc_record (preds_sprel);
1899 ptr->r.record.p.spoff = offset / 4;
1903 static unw_rec_list *
1904 output_fr_mem (mask)
1907 unw_rec_list *ptr = alloc_record (fr_mem);
1908 ptr->r.record.p.rmask = mask;
1912 static unw_rec_list *
1913 output_frgr_mem (gr_mask, fr_mask)
1914 unsigned int gr_mask;
1915 unsigned int fr_mask;
1917 unw_rec_list *ptr = alloc_record (frgr_mem);
1918 ptr->r.record.p.grmask = gr_mask;
1919 ptr->r.record.p.frmask = fr_mask;
1923 static unw_rec_list *
1924 output_gr_gr (mask, reg)
1928 unw_rec_list *ptr = alloc_record (gr_gr);
1929 ptr->r.record.p.grmask = mask;
1930 ptr->r.record.p.gr = reg;
1934 static unw_rec_list *
1935 output_gr_mem (mask)
1938 unw_rec_list *ptr = alloc_record (gr_mem);
1939 ptr->r.record.p.rmask = mask;
1943 static unw_rec_list *
1944 output_br_mem (unsigned int mask)
1946 unw_rec_list *ptr = alloc_record (br_mem);
1947 ptr->r.record.p.brmask = mask;
1951 static unw_rec_list *
1952 output_br_gr (save_mask, reg)
1953 unsigned int save_mask;
1956 unw_rec_list *ptr = alloc_record (br_gr);
1957 ptr->r.record.p.brmask = save_mask;
1958 ptr->r.record.p.gr = reg;
1962 static unw_rec_list *
1963 output_spill_base (offset)
1964 unsigned int offset;
1966 unw_rec_list *ptr = alloc_record (spill_base);
1967 ptr->r.record.p.pspoff = offset / 4;
1971 static unw_rec_list *
1974 unw_rec_list *ptr = alloc_record (unat_when);
1978 static unw_rec_list *
1982 unw_rec_list *ptr = alloc_record (unat_gr);
1983 ptr->r.record.p.gr = gr;
1987 static unw_rec_list *
1988 output_unat_psprel (offset)
1989 unsigned int offset;
1991 unw_rec_list *ptr = alloc_record (unat_psprel);
1992 ptr->r.record.p.pspoff = offset / 4;
1996 static unw_rec_list *
1997 output_unat_sprel (offset)
1998 unsigned int offset;
2000 unw_rec_list *ptr = alloc_record (unat_sprel);
2001 ptr->r.record.p.spoff = offset / 4;
2005 static unw_rec_list *
2008 unw_rec_list *ptr = alloc_record (lc_when);
2012 static unw_rec_list *
2016 unw_rec_list *ptr = alloc_record (lc_gr);
2017 ptr->r.record.p.gr = gr;
2021 static unw_rec_list *
2022 output_lc_psprel (offset)
2023 unsigned int offset;
2025 unw_rec_list *ptr = alloc_record (lc_psprel);
2026 ptr->r.record.p.pspoff = offset / 4;
2030 static unw_rec_list *
2031 output_lc_sprel (offset)
2032 unsigned int offset;
2034 unw_rec_list *ptr = alloc_record (lc_sprel);
2035 ptr->r.record.p.spoff = offset / 4;
2039 static unw_rec_list *
2042 unw_rec_list *ptr = alloc_record (fpsr_when);
2046 static unw_rec_list *
2050 unw_rec_list *ptr = alloc_record (fpsr_gr);
2051 ptr->r.record.p.gr = gr;
2055 static unw_rec_list *
2056 output_fpsr_psprel (offset)
2057 unsigned int offset;
2059 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2060 ptr->r.record.p.pspoff = offset / 4;
2064 static unw_rec_list *
2065 output_fpsr_sprel (offset)
2066 unsigned int offset;
2068 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2069 ptr->r.record.p.spoff = offset / 4;
2073 static unw_rec_list *
2074 output_priunat_when_gr ()
2076 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2080 static unw_rec_list *
2081 output_priunat_when_mem ()
2083 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2087 static unw_rec_list *
2088 output_priunat_gr (gr)
2091 unw_rec_list *ptr = alloc_record (priunat_gr);
2092 ptr->r.record.p.gr = gr;
2096 static unw_rec_list *
2097 output_priunat_psprel (offset)
2098 unsigned int offset;
2100 unw_rec_list *ptr = alloc_record (priunat_psprel);
2101 ptr->r.record.p.pspoff = offset / 4;
2105 static unw_rec_list *
2106 output_priunat_sprel (offset)
2107 unsigned int offset;
2109 unw_rec_list *ptr = alloc_record (priunat_sprel);
2110 ptr->r.record.p.spoff = offset / 4;
2114 static unw_rec_list *
2117 unw_rec_list *ptr = alloc_record (bsp_when);
2121 static unw_rec_list *
2125 unw_rec_list *ptr = alloc_record (bsp_gr);
2126 ptr->r.record.p.gr = gr;
2130 static unw_rec_list *
2131 output_bsp_psprel (offset)
2132 unsigned int offset;
2134 unw_rec_list *ptr = alloc_record (bsp_psprel);
2135 ptr->r.record.p.pspoff = offset / 4;
2139 static unw_rec_list *
2140 output_bsp_sprel (offset)
2141 unsigned int offset;
2143 unw_rec_list *ptr = alloc_record (bsp_sprel);
2144 ptr->r.record.p.spoff = offset / 4;
2148 static unw_rec_list *
2149 output_bspstore_when ()
2151 unw_rec_list *ptr = alloc_record (bspstore_when);
2155 static unw_rec_list *
2156 output_bspstore_gr (gr)
2159 unw_rec_list *ptr = alloc_record (bspstore_gr);
2160 ptr->r.record.p.gr = gr;
2164 static unw_rec_list *
2165 output_bspstore_psprel (offset)
2166 unsigned int offset;
2168 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2169 ptr->r.record.p.pspoff = offset / 4;
2173 static unw_rec_list *
2174 output_bspstore_sprel (offset)
2175 unsigned int offset;
2177 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2178 ptr->r.record.p.spoff = offset / 4;
2182 static unw_rec_list *
2185 unw_rec_list *ptr = alloc_record (rnat_when);
2189 static unw_rec_list *
2193 unw_rec_list *ptr = alloc_record (rnat_gr);
2194 ptr->r.record.p.gr = gr;
2198 static unw_rec_list *
2199 output_rnat_psprel (offset)
2200 unsigned int offset;
2202 unw_rec_list *ptr = alloc_record (rnat_psprel);
2203 ptr->r.record.p.pspoff = offset / 4;
2207 static unw_rec_list *
2208 output_rnat_sprel (offset)
2209 unsigned int offset;
2211 unw_rec_list *ptr = alloc_record (rnat_sprel);
2212 ptr->r.record.p.spoff = offset / 4;
2216 static unw_rec_list *
2217 output_unwabi (abi, context)
2219 unsigned long context;
2221 unw_rec_list *ptr = alloc_record (unwabi);
2222 ptr->r.record.p.abi = abi;
2223 ptr->r.record.p.context = context;
2227 static unw_rec_list *
2228 output_epilogue (unsigned long ecount)
2230 unw_rec_list *ptr = alloc_record (epilogue);
2231 ptr->r.record.b.ecount = ecount;
2235 static unw_rec_list *
2236 output_label_state (unsigned long label)
2238 unw_rec_list *ptr = alloc_record (label_state);
2239 ptr->r.record.b.label = label;
2243 static unw_rec_list *
2244 output_copy_state (unsigned long label)
2246 unw_rec_list *ptr = alloc_record (copy_state);
2247 ptr->r.record.b.label = label;
2251 static unw_rec_list *
2252 output_spill_psprel (ab, reg, offset)
2255 unsigned int offset;
2257 unw_rec_list *ptr = alloc_record (spill_psprel);
2258 ptr->r.record.x.ab = ab;
2259 ptr->r.record.x.reg = reg;
2260 ptr->r.record.x.pspoff = offset / 4;
2264 static unw_rec_list *
2265 output_spill_sprel (ab, reg, offset)
2268 unsigned int offset;
2270 unw_rec_list *ptr = alloc_record (spill_sprel);
2271 ptr->r.record.x.ab = ab;
2272 ptr->r.record.x.reg = reg;
2273 ptr->r.record.x.spoff = offset / 4;
2277 static unw_rec_list *
2278 output_spill_psprel_p (ab, reg, offset, predicate)
2281 unsigned int offset;
2282 unsigned int predicate;
2284 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2285 ptr->r.record.x.ab = ab;
2286 ptr->r.record.x.reg = reg;
2287 ptr->r.record.x.pspoff = offset / 4;
2288 ptr->r.record.x.qp = predicate;
2292 static unw_rec_list *
2293 output_spill_sprel_p (ab, reg, offset, predicate)
2296 unsigned int offset;
2297 unsigned int predicate;
2299 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2300 ptr->r.record.x.ab = ab;
2301 ptr->r.record.x.reg = reg;
2302 ptr->r.record.x.spoff = offset / 4;
2303 ptr->r.record.x.qp = predicate;
2307 static unw_rec_list *
2308 output_spill_reg (ab, reg, targ_reg, xy)
2311 unsigned int targ_reg;
2314 unw_rec_list *ptr = alloc_record (spill_reg);
2315 ptr->r.record.x.ab = ab;
2316 ptr->r.record.x.reg = reg;
2317 ptr->r.record.x.treg = targ_reg;
2318 ptr->r.record.x.xy = xy;
2322 static unw_rec_list *
2323 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2326 unsigned int targ_reg;
2328 unsigned int predicate;
2330 unw_rec_list *ptr = alloc_record (spill_reg_p);
2331 ptr->r.record.x.ab = ab;
2332 ptr->r.record.x.reg = reg;
2333 ptr->r.record.x.treg = targ_reg;
2334 ptr->r.record.x.xy = xy;
2335 ptr->r.record.x.qp = predicate;
2339 /* Given a unw_rec_list process the correct format with the
2340 specified function. */
2343 process_one_record (ptr, f)
2347 unsigned long fr_mask, gr_mask;
2349 switch (ptr->r.type)
2355 /* These are taken care of by prologue/prologue_gr. */
2360 if (ptr->r.type == prologue_gr)
2361 output_R2_format (f, ptr->r.record.r.grmask,
2362 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2364 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2366 /* Output descriptor(s) for union of register spills (if any). */
2367 gr_mask = ptr->r.record.r.mask.gr_mem;
2368 fr_mask = ptr->r.record.r.mask.fr_mem;
2371 if ((fr_mask & ~0xfUL) == 0)
2372 output_P6_format (f, fr_mem, fr_mask);
2375 output_P5_format (f, gr_mask, fr_mask);
2380 output_P6_format (f, gr_mem, gr_mask);
2381 if (ptr->r.record.r.mask.br_mem)
2382 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2384 /* output imask descriptor if necessary: */
2385 if (ptr->r.record.r.mask.i)
2386 output_P4_format (f, ptr->r.record.r.mask.i,
2387 ptr->r.record.r.imask_size);
2391 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2395 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2396 ptr->r.record.p.size);
2409 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2412 output_P3_format (f, rp_br, ptr->r.record.p.br);
2415 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2423 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2432 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2442 case bspstore_sprel:
2444 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2447 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2450 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2453 as_bad ("spill_mask record unimplemented.");
2455 case priunat_when_gr:
2456 case priunat_when_mem:
2460 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2462 case priunat_psprel:
2464 case bspstore_psprel:
2466 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2469 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2472 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2476 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2479 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2480 ptr->r.record.x.reg, ptr->r.record.x.t,
2481 ptr->r.record.x.pspoff);
2484 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2485 ptr->r.record.x.reg, ptr->r.record.x.t,
2486 ptr->r.record.x.spoff);
2489 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2490 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2491 ptr->r.record.x.treg, ptr->r.record.x.t);
2493 case spill_psprel_p:
2494 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2495 ptr->r.record.x.ab, ptr->r.record.x.reg,
2496 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2499 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2500 ptr->r.record.x.ab, ptr->r.record.x.reg,
2501 ptr->r.record.x.t, ptr->r.record.x.spoff);
2504 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2505 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2506 ptr->r.record.x.xy, ptr->r.record.x.treg,
2510 as_bad ("record_type_not_valid");
2515 /* Given a unw_rec_list list, process all the records with
2516 the specified function. */
2518 process_unw_records (list, f)
2523 for (ptr = list; ptr; ptr = ptr->next)
2524 process_one_record (ptr, f);
2527 /* Determine the size of a record list in bytes. */
2529 calc_record_size (list)
2533 process_unw_records (list, count_output);
2537 /* Update IMASK bitmask to reflect the fact that one or more registers
2538 of type TYPE are saved starting at instruction with index T. If N
2539 bits are set in REGMASK, it is assumed that instructions T through
2540 T+N-1 save these registers.
2544 1: instruction saves next fp reg
2545 2: instruction saves next general reg
2546 3: instruction saves next branch reg */
2548 set_imask (region, regmask, t, type)
2549 unw_rec_list *region;
2550 unsigned long regmask;
2554 unsigned char *imask;
2555 unsigned long imask_size;
2559 imask = region->r.record.r.mask.i;
2560 imask_size = region->r.record.r.imask_size;
2563 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2564 imask = xmalloc (imask_size);
2565 memset (imask, 0, imask_size);
2567 region->r.record.r.imask_size = imask_size;
2568 region->r.record.r.mask.i = imask;
2572 pos = 2 * (3 - t % 4);
2575 if (i >= imask_size)
2577 as_bad ("Ignoring attempt to spill beyond end of region");
2581 imask[i] |= (type & 0x3) << pos;
2583 regmask &= (regmask - 1);
2594 count_bits (unsigned long mask)
2606 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2607 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2608 containing FIRST_ADDR. */
2611 slot_index (slot_addr, slot_frag, first_addr, first_frag)
2612 unsigned long slot_addr;
2614 unsigned long first_addr;
2617 unsigned long index = 0;
2619 /* First time we are called, the initial address and frag are invalid. */
2620 if (first_addr == 0)
2623 /* If the two addresses are in different frags, then we need to add in
2624 the remaining size of this frag, and then the entire size of intermediate
2626 while (slot_frag != first_frag)
2628 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2630 /* Add in the full size of the frag converted to instruction slots. */
2631 index += 3 * (first_frag->fr_fix >> 4);
2632 /* Subtract away the initial part before first_addr. */
2633 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2634 + ((first_addr & 0x3) - (start_addr & 0x3)));
2636 /* Move to the beginning of the next frag. */
2637 first_frag = first_frag->fr_next;
2638 first_addr = (unsigned long) &first_frag->fr_literal;
2641 /* Add in the used part of the last frag. */
2642 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2643 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2647 /* Optimize unwind record directives. */
2649 static unw_rec_list *
2650 optimize_unw_records (list)
2656 /* If the only unwind record is ".prologue" or ".prologue" followed
2657 by ".body", then we can optimize the unwind directives away. */
2658 if (list->r.type == prologue
2659 && (list->next == NULL
2660 || (list->next->r.type == body && list->next->next == NULL)))
2666 /* Given a complete record list, process any records which have
2667 unresolved fields, (ie length counts for a prologue). After
2668 this has been run, all neccessary information should be available
2669 within each record to generate an image. */
2672 fixup_unw_records (list)
2675 unw_rec_list *ptr, *region = 0;
2676 unsigned long first_addr = 0, rlen = 0, t;
2677 fragS *first_frag = 0;
2679 for (ptr = list; ptr; ptr = ptr->next)
2681 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2682 as_bad (" Insn slot not set in unwind record.");
2683 t = slot_index (ptr->slot_number, ptr->slot_frag,
2684 first_addr, first_frag);
2685 switch (ptr->r.type)
2692 int size, dir_len = 0;
2693 unsigned long last_addr;
2696 first_addr = ptr->slot_number;
2697 first_frag = ptr->slot_frag;
2698 ptr->slot_number = 0;
2699 /* Find either the next body/prologue start, or the end of
2700 the list, and determine the size of the region. */
2701 last_addr = unwind.next_slot_number;
2702 last_frag = unwind.next_slot_frag;
2703 for (last = ptr->next; last != NULL; last = last->next)
2704 if (last->r.type == prologue || last->r.type == prologue_gr
2705 || last->r.type == body)
2707 last_addr = last->slot_number;
2708 last_frag = last->slot_frag;
2711 else if (!last->next)
2713 /* In the absence of an explicit .body directive,
2714 the prologue ends after the last instruction
2715 covered by an unwind directive. */
2716 if (ptr->r.type != body)
2718 last_addr = last->slot_number;
2719 last_frag = last->slot_frag;
2720 switch (last->r.type)
2723 dir_len = (count_bits (last->r.record.p.frmask)
2724 + count_bits (last->r.record.p.grmask));
2728 dir_len += count_bits (last->r.record.p.rmask);
2732 dir_len += count_bits (last->r.record.p.brmask);
2735 dir_len += count_bits (last->r.record.p.grmask);
2744 size = (slot_index (last_addr, last_frag, first_addr, first_frag)
2746 rlen = ptr->r.record.r.rlen = size;
2747 if (ptr->r.type == body)
2748 /* End of region. */
2755 ptr->r.record.b.t = rlen - 1 - t;
2766 case priunat_when_gr:
2767 case priunat_when_mem:
2771 ptr->r.record.p.t = t;
2779 case spill_psprel_p:
2780 ptr->r.record.x.t = t;
2786 as_bad ("frgr_mem record before region record!\n");
2789 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2790 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2791 set_imask (region, ptr->r.record.p.frmask, t, 1);
2792 set_imask (region, ptr->r.record.p.grmask, t, 2);
2797 as_bad ("fr_mem record before region record!\n");
2800 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2801 set_imask (region, ptr->r.record.p.rmask, t, 1);
2806 as_bad ("gr_mem record before region record!\n");
2809 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2810 set_imask (region, ptr->r.record.p.rmask, t, 2);
2815 as_bad ("br_mem record before region record!\n");
2818 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2819 set_imask (region, ptr->r.record.p.brmask, t, 3);
2825 as_bad ("gr_gr record before region record!\n");
2828 set_imask (region, ptr->r.record.p.grmask, t, 2);
2833 as_bad ("br_gr record before region record!\n");
2836 set_imask (region, ptr->r.record.p.brmask, t, 3);
2845 /* Helper routine for output_unw_records. Emits the header for the unwind
2849 setup_unwind_header (int size, unsigned char **mem)
2854 /* pad to pointer-size boundry. */
2855 x = size % md.pointer_size;
2857 extra = md.pointer_size - x;
2859 /* Add 8 for the header + a pointer for the
2860 personality offset. */
2861 *mem = xmalloc (size + extra + 8 + md.pointer_size);
2863 /* Clear the padding area and personality. */
2864 memset (*mem + 8 + size, 0, extra + md.pointer_size);
2866 /* Initialize the header area. */
2867 if (unwind.personality_routine)
2869 if (md.flags & EF_IA_64_ABI64)
2870 flag_value = (bfd_vma) 3 << 32;
2872 /* 32-bit unwind info block. */
2873 flag_value = (bfd_vma) 0x1003 << 32;
2878 md_number_to_chars (*mem, (((bfd_vma) 1 << 48) /* Version. */
2879 | flag_value /* U & E handler flags. */
2880 | ((size + extra) / md.pointer_size)), /* Length. */
2886 /* Generate an unwind image from a record list. Returns the number of
2887 bytes in the resulting image. The memory image itselof is returned
2888 in the 'ptr' parameter. */
2890 output_unw_records (list, ptr)
2899 list = optimize_unw_records (list);
2900 fixup_unw_records (list);
2901 size = calc_record_size (list);
2903 if (size > 0 || unwind.force_unwind_entry)
2905 unwind.force_unwind_entry = 0;
2906 extra = setup_unwind_header (size, &mem);
2908 vbyte_mem_ptr = mem + 8;
2909 process_unw_records (list, output_vbyte_mem);
2913 size += extra + 8 + md.pointer_size;
2919 convert_expr_to_ab_reg (e, ab, regp)
2926 if (e->X_op != O_register)
2929 reg = e->X_add_number;
2930 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2933 *regp = reg - REG_GR;
2935 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2936 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2939 *regp = reg - REG_FR;
2941 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2944 *regp = reg - REG_BR;
2951 case REG_PR: *regp = 0; break;
2952 case REG_PSP: *regp = 1; break;
2953 case REG_PRIUNAT: *regp = 2; break;
2954 case REG_BR + 0: *regp = 3; break;
2955 case REG_AR + AR_BSP: *regp = 4; break;
2956 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2957 case REG_AR + AR_RNAT: *regp = 6; break;
2958 case REG_AR + AR_UNAT: *regp = 7; break;
2959 case REG_AR + AR_FPSR: *regp = 8; break;
2960 case REG_AR + AR_PFS: *regp = 9; break;
2961 case REG_AR + AR_LC: *regp = 10; break;
2971 convert_expr_to_xy_reg (e, xy, regp)
2978 if (e->X_op != O_register)
2981 reg = e->X_add_number;
2983 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2986 *regp = reg - REG_GR;
2988 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2991 *regp = reg - REG_FR;
2993 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2996 *regp = reg - REG_BR;
3005 int dummy ATTRIBUTE_UNUSED;
3010 radix = *input_line_pointer++;
3012 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3014 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3015 ignore_rest_of_line ();
3020 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3022 dot_special_section (which)
3025 set_section ((char *) special_section_name[which]);
3029 add_unwind_entry (ptr)
3033 unwind.tail->next = ptr;
3038 /* The current entry can in fact be a chain of unwind entries. */
3039 if (unwind.current_entry == NULL)
3040 unwind.current_entry = ptr;
3045 int dummy ATTRIBUTE_UNUSED;
3051 if (e.X_op != O_constant)
3052 as_bad ("Operand to .fframe must be a constant");
3054 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3059 int dummy ATTRIBUTE_UNUSED;
3065 reg = e.X_add_number - REG_GR;
3066 if (e.X_op == O_register && reg < 128)
3068 add_unwind_entry (output_mem_stack_v ());
3069 if (! (unwind.prologue_mask & 2))
3070 add_unwind_entry (output_psp_gr (reg));
3073 as_bad ("First operand to .vframe must be a general register");
3077 dot_vframesp (dummy)
3078 int dummy ATTRIBUTE_UNUSED;
3083 if (e.X_op == O_constant)
3085 add_unwind_entry (output_mem_stack_v ());
3086 add_unwind_entry (output_psp_sprel (e.X_add_number));
3089 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3093 dot_vframepsp (dummy)
3094 int dummy ATTRIBUTE_UNUSED;
3099 if (e.X_op == O_constant)
3101 add_unwind_entry (output_mem_stack_v ());
3102 add_unwind_entry (output_psp_sprel (e.X_add_number));
3105 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3110 int dummy ATTRIBUTE_UNUSED;
3116 sep = parse_operand (&e1);
3118 as_bad ("No second operand to .save");
3119 sep = parse_operand (&e2);
3121 reg1 = e1.X_add_number;
3122 reg2 = e2.X_add_number - REG_GR;
3124 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3125 if (e1.X_op == O_register)
3127 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3131 case REG_AR + AR_BSP:
3132 add_unwind_entry (output_bsp_when ());
3133 add_unwind_entry (output_bsp_gr (reg2));
3135 case REG_AR + AR_BSPSTORE:
3136 add_unwind_entry (output_bspstore_when ());
3137 add_unwind_entry (output_bspstore_gr (reg2));
3139 case REG_AR + AR_RNAT:
3140 add_unwind_entry (output_rnat_when ());
3141 add_unwind_entry (output_rnat_gr (reg2));
3143 case REG_AR + AR_UNAT:
3144 add_unwind_entry (output_unat_when ());
3145 add_unwind_entry (output_unat_gr (reg2));
3147 case REG_AR + AR_FPSR:
3148 add_unwind_entry (output_fpsr_when ());
3149 add_unwind_entry (output_fpsr_gr (reg2));
3151 case REG_AR + AR_PFS:
3152 add_unwind_entry (output_pfs_when ());
3153 if (! (unwind.prologue_mask & 4))
3154 add_unwind_entry (output_pfs_gr (reg2));
3156 case REG_AR + AR_LC:
3157 add_unwind_entry (output_lc_when ());
3158 add_unwind_entry (output_lc_gr (reg2));
3161 add_unwind_entry (output_rp_when ());
3162 if (! (unwind.prologue_mask & 8))
3163 add_unwind_entry (output_rp_gr (reg2));
3166 add_unwind_entry (output_preds_when ());
3167 if (! (unwind.prologue_mask & 1))
3168 add_unwind_entry (output_preds_gr (reg2));
3171 add_unwind_entry (output_priunat_when_gr ());
3172 add_unwind_entry (output_priunat_gr (reg2));
3175 as_bad ("First operand not a valid register");
3179 as_bad (" Second operand not a valid register");
3182 as_bad ("First operand not a register");
3187 int dummy ATTRIBUTE_UNUSED;
3190 unsigned long ecount; /* # of _additional_ regions to pop */
3193 sep = parse_operand (&e1);
3194 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3196 as_bad ("First operand to .restore must be stack pointer (sp)");
3202 parse_operand (&e2);
3203 if (e2.X_op != O_constant || e2.X_add_number < 0)
3205 as_bad ("Second operand to .restore must be a constant >= 0");
3208 ecount = e2.X_add_number;
3211 ecount = unwind.prologue_count - 1;
3213 if (ecount >= unwind.prologue_count)
3215 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3216 ecount + 1, unwind.prologue_count);
3220 add_unwind_entry (output_epilogue (ecount));
3222 if (ecount < unwind.prologue_count)
3223 unwind.prologue_count -= ecount + 1;
3225 unwind.prologue_count = 0;
3229 dot_restorereg (dummy)
3230 int dummy ATTRIBUTE_UNUSED;
3232 unsigned int ab, reg;
3237 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3239 as_bad ("First operand to .restorereg must be a preserved register");
3242 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3246 dot_restorereg_p (dummy)
3247 int dummy ATTRIBUTE_UNUSED;
3249 unsigned int qp, ab, reg;
3253 sep = parse_operand (&e1);
3256 as_bad ("No second operand to .restorereg.p");
3260 parse_operand (&e2);
3262 qp = e1.X_add_number - REG_P;
3263 if (e1.X_op != O_register || qp > 63)
3265 as_bad ("First operand to .restorereg.p must be a predicate");
3269 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3271 as_bad ("Second operand to .restorereg.p must be a preserved register");
3274 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3278 generate_unwind_image (text_name)
3279 const char *text_name;
3284 /* Force out pending instructions, to make sure all unwind records have
3285 a valid slot_number field. */
3286 ia64_flush_insns ();
3288 /* Generate the unwind record. */
3289 size = output_unw_records (unwind.list, &unw_rec);
3290 if (size % md.pointer_size != 0)
3291 as_bad ("Unwind record is not a multiple of %d bytes.", md.pointer_size);
3293 /* If there are unwind records, switch sections, and output the info. */
3296 unsigned char *where;
3299 bfd_reloc_code_real_type reloc;
3301 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3302 set_section (sec_name);
3303 bfd_set_section_flags (stdoutput, now_seg,
3304 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3306 /* Make sure the section has 4 byte alignment for ILP32 and
3307 8 byte alignment for LP64. */
3308 frag_align (md.pointer_size_shift, 0, 0);
3309 record_alignment (now_seg, md.pointer_size_shift);
3311 /* Set expression which points to start of unwind descriptor area. */
3312 unwind.info = expr_build_dot ();
3314 where = (unsigned char *) frag_more (size);
3316 /* Issue a label for this address, and keep track of it to put it
3317 in the unwind section. */
3319 /* Copy the information from the unwind record into this section. The
3320 data is already in the correct byte order. */
3321 memcpy (where, unw_rec, size);
3323 /* Add the personality address to the image. */
3324 if (unwind.personality_routine != 0)
3326 exp.X_op = O_symbol;
3327 exp.X_add_symbol = unwind.personality_routine;
3328 exp.X_add_number = 0;
3330 if (md.flags & EF_IA_64_BE)
3332 if (md.flags & EF_IA_64_ABI64)
3333 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3335 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3339 if (md.flags & EF_IA_64_ABI64)
3340 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3342 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3345 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3346 md.pointer_size, &exp, 0, reloc);
3347 unwind.personality_routine = 0;
3351 free_list_records (unwind.list);
3352 free_saved_prologue_counts ();
3353 unwind.list = unwind.tail = unwind.current_entry = NULL;
3359 dot_handlerdata (dummy)
3360 int dummy ATTRIBUTE_UNUSED;
3362 const char *text_name = segment_name (now_seg);
3364 /* If text section name starts with ".text" (which it should),
3365 strip this prefix off. */
3366 if (strcmp (text_name, ".text") == 0)
3369 unwind.force_unwind_entry = 1;
3371 /* Remember which segment we're in so we can switch back after .endp */
3372 unwind.saved_text_seg = now_seg;
3373 unwind.saved_text_subseg = now_subseg;
3375 /* Generate unwind info into unwind-info section and then leave that
3376 section as the currently active one so dataXX directives go into
3377 the language specific data area of the unwind info block. */
3378 generate_unwind_image (text_name);
3379 demand_empty_rest_of_line ();
3383 dot_unwentry (dummy)
3384 int dummy ATTRIBUTE_UNUSED;
3386 unwind.force_unwind_entry = 1;
3387 demand_empty_rest_of_line ();
3392 int dummy ATTRIBUTE_UNUSED;
3398 reg = e.X_add_number - REG_BR;
3399 if (e.X_op == O_register && reg < 8)
3400 add_unwind_entry (output_rp_br (reg));
3402 as_bad ("First operand not a valid branch register");
3406 dot_savemem (psprel)
3413 sep = parse_operand (&e1);
3415 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3416 sep = parse_operand (&e2);
3418 reg1 = e1.X_add_number;
3419 val = e2.X_add_number;
3421 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3422 if (e1.X_op == O_register)
3424 if (e2.X_op == O_constant)
3428 case REG_AR + AR_BSP:
3429 add_unwind_entry (output_bsp_when ());
3430 add_unwind_entry ((psprel
3432 : output_bsp_sprel) (val));
3434 case REG_AR + AR_BSPSTORE:
3435 add_unwind_entry (output_bspstore_when ());
3436 add_unwind_entry ((psprel
3437 ? output_bspstore_psprel
3438 : output_bspstore_sprel) (val));
3440 case REG_AR + AR_RNAT:
3441 add_unwind_entry (output_rnat_when ());
3442 add_unwind_entry ((psprel
3443 ? output_rnat_psprel
3444 : output_rnat_sprel) (val));
3446 case REG_AR + AR_UNAT:
3447 add_unwind_entry (output_unat_when ());
3448 add_unwind_entry ((psprel
3449 ? output_unat_psprel
3450 : output_unat_sprel) (val));
3452 case REG_AR + AR_FPSR:
3453 add_unwind_entry (output_fpsr_when ());
3454 add_unwind_entry ((psprel
3455 ? output_fpsr_psprel
3456 : output_fpsr_sprel) (val));
3458 case REG_AR + AR_PFS:
3459 add_unwind_entry (output_pfs_when ());
3460 add_unwind_entry ((psprel
3462 : output_pfs_sprel) (val));
3464 case REG_AR + AR_LC:
3465 add_unwind_entry (output_lc_when ());
3466 add_unwind_entry ((psprel
3468 : output_lc_sprel) (val));
3471 add_unwind_entry (output_rp_when ());
3472 add_unwind_entry ((psprel
3474 : output_rp_sprel) (val));
3477 add_unwind_entry (output_preds_when ());
3478 add_unwind_entry ((psprel
3479 ? output_preds_psprel
3480 : output_preds_sprel) (val));
3483 add_unwind_entry (output_priunat_when_mem ());
3484 add_unwind_entry ((psprel
3485 ? output_priunat_psprel
3486 : output_priunat_sprel) (val));
3489 as_bad ("First operand not a valid register");
3493 as_bad (" Second operand not a valid constant");
3496 as_bad ("First operand not a register");
3501 int dummy ATTRIBUTE_UNUSED;
3505 sep = parse_operand (&e1);
3507 parse_operand (&e2);
3509 if (e1.X_op != O_constant)
3510 as_bad ("First operand to .save.g must be a constant.");
3513 int grmask = e1.X_add_number;
3515 add_unwind_entry (output_gr_mem (grmask));
3518 int reg = e2.X_add_number - REG_GR;
3519 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3520 add_unwind_entry (output_gr_gr (grmask, reg));
3522 as_bad ("Second operand is an invalid register.");
3529 int dummy ATTRIBUTE_UNUSED;
3533 sep = parse_operand (&e1);
3535 if (e1.X_op != O_constant)
3536 as_bad ("Operand to .save.f must be a constant.");
3538 add_unwind_entry (output_fr_mem (e1.X_add_number));
3543 int dummy ATTRIBUTE_UNUSED;
3550 sep = parse_operand (&e1);
3551 if (e1.X_op != O_constant)
3553 as_bad ("First operand to .save.b must be a constant.");
3556 brmask = e1.X_add_number;
3560 sep = parse_operand (&e2);
3561 reg = e2.X_add_number - REG_GR;
3562 if (e2.X_op != O_register || reg > 127)
3564 as_bad ("Second operand to .save.b must be a general register.");
3567 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3570 add_unwind_entry (output_br_mem (brmask));
3572 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3573 ignore_rest_of_line ();
3578 int dummy ATTRIBUTE_UNUSED;
3582 sep = parse_operand (&e1);
3584 parse_operand (&e2);
3586 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3587 as_bad ("Both operands of .save.gf must be constants.");
3590 int grmask = e1.X_add_number;
3591 int frmask = e2.X_add_number;
3592 add_unwind_entry (output_frgr_mem (grmask, frmask));
3598 int dummy ATTRIBUTE_UNUSED;
3603 sep = parse_operand (&e);
3604 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3605 ignore_rest_of_line ();
3607 if (e.X_op != O_constant)
3608 as_bad ("Operand to .spill must be a constant");
3610 add_unwind_entry (output_spill_base (e.X_add_number));
3614 dot_spillreg (dummy)
3615 int dummy ATTRIBUTE_UNUSED;
3617 int sep, ab, xy, reg, treg;
3620 sep = parse_operand (&e1);
3623 as_bad ("No second operand to .spillreg");
3627 parse_operand (&e2);
3629 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3631 as_bad ("First operand to .spillreg must be a preserved register");
3635 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3637 as_bad ("Second operand to .spillreg must be a register");
3641 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3645 dot_spillmem (psprel)
3651 sep = parse_operand (&e1);
3654 as_bad ("Second operand missing");
3658 parse_operand (&e2);
3660 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3662 as_bad ("First operand to .spill%s must be a preserved register",
3663 psprel ? "psp" : "sp");
3667 if (e2.X_op != O_constant)
3669 as_bad ("Second operand to .spill%s must be a constant",
3670 psprel ? "psp" : "sp");
3675 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3677 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3681 dot_spillreg_p (dummy)
3682 int dummy ATTRIBUTE_UNUSED;
3684 int sep, ab, xy, reg, treg;
3685 expressionS e1, e2, e3;
3688 sep = parse_operand (&e1);
3691 as_bad ("No second and third operand to .spillreg.p");
3695 sep = parse_operand (&e2);
3698 as_bad ("No third operand to .spillreg.p");
3702 parse_operand (&e3);
3704 qp = e1.X_add_number - REG_P;
3706 if (e1.X_op != O_register || qp > 63)
3708 as_bad ("First operand to .spillreg.p must be a predicate");
3712 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3714 as_bad ("Second operand to .spillreg.p must be a preserved register");
3718 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3720 as_bad ("Third operand to .spillreg.p must be a register");
3724 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3728 dot_spillmem_p (psprel)
3731 expressionS e1, e2, e3;
3735 sep = parse_operand (&e1);
3738 as_bad ("Second operand missing");
3742 parse_operand (&e2);
3745 as_bad ("Second operand missing");
3749 parse_operand (&e3);
3751 qp = e1.X_add_number - REG_P;
3752 if (e1.X_op != O_register || qp > 63)
3754 as_bad ("First operand to .spill%s_p must be a predicate",
3755 psprel ? "psp" : "sp");
3759 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3761 as_bad ("Second operand to .spill%s_p must be a preserved register",
3762 psprel ? "psp" : "sp");
3766 if (e3.X_op != O_constant)
3768 as_bad ("Third operand to .spill%s_p must be a constant",
3769 psprel ? "psp" : "sp");
3774 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3776 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3780 get_saved_prologue_count (lbl)
3783 label_prologue_count *lpc = unwind.saved_prologue_counts;
3785 while (lpc != NULL && lpc->label_number != lbl)
3789 return lpc->prologue_count;
3791 as_bad ("Missing .label_state %ld", lbl);
3796 save_prologue_count (lbl, count)
3800 label_prologue_count *lpc = unwind.saved_prologue_counts;
3802 while (lpc != NULL && lpc->label_number != lbl)
3806 lpc->prologue_count = count;
3809 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3811 new_lpc->next = unwind.saved_prologue_counts;
3812 new_lpc->label_number = lbl;
3813 new_lpc->prologue_count = count;
3814 unwind.saved_prologue_counts = new_lpc;
3819 free_saved_prologue_counts ()
3821 label_prologue_count *lpc = unwind.saved_prologue_counts;
3822 label_prologue_count *next;
3831 unwind.saved_prologue_counts = NULL;
3835 dot_label_state (dummy)
3836 int dummy ATTRIBUTE_UNUSED;
3841 if (e.X_op != O_constant)
3843 as_bad ("Operand to .label_state must be a constant");
3846 add_unwind_entry (output_label_state (e.X_add_number));
3847 save_prologue_count (e.X_add_number, unwind.prologue_count);
3851 dot_copy_state (dummy)
3852 int dummy ATTRIBUTE_UNUSED;
3857 if (e.X_op != O_constant)
3859 as_bad ("Operand to .copy_state must be a constant");
3862 add_unwind_entry (output_copy_state (e.X_add_number));
3863 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3868 int dummy ATTRIBUTE_UNUSED;
3873 sep = parse_operand (&e1);
3876 as_bad ("Second operand to .unwabi missing");
3879 sep = parse_operand (&e2);
3880 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3881 ignore_rest_of_line ();
3883 if (e1.X_op != O_constant)
3885 as_bad ("First operand to .unwabi must be a constant");
3889 if (e2.X_op != O_constant)
3891 as_bad ("Second operand to .unwabi must be a constant");
3895 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3899 dot_personality (dummy)
3900 int dummy ATTRIBUTE_UNUSED;
3904 name = input_line_pointer;
3905 c = get_symbol_end ();
3906 p = input_line_pointer;
3907 unwind.personality_routine = symbol_find_or_make (name);
3908 unwind.force_unwind_entry = 1;
3911 demand_empty_rest_of_line ();
3916 int dummy ATTRIBUTE_UNUSED;
3921 unwind.proc_start = expr_build_dot ();
3922 /* Parse names of main and alternate entry points and mark them as
3923 function symbols: */
3927 name = input_line_pointer;
3928 c = get_symbol_end ();
3929 p = input_line_pointer;
3930 sym = symbol_find_or_make (name);
3931 if (unwind.proc_start == 0)
3933 unwind.proc_start = sym;
3935 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3938 if (*input_line_pointer != ',')
3940 ++input_line_pointer;
3942 demand_empty_rest_of_line ();
3945 unwind.prologue_count = 0;
3946 unwind.list = unwind.tail = unwind.current_entry = NULL;
3947 unwind.personality_routine = 0;
3952 int dummy ATTRIBUTE_UNUSED;
3954 unwind.prologue = 0;
3955 unwind.prologue_mask = 0;
3957 add_unwind_entry (output_body ());
3958 demand_empty_rest_of_line ();
3962 dot_prologue (dummy)
3963 int dummy ATTRIBUTE_UNUSED;
3966 int mask = 0, grsave = 0;
3968 if (!is_it_end_of_statement ())
3971 sep = parse_operand (&e1);
3973 as_bad ("No second operand to .prologue");
3974 sep = parse_operand (&e2);
3975 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3976 ignore_rest_of_line ();
3978 if (e1.X_op == O_constant)
3980 mask = e1.X_add_number;
3982 if (e2.X_op == O_constant)
3983 grsave = e2.X_add_number;
3984 else if (e2.X_op == O_register
3985 && (grsave = e2.X_add_number - REG_GR) < 128)
3988 as_bad ("Second operand not a constant or general register");
3990 add_unwind_entry (output_prologue_gr (mask, grsave));
3993 as_bad ("First operand not a constant");
3996 add_unwind_entry (output_prologue ());
3998 unwind.prologue = 1;
3999 unwind.prologue_mask = mask;
4000 ++unwind.prologue_count;
4005 int dummy ATTRIBUTE_UNUSED;
4009 int bytes_per_address;
4012 subsegT saved_subseg;
4013 const char *sec_name, *text_name;
4017 if (unwind.saved_text_seg)
4019 saved_seg = unwind.saved_text_seg;
4020 saved_subseg = unwind.saved_text_subseg;
4021 unwind.saved_text_seg = NULL;
4025 saved_seg = now_seg;
4026 saved_subseg = now_subseg;
4030 Use a slightly ugly scheme to derive the unwind section names from
4031 the text section name:
4033 text sect. unwind table sect.
4034 name: name: comments:
4035 ---------- ----------------- --------------------------------
4037 .text.foo .IA_64.unwind.text.foo
4038 .foo .IA_64.unwind.foo
4040 .gnu.linkonce.ia64unw.foo
4041 _info .IA_64.unwind_info gas issues error message (ditto)
4042 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
4044 This mapping is done so that:
4046 (a) An object file with unwind info only in .text will use
4047 unwind section names .IA_64.unwind and .IA_64.unwind_info.
4048 This follows the letter of the ABI and also ensures backwards
4049 compatibility with older toolchains.
4051 (b) An object file with unwind info in multiple text sections
4052 will use separate unwind sections for each text section.
4053 This allows us to properly set the "sh_info" and "sh_link"
4054 fields in SHT_IA_64_UNWIND as required by the ABI and also
4055 lets GNU ld support programs with multiple segments
4056 containing unwind info (as might be the case for certain
4057 embedded applications).
4059 (c) An error is issued if there would be a name clash.
4061 text_name = segment_name (saved_seg);
4062 if (strncmp (text_name, "_info", 5) == 0)
4064 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
4066 ignore_rest_of_line ();
4069 if (strcmp (text_name, ".text") == 0)
4072 insn_group_break (1, 0, 0);
4074 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4076 generate_unwind_image (text_name);
4078 if (unwind.info || unwind.force_unwind_entry)
4080 subseg_set (md.last_text_seg, 0);
4081 unwind.proc_end = expr_build_dot ();
4083 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
4084 set_section ((char *) sec_name);
4085 bfd_set_section_flags (stdoutput, now_seg,
4086 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
4088 /* Make sure that section has 4 byte alignment for ILP32 and
4089 8 byte alignment for LP64. */
4090 record_alignment (now_seg, md.pointer_size_shift);
4092 /* Need space for 3 pointers for procedure start, procedure end,
4094 ptr = frag_more (3 * md.pointer_size);
4095 where = frag_now_fix () - (3 * md.pointer_size);
4096 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4098 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4099 e.X_op = O_pseudo_fixup;
4100 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4102 e.X_add_symbol = unwind.proc_start;
4103 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4105 e.X_op = O_pseudo_fixup;
4106 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4108 e.X_add_symbol = unwind.proc_end;
4109 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4110 bytes_per_address, &e);
4114 e.X_op = O_pseudo_fixup;
4115 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4117 e.X_add_symbol = unwind.info;
4118 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4119 bytes_per_address, &e);
4122 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4126 subseg_set (saved_seg, saved_subseg);
4128 /* Parse names of main and alternate entry points and set symbol sizes. */
4132 name = input_line_pointer;
4133 c = get_symbol_end ();
4134 p = input_line_pointer;
4135 sym = symbol_find (name);
4136 if (sym && unwind.proc_start
4137 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4138 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4140 fragS *fr = symbol_get_frag (unwind.proc_start);
4141 fragS *frag = symbol_get_frag (sym);
4143 /* Check whether the function label is at or beyond last
4145 while (fr && fr != frag)
4149 if (frag == frag_now && SEG_NORMAL (now_seg))
4150 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4153 symbol_get_obj (sym)->size =
4154 (expressionS *) xmalloc (sizeof (expressionS));
4155 symbol_get_obj (sym)->size->X_op = O_subtract;
4156 symbol_get_obj (sym)->size->X_add_symbol
4157 = symbol_new (FAKE_LABEL_NAME, now_seg,
4158 frag_now_fix (), frag_now);
4159 symbol_get_obj (sym)->size->X_op_symbol = sym;
4160 symbol_get_obj (sym)->size->X_add_number = 0;
4166 if (*input_line_pointer != ',')
4168 ++input_line_pointer;
4170 demand_empty_rest_of_line ();
4171 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4175 dot_template (template)
4178 CURR_SLOT.user_template = template;
4183 int dummy ATTRIBUTE_UNUSED;
4185 int ins, locs, outs, rots;
4187 if (is_it_end_of_statement ())
4188 ins = locs = outs = rots = 0;
4191 ins = get_absolute_expression ();
4192 if (*input_line_pointer++ != ',')
4194 locs = get_absolute_expression ();
4195 if (*input_line_pointer++ != ',')
4197 outs = get_absolute_expression ();
4198 if (*input_line_pointer++ != ',')
4200 rots = get_absolute_expression ();
4202 set_regstack (ins, locs, outs, rots);
4206 as_bad ("Comma expected");
4207 ignore_rest_of_line ();
4214 unsigned num_regs, num_alloced = 0;
4215 struct dynreg **drpp, *dr;
4216 int ch, base_reg = 0;
4222 case DYNREG_GR: base_reg = REG_GR + 32; break;
4223 case DYNREG_FR: base_reg = REG_FR + 32; break;
4224 case DYNREG_PR: base_reg = REG_P + 16; break;
4228 /* First, remove existing names from hash table. */
4229 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4231 hash_delete (md.dynreg_hash, dr->name);
4235 drpp = &md.dynreg[type];
4238 start = input_line_pointer;
4239 ch = get_symbol_end ();
4240 *input_line_pointer = ch;
4241 len = (input_line_pointer - start);
4244 if (*input_line_pointer != '[')
4246 as_bad ("Expected '['");
4249 ++input_line_pointer; /* skip '[' */
4251 num_regs = get_absolute_expression ();
4253 if (*input_line_pointer++ != ']')
4255 as_bad ("Expected ']'");
4260 num_alloced += num_regs;
4264 if (num_alloced > md.rot.num_regs)
4266 as_bad ("Used more than the declared %d rotating registers",
4272 if (num_alloced > 96)
4274 as_bad ("Used more than the available 96 rotating registers");
4279 if (num_alloced > 48)
4281 as_bad ("Used more than the available 48 rotating registers");
4290 name = obstack_alloc (¬es, len + 1);
4291 memcpy (name, start, len);
4296 *drpp = obstack_alloc (¬es, sizeof (*dr));
4297 memset (*drpp, 0, sizeof (*dr));
4302 dr->num_regs = num_regs;
4303 dr->base = base_reg;
4305 base_reg += num_regs;
4307 if (hash_insert (md.dynreg_hash, name, dr))
4309 as_bad ("Attempt to redefine register set `%s'", name);
4313 if (*input_line_pointer != ',')
4315 ++input_line_pointer; /* skip comma */
4318 demand_empty_rest_of_line ();
4322 ignore_rest_of_line ();
4326 dot_byteorder (byteorder)
4329 segment_info_type *seginfo = seg_info (now_seg);
4331 if (byteorder == -1)
4333 if (seginfo->tc_segment_info_data.endian == 0)
4334 seginfo->tc_segment_info_data.endian
4335 = TARGET_BYTES_BIG_ENDIAN ? 1 : 2;
4336 byteorder = seginfo->tc_segment_info_data.endian == 1;
4339 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4341 if (target_big_endian != byteorder)
4343 target_big_endian = byteorder;
4344 if (target_big_endian)
4346 ia64_number_to_chars = number_to_chars_bigendian;
4347 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4351 ia64_number_to_chars = number_to_chars_littleendian;
4352 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4359 int dummy ATTRIBUTE_UNUSED;
4366 option = input_line_pointer;
4367 ch = get_symbol_end ();
4368 if (strcmp (option, "lsb") == 0)
4369 md.flags &= ~EF_IA_64_BE;
4370 else if (strcmp (option, "msb") == 0)
4371 md.flags |= EF_IA_64_BE;
4372 else if (strcmp (option, "abi32") == 0)
4373 md.flags &= ~EF_IA_64_ABI64;
4374 else if (strcmp (option, "abi64") == 0)
4375 md.flags |= EF_IA_64_ABI64;
4377 as_bad ("Unknown psr option `%s'", option);
4378 *input_line_pointer = ch;
4381 if (*input_line_pointer != ',')
4384 ++input_line_pointer;
4387 demand_empty_rest_of_line ();
4392 int dummy ATTRIBUTE_UNUSED;
4394 new_logical_line (0, get_absolute_expression ());
4395 demand_empty_rest_of_line ();
4399 parse_section_name ()
4405 if (*input_line_pointer != '"')
4407 as_bad ("Missing section name");
4408 ignore_rest_of_line ();
4411 name = demand_copy_C_string (&len);
4414 ignore_rest_of_line ();
4418 if (*input_line_pointer != ',')
4420 as_bad ("Comma expected after section name");
4421 ignore_rest_of_line ();
4424 ++input_line_pointer; /* skip comma */
4432 char *name = parse_section_name ();
4436 md.keep_pending_output = 1;
4439 obj_elf_previous (0);
4440 md.keep_pending_output = 0;
4443 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4446 stmt_float_cons (kind)
4467 ia64_do_align (alignment);
4475 int saved_auto_align = md.auto_align;
4479 md.auto_align = saved_auto_align;
4483 dot_xfloat_cons (kind)
4486 char *name = parse_section_name ();
4490 md.keep_pending_output = 1;
4492 stmt_float_cons (kind);
4493 obj_elf_previous (0);
4494 md.keep_pending_output = 0;
4498 dot_xstringer (zero)
4501 char *name = parse_section_name ();
4505 md.keep_pending_output = 1;
4508 obj_elf_previous (0);
4509 md.keep_pending_output = 0;
4516 int saved_auto_align = md.auto_align;
4517 char *name = parse_section_name ();
4521 md.keep_pending_output = 1;
4525 md.auto_align = saved_auto_align;
4526 obj_elf_previous (0);
4527 md.keep_pending_output = 0;
4531 dot_xfloat_cons_ua (kind)
4534 int saved_auto_align = md.auto_align;
4535 char *name = parse_section_name ();
4539 md.keep_pending_output = 1;
4542 stmt_float_cons (kind);
4543 md.auto_align = saved_auto_align;
4544 obj_elf_previous (0);
4545 md.keep_pending_output = 0;
4548 /* .reg.val <regname>,value */
4552 int dummy ATTRIBUTE_UNUSED;
4557 if (reg.X_op != O_register)
4559 as_bad (_("Register name expected"));
4560 ignore_rest_of_line ();
4562 else if (*input_line_pointer++ != ',')
4564 as_bad (_("Comma expected"));
4565 ignore_rest_of_line ();
4569 valueT value = get_absolute_expression ();
4570 int regno = reg.X_add_number;
4571 if (regno < REG_GR || regno > REG_GR + 128)
4572 as_warn (_("Register value annotation ignored"));
4575 gr_values[regno - REG_GR].known = 1;
4576 gr_values[regno - REG_GR].value = value;
4577 gr_values[regno - REG_GR].path = md.path;
4580 demand_empty_rest_of_line ();
4583 /* select dv checking mode
4588 A stop is inserted when changing modes
4595 if (md.manual_bundling)
4596 as_warn (_("Directive invalid within a bundle"));
4598 if (type == 'E' || type == 'A')
4599 md.mode_explicitly_set = 0;
4601 md.mode_explicitly_set = 1;
4608 if (md.explicit_mode)
4609 insn_group_break (1, 0, 0);
4610 md.explicit_mode = 0;
4614 if (!md.explicit_mode)
4615 insn_group_break (1, 0, 0);
4616 md.explicit_mode = 1;
4620 if (md.explicit_mode != md.default_explicit_mode)
4621 insn_group_break (1, 0, 0);
4622 md.explicit_mode = md.default_explicit_mode;
4623 md.mode_explicitly_set = 0;
4634 for (regno = 0; regno < 64; regno++)
4636 if (mask & ((valueT) 1 << regno))
4638 fprintf (stderr, "%s p%d", comma, regno);
4645 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4646 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4647 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4648 .pred.safe_across_calls p1 [, p2 [,...]]
4657 int p1 = -1, p2 = -1;
4661 if (*input_line_pointer != '"')
4663 as_bad (_("Missing predicate relation type"));
4664 ignore_rest_of_line ();
4670 char *form = demand_copy_C_string (&len);
4671 if (strcmp (form, "mutex") == 0)
4673 else if (strcmp (form, "clear") == 0)
4675 else if (strcmp (form, "imply") == 0)
4679 as_bad (_("Unrecognized predicate relation type"));
4680 ignore_rest_of_line ();
4684 if (*input_line_pointer == ',')
4685 ++input_line_pointer;
4695 if (TOUPPER (*input_line_pointer) != 'P'
4696 || (regno = atoi (++input_line_pointer)) < 0
4699 as_bad (_("Predicate register expected"));
4700 ignore_rest_of_line ();
4703 while (ISDIGIT (*input_line_pointer))
4704 ++input_line_pointer;
4711 as_warn (_("Duplicate predicate register ignored"));
4714 /* See if it's a range. */
4715 if (*input_line_pointer == '-')
4718 ++input_line_pointer;
4720 if (TOUPPER (*input_line_pointer) != 'P'
4721 || (regno = atoi (++input_line_pointer)) < 0
4724 as_bad (_("Predicate register expected"));
4725 ignore_rest_of_line ();
4728 while (ISDIGIT (*input_line_pointer))
4729 ++input_line_pointer;
4733 as_bad (_("Bad register range"));
4734 ignore_rest_of_line ();
4745 if (*input_line_pointer != ',')
4747 ++input_line_pointer;
4756 clear_qp_mutex (mask);
4757 clear_qp_implies (mask, (valueT) 0);
4760 if (count != 2 || p1 == -1 || p2 == -1)
4761 as_bad (_("Predicate source and target required"));
4762 else if (p1 == 0 || p2 == 0)
4763 as_bad (_("Use of p0 is not valid in this context"));
4765 add_qp_imply (p1, p2);
4770 as_bad (_("At least two PR arguments expected"));
4775 as_bad (_("Use of p0 is not valid in this context"));
4778 add_qp_mutex (mask);
4781 /* note that we don't override any existing relations */
4784 as_bad (_("At least one PR argument expected"));
4789 fprintf (stderr, "Safe across calls: ");
4790 print_prmask (mask);
4791 fprintf (stderr, "\n");
4793 qp_safe_across_calls = mask;
4796 demand_empty_rest_of_line ();
4799 /* .entry label [, label [, ...]]
4800 Hint to DV code that the given labels are to be considered entry points.
4801 Otherwise, only global labels are considered entry points. */
4805 int dummy ATTRIBUTE_UNUSED;
4814 name = input_line_pointer;
4815 c = get_symbol_end ();
4816 symbolP = symbol_find_or_make (name);
4818 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4820 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4823 *input_line_pointer = c;
4825 c = *input_line_pointer;
4828 input_line_pointer++;
4830 if (*input_line_pointer == '\n')
4836 demand_empty_rest_of_line ();
4839 /* .mem.offset offset, base
4840 "base" is used to distinguish between offsets from a different base. */
4843 dot_mem_offset (dummy)
4844 int dummy ATTRIBUTE_UNUSED;
4846 md.mem_offset.hint = 1;
4847 md.mem_offset.offset = get_absolute_expression ();
4848 if (*input_line_pointer != ',')
4850 as_bad (_("Comma expected"));
4851 ignore_rest_of_line ();
4854 ++input_line_pointer;
4855 md.mem_offset.base = get_absolute_expression ();
4856 demand_empty_rest_of_line ();
4859 /* ia64-specific pseudo-ops: */
4860 const pseudo_typeS md_pseudo_table[] =
4862 { "radix", dot_radix, 0 },
4863 { "lcomm", s_lcomm_bytes, 1 },
4864 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4865 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4866 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4867 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4868 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4869 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4870 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4871 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4872 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4873 { "proc", dot_proc, 0 },
4874 { "body", dot_body, 0 },
4875 { "prologue", dot_prologue, 0 },
4876 { "endp", dot_endp, 0 },
4878 { "fframe", dot_fframe, 0 },
4879 { "vframe", dot_vframe, 0 },
4880 { "vframesp", dot_vframesp, 0 },
4881 { "vframepsp", dot_vframepsp, 0 },
4882 { "save", dot_save, 0 },
4883 { "restore", dot_restore, 0 },
4884 { "restorereg", dot_restorereg, 0 },
4885 { "restorereg.p", dot_restorereg_p, 0 },
4886 { "handlerdata", dot_handlerdata, 0 },
4887 { "unwentry", dot_unwentry, 0 },
4888 { "altrp", dot_altrp, 0 },
4889 { "savesp", dot_savemem, 0 },
4890 { "savepsp", dot_savemem, 1 },
4891 { "save.g", dot_saveg, 0 },
4892 { "save.f", dot_savef, 0 },
4893 { "save.b", dot_saveb, 0 },
4894 { "save.gf", dot_savegf, 0 },
4895 { "spill", dot_spill, 0 },
4896 { "spillreg", dot_spillreg, 0 },
4897 { "spillsp", dot_spillmem, 0 },
4898 { "spillpsp", dot_spillmem, 1 },
4899 { "spillreg.p", dot_spillreg_p, 0 },
4900 { "spillsp.p", dot_spillmem_p, 0 },
4901 { "spillpsp.p", dot_spillmem_p, 1 },
4902 { "label_state", dot_label_state, 0 },
4903 { "copy_state", dot_copy_state, 0 },
4904 { "unwabi", dot_unwabi, 0 },
4905 { "personality", dot_personality, 0 },
4907 { "estate", dot_estate, 0 },
4909 { "mii", dot_template, 0x0 },
4910 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4911 { "mlx", dot_template, 0x2 },
4912 { "mmi", dot_template, 0x4 },
4913 { "mfi", dot_template, 0x6 },
4914 { "mmf", dot_template, 0x7 },
4915 { "mib", dot_template, 0x8 },
4916 { "mbb", dot_template, 0x9 },
4917 { "bbb", dot_template, 0xb },
4918 { "mmb", dot_template, 0xc },
4919 { "mfb", dot_template, 0xe },
4921 { "lb", dot_scope, 0 },
4922 { "le", dot_scope, 1 },
4924 { "align", s_align_bytes, 0 },
4925 { "regstk", dot_regstk, 0 },
4926 { "rotr", dot_rot, DYNREG_GR },
4927 { "rotf", dot_rot, DYNREG_FR },
4928 { "rotp", dot_rot, DYNREG_PR },
4929 { "lsb", dot_byteorder, 0 },
4930 { "msb", dot_byteorder, 1 },
4931 { "psr", dot_psr, 0 },
4932 { "alias", dot_alias, 0 },
4933 { "secalias", dot_alias, 1 },
4934 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4936 { "xdata1", dot_xdata, 1 },
4937 { "xdata2", dot_xdata, 2 },
4938 { "xdata4", dot_xdata, 4 },
4939 { "xdata8", dot_xdata, 8 },
4940 { "xreal4", dot_xfloat_cons, 'f' },
4941 { "xreal8", dot_xfloat_cons, 'd' },
4942 { "xreal10", dot_xfloat_cons, 'x' },
4943 { "xreal16", dot_xfloat_cons, 'X' },
4944 { "xstring", dot_xstringer, 0 },
4945 { "xstringz", dot_xstringer, 1 },
4947 /* unaligned versions: */
4948 { "xdata2.ua", dot_xdata_ua, 2 },
4949 { "xdata4.ua", dot_xdata_ua, 4 },
4950 { "xdata8.ua", dot_xdata_ua, 8 },
4951 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4952 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4953 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4954 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
4956 /* annotations/DV checking support */
4957 { "entry", dot_entry, 0 },
4958 { "mem.offset", dot_mem_offset, 0 },
4959 { "pred.rel", dot_pred_rel, 0 },
4960 { "pred.rel.clear", dot_pred_rel, 'c' },
4961 { "pred.rel.imply", dot_pred_rel, 'i' },
4962 { "pred.rel.mutex", dot_pred_rel, 'm' },
4963 { "pred.safe_across_calls", dot_pred_rel, 's' },
4964 { "reg.val", dot_reg_val, 0 },
4965 { "auto", dot_dv_mode, 'a' },
4966 { "explicit", dot_dv_mode, 'e' },
4967 { "default", dot_dv_mode, 'd' },
4969 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
4970 IA-64 aligns data allocation pseudo-ops by default, so we have to
4971 tell it that these ones are supposed to be unaligned. Long term,
4972 should rewrite so that only IA-64 specific data allocation pseudo-ops
4973 are aligned by default. */
4974 {"2byte", stmt_cons_ua, 2},
4975 {"4byte", stmt_cons_ua, 4},
4976 {"8byte", stmt_cons_ua, 8},
4981 static const struct pseudo_opcode
4984 void (*handler) (int);
4989 /* these are more like pseudo-ops, but don't start with a dot */
4990 { "data1", cons, 1 },
4991 { "data2", cons, 2 },
4992 { "data4", cons, 4 },
4993 { "data8", cons, 8 },
4994 { "data16", cons, 16 },
4995 { "real4", stmt_float_cons, 'f' },
4996 { "real8", stmt_float_cons, 'd' },
4997 { "real10", stmt_float_cons, 'x' },
4998 { "real16", stmt_float_cons, 'X' },
4999 { "string", stringer, 0 },
5000 { "stringz", stringer, 1 },
5002 /* unaligned versions: */
5003 { "data2.ua", stmt_cons_ua, 2 },
5004 { "data4.ua", stmt_cons_ua, 4 },
5005 { "data8.ua", stmt_cons_ua, 8 },
5006 { "data16.ua", stmt_cons_ua, 16 },
5007 { "real4.ua", float_cons, 'f' },
5008 { "real8.ua", float_cons, 'd' },
5009 { "real10.ua", float_cons, 'x' },
5010 { "real16.ua", float_cons, 'X' },
5013 /* Declare a register by creating a symbol for it and entering it in
5014 the symbol table. */
5017 declare_register (name, regnum)
5024 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5026 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5028 as_fatal ("Inserting \"%s\" into register table failed: %s",
5035 declare_register_set (prefix, num_regs, base_regnum)
5043 for (i = 0; i < num_regs; ++i)
5045 sprintf (name, "%s%u", prefix, i);
5046 declare_register (name, base_regnum + i);
5051 operand_width (opnd)
5052 enum ia64_opnd opnd;
5054 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5055 unsigned int bits = 0;
5059 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5060 bits += odesc->field[i].bits;
5065 static enum operand_match_result
5066 operand_match (idesc, index, e)
5067 const struct ia64_opcode *idesc;
5071 enum ia64_opnd opnd = idesc->operands[index];
5072 int bits, relocatable = 0;
5073 struct insn_fix *fix;
5080 case IA64_OPND_AR_CCV:
5081 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5082 return OPERAND_MATCH;
5085 case IA64_OPND_AR_CSD:
5086 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5087 return OPERAND_MATCH;
5090 case IA64_OPND_AR_PFS:
5091 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5092 return OPERAND_MATCH;
5096 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5097 return OPERAND_MATCH;
5101 if (e->X_op == O_register && e->X_add_number == REG_IP)
5102 return OPERAND_MATCH;
5106 if (e->X_op == O_register && e->X_add_number == REG_PR)
5107 return OPERAND_MATCH;
5110 case IA64_OPND_PR_ROT:
5111 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5112 return OPERAND_MATCH;
5116 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5117 return OPERAND_MATCH;
5120 case IA64_OPND_PSR_L:
5121 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5122 return OPERAND_MATCH;
5125 case IA64_OPND_PSR_UM:
5126 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5127 return OPERAND_MATCH;
5131 if (e->X_op == O_constant)
5133 if (e->X_add_number == 1)
5134 return OPERAND_MATCH;
5136 return OPERAND_OUT_OF_RANGE;
5141 if (e->X_op == O_constant)
5143 if (e->X_add_number == 8)
5144 return OPERAND_MATCH;
5146 return OPERAND_OUT_OF_RANGE;
5151 if (e->X_op == O_constant)
5153 if (e->X_add_number == 16)
5154 return OPERAND_MATCH;
5156 return OPERAND_OUT_OF_RANGE;
5160 /* register operands: */
5163 if (e->X_op == O_register && e->X_add_number >= REG_AR
5164 && e->X_add_number < REG_AR + 128)
5165 return OPERAND_MATCH;
5170 if (e->X_op == O_register && e->X_add_number >= REG_BR
5171 && e->X_add_number < REG_BR + 8)
5172 return OPERAND_MATCH;
5176 if (e->X_op == O_register && e->X_add_number >= REG_CR
5177 && e->X_add_number < REG_CR + 128)
5178 return OPERAND_MATCH;
5185 if (e->X_op == O_register && e->X_add_number >= REG_FR
5186 && e->X_add_number < REG_FR + 128)
5187 return OPERAND_MATCH;
5192 if (e->X_op == O_register && e->X_add_number >= REG_P
5193 && e->X_add_number < REG_P + 64)
5194 return OPERAND_MATCH;
5200 if (e->X_op == O_register && e->X_add_number >= REG_GR
5201 && e->X_add_number < REG_GR + 128)
5202 return OPERAND_MATCH;
5205 case IA64_OPND_R3_2:
5206 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5208 if (e->X_add_number < REG_GR + 4)
5209 return OPERAND_MATCH;
5210 else if (e->X_add_number < REG_GR + 128)
5211 return OPERAND_OUT_OF_RANGE;
5215 /* indirect operands: */
5216 case IA64_OPND_CPUID_R3:
5217 case IA64_OPND_DBR_R3:
5218 case IA64_OPND_DTR_R3:
5219 case IA64_OPND_ITR_R3:
5220 case IA64_OPND_IBR_R3:
5221 case IA64_OPND_MSR_R3:
5222 case IA64_OPND_PKR_R3:
5223 case IA64_OPND_PMC_R3:
5224 case IA64_OPND_PMD_R3:
5225 case IA64_OPND_RR_R3:
5226 if (e->X_op == O_index && e->X_op_symbol
5227 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5228 == opnd - IA64_OPND_CPUID_R3))
5229 return OPERAND_MATCH;
5233 if (e->X_op == O_index && !e->X_op_symbol)
5234 return OPERAND_MATCH;
5237 /* immediate operands: */
5238 case IA64_OPND_CNT2a:
5239 case IA64_OPND_LEN4:
5240 case IA64_OPND_LEN6:
5241 bits = operand_width (idesc->operands[index]);
5242 if (e->X_op == O_constant)
5244 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5245 return OPERAND_MATCH;
5247 return OPERAND_OUT_OF_RANGE;
5251 case IA64_OPND_CNT2b:
5252 if (e->X_op == O_constant)
5254 if ((bfd_vma) (e->X_add_number - 1) < 3)
5255 return OPERAND_MATCH;
5257 return OPERAND_OUT_OF_RANGE;
5261 case IA64_OPND_CNT2c:
5262 val = e->X_add_number;
5263 if (e->X_op == O_constant)
5265 if ((val == 0 || val == 7 || val == 15 || val == 16))
5266 return OPERAND_MATCH;
5268 return OPERAND_OUT_OF_RANGE;
5273 /* SOR must be an integer multiple of 8 */
5274 if (e->X_op == O_constant && e->X_add_number & 0x7)
5275 return OPERAND_OUT_OF_RANGE;
5278 if (e->X_op == O_constant)
5280 if ((bfd_vma) e->X_add_number <= 96)
5281 return OPERAND_MATCH;
5283 return OPERAND_OUT_OF_RANGE;
5287 case IA64_OPND_IMMU62:
5288 if (e->X_op == O_constant)
5290 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5291 return OPERAND_MATCH;
5293 return OPERAND_OUT_OF_RANGE;
5297 /* FIXME -- need 62-bit relocation type */
5298 as_bad (_("62-bit relocation not yet implemented"));
5302 case IA64_OPND_IMMU64:
5303 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5304 || e->X_op == O_subtract)
5306 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5307 fix->code = BFD_RELOC_IA64_IMM64;
5308 if (e->X_op != O_subtract)
5310 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5311 if (e->X_op == O_pseudo_fixup)
5315 fix->opnd = idesc->operands[index];
5318 ++CURR_SLOT.num_fixups;
5319 return OPERAND_MATCH;
5321 else if (e->X_op == O_constant)
5322 return OPERAND_MATCH;
5325 case IA64_OPND_CCNT5:
5326 case IA64_OPND_CNT5:
5327 case IA64_OPND_CNT6:
5328 case IA64_OPND_CPOS6a:
5329 case IA64_OPND_CPOS6b:
5330 case IA64_OPND_CPOS6c:
5331 case IA64_OPND_IMMU2:
5332 case IA64_OPND_IMMU7a:
5333 case IA64_OPND_IMMU7b:
5334 case IA64_OPND_IMMU21:
5335 case IA64_OPND_IMMU24:
5336 case IA64_OPND_MBTYPE4:
5337 case IA64_OPND_MHTYPE8:
5338 case IA64_OPND_POS6:
5339 bits = operand_width (idesc->operands[index]);
5340 if (e->X_op == O_constant)
5342 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5343 return OPERAND_MATCH;
5345 return OPERAND_OUT_OF_RANGE;
5349 case IA64_OPND_IMMU9:
5350 bits = operand_width (idesc->operands[index]);
5351 if (e->X_op == O_constant)
5353 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5355 int lobits = e->X_add_number & 0x3;
5356 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5357 e->X_add_number |= (bfd_vma) 0x3;
5358 return OPERAND_MATCH;
5361 return OPERAND_OUT_OF_RANGE;
5365 case IA64_OPND_IMM44:
5366 /* least 16 bits must be zero */
5367 if ((e->X_add_number & 0xffff) != 0)
5368 /* XXX technically, this is wrong: we should not be issuing warning
5369 messages until we're sure this instruction pattern is going to
5371 as_warn (_("lower 16 bits of mask ignored"));
5373 if (e->X_op == O_constant)
5375 if (((e->X_add_number >= 0
5376 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5377 || (e->X_add_number < 0
5378 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5381 if (e->X_add_number >= 0
5382 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5384 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5386 return OPERAND_MATCH;
5389 return OPERAND_OUT_OF_RANGE;
5393 case IA64_OPND_IMM17:
5394 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5395 if (e->X_op == O_constant)
5397 if (((e->X_add_number >= 0
5398 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5399 || (e->X_add_number < 0
5400 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5403 if (e->X_add_number >= 0
5404 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5406 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5408 return OPERAND_MATCH;
5411 return OPERAND_OUT_OF_RANGE;
5415 case IA64_OPND_IMM14:
5416 case IA64_OPND_IMM22:
5418 case IA64_OPND_IMM1:
5419 case IA64_OPND_IMM8:
5420 case IA64_OPND_IMM8U4:
5421 case IA64_OPND_IMM8M1:
5422 case IA64_OPND_IMM8M1U4:
5423 case IA64_OPND_IMM8M1U8:
5424 case IA64_OPND_IMM9a:
5425 case IA64_OPND_IMM9b:
5426 bits = operand_width (idesc->operands[index]);
5427 if (relocatable && (e->X_op == O_symbol
5428 || e->X_op == O_subtract
5429 || e->X_op == O_pseudo_fixup))
5431 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5433 if (idesc->operands[index] == IA64_OPND_IMM14)
5434 fix->code = BFD_RELOC_IA64_IMM14;
5436 fix->code = BFD_RELOC_IA64_IMM22;
5438 if (e->X_op != O_subtract)
5440 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5441 if (e->X_op == O_pseudo_fixup)
5445 fix->opnd = idesc->operands[index];
5448 ++CURR_SLOT.num_fixups;
5449 return OPERAND_MATCH;
5451 else if (e->X_op != O_constant
5452 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5453 return OPERAND_MISMATCH;
5455 if (opnd == IA64_OPND_IMM8M1U4)
5457 /* Zero is not valid for unsigned compares that take an adjusted
5458 constant immediate range. */
5459 if (e->X_add_number == 0)
5460 return OPERAND_OUT_OF_RANGE;
5462 /* Sign-extend 32-bit unsigned numbers, so that the following range
5463 checks will work. */
5464 val = e->X_add_number;
5465 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5466 && ((val & ((bfd_vma) 1 << 31)) != 0))
5467 val = ((val << 32) >> 32);
5469 /* Check for 0x100000000. This is valid because
5470 0x100000000-1 is the same as ((uint32_t) -1). */
5471 if (val == ((bfd_signed_vma) 1 << 32))
5472 return OPERAND_MATCH;
5476 else if (opnd == IA64_OPND_IMM8M1U8)
5478 /* Zero is not valid for unsigned compares that take an adjusted
5479 constant immediate range. */
5480 if (e->X_add_number == 0)
5481 return OPERAND_OUT_OF_RANGE;
5483 /* Check for 0x10000000000000000. */
5484 if (e->X_op == O_big)
5486 if (generic_bignum[0] == 0
5487 && generic_bignum[1] == 0
5488 && generic_bignum[2] == 0
5489 && generic_bignum[3] == 0
5490 && generic_bignum[4] == 1)
5491 return OPERAND_MATCH;
5493 return OPERAND_OUT_OF_RANGE;
5496 val = e->X_add_number - 1;
5498 else if (opnd == IA64_OPND_IMM8M1)
5499 val = e->X_add_number - 1;
5500 else if (opnd == IA64_OPND_IMM8U4)
5502 /* Sign-extend 32-bit unsigned numbers, so that the following range
5503 checks will work. */
5504 val = e->X_add_number;
5505 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5506 && ((val & ((bfd_vma) 1 << 31)) != 0))
5507 val = ((val << 32) >> 32);
5510 val = e->X_add_number;
5512 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5513 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5514 return OPERAND_MATCH;
5516 return OPERAND_OUT_OF_RANGE;
5518 case IA64_OPND_INC3:
5519 /* +/- 1, 4, 8, 16 */
5520 val = e->X_add_number;
5523 if (e->X_op == O_constant)
5525 if ((val == 1 || val == 4 || val == 8 || val == 16))
5526 return OPERAND_MATCH;
5528 return OPERAND_OUT_OF_RANGE;
5532 case IA64_OPND_TGT25:
5533 case IA64_OPND_TGT25b:
5534 case IA64_OPND_TGT25c:
5535 case IA64_OPND_TGT64:
5536 if (e->X_op == O_symbol)
5538 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5539 if (opnd == IA64_OPND_TGT25)
5540 fix->code = BFD_RELOC_IA64_PCREL21F;
5541 else if (opnd == IA64_OPND_TGT25b)
5542 fix->code = BFD_RELOC_IA64_PCREL21M;
5543 else if (opnd == IA64_OPND_TGT25c)
5544 fix->code = BFD_RELOC_IA64_PCREL21B;
5545 else if (opnd == IA64_OPND_TGT64)
5546 fix->code = BFD_RELOC_IA64_PCREL60B;
5550 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5551 fix->opnd = idesc->operands[index];
5554 ++CURR_SLOT.num_fixups;
5555 return OPERAND_MATCH;
5557 case IA64_OPND_TAG13:
5558 case IA64_OPND_TAG13b:
5562 return OPERAND_MATCH;
5565 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5566 /* There are no external relocs for TAG13/TAG13b fields, so we
5567 create a dummy reloc. This will not live past md_apply_fix3. */
5568 fix->code = BFD_RELOC_UNUSED;
5569 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5570 fix->opnd = idesc->operands[index];
5573 ++CURR_SLOT.num_fixups;
5574 return OPERAND_MATCH;
5581 case IA64_OPND_LDXMOV:
5582 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5583 fix->code = BFD_RELOC_IA64_LDXMOV;
5584 fix->opnd = idesc->operands[index];
5587 ++CURR_SLOT.num_fixups;
5588 return OPERAND_MATCH;
5593 return OPERAND_MISMATCH;
5602 memset (e, 0, sizeof (*e));
5605 if (*input_line_pointer != '}')
5607 sep = *input_line_pointer++;
5611 if (!md.manual_bundling)
5612 as_warn ("Found '}' when manual bundling is off");
5614 CURR_SLOT.manual_bundling_off = 1;
5615 md.manual_bundling = 0;
5621 /* Returns the next entry in the opcode table that matches the one in
5622 IDESC, and frees the entry in IDESC. If no matching entry is
5623 found, NULL is returned instead. */
5625 static struct ia64_opcode *
5626 get_next_opcode (struct ia64_opcode *idesc)
5628 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5629 ia64_free_opcode (idesc);
5633 /* Parse the operands for the opcode and find the opcode variant that
5634 matches the specified operands, or NULL if no match is possible. */
5636 static struct ia64_opcode *
5637 parse_operands (idesc)
5638 struct ia64_opcode *idesc;
5640 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5641 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5642 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5643 enum operand_match_result result;
5645 char *first_arg = 0, *end, *saved_input_pointer;
5648 assert (strlen (idesc->name) <= 128);
5650 strcpy (mnemonic, idesc->name);
5651 if (idesc->operands[2] == IA64_OPND_SOF)
5653 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5654 can't parse the first operand until we have parsed the
5655 remaining operands of the "alloc" instruction. */
5657 first_arg = input_line_pointer;
5658 end = strchr (input_line_pointer, '=');
5661 as_bad ("Expected separator `='");
5664 input_line_pointer = end + 1;
5669 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5671 sep = parse_operand (CURR_SLOT.opnd + i);
5672 if (CURR_SLOT.opnd[i].X_op == O_absent)
5677 if (sep != '=' && sep != ',')
5682 if (num_outputs > 0)
5683 as_bad ("Duplicate equal sign (=) in instruction");
5685 num_outputs = i + 1;
5690 as_bad ("Illegal operand separator `%c'", sep);
5694 if (idesc->operands[2] == IA64_OPND_SOF)
5696 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5697 know (strcmp (idesc->name, "alloc") == 0);
5698 if (num_operands == 5 /* first_arg not included in this count! */
5699 && CURR_SLOT.opnd[2].X_op == O_constant
5700 && CURR_SLOT.opnd[3].X_op == O_constant
5701 && CURR_SLOT.opnd[4].X_op == O_constant
5702 && CURR_SLOT.opnd[5].X_op == O_constant)
5704 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5705 CURR_SLOT.opnd[3].X_add_number,
5706 CURR_SLOT.opnd[4].X_add_number,
5707 CURR_SLOT.opnd[5].X_add_number);
5709 /* now we can parse the first arg: */
5710 saved_input_pointer = input_line_pointer;
5711 input_line_pointer = first_arg;
5712 sep = parse_operand (CURR_SLOT.opnd + 0);
5714 --num_outputs; /* force error */
5715 input_line_pointer = saved_input_pointer;
5717 CURR_SLOT.opnd[2].X_add_number = sof;
5718 CURR_SLOT.opnd[3].X_add_number
5719 = sof - CURR_SLOT.opnd[4].X_add_number;
5720 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5724 highest_unmatched_operand = 0;
5725 curr_out_of_range_pos = -1;
5727 expected_operand = idesc->operands[0];
5728 for (; idesc; idesc = get_next_opcode (idesc))
5730 if (num_outputs != idesc->num_outputs)
5731 continue; /* mismatch in # of outputs */
5733 CURR_SLOT.num_fixups = 0;
5735 /* Try to match all operands. If we see an out-of-range operand,
5736 then continue trying to match the rest of the operands, since if
5737 the rest match, then this idesc will give the best error message. */
5739 out_of_range_pos = -1;
5740 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5742 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5743 if (result != OPERAND_MATCH)
5745 if (result != OPERAND_OUT_OF_RANGE)
5747 if (out_of_range_pos < 0)
5748 /* remember position of the first out-of-range operand: */
5749 out_of_range_pos = i;
5753 /* If we did not match all operands, or if at least one operand was
5754 out-of-range, then this idesc does not match. Keep track of which
5755 idesc matched the most operands before failing. If we have two
5756 idescs that failed at the same position, and one had an out-of-range
5757 operand, then prefer the out-of-range operand. Thus if we have
5758 "add r0=0x1000000,r1" we get an error saying the constant is out
5759 of range instead of an error saying that the constant should have been
5762 if (i != num_operands || out_of_range_pos >= 0)
5764 if (i > highest_unmatched_operand
5765 || (i == highest_unmatched_operand
5766 && out_of_range_pos > curr_out_of_range_pos))
5768 highest_unmatched_operand = i;
5769 if (out_of_range_pos >= 0)
5771 expected_operand = idesc->operands[out_of_range_pos];
5772 error_pos = out_of_range_pos;
5776 expected_operand = idesc->operands[i];
5779 curr_out_of_range_pos = out_of_range_pos;
5784 if (num_operands < NELEMS (idesc->operands)
5785 && idesc->operands[num_operands])
5786 continue; /* mismatch in number of arguments */
5792 if (expected_operand)
5793 as_bad ("Operand %u of `%s' should be %s",
5794 error_pos + 1, mnemonic,
5795 elf64_ia64_operands[expected_operand].desc);
5797 as_bad ("Operand mismatch");
5803 /* Keep track of state necessary to determine whether a NOP is necessary
5804 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5805 detect a case where additional NOPs may be necessary. */
5807 errata_nop_necessary_p (slot, insn_unit)
5809 enum ia64_unit insn_unit;
5812 struct group *this_group = md.last_groups + md.group_idx;
5813 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5814 struct ia64_opcode *idesc = slot->idesc;
5816 /* Test whether this could be the first insn in a problematic sequence. */
5817 if (insn_unit == IA64_UNIT_F)
5819 for (i = 0; i < idesc->num_outputs; i++)
5820 if (idesc->operands[i] == IA64_OPND_P1
5821 || idesc->operands[i] == IA64_OPND_P2)
5823 int regno = slot->opnd[i].X_add_number - REG_P;
5824 /* Ignore invalid operands; they generate errors elsewhere. */
5827 this_group->p_reg_set[regno] = 1;
5831 /* Test whether this could be the second insn in a problematic sequence. */
5832 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5833 && prev_group->p_reg_set[slot->qp_regno])
5835 for (i = 0; i < idesc->num_outputs; i++)
5836 if (idesc->operands[i] == IA64_OPND_R1
5837 || idesc->operands[i] == IA64_OPND_R2
5838 || idesc->operands[i] == IA64_OPND_R3)
5840 int regno = slot->opnd[i].X_add_number - REG_GR;
5841 /* Ignore invalid operands; they generate errors elsewhere. */
5844 if (strncmp (idesc->name, "add", 3) != 0
5845 && strncmp (idesc->name, "sub", 3) != 0
5846 && strncmp (idesc->name, "shladd", 6) != 0
5847 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5848 this_group->g_reg_set_conditionally[regno] = 1;
5852 /* Test whether this could be the third insn in a problematic sequence. */
5853 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5855 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5856 idesc->operands[i] == IA64_OPND_R3
5857 /* For mov indirect. */
5858 || idesc->operands[i] == IA64_OPND_RR_R3
5859 || idesc->operands[i] == IA64_OPND_DBR_R3
5860 || idesc->operands[i] == IA64_OPND_IBR_R3
5861 || idesc->operands[i] == IA64_OPND_PKR_R3
5862 || idesc->operands[i] == IA64_OPND_PMC_R3
5863 || idesc->operands[i] == IA64_OPND_PMD_R3
5864 || idesc->operands[i] == IA64_OPND_MSR_R3
5865 || idesc->operands[i] == IA64_OPND_CPUID_R3
5867 || idesc->operands[i] == IA64_OPND_ITR_R3
5868 || idesc->operands[i] == IA64_OPND_DTR_R3
5869 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5870 || idesc->operands[i] == IA64_OPND_MR3)
5872 int regno = slot->opnd[i].X_add_number - REG_GR;
5873 /* Ignore invalid operands; they generate errors elsewhere. */
5876 if (idesc->operands[i] == IA64_OPND_R3)
5878 if (strcmp (idesc->name, "fc") != 0
5879 && strcmp (idesc->name, "tak") != 0
5880 && strcmp (idesc->name, "thash") != 0
5881 && strcmp (idesc->name, "tpa") != 0
5882 && strcmp (idesc->name, "ttag") != 0
5883 && strncmp (idesc->name, "ptr", 3) != 0
5884 && strncmp (idesc->name, "ptc", 3) != 0
5885 && strncmp (idesc->name, "probe", 5) != 0)
5888 if (prev_group->g_reg_set_conditionally[regno])
5896 build_insn (slot, insnp)
5900 const struct ia64_operand *odesc, *o2desc;
5901 struct ia64_opcode *idesc = slot->idesc;
5902 bfd_signed_vma insn, val;
5906 insn = idesc->opcode | slot->qp_regno;
5908 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5910 if (slot->opnd[i].X_op == O_register
5911 || slot->opnd[i].X_op == O_constant
5912 || slot->opnd[i].X_op == O_index)
5913 val = slot->opnd[i].X_add_number;
5914 else if (slot->opnd[i].X_op == O_big)
5916 /* This must be the value 0x10000000000000000. */
5917 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5923 switch (idesc->operands[i])
5925 case IA64_OPND_IMMU64:
5926 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5927 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5928 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5929 | (((val >> 63) & 0x1) << 36));
5932 case IA64_OPND_IMMU62:
5933 val &= 0x3fffffffffffffffULL;
5934 if (val != slot->opnd[i].X_add_number)
5935 as_warn (_("Value truncated to 62 bits"));
5936 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5937 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5940 case IA64_OPND_TGT64:
5942 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5943 insn |= ((((val >> 59) & 0x1) << 36)
5944 | (((val >> 0) & 0xfffff) << 13));
5975 case IA64_OPND_R3_2:
5976 case IA64_OPND_CPUID_R3:
5977 case IA64_OPND_DBR_R3:
5978 case IA64_OPND_DTR_R3:
5979 case IA64_OPND_ITR_R3:
5980 case IA64_OPND_IBR_R3:
5982 case IA64_OPND_MSR_R3:
5983 case IA64_OPND_PKR_R3:
5984 case IA64_OPND_PMC_R3:
5985 case IA64_OPND_PMD_R3:
5986 case IA64_OPND_RR_R3:
5994 odesc = elf64_ia64_operands + idesc->operands[i];
5995 err = (*odesc->insert) (odesc, val, &insn);
5997 as_bad_where (slot->src_file, slot->src_line,
5998 "Bad operand value: %s", err);
5999 if (idesc->flags & IA64_OPCODE_PSEUDO)
6001 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6002 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6004 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6005 (*o2desc->insert) (o2desc, val, &insn);
6007 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6008 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6009 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6011 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6012 (*o2desc->insert) (o2desc, 64 - val, &insn);
6022 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
6023 unsigned int manual_bundling = 0;
6024 enum ia64_unit required_unit, insn_unit = 0;
6025 enum ia64_insn_type type[3], insn_type;
6026 unsigned int template, orig_template;
6027 bfd_vma insn[3] = { -1, -1, -1 };
6028 struct ia64_opcode *idesc;
6029 int end_of_insn_group = 0, user_template = -1;
6030 int n, i, j, first, curr;
6032 bfd_vma t0 = 0, t1 = 0;
6033 struct label_fix *lfix;
6034 struct insn_fix *ifix;
6039 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6040 know (first >= 0 & first < NUM_SLOTS);
6041 n = MIN (3, md.num_slots_in_use);
6043 /* Determine template: user user_template if specified, best match
6046 if (md.slot[first].user_template >= 0)
6047 user_template = template = md.slot[first].user_template;
6050 /* Auto select appropriate template. */
6051 memset (type, 0, sizeof (type));
6053 for (i = 0; i < n; ++i)
6055 if (md.slot[curr].label_fixups && i != 0)
6057 type[i] = md.slot[curr].idesc->type;
6058 curr = (curr + 1) % NUM_SLOTS;
6060 template = best_template[type[0]][type[1]][type[2]];
6063 /* initialize instructions with appropriate nops: */
6064 for (i = 0; i < 3; ++i)
6065 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6069 /* now fill in slots with as many insns as possible: */
6071 idesc = md.slot[curr].idesc;
6072 end_of_insn_group = 0;
6073 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6075 /* Set the slot number for prologue/body records now as those
6076 refer to the current point, not the point after the
6077 instruction has been issued: */
6078 /* Don't try to delete prologue/body records here, as that will cause
6079 them to also be deleted from the master list of unwind records. */
6080 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6081 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6082 || ptr->r.type == body)
6084 ptr->slot_number = (unsigned long) f + i;
6085 ptr->slot_frag = frag_now;
6088 if (idesc->flags & IA64_OPCODE_SLOT2)
6090 if (manual_bundling && i != 2)
6091 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6092 "`%s' must be last in bundle", idesc->name);
6096 if (idesc->flags & IA64_OPCODE_LAST)
6099 unsigned int required_template;
6101 /* If we need a stop bit after an M slot, our only choice is
6102 template 5 (M;;MI). If we need a stop bit after a B
6103 slot, our only choice is to place it at the end of the
6104 bundle, because the only available templates are MIB,
6105 MBB, BBB, MMB, and MFB. We don't handle anything other
6106 than M and B slots because these are the only kind of
6107 instructions that can have the IA64_OPCODE_LAST bit set. */
6108 required_template = template;
6109 switch (idesc->type)
6113 required_template = 5;
6121 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6122 "Internal error: don't know how to force %s to end"
6123 "of instruction group", idesc->name);
6127 if (manual_bundling && i != required_slot)
6128 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6129 "`%s' must be last in instruction group",
6131 if (required_slot < i)
6132 /* Can't fit this instruction. */
6136 if (required_template != template)
6138 /* If we switch the template, we need to reset the NOPs
6139 after slot i. The slot-types of the instructions ahead
6140 of i never change, so we don't need to worry about
6141 changing NOPs in front of this slot. */
6142 for (j = i; j < 3; ++j)
6143 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6145 template = required_template;
6147 if (curr != first && md.slot[curr].label_fixups)
6149 if (manual_bundling_on)
6150 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6151 "Label must be first in a bundle");
6152 /* This insn must go into the first slot of a bundle. */
6156 manual_bundling_on = md.slot[curr].manual_bundling_on;
6157 manual_bundling_off = md.slot[curr].manual_bundling_off;
6159 if (manual_bundling_on)
6162 manual_bundling = 1;
6164 break; /* need to start a new bundle */
6167 if (end_of_insn_group && md.num_slots_in_use >= 1)
6169 /* We need an instruction group boundary in the middle of a
6170 bundle. See if we can switch to an other template with
6171 an appropriate boundary. */
6173 orig_template = template;
6174 if (i == 1 && (user_template == 4
6175 || (user_template < 0
6176 && (ia64_templ_desc[template].exec_unit[0]
6180 end_of_insn_group = 0;
6182 else if (i == 2 && (user_template == 0
6183 || (user_template < 0
6184 && (ia64_templ_desc[template].exec_unit[1]
6186 /* This test makes sure we don't switch the template if
6187 the next instruction is one that needs to be first in
6188 an instruction group. Since all those instructions are
6189 in the M group, there is no way such an instruction can
6190 fit in this bundle even if we switch the template. The
6191 reason we have to check for this is that otherwise we
6192 may end up generating "MI;;I M.." which has the deadly
6193 effect that the second M instruction is no longer the
6194 first in the bundle! --davidm 99/12/16 */
6195 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6198 end_of_insn_group = 0;
6200 else if (curr != first)
6201 /* can't fit this insn */
6204 if (template != orig_template)
6205 /* if we switch the template, we need to reset the NOPs
6206 after slot i. The slot-types of the instructions ahead
6207 of i never change, so we don't need to worry about
6208 changing NOPs in front of this slot. */
6209 for (j = i; j < 3; ++j)
6210 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6212 required_unit = ia64_templ_desc[template].exec_unit[i];
6214 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6215 if (idesc->type == IA64_TYPE_DYN)
6217 if ((strcmp (idesc->name, "nop") == 0)
6218 || (strcmp (idesc->name, "hint") == 0)
6219 || (strcmp (idesc->name, "break") == 0))
6220 insn_unit = required_unit;
6221 else if (strcmp (idesc->name, "chk.s") == 0)
6223 insn_unit = IA64_UNIT_M;
6224 if (required_unit == IA64_UNIT_I)
6225 insn_unit = IA64_UNIT_I;
6228 as_fatal ("emit_one_bundle: unexpected dynamic op");
6230 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6231 ia64_free_opcode (idesc);
6232 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6234 know (!idesc->next); /* no resolved dynamic ops have collisions */
6239 insn_type = idesc->type;
6240 insn_unit = IA64_UNIT_NIL;
6244 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6245 insn_unit = required_unit;
6247 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6248 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6249 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6250 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6251 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6256 if (insn_unit != required_unit)
6258 if (required_unit == IA64_UNIT_L
6259 && insn_unit == IA64_UNIT_I
6260 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6262 /* we got ourselves an MLX template but the current
6263 instruction isn't an X-unit, or an I-unit instruction
6264 that can go into the X slot of an MLX template. Duh. */
6265 if (md.num_slots_in_use >= NUM_SLOTS)
6267 as_bad_where (md.slot[curr].src_file,
6268 md.slot[curr].src_line,
6269 "`%s' can't go in X slot of "
6270 "MLX template", idesc->name);
6271 /* drop this insn so we don't livelock: */
6272 --md.num_slots_in_use;
6276 continue; /* try next slot */
6282 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6283 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6286 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6287 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6289 build_insn (md.slot + curr, insn + i);
6291 /* Set slot counts for non prologue/body unwind records. */
6292 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6293 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
6294 && ptr->r.type != body)
6296 ptr->slot_number = (unsigned long) f + i;
6297 ptr->slot_frag = frag_now;
6299 md.slot[curr].unwind_record = NULL;
6301 if (required_unit == IA64_UNIT_L)
6304 /* skip one slot for long/X-unit instructions */
6307 --md.num_slots_in_use;
6309 /* now is a good time to fix up the labels for this insn: */
6310 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6312 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6313 symbol_set_frag (lfix->sym, frag_now);
6315 /* and fix up the tags also. */
6316 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6318 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6319 symbol_set_frag (lfix->sym, frag_now);
6322 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6324 ifix = md.slot[curr].fixup + j;
6325 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6326 &ifix->expr, ifix->is_pcrel, ifix->code);
6327 fix->tc_fix_data.opnd = ifix->opnd;
6328 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6329 fix->fx_file = md.slot[curr].src_file;
6330 fix->fx_line = md.slot[curr].src_line;
6333 end_of_insn_group = md.slot[curr].end_of_insn_group;
6335 if (end_of_insn_group)
6337 md.group_idx = (md.group_idx + 1) % 3;
6338 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6342 ia64_free_opcode (md.slot[curr].idesc);
6343 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6344 md.slot[curr].user_template = -1;
6346 if (manual_bundling_off)
6348 manual_bundling = 0;
6351 curr = (curr + 1) % NUM_SLOTS;
6352 idesc = md.slot[curr].idesc;
6354 if (manual_bundling)
6356 if (md.num_slots_in_use > 0)
6357 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6358 "`%s' does not fit into %s template",
6359 idesc->name, ia64_templ_desc[template].name);
6361 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6362 "Missing '}' at end of file");
6364 know (md.num_slots_in_use < NUM_SLOTS);
6366 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6367 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6369 number_to_chars_littleendian (f + 0, t0, 8);
6370 number_to_chars_littleendian (f + 8, t1, 8);
6372 unwind.next_slot_number = (unsigned long) f + 16;
6373 unwind.next_slot_frag = frag_now;
6377 md_parse_option (c, arg)
6384 /* Switches from the Intel assembler. */
6386 if (strcmp (arg, "ilp64") == 0
6387 || strcmp (arg, "lp64") == 0
6388 || strcmp (arg, "p64") == 0)
6390 md.flags |= EF_IA_64_ABI64;
6392 else if (strcmp (arg, "ilp32") == 0)
6394 md.flags &= ~EF_IA_64_ABI64;
6396 else if (strcmp (arg, "le") == 0)
6398 md.flags &= ~EF_IA_64_BE;
6400 else if (strcmp (arg, "be") == 0)
6402 md.flags |= EF_IA_64_BE;
6409 if (strcmp (arg, "so") == 0)
6411 /* Suppress signon message. */
6413 else if (strcmp (arg, "pi") == 0)
6415 /* Reject privileged instructions. FIXME */
6417 else if (strcmp (arg, "us") == 0)
6419 /* Allow union of signed and unsigned range. FIXME */
6421 else if (strcmp (arg, "close_fcalls") == 0)
6423 /* Do not resolve global function calls. */
6430 /* temp[="prefix"] Insert temporary labels into the object file
6431 symbol table prefixed by "prefix".
6432 Default prefix is ":temp:".
6437 /* indirect=<tgt> Assume unannotated indirect branches behavior
6438 according to <tgt> --
6439 exit: branch out from the current context (default)
6440 labels: all labels in context may be branch targets
6442 if (strncmp (arg, "indirect=", 9) != 0)
6447 /* -X conflicts with an ignored option, use -x instead */
6449 if (!arg || strcmp (arg, "explicit") == 0)
6451 /* set default mode to explicit */
6452 md.default_explicit_mode = 1;
6455 else if (strcmp (arg, "auto") == 0)
6457 md.default_explicit_mode = 0;
6459 else if (strcmp (arg, "debug") == 0)
6463 else if (strcmp (arg, "debugx") == 0)
6465 md.default_explicit_mode = 1;
6470 as_bad (_("Unrecognized option '-x%s'"), arg);
6475 /* nops Print nops statistics. */
6478 /* GNU specific switches for gcc. */
6479 case OPTION_MCONSTANT_GP:
6480 md.flags |= EF_IA_64_CONS_GP;
6483 case OPTION_MAUTO_PIC:
6484 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6495 md_show_usage (stream)
6500 --mconstant-gp mark output file as using the constant-GP model\n\
6501 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6502 --mauto-pic mark output file as using the constant-GP model\n\
6503 without function descriptors (sets ELF header flag\n\
6504 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6505 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6506 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6507 -x | -xexplicit turn on dependency violation checking (default)\n\
6508 -xauto automagically remove dependency violations\n\
6509 -xdebug debug dependency violation checker\n"),
6514 ia64_after_parse_args ()
6516 if (debug_type == DEBUG_STABS)
6517 as_fatal (_("--gstabs is not supported for ia64"));
6520 /* Return true if TYPE fits in TEMPL at SLOT. */
6523 match (int templ, int type, int slot)
6525 enum ia64_unit unit;
6528 unit = ia64_templ_desc[templ].exec_unit[slot];
6531 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6533 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6535 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6536 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6537 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6538 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6539 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6540 default: result = 0; break;
6545 /* Add a bit of extra goodness if a nop of type F or B would fit
6546 in TEMPL at SLOT. */
6549 extra_goodness (int templ, int slot)
6551 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6553 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6558 /* This function is called once, at assembler startup time. It sets
6559 up all the tables, etc. that the MD part of the assembler will need
6560 that can be determined before arguments are parsed. */
6564 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6569 md.explicit_mode = md.default_explicit_mode;
6571 bfd_set_section_alignment (stdoutput, text_section, 4);
6573 /* Make sure fucntion pointers get initialized. */
6574 target_big_endian = -1;
6575 dot_byteorder (TARGET_BYTES_BIG_ENDIAN);
6577 alias_hash = hash_new ();
6578 alias_name_hash = hash_new ();
6579 secalias_hash = hash_new ();
6580 secalias_name_hash = hash_new ();
6582 pseudo_func[FUNC_DTP_MODULE].u.sym =
6583 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6584 &zero_address_frag);
6586 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6587 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6588 &zero_address_frag);
6590 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6591 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6592 &zero_address_frag);
6594 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6595 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6596 &zero_address_frag);
6598 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6599 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6600 &zero_address_frag);
6602 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6603 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6604 &zero_address_frag);
6606 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6607 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6608 &zero_address_frag);
6610 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6611 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6612 &zero_address_frag);
6614 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6615 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6616 &zero_address_frag);
6618 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6619 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6620 &zero_address_frag);
6622 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6623 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6624 &zero_address_frag);
6626 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6627 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6628 &zero_address_frag);
6630 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6631 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6632 &zero_address_frag);
6634 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6635 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6636 &zero_address_frag);
6638 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6639 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6640 &zero_address_frag);
6642 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6643 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6644 &zero_address_frag);
6646 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6647 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6648 &zero_address_frag);
6650 /* Compute the table of best templates. We compute goodness as a
6651 base 4 value, in which each match counts for 3, each F counts
6652 for 2, each B counts for 1. This should maximize the number of
6653 F and B nops in the chosen bundles, which is good because these
6654 pipelines are least likely to be overcommitted. */
6655 for (i = 0; i < IA64_NUM_TYPES; ++i)
6656 for (j = 0; j < IA64_NUM_TYPES; ++j)
6657 for (k = 0; k < IA64_NUM_TYPES; ++k)
6660 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6663 if (match (t, i, 0))
6665 if (match (t, j, 1))
6667 if (match (t, k, 2))
6668 goodness = 3 + 3 + 3;
6670 goodness = 3 + 3 + extra_goodness (t, 2);
6672 else if (match (t, j, 2))
6673 goodness = 3 + 3 + extra_goodness (t, 1);
6677 goodness += extra_goodness (t, 1);
6678 goodness += extra_goodness (t, 2);
6681 else if (match (t, i, 1))
6683 if (match (t, j, 2))
6686 goodness = 3 + extra_goodness (t, 2);
6688 else if (match (t, i, 2))
6689 goodness = 3 + extra_goodness (t, 1);
6691 if (goodness > best)
6694 best_template[i][j][k] = t;
6699 for (i = 0; i < NUM_SLOTS; ++i)
6700 md.slot[i].user_template = -1;
6702 md.pseudo_hash = hash_new ();
6703 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6705 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6706 (void *) (pseudo_opcode + i));
6708 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6709 pseudo_opcode[i].name, err);
6712 md.reg_hash = hash_new ();
6713 md.dynreg_hash = hash_new ();
6714 md.const_hash = hash_new ();
6715 md.entry_hash = hash_new ();
6717 /* general registers: */
6720 for (i = 0; i < total; ++i)
6722 sprintf (name, "r%d", i - REG_GR);
6723 md.regsym[i] = declare_register (name, i);
6726 /* floating point registers: */
6728 for (; i < total; ++i)
6730 sprintf (name, "f%d", i - REG_FR);
6731 md.regsym[i] = declare_register (name, i);
6734 /* application registers: */
6737 for (; i < total; ++i)
6739 sprintf (name, "ar%d", i - REG_AR);
6740 md.regsym[i] = declare_register (name, i);
6743 /* control registers: */
6746 for (; i < total; ++i)
6748 sprintf (name, "cr%d", i - REG_CR);
6749 md.regsym[i] = declare_register (name, i);
6752 /* predicate registers: */
6754 for (; i < total; ++i)
6756 sprintf (name, "p%d", i - REG_P);
6757 md.regsym[i] = declare_register (name, i);
6760 /* branch registers: */
6762 for (; i < total; ++i)
6764 sprintf (name, "b%d", i - REG_BR);
6765 md.regsym[i] = declare_register (name, i);
6768 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6769 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6770 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6771 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6772 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6773 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6774 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6776 for (i = 0; i < NELEMS (indirect_reg); ++i)
6778 regnum = indirect_reg[i].regnum;
6779 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6782 /* define synonyms for application registers: */
6783 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6784 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6785 REG_AR + ar[i - REG_AR].regnum);
6787 /* define synonyms for control registers: */
6788 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6789 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6790 REG_CR + cr[i - REG_CR].regnum);
6792 declare_register ("gp", REG_GR + 1);
6793 declare_register ("sp", REG_GR + 12);
6794 declare_register ("rp", REG_BR + 0);
6796 /* pseudo-registers used to specify unwind info: */
6797 declare_register ("psp", REG_PSP);
6799 declare_register_set ("ret", 4, REG_GR + 8);
6800 declare_register_set ("farg", 8, REG_FR + 8);
6801 declare_register_set ("fret", 8, REG_FR + 8);
6803 for (i = 0; i < NELEMS (const_bits); ++i)
6805 err = hash_insert (md.const_hash, const_bits[i].name,
6806 (PTR) (const_bits + i));
6808 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6812 /* Set the architecture and machine depending on defaults and command line
6814 if (md.flags & EF_IA_64_ABI64)
6815 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6817 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6820 as_warn (_("Could not set architecture and machine"));
6822 /* Set the pointer size and pointer shift size depending on md.flags */
6824 if (md.flags & EF_IA_64_ABI64)
6826 md.pointer_size = 8; /* pointers are 8 bytes */
6827 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6831 md.pointer_size = 4; /* pointers are 4 bytes */
6832 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6835 md.mem_offset.hint = 0;
6838 md.entry_labels = NULL;
6841 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6842 because that is called after md_parse_option which is where we do the
6843 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6844 default endianness. */
6847 ia64_init (argc, argv)
6848 int argc ATTRIBUTE_UNUSED;
6849 char **argv ATTRIBUTE_UNUSED;
6851 md.flags = MD_FLAGS_DEFAULT;
6854 /* Return a string for the target object file format. */
6857 ia64_target_format ()
6859 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6861 if (md.flags & EF_IA_64_BE)
6863 if (md.flags & EF_IA_64_ABI64)
6864 #if defined(TE_AIX50)
6865 return "elf64-ia64-aix-big";
6866 #elif defined(TE_HPUX)
6867 return "elf64-ia64-hpux-big";
6869 return "elf64-ia64-big";
6872 #if defined(TE_AIX50)
6873 return "elf32-ia64-aix-big";
6874 #elif defined(TE_HPUX)
6875 return "elf32-ia64-hpux-big";
6877 return "elf32-ia64-big";
6882 if (md.flags & EF_IA_64_ABI64)
6884 return "elf64-ia64-aix-little";
6886 return "elf64-ia64-little";
6890 return "elf32-ia64-aix-little";
6892 return "elf32-ia64-little";
6897 return "unknown-format";
6901 ia64_end_of_source ()
6903 /* terminate insn group upon reaching end of file: */
6904 insn_group_break (1, 0, 0);
6906 /* emits slots we haven't written yet: */
6907 ia64_flush_insns ();
6909 bfd_set_private_flags (stdoutput, md.flags);
6911 md.mem_offset.hint = 0;
6917 if (md.qp.X_op == O_register)
6918 as_bad ("qualifying predicate not followed by instruction");
6919 md.qp.X_op = O_absent;
6921 if (ignore_input ())
6924 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6926 if (md.detect_dv && !md.explicit_mode)
6927 as_warn (_("Explicit stops are ignored in auto mode"));
6929 insn_group_break (1, 0, 0);
6933 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
6935 static int defining_tag = 0;
6938 ia64_unrecognized_line (ch)
6944 expression (&md.qp);
6945 if (*input_line_pointer++ != ')')
6947 as_bad ("Expected ')'");
6950 if (md.qp.X_op != O_register)
6952 as_bad ("Qualifying predicate expected");
6955 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
6957 as_bad ("Predicate register expected");
6963 if (md.manual_bundling)
6964 as_warn ("Found '{' when manual bundling is already turned on");
6966 CURR_SLOT.manual_bundling_on = 1;
6967 md.manual_bundling = 1;
6969 /* Bundling is only acceptable in explicit mode
6970 or when in default automatic mode. */
6971 if (md.detect_dv && !md.explicit_mode)
6973 if (!md.mode_explicitly_set
6974 && !md.default_explicit_mode)
6977 as_warn (_("Found '{' after explicit switch to automatic mode"));
6982 if (!md.manual_bundling)
6983 as_warn ("Found '}' when manual bundling is off");
6985 PREV_SLOT.manual_bundling_off = 1;
6986 md.manual_bundling = 0;
6988 /* switch back to automatic mode, if applicable */
6991 && !md.mode_explicitly_set
6992 && !md.default_explicit_mode)
6995 /* Allow '{' to follow on the same line. We also allow ";;", but that
6996 happens automatically because ';' is an end of line marker. */
6998 if (input_line_pointer[0] == '{')
7000 input_line_pointer++;
7001 return ia64_unrecognized_line ('{');
7004 demand_empty_rest_of_line ();
7014 if (md.qp.X_op == O_register)
7016 as_bad ("Tag must come before qualifying predicate.");
7020 /* This implements just enough of read_a_source_file in read.c to
7021 recognize labels. */
7022 if (is_name_beginner (*input_line_pointer))
7024 s = input_line_pointer;
7025 c = get_symbol_end ();
7027 else if (LOCAL_LABELS_FB
7028 && ISDIGIT (*input_line_pointer))
7031 while (ISDIGIT (*input_line_pointer))
7032 temp = (temp * 10) + *input_line_pointer++ - '0';
7033 fb_label_instance_inc (temp);
7034 s = fb_label_name (temp, 0);
7035 c = *input_line_pointer;
7044 /* Put ':' back for error messages' sake. */
7045 *input_line_pointer++ = ':';
7046 as_bad ("Expected ':'");
7053 /* Put ':' back for error messages' sake. */
7054 *input_line_pointer++ = ':';
7055 if (*input_line_pointer++ != ']')
7057 as_bad ("Expected ']'");
7062 as_bad ("Tag name expected");
7072 /* Not a valid line. */
7077 ia64_frob_label (sym)
7080 struct label_fix *fix;
7082 /* Tags need special handling since they are not bundle breaks like
7086 fix = obstack_alloc (¬es, sizeof (*fix));
7088 fix->next = CURR_SLOT.tag_fixups;
7089 CURR_SLOT.tag_fixups = fix;
7094 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7096 md.last_text_seg = now_seg;
7097 fix = obstack_alloc (¬es, sizeof (*fix));
7099 fix->next = CURR_SLOT.label_fixups;
7100 CURR_SLOT.label_fixups = fix;
7102 /* Keep track of how many code entry points we've seen. */
7103 if (md.path == md.maxpaths)
7106 md.entry_labels = (const char **)
7107 xrealloc ((void *) md.entry_labels,
7108 md.maxpaths * sizeof (char *));
7110 md.entry_labels[md.path++] = S_GET_NAME (sym);
7115 ia64_flush_pending_output ()
7117 if (!md.keep_pending_output
7118 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7120 /* ??? This causes many unnecessary stop bits to be emitted.
7121 Unfortunately, it isn't clear if it is safe to remove this. */
7122 insn_group_break (1, 0, 0);
7123 ia64_flush_insns ();
7127 /* Do ia64-specific expression optimization. All that's done here is
7128 to transform index expressions that are either due to the indexing
7129 of rotating registers or due to the indexing of indirect register
7132 ia64_optimize_expr (l, op, r)
7141 if (l->X_op == O_register && r->X_op == O_constant)
7143 num_regs = (l->X_add_number >> 16);
7144 if ((unsigned) r->X_add_number >= num_regs)
7147 as_bad ("No current frame");
7149 as_bad ("Index out of range 0..%u", num_regs - 1);
7150 r->X_add_number = 0;
7152 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7155 else if (l->X_op == O_register && r->X_op == O_register)
7157 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7158 || l->X_add_number == IND_MEM)
7160 as_bad ("Indirect register set name expected");
7161 l->X_add_number = IND_CPUID;
7164 l->X_op_symbol = md.regsym[l->X_add_number];
7165 l->X_add_number = r->X_add_number;
7173 ia64_parse_name (name, e)
7177 struct const_desc *cdesc;
7178 struct dynreg *dr = 0;
7179 unsigned int regnum;
7183 /* first see if NAME is a known register name: */
7184 sym = hash_find (md.reg_hash, name);
7187 e->X_op = O_register;
7188 e->X_add_number = S_GET_VALUE (sym);
7192 cdesc = hash_find (md.const_hash, name);
7195 e->X_op = O_constant;
7196 e->X_add_number = cdesc->value;
7200 /* check for inN, locN, or outN: */
7204 if (name[1] == 'n' && ISDIGIT (name[2]))
7212 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7220 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7233 /* The name is inN, locN, or outN; parse the register number. */
7234 regnum = strtoul (name, &end, 10);
7235 if (end > name && *end == '\0')
7237 if ((unsigned) regnum >= dr->num_regs)
7240 as_bad ("No current frame");
7242 as_bad ("Register number out of range 0..%u",
7246 e->X_op = O_register;
7247 e->X_add_number = dr->base + regnum;
7252 if ((dr = hash_find (md.dynreg_hash, name)))
7254 /* We've got ourselves the name of a rotating register set.
7255 Store the base register number in the low 16 bits of
7256 X_add_number and the size of the register set in the top 16
7258 e->X_op = O_register;
7259 e->X_add_number = dr->base | (dr->num_regs << 16);
7265 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7268 ia64_canonicalize_symbol_name (name)
7271 size_t len = strlen (name);
7272 if (len > 1 && name[len - 1] == '#')
7273 name[len - 1] = '\0';
7277 /* Return true if idesc is a conditional branch instruction. This excludes
7278 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7279 because they always read/write resources regardless of the value of the
7280 qualifying predicate. br.ia must always use p0, and hence is always
7281 taken. Thus this function returns true for branches which can fall
7282 through, and which use no resources if they do fall through. */
7285 is_conditional_branch (idesc)
7286 struct ia64_opcode *idesc;
7288 /* br is a conditional branch. Everything that starts with br. except
7289 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7290 Everything that starts with brl is a conditional branch. */
7291 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7292 && (idesc->name[2] == '\0'
7293 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7294 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7295 || idesc->name[2] == 'l'
7296 /* br.cond, br.call, br.clr */
7297 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7298 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7299 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7302 /* Return whether the given opcode is a taken branch. If there's any doubt,
7306 is_taken_branch (idesc)
7307 struct ia64_opcode *idesc;
7309 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7310 || strncmp (idesc->name, "br.ia", 5) == 0);
7313 /* Return whether the given opcode is an interruption or rfi. If there's any
7314 doubt, returns zero. */
7317 is_interruption_or_rfi (idesc)
7318 struct ia64_opcode *idesc;
7320 if (strcmp (idesc->name, "rfi") == 0)
7325 /* Returns the index of the given dependency in the opcode's list of chks, or
7326 -1 if there is no dependency. */
7329 depends_on (depind, idesc)
7331 struct ia64_opcode *idesc;
7334 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7335 for (i = 0; i < dep->nchks; i++)
7337 if (depind == DEP (dep->chks[i]))
7343 /* Determine a set of specific resources used for a particular resource
7344 class. Returns the number of specific resources identified For those
7345 cases which are not determinable statically, the resource returned is
7348 Meanings of value in 'NOTE':
7349 1) only read/write when the register number is explicitly encoded in the
7351 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7352 accesses CFM when qualifying predicate is in the rotating region.
7353 3) general register value is used to specify an indirect register; not
7354 determinable statically.
7355 4) only read the given resource when bits 7:0 of the indirect index
7356 register value does not match the register number of the resource; not
7357 determinable statically.
7358 5) all rules are implementation specific.
7359 6) only when both the index specified by the reader and the index specified
7360 by the writer have the same value in bits 63:61; not determinable
7362 7) only access the specified resource when the corresponding mask bit is
7364 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7365 only read when these insns reference FR2-31
7366 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7367 written when these insns write FR32-127
7368 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7370 11) The target predicates are written independently of PR[qp], but source
7371 registers are only read if PR[qp] is true. Since the state of PR[qp]
7372 cannot statically be determined, all source registers are marked used.
7373 12) This insn only reads the specified predicate register when that
7374 register is the PR[qp].
7375 13) This reference to ld-c only applies to teh GR whose value is loaded
7376 with data returned from memory, not the post-incremented address register.
7377 14) The RSE resource includes the implementation-specific RSE internal
7378 state resources. At least one (and possibly more) of these resources are
7379 read by each instruction listed in IC:rse-readers. At least one (and
7380 possibly more) of these resources are written by each insn listed in
7382 15+16) Represents reserved instructions, which the assembler does not
7385 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7386 this code; there are no dependency violations based on memory access.
7389 #define MAX_SPECS 256
7394 specify_resource (dep, idesc, type, specs, note, path)
7395 const struct ia64_dependency *dep;
7396 struct ia64_opcode *idesc;
7397 int type; /* is this a DV chk or a DV reg? */
7398 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7399 int note; /* resource note for this insn's usage */
7400 int path; /* which execution path to examine */
7407 if (dep->mode == IA64_DV_WAW
7408 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7409 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7412 /* template for any resources we identify */
7413 tmpl.dependency = dep;
7415 tmpl.insn_srlz = tmpl.data_srlz = 0;
7416 tmpl.qp_regno = CURR_SLOT.qp_regno;
7417 tmpl.link_to_qp_branch = 1;
7418 tmpl.mem_offset.hint = 0;
7421 tmpl.cmp_type = CMP_NONE;
7424 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7425 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7426 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7428 /* we don't need to track these */
7429 if (dep->semantics == IA64_DVS_NONE)
7432 switch (dep->specifier)
7437 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7439 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7440 if (regno >= 0 && regno <= 7)
7442 specs[count] = tmpl;
7443 specs[count++].index = regno;
7449 for (i = 0; i < 8; i++)
7451 specs[count] = tmpl;
7452 specs[count++].index = i;
7461 case IA64_RS_AR_UNAT:
7462 /* This is a mov =AR or mov AR= instruction. */
7463 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7465 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7466 if (regno == AR_UNAT)
7468 specs[count++] = tmpl;
7473 /* This is a spill/fill, or other instruction that modifies the
7476 /* Unless we can determine the specific bits used, mark the whole
7477 thing; bits 8:3 of the memory address indicate the bit used in
7478 UNAT. The .mem.offset hint may be used to eliminate a small
7479 subset of conflicts. */
7480 specs[count] = tmpl;
7481 if (md.mem_offset.hint)
7484 fprintf (stderr, " Using hint for spill/fill\n");
7485 /* The index isn't actually used, just set it to something
7486 approximating the bit index. */
7487 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7488 specs[count].mem_offset.hint = 1;
7489 specs[count].mem_offset.offset = md.mem_offset.offset;
7490 specs[count++].mem_offset.base = md.mem_offset.base;
7494 specs[count++].specific = 0;
7502 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7504 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7505 if ((regno >= 8 && regno <= 15)
7506 || (regno >= 20 && regno <= 23)
7507 || (regno >= 31 && regno <= 39)
7508 || (regno >= 41 && regno <= 47)
7509 || (regno >= 67 && regno <= 111))
7511 specs[count] = tmpl;
7512 specs[count++].index = regno;
7525 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7527 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7528 if ((regno >= 48 && regno <= 63)
7529 || (regno >= 112 && regno <= 127))
7531 specs[count] = tmpl;
7532 specs[count++].index = regno;
7538 for (i = 48; i < 64; i++)
7540 specs[count] = tmpl;
7541 specs[count++].index = i;
7543 for (i = 112; i < 128; i++)
7545 specs[count] = tmpl;
7546 specs[count++].index = i;
7564 for (i = 0; i < idesc->num_outputs; i++)
7565 if (idesc->operands[i] == IA64_OPND_B1
7566 || idesc->operands[i] == IA64_OPND_B2)
7568 specs[count] = tmpl;
7569 specs[count++].index =
7570 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7575 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7576 if (idesc->operands[i] == IA64_OPND_B1
7577 || idesc->operands[i] == IA64_OPND_B2)
7579 specs[count] = tmpl;
7580 specs[count++].index =
7581 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7587 case IA64_RS_CPUID: /* four or more registers */
7590 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7592 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7593 if (regno >= 0 && regno < NELEMS (gr_values)
7596 specs[count] = tmpl;
7597 specs[count++].index = gr_values[regno].value & 0xFF;
7601 specs[count] = tmpl;
7602 specs[count++].specific = 0;
7612 case IA64_RS_DBR: /* four or more registers */
7615 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7617 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7618 if (regno >= 0 && regno < NELEMS (gr_values)
7621 specs[count] = tmpl;
7622 specs[count++].index = gr_values[regno].value & 0xFF;
7626 specs[count] = tmpl;
7627 specs[count++].specific = 0;
7631 else if (note == 0 && !rsrc_write)
7633 specs[count] = tmpl;
7634 specs[count++].specific = 0;
7642 case IA64_RS_IBR: /* four or more registers */
7645 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7647 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7648 if (regno >= 0 && regno < NELEMS (gr_values)
7651 specs[count] = tmpl;
7652 specs[count++].index = gr_values[regno].value & 0xFF;
7656 specs[count] = tmpl;
7657 specs[count++].specific = 0;
7670 /* These are implementation specific. Force all references to
7671 conflict with all other references. */
7672 specs[count] = tmpl;
7673 specs[count++].specific = 0;
7681 case IA64_RS_PKR: /* 16 or more registers */
7682 if (note == 3 || note == 4)
7684 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7686 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7687 if (regno >= 0 && regno < NELEMS (gr_values)
7692 specs[count] = tmpl;
7693 specs[count++].index = gr_values[regno].value & 0xFF;
7696 for (i = 0; i < NELEMS (gr_values); i++)
7698 /* Uses all registers *except* the one in R3. */
7699 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7701 specs[count] = tmpl;
7702 specs[count++].index = i;
7708 specs[count] = tmpl;
7709 specs[count++].specific = 0;
7716 specs[count] = tmpl;
7717 specs[count++].specific = 0;
7721 case IA64_RS_PMC: /* four or more registers */
7724 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7725 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7728 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7730 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7731 if (regno >= 0 && regno < NELEMS (gr_values)
7734 specs[count] = tmpl;
7735 specs[count++].index = gr_values[regno].value & 0xFF;
7739 specs[count] = tmpl;
7740 specs[count++].specific = 0;
7750 case IA64_RS_PMD: /* four or more registers */
7753 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7755 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7756 if (regno >= 0 && regno < NELEMS (gr_values)
7759 specs[count] = tmpl;
7760 specs[count++].index = gr_values[regno].value & 0xFF;
7764 specs[count] = tmpl;
7765 specs[count++].specific = 0;
7775 case IA64_RS_RR: /* eight registers */
7778 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7780 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7781 if (regno >= 0 && regno < NELEMS (gr_values)
7784 specs[count] = tmpl;
7785 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7789 specs[count] = tmpl;
7790 specs[count++].specific = 0;
7794 else if (note == 0 && !rsrc_write)
7796 specs[count] = tmpl;
7797 specs[count++].specific = 0;
7805 case IA64_RS_CR_IRR:
7808 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7809 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7811 && idesc->operands[1] == IA64_OPND_CR3
7814 for (i = 0; i < 4; i++)
7816 specs[count] = tmpl;
7817 specs[count++].index = CR_IRR0 + i;
7823 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7824 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7826 && regno <= CR_IRR3)
7828 specs[count] = tmpl;
7829 specs[count++].index = regno;
7838 case IA64_RS_CR_LRR:
7845 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7846 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7847 && (regno == CR_LRR0 || regno == CR_LRR1))
7849 specs[count] = tmpl;
7850 specs[count++].index = regno;
7858 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7860 specs[count] = tmpl;
7861 specs[count++].index =
7862 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7877 else if (rsrc_write)
7879 if (dep->specifier == IA64_RS_FRb
7880 && idesc->operands[0] == IA64_OPND_F1)
7882 specs[count] = tmpl;
7883 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7888 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7890 if (idesc->operands[i] == IA64_OPND_F2
7891 || idesc->operands[i] == IA64_OPND_F3
7892 || idesc->operands[i] == IA64_OPND_F4)
7894 specs[count] = tmpl;
7895 specs[count++].index =
7896 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7905 /* This reference applies only to the GR whose value is loaded with
7906 data returned from memory. */
7907 specs[count] = tmpl;
7908 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7914 for (i = 0; i < idesc->num_outputs; i++)
7915 if (idesc->operands[i] == IA64_OPND_R1
7916 || idesc->operands[i] == IA64_OPND_R2
7917 || idesc->operands[i] == IA64_OPND_R3)
7919 specs[count] = tmpl;
7920 specs[count++].index =
7921 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7923 if (idesc->flags & IA64_OPCODE_POSTINC)
7924 for (i = 0; i < NELEMS (idesc->operands); i++)
7925 if (idesc->operands[i] == IA64_OPND_MR3)
7927 specs[count] = tmpl;
7928 specs[count++].index =
7929 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7934 /* Look for anything that reads a GR. */
7935 for (i = 0; i < NELEMS (idesc->operands); i++)
7937 if (idesc->operands[i] == IA64_OPND_MR3
7938 || idesc->operands[i] == IA64_OPND_CPUID_R3
7939 || idesc->operands[i] == IA64_OPND_DBR_R3
7940 || idesc->operands[i] == IA64_OPND_IBR_R3
7941 || idesc->operands[i] == IA64_OPND_MSR_R3
7942 || idesc->operands[i] == IA64_OPND_PKR_R3
7943 || idesc->operands[i] == IA64_OPND_PMC_R3
7944 || idesc->operands[i] == IA64_OPND_PMD_R3
7945 || idesc->operands[i] == IA64_OPND_RR_R3
7946 || ((i >= idesc->num_outputs)
7947 && (idesc->operands[i] == IA64_OPND_R1
7948 || idesc->operands[i] == IA64_OPND_R2
7949 || idesc->operands[i] == IA64_OPND_R3
7950 /* addl source register. */
7951 || idesc->operands[i] == IA64_OPND_R3_2)))
7953 specs[count] = tmpl;
7954 specs[count++].index =
7955 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7966 /* This is the same as IA64_RS_PRr, except that the register range is
7967 from 1 - 15, and there are no rotating register reads/writes here. */
7971 for (i = 1; i < 16; i++)
7973 specs[count] = tmpl;
7974 specs[count++].index = i;
7980 /* Mark only those registers indicated by the mask. */
7983 mask = CURR_SLOT.opnd[2].X_add_number;
7984 for (i = 1; i < 16; i++)
7985 if (mask & ((valueT) 1 << i))
7987 specs[count] = tmpl;
7988 specs[count++].index = i;
7996 else if (note == 11) /* note 11 implies note 1 as well */
8000 for (i = 0; i < idesc->num_outputs; i++)
8002 if (idesc->operands[i] == IA64_OPND_P1
8003 || idesc->operands[i] == IA64_OPND_P2)
8005 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8006 if (regno >= 1 && regno < 16)
8008 specs[count] = tmpl;
8009 specs[count++].index = regno;
8019 else if (note == 12)
8021 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8023 specs[count] = tmpl;
8024 specs[count++].index = CURR_SLOT.qp_regno;
8031 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8032 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8033 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8034 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8036 if ((idesc->operands[0] == IA64_OPND_P1
8037 || idesc->operands[0] == IA64_OPND_P2)
8038 && p1 >= 1 && p1 < 16)
8040 specs[count] = tmpl;
8041 specs[count].cmp_type =
8042 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8043 specs[count++].index = p1;
8045 if ((idesc->operands[1] == IA64_OPND_P1
8046 || idesc->operands[1] == IA64_OPND_P2)
8047 && p2 >= 1 && p2 < 16)
8049 specs[count] = tmpl;
8050 specs[count].cmp_type =
8051 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8052 specs[count++].index = p2;
8057 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8059 specs[count] = tmpl;
8060 specs[count++].index = CURR_SLOT.qp_regno;
8062 if (idesc->operands[1] == IA64_OPND_PR)
8064 for (i = 1; i < 16; i++)
8066 specs[count] = tmpl;
8067 specs[count++].index = i;
8078 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8079 simplified cases of this. */
8083 for (i = 16; i < 63; i++)
8085 specs[count] = tmpl;
8086 specs[count++].index = i;
8092 /* Mark only those registers indicated by the mask. */
8094 && idesc->operands[0] == IA64_OPND_PR)
8096 mask = CURR_SLOT.opnd[2].X_add_number;
8097 if (mask & ((valueT) 1 << 16))
8098 for (i = 16; i < 63; i++)
8100 specs[count] = tmpl;
8101 specs[count++].index = i;
8105 && idesc->operands[0] == IA64_OPND_PR_ROT)
8107 for (i = 16; i < 63; i++)
8109 specs[count] = tmpl;
8110 specs[count++].index = i;
8118 else if (note == 11) /* note 11 implies note 1 as well */
8122 for (i = 0; i < idesc->num_outputs; i++)
8124 if (idesc->operands[i] == IA64_OPND_P1
8125 || idesc->operands[i] == IA64_OPND_P2)
8127 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8128 if (regno >= 16 && regno < 63)
8130 specs[count] = tmpl;
8131 specs[count++].index = regno;
8141 else if (note == 12)
8143 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8145 specs[count] = tmpl;
8146 specs[count++].index = CURR_SLOT.qp_regno;
8153 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8154 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8155 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8156 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8158 if ((idesc->operands[0] == IA64_OPND_P1
8159 || idesc->operands[0] == IA64_OPND_P2)
8160 && p1 >= 16 && p1 < 63)
8162 specs[count] = tmpl;
8163 specs[count].cmp_type =
8164 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8165 specs[count++].index = p1;
8167 if ((idesc->operands[1] == IA64_OPND_P1
8168 || idesc->operands[1] == IA64_OPND_P2)
8169 && p2 >= 16 && p2 < 63)
8171 specs[count] = tmpl;
8172 specs[count].cmp_type =
8173 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8174 specs[count++].index = p2;
8179 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8181 specs[count] = tmpl;
8182 specs[count++].index = CURR_SLOT.qp_regno;
8184 if (idesc->operands[1] == IA64_OPND_PR)
8186 for (i = 16; i < 63; i++)
8188 specs[count] = tmpl;
8189 specs[count++].index = i;
8201 /* Verify that the instruction is using the PSR bit indicated in
8205 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8207 if (dep->regindex < 6)
8209 specs[count++] = tmpl;
8212 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8214 if (dep->regindex < 32
8215 || dep->regindex == 35
8216 || dep->regindex == 36
8217 || (!rsrc_write && dep->regindex == PSR_CPL))
8219 specs[count++] = tmpl;
8222 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8224 if (dep->regindex < 32
8225 || dep->regindex == 35
8226 || dep->regindex == 36
8227 || (rsrc_write && dep->regindex == PSR_CPL))
8229 specs[count++] = tmpl;
8234 /* Several PSR bits have very specific dependencies. */
8235 switch (dep->regindex)
8238 specs[count++] = tmpl;
8243 specs[count++] = tmpl;
8247 /* Only certain CR accesses use PSR.ic */
8248 if (idesc->operands[0] == IA64_OPND_CR3
8249 || idesc->operands[1] == IA64_OPND_CR3)
8252 ((idesc->operands[0] == IA64_OPND_CR3)
8255 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8270 specs[count++] = tmpl;
8279 specs[count++] = tmpl;
8283 /* Only some AR accesses use cpl */
8284 if (idesc->operands[0] == IA64_OPND_AR3
8285 || idesc->operands[1] == IA64_OPND_AR3)
8288 ((idesc->operands[0] == IA64_OPND_AR3)
8291 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8298 && regno <= AR_K7))))
8300 specs[count++] = tmpl;
8305 specs[count++] = tmpl;
8315 if (idesc->operands[0] == IA64_OPND_IMMU24)
8317 mask = CURR_SLOT.opnd[0].X_add_number;
8323 if (mask & ((valueT) 1 << dep->regindex))
8325 specs[count++] = tmpl;
8330 int min = dep->regindex == PSR_DFL ? 2 : 32;
8331 int max = dep->regindex == PSR_DFL ? 31 : 127;
8332 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8333 for (i = 0; i < NELEMS (idesc->operands); i++)
8335 if (idesc->operands[i] == IA64_OPND_F1
8336 || idesc->operands[i] == IA64_OPND_F2
8337 || idesc->operands[i] == IA64_OPND_F3
8338 || idesc->operands[i] == IA64_OPND_F4)
8340 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8341 if (reg >= min && reg <= max)
8343 specs[count++] = tmpl;
8350 int min = dep->regindex == PSR_MFL ? 2 : 32;
8351 int max = dep->regindex == PSR_MFL ? 31 : 127;
8352 /* mfh is read on writes to FR32-127; mfl is read on writes to
8354 for (i = 0; i < idesc->num_outputs; i++)
8356 if (idesc->operands[i] == IA64_OPND_F1)
8358 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8359 if (reg >= min && reg <= max)
8361 specs[count++] = tmpl;
8366 else if (note == 10)
8368 for (i = 0; i < NELEMS (idesc->operands); i++)
8370 if (idesc->operands[i] == IA64_OPND_R1
8371 || idesc->operands[i] == IA64_OPND_R2
8372 || idesc->operands[i] == IA64_OPND_R3)
8374 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8375 if (regno >= 16 && regno <= 31)
8377 specs[count++] = tmpl;
8388 case IA64_RS_AR_FPSR:
8389 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8391 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8392 if (regno == AR_FPSR)
8394 specs[count++] = tmpl;
8399 specs[count++] = tmpl;
8404 /* Handle all AR[REG] resources */
8405 if (note == 0 || note == 1)
8407 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8408 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8409 && regno == dep->regindex)
8411 specs[count++] = tmpl;
8413 /* other AR[REG] resources may be affected by AR accesses */
8414 else if (idesc->operands[0] == IA64_OPND_AR3)
8417 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8418 switch (dep->regindex)
8424 if (regno == AR_BSPSTORE)
8426 specs[count++] = tmpl;
8430 (regno == AR_BSPSTORE
8431 || regno == AR_RNAT))
8433 specs[count++] = tmpl;
8438 else if (idesc->operands[1] == IA64_OPND_AR3)
8441 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8442 switch (dep->regindex)
8447 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8449 specs[count++] = tmpl;
8456 specs[count++] = tmpl;
8466 /* Handle all CR[REG] resources */
8467 if (note == 0 || note == 1)
8469 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8471 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8472 if (regno == dep->regindex)
8474 specs[count++] = tmpl;
8476 else if (!rsrc_write)
8478 /* Reads from CR[IVR] affect other resources. */
8479 if (regno == CR_IVR)
8481 if ((dep->regindex >= CR_IRR0
8482 && dep->regindex <= CR_IRR3)
8483 || dep->regindex == CR_TPR)
8485 specs[count++] = tmpl;
8492 specs[count++] = tmpl;
8501 case IA64_RS_INSERVICE:
8502 /* look for write of EOI (67) or read of IVR (65) */
8503 if ((idesc->operands[0] == IA64_OPND_CR3
8504 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8505 || (idesc->operands[1] == IA64_OPND_CR3
8506 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8508 specs[count++] = tmpl;
8515 specs[count++] = tmpl;
8526 specs[count++] = tmpl;
8530 /* Check if any of the registers accessed are in the rotating region.
8531 mov to/from pr accesses CFM only when qp_regno is in the rotating
8533 for (i = 0; i < NELEMS (idesc->operands); i++)
8535 if (idesc->operands[i] == IA64_OPND_R1
8536 || idesc->operands[i] == IA64_OPND_R2
8537 || idesc->operands[i] == IA64_OPND_R3)
8539 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8540 /* Assumes that md.rot.num_regs is always valid */
8541 if (md.rot.num_regs > 0
8543 && num < 31 + md.rot.num_regs)
8545 specs[count] = tmpl;
8546 specs[count++].specific = 0;
8549 else if (idesc->operands[i] == IA64_OPND_F1
8550 || idesc->operands[i] == IA64_OPND_F2
8551 || idesc->operands[i] == IA64_OPND_F3
8552 || idesc->operands[i] == IA64_OPND_F4)
8554 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8557 specs[count] = tmpl;
8558 specs[count++].specific = 0;
8561 else if (idesc->operands[i] == IA64_OPND_P1
8562 || idesc->operands[i] == IA64_OPND_P2)
8564 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8567 specs[count] = tmpl;
8568 specs[count++].specific = 0;
8572 if (CURR_SLOT.qp_regno > 15)
8574 specs[count] = tmpl;
8575 specs[count++].specific = 0;
8580 /* This is the same as IA64_RS_PRr, except simplified to account for
8581 the fact that there is only one register. */
8585 specs[count++] = tmpl;
8590 if (idesc->operands[2] == IA64_OPND_IMM17)
8591 mask = CURR_SLOT.opnd[2].X_add_number;
8592 if (mask & ((valueT) 1 << 63))
8593 specs[count++] = tmpl;
8595 else if (note == 11)
8597 if ((idesc->operands[0] == IA64_OPND_P1
8598 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8599 || (idesc->operands[1] == IA64_OPND_P2
8600 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8602 specs[count++] = tmpl;
8605 else if (note == 12)
8607 if (CURR_SLOT.qp_regno == 63)
8609 specs[count++] = tmpl;
8616 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8617 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8618 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8619 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8622 && (idesc->operands[0] == IA64_OPND_P1
8623 || idesc->operands[0] == IA64_OPND_P2))
8625 specs[count] = tmpl;
8626 specs[count++].cmp_type =
8627 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8630 && (idesc->operands[1] == IA64_OPND_P1
8631 || idesc->operands[1] == IA64_OPND_P2))
8633 specs[count] = tmpl;
8634 specs[count++].cmp_type =
8635 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8640 if (CURR_SLOT.qp_regno == 63)
8642 specs[count++] = tmpl;
8653 /* FIXME we can identify some individual RSE written resources, but RSE
8654 read resources have not yet been completely identified, so for now
8655 treat RSE as a single resource */
8656 if (strncmp (idesc->name, "mov", 3) == 0)
8660 if (idesc->operands[0] == IA64_OPND_AR3
8661 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8663 specs[count] = tmpl;
8664 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8669 if (idesc->operands[0] == IA64_OPND_AR3)
8671 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8672 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8674 specs[count++] = tmpl;
8677 else if (idesc->operands[1] == IA64_OPND_AR3)
8679 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8680 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8681 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8683 specs[count++] = tmpl;
8690 specs[count++] = tmpl;
8695 /* FIXME -- do any of these need to be non-specific? */
8696 specs[count++] = tmpl;
8700 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8707 /* Clear branch flags on marked resources. This breaks the link between the
8708 QP of the marking instruction and a subsequent branch on the same QP. */
8711 clear_qp_branch_flag (mask)
8715 for (i = 0; i < regdepslen; i++)
8717 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8718 if ((bit & mask) != 0)
8720 regdeps[i].link_to_qp_branch = 0;
8725 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8727 Any changes to a PR clears the mutex relations which include that PR. */
8730 clear_qp_mutex (mask)
8736 while (i < qp_mutexeslen)
8738 if ((qp_mutexes[i].prmask & mask) != 0)
8742 fprintf (stderr, " Clearing mutex relation");
8743 print_prmask (qp_mutexes[i].prmask);
8744 fprintf (stderr, "\n");
8746 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8753 /* Clear implies relations which contain PRs in the given masks.
8754 P1_MASK indicates the source of the implies relation, while P2_MASK
8755 indicates the implied PR. */
8758 clear_qp_implies (p1_mask, p2_mask)
8765 while (i < qp_implieslen)
8767 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8768 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8771 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8772 qp_implies[i].p1, qp_implies[i].p2);
8773 qp_implies[i] = qp_implies[--qp_implieslen];
8780 /* Add the PRs specified to the list of implied relations. */
8783 add_qp_imply (p1, p2)
8790 /* p0 is not meaningful here. */
8791 if (p1 == 0 || p2 == 0)
8797 /* If it exists already, ignore it. */
8798 for (i = 0; i < qp_implieslen; i++)
8800 if (qp_implies[i].p1 == p1
8801 && qp_implies[i].p2 == p2
8802 && qp_implies[i].path == md.path
8803 && !qp_implies[i].p2_branched)
8807 if (qp_implieslen == qp_impliestotlen)
8809 qp_impliestotlen += 20;
8810 qp_implies = (struct qp_imply *)
8811 xrealloc ((void *) qp_implies,
8812 qp_impliestotlen * sizeof (struct qp_imply));
8815 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8816 qp_implies[qp_implieslen].p1 = p1;
8817 qp_implies[qp_implieslen].p2 = p2;
8818 qp_implies[qp_implieslen].path = md.path;
8819 qp_implies[qp_implieslen++].p2_branched = 0;
8821 /* Add in the implied transitive relations; for everything that p2 implies,
8822 make p1 imply that, too; for everything that implies p1, make it imply p2
8824 for (i = 0; i < qp_implieslen; i++)
8826 if (qp_implies[i].p1 == p2)
8827 add_qp_imply (p1, qp_implies[i].p2);
8828 if (qp_implies[i].p2 == p1)
8829 add_qp_imply (qp_implies[i].p1, p2);
8831 /* Add in mutex relations implied by this implies relation; for each mutex
8832 relation containing p2, duplicate it and replace p2 with p1. */
8833 bit = (valueT) 1 << p1;
8834 mask = (valueT) 1 << p2;
8835 for (i = 0; i < qp_mutexeslen; i++)
8837 if (qp_mutexes[i].prmask & mask)
8838 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8842 /* Add the PRs specified in the mask to the mutex list; this means that only
8843 one of the PRs can be true at any time. PR0 should never be included in
8853 if (qp_mutexeslen == qp_mutexestotlen)
8855 qp_mutexestotlen += 20;
8856 qp_mutexes = (struct qpmutex *)
8857 xrealloc ((void *) qp_mutexes,
8858 qp_mutexestotlen * sizeof (struct qpmutex));
8862 fprintf (stderr, " Registering mutex on");
8863 print_prmask (mask);
8864 fprintf (stderr, "\n");
8866 qp_mutexes[qp_mutexeslen].path = md.path;
8867 qp_mutexes[qp_mutexeslen++].prmask = mask;
8871 has_suffix_p (name, suffix)
8875 size_t namelen = strlen (name);
8876 size_t sufflen = strlen (suffix);
8878 if (namelen <= sufflen)
8880 return strcmp (name + namelen - sufflen, suffix) == 0;
8884 clear_register_values ()
8888 fprintf (stderr, " Clearing register values\n");
8889 for (i = 1; i < NELEMS (gr_values); i++)
8890 gr_values[i].known = 0;
8893 /* Keep track of register values/changes which affect DV tracking.
8895 optimization note: should add a flag to classes of insns where otherwise we
8896 have to examine a group of strings to identify them. */
8899 note_register_values (idesc)
8900 struct ia64_opcode *idesc;
8902 valueT qp_changemask = 0;
8905 /* Invalidate values for registers being written to. */
8906 for (i = 0; i < idesc->num_outputs; i++)
8908 if (idesc->operands[i] == IA64_OPND_R1
8909 || idesc->operands[i] == IA64_OPND_R2
8910 || idesc->operands[i] == IA64_OPND_R3)
8912 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8913 if (regno > 0 && regno < NELEMS (gr_values))
8914 gr_values[regno].known = 0;
8916 else if (idesc->operands[i] == IA64_OPND_R3_2)
8918 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8919 if (regno > 0 && regno < 4)
8920 gr_values[regno].known = 0;
8922 else if (idesc->operands[i] == IA64_OPND_P1
8923 || idesc->operands[i] == IA64_OPND_P2)
8925 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8926 qp_changemask |= (valueT) 1 << regno;
8928 else if (idesc->operands[i] == IA64_OPND_PR)
8930 if (idesc->operands[2] & (valueT) 0x10000)
8931 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
8933 qp_changemask = idesc->operands[2];
8936 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
8938 if (idesc->operands[1] & ((valueT) 1 << 43))
8939 qp_changemask = ~(valueT) 0xFFFFFFFFFFF | idesc->operands[1];
8941 qp_changemask = idesc->operands[1];
8942 qp_changemask &= ~(valueT) 0xFFFF;
8947 /* Always clear qp branch flags on any PR change. */
8948 /* FIXME there may be exceptions for certain compares. */
8949 clear_qp_branch_flag (qp_changemask);
8951 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
8952 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
8954 qp_changemask |= ~(valueT) 0xFFFF;
8955 if (strcmp (idesc->name, "clrrrb.pr") != 0)
8957 for (i = 32; i < 32 + md.rot.num_regs; i++)
8958 gr_values[i].known = 0;
8960 clear_qp_mutex (qp_changemask);
8961 clear_qp_implies (qp_changemask, qp_changemask);
8963 /* After a call, all register values are undefined, except those marked
8965 else if (strncmp (idesc->name, "br.call", 6) == 0
8966 || strncmp (idesc->name, "brl.call", 7) == 0)
8968 /* FIXME keep GR values which are marked as "safe_across_calls" */
8969 clear_register_values ();
8970 clear_qp_mutex (~qp_safe_across_calls);
8971 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
8972 clear_qp_branch_flag (~qp_safe_across_calls);
8974 else if (is_interruption_or_rfi (idesc)
8975 || is_taken_branch (idesc))
8977 clear_register_values ();
8978 clear_qp_mutex (~(valueT) 0);
8979 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
8981 /* Look for mutex and implies relations. */
8982 else if ((idesc->operands[0] == IA64_OPND_P1
8983 || idesc->operands[0] == IA64_OPND_P2)
8984 && (idesc->operands[1] == IA64_OPND_P1
8985 || idesc->operands[1] == IA64_OPND_P2))
8987 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8988 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8989 valueT p1mask = (valueT) 1 << p1;
8990 valueT p2mask = (valueT) 1 << p2;
8992 /* If one of the PRs is PR0, we can't really do anything. */
8993 if (p1 == 0 || p2 == 0)
8996 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
8998 /* In general, clear mutexes and implies which include P1 or P2,
8999 with the following exceptions. */
9000 else if (has_suffix_p (idesc->name, ".or.andcm")
9001 || has_suffix_p (idesc->name, ".and.orcm"))
9003 add_qp_mutex (p1mask | p2mask);
9004 clear_qp_implies (p2mask, p1mask);
9006 else if (has_suffix_p (idesc->name, ".andcm")
9007 || has_suffix_p (idesc->name, ".and"))
9009 clear_qp_implies (0, p1mask | p2mask);
9011 else if (has_suffix_p (idesc->name, ".orcm")
9012 || has_suffix_p (idesc->name, ".or"))
9014 clear_qp_mutex (p1mask | p2mask);
9015 clear_qp_implies (p1mask | p2mask, 0);
9019 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9020 if (has_suffix_p (idesc->name, ".unc"))
9022 add_qp_mutex (p1mask | p2mask);
9023 if (CURR_SLOT.qp_regno != 0)
9025 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
9026 CURR_SLOT.qp_regno);
9027 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
9028 CURR_SLOT.qp_regno);
9031 else if (CURR_SLOT.qp_regno == 0)
9033 add_qp_mutex (p1mask | p2mask);
9037 clear_qp_mutex (p1mask | p2mask);
9041 /* Look for mov imm insns into GRs. */
9042 else if (idesc->operands[0] == IA64_OPND_R1
9043 && (idesc->operands[1] == IA64_OPND_IMM22
9044 || idesc->operands[1] == IA64_OPND_IMMU64)
9045 && (strcmp (idesc->name, "mov") == 0
9046 || strcmp (idesc->name, "movl") == 0))
9048 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9049 if (regno > 0 && regno < NELEMS (gr_values))
9051 gr_values[regno].known = 1;
9052 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9053 gr_values[regno].path = md.path;
9056 fprintf (stderr, " Know gr%d = ", regno);
9057 fprintf_vma (stderr, gr_values[regno].value);
9058 fputs ("\n", stderr);
9064 clear_qp_mutex (qp_changemask);
9065 clear_qp_implies (qp_changemask, qp_changemask);
9069 /* Return whether the given predicate registers are currently mutex. */
9072 qp_mutex (p1, p2, path)
9082 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9083 for (i = 0; i < qp_mutexeslen; i++)
9085 if (qp_mutexes[i].path >= path
9086 && (qp_mutexes[i].prmask & mask) == mask)
9093 /* Return whether the given resource is in the given insn's list of chks
9094 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9098 resources_match (rs, idesc, note, qp_regno, path)
9100 struct ia64_opcode *idesc;
9105 struct rsrc specs[MAX_SPECS];
9108 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9109 we don't need to check. One exception is note 11, which indicates that
9110 target predicates are written regardless of PR[qp]. */
9111 if (qp_mutex (rs->qp_regno, qp_regno, path)
9115 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9118 /* UNAT checking is a bit more specific than other resources */
9119 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9120 && specs[count].mem_offset.hint
9121 && rs->mem_offset.hint)
9123 if (rs->mem_offset.base == specs[count].mem_offset.base)
9125 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9126 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9133 /* Skip apparent PR write conflicts where both writes are an AND or both
9134 writes are an OR. */
9135 if (rs->dependency->specifier == IA64_RS_PR
9136 || rs->dependency->specifier == IA64_RS_PRr
9137 || rs->dependency->specifier == IA64_RS_PR63)
9139 if (specs[count].cmp_type != CMP_NONE
9140 && specs[count].cmp_type == rs->cmp_type)
9143 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9144 dv_mode[rs->dependency->mode],
9145 rs->dependency->specifier != IA64_RS_PR63 ?
9146 specs[count].index : 63);
9151 " %s on parallel compare conflict %s vs %s on PR%d\n",
9152 dv_mode[rs->dependency->mode],
9153 dv_cmp_type[rs->cmp_type],
9154 dv_cmp_type[specs[count].cmp_type],
9155 rs->dependency->specifier != IA64_RS_PR63 ?
9156 specs[count].index : 63);
9160 /* If either resource is not specific, conservatively assume a conflict
9162 if (!specs[count].specific || !rs->specific)
9164 else if (specs[count].index == rs->index)
9169 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9175 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9176 insert a stop to create the break. Update all resource dependencies
9177 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9178 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9179 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9183 insn_group_break (insert_stop, qp_regno, save_current)
9190 if (insert_stop && md.num_slots_in_use > 0)
9191 PREV_SLOT.end_of_insn_group = 1;
9195 fprintf (stderr, " Insn group break%s",
9196 (insert_stop ? " (w/stop)" : ""));
9198 fprintf (stderr, " effective for QP=%d", qp_regno);
9199 fprintf (stderr, "\n");
9203 while (i < regdepslen)
9205 const struct ia64_dependency *dep = regdeps[i].dependency;
9208 && regdeps[i].qp_regno != qp_regno)
9215 && CURR_SLOT.src_file == regdeps[i].file
9216 && CURR_SLOT.src_line == regdeps[i].line)
9222 /* clear dependencies which are automatically cleared by a stop, or
9223 those that have reached the appropriate state of insn serialization */
9224 if (dep->semantics == IA64_DVS_IMPLIED
9225 || dep->semantics == IA64_DVS_IMPLIEDF
9226 || regdeps[i].insn_srlz == STATE_SRLZ)
9228 print_dependency ("Removing", i);
9229 regdeps[i] = regdeps[--regdepslen];
9233 if (dep->semantics == IA64_DVS_DATA
9234 || dep->semantics == IA64_DVS_INSTR
9235 || dep->semantics == IA64_DVS_SPECIFIC)
9237 if (regdeps[i].insn_srlz == STATE_NONE)
9238 regdeps[i].insn_srlz = STATE_STOP;
9239 if (regdeps[i].data_srlz == STATE_NONE)
9240 regdeps[i].data_srlz = STATE_STOP;
9247 /* Add the given resource usage spec to the list of active dependencies. */
9250 mark_resource (idesc, dep, spec, depind, path)
9251 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9252 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9257 if (regdepslen == regdepstotlen)
9259 regdepstotlen += 20;
9260 regdeps = (struct rsrc *)
9261 xrealloc ((void *) regdeps,
9262 regdepstotlen * sizeof (struct rsrc));
9265 regdeps[regdepslen] = *spec;
9266 regdeps[regdepslen].depind = depind;
9267 regdeps[regdepslen].path = path;
9268 regdeps[regdepslen].file = CURR_SLOT.src_file;
9269 regdeps[regdepslen].line = CURR_SLOT.src_line;
9271 print_dependency ("Adding", regdepslen);
9277 print_dependency (action, depind)
9283 fprintf (stderr, " %s %s '%s'",
9284 action, dv_mode[(regdeps[depind].dependency)->mode],
9285 (regdeps[depind].dependency)->name);
9286 if (regdeps[depind].specific && regdeps[depind].index != 0)
9287 fprintf (stderr, " (%d)", regdeps[depind].index);
9288 if (regdeps[depind].mem_offset.hint)
9290 fputs (" ", stderr);
9291 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9292 fputs ("+", stderr);
9293 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9295 fprintf (stderr, "\n");
9300 instruction_serialization ()
9304 fprintf (stderr, " Instruction serialization\n");
9305 for (i = 0; i < regdepslen; i++)
9306 if (regdeps[i].insn_srlz == STATE_STOP)
9307 regdeps[i].insn_srlz = STATE_SRLZ;
9311 data_serialization ()
9315 fprintf (stderr, " Data serialization\n");
9316 while (i < regdepslen)
9318 if (regdeps[i].data_srlz == STATE_STOP
9319 /* Note: as of 991210, all "other" dependencies are cleared by a
9320 data serialization. This might change with new tables */
9321 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9323 print_dependency ("Removing", i);
9324 regdeps[i] = regdeps[--regdepslen];
9331 /* Insert stops and serializations as needed to avoid DVs. */
9334 remove_marked_resource (rs)
9337 switch (rs->dependency->semantics)
9339 case IA64_DVS_SPECIFIC:
9341 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9342 /* ...fall through... */
9343 case IA64_DVS_INSTR:
9345 fprintf (stderr, "Inserting instr serialization\n");
9346 if (rs->insn_srlz < STATE_STOP)
9347 insn_group_break (1, 0, 0);
9348 if (rs->insn_srlz < STATE_SRLZ)
9350 int oldqp = CURR_SLOT.qp_regno;
9351 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9352 /* Manually jam a srlz.i insn into the stream */
9353 CURR_SLOT.qp_regno = 0;
9354 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9355 instruction_serialization ();
9356 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9357 if (++md.num_slots_in_use >= NUM_SLOTS)
9359 CURR_SLOT.qp_regno = oldqp;
9360 CURR_SLOT.idesc = oldidesc;
9362 insn_group_break (1, 0, 0);
9364 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9365 "other" types of DV are eliminated
9366 by a data serialization */
9369 fprintf (stderr, "Inserting data serialization\n");
9370 if (rs->data_srlz < STATE_STOP)
9371 insn_group_break (1, 0, 0);
9373 int oldqp = CURR_SLOT.qp_regno;
9374 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9375 /* Manually jam a srlz.d insn into the stream */
9376 CURR_SLOT.qp_regno = 0;
9377 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9378 data_serialization ();
9379 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9380 if (++md.num_slots_in_use >= NUM_SLOTS)
9382 CURR_SLOT.qp_regno = oldqp;
9383 CURR_SLOT.idesc = oldidesc;
9386 case IA64_DVS_IMPLIED:
9387 case IA64_DVS_IMPLIEDF:
9389 fprintf (stderr, "Inserting stop\n");
9390 insn_group_break (1, 0, 0);
9397 /* Check the resources used by the given opcode against the current dependency
9400 The check is run once for each execution path encountered. In this case,
9401 a unique execution path is the sequence of instructions following a code
9402 entry point, e.g. the following has three execution paths, one starting
9403 at L0, one at L1, and one at L2.
9412 check_dependencies (idesc)
9413 struct ia64_opcode *idesc;
9415 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9419 /* Note that the number of marked resources may change within the
9420 loop if in auto mode. */
9422 while (i < regdepslen)
9424 struct rsrc *rs = ®deps[i];
9425 const struct ia64_dependency *dep = rs->dependency;
9430 if (dep->semantics == IA64_DVS_NONE
9431 || (chkind = depends_on (rs->depind, idesc)) == -1)
9437 note = NOTE (opdeps->chks[chkind]);
9439 /* Check this resource against each execution path seen thus far. */
9440 for (path = 0; path <= md.path; path++)
9444 /* If the dependency wasn't on the path being checked, ignore it. */
9445 if (rs->path < path)
9448 /* If the QP for this insn implies a QP which has branched, don't
9449 bother checking. Ed. NOTE: I don't think this check is terribly
9450 useful; what's the point of generating code which will only be
9451 reached if its QP is zero?
9452 This code was specifically inserted to handle the following code,
9453 based on notes from Intel's DV checking code, where p1 implies p2.
9459 if (CURR_SLOT.qp_regno != 0)
9463 for (implies = 0; implies < qp_implieslen; implies++)
9465 if (qp_implies[implies].path >= path
9466 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9467 && qp_implies[implies].p2_branched)
9477 if ((matchtype = resources_match (rs, idesc, note,
9478 CURR_SLOT.qp_regno, path)) != 0)
9481 char pathmsg[256] = "";
9482 char indexmsg[256] = "";
9483 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9486 sprintf (pathmsg, " when entry is at label '%s'",
9487 md.entry_labels[path - 1]);
9488 if (rs->specific && rs->index != 0)
9489 sprintf (indexmsg, ", specific resource number is %d",
9491 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9493 (certain ? "violates" : "may violate"),
9494 dv_mode[dep->mode], dep->name,
9495 dv_sem[dep->semantics],
9498 if (md.explicit_mode)
9500 as_warn ("%s", msg);
9502 as_warn (_("Only the first path encountering the conflict "
9504 as_warn_where (rs->file, rs->line,
9505 _("This is the location of the "
9506 "conflicting usage"));
9507 /* Don't bother checking other paths, to avoid duplicating
9514 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9516 remove_marked_resource (rs);
9518 /* since the set of dependencies has changed, start over */
9519 /* FIXME -- since we're removing dvs as we go, we
9520 probably don't really need to start over... */
9533 /* Register new dependencies based on the given opcode. */
9536 mark_resources (idesc)
9537 struct ia64_opcode *idesc;
9540 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9541 int add_only_qp_reads = 0;
9543 /* A conditional branch only uses its resources if it is taken; if it is
9544 taken, we stop following that path. The other branch types effectively
9545 *always* write their resources. If it's not taken, register only QP
9547 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9549 add_only_qp_reads = 1;
9553 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9555 for (i = 0; i < opdeps->nregs; i++)
9557 const struct ia64_dependency *dep;
9558 struct rsrc specs[MAX_SPECS];
9563 dep = ia64_find_dependency (opdeps->regs[i]);
9564 note = NOTE (opdeps->regs[i]);
9566 if (add_only_qp_reads
9567 && !(dep->mode == IA64_DV_WAR
9568 && (dep->specifier == IA64_RS_PR
9569 || dep->specifier == IA64_RS_PRr
9570 || dep->specifier == IA64_RS_PR63)))
9573 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9576 if (md.debug_dv && !count)
9577 fprintf (stderr, " No %s %s usage found (path %d)\n",
9578 dv_mode[dep->mode], dep->name, md.path);
9583 mark_resource (idesc, dep, &specs[count],
9584 DEP (opdeps->regs[i]), md.path);
9587 /* The execution path may affect register values, which may in turn
9588 affect which indirect-access resources are accessed. */
9589 switch (dep->specifier)
9601 for (path = 0; path < md.path; path++)
9603 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9605 mark_resource (idesc, dep, &specs[count],
9606 DEP (opdeps->regs[i]), path);
9613 /* Remove dependencies when they no longer apply. */
9616 update_dependencies (idesc)
9617 struct ia64_opcode *idesc;
9621 if (strcmp (idesc->name, "srlz.i") == 0)
9623 instruction_serialization ();
9625 else if (strcmp (idesc->name, "srlz.d") == 0)
9627 data_serialization ();
9629 else if (is_interruption_or_rfi (idesc)
9630 || is_taken_branch (idesc))
9632 /* Although technically the taken branch doesn't clear dependencies
9633 which require a srlz.[id], we don't follow the branch; the next
9634 instruction is assumed to start with a clean slate. */
9638 else if (is_conditional_branch (idesc)
9639 && CURR_SLOT.qp_regno != 0)
9641 int is_call = strstr (idesc->name, ".call") != NULL;
9643 for (i = 0; i < qp_implieslen; i++)
9645 /* If the conditional branch's predicate is implied by the predicate
9646 in an existing dependency, remove that dependency. */
9647 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9650 /* Note that this implied predicate takes a branch so that if
9651 a later insn generates a DV but its predicate implies this
9652 one, we can avoid the false DV warning. */
9653 qp_implies[i].p2_branched = 1;
9654 while (depind < regdepslen)
9656 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9658 print_dependency ("Removing", depind);
9659 regdeps[depind] = regdeps[--regdepslen];
9666 /* Any marked resources which have this same predicate should be
9667 cleared, provided that the QP hasn't been modified between the
9668 marking instruction and the branch. */
9671 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9676 while (i < regdepslen)
9678 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9679 && regdeps[i].link_to_qp_branch
9680 && (regdeps[i].file != CURR_SLOT.src_file
9681 || regdeps[i].line != CURR_SLOT.src_line))
9683 /* Treat like a taken branch */
9684 print_dependency ("Removing", i);
9685 regdeps[i] = regdeps[--regdepslen];
9694 /* Examine the current instruction for dependency violations. */
9698 struct ia64_opcode *idesc;
9702 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9703 idesc->name, CURR_SLOT.src_line,
9704 idesc->dependencies->nchks,
9705 idesc->dependencies->nregs);
9708 /* Look through the list of currently marked resources; if the current
9709 instruction has the dependency in its chks list which uses that resource,
9710 check against the specific resources used. */
9711 check_dependencies (idesc);
9713 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9714 then add them to the list of marked resources. */
9715 mark_resources (idesc);
9717 /* There are several types of dependency semantics, and each has its own
9718 requirements for being cleared
9720 Instruction serialization (insns separated by interruption, rfi, or
9721 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9723 Data serialization (instruction serialization, or writer + srlz.d +
9724 reader, where writer and srlz.d are in separate groups) clears
9725 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9726 always be the case).
9728 Instruction group break (groups separated by stop, taken branch,
9729 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9731 update_dependencies (idesc);
9733 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9734 warning. Keep track of as many as possible that are useful. */
9735 note_register_values (idesc);
9737 /* We don't need or want this anymore. */
9738 md.mem_offset.hint = 0;
9743 /* Translate one line of assembly. Pseudo ops and labels do not show
9749 char *saved_input_line_pointer, *mnemonic;
9750 const struct pseudo_opcode *pdesc;
9751 struct ia64_opcode *idesc;
9752 unsigned char qp_regno;
9756 saved_input_line_pointer = input_line_pointer;
9757 input_line_pointer = str;
9759 /* extract the opcode (mnemonic): */
9761 mnemonic = input_line_pointer;
9762 ch = get_symbol_end ();
9763 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9766 *input_line_pointer = ch;
9767 (*pdesc->handler) (pdesc->arg);
9771 /* Find the instruction descriptor matching the arguments. */
9773 idesc = ia64_find_opcode (mnemonic);
9774 *input_line_pointer = ch;
9777 as_bad ("Unknown opcode `%s'", mnemonic);
9781 idesc = parse_operands (idesc);
9785 /* Handle the dynamic ops we can handle now: */
9786 if (idesc->type == IA64_TYPE_DYN)
9788 if (strcmp (idesc->name, "add") == 0)
9790 if (CURR_SLOT.opnd[2].X_op == O_register
9791 && CURR_SLOT.opnd[2].X_add_number < 4)
9795 ia64_free_opcode (idesc);
9796 idesc = ia64_find_opcode (mnemonic);
9798 know (!idesc->next);
9801 else if (strcmp (idesc->name, "mov") == 0)
9803 enum ia64_opnd opnd1, opnd2;
9806 opnd1 = idesc->operands[0];
9807 opnd2 = idesc->operands[1];
9808 if (opnd1 == IA64_OPND_AR3)
9810 else if (opnd2 == IA64_OPND_AR3)
9814 if (CURR_SLOT.opnd[rop].X_op == O_register
9815 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9819 ia64_free_opcode (idesc);
9820 idesc = ia64_find_opcode (mnemonic);
9821 while (idesc != NULL
9822 && (idesc->operands[0] != opnd1
9823 || idesc->operands[1] != opnd2))
9824 idesc = get_next_opcode (idesc);
9829 if (md.qp.X_op == O_register)
9831 qp_regno = md.qp.X_add_number - REG_P;
9832 md.qp.X_op = O_absent;
9835 flags = idesc->flags;
9837 if ((flags & IA64_OPCODE_FIRST) != 0)
9838 insn_group_break (1, 0, 0);
9840 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
9842 as_bad ("`%s' cannot be predicated", idesc->name);
9846 /* Build the instruction. */
9847 CURR_SLOT.qp_regno = qp_regno;
9848 CURR_SLOT.idesc = idesc;
9849 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
9850 dwarf2_where (&CURR_SLOT.debug_line);
9852 /* Add unwind entry, if there is one. */
9853 if (unwind.current_entry)
9855 CURR_SLOT.unwind_record = unwind.current_entry;
9856 unwind.current_entry = NULL;
9859 /* Check for dependency violations. */
9863 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9864 if (++md.num_slots_in_use >= NUM_SLOTS)
9867 if ((flags & IA64_OPCODE_LAST) != 0)
9868 insn_group_break (1, 0, 0);
9870 md.last_text_seg = now_seg;
9873 input_line_pointer = saved_input_line_pointer;
9876 /* Called when symbol NAME cannot be found in the symbol table.
9877 Should be used for dynamic valued symbols only. */
9880 md_undefined_symbol (name)
9881 char *name ATTRIBUTE_UNUSED;
9886 /* Called for any expression that can not be recognized. When the
9887 function is called, `input_line_pointer' will point to the start of
9894 enum pseudo_type pseudo_type;
9899 switch (*input_line_pointer)
9902 /* Find what relocation pseudo-function we're dealing with. */
9904 ch = *++input_line_pointer;
9905 for (i = 0; i < NELEMS (pseudo_func); ++i)
9906 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
9908 len = strlen (pseudo_func[i].name);
9909 if (strncmp (pseudo_func[i].name + 1,
9910 input_line_pointer + 1, len - 1) == 0
9911 && !is_part_of_name (input_line_pointer[len]))
9913 input_line_pointer += len;
9914 pseudo_type = pseudo_func[i].type;
9918 switch (pseudo_type)
9920 case PSEUDO_FUNC_RELOC:
9922 if (*input_line_pointer != '(')
9924 as_bad ("Expected '('");
9928 ++input_line_pointer;
9930 if (*input_line_pointer++ != ')')
9932 as_bad ("Missing ')'");
9935 if (e->X_op != O_symbol)
9937 if (e->X_op != O_pseudo_fixup)
9939 as_bad ("Not a symbolic expression");
9942 if (i != FUNC_LT_RELATIVE)
9944 as_bad ("Illegal combination of relocation functions");
9947 switch (S_GET_VALUE (e->X_op_symbol))
9949 case FUNC_FPTR_RELATIVE:
9950 i = FUNC_LT_FPTR_RELATIVE; break;
9951 case FUNC_DTP_MODULE:
9952 i = FUNC_LT_DTP_MODULE; break;
9953 case FUNC_DTP_RELATIVE:
9954 i = FUNC_LT_DTP_RELATIVE; break;
9955 case FUNC_TP_RELATIVE:
9956 i = FUNC_LT_TP_RELATIVE; break;
9958 as_bad ("Illegal combination of relocation functions");
9962 /* Make sure gas doesn't get rid of local symbols that are used
9964 e->X_op = O_pseudo_fixup;
9965 e->X_op_symbol = pseudo_func[i].u.sym;
9968 case PSEUDO_FUNC_CONST:
9969 e->X_op = O_constant;
9970 e->X_add_number = pseudo_func[i].u.ival;
9973 case PSEUDO_FUNC_REG:
9974 e->X_op = O_register;
9975 e->X_add_number = pseudo_func[i].u.ival;
9979 name = input_line_pointer - 1;
9981 as_bad ("Unknown pseudo function `%s'", name);
9987 ++input_line_pointer;
9989 if (*input_line_pointer != ']')
9991 as_bad ("Closing bracket misssing");
9996 if (e->X_op != O_register)
9997 as_bad ("Register expected as index");
9999 ++input_line_pointer;
10010 ignore_rest_of_line ();
10013 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10014 a section symbol plus some offset. For relocs involving @fptr(),
10015 directives we don't want such adjustments since we need to have the
10016 original symbol's name in the reloc. */
10018 ia64_fix_adjustable (fix)
10021 /* Prevent all adjustments to global symbols */
10022 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10025 switch (fix->fx_r_type)
10027 case BFD_RELOC_IA64_FPTR64I:
10028 case BFD_RELOC_IA64_FPTR32MSB:
10029 case BFD_RELOC_IA64_FPTR32LSB:
10030 case BFD_RELOC_IA64_FPTR64MSB:
10031 case BFD_RELOC_IA64_FPTR64LSB:
10032 case BFD_RELOC_IA64_LTOFF_FPTR22:
10033 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10043 ia64_force_relocation (fix)
10046 switch (fix->fx_r_type)
10048 case BFD_RELOC_IA64_FPTR64I:
10049 case BFD_RELOC_IA64_FPTR32MSB:
10050 case BFD_RELOC_IA64_FPTR32LSB:
10051 case BFD_RELOC_IA64_FPTR64MSB:
10052 case BFD_RELOC_IA64_FPTR64LSB:
10054 case BFD_RELOC_IA64_LTOFF22:
10055 case BFD_RELOC_IA64_LTOFF64I:
10056 case BFD_RELOC_IA64_LTOFF_FPTR22:
10057 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10058 case BFD_RELOC_IA64_PLTOFF22:
10059 case BFD_RELOC_IA64_PLTOFF64I:
10060 case BFD_RELOC_IA64_PLTOFF64MSB:
10061 case BFD_RELOC_IA64_PLTOFF64LSB:
10063 case BFD_RELOC_IA64_LTOFF22X:
10064 case BFD_RELOC_IA64_LDXMOV:
10071 return generic_force_reloc (fix);
10074 /* Decide from what point a pc-relative relocation is relative to,
10075 relative to the pc-relative fixup. Er, relatively speaking. */
10077 ia64_pcrel_from_section (fix, sec)
10081 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10083 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10090 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10092 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10096 expr.X_op = O_pseudo_fixup;
10097 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10098 expr.X_add_number = 0;
10099 expr.X_add_symbol = symbol;
10100 emit_expr (&expr, size);
10103 /* This is called whenever some data item (not an instruction) needs a
10104 fixup. We pick the right reloc code depending on the byteorder
10105 currently in effect. */
10107 ia64_cons_fix_new (f, where, nbytes, exp)
10113 bfd_reloc_code_real_type code;
10118 /* There are no reloc for 8 and 16 bit quantities, but we allow
10119 them here since they will work fine as long as the expression
10120 is fully defined at the end of the pass over the source file. */
10121 case 1: code = BFD_RELOC_8; break;
10122 case 2: code = BFD_RELOC_16; break;
10124 if (target_big_endian)
10125 code = BFD_RELOC_IA64_DIR32MSB;
10127 code = BFD_RELOC_IA64_DIR32LSB;
10131 /* In 32-bit mode, data8 could mean function descriptors too. */
10132 if (exp->X_op == O_pseudo_fixup
10133 && exp->X_op_symbol
10134 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10135 && !(md.flags & EF_IA_64_ABI64))
10137 if (target_big_endian)
10138 code = BFD_RELOC_IA64_IPLTMSB;
10140 code = BFD_RELOC_IA64_IPLTLSB;
10141 exp->X_op = O_symbol;
10146 if (target_big_endian)
10147 code = BFD_RELOC_IA64_DIR64MSB;
10149 code = BFD_RELOC_IA64_DIR64LSB;
10154 if (exp->X_op == O_pseudo_fixup
10155 && exp->X_op_symbol
10156 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10158 if (target_big_endian)
10159 code = BFD_RELOC_IA64_IPLTMSB;
10161 code = BFD_RELOC_IA64_IPLTLSB;
10162 exp->X_op = O_symbol;
10168 as_bad ("Unsupported fixup size %d", nbytes);
10169 ignore_rest_of_line ();
10173 if (exp->X_op == O_pseudo_fixup)
10175 exp->X_op = O_symbol;
10176 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10177 /* ??? If code unchanged, unsupported. */
10180 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10181 /* We need to store the byte order in effect in case we're going
10182 to fix an 8 or 16 bit relocation (for which there no real
10183 relocs available). See md_apply_fix3(). */
10184 fix->tc_fix_data.bigendian = target_big_endian;
10187 /* Return the actual relocation we wish to associate with the pseudo
10188 reloc described by SYM and R_TYPE. SYM should be one of the
10189 symbols in the pseudo_func array, or NULL. */
10191 static bfd_reloc_code_real_type
10192 ia64_gen_real_reloc_type (sym, r_type)
10193 struct symbol *sym;
10194 bfd_reloc_code_real_type r_type;
10196 bfd_reloc_code_real_type new = 0;
10203 switch (S_GET_VALUE (sym))
10205 case FUNC_FPTR_RELATIVE:
10208 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10209 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10210 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10211 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10212 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10217 case FUNC_GP_RELATIVE:
10220 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10221 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10222 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10223 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10224 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10225 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10230 case FUNC_LT_RELATIVE:
10233 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10234 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10239 case FUNC_LT_RELATIVE_X:
10242 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10247 case FUNC_PC_RELATIVE:
10250 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10251 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10252 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10253 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10254 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10255 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10260 case FUNC_PLT_RELATIVE:
10263 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10264 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10265 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10266 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10271 case FUNC_SEC_RELATIVE:
10274 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10275 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10276 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10277 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10282 case FUNC_SEG_RELATIVE:
10285 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10286 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10287 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10288 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10293 case FUNC_LTV_RELATIVE:
10296 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10297 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10298 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10299 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10304 case FUNC_LT_FPTR_RELATIVE:
10307 case BFD_RELOC_IA64_IMM22:
10308 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10309 case BFD_RELOC_IA64_IMM64:
10310 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10316 case FUNC_TP_RELATIVE:
10319 case BFD_RELOC_IA64_IMM14:
10320 new = BFD_RELOC_IA64_TPREL14; break;
10321 case BFD_RELOC_IA64_IMM22:
10322 new = BFD_RELOC_IA64_TPREL22; break;
10323 case BFD_RELOC_IA64_IMM64:
10324 new = BFD_RELOC_IA64_TPREL64I; break;
10330 case FUNC_LT_TP_RELATIVE:
10333 case BFD_RELOC_IA64_IMM22:
10334 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10340 case FUNC_LT_DTP_MODULE:
10343 case BFD_RELOC_IA64_IMM22:
10344 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10350 case FUNC_DTP_RELATIVE:
10353 case BFD_RELOC_IA64_DIR64MSB:
10354 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10355 case BFD_RELOC_IA64_DIR64LSB:
10356 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10357 case BFD_RELOC_IA64_IMM14:
10358 new = BFD_RELOC_IA64_DTPREL14; break;
10359 case BFD_RELOC_IA64_IMM22:
10360 new = BFD_RELOC_IA64_DTPREL22; break;
10361 case BFD_RELOC_IA64_IMM64:
10362 new = BFD_RELOC_IA64_DTPREL64I; break;
10368 case FUNC_LT_DTP_RELATIVE:
10371 case BFD_RELOC_IA64_IMM22:
10372 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10378 case FUNC_IPLT_RELOC:
10385 /* Hmmmm. Should this ever occur? */
10392 /* Here is where generate the appropriate reloc for pseudo relocation
10395 ia64_validate_fix (fix)
10398 switch (fix->fx_r_type)
10400 case BFD_RELOC_IA64_FPTR64I:
10401 case BFD_RELOC_IA64_FPTR32MSB:
10402 case BFD_RELOC_IA64_FPTR64LSB:
10403 case BFD_RELOC_IA64_LTOFF_FPTR22:
10404 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10405 if (fix->fx_offset != 0)
10406 as_bad_where (fix->fx_file, fix->fx_line,
10407 "No addend allowed in @fptr() relocation");
10417 fix_insn (fix, odesc, value)
10419 const struct ia64_operand *odesc;
10422 bfd_vma insn[3], t0, t1, control_bits;
10427 slot = fix->fx_where & 0x3;
10428 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10430 /* Bundles are always in little-endian byte order */
10431 t0 = bfd_getl64 (fixpos);
10432 t1 = bfd_getl64 (fixpos + 8);
10433 control_bits = t0 & 0x1f;
10434 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10435 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10436 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10439 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10441 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10442 insn[2] |= (((value & 0x7f) << 13)
10443 | (((value >> 7) & 0x1ff) << 27)
10444 | (((value >> 16) & 0x1f) << 22)
10445 | (((value >> 21) & 0x1) << 21)
10446 | (((value >> 63) & 0x1) << 36));
10448 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10450 if (value & ~0x3fffffffffffffffULL)
10451 err = "integer operand out of range";
10452 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10453 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10455 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10458 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10459 insn[2] |= ((((value >> 59) & 0x1) << 36)
10460 | (((value >> 0) & 0xfffff) << 13));
10463 err = (*odesc->insert) (odesc, value, insn + slot);
10466 as_bad_where (fix->fx_file, fix->fx_line, err);
10468 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10469 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10470 number_to_chars_littleendian (fixpos + 0, t0, 8);
10471 number_to_chars_littleendian (fixpos + 8, t1, 8);
10474 /* Attempt to simplify or even eliminate a fixup. The return value is
10475 ignored; perhaps it was once meaningful, but now it is historical.
10476 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10478 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10482 md_apply_fix3 (fix, valP, seg)
10485 segT seg ATTRIBUTE_UNUSED;
10488 valueT value = *valP;
10490 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10494 switch (fix->fx_r_type)
10496 case BFD_RELOC_IA64_DIR32MSB:
10497 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10500 case BFD_RELOC_IA64_DIR32LSB:
10501 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10504 case BFD_RELOC_IA64_DIR64MSB:
10505 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10508 case BFD_RELOC_IA64_DIR64LSB:
10509 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10518 switch (fix->fx_r_type)
10520 case BFD_RELOC_UNUSED:
10521 /* This must be a TAG13 or TAG13b operand. There are no external
10522 relocs defined for them, so we must give an error. */
10523 as_bad_where (fix->fx_file, fix->fx_line,
10524 "%s must have a constant value",
10525 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10529 case BFD_RELOC_IA64_TPREL14:
10530 case BFD_RELOC_IA64_TPREL22:
10531 case BFD_RELOC_IA64_TPREL64I:
10532 case BFD_RELOC_IA64_LTOFF_TPREL22:
10533 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10534 case BFD_RELOC_IA64_DTPREL14:
10535 case BFD_RELOC_IA64_DTPREL22:
10536 case BFD_RELOC_IA64_DTPREL64I:
10537 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10538 S_SET_THREAD_LOCAL (fix->fx_addsy);
10545 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10547 if (fix->tc_fix_data.bigendian)
10548 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10550 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10555 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10560 /* Generate the BFD reloc to be stuck in the object file from the
10561 fixup used internally in the assembler. */
10564 tc_gen_reloc (sec, fixp)
10565 asection *sec ATTRIBUTE_UNUSED;
10570 reloc = xmalloc (sizeof (*reloc));
10571 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10572 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10573 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10574 reloc->addend = fixp->fx_offset;
10575 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10579 as_bad_where (fixp->fx_file, fixp->fx_line,
10580 "Cannot represent %s relocation in object file",
10581 bfd_get_reloc_code_name (fixp->fx_r_type));
10586 /* Turn a string in input_line_pointer into a floating point constant
10587 of type TYPE, and store the appropriate bytes in *LIT. The number
10588 of LITTLENUMS emitted is stored in *SIZE. An error message is
10589 returned, or NULL on OK. */
10591 #define MAX_LITTLENUMS 5
10594 md_atof (type, lit, size)
10599 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10629 return "Bad call to MD_ATOF()";
10631 t = atof_ieee (input_line_pointer, type, words);
10633 input_line_pointer = t;
10635 (*ia64_float_to_chars) (lit, words, prec);
10639 /* It is 10 byte floating point with 6 byte padding. */
10640 memset (&lit [10], 0, 6);
10641 *size = 8 * sizeof (LITTLENUM_TYPE);
10644 *size = prec * sizeof (LITTLENUM_TYPE);
10649 /* Handle ia64 specific semantics of the align directive. */
10652 ia64_md_do_align (n, fill, len, max)
10653 int n ATTRIBUTE_UNUSED;
10654 const char *fill ATTRIBUTE_UNUSED;
10655 int len ATTRIBUTE_UNUSED;
10656 int max ATTRIBUTE_UNUSED;
10658 if (subseg_text_p (now_seg))
10659 ia64_flush_insns ();
10662 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10663 of an rs_align_code fragment. */
10666 ia64_handle_align (fragp)
10669 /* Use mfi bundle of nops with no stop bits. */
10670 static const unsigned char be_nop[]
10671 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
10672 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
10673 static const unsigned char le_nop[]
10674 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10675 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10680 if (fragp->fr_type != rs_align_code)
10683 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10684 p = fragp->fr_literal + fragp->fr_fix;
10686 /* Make sure we are on a 16-byte boundary, in case someone has been
10687 putting data into a text section. */
10690 int fix = bytes & 15;
10691 memset (p, 0, fix);
10694 fragp->fr_fix += fix;
10697 memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
10698 fragp->fr_var = 16;
10702 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
10707 number_to_chars_bigendian (lit, (long) (*words++),
10708 sizeof (LITTLENUM_TYPE));
10709 lit += sizeof (LITTLENUM_TYPE);
10714 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
10719 number_to_chars_littleendian (lit, (long) (words[prec]),
10720 sizeof (LITTLENUM_TYPE));
10721 lit += sizeof (LITTLENUM_TYPE);
10726 ia64_elf_section_change_hook (void)
10728 dot_byteorder (-1);
10731 /* Check if a label should be made global. */
10733 ia64_check_label (symbolS *label)
10735 if (*input_line_pointer == ':')
10737 S_SET_EXTERNAL (label);
10738 input_line_pointer++;
10742 /* Used to remember where .alias and .secalias directives are seen. We
10743 will rename symbol and section names when we are about to output
10744 the relocatable file. */
10747 char *file; /* The file where the directive is seen. */
10748 unsigned int line; /* The line number the directive is at. */
10749 const char *name; /* The orignale name of the symbol. */
10752 /* Called for .alias and .secalias directives. If SECTION is 1, it is
10753 .secalias. Otherwise, it is .alias. */
10755 dot_alias (int section)
10757 char *name, *alias;
10761 const char *error_string;
10764 struct hash_control *ahash, *nhash;
10767 name = input_line_pointer;
10768 delim = get_symbol_end ();
10769 end_name = input_line_pointer;
10772 if (name == end_name)
10774 as_bad (_("expected symbol name"));
10775 discard_rest_of_line ();
10779 SKIP_WHITESPACE ();
10781 if (*input_line_pointer != ',')
10784 as_bad (_("expected comma after \"%s\""), name);
10786 ignore_rest_of_line ();
10790 input_line_pointer++;
10793 /* We call demand_copy_C_string to check if alias string is valid.
10794 There should be a closing `"' and no `\0' in the string. */
10795 alias = demand_copy_C_string (&len);
10798 ignore_rest_of_line ();
10802 /* Make a copy of name string. */
10803 len = strlen (name) + 1;
10804 obstack_grow (¬es, name, len);
10805 name = obstack_finish (¬es);
10810 ahash = secalias_hash;
10811 nhash = secalias_name_hash;
10816 ahash = alias_hash;
10817 nhash = alias_name_hash;
10820 /* Check if alias has been used before. */
10821 h = (struct alias *) hash_find (ahash, alias);
10824 if (strcmp (h->name, name))
10825 as_bad (_("`%s' is already the alias of %s `%s'"),
10826 alias, kind, h->name);
10830 /* Check if name already has an alias. */
10831 a = (const char *) hash_find (nhash, name);
10834 if (strcmp (a, alias))
10835 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
10839 h = (struct alias *) xmalloc (sizeof (struct alias));
10840 as_where (&h->file, &h->line);
10843 error_string = hash_jam (ahash, alias, (PTR) h);
10846 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
10847 alias, kind, error_string);
10851 error_string = hash_jam (nhash, name, (PTR) alias);
10854 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
10855 alias, kind, error_string);
10857 obstack_free (¬es, name);
10858 obstack_free (¬es, alias);
10861 demand_empty_rest_of_line ();
10864 /* It renames the original symbol name to its alias. */
10866 do_alias (const char *alias, PTR value)
10868 struct alias *h = (struct alias *) value;
10869 symbolS *sym = symbol_find (h->name);
10872 as_warn_where (h->file, h->line,
10873 _("symbol `%s' aliased to `%s' is not used"),
10876 S_SET_NAME (sym, (char *) alias);
10879 /* Called from write_object_file. */
10881 ia64_adjust_symtab (void)
10883 hash_traverse (alias_hash, do_alias);
10886 /* It renames the original section name to its alias. */
10888 do_secalias (const char *alias, PTR value)
10890 struct alias *h = (struct alias *) value;
10891 segT sec = bfd_get_section_by_name (stdoutput, h->name);
10894 as_warn_where (h->file, h->line,
10895 _("section `%s' aliased to `%s' is not used"),
10901 /* Called from write_object_file. */
10903 ia64_frob_file (void)
10905 hash_traverse (secalias_hash, do_secalias);