1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
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, { ELFOSABI_NONE } },
542 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
543 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
544 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
545 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
546 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
547 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
549 /* unwind-related registers: */
550 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
553 /* 41-bit nop opcodes (one per unit): */
554 static const bfd_vma nop[IA64_NUM_UNITS] =
556 0x0000000000LL, /* NIL => break 0 */
557 0x0008000000LL, /* I-unit nop */
558 0x0008000000LL, /* M-unit nop */
559 0x4000000000LL, /* B-unit nop */
560 0x0008000000LL, /* F-unit nop */
561 0x0008000000LL, /* L-"unit" nop */
562 0x0008000000LL, /* X-unit nop */
565 /* Can't be `const' as it's passed to input routines (which have the
566 habit of setting temporary sentinels. */
567 static char special_section_name[][20] =
569 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
570 {".IA_64.unwind"}, {".IA_64.unwind_info"},
571 {".init_array"}, {".fini_array"}
574 /* The best template for a particular sequence of up to three
576 #define N IA64_NUM_TYPES
577 static unsigned char best_template[N][N][N];
580 /* Resource dependencies currently in effect */
582 int depind; /* dependency index */
583 const struct ia64_dependency *dependency; /* actual dependency */
584 unsigned specific:1, /* is this a specific bit/regno? */
585 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
586 int index; /* specific regno/bit within dependency */
587 int note; /* optional qualifying note (0 if none) */
591 int insn_srlz; /* current insn serialization state */
592 int data_srlz; /* current data serialization state */
593 int qp_regno; /* qualifying predicate for this usage */
594 char *file; /* what file marked this dependency */
595 unsigned int line; /* what line marked this dependency */
596 struct mem_offset mem_offset; /* optional memory offset hint */
597 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
598 int path; /* corresponding code entry index */
600 static int regdepslen = 0;
601 static int regdepstotlen = 0;
602 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
603 static const char *dv_sem[] = { "none", "implied", "impliedf",
604 "data", "instr", "specific", "stop", "other" };
605 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
607 /* Current state of PR mutexation */
608 static struct qpmutex {
611 } *qp_mutexes = NULL; /* QP mutex bitmasks */
612 static int qp_mutexeslen = 0;
613 static int qp_mutexestotlen = 0;
614 static valueT qp_safe_across_calls = 0;
616 /* Current state of PR implications */
617 static struct qp_imply {
620 unsigned p2_branched:1;
622 } *qp_implies = NULL;
623 static int qp_implieslen = 0;
624 static int qp_impliestotlen = 0;
626 /* Keep track of static GR values so that indirect register usage can
627 sometimes be tracked. */
632 } gr_values[128] = {{ 1, 0, 0 }};
634 /* Remember the alignment frag. */
635 static fragS *align_frag;
637 /* These are the routines required to output the various types of
640 /* A slot_number is a frag address plus the slot index (0-2). We use the
641 frag address here so that if there is a section switch in the middle of
642 a function, then instructions emitted to a different section are not
643 counted. Since there may be more than one frag for a function, this
644 means we also need to keep track of which frag this address belongs to
645 so we can compute inter-frag distances. This also nicely solves the
646 problem with nops emitted for align directives, which can't easily be
647 counted, but can easily be derived from frag sizes. */
649 typedef struct unw_rec_list {
651 unsigned long slot_number;
653 unsigned long next_slot_number;
654 fragS *next_slot_frag;
655 struct unw_rec_list *next;
658 #define SLOT_NUM_NOT_SET (unsigned)-1
660 /* Linked list of saved prologue counts. A very poor
661 implementation of a map from label numbers to prologue counts. */
662 typedef struct label_prologue_count
664 struct label_prologue_count *next;
665 unsigned long label_number;
666 unsigned int prologue_count;
667 } label_prologue_count;
671 /* Maintain a list of unwind entries for the current function. */
675 /* Any unwind entires that should be attached to the current slot
676 that an insn is being constructed for. */
677 unw_rec_list *current_entry;
679 /* These are used to create the unwind table entry for this function. */
682 symbolS *info; /* pointer to unwind info */
683 symbolS *personality_routine;
685 subsegT saved_text_subseg;
686 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
688 /* TRUE if processing unwind directives in a prologue region. */
691 unsigned int prologue_count; /* number of .prologues seen so far */
692 /* Prologue counts at previous .label_state directives. */
693 struct label_prologue_count * saved_prologue_counts;
696 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
698 /* Forward declarations: */
699 static int ar_is_in_integer_unit PARAMS ((int regnum));
700 static void set_section PARAMS ((char *name));
701 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
702 unsigned int, unsigned int));
703 static void dot_align (int);
704 static void dot_radix PARAMS ((int));
705 static void dot_special_section PARAMS ((int));
706 static void dot_proc PARAMS ((int));
707 static void dot_fframe PARAMS ((int));
708 static void dot_vframe PARAMS ((int));
709 static void dot_vframesp PARAMS ((int));
710 static void dot_vframepsp PARAMS ((int));
711 static void dot_save PARAMS ((int));
712 static void dot_restore PARAMS ((int));
713 static void dot_restorereg PARAMS ((int));
714 static void dot_restorereg_p PARAMS ((int));
715 static void dot_handlerdata PARAMS ((int));
716 static void dot_unwentry PARAMS ((int));
717 static void dot_altrp PARAMS ((int));
718 static void dot_savemem PARAMS ((int));
719 static void dot_saveg PARAMS ((int));
720 static void dot_savef PARAMS ((int));
721 static void dot_saveb PARAMS ((int));
722 static void dot_savegf PARAMS ((int));
723 static void dot_spill PARAMS ((int));
724 static void dot_spillreg PARAMS ((int));
725 static void dot_spillmem PARAMS ((int));
726 static void dot_spillreg_p PARAMS ((int));
727 static void dot_spillmem_p PARAMS ((int));
728 static void dot_label_state PARAMS ((int));
729 static void dot_copy_state PARAMS ((int));
730 static void dot_unwabi PARAMS ((int));
731 static void dot_personality PARAMS ((int));
732 static void dot_body PARAMS ((int));
733 static void dot_prologue PARAMS ((int));
734 static void dot_endp PARAMS ((int));
735 static void dot_template PARAMS ((int));
736 static void dot_regstk PARAMS ((int));
737 static void dot_rot PARAMS ((int));
738 static void dot_byteorder PARAMS ((int));
739 static void dot_psr PARAMS ((int));
740 static void dot_alias PARAMS ((int));
741 static void dot_ln PARAMS ((int));
742 static char *parse_section_name PARAMS ((void));
743 static void dot_xdata PARAMS ((int));
744 static void stmt_float_cons PARAMS ((int));
745 static void stmt_cons_ua PARAMS ((int));
746 static void dot_xfloat_cons PARAMS ((int));
747 static void dot_xstringer PARAMS ((int));
748 static void dot_xdata_ua PARAMS ((int));
749 static void dot_xfloat_cons_ua PARAMS ((int));
750 static void print_prmask PARAMS ((valueT mask));
751 static void dot_pred_rel PARAMS ((int));
752 static void dot_reg_val PARAMS ((int));
753 static void dot_serialize PARAMS ((int));
754 static void dot_dv_mode PARAMS ((int));
755 static void dot_entry PARAMS ((int));
756 static void dot_mem_offset PARAMS ((int));
757 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
758 static symbolS *declare_register PARAMS ((const char *name, int regnum));
759 static void declare_register_set PARAMS ((const char *, int, int));
760 static unsigned int operand_width PARAMS ((enum ia64_opnd));
761 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
764 static int parse_operand PARAMS ((expressionS *e));
765 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
766 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
767 static void build_insn PARAMS ((struct slot *, bfd_vma *));
768 static void emit_one_bundle PARAMS ((void));
769 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
770 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
771 bfd_reloc_code_real_type r_type));
772 static void insn_group_break PARAMS ((int, int, int));
773 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
774 struct rsrc *, int depind, int path));
775 static void add_qp_mutex PARAMS((valueT mask));
776 static void add_qp_imply PARAMS((int p1, int p2));
777 static void clear_qp_branch_flag PARAMS((valueT mask));
778 static void clear_qp_mutex PARAMS((valueT mask));
779 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
780 static int has_suffix_p PARAMS((const char *, const char *));
781 static void clear_register_values PARAMS ((void));
782 static void print_dependency PARAMS ((const char *action, int depind));
783 static void instruction_serialization PARAMS ((void));
784 static void data_serialization PARAMS ((void));
785 static void remove_marked_resource PARAMS ((struct rsrc *));
786 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
787 static int is_taken_branch PARAMS ((struct ia64_opcode *));
788 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
789 static int depends_on PARAMS ((int, struct ia64_opcode *));
790 static int specify_resource PARAMS ((const struct ia64_dependency *,
791 struct ia64_opcode *, int, struct rsrc [], int, int));
792 static int check_dv PARAMS((struct ia64_opcode *idesc));
793 static void check_dependencies PARAMS((struct ia64_opcode *));
794 static void mark_resources PARAMS((struct ia64_opcode *));
795 static void update_dependencies PARAMS((struct ia64_opcode *));
796 static void note_register_values PARAMS((struct ia64_opcode *));
797 static int qp_mutex PARAMS ((int, int, int));
798 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
799 static void output_vbyte_mem PARAMS ((int, char *, char *));
800 static void count_output PARAMS ((int, char *, char *));
801 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
802 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
803 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
804 static void output_P1_format PARAMS ((vbyte_func, int));
805 static void output_P2_format PARAMS ((vbyte_func, int, int));
806 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
807 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
808 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
809 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
810 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
811 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
812 static void output_P9_format PARAMS ((vbyte_func, int, int));
813 static void output_P10_format PARAMS ((vbyte_func, int, int));
814 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
815 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
816 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
817 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
818 static char format_ab_reg PARAMS ((int, int));
819 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
821 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
822 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
824 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
825 static unw_rec_list *output_endp PARAMS ((void));
826 static unw_rec_list *output_prologue PARAMS ((void));
827 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
828 static unw_rec_list *output_body PARAMS ((void));
829 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
830 static unw_rec_list *output_mem_stack_v PARAMS ((void));
831 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
832 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
833 static unw_rec_list *output_rp_when PARAMS ((void));
834 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
835 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
836 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
837 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
838 static unw_rec_list *output_pfs_when PARAMS ((void));
839 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
840 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
841 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
842 static unw_rec_list *output_preds_when PARAMS ((void));
843 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
844 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
845 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
846 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
847 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
848 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
849 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
850 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
851 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
852 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
853 static unw_rec_list *output_unat_when PARAMS ((void));
854 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
855 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
856 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
857 static unw_rec_list *output_lc_when PARAMS ((void));
858 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
859 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
860 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
861 static unw_rec_list *output_fpsr_when PARAMS ((void));
862 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
863 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
864 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
865 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
866 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
867 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
868 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
869 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
870 static unw_rec_list *output_bsp_when PARAMS ((void));
871 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
872 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
873 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
874 static unw_rec_list *output_bspstore_when PARAMS ((void));
875 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
876 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
877 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
878 static unw_rec_list *output_rnat_when PARAMS ((void));
879 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
880 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
881 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
882 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
883 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
884 static unw_rec_list *output_label_state PARAMS ((unsigned long));
885 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
886 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
887 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
888 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
890 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
892 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
894 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
895 unsigned int, unsigned int));
896 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
897 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
898 static int calc_record_size PARAMS ((unw_rec_list *));
899 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
900 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
901 unsigned long, fragS *,
903 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
904 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
905 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
906 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
907 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
908 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
909 static void free_saved_prologue_counts PARAMS ((void));
911 /* Determine if application register REGNUM resides in the integer
912 unit (as opposed to the memory unit). */
914 ar_is_in_integer_unit (reg)
919 return (reg == 64 /* pfs */
920 || reg == 65 /* lc */
921 || reg == 66 /* ec */
922 /* ??? ias accepts and puts these in the integer unit. */
923 || (reg >= 112 && reg <= 127));
926 /* Switch to section NAME and create section if necessary. It's
927 rather ugly that we have to manipulate input_line_pointer but I
928 don't see any other way to accomplish the same thing without
929 changing obj-elf.c (which may be the Right Thing, in the end). */
934 char *saved_input_line_pointer;
936 saved_input_line_pointer = input_line_pointer;
937 input_line_pointer = name;
939 input_line_pointer = saved_input_line_pointer;
942 /* Map 's' to SHF_IA_64_SHORT. */
945 ia64_elf_section_letter (letter, ptr_msg)
950 return SHF_IA_64_SHORT;
951 else if (letter == 'o')
952 return SHF_LINK_ORDER;
954 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
958 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
961 ia64_elf_section_flags (flags, attr, type)
963 int attr, type ATTRIBUTE_UNUSED;
965 if (attr & SHF_IA_64_SHORT)
966 flags |= SEC_SMALL_DATA;
971 ia64_elf_section_type (str, len)
975 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
977 if (STREQ (ELF_STRING_ia64_unwind_info))
980 if (STREQ (ELF_STRING_ia64_unwind_info_once))
983 if (STREQ (ELF_STRING_ia64_unwind))
984 return SHT_IA_64_UNWIND;
986 if (STREQ (ELF_STRING_ia64_unwind_once))
987 return SHT_IA_64_UNWIND;
989 if (STREQ ("unwind"))
990 return SHT_IA_64_UNWIND;
992 if (STREQ ("init_array"))
993 return SHT_INIT_ARRAY;
995 if (STREQ ("fini_array"))
996 return SHT_FINI_ARRAY;
1003 set_regstack (ins, locs, outs, rots)
1004 unsigned int ins, locs, outs, rots;
1006 /* Size of frame. */
1009 sof = ins + locs + outs;
1012 as_bad ("Size of frame exceeds maximum of 96 registers");
1017 as_warn ("Size of rotating registers exceeds frame size");
1020 md.in.base = REG_GR + 32;
1021 md.loc.base = md.in.base + ins;
1022 md.out.base = md.loc.base + locs;
1024 md.in.num_regs = ins;
1025 md.loc.num_regs = locs;
1026 md.out.num_regs = outs;
1027 md.rot.num_regs = rots;
1034 struct label_fix *lfix;
1036 subsegT saved_subseg;
1039 if (!md.last_text_seg)
1042 saved_seg = now_seg;
1043 saved_subseg = now_subseg;
1045 subseg_set (md.last_text_seg, 0);
1047 while (md.num_slots_in_use > 0)
1048 emit_one_bundle (); /* force out queued instructions */
1050 /* In case there are labels following the last instruction, resolve
1052 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1054 S_SET_VALUE (lfix->sym, frag_now_fix ());
1055 symbol_set_frag (lfix->sym, frag_now);
1057 CURR_SLOT.label_fixups = 0;
1058 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1060 S_SET_VALUE (lfix->sym, frag_now_fix ());
1061 symbol_set_frag (lfix->sym, frag_now);
1063 CURR_SLOT.tag_fixups = 0;
1065 /* In case there are unwind directives following the last instruction,
1066 resolve those now. We only handle prologue, body, and endp directives
1067 here. Give an error for others. */
1068 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1070 switch (ptr->r.type)
1076 ptr->slot_number = (unsigned long) frag_more (0);
1077 ptr->slot_frag = frag_now;
1080 /* Allow any record which doesn't have a "t" field (i.e.,
1081 doesn't relate to a particular instruction). */
1097 as_bad (_("Unwind directive not followed by an instruction."));
1101 unwind.current_entry = NULL;
1103 subseg_set (saved_seg, saved_subseg);
1105 if (md.qp.X_op == O_register)
1106 as_bad ("qualifying predicate not followed by instruction");
1110 ia64_do_align (int nbytes)
1112 char *saved_input_line_pointer = input_line_pointer;
1114 input_line_pointer = "";
1115 s_align_bytes (nbytes);
1116 input_line_pointer = saved_input_line_pointer;
1120 ia64_cons_align (nbytes)
1125 char *saved_input_line_pointer = input_line_pointer;
1126 input_line_pointer = "";
1127 s_align_bytes (nbytes);
1128 input_line_pointer = saved_input_line_pointer;
1132 /* Output COUNT bytes to a memory location. */
1133 static unsigned char *vbyte_mem_ptr = NULL;
1136 output_vbyte_mem (count, ptr, comment)
1139 char *comment ATTRIBUTE_UNUSED;
1142 if (vbyte_mem_ptr == NULL)
1147 for (x = 0; x < count; x++)
1148 *(vbyte_mem_ptr++) = ptr[x];
1151 /* Count the number of bytes required for records. */
1152 static int vbyte_count = 0;
1154 count_output (count, ptr, comment)
1156 char *ptr ATTRIBUTE_UNUSED;
1157 char *comment ATTRIBUTE_UNUSED;
1159 vbyte_count += count;
1163 output_R1_format (f, rtype, rlen)
1165 unw_record_type rtype;
1172 output_R3_format (f, rtype, rlen);
1178 else if (rtype != prologue)
1179 as_bad ("record type is not valid");
1181 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1182 (*f) (1, &byte, NULL);
1186 output_R2_format (f, mask, grsave, rlen)
1193 mask = (mask & 0x0f);
1194 grsave = (grsave & 0x7f);
1196 bytes[0] = (UNW_R2 | (mask >> 1));
1197 bytes[1] = (((mask & 0x01) << 7) | grsave);
1198 count += output_leb128 (bytes + 2, rlen, 0);
1199 (*f) (count, bytes, NULL);
1203 output_R3_format (f, rtype, rlen)
1205 unw_record_type rtype;
1212 output_R1_format (f, rtype, rlen);
1218 else if (rtype != prologue)
1219 as_bad ("record type is not valid");
1220 bytes[0] = (UNW_R3 | r);
1221 count = output_leb128 (bytes + 1, rlen, 0);
1222 (*f) (count + 1, bytes, NULL);
1226 output_P1_format (f, brmask)
1231 byte = UNW_P1 | (brmask & 0x1f);
1232 (*f) (1, &byte, NULL);
1236 output_P2_format (f, brmask, gr)
1242 brmask = (brmask & 0x1f);
1243 bytes[0] = UNW_P2 | (brmask >> 1);
1244 bytes[1] = (((brmask & 1) << 7) | gr);
1245 (*f) (2, bytes, NULL);
1249 output_P3_format (f, rtype, reg)
1251 unw_record_type rtype;
1296 as_bad ("Invalid record type for P3 format.");
1298 bytes[0] = (UNW_P3 | (r >> 1));
1299 bytes[1] = (((r & 1) << 7) | reg);
1300 (*f) (2, bytes, NULL);
1304 output_P4_format (f, imask, imask_size)
1306 unsigned char *imask;
1307 unsigned long imask_size;
1310 (*f) (imask_size, imask, NULL);
1314 output_P5_format (f, grmask, frmask)
1317 unsigned long frmask;
1320 grmask = (grmask & 0x0f);
1323 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1324 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1325 bytes[3] = (frmask & 0x000000ff);
1326 (*f) (4, bytes, NULL);
1330 output_P6_format (f, rtype, rmask)
1332 unw_record_type rtype;
1338 if (rtype == gr_mem)
1340 else if (rtype != fr_mem)
1341 as_bad ("Invalid record type for format P6");
1342 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1343 (*f) (1, &byte, NULL);
1347 output_P7_format (f, rtype, w1, w2)
1349 unw_record_type rtype;
1356 count += output_leb128 (bytes + 1, w1, 0);
1361 count += output_leb128 (bytes + count, w2 >> 4, 0);
1411 bytes[0] = (UNW_P7 | r);
1412 (*f) (count, bytes, NULL);
1416 output_P8_format (f, rtype, t)
1418 unw_record_type rtype;
1457 case bspstore_psprel:
1460 case bspstore_sprel:
1472 case priunat_when_gr:
1475 case priunat_psprel:
1481 case priunat_when_mem:
1488 count += output_leb128 (bytes + 2, t, 0);
1489 (*f) (count, bytes, NULL);
1493 output_P9_format (f, grmask, gr)
1500 bytes[1] = (grmask & 0x0f);
1501 bytes[2] = (gr & 0x7f);
1502 (*f) (3, bytes, NULL);
1506 output_P10_format (f, abi, context)
1513 bytes[1] = (abi & 0xff);
1514 bytes[2] = (context & 0xff);
1515 (*f) (3, bytes, NULL);
1519 output_B1_format (f, rtype, label)
1521 unw_record_type rtype;
1522 unsigned long label;
1528 output_B4_format (f, rtype, label);
1531 if (rtype == copy_state)
1533 else if (rtype != label_state)
1534 as_bad ("Invalid record type for format B1");
1536 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1537 (*f) (1, &byte, NULL);
1541 output_B2_format (f, ecount, t)
1543 unsigned long ecount;
1550 output_B3_format (f, ecount, t);
1553 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1554 count += output_leb128 (bytes + 1, t, 0);
1555 (*f) (count, bytes, NULL);
1559 output_B3_format (f, ecount, t)
1561 unsigned long ecount;
1568 output_B2_format (f, ecount, t);
1572 count += output_leb128 (bytes + 1, t, 0);
1573 count += output_leb128 (bytes + count, ecount, 0);
1574 (*f) (count, bytes, NULL);
1578 output_B4_format (f, rtype, label)
1580 unw_record_type rtype;
1581 unsigned long label;
1588 output_B1_format (f, rtype, label);
1592 if (rtype == copy_state)
1594 else if (rtype != label_state)
1595 as_bad ("Invalid record type for format B1");
1597 bytes[0] = (UNW_B4 | (r << 3));
1598 count += output_leb128 (bytes + 1, label, 0);
1599 (*f) (count, bytes, NULL);
1603 format_ab_reg (ab, reg)
1610 ret = (ab << 5) | reg;
1615 output_X1_format (f, rtype, ab, reg, t, w1)
1617 unw_record_type rtype;
1627 if (rtype == spill_sprel)
1629 else if (rtype != spill_psprel)
1630 as_bad ("Invalid record type for format X1");
1631 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1632 count += output_leb128 (bytes + 2, t, 0);
1633 count += output_leb128 (bytes + count, w1, 0);
1634 (*f) (count, bytes, NULL);
1638 output_X2_format (f, ab, reg, x, y, treg, t)
1647 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1648 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1649 count += output_leb128 (bytes + 3, t, 0);
1650 (*f) (count, bytes, NULL);
1654 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1656 unw_record_type rtype;
1667 if (rtype == spill_sprel_p)
1669 else if (rtype != spill_psprel_p)
1670 as_bad ("Invalid record type for format X3");
1671 bytes[1] = ((r << 7) | (qp & 0x3f));
1672 bytes[2] = format_ab_reg (ab, reg);
1673 count += output_leb128 (bytes + 3, t, 0);
1674 count += output_leb128 (bytes + count, w1, 0);
1675 (*f) (count, bytes, NULL);
1679 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1689 bytes[1] = (qp & 0x3f);
1690 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1691 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1692 count += output_leb128 (bytes + 4, t, 0);
1693 (*f) (count, bytes, NULL);
1696 /* This function allocates a record list structure, and initializes fields. */
1698 static unw_rec_list *
1699 alloc_record (unw_record_type t)
1702 ptr = xmalloc (sizeof (*ptr));
1704 ptr->slot_number = SLOT_NUM_NOT_SET;
1706 ptr->next_slot_number = 0;
1707 ptr->next_slot_frag = 0;
1711 /* Dummy unwind record used for calculating the length of the last prologue or
1714 static unw_rec_list *
1717 unw_rec_list *ptr = alloc_record (endp);
1721 static unw_rec_list *
1724 unw_rec_list *ptr = alloc_record (prologue);
1725 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1729 static unw_rec_list *
1730 output_prologue_gr (saved_mask, reg)
1731 unsigned int saved_mask;
1734 unw_rec_list *ptr = alloc_record (prologue_gr);
1735 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1736 ptr->r.record.r.grmask = saved_mask;
1737 ptr->r.record.r.grsave = reg;
1741 static unw_rec_list *
1744 unw_rec_list *ptr = alloc_record (body);
1748 static unw_rec_list *
1749 output_mem_stack_f (size)
1752 unw_rec_list *ptr = alloc_record (mem_stack_f);
1753 ptr->r.record.p.size = size;
1757 static unw_rec_list *
1758 output_mem_stack_v ()
1760 unw_rec_list *ptr = alloc_record (mem_stack_v);
1764 static unw_rec_list *
1768 unw_rec_list *ptr = alloc_record (psp_gr);
1769 ptr->r.record.p.gr = gr;
1773 static unw_rec_list *
1774 output_psp_sprel (offset)
1775 unsigned int offset;
1777 unw_rec_list *ptr = alloc_record (psp_sprel);
1778 ptr->r.record.p.spoff = offset / 4;
1782 static unw_rec_list *
1785 unw_rec_list *ptr = alloc_record (rp_when);
1789 static unw_rec_list *
1793 unw_rec_list *ptr = alloc_record (rp_gr);
1794 ptr->r.record.p.gr = gr;
1798 static unw_rec_list *
1802 unw_rec_list *ptr = alloc_record (rp_br);
1803 ptr->r.record.p.br = br;
1807 static unw_rec_list *
1808 output_rp_psprel (offset)
1809 unsigned int offset;
1811 unw_rec_list *ptr = alloc_record (rp_psprel);
1812 ptr->r.record.p.pspoff = offset / 4;
1816 static unw_rec_list *
1817 output_rp_sprel (offset)
1818 unsigned int offset;
1820 unw_rec_list *ptr = alloc_record (rp_sprel);
1821 ptr->r.record.p.spoff = offset / 4;
1825 static unw_rec_list *
1828 unw_rec_list *ptr = alloc_record (pfs_when);
1832 static unw_rec_list *
1836 unw_rec_list *ptr = alloc_record (pfs_gr);
1837 ptr->r.record.p.gr = gr;
1841 static unw_rec_list *
1842 output_pfs_psprel (offset)
1843 unsigned int offset;
1845 unw_rec_list *ptr = alloc_record (pfs_psprel);
1846 ptr->r.record.p.pspoff = offset / 4;
1850 static unw_rec_list *
1851 output_pfs_sprel (offset)
1852 unsigned int offset;
1854 unw_rec_list *ptr = alloc_record (pfs_sprel);
1855 ptr->r.record.p.spoff = offset / 4;
1859 static unw_rec_list *
1860 output_preds_when ()
1862 unw_rec_list *ptr = alloc_record (preds_when);
1866 static unw_rec_list *
1867 output_preds_gr (gr)
1870 unw_rec_list *ptr = alloc_record (preds_gr);
1871 ptr->r.record.p.gr = gr;
1875 static unw_rec_list *
1876 output_preds_psprel (offset)
1877 unsigned int offset;
1879 unw_rec_list *ptr = alloc_record (preds_psprel);
1880 ptr->r.record.p.pspoff = offset / 4;
1884 static unw_rec_list *
1885 output_preds_sprel (offset)
1886 unsigned int offset;
1888 unw_rec_list *ptr = alloc_record (preds_sprel);
1889 ptr->r.record.p.spoff = offset / 4;
1893 static unw_rec_list *
1894 output_fr_mem (mask)
1897 unw_rec_list *ptr = alloc_record (fr_mem);
1898 ptr->r.record.p.rmask = mask;
1902 static unw_rec_list *
1903 output_frgr_mem (gr_mask, fr_mask)
1904 unsigned int gr_mask;
1905 unsigned int fr_mask;
1907 unw_rec_list *ptr = alloc_record (frgr_mem);
1908 ptr->r.record.p.grmask = gr_mask;
1909 ptr->r.record.p.frmask = fr_mask;
1913 static unw_rec_list *
1914 output_gr_gr (mask, reg)
1918 unw_rec_list *ptr = alloc_record (gr_gr);
1919 ptr->r.record.p.grmask = mask;
1920 ptr->r.record.p.gr = reg;
1924 static unw_rec_list *
1925 output_gr_mem (mask)
1928 unw_rec_list *ptr = alloc_record (gr_mem);
1929 ptr->r.record.p.rmask = mask;
1933 static unw_rec_list *
1934 output_br_mem (unsigned int mask)
1936 unw_rec_list *ptr = alloc_record (br_mem);
1937 ptr->r.record.p.brmask = mask;
1941 static unw_rec_list *
1942 output_br_gr (save_mask, reg)
1943 unsigned int save_mask;
1946 unw_rec_list *ptr = alloc_record (br_gr);
1947 ptr->r.record.p.brmask = save_mask;
1948 ptr->r.record.p.gr = reg;
1952 static unw_rec_list *
1953 output_spill_base (offset)
1954 unsigned int offset;
1956 unw_rec_list *ptr = alloc_record (spill_base);
1957 ptr->r.record.p.pspoff = offset / 4;
1961 static unw_rec_list *
1964 unw_rec_list *ptr = alloc_record (unat_when);
1968 static unw_rec_list *
1972 unw_rec_list *ptr = alloc_record (unat_gr);
1973 ptr->r.record.p.gr = gr;
1977 static unw_rec_list *
1978 output_unat_psprel (offset)
1979 unsigned int offset;
1981 unw_rec_list *ptr = alloc_record (unat_psprel);
1982 ptr->r.record.p.pspoff = offset / 4;
1986 static unw_rec_list *
1987 output_unat_sprel (offset)
1988 unsigned int offset;
1990 unw_rec_list *ptr = alloc_record (unat_sprel);
1991 ptr->r.record.p.spoff = offset / 4;
1995 static unw_rec_list *
1998 unw_rec_list *ptr = alloc_record (lc_when);
2002 static unw_rec_list *
2006 unw_rec_list *ptr = alloc_record (lc_gr);
2007 ptr->r.record.p.gr = gr;
2011 static unw_rec_list *
2012 output_lc_psprel (offset)
2013 unsigned int offset;
2015 unw_rec_list *ptr = alloc_record (lc_psprel);
2016 ptr->r.record.p.pspoff = offset / 4;
2020 static unw_rec_list *
2021 output_lc_sprel (offset)
2022 unsigned int offset;
2024 unw_rec_list *ptr = alloc_record (lc_sprel);
2025 ptr->r.record.p.spoff = offset / 4;
2029 static unw_rec_list *
2032 unw_rec_list *ptr = alloc_record (fpsr_when);
2036 static unw_rec_list *
2040 unw_rec_list *ptr = alloc_record (fpsr_gr);
2041 ptr->r.record.p.gr = gr;
2045 static unw_rec_list *
2046 output_fpsr_psprel (offset)
2047 unsigned int offset;
2049 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2050 ptr->r.record.p.pspoff = offset / 4;
2054 static unw_rec_list *
2055 output_fpsr_sprel (offset)
2056 unsigned int offset;
2058 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2059 ptr->r.record.p.spoff = offset / 4;
2063 static unw_rec_list *
2064 output_priunat_when_gr ()
2066 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2070 static unw_rec_list *
2071 output_priunat_when_mem ()
2073 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2077 static unw_rec_list *
2078 output_priunat_gr (gr)
2081 unw_rec_list *ptr = alloc_record (priunat_gr);
2082 ptr->r.record.p.gr = gr;
2086 static unw_rec_list *
2087 output_priunat_psprel (offset)
2088 unsigned int offset;
2090 unw_rec_list *ptr = alloc_record (priunat_psprel);
2091 ptr->r.record.p.pspoff = offset / 4;
2095 static unw_rec_list *
2096 output_priunat_sprel (offset)
2097 unsigned int offset;
2099 unw_rec_list *ptr = alloc_record (priunat_sprel);
2100 ptr->r.record.p.spoff = offset / 4;
2104 static unw_rec_list *
2107 unw_rec_list *ptr = alloc_record (bsp_when);
2111 static unw_rec_list *
2115 unw_rec_list *ptr = alloc_record (bsp_gr);
2116 ptr->r.record.p.gr = gr;
2120 static unw_rec_list *
2121 output_bsp_psprel (offset)
2122 unsigned int offset;
2124 unw_rec_list *ptr = alloc_record (bsp_psprel);
2125 ptr->r.record.p.pspoff = offset / 4;
2129 static unw_rec_list *
2130 output_bsp_sprel (offset)
2131 unsigned int offset;
2133 unw_rec_list *ptr = alloc_record (bsp_sprel);
2134 ptr->r.record.p.spoff = offset / 4;
2138 static unw_rec_list *
2139 output_bspstore_when ()
2141 unw_rec_list *ptr = alloc_record (bspstore_when);
2145 static unw_rec_list *
2146 output_bspstore_gr (gr)
2149 unw_rec_list *ptr = alloc_record (bspstore_gr);
2150 ptr->r.record.p.gr = gr;
2154 static unw_rec_list *
2155 output_bspstore_psprel (offset)
2156 unsigned int offset;
2158 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2159 ptr->r.record.p.pspoff = offset / 4;
2163 static unw_rec_list *
2164 output_bspstore_sprel (offset)
2165 unsigned int offset;
2167 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2168 ptr->r.record.p.spoff = offset / 4;
2172 static unw_rec_list *
2175 unw_rec_list *ptr = alloc_record (rnat_when);
2179 static unw_rec_list *
2183 unw_rec_list *ptr = alloc_record (rnat_gr);
2184 ptr->r.record.p.gr = gr;
2188 static unw_rec_list *
2189 output_rnat_psprel (offset)
2190 unsigned int offset;
2192 unw_rec_list *ptr = alloc_record (rnat_psprel);
2193 ptr->r.record.p.pspoff = offset / 4;
2197 static unw_rec_list *
2198 output_rnat_sprel (offset)
2199 unsigned int offset;
2201 unw_rec_list *ptr = alloc_record (rnat_sprel);
2202 ptr->r.record.p.spoff = offset / 4;
2206 static unw_rec_list *
2207 output_unwabi (abi, context)
2209 unsigned long context;
2211 unw_rec_list *ptr = alloc_record (unwabi);
2212 ptr->r.record.p.abi = abi;
2213 ptr->r.record.p.context = context;
2217 static unw_rec_list *
2218 output_epilogue (unsigned long ecount)
2220 unw_rec_list *ptr = alloc_record (epilogue);
2221 ptr->r.record.b.ecount = ecount;
2225 static unw_rec_list *
2226 output_label_state (unsigned long label)
2228 unw_rec_list *ptr = alloc_record (label_state);
2229 ptr->r.record.b.label = label;
2233 static unw_rec_list *
2234 output_copy_state (unsigned long label)
2236 unw_rec_list *ptr = alloc_record (copy_state);
2237 ptr->r.record.b.label = label;
2241 static unw_rec_list *
2242 output_spill_psprel (ab, reg, offset)
2245 unsigned int offset;
2247 unw_rec_list *ptr = alloc_record (spill_psprel);
2248 ptr->r.record.x.ab = ab;
2249 ptr->r.record.x.reg = reg;
2250 ptr->r.record.x.pspoff = offset / 4;
2254 static unw_rec_list *
2255 output_spill_sprel (ab, reg, offset)
2258 unsigned int offset;
2260 unw_rec_list *ptr = alloc_record (spill_sprel);
2261 ptr->r.record.x.ab = ab;
2262 ptr->r.record.x.reg = reg;
2263 ptr->r.record.x.spoff = offset / 4;
2267 static unw_rec_list *
2268 output_spill_psprel_p (ab, reg, offset, predicate)
2271 unsigned int offset;
2272 unsigned int predicate;
2274 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2275 ptr->r.record.x.ab = ab;
2276 ptr->r.record.x.reg = reg;
2277 ptr->r.record.x.pspoff = offset / 4;
2278 ptr->r.record.x.qp = predicate;
2282 static unw_rec_list *
2283 output_spill_sprel_p (ab, reg, offset, predicate)
2286 unsigned int offset;
2287 unsigned int predicate;
2289 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2290 ptr->r.record.x.ab = ab;
2291 ptr->r.record.x.reg = reg;
2292 ptr->r.record.x.spoff = offset / 4;
2293 ptr->r.record.x.qp = predicate;
2297 static unw_rec_list *
2298 output_spill_reg (ab, reg, targ_reg, xy)
2301 unsigned int targ_reg;
2304 unw_rec_list *ptr = alloc_record (spill_reg);
2305 ptr->r.record.x.ab = ab;
2306 ptr->r.record.x.reg = reg;
2307 ptr->r.record.x.treg = targ_reg;
2308 ptr->r.record.x.xy = xy;
2312 static unw_rec_list *
2313 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2316 unsigned int targ_reg;
2318 unsigned int predicate;
2320 unw_rec_list *ptr = alloc_record (spill_reg_p);
2321 ptr->r.record.x.ab = ab;
2322 ptr->r.record.x.reg = reg;
2323 ptr->r.record.x.treg = targ_reg;
2324 ptr->r.record.x.xy = xy;
2325 ptr->r.record.x.qp = predicate;
2329 /* Given a unw_rec_list process the correct format with the
2330 specified function. */
2333 process_one_record (ptr, f)
2337 unsigned long fr_mask, gr_mask;
2339 switch (ptr->r.type)
2341 /* This is a dummy record that takes up no space in the output. */
2349 /* These are taken care of by prologue/prologue_gr. */
2354 if (ptr->r.type == prologue_gr)
2355 output_R2_format (f, ptr->r.record.r.grmask,
2356 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2358 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2360 /* Output descriptor(s) for union of register spills (if any). */
2361 gr_mask = ptr->r.record.r.mask.gr_mem;
2362 fr_mask = ptr->r.record.r.mask.fr_mem;
2365 if ((fr_mask & ~0xfUL) == 0)
2366 output_P6_format (f, fr_mem, fr_mask);
2369 output_P5_format (f, gr_mask, fr_mask);
2374 output_P6_format (f, gr_mem, gr_mask);
2375 if (ptr->r.record.r.mask.br_mem)
2376 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2378 /* output imask descriptor if necessary: */
2379 if (ptr->r.record.r.mask.i)
2380 output_P4_format (f, ptr->r.record.r.mask.i,
2381 ptr->r.record.r.imask_size);
2385 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2389 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2390 ptr->r.record.p.size);
2403 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2406 output_P3_format (f, rp_br, ptr->r.record.p.br);
2409 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2417 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2426 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2436 case bspstore_sprel:
2438 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2441 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2444 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2447 as_bad ("spill_mask record unimplemented.");
2449 case priunat_when_gr:
2450 case priunat_when_mem:
2454 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2456 case priunat_psprel:
2458 case bspstore_psprel:
2460 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2463 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2466 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2470 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2473 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2474 ptr->r.record.x.reg, ptr->r.record.x.t,
2475 ptr->r.record.x.pspoff);
2478 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2479 ptr->r.record.x.reg, ptr->r.record.x.t,
2480 ptr->r.record.x.spoff);
2483 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2484 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2485 ptr->r.record.x.treg, ptr->r.record.x.t);
2487 case spill_psprel_p:
2488 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2489 ptr->r.record.x.ab, ptr->r.record.x.reg,
2490 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2493 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2494 ptr->r.record.x.ab, ptr->r.record.x.reg,
2495 ptr->r.record.x.t, ptr->r.record.x.spoff);
2498 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2499 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2500 ptr->r.record.x.xy, ptr->r.record.x.treg,
2504 as_bad ("record_type_not_valid");
2509 /* Given a unw_rec_list list, process all the records with
2510 the specified function. */
2512 process_unw_records (list, f)
2517 for (ptr = list; ptr; ptr = ptr->next)
2518 process_one_record (ptr, f);
2521 /* Determine the size of a record list in bytes. */
2523 calc_record_size (list)
2527 process_unw_records (list, count_output);
2531 /* Update IMASK bitmask to reflect the fact that one or more registers
2532 of type TYPE are saved starting at instruction with index T. If N
2533 bits are set in REGMASK, it is assumed that instructions T through
2534 T+N-1 save these registers.
2538 1: instruction saves next fp reg
2539 2: instruction saves next general reg
2540 3: instruction saves next branch reg */
2542 set_imask (region, regmask, t, type)
2543 unw_rec_list *region;
2544 unsigned long regmask;
2548 unsigned char *imask;
2549 unsigned long imask_size;
2553 imask = region->r.record.r.mask.i;
2554 imask_size = region->r.record.r.imask_size;
2557 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2558 imask = xmalloc (imask_size);
2559 memset (imask, 0, imask_size);
2561 region->r.record.r.imask_size = imask_size;
2562 region->r.record.r.mask.i = imask;
2566 pos = 2 * (3 - t % 4);
2569 if (i >= imask_size)
2571 as_bad ("Ignoring attempt to spill beyond end of region");
2575 imask[i] |= (type & 0x3) << pos;
2577 regmask &= (regmask - 1);
2587 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2588 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2589 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2593 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2594 unsigned long slot_addr;
2596 unsigned long first_addr;
2600 unsigned long index = 0;
2602 /* First time we are called, the initial address and frag are invalid. */
2603 if (first_addr == 0)
2606 /* If the two addresses are in different frags, then we need to add in
2607 the remaining size of this frag, and then the entire size of intermediate
2609 while (slot_frag != first_frag)
2611 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2615 /* We can get the final addresses only during and after
2617 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2618 index += 3 * ((first_frag->fr_next->fr_address
2619 - first_frag->fr_address
2620 - first_frag->fr_fix) >> 4);
2623 /* We don't know what the final addresses will be. We try our
2624 best to estimate. */
2625 switch (first_frag->fr_type)
2631 as_fatal ("only constant space allocation is supported");
2637 /* Take alignment into account. Assume the worst case
2638 before relaxation. */
2639 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2643 if (first_frag->fr_symbol)
2645 as_fatal ("only constant offsets are supported");
2649 index += 3 * (first_frag->fr_offset >> 4);
2653 /* Add in the full size of the frag converted to instruction slots. */
2654 index += 3 * (first_frag->fr_fix >> 4);
2655 /* Subtract away the initial part before first_addr. */
2656 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2657 + ((first_addr & 0x3) - (start_addr & 0x3)));
2659 /* Move to the beginning of the next frag. */
2660 first_frag = first_frag->fr_next;
2661 first_addr = (unsigned long) &first_frag->fr_literal;
2664 /* Add in the used part of the last frag. */
2665 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2666 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2670 /* Optimize unwind record directives. */
2672 static unw_rec_list *
2673 optimize_unw_records (list)
2679 /* If the only unwind record is ".prologue" or ".prologue" followed
2680 by ".body", then we can optimize the unwind directives away. */
2681 if (list->r.type == prologue
2682 && (list->next->r.type == endp
2683 || (list->next->r.type == body && list->next->next->r.type == endp)))
2689 /* Given a complete record list, process any records which have
2690 unresolved fields, (ie length counts for a prologue). After
2691 this has been run, all necessary information should be available
2692 within each record to generate an image. */
2695 fixup_unw_records (list, before_relax)
2699 unw_rec_list *ptr, *region = 0;
2700 unsigned long first_addr = 0, rlen = 0, t;
2701 fragS *first_frag = 0;
2703 for (ptr = list; ptr; ptr = ptr->next)
2705 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2706 as_bad (" Insn slot not set in unwind record.");
2707 t = slot_index (ptr->slot_number, ptr->slot_frag,
2708 first_addr, first_frag, before_relax);
2709 switch (ptr->r.type)
2717 unsigned long last_addr = 0;
2718 fragS *last_frag = NULL;
2720 first_addr = ptr->slot_number;
2721 first_frag = ptr->slot_frag;
2722 /* Find either the next body/prologue start, or the end of
2723 the function, and determine the size of the region. */
2724 for (last = ptr->next; last != NULL; last = last->next)
2725 if (last->r.type == prologue || last->r.type == prologue_gr
2726 || last->r.type == body || last->r.type == endp)
2728 last_addr = last->slot_number;
2729 last_frag = last->slot_frag;
2732 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2734 rlen = ptr->r.record.r.rlen = size;
2735 if (ptr->r.type == body)
2736 /* End of region. */
2743 ptr->r.record.b.t = rlen - 1 - t;
2754 case priunat_when_gr:
2755 case priunat_when_mem:
2759 ptr->r.record.p.t = t;
2767 case spill_psprel_p:
2768 ptr->r.record.x.t = t;
2774 as_bad ("frgr_mem record before region record!\n");
2777 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2778 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2779 set_imask (region, ptr->r.record.p.frmask, t, 1);
2780 set_imask (region, ptr->r.record.p.grmask, t, 2);
2785 as_bad ("fr_mem record before region record!\n");
2788 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2789 set_imask (region, ptr->r.record.p.rmask, t, 1);
2794 as_bad ("gr_mem record before region record!\n");
2797 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2798 set_imask (region, ptr->r.record.p.rmask, t, 2);
2803 as_bad ("br_mem record before region record!\n");
2806 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2807 set_imask (region, ptr->r.record.p.brmask, t, 3);
2813 as_bad ("gr_gr record before region record!\n");
2816 set_imask (region, ptr->r.record.p.grmask, t, 2);
2821 as_bad ("br_gr record before region record!\n");
2824 set_imask (region, ptr->r.record.p.brmask, t, 3);
2833 /* Estimate the size of a frag before relaxing. We only have one type of frag
2834 to handle here, which is the unwind info frag. */
2837 ia64_estimate_size_before_relax (fragS *frag,
2838 asection *segtype ATTRIBUTE_UNUSED)
2843 /* ??? This code is identical to the first part of ia64_convert_frag. */
2844 list = (unw_rec_list *) frag->fr_opcode;
2845 fixup_unw_records (list, 0);
2847 len = calc_record_size (list);
2848 /* pad to pointer-size boundary. */
2849 pad = len % md.pointer_size;
2851 len += md.pointer_size - pad;
2852 /* Add 8 for the header + a pointer for the personality offset. */
2853 size = len + 8 + md.pointer_size;
2855 /* fr_var carries the max_chars that we created the fragment with.
2856 We must, of course, have allocated enough memory earlier. */
2857 assert (frag->fr_var >= size);
2859 return frag->fr_fix + size;
2862 /* This function converts a rs_machine_dependent variant frag into a
2863 normal fill frag with the unwind image from the the record list. */
2865 ia64_convert_frag (fragS *frag)
2871 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2872 list = (unw_rec_list *) frag->fr_opcode;
2873 fixup_unw_records (list, 0);
2875 len = calc_record_size (list);
2876 /* pad to pointer-size boundary. */
2877 pad = len % md.pointer_size;
2879 len += md.pointer_size - pad;
2880 /* Add 8 for the header + a pointer for the personality offset. */
2881 size = len + 8 + md.pointer_size;
2883 /* fr_var carries the max_chars that we created the fragment with.
2884 We must, of course, have allocated enough memory earlier. */
2885 assert (frag->fr_var >= size);
2887 /* Initialize the header area. fr_offset is initialized with
2888 unwind.personality_routine. */
2889 if (frag->fr_offset)
2891 if (md.flags & EF_IA_64_ABI64)
2892 flag_value = (bfd_vma) 3 << 32;
2894 /* 32-bit unwind info block. */
2895 flag_value = (bfd_vma) 0x1003 << 32;
2900 md_number_to_chars (frag->fr_literal,
2901 (((bfd_vma) 1 << 48) /* Version. */
2902 | flag_value /* U & E handler flags. */
2903 | (len / md.pointer_size)), /* Length. */
2906 /* Skip the header. */
2907 vbyte_mem_ptr = frag->fr_literal + 8;
2908 process_unw_records (list, output_vbyte_mem);
2910 /* Fill the padding bytes with zeros. */
2912 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2913 md.pointer_size - pad);
2915 frag->fr_fix += size;
2916 frag->fr_type = rs_fill;
2918 frag->fr_offset = 0;
2922 convert_expr_to_ab_reg (e, ab, regp)
2929 if (e->X_op != O_register)
2932 reg = e->X_add_number;
2933 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2936 *regp = reg - REG_GR;
2938 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2939 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2942 *regp = reg - REG_FR;
2944 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2947 *regp = reg - REG_BR;
2954 case REG_PR: *regp = 0; break;
2955 case REG_PSP: *regp = 1; break;
2956 case REG_PRIUNAT: *regp = 2; break;
2957 case REG_BR + 0: *regp = 3; break;
2958 case REG_AR + AR_BSP: *regp = 4; break;
2959 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2960 case REG_AR + AR_RNAT: *regp = 6; break;
2961 case REG_AR + AR_UNAT: *regp = 7; break;
2962 case REG_AR + AR_FPSR: *regp = 8; break;
2963 case REG_AR + AR_PFS: *regp = 9; break;
2964 case REG_AR + AR_LC: *regp = 10; break;
2974 convert_expr_to_xy_reg (e, xy, regp)
2981 if (e->X_op != O_register)
2984 reg = e->X_add_number;
2986 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2989 *regp = reg - REG_GR;
2991 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2994 *regp = reg - REG_FR;
2996 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2999 *regp = reg - REG_BR;
3009 /* The current frag is an alignment frag. */
3010 align_frag = frag_now;
3011 s_align_bytes (arg);
3016 int dummy ATTRIBUTE_UNUSED;
3021 radix = *input_line_pointer++;
3023 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3025 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3026 ignore_rest_of_line ();
3031 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3033 dot_special_section (which)
3036 set_section ((char *) special_section_name[which]);
3040 add_unwind_entry (ptr)
3044 unwind.tail->next = ptr;
3049 /* The current entry can in fact be a chain of unwind entries. */
3050 if (unwind.current_entry == NULL)
3051 unwind.current_entry = ptr;
3056 int dummy ATTRIBUTE_UNUSED;
3062 if (e.X_op != O_constant)
3063 as_bad ("Operand to .fframe must be a constant");
3065 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3070 int dummy ATTRIBUTE_UNUSED;
3076 reg = e.X_add_number - REG_GR;
3077 if (e.X_op == O_register && reg < 128)
3079 add_unwind_entry (output_mem_stack_v ());
3080 if (! (unwind.prologue_mask & 2))
3081 add_unwind_entry (output_psp_gr (reg));
3084 as_bad ("First operand to .vframe must be a general register");
3088 dot_vframesp (dummy)
3089 int dummy ATTRIBUTE_UNUSED;
3094 if (e.X_op == O_constant)
3096 add_unwind_entry (output_mem_stack_v ());
3097 add_unwind_entry (output_psp_sprel (e.X_add_number));
3100 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3104 dot_vframepsp (dummy)
3105 int dummy ATTRIBUTE_UNUSED;
3110 if (e.X_op == O_constant)
3112 add_unwind_entry (output_mem_stack_v ());
3113 add_unwind_entry (output_psp_sprel (e.X_add_number));
3116 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3121 int dummy ATTRIBUTE_UNUSED;
3127 sep = parse_operand (&e1);
3129 as_bad ("No second operand to .save");
3130 sep = parse_operand (&e2);
3132 reg1 = e1.X_add_number;
3133 reg2 = e2.X_add_number - REG_GR;
3135 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3136 if (e1.X_op == O_register)
3138 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3142 case REG_AR + AR_BSP:
3143 add_unwind_entry (output_bsp_when ());
3144 add_unwind_entry (output_bsp_gr (reg2));
3146 case REG_AR + AR_BSPSTORE:
3147 add_unwind_entry (output_bspstore_when ());
3148 add_unwind_entry (output_bspstore_gr (reg2));
3150 case REG_AR + AR_RNAT:
3151 add_unwind_entry (output_rnat_when ());
3152 add_unwind_entry (output_rnat_gr (reg2));
3154 case REG_AR + AR_UNAT:
3155 add_unwind_entry (output_unat_when ());
3156 add_unwind_entry (output_unat_gr (reg2));
3158 case REG_AR + AR_FPSR:
3159 add_unwind_entry (output_fpsr_when ());
3160 add_unwind_entry (output_fpsr_gr (reg2));
3162 case REG_AR + AR_PFS:
3163 add_unwind_entry (output_pfs_when ());
3164 if (! (unwind.prologue_mask & 4))
3165 add_unwind_entry (output_pfs_gr (reg2));
3167 case REG_AR + AR_LC:
3168 add_unwind_entry (output_lc_when ());
3169 add_unwind_entry (output_lc_gr (reg2));
3172 add_unwind_entry (output_rp_when ());
3173 if (! (unwind.prologue_mask & 8))
3174 add_unwind_entry (output_rp_gr (reg2));
3177 add_unwind_entry (output_preds_when ());
3178 if (! (unwind.prologue_mask & 1))
3179 add_unwind_entry (output_preds_gr (reg2));
3182 add_unwind_entry (output_priunat_when_gr ());
3183 add_unwind_entry (output_priunat_gr (reg2));
3186 as_bad ("First operand not a valid register");
3190 as_bad (" Second operand not a valid register");
3193 as_bad ("First operand not a register");
3198 int dummy ATTRIBUTE_UNUSED;
3201 unsigned long ecount; /* # of _additional_ regions to pop */
3204 sep = parse_operand (&e1);
3205 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3207 as_bad ("First operand to .restore must be stack pointer (sp)");
3213 parse_operand (&e2);
3214 if (e2.X_op != O_constant || e2.X_add_number < 0)
3216 as_bad ("Second operand to .restore must be a constant >= 0");
3219 ecount = e2.X_add_number;
3222 ecount = unwind.prologue_count - 1;
3224 if (ecount >= unwind.prologue_count)
3226 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3227 ecount + 1, unwind.prologue_count);
3231 add_unwind_entry (output_epilogue (ecount));
3233 if (ecount < unwind.prologue_count)
3234 unwind.prologue_count -= ecount + 1;
3236 unwind.prologue_count = 0;
3240 dot_restorereg (dummy)
3241 int dummy ATTRIBUTE_UNUSED;
3243 unsigned int ab, reg;
3248 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3250 as_bad ("First operand to .restorereg must be a preserved register");
3253 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3257 dot_restorereg_p (dummy)
3258 int dummy ATTRIBUTE_UNUSED;
3260 unsigned int qp, ab, reg;
3264 sep = parse_operand (&e1);
3267 as_bad ("No second operand to .restorereg.p");
3271 parse_operand (&e2);
3273 qp = e1.X_add_number - REG_P;
3274 if (e1.X_op != O_register || qp > 63)
3276 as_bad ("First operand to .restorereg.p must be a predicate");
3280 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3282 as_bad ("Second operand to .restorereg.p must be a preserved register");
3285 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3288 static char *special_linkonce_name[] =
3290 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3294 start_unwind_section (const segT text_seg, int sec_index)
3297 Use a slightly ugly scheme to derive the unwind section names from
3298 the text section name:
3300 text sect. unwind table sect.
3301 name: name: comments:
3302 ---------- ----------------- --------------------------------
3304 .text.foo .IA_64.unwind.text.foo
3305 .foo .IA_64.unwind.foo
3307 .gnu.linkonce.ia64unw.foo
3308 _info .IA_64.unwind_info gas issues error message (ditto)
3309 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3311 This mapping is done so that:
3313 (a) An object file with unwind info only in .text will use
3314 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3315 This follows the letter of the ABI and also ensures backwards
3316 compatibility with older toolchains.
3318 (b) An object file with unwind info in multiple text sections
3319 will use separate unwind sections for each text section.
3320 This allows us to properly set the "sh_info" and "sh_link"
3321 fields in SHT_IA_64_UNWIND as required by the ABI and also
3322 lets GNU ld support programs with multiple segments
3323 containing unwind info (as might be the case for certain
3324 embedded applications).
3326 (c) An error is issued if there would be a name clash.
3329 const char *text_name, *sec_text_name;
3331 const char *prefix = special_section_name [sec_index];
3333 size_t prefix_len, suffix_len, sec_name_len;
3335 sec_text_name = segment_name (text_seg);
3336 text_name = sec_text_name;
3337 if (strncmp (text_name, "_info", 5) == 0)
3339 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3341 ignore_rest_of_line ();
3344 if (strcmp (text_name, ".text") == 0)
3347 /* Build the unwind section name by appending the (possibly stripped)
3348 text section name to the unwind prefix. */
3350 if (strncmp (text_name, ".gnu.linkonce.t.",
3351 sizeof (".gnu.linkonce.t.") - 1) == 0)
3353 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3354 suffix += sizeof (".gnu.linkonce.t.") - 1;
3357 prefix_len = strlen (prefix);
3358 suffix_len = strlen (suffix);
3359 sec_name_len = prefix_len + suffix_len;
3360 sec_name = alloca (sec_name_len + 1);
3361 memcpy (sec_name, prefix, prefix_len);
3362 memcpy (sec_name + prefix_len, suffix, suffix_len);
3363 sec_name [sec_name_len] = '\0';
3365 /* Handle COMDAT group. */
3366 if (suffix == text_name && (text_seg->flags & SEC_LINK_ONCE) != 0)
3369 size_t len, group_name_len;
3370 const char *group_name = elf_group_name (text_seg);
3372 if (group_name == NULL)
3374 as_bad ("Group section `%s' has no group signature",
3376 ignore_rest_of_line ();
3379 /* We have to construct a fake section directive. */
3380 group_name_len = strlen (group_name);
3382 + 16 /* ,"aG",@progbits, */
3383 + group_name_len /* ,group_name */
3386 section = alloca (len + 1);
3387 memcpy (section, sec_name, sec_name_len);
3388 memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3389 memcpy (section + sec_name_len + 16, group_name, group_name_len);
3390 memcpy (section + len - 7, ",comdat", 7);
3391 section [len] = '\0';
3392 set_section (section);
3396 set_section (sec_name);
3397 bfd_set_section_flags (stdoutput, now_seg,
3398 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3403 generate_unwind_image (const segT text_seg)
3408 /* Mark the end of the unwind info, so that we can compute the size of the
3409 last unwind region. */
3410 add_unwind_entry (output_endp ());
3412 /* Force out pending instructions, to make sure all unwind records have
3413 a valid slot_number field. */
3414 ia64_flush_insns ();
3416 /* Generate the unwind record. */
3417 list = optimize_unw_records (unwind.list);
3418 fixup_unw_records (list, 1);
3419 size = calc_record_size (list);
3421 if (size > 0 || unwind.force_unwind_entry)
3423 unwind.force_unwind_entry = 0;
3424 /* pad to pointer-size boundary. */
3425 pad = size % md.pointer_size;
3427 size += md.pointer_size - pad;
3428 /* Add 8 for the header + a pointer for the personality
3430 size += 8 + md.pointer_size;
3433 /* If there are unwind records, switch sections, and output the info. */
3437 bfd_reloc_code_real_type reloc;
3439 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO);
3441 /* Make sure the section has 4 byte alignment for ILP32 and
3442 8 byte alignment for LP64. */
3443 frag_align (md.pointer_size_shift, 0, 0);
3444 record_alignment (now_seg, md.pointer_size_shift);
3446 /* Set expression which points to start of unwind descriptor area. */
3447 unwind.info = expr_build_dot ();
3449 frag_var (rs_machine_dependent, size, size, 0, 0,
3450 (offsetT) unwind.personality_routine, (char *) list);
3452 /* Add the personality address to the image. */
3453 if (unwind.personality_routine != 0)
3455 exp.X_op = O_symbol;
3456 exp.X_add_symbol = unwind.personality_routine;
3457 exp.X_add_number = 0;
3459 if (md.flags & EF_IA_64_BE)
3461 if (md.flags & EF_IA_64_ABI64)
3462 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3464 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3468 if (md.flags & EF_IA_64_ABI64)
3469 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3471 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3474 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3475 md.pointer_size, &exp, 0, reloc);
3476 unwind.personality_routine = 0;
3480 free_saved_prologue_counts ();
3481 unwind.list = unwind.tail = unwind.current_entry = NULL;
3485 dot_handlerdata (dummy)
3486 int dummy ATTRIBUTE_UNUSED;
3488 unwind.force_unwind_entry = 1;
3490 /* Remember which segment we're in so we can switch back after .endp */
3491 unwind.saved_text_seg = now_seg;
3492 unwind.saved_text_subseg = now_subseg;
3494 /* Generate unwind info into unwind-info section and then leave that
3495 section as the currently active one so dataXX directives go into
3496 the language specific data area of the unwind info block. */
3497 generate_unwind_image (now_seg);
3498 demand_empty_rest_of_line ();
3502 dot_unwentry (dummy)
3503 int dummy ATTRIBUTE_UNUSED;
3505 unwind.force_unwind_entry = 1;
3506 demand_empty_rest_of_line ();
3511 int dummy ATTRIBUTE_UNUSED;
3517 reg = e.X_add_number - REG_BR;
3518 if (e.X_op == O_register && reg < 8)
3519 add_unwind_entry (output_rp_br (reg));
3521 as_bad ("First operand not a valid branch register");
3525 dot_savemem (psprel)
3532 sep = parse_operand (&e1);
3534 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3535 sep = parse_operand (&e2);
3537 reg1 = e1.X_add_number;
3538 val = e2.X_add_number;
3540 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3541 if (e1.X_op == O_register)
3543 if (e2.X_op == O_constant)
3547 case REG_AR + AR_BSP:
3548 add_unwind_entry (output_bsp_when ());
3549 add_unwind_entry ((psprel
3551 : output_bsp_sprel) (val));
3553 case REG_AR + AR_BSPSTORE:
3554 add_unwind_entry (output_bspstore_when ());
3555 add_unwind_entry ((psprel
3556 ? output_bspstore_psprel
3557 : output_bspstore_sprel) (val));
3559 case REG_AR + AR_RNAT:
3560 add_unwind_entry (output_rnat_when ());
3561 add_unwind_entry ((psprel
3562 ? output_rnat_psprel
3563 : output_rnat_sprel) (val));
3565 case REG_AR + AR_UNAT:
3566 add_unwind_entry (output_unat_when ());
3567 add_unwind_entry ((psprel
3568 ? output_unat_psprel
3569 : output_unat_sprel) (val));
3571 case REG_AR + AR_FPSR:
3572 add_unwind_entry (output_fpsr_when ());
3573 add_unwind_entry ((psprel
3574 ? output_fpsr_psprel
3575 : output_fpsr_sprel) (val));
3577 case REG_AR + AR_PFS:
3578 add_unwind_entry (output_pfs_when ());
3579 add_unwind_entry ((psprel
3581 : output_pfs_sprel) (val));
3583 case REG_AR + AR_LC:
3584 add_unwind_entry (output_lc_when ());
3585 add_unwind_entry ((psprel
3587 : output_lc_sprel) (val));
3590 add_unwind_entry (output_rp_when ());
3591 add_unwind_entry ((psprel
3593 : output_rp_sprel) (val));
3596 add_unwind_entry (output_preds_when ());
3597 add_unwind_entry ((psprel
3598 ? output_preds_psprel
3599 : output_preds_sprel) (val));
3602 add_unwind_entry (output_priunat_when_mem ());
3603 add_unwind_entry ((psprel
3604 ? output_priunat_psprel
3605 : output_priunat_sprel) (val));
3608 as_bad ("First operand not a valid register");
3612 as_bad (" Second operand not a valid constant");
3615 as_bad ("First operand not a register");
3620 int dummy ATTRIBUTE_UNUSED;
3624 sep = parse_operand (&e1);
3626 parse_operand (&e2);
3628 if (e1.X_op != O_constant)
3629 as_bad ("First operand to .save.g must be a constant.");
3632 int grmask = e1.X_add_number;
3634 add_unwind_entry (output_gr_mem (grmask));
3637 int reg = e2.X_add_number - REG_GR;
3638 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3639 add_unwind_entry (output_gr_gr (grmask, reg));
3641 as_bad ("Second operand is an invalid register.");
3648 int dummy ATTRIBUTE_UNUSED;
3652 sep = parse_operand (&e1);
3654 if (e1.X_op != O_constant)
3655 as_bad ("Operand to .save.f must be a constant.");
3657 add_unwind_entry (output_fr_mem (e1.X_add_number));
3662 int dummy ATTRIBUTE_UNUSED;
3669 sep = parse_operand (&e1);
3670 if (e1.X_op != O_constant)
3672 as_bad ("First operand to .save.b must be a constant.");
3675 brmask = e1.X_add_number;
3679 sep = parse_operand (&e2);
3680 reg = e2.X_add_number - REG_GR;
3681 if (e2.X_op != O_register || reg > 127)
3683 as_bad ("Second operand to .save.b must be a general register.");
3686 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3689 add_unwind_entry (output_br_mem (brmask));
3691 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3692 demand_empty_rest_of_line ();
3697 int dummy ATTRIBUTE_UNUSED;
3701 sep = parse_operand (&e1);
3703 parse_operand (&e2);
3705 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3706 as_bad ("Both operands of .save.gf must be constants.");
3709 int grmask = e1.X_add_number;
3710 int frmask = e2.X_add_number;
3711 add_unwind_entry (output_frgr_mem (grmask, frmask));
3717 int dummy ATTRIBUTE_UNUSED;
3722 sep = parse_operand (&e);
3723 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3724 demand_empty_rest_of_line ();
3726 if (e.X_op != O_constant)
3727 as_bad ("Operand to .spill must be a constant");
3729 add_unwind_entry (output_spill_base (e.X_add_number));
3733 dot_spillreg (dummy)
3734 int dummy ATTRIBUTE_UNUSED;
3736 int sep, ab, xy, reg, treg;
3739 sep = parse_operand (&e1);
3742 as_bad ("No second operand to .spillreg");
3746 parse_operand (&e2);
3748 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3750 as_bad ("First operand to .spillreg must be a preserved register");
3754 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3756 as_bad ("Second operand to .spillreg must be a register");
3760 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3764 dot_spillmem (psprel)
3770 sep = parse_operand (&e1);
3773 as_bad ("Second operand missing");
3777 parse_operand (&e2);
3779 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3781 as_bad ("First operand to .spill%s must be a preserved register",
3782 psprel ? "psp" : "sp");
3786 if (e2.X_op != O_constant)
3788 as_bad ("Second operand to .spill%s must be a constant",
3789 psprel ? "psp" : "sp");
3794 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3796 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3800 dot_spillreg_p (dummy)
3801 int dummy ATTRIBUTE_UNUSED;
3803 int sep, ab, xy, reg, treg;
3804 expressionS e1, e2, e3;
3807 sep = parse_operand (&e1);
3810 as_bad ("No second and third operand to .spillreg.p");
3814 sep = parse_operand (&e2);
3817 as_bad ("No third operand to .spillreg.p");
3821 parse_operand (&e3);
3823 qp = e1.X_add_number - REG_P;
3825 if (e1.X_op != O_register || qp > 63)
3827 as_bad ("First operand to .spillreg.p must be a predicate");
3831 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3833 as_bad ("Second operand to .spillreg.p must be a preserved register");
3837 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3839 as_bad ("Third operand to .spillreg.p must be a register");
3843 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3847 dot_spillmem_p (psprel)
3850 expressionS e1, e2, e3;
3854 sep = parse_operand (&e1);
3857 as_bad ("Second operand missing");
3861 parse_operand (&e2);
3864 as_bad ("Second operand missing");
3868 parse_operand (&e3);
3870 qp = e1.X_add_number - REG_P;
3871 if (e1.X_op != O_register || qp > 63)
3873 as_bad ("First operand to .spill%s_p must be a predicate",
3874 psprel ? "psp" : "sp");
3878 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3880 as_bad ("Second operand to .spill%s_p must be a preserved register",
3881 psprel ? "psp" : "sp");
3885 if (e3.X_op != O_constant)
3887 as_bad ("Third operand to .spill%s_p must be a constant",
3888 psprel ? "psp" : "sp");
3893 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3895 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3899 get_saved_prologue_count (lbl)
3902 label_prologue_count *lpc = unwind.saved_prologue_counts;
3904 while (lpc != NULL && lpc->label_number != lbl)
3908 return lpc->prologue_count;
3910 as_bad ("Missing .label_state %ld", lbl);
3915 save_prologue_count (lbl, count)
3919 label_prologue_count *lpc = unwind.saved_prologue_counts;
3921 while (lpc != NULL && lpc->label_number != lbl)
3925 lpc->prologue_count = count;
3928 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3930 new_lpc->next = unwind.saved_prologue_counts;
3931 new_lpc->label_number = lbl;
3932 new_lpc->prologue_count = count;
3933 unwind.saved_prologue_counts = new_lpc;
3938 free_saved_prologue_counts ()
3940 label_prologue_count *lpc = unwind.saved_prologue_counts;
3941 label_prologue_count *next;
3950 unwind.saved_prologue_counts = NULL;
3954 dot_label_state (dummy)
3955 int dummy ATTRIBUTE_UNUSED;
3960 if (e.X_op != O_constant)
3962 as_bad ("Operand to .label_state must be a constant");
3965 add_unwind_entry (output_label_state (e.X_add_number));
3966 save_prologue_count (e.X_add_number, unwind.prologue_count);
3970 dot_copy_state (dummy)
3971 int dummy ATTRIBUTE_UNUSED;
3976 if (e.X_op != O_constant)
3978 as_bad ("Operand to .copy_state must be a constant");
3981 add_unwind_entry (output_copy_state (e.X_add_number));
3982 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3987 int dummy ATTRIBUTE_UNUSED;
3992 sep = parse_operand (&e1);
3995 as_bad ("Second operand to .unwabi missing");
3998 sep = parse_operand (&e2);
3999 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4000 demand_empty_rest_of_line ();
4002 if (e1.X_op != O_constant)
4004 as_bad ("First operand to .unwabi must be a constant");
4008 if (e2.X_op != O_constant)
4010 as_bad ("Second operand to .unwabi must be a constant");
4014 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4018 dot_personality (dummy)
4019 int dummy ATTRIBUTE_UNUSED;
4023 name = input_line_pointer;
4024 c = get_symbol_end ();
4025 p = input_line_pointer;
4026 unwind.personality_routine = symbol_find_or_make (name);
4027 unwind.force_unwind_entry = 1;
4030 demand_empty_rest_of_line ();
4035 int dummy ATTRIBUTE_UNUSED;
4040 unwind.proc_start = expr_build_dot ();
4041 /* Parse names of main and alternate entry points and mark them as
4042 function symbols: */
4046 name = input_line_pointer;
4047 c = get_symbol_end ();
4048 p = input_line_pointer;
4049 sym = symbol_find_or_make (name);
4050 if (unwind.proc_start == 0)
4052 unwind.proc_start = sym;
4054 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4057 if (*input_line_pointer != ',')
4059 ++input_line_pointer;
4061 demand_empty_rest_of_line ();
4064 unwind.prologue_count = 0;
4065 unwind.list = unwind.tail = unwind.current_entry = NULL;
4066 unwind.personality_routine = 0;
4071 int dummy ATTRIBUTE_UNUSED;
4073 unwind.prologue = 0;
4074 unwind.prologue_mask = 0;
4076 add_unwind_entry (output_body ());
4077 demand_empty_rest_of_line ();
4081 dot_prologue (dummy)
4082 int dummy ATTRIBUTE_UNUSED;
4085 int mask = 0, grsave = 0;
4087 if (!is_it_end_of_statement ())
4090 sep = parse_operand (&e1);
4092 as_bad ("No second operand to .prologue");
4093 sep = parse_operand (&e2);
4094 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4095 demand_empty_rest_of_line ();
4097 if (e1.X_op == O_constant)
4099 mask = e1.X_add_number;
4101 if (e2.X_op == O_constant)
4102 grsave = e2.X_add_number;
4103 else if (e2.X_op == O_register
4104 && (grsave = e2.X_add_number - REG_GR) < 128)
4107 as_bad ("Second operand not a constant or general register");
4109 add_unwind_entry (output_prologue_gr (mask, grsave));
4112 as_bad ("First operand not a constant");
4115 add_unwind_entry (output_prologue ());
4117 unwind.prologue = 1;
4118 unwind.prologue_mask = mask;
4119 ++unwind.prologue_count;
4124 int dummy ATTRIBUTE_UNUSED;
4128 int bytes_per_address;
4131 subsegT saved_subseg;
4135 if (unwind.saved_text_seg)
4137 saved_seg = unwind.saved_text_seg;
4138 saved_subseg = unwind.saved_text_subseg;
4139 unwind.saved_text_seg = NULL;
4143 saved_seg = now_seg;
4144 saved_subseg = now_subseg;
4147 insn_group_break (1, 0, 0);
4149 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4151 generate_unwind_image (saved_seg);
4153 if (unwind.info || unwind.force_unwind_entry)
4155 subseg_set (md.last_text_seg, 0);
4156 unwind.proc_end = expr_build_dot ();
4158 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND);
4160 /* Make sure that section has 4 byte alignment for ILP32 and
4161 8 byte alignment for LP64. */
4162 record_alignment (now_seg, md.pointer_size_shift);
4164 /* Need space for 3 pointers for procedure start, procedure end,
4166 ptr = frag_more (3 * md.pointer_size);
4167 where = frag_now_fix () - (3 * md.pointer_size);
4168 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4170 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4171 e.X_op = O_pseudo_fixup;
4172 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4174 e.X_add_symbol = unwind.proc_start;
4175 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4177 e.X_op = O_pseudo_fixup;
4178 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4180 e.X_add_symbol = unwind.proc_end;
4181 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4182 bytes_per_address, &e);
4186 e.X_op = O_pseudo_fixup;
4187 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4189 e.X_add_symbol = unwind.info;
4190 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4191 bytes_per_address, &e);
4194 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4198 subseg_set (saved_seg, saved_subseg);
4200 /* Parse names of main and alternate entry points and set symbol sizes. */
4204 name = input_line_pointer;
4205 c = get_symbol_end ();
4206 p = input_line_pointer;
4207 sym = symbol_find (name);
4208 if (sym && unwind.proc_start
4209 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4210 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4212 fragS *fr = symbol_get_frag (unwind.proc_start);
4213 fragS *frag = symbol_get_frag (sym);
4215 /* Check whether the function label is at or beyond last
4217 while (fr && fr != frag)
4221 if (frag == frag_now && SEG_NORMAL (now_seg))
4222 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4225 symbol_get_obj (sym)->size =
4226 (expressionS *) xmalloc (sizeof (expressionS));
4227 symbol_get_obj (sym)->size->X_op = O_subtract;
4228 symbol_get_obj (sym)->size->X_add_symbol
4229 = symbol_new (FAKE_LABEL_NAME, now_seg,
4230 frag_now_fix (), frag_now);
4231 symbol_get_obj (sym)->size->X_op_symbol = sym;
4232 symbol_get_obj (sym)->size->X_add_number = 0;
4238 if (*input_line_pointer != ',')
4240 ++input_line_pointer;
4242 demand_empty_rest_of_line ();
4243 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4247 dot_template (template)
4250 CURR_SLOT.user_template = template;
4255 int dummy ATTRIBUTE_UNUSED;
4257 int ins, locs, outs, rots;
4259 if (is_it_end_of_statement ())
4260 ins = locs = outs = rots = 0;
4263 ins = get_absolute_expression ();
4264 if (*input_line_pointer++ != ',')
4266 locs = get_absolute_expression ();
4267 if (*input_line_pointer++ != ',')
4269 outs = get_absolute_expression ();
4270 if (*input_line_pointer++ != ',')
4272 rots = get_absolute_expression ();
4274 set_regstack (ins, locs, outs, rots);
4278 as_bad ("Comma expected");
4279 ignore_rest_of_line ();
4286 unsigned num_regs, num_alloced = 0;
4287 struct dynreg **drpp, *dr;
4288 int ch, base_reg = 0;
4294 case DYNREG_GR: base_reg = REG_GR + 32; break;
4295 case DYNREG_FR: base_reg = REG_FR + 32; break;
4296 case DYNREG_PR: base_reg = REG_P + 16; break;
4300 /* First, remove existing names from hash table. */
4301 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4303 hash_delete (md.dynreg_hash, dr->name);
4307 drpp = &md.dynreg[type];
4310 start = input_line_pointer;
4311 ch = get_symbol_end ();
4312 *input_line_pointer = ch;
4313 len = (input_line_pointer - start);
4316 if (*input_line_pointer != '[')
4318 as_bad ("Expected '['");
4321 ++input_line_pointer; /* skip '[' */
4323 num_regs = get_absolute_expression ();
4325 if (*input_line_pointer++ != ']')
4327 as_bad ("Expected ']'");
4332 num_alloced += num_regs;
4336 if (num_alloced > md.rot.num_regs)
4338 as_bad ("Used more than the declared %d rotating registers",
4344 if (num_alloced > 96)
4346 as_bad ("Used more than the available 96 rotating registers");
4351 if (num_alloced > 48)
4353 as_bad ("Used more than the available 48 rotating registers");
4362 name = obstack_alloc (¬es, len + 1);
4363 memcpy (name, start, len);
4368 *drpp = obstack_alloc (¬es, sizeof (*dr));
4369 memset (*drpp, 0, sizeof (*dr));
4374 dr->num_regs = num_regs;
4375 dr->base = base_reg;
4377 base_reg += num_regs;
4379 if (hash_insert (md.dynreg_hash, name, dr))
4381 as_bad ("Attempt to redefine register set `%s'", name);
4385 if (*input_line_pointer != ',')
4387 ++input_line_pointer; /* skip comma */
4390 demand_empty_rest_of_line ();
4394 ignore_rest_of_line ();
4398 dot_byteorder (byteorder)
4401 segment_info_type *seginfo = seg_info (now_seg);
4403 if (byteorder == -1)
4405 if (seginfo->tc_segment_info_data.endian == 0)
4406 seginfo->tc_segment_info_data.endian
4407 = TARGET_BYTES_BIG_ENDIAN ? 1 : 2;
4408 byteorder = seginfo->tc_segment_info_data.endian == 1;
4411 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4413 if (target_big_endian != byteorder)
4415 target_big_endian = byteorder;
4416 if (target_big_endian)
4418 ia64_number_to_chars = number_to_chars_bigendian;
4419 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4423 ia64_number_to_chars = number_to_chars_littleendian;
4424 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4431 int dummy ATTRIBUTE_UNUSED;
4438 option = input_line_pointer;
4439 ch = get_symbol_end ();
4440 if (strcmp (option, "lsb") == 0)
4441 md.flags &= ~EF_IA_64_BE;
4442 else if (strcmp (option, "msb") == 0)
4443 md.flags |= EF_IA_64_BE;
4444 else if (strcmp (option, "abi32") == 0)
4445 md.flags &= ~EF_IA_64_ABI64;
4446 else if (strcmp (option, "abi64") == 0)
4447 md.flags |= EF_IA_64_ABI64;
4449 as_bad ("Unknown psr option `%s'", option);
4450 *input_line_pointer = ch;
4453 if (*input_line_pointer != ',')
4456 ++input_line_pointer;
4459 demand_empty_rest_of_line ();
4464 int dummy ATTRIBUTE_UNUSED;
4466 new_logical_line (0, get_absolute_expression ());
4467 demand_empty_rest_of_line ();
4471 parse_section_name ()
4477 if (*input_line_pointer != '"')
4479 as_bad ("Missing section name");
4480 ignore_rest_of_line ();
4483 name = demand_copy_C_string (&len);
4486 ignore_rest_of_line ();
4490 if (*input_line_pointer != ',')
4492 as_bad ("Comma expected after section name");
4493 ignore_rest_of_line ();
4496 ++input_line_pointer; /* skip comma */
4504 char *name = parse_section_name ();
4508 md.keep_pending_output = 1;
4511 obj_elf_previous (0);
4512 md.keep_pending_output = 0;
4515 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4518 stmt_float_cons (kind)
4539 ia64_do_align (alignment);
4547 int saved_auto_align = md.auto_align;
4551 md.auto_align = saved_auto_align;
4555 dot_xfloat_cons (kind)
4558 char *name = parse_section_name ();
4562 md.keep_pending_output = 1;
4564 stmt_float_cons (kind);
4565 obj_elf_previous (0);
4566 md.keep_pending_output = 0;
4570 dot_xstringer (zero)
4573 char *name = parse_section_name ();
4577 md.keep_pending_output = 1;
4580 obj_elf_previous (0);
4581 md.keep_pending_output = 0;
4588 int saved_auto_align = md.auto_align;
4589 char *name = parse_section_name ();
4593 md.keep_pending_output = 1;
4597 md.auto_align = saved_auto_align;
4598 obj_elf_previous (0);
4599 md.keep_pending_output = 0;
4603 dot_xfloat_cons_ua (kind)
4606 int saved_auto_align = md.auto_align;
4607 char *name = parse_section_name ();
4611 md.keep_pending_output = 1;
4614 stmt_float_cons (kind);
4615 md.auto_align = saved_auto_align;
4616 obj_elf_previous (0);
4617 md.keep_pending_output = 0;
4620 /* .reg.val <regname>,value */
4624 int dummy ATTRIBUTE_UNUSED;
4629 if (reg.X_op != O_register)
4631 as_bad (_("Register name expected"));
4632 ignore_rest_of_line ();
4634 else if (*input_line_pointer++ != ',')
4636 as_bad (_("Comma expected"));
4637 ignore_rest_of_line ();
4641 valueT value = get_absolute_expression ();
4642 int regno = reg.X_add_number;
4643 if (regno < REG_GR || regno > REG_GR + 128)
4644 as_warn (_("Register value annotation ignored"));
4647 gr_values[regno - REG_GR].known = 1;
4648 gr_values[regno - REG_GR].value = value;
4649 gr_values[regno - REG_GR].path = md.path;
4652 demand_empty_rest_of_line ();
4657 .serialize.instruction
4660 dot_serialize (type)
4663 insn_group_break (0, 0, 0);
4665 instruction_serialization ();
4667 data_serialization ();
4668 insn_group_break (0, 0, 0);
4669 demand_empty_rest_of_line ();
4672 /* select dv checking mode
4677 A stop is inserted when changing modes
4684 if (md.manual_bundling)
4685 as_warn (_("Directive invalid within a bundle"));
4687 if (type == 'E' || type == 'A')
4688 md.mode_explicitly_set = 0;
4690 md.mode_explicitly_set = 1;
4697 if (md.explicit_mode)
4698 insn_group_break (1, 0, 0);
4699 md.explicit_mode = 0;
4703 if (!md.explicit_mode)
4704 insn_group_break (1, 0, 0);
4705 md.explicit_mode = 1;
4709 if (md.explicit_mode != md.default_explicit_mode)
4710 insn_group_break (1, 0, 0);
4711 md.explicit_mode = md.default_explicit_mode;
4712 md.mode_explicitly_set = 0;
4723 for (regno = 0; regno < 64; regno++)
4725 if (mask & ((valueT) 1 << regno))
4727 fprintf (stderr, "%s p%d", comma, regno);
4734 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4735 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4736 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4737 .pred.safe_across_calls p1 [, p2 [,...]]
4746 int p1 = -1, p2 = -1;
4750 if (*input_line_pointer != '"')
4752 as_bad (_("Missing predicate relation type"));
4753 ignore_rest_of_line ();
4759 char *form = demand_copy_C_string (&len);
4760 if (strcmp (form, "mutex") == 0)
4762 else if (strcmp (form, "clear") == 0)
4764 else if (strcmp (form, "imply") == 0)
4768 as_bad (_("Unrecognized predicate relation type"));
4769 ignore_rest_of_line ();
4773 if (*input_line_pointer == ',')
4774 ++input_line_pointer;
4784 if (TOUPPER (*input_line_pointer) != 'P'
4785 || (regno = atoi (++input_line_pointer)) < 0
4788 as_bad (_("Predicate register expected"));
4789 ignore_rest_of_line ();
4792 while (ISDIGIT (*input_line_pointer))
4793 ++input_line_pointer;
4800 as_warn (_("Duplicate predicate register ignored"));
4803 /* See if it's a range. */
4804 if (*input_line_pointer == '-')
4807 ++input_line_pointer;
4809 if (TOUPPER (*input_line_pointer) != 'P'
4810 || (regno = atoi (++input_line_pointer)) < 0
4813 as_bad (_("Predicate register expected"));
4814 ignore_rest_of_line ();
4817 while (ISDIGIT (*input_line_pointer))
4818 ++input_line_pointer;
4822 as_bad (_("Bad register range"));
4823 ignore_rest_of_line ();
4834 if (*input_line_pointer != ',')
4836 ++input_line_pointer;
4845 clear_qp_mutex (mask);
4846 clear_qp_implies (mask, (valueT) 0);
4849 if (count != 2 || p1 == -1 || p2 == -1)
4850 as_bad (_("Predicate source and target required"));
4851 else if (p1 == 0 || p2 == 0)
4852 as_bad (_("Use of p0 is not valid in this context"));
4854 add_qp_imply (p1, p2);
4859 as_bad (_("At least two PR arguments expected"));
4864 as_bad (_("Use of p0 is not valid in this context"));
4867 add_qp_mutex (mask);
4870 /* note that we don't override any existing relations */
4873 as_bad (_("At least one PR argument expected"));
4878 fprintf (stderr, "Safe across calls: ");
4879 print_prmask (mask);
4880 fprintf (stderr, "\n");
4882 qp_safe_across_calls = mask;
4885 demand_empty_rest_of_line ();
4888 /* .entry label [, label [, ...]]
4889 Hint to DV code that the given labels are to be considered entry points.
4890 Otherwise, only global labels are considered entry points. */
4894 int dummy ATTRIBUTE_UNUSED;
4903 name = input_line_pointer;
4904 c = get_symbol_end ();
4905 symbolP = symbol_find_or_make (name);
4907 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4909 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4912 *input_line_pointer = c;
4914 c = *input_line_pointer;
4917 input_line_pointer++;
4919 if (*input_line_pointer == '\n')
4925 demand_empty_rest_of_line ();
4928 /* .mem.offset offset, base
4929 "base" is used to distinguish between offsets from a different base. */
4932 dot_mem_offset (dummy)
4933 int dummy ATTRIBUTE_UNUSED;
4935 md.mem_offset.hint = 1;
4936 md.mem_offset.offset = get_absolute_expression ();
4937 if (*input_line_pointer != ',')
4939 as_bad (_("Comma expected"));
4940 ignore_rest_of_line ();
4943 ++input_line_pointer;
4944 md.mem_offset.base = get_absolute_expression ();
4945 demand_empty_rest_of_line ();
4948 /* ia64-specific pseudo-ops: */
4949 const pseudo_typeS md_pseudo_table[] =
4951 { "radix", dot_radix, 0 },
4952 { "lcomm", s_lcomm_bytes, 1 },
4953 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4954 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4955 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4956 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4957 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4958 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4959 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4960 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4961 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4962 { "proc", dot_proc, 0 },
4963 { "body", dot_body, 0 },
4964 { "prologue", dot_prologue, 0 },
4965 { "endp", dot_endp, 0 },
4967 { "fframe", dot_fframe, 0 },
4968 { "vframe", dot_vframe, 0 },
4969 { "vframesp", dot_vframesp, 0 },
4970 { "vframepsp", dot_vframepsp, 0 },
4971 { "save", dot_save, 0 },
4972 { "restore", dot_restore, 0 },
4973 { "restorereg", dot_restorereg, 0 },
4974 { "restorereg.p", dot_restorereg_p, 0 },
4975 { "handlerdata", dot_handlerdata, 0 },
4976 { "unwentry", dot_unwentry, 0 },
4977 { "altrp", dot_altrp, 0 },
4978 { "savesp", dot_savemem, 0 },
4979 { "savepsp", dot_savemem, 1 },
4980 { "save.g", dot_saveg, 0 },
4981 { "save.f", dot_savef, 0 },
4982 { "save.b", dot_saveb, 0 },
4983 { "save.gf", dot_savegf, 0 },
4984 { "spill", dot_spill, 0 },
4985 { "spillreg", dot_spillreg, 0 },
4986 { "spillsp", dot_spillmem, 0 },
4987 { "spillpsp", dot_spillmem, 1 },
4988 { "spillreg.p", dot_spillreg_p, 0 },
4989 { "spillsp.p", dot_spillmem_p, 0 },
4990 { "spillpsp.p", dot_spillmem_p, 1 },
4991 { "label_state", dot_label_state, 0 },
4992 { "copy_state", dot_copy_state, 0 },
4993 { "unwabi", dot_unwabi, 0 },
4994 { "personality", dot_personality, 0 },
4996 { "estate", dot_estate, 0 },
4998 { "mii", dot_template, 0x0 },
4999 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5000 { "mlx", dot_template, 0x2 },
5001 { "mmi", dot_template, 0x4 },
5002 { "mfi", dot_template, 0x6 },
5003 { "mmf", dot_template, 0x7 },
5004 { "mib", dot_template, 0x8 },
5005 { "mbb", dot_template, 0x9 },
5006 { "bbb", dot_template, 0xb },
5007 { "mmb", dot_template, 0xc },
5008 { "mfb", dot_template, 0xe },
5010 { "lb", dot_scope, 0 },
5011 { "le", dot_scope, 1 },
5013 { "align", dot_align, 0 },
5014 { "regstk", dot_regstk, 0 },
5015 { "rotr", dot_rot, DYNREG_GR },
5016 { "rotf", dot_rot, DYNREG_FR },
5017 { "rotp", dot_rot, DYNREG_PR },
5018 { "lsb", dot_byteorder, 0 },
5019 { "msb", dot_byteorder, 1 },
5020 { "psr", dot_psr, 0 },
5021 { "alias", dot_alias, 0 },
5022 { "secalias", dot_alias, 1 },
5023 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5025 { "xdata1", dot_xdata, 1 },
5026 { "xdata2", dot_xdata, 2 },
5027 { "xdata4", dot_xdata, 4 },
5028 { "xdata8", dot_xdata, 8 },
5029 { "xreal4", dot_xfloat_cons, 'f' },
5030 { "xreal8", dot_xfloat_cons, 'd' },
5031 { "xreal10", dot_xfloat_cons, 'x' },
5032 { "xreal16", dot_xfloat_cons, 'X' },
5033 { "xstring", dot_xstringer, 0 },
5034 { "xstringz", dot_xstringer, 1 },
5036 /* unaligned versions: */
5037 { "xdata2.ua", dot_xdata_ua, 2 },
5038 { "xdata4.ua", dot_xdata_ua, 4 },
5039 { "xdata8.ua", dot_xdata_ua, 8 },
5040 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5041 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5042 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5043 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5045 /* annotations/DV checking support */
5046 { "entry", dot_entry, 0 },
5047 { "mem.offset", dot_mem_offset, 0 },
5048 { "pred.rel", dot_pred_rel, 0 },
5049 { "pred.rel.clear", dot_pred_rel, 'c' },
5050 { "pred.rel.imply", dot_pred_rel, 'i' },
5051 { "pred.rel.mutex", dot_pred_rel, 'm' },
5052 { "pred.safe_across_calls", dot_pred_rel, 's' },
5053 { "reg.val", dot_reg_val, 0 },
5054 { "serialize.data", dot_serialize, 0 },
5055 { "serialize.instruction", dot_serialize, 1 },
5056 { "auto", dot_dv_mode, 'a' },
5057 { "explicit", dot_dv_mode, 'e' },
5058 { "default", dot_dv_mode, 'd' },
5060 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5061 IA-64 aligns data allocation pseudo-ops by default, so we have to
5062 tell it that these ones are supposed to be unaligned. Long term,
5063 should rewrite so that only IA-64 specific data allocation pseudo-ops
5064 are aligned by default. */
5065 {"2byte", stmt_cons_ua, 2},
5066 {"4byte", stmt_cons_ua, 4},
5067 {"8byte", stmt_cons_ua, 8},
5072 static const struct pseudo_opcode
5075 void (*handler) (int);
5080 /* these are more like pseudo-ops, but don't start with a dot */
5081 { "data1", cons, 1 },
5082 { "data2", cons, 2 },
5083 { "data4", cons, 4 },
5084 { "data8", cons, 8 },
5085 { "data16", cons, 16 },
5086 { "real4", stmt_float_cons, 'f' },
5087 { "real8", stmt_float_cons, 'd' },
5088 { "real10", stmt_float_cons, 'x' },
5089 { "real16", stmt_float_cons, 'X' },
5090 { "string", stringer, 0 },
5091 { "stringz", stringer, 1 },
5093 /* unaligned versions: */
5094 { "data2.ua", stmt_cons_ua, 2 },
5095 { "data4.ua", stmt_cons_ua, 4 },
5096 { "data8.ua", stmt_cons_ua, 8 },
5097 { "data16.ua", stmt_cons_ua, 16 },
5098 { "real4.ua", float_cons, 'f' },
5099 { "real8.ua", float_cons, 'd' },
5100 { "real10.ua", float_cons, 'x' },
5101 { "real16.ua", float_cons, 'X' },
5104 /* Declare a register by creating a symbol for it and entering it in
5105 the symbol table. */
5108 declare_register (name, regnum)
5115 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5117 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5119 as_fatal ("Inserting \"%s\" into register table failed: %s",
5126 declare_register_set (prefix, num_regs, base_regnum)
5134 for (i = 0; i < num_regs; ++i)
5136 sprintf (name, "%s%u", prefix, i);
5137 declare_register (name, base_regnum + i);
5142 operand_width (opnd)
5143 enum ia64_opnd opnd;
5145 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5146 unsigned int bits = 0;
5150 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5151 bits += odesc->field[i].bits;
5156 static enum operand_match_result
5157 operand_match (idesc, index, e)
5158 const struct ia64_opcode *idesc;
5162 enum ia64_opnd opnd = idesc->operands[index];
5163 int bits, relocatable = 0;
5164 struct insn_fix *fix;
5171 case IA64_OPND_AR_CCV:
5172 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5173 return OPERAND_MATCH;
5176 case IA64_OPND_AR_CSD:
5177 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5178 return OPERAND_MATCH;
5181 case IA64_OPND_AR_PFS:
5182 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5183 return OPERAND_MATCH;
5187 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5188 return OPERAND_MATCH;
5192 if (e->X_op == O_register && e->X_add_number == REG_IP)
5193 return OPERAND_MATCH;
5197 if (e->X_op == O_register && e->X_add_number == REG_PR)
5198 return OPERAND_MATCH;
5201 case IA64_OPND_PR_ROT:
5202 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5203 return OPERAND_MATCH;
5207 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5208 return OPERAND_MATCH;
5211 case IA64_OPND_PSR_L:
5212 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5213 return OPERAND_MATCH;
5216 case IA64_OPND_PSR_UM:
5217 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5218 return OPERAND_MATCH;
5222 if (e->X_op == O_constant)
5224 if (e->X_add_number == 1)
5225 return OPERAND_MATCH;
5227 return OPERAND_OUT_OF_RANGE;
5232 if (e->X_op == O_constant)
5234 if (e->X_add_number == 8)
5235 return OPERAND_MATCH;
5237 return OPERAND_OUT_OF_RANGE;
5242 if (e->X_op == O_constant)
5244 if (e->X_add_number == 16)
5245 return OPERAND_MATCH;
5247 return OPERAND_OUT_OF_RANGE;
5251 /* register operands: */
5254 if (e->X_op == O_register && e->X_add_number >= REG_AR
5255 && e->X_add_number < REG_AR + 128)
5256 return OPERAND_MATCH;
5261 if (e->X_op == O_register && e->X_add_number >= REG_BR
5262 && e->X_add_number < REG_BR + 8)
5263 return OPERAND_MATCH;
5267 if (e->X_op == O_register && e->X_add_number >= REG_CR
5268 && e->X_add_number < REG_CR + 128)
5269 return OPERAND_MATCH;
5276 if (e->X_op == O_register && e->X_add_number >= REG_FR
5277 && e->X_add_number < REG_FR + 128)
5278 return OPERAND_MATCH;
5283 if (e->X_op == O_register && e->X_add_number >= REG_P
5284 && e->X_add_number < REG_P + 64)
5285 return OPERAND_MATCH;
5291 if (e->X_op == O_register && e->X_add_number >= REG_GR
5292 && e->X_add_number < REG_GR + 128)
5293 return OPERAND_MATCH;
5296 case IA64_OPND_R3_2:
5297 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5299 if (e->X_add_number < REG_GR + 4)
5300 return OPERAND_MATCH;
5301 else if (e->X_add_number < REG_GR + 128)
5302 return OPERAND_OUT_OF_RANGE;
5306 /* indirect operands: */
5307 case IA64_OPND_CPUID_R3:
5308 case IA64_OPND_DBR_R3:
5309 case IA64_OPND_DTR_R3:
5310 case IA64_OPND_ITR_R3:
5311 case IA64_OPND_IBR_R3:
5312 case IA64_OPND_MSR_R3:
5313 case IA64_OPND_PKR_R3:
5314 case IA64_OPND_PMC_R3:
5315 case IA64_OPND_PMD_R3:
5316 case IA64_OPND_RR_R3:
5317 if (e->X_op == O_index && e->X_op_symbol
5318 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5319 == opnd - IA64_OPND_CPUID_R3))
5320 return OPERAND_MATCH;
5324 if (e->X_op == O_index && !e->X_op_symbol)
5325 return OPERAND_MATCH;
5328 /* immediate operands: */
5329 case IA64_OPND_CNT2a:
5330 case IA64_OPND_LEN4:
5331 case IA64_OPND_LEN6:
5332 bits = operand_width (idesc->operands[index]);
5333 if (e->X_op == O_constant)
5335 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5336 return OPERAND_MATCH;
5338 return OPERAND_OUT_OF_RANGE;
5342 case IA64_OPND_CNT2b:
5343 if (e->X_op == O_constant)
5345 if ((bfd_vma) (e->X_add_number - 1) < 3)
5346 return OPERAND_MATCH;
5348 return OPERAND_OUT_OF_RANGE;
5352 case IA64_OPND_CNT2c:
5353 val = e->X_add_number;
5354 if (e->X_op == O_constant)
5356 if ((val == 0 || val == 7 || val == 15 || val == 16))
5357 return OPERAND_MATCH;
5359 return OPERAND_OUT_OF_RANGE;
5364 /* SOR must be an integer multiple of 8 */
5365 if (e->X_op == O_constant && e->X_add_number & 0x7)
5366 return OPERAND_OUT_OF_RANGE;
5369 if (e->X_op == O_constant)
5371 if ((bfd_vma) e->X_add_number <= 96)
5372 return OPERAND_MATCH;
5374 return OPERAND_OUT_OF_RANGE;
5378 case IA64_OPND_IMMU62:
5379 if (e->X_op == O_constant)
5381 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5382 return OPERAND_MATCH;
5384 return OPERAND_OUT_OF_RANGE;
5388 /* FIXME -- need 62-bit relocation type */
5389 as_bad (_("62-bit relocation not yet implemented"));
5393 case IA64_OPND_IMMU64:
5394 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5395 || e->X_op == O_subtract)
5397 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5398 fix->code = BFD_RELOC_IA64_IMM64;
5399 if (e->X_op != O_subtract)
5401 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5402 if (e->X_op == O_pseudo_fixup)
5406 fix->opnd = idesc->operands[index];
5409 ++CURR_SLOT.num_fixups;
5410 return OPERAND_MATCH;
5412 else if (e->X_op == O_constant)
5413 return OPERAND_MATCH;
5416 case IA64_OPND_CCNT5:
5417 case IA64_OPND_CNT5:
5418 case IA64_OPND_CNT6:
5419 case IA64_OPND_CPOS6a:
5420 case IA64_OPND_CPOS6b:
5421 case IA64_OPND_CPOS6c:
5422 case IA64_OPND_IMMU2:
5423 case IA64_OPND_IMMU7a:
5424 case IA64_OPND_IMMU7b:
5425 case IA64_OPND_IMMU21:
5426 case IA64_OPND_IMMU24:
5427 case IA64_OPND_MBTYPE4:
5428 case IA64_OPND_MHTYPE8:
5429 case IA64_OPND_POS6:
5430 bits = operand_width (idesc->operands[index]);
5431 if (e->X_op == O_constant)
5433 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5434 return OPERAND_MATCH;
5436 return OPERAND_OUT_OF_RANGE;
5440 case IA64_OPND_IMMU9:
5441 bits = operand_width (idesc->operands[index]);
5442 if (e->X_op == O_constant)
5444 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5446 int lobits = e->X_add_number & 0x3;
5447 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5448 e->X_add_number |= (bfd_vma) 0x3;
5449 return OPERAND_MATCH;
5452 return OPERAND_OUT_OF_RANGE;
5456 case IA64_OPND_IMM44:
5457 /* least 16 bits must be zero */
5458 if ((e->X_add_number & 0xffff) != 0)
5459 /* XXX technically, this is wrong: we should not be issuing warning
5460 messages until we're sure this instruction pattern is going to
5462 as_warn (_("lower 16 bits of mask ignored"));
5464 if (e->X_op == O_constant)
5466 if (((e->X_add_number >= 0
5467 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5468 || (e->X_add_number < 0
5469 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5472 if (e->X_add_number >= 0
5473 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5475 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5477 return OPERAND_MATCH;
5480 return OPERAND_OUT_OF_RANGE;
5484 case IA64_OPND_IMM17:
5485 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5486 if (e->X_op == O_constant)
5488 if (((e->X_add_number >= 0
5489 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5490 || (e->X_add_number < 0
5491 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5494 if (e->X_add_number >= 0
5495 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5497 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5499 return OPERAND_MATCH;
5502 return OPERAND_OUT_OF_RANGE;
5506 case IA64_OPND_IMM14:
5507 case IA64_OPND_IMM22:
5509 case IA64_OPND_IMM1:
5510 case IA64_OPND_IMM8:
5511 case IA64_OPND_IMM8U4:
5512 case IA64_OPND_IMM8M1:
5513 case IA64_OPND_IMM8M1U4:
5514 case IA64_OPND_IMM8M1U8:
5515 case IA64_OPND_IMM9a:
5516 case IA64_OPND_IMM9b:
5517 bits = operand_width (idesc->operands[index]);
5518 if (relocatable && (e->X_op == O_symbol
5519 || e->X_op == O_subtract
5520 || e->X_op == O_pseudo_fixup))
5522 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5524 if (idesc->operands[index] == IA64_OPND_IMM14)
5525 fix->code = BFD_RELOC_IA64_IMM14;
5527 fix->code = BFD_RELOC_IA64_IMM22;
5529 if (e->X_op != O_subtract)
5531 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5532 if (e->X_op == O_pseudo_fixup)
5536 fix->opnd = idesc->operands[index];
5539 ++CURR_SLOT.num_fixups;
5540 return OPERAND_MATCH;
5542 else if (e->X_op != O_constant
5543 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5544 return OPERAND_MISMATCH;
5546 if (opnd == IA64_OPND_IMM8M1U4)
5548 /* Zero is not valid for unsigned compares that take an adjusted
5549 constant immediate range. */
5550 if (e->X_add_number == 0)
5551 return OPERAND_OUT_OF_RANGE;
5553 /* Sign-extend 32-bit unsigned numbers, so that the following range
5554 checks will work. */
5555 val = e->X_add_number;
5556 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5557 && ((val & ((bfd_vma) 1 << 31)) != 0))
5558 val = ((val << 32) >> 32);
5560 /* Check for 0x100000000. This is valid because
5561 0x100000000-1 is the same as ((uint32_t) -1). */
5562 if (val == ((bfd_signed_vma) 1 << 32))
5563 return OPERAND_MATCH;
5567 else if (opnd == IA64_OPND_IMM8M1U8)
5569 /* Zero is not valid for unsigned compares that take an adjusted
5570 constant immediate range. */
5571 if (e->X_add_number == 0)
5572 return OPERAND_OUT_OF_RANGE;
5574 /* Check for 0x10000000000000000. */
5575 if (e->X_op == O_big)
5577 if (generic_bignum[0] == 0
5578 && generic_bignum[1] == 0
5579 && generic_bignum[2] == 0
5580 && generic_bignum[3] == 0
5581 && generic_bignum[4] == 1)
5582 return OPERAND_MATCH;
5584 return OPERAND_OUT_OF_RANGE;
5587 val = e->X_add_number - 1;
5589 else if (opnd == IA64_OPND_IMM8M1)
5590 val = e->X_add_number - 1;
5591 else if (opnd == IA64_OPND_IMM8U4)
5593 /* Sign-extend 32-bit unsigned numbers, so that the following range
5594 checks will work. */
5595 val = e->X_add_number;
5596 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5597 && ((val & ((bfd_vma) 1 << 31)) != 0))
5598 val = ((val << 32) >> 32);
5601 val = e->X_add_number;
5603 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5604 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5605 return OPERAND_MATCH;
5607 return OPERAND_OUT_OF_RANGE;
5609 case IA64_OPND_INC3:
5610 /* +/- 1, 4, 8, 16 */
5611 val = e->X_add_number;
5614 if (e->X_op == O_constant)
5616 if ((val == 1 || val == 4 || val == 8 || val == 16))
5617 return OPERAND_MATCH;
5619 return OPERAND_OUT_OF_RANGE;
5623 case IA64_OPND_TGT25:
5624 case IA64_OPND_TGT25b:
5625 case IA64_OPND_TGT25c:
5626 case IA64_OPND_TGT64:
5627 if (e->X_op == O_symbol)
5629 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5630 if (opnd == IA64_OPND_TGT25)
5631 fix->code = BFD_RELOC_IA64_PCREL21F;
5632 else if (opnd == IA64_OPND_TGT25b)
5633 fix->code = BFD_RELOC_IA64_PCREL21M;
5634 else if (opnd == IA64_OPND_TGT25c)
5635 fix->code = BFD_RELOC_IA64_PCREL21B;
5636 else if (opnd == IA64_OPND_TGT64)
5637 fix->code = BFD_RELOC_IA64_PCREL60B;
5641 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5642 fix->opnd = idesc->operands[index];
5645 ++CURR_SLOT.num_fixups;
5646 return OPERAND_MATCH;
5648 case IA64_OPND_TAG13:
5649 case IA64_OPND_TAG13b:
5653 return OPERAND_MATCH;
5656 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5657 /* There are no external relocs for TAG13/TAG13b fields, so we
5658 create a dummy reloc. This will not live past md_apply_fix3. */
5659 fix->code = BFD_RELOC_UNUSED;
5660 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5661 fix->opnd = idesc->operands[index];
5664 ++CURR_SLOT.num_fixups;
5665 return OPERAND_MATCH;
5672 case IA64_OPND_LDXMOV:
5673 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5674 fix->code = BFD_RELOC_IA64_LDXMOV;
5675 fix->opnd = idesc->operands[index];
5678 ++CURR_SLOT.num_fixups;
5679 return OPERAND_MATCH;
5684 return OPERAND_MISMATCH;
5693 memset (e, 0, sizeof (*e));
5696 if (*input_line_pointer != '}')
5698 sep = *input_line_pointer++;
5702 if (!md.manual_bundling)
5703 as_warn ("Found '}' when manual bundling is off");
5705 CURR_SLOT.manual_bundling_off = 1;
5706 md.manual_bundling = 0;
5712 /* Returns the next entry in the opcode table that matches the one in
5713 IDESC, and frees the entry in IDESC. If no matching entry is
5714 found, NULL is returned instead. */
5716 static struct ia64_opcode *
5717 get_next_opcode (struct ia64_opcode *idesc)
5719 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5720 ia64_free_opcode (idesc);
5724 /* Parse the operands for the opcode and find the opcode variant that
5725 matches the specified operands, or NULL if no match is possible. */
5727 static struct ia64_opcode *
5728 parse_operands (idesc)
5729 struct ia64_opcode *idesc;
5731 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5732 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5733 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5734 enum operand_match_result result;
5736 char *first_arg = 0, *end, *saved_input_pointer;
5739 assert (strlen (idesc->name) <= 128);
5741 strcpy (mnemonic, idesc->name);
5742 if (idesc->operands[2] == IA64_OPND_SOF)
5744 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5745 can't parse the first operand until we have parsed the
5746 remaining operands of the "alloc" instruction. */
5748 first_arg = input_line_pointer;
5749 end = strchr (input_line_pointer, '=');
5752 as_bad ("Expected separator `='");
5755 input_line_pointer = end + 1;
5760 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5762 sep = parse_operand (CURR_SLOT.opnd + i);
5763 if (CURR_SLOT.opnd[i].X_op == O_absent)
5768 if (sep != '=' && sep != ',')
5773 if (num_outputs > 0)
5774 as_bad ("Duplicate equal sign (=) in instruction");
5776 num_outputs = i + 1;
5781 as_bad ("Illegal operand separator `%c'", sep);
5785 if (idesc->operands[2] == IA64_OPND_SOF)
5787 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5788 know (strcmp (idesc->name, "alloc") == 0);
5789 if (num_operands == 5 /* first_arg not included in this count! */
5790 && CURR_SLOT.opnd[2].X_op == O_constant
5791 && CURR_SLOT.opnd[3].X_op == O_constant
5792 && CURR_SLOT.opnd[4].X_op == O_constant
5793 && CURR_SLOT.opnd[5].X_op == O_constant)
5795 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5796 CURR_SLOT.opnd[3].X_add_number,
5797 CURR_SLOT.opnd[4].X_add_number,
5798 CURR_SLOT.opnd[5].X_add_number);
5800 /* now we can parse the first arg: */
5801 saved_input_pointer = input_line_pointer;
5802 input_line_pointer = first_arg;
5803 sep = parse_operand (CURR_SLOT.opnd + 0);
5805 --num_outputs; /* force error */
5806 input_line_pointer = saved_input_pointer;
5808 CURR_SLOT.opnd[2].X_add_number = sof;
5809 CURR_SLOT.opnd[3].X_add_number
5810 = sof - CURR_SLOT.opnd[4].X_add_number;
5811 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5815 highest_unmatched_operand = 0;
5816 curr_out_of_range_pos = -1;
5818 expected_operand = idesc->operands[0];
5819 for (; idesc; idesc = get_next_opcode (idesc))
5821 if (num_outputs != idesc->num_outputs)
5822 continue; /* mismatch in # of outputs */
5824 CURR_SLOT.num_fixups = 0;
5826 /* Try to match all operands. If we see an out-of-range operand,
5827 then continue trying to match the rest of the operands, since if
5828 the rest match, then this idesc will give the best error message. */
5830 out_of_range_pos = -1;
5831 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5833 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5834 if (result != OPERAND_MATCH)
5836 if (result != OPERAND_OUT_OF_RANGE)
5838 if (out_of_range_pos < 0)
5839 /* remember position of the first out-of-range operand: */
5840 out_of_range_pos = i;
5844 /* If we did not match all operands, or if at least one operand was
5845 out-of-range, then this idesc does not match. Keep track of which
5846 idesc matched the most operands before failing. If we have two
5847 idescs that failed at the same position, and one had an out-of-range
5848 operand, then prefer the out-of-range operand. Thus if we have
5849 "add r0=0x1000000,r1" we get an error saying the constant is out
5850 of range instead of an error saying that the constant should have been
5853 if (i != num_operands || out_of_range_pos >= 0)
5855 if (i > highest_unmatched_operand
5856 || (i == highest_unmatched_operand
5857 && out_of_range_pos > curr_out_of_range_pos))
5859 highest_unmatched_operand = i;
5860 if (out_of_range_pos >= 0)
5862 expected_operand = idesc->operands[out_of_range_pos];
5863 error_pos = out_of_range_pos;
5867 expected_operand = idesc->operands[i];
5870 curr_out_of_range_pos = out_of_range_pos;
5875 if (num_operands < NELEMS (idesc->operands)
5876 && idesc->operands[num_operands])
5877 continue; /* mismatch in number of arguments */
5883 if (expected_operand)
5884 as_bad ("Operand %u of `%s' should be %s",
5885 error_pos + 1, mnemonic,
5886 elf64_ia64_operands[expected_operand].desc);
5888 as_bad ("Operand mismatch");
5894 /* Keep track of state necessary to determine whether a NOP is necessary
5895 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5896 detect a case where additional NOPs may be necessary. */
5898 errata_nop_necessary_p (slot, insn_unit)
5900 enum ia64_unit insn_unit;
5903 struct group *this_group = md.last_groups + md.group_idx;
5904 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5905 struct ia64_opcode *idesc = slot->idesc;
5907 /* Test whether this could be the first insn in a problematic sequence. */
5908 if (insn_unit == IA64_UNIT_F)
5910 for (i = 0; i < idesc->num_outputs; i++)
5911 if (idesc->operands[i] == IA64_OPND_P1
5912 || idesc->operands[i] == IA64_OPND_P2)
5914 int regno = slot->opnd[i].X_add_number - REG_P;
5915 /* Ignore invalid operands; they generate errors elsewhere. */
5918 this_group->p_reg_set[regno] = 1;
5922 /* Test whether this could be the second insn in a problematic sequence. */
5923 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5924 && prev_group->p_reg_set[slot->qp_regno])
5926 for (i = 0; i < idesc->num_outputs; i++)
5927 if (idesc->operands[i] == IA64_OPND_R1
5928 || idesc->operands[i] == IA64_OPND_R2
5929 || idesc->operands[i] == IA64_OPND_R3)
5931 int regno = slot->opnd[i].X_add_number - REG_GR;
5932 /* Ignore invalid operands; they generate errors elsewhere. */
5935 if (strncmp (idesc->name, "add", 3) != 0
5936 && strncmp (idesc->name, "sub", 3) != 0
5937 && strncmp (idesc->name, "shladd", 6) != 0
5938 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5939 this_group->g_reg_set_conditionally[regno] = 1;
5943 /* Test whether this could be the third insn in a problematic sequence. */
5944 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5946 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5947 idesc->operands[i] == IA64_OPND_R3
5948 /* For mov indirect. */
5949 || idesc->operands[i] == IA64_OPND_RR_R3
5950 || idesc->operands[i] == IA64_OPND_DBR_R3
5951 || idesc->operands[i] == IA64_OPND_IBR_R3
5952 || idesc->operands[i] == IA64_OPND_PKR_R3
5953 || idesc->operands[i] == IA64_OPND_PMC_R3
5954 || idesc->operands[i] == IA64_OPND_PMD_R3
5955 || idesc->operands[i] == IA64_OPND_MSR_R3
5956 || idesc->operands[i] == IA64_OPND_CPUID_R3
5958 || idesc->operands[i] == IA64_OPND_ITR_R3
5959 || idesc->operands[i] == IA64_OPND_DTR_R3
5960 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5961 || idesc->operands[i] == IA64_OPND_MR3)
5963 int regno = slot->opnd[i].X_add_number - REG_GR;
5964 /* Ignore invalid operands; they generate errors elsewhere. */
5967 if (idesc->operands[i] == IA64_OPND_R3)
5969 if (strcmp (idesc->name, "fc") != 0
5970 && strcmp (idesc->name, "tak") != 0
5971 && strcmp (idesc->name, "thash") != 0
5972 && strcmp (idesc->name, "tpa") != 0
5973 && strcmp (idesc->name, "ttag") != 0
5974 && strncmp (idesc->name, "ptr", 3) != 0
5975 && strncmp (idesc->name, "ptc", 3) != 0
5976 && strncmp (idesc->name, "probe", 5) != 0)
5979 if (prev_group->g_reg_set_conditionally[regno])
5987 build_insn (slot, insnp)
5991 const struct ia64_operand *odesc, *o2desc;
5992 struct ia64_opcode *idesc = slot->idesc;
5993 bfd_signed_vma insn, val;
5997 insn = idesc->opcode | slot->qp_regno;
5999 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6001 if (slot->opnd[i].X_op == O_register
6002 || slot->opnd[i].X_op == O_constant
6003 || slot->opnd[i].X_op == O_index)
6004 val = slot->opnd[i].X_add_number;
6005 else if (slot->opnd[i].X_op == O_big)
6007 /* This must be the value 0x10000000000000000. */
6008 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6014 switch (idesc->operands[i])
6016 case IA64_OPND_IMMU64:
6017 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6018 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6019 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6020 | (((val >> 63) & 0x1) << 36));
6023 case IA64_OPND_IMMU62:
6024 val &= 0x3fffffffffffffffULL;
6025 if (val != slot->opnd[i].X_add_number)
6026 as_warn (_("Value truncated to 62 bits"));
6027 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6028 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6031 case IA64_OPND_TGT64:
6033 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6034 insn |= ((((val >> 59) & 0x1) << 36)
6035 | (((val >> 0) & 0xfffff) << 13));
6066 case IA64_OPND_R3_2:
6067 case IA64_OPND_CPUID_R3:
6068 case IA64_OPND_DBR_R3:
6069 case IA64_OPND_DTR_R3:
6070 case IA64_OPND_ITR_R3:
6071 case IA64_OPND_IBR_R3:
6073 case IA64_OPND_MSR_R3:
6074 case IA64_OPND_PKR_R3:
6075 case IA64_OPND_PMC_R3:
6076 case IA64_OPND_PMD_R3:
6077 case IA64_OPND_RR_R3:
6085 odesc = elf64_ia64_operands + idesc->operands[i];
6086 err = (*odesc->insert) (odesc, val, &insn);
6088 as_bad_where (slot->src_file, slot->src_line,
6089 "Bad operand value: %s", err);
6090 if (idesc->flags & IA64_OPCODE_PSEUDO)
6092 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6093 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6095 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6096 (*o2desc->insert) (o2desc, val, &insn);
6098 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6099 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6100 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6102 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6103 (*o2desc->insert) (o2desc, 64 - val, &insn);
6113 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
6114 unsigned int manual_bundling = 0;
6115 enum ia64_unit required_unit, insn_unit = 0;
6116 enum ia64_insn_type type[3], insn_type;
6117 unsigned int template, orig_template;
6118 bfd_vma insn[3] = { -1, -1, -1 };
6119 struct ia64_opcode *idesc;
6120 int end_of_insn_group = 0, user_template = -1;
6121 int n, i, j, first, curr;
6122 unw_rec_list *ptr, *last_ptr, *end_ptr;
6123 bfd_vma t0 = 0, t1 = 0;
6124 struct label_fix *lfix;
6125 struct insn_fix *ifix;
6130 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6131 know (first >= 0 & first < NUM_SLOTS);
6132 n = MIN (3, md.num_slots_in_use);
6134 /* Determine template: user user_template if specified, best match
6137 if (md.slot[first].user_template >= 0)
6138 user_template = template = md.slot[first].user_template;
6141 /* Auto select appropriate template. */
6142 memset (type, 0, sizeof (type));
6144 for (i = 0; i < n; ++i)
6146 if (md.slot[curr].label_fixups && i != 0)
6148 type[i] = md.slot[curr].idesc->type;
6149 curr = (curr + 1) % NUM_SLOTS;
6151 template = best_template[type[0]][type[1]][type[2]];
6154 /* initialize instructions with appropriate nops: */
6155 for (i = 0; i < 3; ++i)
6156 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6160 /* now fill in slots with as many insns as possible: */
6162 idesc = md.slot[curr].idesc;
6163 end_of_insn_group = 0;
6164 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6166 /* If we have unwind records, we may need to update some now. */
6167 ptr = md.slot[curr].unwind_record;
6170 /* Find the last prologue/body record in the list for the current
6171 insn, and set the slot number for all records up to that point.
6172 This needs to be done now, because prologue/body records refer to
6173 the current point, not the point after the instruction has been
6174 issued. This matters because there may have been nops emitted
6175 meanwhile. Any non-prologue non-body record followed by a
6176 prologue/body record must also refer to the current point. */
6178 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6179 for (; ptr != end_ptr; ptr = ptr->next)
6180 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6181 || ptr->r.type == body)
6185 /* Make last_ptr point one after the last prologue/body
6187 last_ptr = last_ptr->next;
6188 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6191 ptr->slot_number = (unsigned long) f + i;
6192 ptr->slot_frag = frag_now;
6194 /* Remove the initialized records, so that we won't accidentally
6195 update them again if we insert a nop and continue. */
6196 md.slot[curr].unwind_record = last_ptr;
6200 if (idesc->flags & IA64_OPCODE_SLOT2)
6202 if (manual_bundling && i != 2)
6203 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6204 "`%s' must be last in bundle", idesc->name);
6208 if (idesc->flags & IA64_OPCODE_LAST)
6211 unsigned int required_template;
6213 /* If we need a stop bit after an M slot, our only choice is
6214 template 5 (M;;MI). If we need a stop bit after a B
6215 slot, our only choice is to place it at the end of the
6216 bundle, because the only available templates are MIB,
6217 MBB, BBB, MMB, and MFB. We don't handle anything other
6218 than M and B slots because these are the only kind of
6219 instructions that can have the IA64_OPCODE_LAST bit set. */
6220 required_template = template;
6221 switch (idesc->type)
6225 required_template = 5;
6233 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6234 "Internal error: don't know how to force %s to end"
6235 "of instruction group", idesc->name);
6239 if (manual_bundling && i != required_slot)
6240 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6241 "`%s' must be last in instruction group",
6243 if (required_slot < i)
6244 /* Can't fit this instruction. */
6248 if (required_template != template)
6250 /* If we switch the template, we need to reset the NOPs
6251 after slot i. The slot-types of the instructions ahead
6252 of i never change, so we don't need to worry about
6253 changing NOPs in front of this slot. */
6254 for (j = i; j < 3; ++j)
6255 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6257 template = required_template;
6259 if (curr != first && md.slot[curr].label_fixups)
6261 if (manual_bundling_on)
6262 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6263 "Label must be first in a bundle");
6264 /* This insn must go into the first slot of a bundle. */
6268 manual_bundling_on = md.slot[curr].manual_bundling_on;
6269 manual_bundling_off = md.slot[curr].manual_bundling_off;
6271 if (manual_bundling_on)
6274 manual_bundling = 1;
6276 break; /* need to start a new bundle */
6279 if (end_of_insn_group && md.num_slots_in_use >= 1)
6281 /* We need an instruction group boundary in the middle of a
6282 bundle. See if we can switch to an other template with
6283 an appropriate boundary. */
6285 orig_template = template;
6286 if (i == 1 && (user_template == 4
6287 || (user_template < 0
6288 && (ia64_templ_desc[template].exec_unit[0]
6292 end_of_insn_group = 0;
6294 else if (i == 2 && (user_template == 0
6295 || (user_template < 0
6296 && (ia64_templ_desc[template].exec_unit[1]
6298 /* This test makes sure we don't switch the template if
6299 the next instruction is one that needs to be first in
6300 an instruction group. Since all those instructions are
6301 in the M group, there is no way such an instruction can
6302 fit in this bundle even if we switch the template. The
6303 reason we have to check for this is that otherwise we
6304 may end up generating "MI;;I M.." which has the deadly
6305 effect that the second M instruction is no longer the
6306 first in the bundle! --davidm 99/12/16 */
6307 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6310 end_of_insn_group = 0;
6312 else if (curr != first)
6313 /* can't fit this insn */
6316 if (template != orig_template)
6317 /* if we switch the template, we need to reset the NOPs
6318 after slot i. The slot-types of the instructions ahead
6319 of i never change, so we don't need to worry about
6320 changing NOPs in front of this slot. */
6321 for (j = i; j < 3; ++j)
6322 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6324 required_unit = ia64_templ_desc[template].exec_unit[i];
6326 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6327 if (idesc->type == IA64_TYPE_DYN)
6329 if ((strcmp (idesc->name, "nop") == 0)
6330 || (strcmp (idesc->name, "hint") == 0)
6331 || (strcmp (idesc->name, "break") == 0))
6332 insn_unit = required_unit;
6333 else if (strcmp (idesc->name, "chk.s") == 0)
6335 insn_unit = IA64_UNIT_M;
6336 if (required_unit == IA64_UNIT_I)
6337 insn_unit = IA64_UNIT_I;
6340 as_fatal ("emit_one_bundle: unexpected dynamic op");
6342 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6343 ia64_free_opcode (idesc);
6344 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6346 know (!idesc->next); /* no resolved dynamic ops have collisions */
6351 insn_type = idesc->type;
6352 insn_unit = IA64_UNIT_NIL;
6356 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6357 insn_unit = required_unit;
6359 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6360 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6361 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6362 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6363 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6368 if (insn_unit != required_unit)
6370 if (required_unit == IA64_UNIT_L
6371 && insn_unit == IA64_UNIT_I
6372 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6374 /* we got ourselves an MLX template but the current
6375 instruction isn't an X-unit, or an I-unit instruction
6376 that can go into the X slot of an MLX template. Duh. */
6377 if (md.num_slots_in_use >= NUM_SLOTS)
6379 as_bad_where (md.slot[curr].src_file,
6380 md.slot[curr].src_line,
6381 "`%s' can't go in X slot of "
6382 "MLX template", idesc->name);
6383 /* drop this insn so we don't livelock: */
6384 --md.num_slots_in_use;
6388 continue; /* try next slot */
6394 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6395 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6398 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6399 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6401 build_insn (md.slot + curr, insn + i);
6403 ptr = md.slot[curr].unwind_record;
6406 /* Set slot numbers for all remaining unwind records belonging to the
6407 current insn. There can not be any prologue/body unwind records
6409 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6410 for (; ptr != end_ptr; ptr = ptr->next)
6412 ptr->slot_number = (unsigned long) f + i;
6413 ptr->slot_frag = frag_now;
6415 md.slot[curr].unwind_record = NULL;
6418 if (required_unit == IA64_UNIT_L)
6421 /* skip one slot for long/X-unit instructions */
6424 --md.num_slots_in_use;
6426 /* now is a good time to fix up the labels for this insn: */
6427 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6429 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6430 symbol_set_frag (lfix->sym, frag_now);
6432 /* and fix up the tags also. */
6433 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6435 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6436 symbol_set_frag (lfix->sym, frag_now);
6439 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6441 ifix = md.slot[curr].fixup + j;
6442 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6443 &ifix->expr, ifix->is_pcrel, ifix->code);
6444 fix->tc_fix_data.opnd = ifix->opnd;
6445 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6446 fix->fx_file = md.slot[curr].src_file;
6447 fix->fx_line = md.slot[curr].src_line;
6450 end_of_insn_group = md.slot[curr].end_of_insn_group;
6452 if (end_of_insn_group)
6454 md.group_idx = (md.group_idx + 1) % 3;
6455 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6459 ia64_free_opcode (md.slot[curr].idesc);
6460 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6461 md.slot[curr].user_template = -1;
6463 if (manual_bundling_off)
6465 manual_bundling = 0;
6468 curr = (curr + 1) % NUM_SLOTS;
6469 idesc = md.slot[curr].idesc;
6471 if (manual_bundling)
6473 if (md.num_slots_in_use > 0)
6474 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6475 "`%s' does not fit into %s template",
6476 idesc->name, ia64_templ_desc[template].name);
6478 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6479 "Missing '}' at end of file");
6481 know (md.num_slots_in_use < NUM_SLOTS);
6483 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6484 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6486 number_to_chars_littleendian (f + 0, t0, 8);
6487 number_to_chars_littleendian (f + 8, t1, 8);
6491 unwind.list->next_slot_number = (unsigned long) f + 16;
6492 unwind.list->next_slot_frag = frag_now;
6497 md_parse_option (c, arg)
6504 /* Switches from the Intel assembler. */
6506 if (strcmp (arg, "ilp64") == 0
6507 || strcmp (arg, "lp64") == 0
6508 || strcmp (arg, "p64") == 0)
6510 md.flags |= EF_IA_64_ABI64;
6512 else if (strcmp (arg, "ilp32") == 0)
6514 md.flags &= ~EF_IA_64_ABI64;
6516 else if (strcmp (arg, "le") == 0)
6518 md.flags &= ~EF_IA_64_BE;
6520 else if (strcmp (arg, "be") == 0)
6522 md.flags |= EF_IA_64_BE;
6529 if (strcmp (arg, "so") == 0)
6531 /* Suppress signon message. */
6533 else if (strcmp (arg, "pi") == 0)
6535 /* Reject privileged instructions. FIXME */
6537 else if (strcmp (arg, "us") == 0)
6539 /* Allow union of signed and unsigned range. FIXME */
6541 else if (strcmp (arg, "close_fcalls") == 0)
6543 /* Do not resolve global function calls. */
6550 /* temp[="prefix"] Insert temporary labels into the object file
6551 symbol table prefixed by "prefix".
6552 Default prefix is ":temp:".
6557 /* indirect=<tgt> Assume unannotated indirect branches behavior
6558 according to <tgt> --
6559 exit: branch out from the current context (default)
6560 labels: all labels in context may be branch targets
6562 if (strncmp (arg, "indirect=", 9) != 0)
6567 /* -X conflicts with an ignored option, use -x instead */
6569 if (!arg || strcmp (arg, "explicit") == 0)
6571 /* set default mode to explicit */
6572 md.default_explicit_mode = 1;
6575 else if (strcmp (arg, "auto") == 0)
6577 md.default_explicit_mode = 0;
6579 else if (strcmp (arg, "debug") == 0)
6583 else if (strcmp (arg, "debugx") == 0)
6585 md.default_explicit_mode = 1;
6590 as_bad (_("Unrecognized option '-x%s'"), arg);
6595 /* nops Print nops statistics. */
6598 /* GNU specific switches for gcc. */
6599 case OPTION_MCONSTANT_GP:
6600 md.flags |= EF_IA_64_CONS_GP;
6603 case OPTION_MAUTO_PIC:
6604 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6615 md_show_usage (stream)
6620 --mconstant-gp mark output file as using the constant-GP model\n\
6621 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6622 --mauto-pic mark output file as using the constant-GP model\n\
6623 without function descriptors (sets ELF header flag\n\
6624 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6625 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6626 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6627 -x | -xexplicit turn on dependency violation checking (default)\n\
6628 -xauto automagically remove dependency violations\n\
6629 -xdebug debug dependency violation checker\n"),
6634 ia64_after_parse_args ()
6636 if (debug_type == DEBUG_STABS)
6637 as_fatal (_("--gstabs is not supported for ia64"));
6640 /* Return true if TYPE fits in TEMPL at SLOT. */
6643 match (int templ, int type, int slot)
6645 enum ia64_unit unit;
6648 unit = ia64_templ_desc[templ].exec_unit[slot];
6651 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6653 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6655 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6656 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6657 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6658 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6659 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6660 default: result = 0; break;
6665 /* Add a bit of extra goodness if a nop of type F or B would fit
6666 in TEMPL at SLOT. */
6669 extra_goodness (int templ, int slot)
6671 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6673 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6678 /* This function is called once, at assembler startup time. It sets
6679 up all the tables, etc. that the MD part of the assembler will need
6680 that can be determined before arguments are parsed. */
6684 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6689 md.explicit_mode = md.default_explicit_mode;
6691 bfd_set_section_alignment (stdoutput, text_section, 4);
6693 /* Make sure function pointers get initialized. */
6694 target_big_endian = -1;
6695 dot_byteorder (TARGET_BYTES_BIG_ENDIAN);
6697 alias_hash = hash_new ();
6698 alias_name_hash = hash_new ();
6699 secalias_hash = hash_new ();
6700 secalias_name_hash = hash_new ();
6702 pseudo_func[FUNC_DTP_MODULE].u.sym =
6703 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6704 &zero_address_frag);
6706 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6707 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6708 &zero_address_frag);
6710 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6711 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6712 &zero_address_frag);
6714 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6715 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6716 &zero_address_frag);
6718 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6719 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6720 &zero_address_frag);
6722 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6723 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6724 &zero_address_frag);
6726 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6727 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6728 &zero_address_frag);
6730 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6731 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6732 &zero_address_frag);
6734 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6735 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6736 &zero_address_frag);
6738 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6739 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6740 &zero_address_frag);
6742 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6743 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6744 &zero_address_frag);
6746 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6747 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6748 &zero_address_frag);
6750 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6751 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6752 &zero_address_frag);
6754 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6755 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6756 &zero_address_frag);
6758 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6759 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6760 &zero_address_frag);
6762 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6763 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6764 &zero_address_frag);
6766 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6767 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6768 &zero_address_frag);
6770 /* Compute the table of best templates. We compute goodness as a
6771 base 4 value, in which each match counts for 3, each F counts
6772 for 2, each B counts for 1. This should maximize the number of
6773 F and B nops in the chosen bundles, which is good because these
6774 pipelines are least likely to be overcommitted. */
6775 for (i = 0; i < IA64_NUM_TYPES; ++i)
6776 for (j = 0; j < IA64_NUM_TYPES; ++j)
6777 for (k = 0; k < IA64_NUM_TYPES; ++k)
6780 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6783 if (match (t, i, 0))
6785 if (match (t, j, 1))
6787 if (match (t, k, 2))
6788 goodness = 3 + 3 + 3;
6790 goodness = 3 + 3 + extra_goodness (t, 2);
6792 else if (match (t, j, 2))
6793 goodness = 3 + 3 + extra_goodness (t, 1);
6797 goodness += extra_goodness (t, 1);
6798 goodness += extra_goodness (t, 2);
6801 else if (match (t, i, 1))
6803 if (match (t, j, 2))
6806 goodness = 3 + extra_goodness (t, 2);
6808 else if (match (t, i, 2))
6809 goodness = 3 + extra_goodness (t, 1);
6811 if (goodness > best)
6814 best_template[i][j][k] = t;
6819 for (i = 0; i < NUM_SLOTS; ++i)
6820 md.slot[i].user_template = -1;
6822 md.pseudo_hash = hash_new ();
6823 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6825 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6826 (void *) (pseudo_opcode + i));
6828 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6829 pseudo_opcode[i].name, err);
6832 md.reg_hash = hash_new ();
6833 md.dynreg_hash = hash_new ();
6834 md.const_hash = hash_new ();
6835 md.entry_hash = hash_new ();
6837 /* general registers: */
6840 for (i = 0; i < total; ++i)
6842 sprintf (name, "r%d", i - REG_GR);
6843 md.regsym[i] = declare_register (name, i);
6846 /* floating point registers: */
6848 for (; i < total; ++i)
6850 sprintf (name, "f%d", i - REG_FR);
6851 md.regsym[i] = declare_register (name, i);
6854 /* application registers: */
6857 for (; i < total; ++i)
6859 sprintf (name, "ar%d", i - REG_AR);
6860 md.regsym[i] = declare_register (name, i);
6863 /* control registers: */
6866 for (; i < total; ++i)
6868 sprintf (name, "cr%d", i - REG_CR);
6869 md.regsym[i] = declare_register (name, i);
6872 /* predicate registers: */
6874 for (; i < total; ++i)
6876 sprintf (name, "p%d", i - REG_P);
6877 md.regsym[i] = declare_register (name, i);
6880 /* branch registers: */
6882 for (; i < total; ++i)
6884 sprintf (name, "b%d", i - REG_BR);
6885 md.regsym[i] = declare_register (name, i);
6888 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6889 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6890 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6891 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6892 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6893 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6894 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6896 for (i = 0; i < NELEMS (indirect_reg); ++i)
6898 regnum = indirect_reg[i].regnum;
6899 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6902 /* define synonyms for application registers: */
6903 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6904 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6905 REG_AR + ar[i - REG_AR].regnum);
6907 /* define synonyms for control registers: */
6908 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6909 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6910 REG_CR + cr[i - REG_CR].regnum);
6912 declare_register ("gp", REG_GR + 1);
6913 declare_register ("sp", REG_GR + 12);
6914 declare_register ("rp", REG_BR + 0);
6916 /* pseudo-registers used to specify unwind info: */
6917 declare_register ("psp", REG_PSP);
6919 declare_register_set ("ret", 4, REG_GR + 8);
6920 declare_register_set ("farg", 8, REG_FR + 8);
6921 declare_register_set ("fret", 8, REG_FR + 8);
6923 for (i = 0; i < NELEMS (const_bits); ++i)
6925 err = hash_insert (md.const_hash, const_bits[i].name,
6926 (PTR) (const_bits + i));
6928 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6932 /* Set the architecture and machine depending on defaults and command line
6934 if (md.flags & EF_IA_64_ABI64)
6935 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6937 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6940 as_warn (_("Could not set architecture and machine"));
6942 /* Set the pointer size and pointer shift size depending on md.flags */
6944 if (md.flags & EF_IA_64_ABI64)
6946 md.pointer_size = 8; /* pointers are 8 bytes */
6947 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6951 md.pointer_size = 4; /* pointers are 4 bytes */
6952 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6955 md.mem_offset.hint = 0;
6958 md.entry_labels = NULL;
6961 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6962 because that is called after md_parse_option which is where we do the
6963 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6964 default endianness. */
6967 ia64_init (argc, argv)
6968 int argc ATTRIBUTE_UNUSED;
6969 char **argv ATTRIBUTE_UNUSED;
6971 md.flags = MD_FLAGS_DEFAULT;
6974 /* Return a string for the target object file format. */
6977 ia64_target_format ()
6979 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6981 if (md.flags & EF_IA_64_BE)
6983 if (md.flags & EF_IA_64_ABI64)
6984 #if defined(TE_AIX50)
6985 return "elf64-ia64-aix-big";
6986 #elif defined(TE_HPUX)
6987 return "elf64-ia64-hpux-big";
6989 return "elf64-ia64-big";
6992 #if defined(TE_AIX50)
6993 return "elf32-ia64-aix-big";
6994 #elif defined(TE_HPUX)
6995 return "elf32-ia64-hpux-big";
6997 return "elf32-ia64-big";
7002 if (md.flags & EF_IA_64_ABI64)
7004 return "elf64-ia64-aix-little";
7006 return "elf64-ia64-little";
7010 return "elf32-ia64-aix-little";
7012 return "elf32-ia64-little";
7017 return "unknown-format";
7021 ia64_end_of_source ()
7023 /* terminate insn group upon reaching end of file: */
7024 insn_group_break (1, 0, 0);
7026 /* emits slots we haven't written yet: */
7027 ia64_flush_insns ();
7029 bfd_set_private_flags (stdoutput, md.flags);
7031 md.mem_offset.hint = 0;
7037 if (md.qp.X_op == O_register)
7038 as_bad ("qualifying predicate not followed by instruction");
7039 md.qp.X_op = O_absent;
7041 if (ignore_input ())
7044 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7046 if (md.detect_dv && !md.explicit_mode)
7047 as_warn (_("Explicit stops are ignored in auto mode"));
7049 insn_group_break (1, 0, 0);
7053 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7055 static int defining_tag = 0;
7058 ia64_unrecognized_line (ch)
7064 expression (&md.qp);
7065 if (*input_line_pointer++ != ')')
7067 as_bad ("Expected ')'");
7070 if (md.qp.X_op != O_register)
7072 as_bad ("Qualifying predicate expected");
7075 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7077 as_bad ("Predicate register expected");
7083 if (md.manual_bundling)
7084 as_warn ("Found '{' when manual bundling is already turned on");
7086 CURR_SLOT.manual_bundling_on = 1;
7087 md.manual_bundling = 1;
7089 /* Bundling is only acceptable in explicit mode
7090 or when in default automatic mode. */
7091 if (md.detect_dv && !md.explicit_mode)
7093 if (!md.mode_explicitly_set
7094 && !md.default_explicit_mode)
7097 as_warn (_("Found '{' after explicit switch to automatic mode"));
7102 if (!md.manual_bundling)
7103 as_warn ("Found '}' when manual bundling is off");
7105 PREV_SLOT.manual_bundling_off = 1;
7106 md.manual_bundling = 0;
7108 /* switch back to automatic mode, if applicable */
7111 && !md.mode_explicitly_set
7112 && !md.default_explicit_mode)
7115 /* Allow '{' to follow on the same line. We also allow ";;", but that
7116 happens automatically because ';' is an end of line marker. */
7118 if (input_line_pointer[0] == '{')
7120 input_line_pointer++;
7121 return ia64_unrecognized_line ('{');
7124 demand_empty_rest_of_line ();
7134 if (md.qp.X_op == O_register)
7136 as_bad ("Tag must come before qualifying predicate.");
7140 /* This implements just enough of read_a_source_file in read.c to
7141 recognize labels. */
7142 if (is_name_beginner (*input_line_pointer))
7144 s = input_line_pointer;
7145 c = get_symbol_end ();
7147 else if (LOCAL_LABELS_FB
7148 && ISDIGIT (*input_line_pointer))
7151 while (ISDIGIT (*input_line_pointer))
7152 temp = (temp * 10) + *input_line_pointer++ - '0';
7153 fb_label_instance_inc (temp);
7154 s = fb_label_name (temp, 0);
7155 c = *input_line_pointer;
7164 /* Put ':' back for error messages' sake. */
7165 *input_line_pointer++ = ':';
7166 as_bad ("Expected ':'");
7173 /* Put ':' back for error messages' sake. */
7174 *input_line_pointer++ = ':';
7175 if (*input_line_pointer++ != ']')
7177 as_bad ("Expected ']'");
7182 as_bad ("Tag name expected");
7192 /* Not a valid line. */
7197 ia64_frob_label (sym)
7200 struct label_fix *fix;
7202 /* Tags need special handling since they are not bundle breaks like
7206 fix = obstack_alloc (¬es, sizeof (*fix));
7208 fix->next = CURR_SLOT.tag_fixups;
7209 CURR_SLOT.tag_fixups = fix;
7214 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7216 md.last_text_seg = now_seg;
7217 fix = obstack_alloc (¬es, sizeof (*fix));
7219 fix->next = CURR_SLOT.label_fixups;
7220 CURR_SLOT.label_fixups = fix;
7222 /* Keep track of how many code entry points we've seen. */
7223 if (md.path == md.maxpaths)
7226 md.entry_labels = (const char **)
7227 xrealloc ((void *) md.entry_labels,
7228 md.maxpaths * sizeof (char *));
7230 md.entry_labels[md.path++] = S_GET_NAME (sym);
7235 /* The HP-UX linker will give unresolved symbol errors for symbols
7236 that are declared but unused. This routine removes declared,
7237 unused symbols from an object. */
7239 ia64_frob_symbol (sym)
7242 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7243 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7244 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7245 && ! S_IS_EXTERNAL (sym)))
7252 ia64_flush_pending_output ()
7254 if (!md.keep_pending_output
7255 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7257 /* ??? This causes many unnecessary stop bits to be emitted.
7258 Unfortunately, it isn't clear if it is safe to remove this. */
7259 insn_group_break (1, 0, 0);
7260 ia64_flush_insns ();
7264 /* Do ia64-specific expression optimization. All that's done here is
7265 to transform index expressions that are either due to the indexing
7266 of rotating registers or due to the indexing of indirect register
7269 ia64_optimize_expr (l, op, r)
7278 if (l->X_op == O_register && r->X_op == O_constant)
7280 num_regs = (l->X_add_number >> 16);
7281 if ((unsigned) r->X_add_number >= num_regs)
7284 as_bad ("No current frame");
7286 as_bad ("Index out of range 0..%u", num_regs - 1);
7287 r->X_add_number = 0;
7289 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7292 else if (l->X_op == O_register && r->X_op == O_register)
7294 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7295 || l->X_add_number == IND_MEM)
7297 as_bad ("Indirect register set name expected");
7298 l->X_add_number = IND_CPUID;
7301 l->X_op_symbol = md.regsym[l->X_add_number];
7302 l->X_add_number = r->X_add_number;
7310 ia64_parse_name (name, e)
7314 struct const_desc *cdesc;
7315 struct dynreg *dr = 0;
7316 unsigned int regnum;
7320 /* first see if NAME is a known register name: */
7321 sym = hash_find (md.reg_hash, name);
7324 e->X_op = O_register;
7325 e->X_add_number = S_GET_VALUE (sym);
7329 cdesc = hash_find (md.const_hash, name);
7332 e->X_op = O_constant;
7333 e->X_add_number = cdesc->value;
7337 /* check for inN, locN, or outN: */
7341 if (name[1] == 'n' && ISDIGIT (name[2]))
7349 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7357 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7370 /* The name is inN, locN, or outN; parse the register number. */
7371 regnum = strtoul (name, &end, 10);
7372 if (end > name && *end == '\0')
7374 if ((unsigned) regnum >= dr->num_regs)
7377 as_bad ("No current frame");
7379 as_bad ("Register number out of range 0..%u",
7383 e->X_op = O_register;
7384 e->X_add_number = dr->base + regnum;
7389 if ((dr = hash_find (md.dynreg_hash, name)))
7391 /* We've got ourselves the name of a rotating register set.
7392 Store the base register number in the low 16 bits of
7393 X_add_number and the size of the register set in the top 16
7395 e->X_op = O_register;
7396 e->X_add_number = dr->base | (dr->num_regs << 16);
7402 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7405 ia64_canonicalize_symbol_name (name)
7408 size_t len = strlen (name);
7409 if (len > 1 && name[len - 1] == '#')
7410 name[len - 1] = '\0';
7414 /* Return true if idesc is a conditional branch instruction. This excludes
7415 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7416 because they always read/write resources regardless of the value of the
7417 qualifying predicate. br.ia must always use p0, and hence is always
7418 taken. Thus this function returns true for branches which can fall
7419 through, and which use no resources if they do fall through. */
7422 is_conditional_branch (idesc)
7423 struct ia64_opcode *idesc;
7425 /* br is a conditional branch. Everything that starts with br. except
7426 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7427 Everything that starts with brl is a conditional branch. */
7428 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7429 && (idesc->name[2] == '\0'
7430 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7431 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7432 || idesc->name[2] == 'l'
7433 /* br.cond, br.call, br.clr */
7434 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7435 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7436 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7439 /* Return whether the given opcode is a taken branch. If there's any doubt,
7443 is_taken_branch (idesc)
7444 struct ia64_opcode *idesc;
7446 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7447 || strncmp (idesc->name, "br.ia", 5) == 0);
7450 /* Return whether the given opcode is an interruption or rfi. If there's any
7451 doubt, returns zero. */
7454 is_interruption_or_rfi (idesc)
7455 struct ia64_opcode *idesc;
7457 if (strcmp (idesc->name, "rfi") == 0)
7462 /* Returns the index of the given dependency in the opcode's list of chks, or
7463 -1 if there is no dependency. */
7466 depends_on (depind, idesc)
7468 struct ia64_opcode *idesc;
7471 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7472 for (i = 0; i < dep->nchks; i++)
7474 if (depind == DEP (dep->chks[i]))
7480 /* Determine a set of specific resources used for a particular resource
7481 class. Returns the number of specific resources identified For those
7482 cases which are not determinable statically, the resource returned is
7485 Meanings of value in 'NOTE':
7486 1) only read/write when the register number is explicitly encoded in the
7488 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7489 accesses CFM when qualifying predicate is in the rotating region.
7490 3) general register value is used to specify an indirect register; not
7491 determinable statically.
7492 4) only read the given resource when bits 7:0 of the indirect index
7493 register value does not match the register number of the resource; not
7494 determinable statically.
7495 5) all rules are implementation specific.
7496 6) only when both the index specified by the reader and the index specified
7497 by the writer have the same value in bits 63:61; not determinable
7499 7) only access the specified resource when the corresponding mask bit is
7501 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7502 only read when these insns reference FR2-31
7503 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7504 written when these insns write FR32-127
7505 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7507 11) The target predicates are written independently of PR[qp], but source
7508 registers are only read if PR[qp] is true. Since the state of PR[qp]
7509 cannot statically be determined, all source registers are marked used.
7510 12) This insn only reads the specified predicate register when that
7511 register is the PR[qp].
7512 13) This reference to ld-c only applies to teh GR whose value is loaded
7513 with data returned from memory, not the post-incremented address register.
7514 14) The RSE resource includes the implementation-specific RSE internal
7515 state resources. At least one (and possibly more) of these resources are
7516 read by each instruction listed in IC:rse-readers. At least one (and
7517 possibly more) of these resources are written by each insn listed in
7519 15+16) Represents reserved instructions, which the assembler does not
7522 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7523 this code; there are no dependency violations based on memory access.
7526 #define MAX_SPECS 256
7531 specify_resource (dep, idesc, type, specs, note, path)
7532 const struct ia64_dependency *dep;
7533 struct ia64_opcode *idesc;
7534 int type; /* is this a DV chk or a DV reg? */
7535 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7536 int note; /* resource note for this insn's usage */
7537 int path; /* which execution path to examine */
7544 if (dep->mode == IA64_DV_WAW
7545 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7546 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7549 /* template for any resources we identify */
7550 tmpl.dependency = dep;
7552 tmpl.insn_srlz = tmpl.data_srlz = 0;
7553 tmpl.qp_regno = CURR_SLOT.qp_regno;
7554 tmpl.link_to_qp_branch = 1;
7555 tmpl.mem_offset.hint = 0;
7558 tmpl.cmp_type = CMP_NONE;
7561 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7562 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7563 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7565 /* we don't need to track these */
7566 if (dep->semantics == IA64_DVS_NONE)
7569 switch (dep->specifier)
7574 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7576 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7577 if (regno >= 0 && regno <= 7)
7579 specs[count] = tmpl;
7580 specs[count++].index = regno;
7586 for (i = 0; i < 8; i++)
7588 specs[count] = tmpl;
7589 specs[count++].index = i;
7598 case IA64_RS_AR_UNAT:
7599 /* This is a mov =AR or mov AR= instruction. */
7600 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7602 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7603 if (regno == AR_UNAT)
7605 specs[count++] = tmpl;
7610 /* This is a spill/fill, or other instruction that modifies the
7613 /* Unless we can determine the specific bits used, mark the whole
7614 thing; bits 8:3 of the memory address indicate the bit used in
7615 UNAT. The .mem.offset hint may be used to eliminate a small
7616 subset of conflicts. */
7617 specs[count] = tmpl;
7618 if (md.mem_offset.hint)
7621 fprintf (stderr, " Using hint for spill/fill\n");
7622 /* The index isn't actually used, just set it to something
7623 approximating the bit index. */
7624 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7625 specs[count].mem_offset.hint = 1;
7626 specs[count].mem_offset.offset = md.mem_offset.offset;
7627 specs[count++].mem_offset.base = md.mem_offset.base;
7631 specs[count++].specific = 0;
7639 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7641 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7642 if ((regno >= 8 && regno <= 15)
7643 || (regno >= 20 && regno <= 23)
7644 || (regno >= 31 && regno <= 39)
7645 || (regno >= 41 && regno <= 47)
7646 || (regno >= 67 && regno <= 111))
7648 specs[count] = tmpl;
7649 specs[count++].index = regno;
7662 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7664 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7665 if ((regno >= 48 && regno <= 63)
7666 || (regno >= 112 && regno <= 127))
7668 specs[count] = tmpl;
7669 specs[count++].index = regno;
7675 for (i = 48; i < 64; i++)
7677 specs[count] = tmpl;
7678 specs[count++].index = i;
7680 for (i = 112; i < 128; i++)
7682 specs[count] = tmpl;
7683 specs[count++].index = i;
7701 for (i = 0; i < idesc->num_outputs; i++)
7702 if (idesc->operands[i] == IA64_OPND_B1
7703 || idesc->operands[i] == IA64_OPND_B2)
7705 specs[count] = tmpl;
7706 specs[count++].index =
7707 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7712 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7713 if (idesc->operands[i] == IA64_OPND_B1
7714 || idesc->operands[i] == IA64_OPND_B2)
7716 specs[count] = tmpl;
7717 specs[count++].index =
7718 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7724 case IA64_RS_CPUID: /* four or more registers */
7727 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7729 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7730 if (regno >= 0 && regno < NELEMS (gr_values)
7733 specs[count] = tmpl;
7734 specs[count++].index = gr_values[regno].value & 0xFF;
7738 specs[count] = tmpl;
7739 specs[count++].specific = 0;
7749 case IA64_RS_DBR: /* four or more registers */
7752 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7754 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7755 if (regno >= 0 && regno < NELEMS (gr_values)
7758 specs[count] = tmpl;
7759 specs[count++].index = gr_values[regno].value & 0xFF;
7763 specs[count] = tmpl;
7764 specs[count++].specific = 0;
7768 else if (note == 0 && !rsrc_write)
7770 specs[count] = tmpl;
7771 specs[count++].specific = 0;
7779 case IA64_RS_IBR: /* four or more registers */
7782 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7784 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7785 if (regno >= 0 && regno < NELEMS (gr_values)
7788 specs[count] = tmpl;
7789 specs[count++].index = gr_values[regno].value & 0xFF;
7793 specs[count] = tmpl;
7794 specs[count++].specific = 0;
7807 /* These are implementation specific. Force all references to
7808 conflict with all other references. */
7809 specs[count] = tmpl;
7810 specs[count++].specific = 0;
7818 case IA64_RS_PKR: /* 16 or more registers */
7819 if (note == 3 || note == 4)
7821 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7823 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7824 if (regno >= 0 && regno < NELEMS (gr_values)
7829 specs[count] = tmpl;
7830 specs[count++].index = gr_values[regno].value & 0xFF;
7833 for (i = 0; i < NELEMS (gr_values); i++)
7835 /* Uses all registers *except* the one in R3. */
7836 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7838 specs[count] = tmpl;
7839 specs[count++].index = i;
7845 specs[count] = tmpl;
7846 specs[count++].specific = 0;
7853 specs[count] = tmpl;
7854 specs[count++].specific = 0;
7858 case IA64_RS_PMC: /* four or more registers */
7861 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7862 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7865 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7867 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7868 if (regno >= 0 && regno < NELEMS (gr_values)
7871 specs[count] = tmpl;
7872 specs[count++].index = gr_values[regno].value & 0xFF;
7876 specs[count] = tmpl;
7877 specs[count++].specific = 0;
7887 case IA64_RS_PMD: /* four or more registers */
7890 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7892 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7893 if (regno >= 0 && regno < NELEMS (gr_values)
7896 specs[count] = tmpl;
7897 specs[count++].index = gr_values[regno].value & 0xFF;
7901 specs[count] = tmpl;
7902 specs[count++].specific = 0;
7912 case IA64_RS_RR: /* eight registers */
7915 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7917 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7918 if (regno >= 0 && regno < NELEMS (gr_values)
7921 specs[count] = tmpl;
7922 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7926 specs[count] = tmpl;
7927 specs[count++].specific = 0;
7931 else if (note == 0 && !rsrc_write)
7933 specs[count] = tmpl;
7934 specs[count++].specific = 0;
7942 case IA64_RS_CR_IRR:
7945 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7946 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7948 && idesc->operands[1] == IA64_OPND_CR3
7951 for (i = 0; i < 4; i++)
7953 specs[count] = tmpl;
7954 specs[count++].index = CR_IRR0 + i;
7960 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7961 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7963 && regno <= CR_IRR3)
7965 specs[count] = tmpl;
7966 specs[count++].index = regno;
7975 case IA64_RS_CR_LRR:
7982 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7983 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7984 && (regno == CR_LRR0 || regno == CR_LRR1))
7986 specs[count] = tmpl;
7987 specs[count++].index = regno;
7995 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7997 specs[count] = tmpl;
7998 specs[count++].index =
7999 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8014 else if (rsrc_write)
8016 if (dep->specifier == IA64_RS_FRb
8017 && idesc->operands[0] == IA64_OPND_F1)
8019 specs[count] = tmpl;
8020 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8025 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8027 if (idesc->operands[i] == IA64_OPND_F2
8028 || idesc->operands[i] == IA64_OPND_F3
8029 || idesc->operands[i] == IA64_OPND_F4)
8031 specs[count] = tmpl;
8032 specs[count++].index =
8033 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8042 /* This reference applies only to the GR whose value is loaded with
8043 data returned from memory. */
8044 specs[count] = tmpl;
8045 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8051 for (i = 0; i < idesc->num_outputs; i++)
8052 if (idesc->operands[i] == IA64_OPND_R1
8053 || idesc->operands[i] == IA64_OPND_R2
8054 || idesc->operands[i] == IA64_OPND_R3)
8056 specs[count] = tmpl;
8057 specs[count++].index =
8058 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8060 if (idesc->flags & IA64_OPCODE_POSTINC)
8061 for (i = 0; i < NELEMS (idesc->operands); i++)
8062 if (idesc->operands[i] == IA64_OPND_MR3)
8064 specs[count] = tmpl;
8065 specs[count++].index =
8066 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8071 /* Look for anything that reads a GR. */
8072 for (i = 0; i < NELEMS (idesc->operands); i++)
8074 if (idesc->operands[i] == IA64_OPND_MR3
8075 || idesc->operands[i] == IA64_OPND_CPUID_R3
8076 || idesc->operands[i] == IA64_OPND_DBR_R3
8077 || idesc->operands[i] == IA64_OPND_IBR_R3
8078 || idesc->operands[i] == IA64_OPND_MSR_R3
8079 || idesc->operands[i] == IA64_OPND_PKR_R3
8080 || idesc->operands[i] == IA64_OPND_PMC_R3
8081 || idesc->operands[i] == IA64_OPND_PMD_R3
8082 || idesc->operands[i] == IA64_OPND_RR_R3
8083 || ((i >= idesc->num_outputs)
8084 && (idesc->operands[i] == IA64_OPND_R1
8085 || idesc->operands[i] == IA64_OPND_R2
8086 || idesc->operands[i] == IA64_OPND_R3
8087 /* addl source register. */
8088 || idesc->operands[i] == IA64_OPND_R3_2)))
8090 specs[count] = tmpl;
8091 specs[count++].index =
8092 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8103 /* This is the same as IA64_RS_PRr, except that the register range is
8104 from 1 - 15, and there are no rotating register reads/writes here. */
8108 for (i = 1; i < 16; i++)
8110 specs[count] = tmpl;
8111 specs[count++].index = i;
8117 /* Mark only those registers indicated by the mask. */
8120 mask = CURR_SLOT.opnd[2].X_add_number;
8121 for (i = 1; i < 16; i++)
8122 if (mask & ((valueT) 1 << i))
8124 specs[count] = tmpl;
8125 specs[count++].index = i;
8133 else if (note == 11) /* note 11 implies note 1 as well */
8137 for (i = 0; i < idesc->num_outputs; i++)
8139 if (idesc->operands[i] == IA64_OPND_P1
8140 || idesc->operands[i] == IA64_OPND_P2)
8142 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8143 if (regno >= 1 && regno < 16)
8145 specs[count] = tmpl;
8146 specs[count++].index = regno;
8156 else if (note == 12)
8158 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8160 specs[count] = tmpl;
8161 specs[count++].index = CURR_SLOT.qp_regno;
8168 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8169 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8170 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8171 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8173 if ((idesc->operands[0] == IA64_OPND_P1
8174 || idesc->operands[0] == IA64_OPND_P2)
8175 && p1 >= 1 && p1 < 16)
8177 specs[count] = tmpl;
8178 specs[count].cmp_type =
8179 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8180 specs[count++].index = p1;
8182 if ((idesc->operands[1] == IA64_OPND_P1
8183 || idesc->operands[1] == IA64_OPND_P2)
8184 && p2 >= 1 && p2 < 16)
8186 specs[count] = tmpl;
8187 specs[count].cmp_type =
8188 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8189 specs[count++].index = p2;
8194 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8196 specs[count] = tmpl;
8197 specs[count++].index = CURR_SLOT.qp_regno;
8199 if (idesc->operands[1] == IA64_OPND_PR)
8201 for (i = 1; i < 16; i++)
8203 specs[count] = tmpl;
8204 specs[count++].index = i;
8215 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8216 simplified cases of this. */
8220 for (i = 16; i < 63; i++)
8222 specs[count] = tmpl;
8223 specs[count++].index = i;
8229 /* Mark only those registers indicated by the mask. */
8231 && idesc->operands[0] == IA64_OPND_PR)
8233 mask = CURR_SLOT.opnd[2].X_add_number;
8234 if (mask & ((valueT) 1 << 16))
8235 for (i = 16; i < 63; i++)
8237 specs[count] = tmpl;
8238 specs[count++].index = i;
8242 && idesc->operands[0] == IA64_OPND_PR_ROT)
8244 for (i = 16; i < 63; i++)
8246 specs[count] = tmpl;
8247 specs[count++].index = i;
8255 else if (note == 11) /* note 11 implies note 1 as well */
8259 for (i = 0; i < idesc->num_outputs; i++)
8261 if (idesc->operands[i] == IA64_OPND_P1
8262 || idesc->operands[i] == IA64_OPND_P2)
8264 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8265 if (regno >= 16 && regno < 63)
8267 specs[count] = tmpl;
8268 specs[count++].index = regno;
8278 else if (note == 12)
8280 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8282 specs[count] = tmpl;
8283 specs[count++].index = CURR_SLOT.qp_regno;
8290 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8291 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8292 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8293 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8295 if ((idesc->operands[0] == IA64_OPND_P1
8296 || idesc->operands[0] == IA64_OPND_P2)
8297 && p1 >= 16 && p1 < 63)
8299 specs[count] = tmpl;
8300 specs[count].cmp_type =
8301 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8302 specs[count++].index = p1;
8304 if ((idesc->operands[1] == IA64_OPND_P1
8305 || idesc->operands[1] == IA64_OPND_P2)
8306 && p2 >= 16 && p2 < 63)
8308 specs[count] = tmpl;
8309 specs[count].cmp_type =
8310 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8311 specs[count++].index = p2;
8316 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8318 specs[count] = tmpl;
8319 specs[count++].index = CURR_SLOT.qp_regno;
8321 if (idesc->operands[1] == IA64_OPND_PR)
8323 for (i = 16; i < 63; i++)
8325 specs[count] = tmpl;
8326 specs[count++].index = i;
8338 /* Verify that the instruction is using the PSR bit indicated in
8342 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8344 if (dep->regindex < 6)
8346 specs[count++] = tmpl;
8349 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8351 if (dep->regindex < 32
8352 || dep->regindex == 35
8353 || dep->regindex == 36
8354 || (!rsrc_write && dep->regindex == PSR_CPL))
8356 specs[count++] = tmpl;
8359 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8361 if (dep->regindex < 32
8362 || dep->regindex == 35
8363 || dep->regindex == 36
8364 || (rsrc_write && dep->regindex == PSR_CPL))
8366 specs[count++] = tmpl;
8371 /* Several PSR bits have very specific dependencies. */
8372 switch (dep->regindex)
8375 specs[count++] = tmpl;
8380 specs[count++] = tmpl;
8384 /* Only certain CR accesses use PSR.ic */
8385 if (idesc->operands[0] == IA64_OPND_CR3
8386 || idesc->operands[1] == IA64_OPND_CR3)
8389 ((idesc->operands[0] == IA64_OPND_CR3)
8392 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8407 specs[count++] = tmpl;
8416 specs[count++] = tmpl;
8420 /* Only some AR accesses use cpl */
8421 if (idesc->operands[0] == IA64_OPND_AR3
8422 || idesc->operands[1] == IA64_OPND_AR3)
8425 ((idesc->operands[0] == IA64_OPND_AR3)
8428 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8435 && regno <= AR_K7))))
8437 specs[count++] = tmpl;
8442 specs[count++] = tmpl;
8452 if (idesc->operands[0] == IA64_OPND_IMMU24)
8454 mask = CURR_SLOT.opnd[0].X_add_number;
8460 if (mask & ((valueT) 1 << dep->regindex))
8462 specs[count++] = tmpl;
8467 int min = dep->regindex == PSR_DFL ? 2 : 32;
8468 int max = dep->regindex == PSR_DFL ? 31 : 127;
8469 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8470 for (i = 0; i < NELEMS (idesc->operands); i++)
8472 if (idesc->operands[i] == IA64_OPND_F1
8473 || idesc->operands[i] == IA64_OPND_F2
8474 || idesc->operands[i] == IA64_OPND_F3
8475 || idesc->operands[i] == IA64_OPND_F4)
8477 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8478 if (reg >= min && reg <= max)
8480 specs[count++] = tmpl;
8487 int min = dep->regindex == PSR_MFL ? 2 : 32;
8488 int max = dep->regindex == PSR_MFL ? 31 : 127;
8489 /* mfh is read on writes to FR32-127; mfl is read on writes to
8491 for (i = 0; i < idesc->num_outputs; i++)
8493 if (idesc->operands[i] == IA64_OPND_F1)
8495 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8496 if (reg >= min && reg <= max)
8498 specs[count++] = tmpl;
8503 else if (note == 10)
8505 for (i = 0; i < NELEMS (idesc->operands); i++)
8507 if (idesc->operands[i] == IA64_OPND_R1
8508 || idesc->operands[i] == IA64_OPND_R2
8509 || idesc->operands[i] == IA64_OPND_R3)
8511 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8512 if (regno >= 16 && regno <= 31)
8514 specs[count++] = tmpl;
8525 case IA64_RS_AR_FPSR:
8526 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8528 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8529 if (regno == AR_FPSR)
8531 specs[count++] = tmpl;
8536 specs[count++] = tmpl;
8541 /* Handle all AR[REG] resources */
8542 if (note == 0 || note == 1)
8544 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8545 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8546 && regno == dep->regindex)
8548 specs[count++] = tmpl;
8550 /* other AR[REG] resources may be affected by AR accesses */
8551 else if (idesc->operands[0] == IA64_OPND_AR3)
8554 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8555 switch (dep->regindex)
8561 if (regno == AR_BSPSTORE)
8563 specs[count++] = tmpl;
8567 (regno == AR_BSPSTORE
8568 || regno == AR_RNAT))
8570 specs[count++] = tmpl;
8575 else if (idesc->operands[1] == IA64_OPND_AR3)
8578 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8579 switch (dep->regindex)
8584 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8586 specs[count++] = tmpl;
8593 specs[count++] = tmpl;
8603 /* Handle all CR[REG] resources */
8604 if (note == 0 || note == 1)
8606 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8608 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8609 if (regno == dep->regindex)
8611 specs[count++] = tmpl;
8613 else if (!rsrc_write)
8615 /* Reads from CR[IVR] affect other resources. */
8616 if (regno == CR_IVR)
8618 if ((dep->regindex >= CR_IRR0
8619 && dep->regindex <= CR_IRR3)
8620 || dep->regindex == CR_TPR)
8622 specs[count++] = tmpl;
8629 specs[count++] = tmpl;
8638 case IA64_RS_INSERVICE:
8639 /* look for write of EOI (67) or read of IVR (65) */
8640 if ((idesc->operands[0] == IA64_OPND_CR3
8641 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8642 || (idesc->operands[1] == IA64_OPND_CR3
8643 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8645 specs[count++] = tmpl;
8652 specs[count++] = tmpl;
8663 specs[count++] = tmpl;
8667 /* Check if any of the registers accessed are in the rotating region.
8668 mov to/from pr accesses CFM only when qp_regno is in the rotating
8670 for (i = 0; i < NELEMS (idesc->operands); i++)
8672 if (idesc->operands[i] == IA64_OPND_R1
8673 || idesc->operands[i] == IA64_OPND_R2
8674 || idesc->operands[i] == IA64_OPND_R3)
8676 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8677 /* Assumes that md.rot.num_regs is always valid */
8678 if (md.rot.num_regs > 0
8680 && num < 31 + md.rot.num_regs)
8682 specs[count] = tmpl;
8683 specs[count++].specific = 0;
8686 else if (idesc->operands[i] == IA64_OPND_F1
8687 || idesc->operands[i] == IA64_OPND_F2
8688 || idesc->operands[i] == IA64_OPND_F3
8689 || idesc->operands[i] == IA64_OPND_F4)
8691 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8694 specs[count] = tmpl;
8695 specs[count++].specific = 0;
8698 else if (idesc->operands[i] == IA64_OPND_P1
8699 || idesc->operands[i] == IA64_OPND_P2)
8701 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8704 specs[count] = tmpl;
8705 specs[count++].specific = 0;
8709 if (CURR_SLOT.qp_regno > 15)
8711 specs[count] = tmpl;
8712 specs[count++].specific = 0;
8717 /* This is the same as IA64_RS_PRr, except simplified to account for
8718 the fact that there is only one register. */
8722 specs[count++] = tmpl;
8727 if (idesc->operands[2] == IA64_OPND_IMM17)
8728 mask = CURR_SLOT.opnd[2].X_add_number;
8729 if (mask & ((valueT) 1 << 63))
8730 specs[count++] = tmpl;
8732 else if (note == 11)
8734 if ((idesc->operands[0] == IA64_OPND_P1
8735 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8736 || (idesc->operands[1] == IA64_OPND_P2
8737 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8739 specs[count++] = tmpl;
8742 else if (note == 12)
8744 if (CURR_SLOT.qp_regno == 63)
8746 specs[count++] = tmpl;
8753 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8754 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8755 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8756 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8759 && (idesc->operands[0] == IA64_OPND_P1
8760 || idesc->operands[0] == IA64_OPND_P2))
8762 specs[count] = tmpl;
8763 specs[count++].cmp_type =
8764 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8767 && (idesc->operands[1] == IA64_OPND_P1
8768 || idesc->operands[1] == IA64_OPND_P2))
8770 specs[count] = tmpl;
8771 specs[count++].cmp_type =
8772 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8777 if (CURR_SLOT.qp_regno == 63)
8779 specs[count++] = tmpl;
8790 /* FIXME we can identify some individual RSE written resources, but RSE
8791 read resources have not yet been completely identified, so for now
8792 treat RSE as a single resource */
8793 if (strncmp (idesc->name, "mov", 3) == 0)
8797 if (idesc->operands[0] == IA64_OPND_AR3
8798 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8800 specs[count] = tmpl;
8801 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8806 if (idesc->operands[0] == IA64_OPND_AR3)
8808 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8809 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8811 specs[count++] = tmpl;
8814 else if (idesc->operands[1] == IA64_OPND_AR3)
8816 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8817 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8818 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8820 specs[count++] = tmpl;
8827 specs[count++] = tmpl;
8832 /* FIXME -- do any of these need to be non-specific? */
8833 specs[count++] = tmpl;
8837 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8844 /* Clear branch flags on marked resources. This breaks the link between the
8845 QP of the marking instruction and a subsequent branch on the same QP. */
8848 clear_qp_branch_flag (mask)
8852 for (i = 0; i < regdepslen; i++)
8854 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8855 if ((bit & mask) != 0)
8857 regdeps[i].link_to_qp_branch = 0;
8862 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
8863 any mutexes which contain one of the PRs and create new ones when
8867 update_qp_mutex (valueT mask)
8873 while (i < qp_mutexeslen)
8875 if ((qp_mutexes[i].prmask & mask) != 0)
8877 /* If it destroys and creates the same mutex, do nothing. */
8878 if (qp_mutexes[i].prmask == mask
8879 && qp_mutexes[i].path == md.path)
8890 fprintf (stderr, " Clearing mutex relation");
8891 print_prmask (qp_mutexes[i].prmask);
8892 fprintf (stderr, "\n");
8895 /* Deal with the old mutex with more than 3+ PRs only if
8896 the new mutex on the same execution path with it.
8898 FIXME: The 3+ mutex support is incomplete.
8899 dot_pred_rel () may be a better place to fix it. */
8900 if (qp_mutexes[i].path == md.path)
8902 /* If it is a proper subset of the mutex, create a
8905 && (qp_mutexes[i].prmask & mask) == mask)
8908 qp_mutexes[i].prmask &= ~mask;
8909 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
8911 /* Modify the mutex if there are more than one
8919 /* Remove the mutex. */
8920 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8928 add_qp_mutex (mask);
8933 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8935 Any changes to a PR clears the mutex relations which include that PR. */
8938 clear_qp_mutex (mask)
8944 while (i < qp_mutexeslen)
8946 if ((qp_mutexes[i].prmask & mask) != 0)
8950 fprintf (stderr, " Clearing mutex relation");
8951 print_prmask (qp_mutexes[i].prmask);
8952 fprintf (stderr, "\n");
8954 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8961 /* Clear implies relations which contain PRs in the given masks.
8962 P1_MASK indicates the source of the implies relation, while P2_MASK
8963 indicates the implied PR. */
8966 clear_qp_implies (p1_mask, p2_mask)
8973 while (i < qp_implieslen)
8975 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8976 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8979 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8980 qp_implies[i].p1, qp_implies[i].p2);
8981 qp_implies[i] = qp_implies[--qp_implieslen];
8988 /* Add the PRs specified to the list of implied relations. */
8991 add_qp_imply (p1, p2)
8998 /* p0 is not meaningful here. */
8999 if (p1 == 0 || p2 == 0)
9005 /* If it exists already, ignore it. */
9006 for (i = 0; i < qp_implieslen; i++)
9008 if (qp_implies[i].p1 == p1
9009 && qp_implies[i].p2 == p2
9010 && qp_implies[i].path == md.path
9011 && !qp_implies[i].p2_branched)
9015 if (qp_implieslen == qp_impliestotlen)
9017 qp_impliestotlen += 20;
9018 qp_implies = (struct qp_imply *)
9019 xrealloc ((void *) qp_implies,
9020 qp_impliestotlen * sizeof (struct qp_imply));
9023 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9024 qp_implies[qp_implieslen].p1 = p1;
9025 qp_implies[qp_implieslen].p2 = p2;
9026 qp_implies[qp_implieslen].path = md.path;
9027 qp_implies[qp_implieslen++].p2_branched = 0;
9029 /* Add in the implied transitive relations; for everything that p2 implies,
9030 make p1 imply that, too; for everything that implies p1, make it imply p2
9032 for (i = 0; i < qp_implieslen; i++)
9034 if (qp_implies[i].p1 == p2)
9035 add_qp_imply (p1, qp_implies[i].p2);
9036 if (qp_implies[i].p2 == p1)
9037 add_qp_imply (qp_implies[i].p1, p2);
9039 /* Add in mutex relations implied by this implies relation; for each mutex
9040 relation containing p2, duplicate it and replace p2 with p1. */
9041 bit = (valueT) 1 << p1;
9042 mask = (valueT) 1 << p2;
9043 for (i = 0; i < qp_mutexeslen; i++)
9045 if (qp_mutexes[i].prmask & mask)
9046 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9050 /* Add the PRs specified in the mask to the mutex list; this means that only
9051 one of the PRs can be true at any time. PR0 should never be included in
9061 if (qp_mutexeslen == qp_mutexestotlen)
9063 qp_mutexestotlen += 20;
9064 qp_mutexes = (struct qpmutex *)
9065 xrealloc ((void *) qp_mutexes,
9066 qp_mutexestotlen * sizeof (struct qpmutex));
9070 fprintf (stderr, " Registering mutex on");
9071 print_prmask (mask);
9072 fprintf (stderr, "\n");
9074 qp_mutexes[qp_mutexeslen].path = md.path;
9075 qp_mutexes[qp_mutexeslen++].prmask = mask;
9079 has_suffix_p (name, suffix)
9083 size_t namelen = strlen (name);
9084 size_t sufflen = strlen (suffix);
9086 if (namelen <= sufflen)
9088 return strcmp (name + namelen - sufflen, suffix) == 0;
9092 clear_register_values ()
9096 fprintf (stderr, " Clearing register values\n");
9097 for (i = 1; i < NELEMS (gr_values); i++)
9098 gr_values[i].known = 0;
9101 /* Keep track of register values/changes which affect DV tracking.
9103 optimization note: should add a flag to classes of insns where otherwise we
9104 have to examine a group of strings to identify them. */
9107 note_register_values (idesc)
9108 struct ia64_opcode *idesc;
9110 valueT qp_changemask = 0;
9113 /* Invalidate values for registers being written to. */
9114 for (i = 0; i < idesc->num_outputs; i++)
9116 if (idesc->operands[i] == IA64_OPND_R1
9117 || idesc->operands[i] == IA64_OPND_R2
9118 || idesc->operands[i] == IA64_OPND_R3)
9120 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9121 if (regno > 0 && regno < NELEMS (gr_values))
9122 gr_values[regno].known = 0;
9124 else if (idesc->operands[i] == IA64_OPND_R3_2)
9126 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9127 if (regno > 0 && regno < 4)
9128 gr_values[regno].known = 0;
9130 else if (idesc->operands[i] == IA64_OPND_P1
9131 || idesc->operands[i] == IA64_OPND_P2)
9133 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9134 qp_changemask |= (valueT) 1 << regno;
9136 else if (idesc->operands[i] == IA64_OPND_PR)
9138 if (idesc->operands[2] & (valueT) 0x10000)
9139 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9141 qp_changemask = idesc->operands[2];
9144 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9146 if (idesc->operands[1] & ((valueT) 1 << 43))
9147 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9149 qp_changemask = idesc->operands[1];
9150 qp_changemask &= ~(valueT) 0xFFFF;
9155 /* Always clear qp branch flags on any PR change. */
9156 /* FIXME there may be exceptions for certain compares. */
9157 clear_qp_branch_flag (qp_changemask);
9159 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9160 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9162 qp_changemask |= ~(valueT) 0xFFFF;
9163 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9165 for (i = 32; i < 32 + md.rot.num_regs; i++)
9166 gr_values[i].known = 0;
9168 clear_qp_mutex (qp_changemask);
9169 clear_qp_implies (qp_changemask, qp_changemask);
9171 /* After a call, all register values are undefined, except those marked
9173 else if (strncmp (idesc->name, "br.call", 6) == 0
9174 || strncmp (idesc->name, "brl.call", 7) == 0)
9176 /* FIXME keep GR values which are marked as "safe_across_calls" */
9177 clear_register_values ();
9178 clear_qp_mutex (~qp_safe_across_calls);
9179 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9180 clear_qp_branch_flag (~qp_safe_across_calls);
9182 else if (is_interruption_or_rfi (idesc)
9183 || is_taken_branch (idesc))
9185 clear_register_values ();
9186 clear_qp_mutex (~(valueT) 0);
9187 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9189 /* Look for mutex and implies relations. */
9190 else if ((idesc->operands[0] == IA64_OPND_P1
9191 || idesc->operands[0] == IA64_OPND_P2)
9192 && (idesc->operands[1] == IA64_OPND_P1
9193 || idesc->operands[1] == IA64_OPND_P2))
9195 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9196 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9197 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9198 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9200 /* If both PRs are PR0, we can't really do anything. */
9201 if (p1 == 0 && p2 == 0)
9204 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9206 /* In general, clear mutexes and implies which include P1 or P2,
9207 with the following exceptions. */
9208 else if (has_suffix_p (idesc->name, ".or.andcm")
9209 || has_suffix_p (idesc->name, ".and.orcm"))
9211 clear_qp_implies (p2mask, p1mask);
9213 else if (has_suffix_p (idesc->name, ".andcm")
9214 || has_suffix_p (idesc->name, ".and"))
9216 clear_qp_implies (0, p1mask | p2mask);
9218 else if (has_suffix_p (idesc->name, ".orcm")
9219 || has_suffix_p (idesc->name, ".or"))
9221 clear_qp_mutex (p1mask | p2mask);
9222 clear_qp_implies (p1mask | p2mask, 0);
9228 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9230 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9231 if (p1 == 0 || p2 == 0)
9232 clear_qp_mutex (p1mask | p2mask);
9234 added = update_qp_mutex (p1mask | p2mask);
9236 if (CURR_SLOT.qp_regno == 0
9237 || has_suffix_p (idesc->name, ".unc"))
9239 if (added == 0 && p1 && p2)
9240 add_qp_mutex (p1mask | p2mask);
9241 if (CURR_SLOT.qp_regno != 0)
9244 add_qp_imply (p1, CURR_SLOT.qp_regno);
9246 add_qp_imply (p2, CURR_SLOT.qp_regno);
9251 /* Look for mov imm insns into GRs. */
9252 else if (idesc->operands[0] == IA64_OPND_R1
9253 && (idesc->operands[1] == IA64_OPND_IMM22
9254 || idesc->operands[1] == IA64_OPND_IMMU64)
9255 && (strcmp (idesc->name, "mov") == 0
9256 || strcmp (idesc->name, "movl") == 0))
9258 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9259 if (regno > 0 && regno < NELEMS (gr_values))
9261 gr_values[regno].known = 1;
9262 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9263 gr_values[regno].path = md.path;
9266 fprintf (stderr, " Know gr%d = ", regno);
9267 fprintf_vma (stderr, gr_values[regno].value);
9268 fputs ("\n", stderr);
9274 clear_qp_mutex (qp_changemask);
9275 clear_qp_implies (qp_changemask, qp_changemask);
9279 /* Return whether the given predicate registers are currently mutex. */
9282 qp_mutex (p1, p2, path)
9292 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9293 for (i = 0; i < qp_mutexeslen; i++)
9295 if (qp_mutexes[i].path >= path
9296 && (qp_mutexes[i].prmask & mask) == mask)
9303 /* Return whether the given resource is in the given insn's list of chks
9304 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9308 resources_match (rs, idesc, note, qp_regno, path)
9310 struct ia64_opcode *idesc;
9315 struct rsrc specs[MAX_SPECS];
9318 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9319 we don't need to check. One exception is note 11, which indicates that
9320 target predicates are written regardless of PR[qp]. */
9321 if (qp_mutex (rs->qp_regno, qp_regno, path)
9325 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9328 /* UNAT checking is a bit more specific than other resources */
9329 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9330 && specs[count].mem_offset.hint
9331 && rs->mem_offset.hint)
9333 if (rs->mem_offset.base == specs[count].mem_offset.base)
9335 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9336 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9343 /* Skip apparent PR write conflicts where both writes are an AND or both
9344 writes are an OR. */
9345 if (rs->dependency->specifier == IA64_RS_PR
9346 || rs->dependency->specifier == IA64_RS_PRr
9347 || rs->dependency->specifier == IA64_RS_PR63)
9349 if (specs[count].cmp_type != CMP_NONE
9350 && specs[count].cmp_type == rs->cmp_type)
9353 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9354 dv_mode[rs->dependency->mode],
9355 rs->dependency->specifier != IA64_RS_PR63 ?
9356 specs[count].index : 63);
9361 " %s on parallel compare conflict %s vs %s on PR%d\n",
9362 dv_mode[rs->dependency->mode],
9363 dv_cmp_type[rs->cmp_type],
9364 dv_cmp_type[specs[count].cmp_type],
9365 rs->dependency->specifier != IA64_RS_PR63 ?
9366 specs[count].index : 63);
9370 /* If either resource is not specific, conservatively assume a conflict
9372 if (!specs[count].specific || !rs->specific)
9374 else if (specs[count].index == rs->index)
9379 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9385 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9386 insert a stop to create the break. Update all resource dependencies
9387 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9388 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9389 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9393 insn_group_break (insert_stop, qp_regno, save_current)
9400 if (insert_stop && md.num_slots_in_use > 0)
9401 PREV_SLOT.end_of_insn_group = 1;
9405 fprintf (stderr, " Insn group break%s",
9406 (insert_stop ? " (w/stop)" : ""));
9408 fprintf (stderr, " effective for QP=%d", qp_regno);
9409 fprintf (stderr, "\n");
9413 while (i < regdepslen)
9415 const struct ia64_dependency *dep = regdeps[i].dependency;
9418 && regdeps[i].qp_regno != qp_regno)
9425 && CURR_SLOT.src_file == regdeps[i].file
9426 && CURR_SLOT.src_line == regdeps[i].line)
9432 /* clear dependencies which are automatically cleared by a stop, or
9433 those that have reached the appropriate state of insn serialization */
9434 if (dep->semantics == IA64_DVS_IMPLIED
9435 || dep->semantics == IA64_DVS_IMPLIEDF
9436 || regdeps[i].insn_srlz == STATE_SRLZ)
9438 print_dependency ("Removing", i);
9439 regdeps[i] = regdeps[--regdepslen];
9443 if (dep->semantics == IA64_DVS_DATA
9444 || dep->semantics == IA64_DVS_INSTR
9445 || dep->semantics == IA64_DVS_SPECIFIC)
9447 if (regdeps[i].insn_srlz == STATE_NONE)
9448 regdeps[i].insn_srlz = STATE_STOP;
9449 if (regdeps[i].data_srlz == STATE_NONE)
9450 regdeps[i].data_srlz = STATE_STOP;
9457 /* Add the given resource usage spec to the list of active dependencies. */
9460 mark_resource (idesc, dep, spec, depind, path)
9461 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9462 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9467 if (regdepslen == regdepstotlen)
9469 regdepstotlen += 20;
9470 regdeps = (struct rsrc *)
9471 xrealloc ((void *) regdeps,
9472 regdepstotlen * sizeof (struct rsrc));
9475 regdeps[regdepslen] = *spec;
9476 regdeps[regdepslen].depind = depind;
9477 regdeps[regdepslen].path = path;
9478 regdeps[regdepslen].file = CURR_SLOT.src_file;
9479 regdeps[regdepslen].line = CURR_SLOT.src_line;
9481 print_dependency ("Adding", regdepslen);
9487 print_dependency (action, depind)
9493 fprintf (stderr, " %s %s '%s'",
9494 action, dv_mode[(regdeps[depind].dependency)->mode],
9495 (regdeps[depind].dependency)->name);
9496 if (regdeps[depind].specific && regdeps[depind].index != 0)
9497 fprintf (stderr, " (%d)", regdeps[depind].index);
9498 if (regdeps[depind].mem_offset.hint)
9500 fputs (" ", stderr);
9501 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9502 fputs ("+", stderr);
9503 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9505 fprintf (stderr, "\n");
9510 instruction_serialization ()
9514 fprintf (stderr, " Instruction serialization\n");
9515 for (i = 0; i < regdepslen; i++)
9516 if (regdeps[i].insn_srlz == STATE_STOP)
9517 regdeps[i].insn_srlz = STATE_SRLZ;
9521 data_serialization ()
9525 fprintf (stderr, " Data serialization\n");
9526 while (i < regdepslen)
9528 if (regdeps[i].data_srlz == STATE_STOP
9529 /* Note: as of 991210, all "other" dependencies are cleared by a
9530 data serialization. This might change with new tables */
9531 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9533 print_dependency ("Removing", i);
9534 regdeps[i] = regdeps[--regdepslen];
9541 /* Insert stops and serializations as needed to avoid DVs. */
9544 remove_marked_resource (rs)
9547 switch (rs->dependency->semantics)
9549 case IA64_DVS_SPECIFIC:
9551 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9552 /* ...fall through... */
9553 case IA64_DVS_INSTR:
9555 fprintf (stderr, "Inserting instr serialization\n");
9556 if (rs->insn_srlz < STATE_STOP)
9557 insn_group_break (1, 0, 0);
9558 if (rs->insn_srlz < STATE_SRLZ)
9560 int oldqp = CURR_SLOT.qp_regno;
9561 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9562 /* Manually jam a srlz.i insn into the stream */
9563 CURR_SLOT.qp_regno = 0;
9564 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9565 instruction_serialization ();
9566 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9567 if (++md.num_slots_in_use >= NUM_SLOTS)
9569 CURR_SLOT.qp_regno = oldqp;
9570 CURR_SLOT.idesc = oldidesc;
9572 insn_group_break (1, 0, 0);
9574 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9575 "other" types of DV are eliminated
9576 by a data serialization */
9579 fprintf (stderr, "Inserting data serialization\n");
9580 if (rs->data_srlz < STATE_STOP)
9581 insn_group_break (1, 0, 0);
9583 int oldqp = CURR_SLOT.qp_regno;
9584 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9585 /* Manually jam a srlz.d insn into the stream */
9586 CURR_SLOT.qp_regno = 0;
9587 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9588 data_serialization ();
9589 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9590 if (++md.num_slots_in_use >= NUM_SLOTS)
9592 CURR_SLOT.qp_regno = oldqp;
9593 CURR_SLOT.idesc = oldidesc;
9596 case IA64_DVS_IMPLIED:
9597 case IA64_DVS_IMPLIEDF:
9599 fprintf (stderr, "Inserting stop\n");
9600 insn_group_break (1, 0, 0);
9607 /* Check the resources used by the given opcode against the current dependency
9610 The check is run once for each execution path encountered. In this case,
9611 a unique execution path is the sequence of instructions following a code
9612 entry point, e.g. the following has three execution paths, one starting
9613 at L0, one at L1, and one at L2.
9622 check_dependencies (idesc)
9623 struct ia64_opcode *idesc;
9625 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9629 /* Note that the number of marked resources may change within the
9630 loop if in auto mode. */
9632 while (i < regdepslen)
9634 struct rsrc *rs = ®deps[i];
9635 const struct ia64_dependency *dep = rs->dependency;
9640 if (dep->semantics == IA64_DVS_NONE
9641 || (chkind = depends_on (rs->depind, idesc)) == -1)
9647 note = NOTE (opdeps->chks[chkind]);
9649 /* Check this resource against each execution path seen thus far. */
9650 for (path = 0; path <= md.path; path++)
9654 /* If the dependency wasn't on the path being checked, ignore it. */
9655 if (rs->path < path)
9658 /* If the QP for this insn implies a QP which has branched, don't
9659 bother checking. Ed. NOTE: I don't think this check is terribly
9660 useful; what's the point of generating code which will only be
9661 reached if its QP is zero?
9662 This code was specifically inserted to handle the following code,
9663 based on notes from Intel's DV checking code, where p1 implies p2.
9669 if (CURR_SLOT.qp_regno != 0)
9673 for (implies = 0; implies < qp_implieslen; implies++)
9675 if (qp_implies[implies].path >= path
9676 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9677 && qp_implies[implies].p2_branched)
9687 if ((matchtype = resources_match (rs, idesc, note,
9688 CURR_SLOT.qp_regno, path)) != 0)
9691 char pathmsg[256] = "";
9692 char indexmsg[256] = "";
9693 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9696 sprintf (pathmsg, " when entry is at label '%s'",
9697 md.entry_labels[path - 1]);
9698 if (rs->specific && rs->index != 0)
9699 sprintf (indexmsg, ", specific resource number is %d",
9701 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9703 (certain ? "violates" : "may violate"),
9704 dv_mode[dep->mode], dep->name,
9705 dv_sem[dep->semantics],
9708 if (md.explicit_mode)
9710 as_warn ("%s", msg);
9712 as_warn (_("Only the first path encountering the conflict "
9714 as_warn_where (rs->file, rs->line,
9715 _("This is the location of the "
9716 "conflicting usage"));
9717 /* Don't bother checking other paths, to avoid duplicating
9724 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9726 remove_marked_resource (rs);
9728 /* since the set of dependencies has changed, start over */
9729 /* FIXME -- since we're removing dvs as we go, we
9730 probably don't really need to start over... */
9743 /* Register new dependencies based on the given opcode. */
9746 mark_resources (idesc)
9747 struct ia64_opcode *idesc;
9750 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9751 int add_only_qp_reads = 0;
9753 /* A conditional branch only uses its resources if it is taken; if it is
9754 taken, we stop following that path. The other branch types effectively
9755 *always* write their resources. If it's not taken, register only QP
9757 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9759 add_only_qp_reads = 1;
9763 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9765 for (i = 0; i < opdeps->nregs; i++)
9767 const struct ia64_dependency *dep;
9768 struct rsrc specs[MAX_SPECS];
9773 dep = ia64_find_dependency (opdeps->regs[i]);
9774 note = NOTE (opdeps->regs[i]);
9776 if (add_only_qp_reads
9777 && !(dep->mode == IA64_DV_WAR
9778 && (dep->specifier == IA64_RS_PR
9779 || dep->specifier == IA64_RS_PRr
9780 || dep->specifier == IA64_RS_PR63)))
9783 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9786 if (md.debug_dv && !count)
9787 fprintf (stderr, " No %s %s usage found (path %d)\n",
9788 dv_mode[dep->mode], dep->name, md.path);
9793 mark_resource (idesc, dep, &specs[count],
9794 DEP (opdeps->regs[i]), md.path);
9797 /* The execution path may affect register values, which may in turn
9798 affect which indirect-access resources are accessed. */
9799 switch (dep->specifier)
9811 for (path = 0; path < md.path; path++)
9813 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9815 mark_resource (idesc, dep, &specs[count],
9816 DEP (opdeps->regs[i]), path);
9823 /* Remove dependencies when they no longer apply. */
9826 update_dependencies (idesc)
9827 struct ia64_opcode *idesc;
9831 if (strcmp (idesc->name, "srlz.i") == 0)
9833 instruction_serialization ();
9835 else if (strcmp (idesc->name, "srlz.d") == 0)
9837 data_serialization ();
9839 else if (is_interruption_or_rfi (idesc)
9840 || is_taken_branch (idesc))
9842 /* Although technically the taken branch doesn't clear dependencies
9843 which require a srlz.[id], we don't follow the branch; the next
9844 instruction is assumed to start with a clean slate. */
9848 else if (is_conditional_branch (idesc)
9849 && CURR_SLOT.qp_regno != 0)
9851 int is_call = strstr (idesc->name, ".call") != NULL;
9853 for (i = 0; i < qp_implieslen; i++)
9855 /* If the conditional branch's predicate is implied by the predicate
9856 in an existing dependency, remove that dependency. */
9857 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9860 /* Note that this implied predicate takes a branch so that if
9861 a later insn generates a DV but its predicate implies this
9862 one, we can avoid the false DV warning. */
9863 qp_implies[i].p2_branched = 1;
9864 while (depind < regdepslen)
9866 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9868 print_dependency ("Removing", depind);
9869 regdeps[depind] = regdeps[--regdepslen];
9876 /* Any marked resources which have this same predicate should be
9877 cleared, provided that the QP hasn't been modified between the
9878 marking instruction and the branch. */
9881 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9886 while (i < regdepslen)
9888 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9889 && regdeps[i].link_to_qp_branch
9890 && (regdeps[i].file != CURR_SLOT.src_file
9891 || regdeps[i].line != CURR_SLOT.src_line))
9893 /* Treat like a taken branch */
9894 print_dependency ("Removing", i);
9895 regdeps[i] = regdeps[--regdepslen];
9904 /* Examine the current instruction for dependency violations. */
9908 struct ia64_opcode *idesc;
9912 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9913 idesc->name, CURR_SLOT.src_line,
9914 idesc->dependencies->nchks,
9915 idesc->dependencies->nregs);
9918 /* Look through the list of currently marked resources; if the current
9919 instruction has the dependency in its chks list which uses that resource,
9920 check against the specific resources used. */
9921 check_dependencies (idesc);
9923 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9924 then add them to the list of marked resources. */
9925 mark_resources (idesc);
9927 /* There are several types of dependency semantics, and each has its own
9928 requirements for being cleared
9930 Instruction serialization (insns separated by interruption, rfi, or
9931 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9933 Data serialization (instruction serialization, or writer + srlz.d +
9934 reader, where writer and srlz.d are in separate groups) clears
9935 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9936 always be the case).
9938 Instruction group break (groups separated by stop, taken branch,
9939 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9941 update_dependencies (idesc);
9943 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9944 warning. Keep track of as many as possible that are useful. */
9945 note_register_values (idesc);
9947 /* We don't need or want this anymore. */
9948 md.mem_offset.hint = 0;
9953 /* Translate one line of assembly. Pseudo ops and labels do not show
9959 char *saved_input_line_pointer, *mnemonic;
9960 const struct pseudo_opcode *pdesc;
9961 struct ia64_opcode *idesc;
9962 unsigned char qp_regno;
9966 saved_input_line_pointer = input_line_pointer;
9967 input_line_pointer = str;
9969 /* extract the opcode (mnemonic): */
9971 mnemonic = input_line_pointer;
9972 ch = get_symbol_end ();
9973 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9976 *input_line_pointer = ch;
9977 (*pdesc->handler) (pdesc->arg);
9981 /* Find the instruction descriptor matching the arguments. */
9983 idesc = ia64_find_opcode (mnemonic);
9984 *input_line_pointer = ch;
9987 as_bad ("Unknown opcode `%s'", mnemonic);
9991 idesc = parse_operands (idesc);
9995 /* Handle the dynamic ops we can handle now: */
9996 if (idesc->type == IA64_TYPE_DYN)
9998 if (strcmp (idesc->name, "add") == 0)
10000 if (CURR_SLOT.opnd[2].X_op == O_register
10001 && CURR_SLOT.opnd[2].X_add_number < 4)
10005 ia64_free_opcode (idesc);
10006 idesc = ia64_find_opcode (mnemonic);
10008 know (!idesc->next);
10011 else if (strcmp (idesc->name, "mov") == 0)
10013 enum ia64_opnd opnd1, opnd2;
10016 opnd1 = idesc->operands[0];
10017 opnd2 = idesc->operands[1];
10018 if (opnd1 == IA64_OPND_AR3)
10020 else if (opnd2 == IA64_OPND_AR3)
10024 if (CURR_SLOT.opnd[rop].X_op == O_register
10025 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10026 mnemonic = "mov.i";
10028 mnemonic = "mov.m";
10029 ia64_free_opcode (idesc);
10030 idesc = ia64_find_opcode (mnemonic);
10031 while (idesc != NULL
10032 && (idesc->operands[0] != opnd1
10033 || idesc->operands[1] != opnd2))
10034 idesc = get_next_opcode (idesc);
10039 if (md.qp.X_op == O_register)
10041 qp_regno = md.qp.X_add_number - REG_P;
10042 md.qp.X_op = O_absent;
10045 flags = idesc->flags;
10047 if ((flags & IA64_OPCODE_FIRST) != 0)
10049 /* The alignment frag has to end with a stop bit only if the
10050 next instruction after the alignment directive has to be
10051 the first instruction in an instruction group. */
10054 while (align_frag->fr_type != rs_align_code)
10056 align_frag = align_frag->fr_next;
10060 /* align_frag can be NULL if there are directives in
10062 if (align_frag && align_frag->fr_next == frag_now)
10063 align_frag->tc_frag_data = 1;
10066 insn_group_break (1, 0, 0);
10070 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10072 as_bad ("`%s' cannot be predicated", idesc->name);
10076 /* Build the instruction. */
10077 CURR_SLOT.qp_regno = qp_regno;
10078 CURR_SLOT.idesc = idesc;
10079 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10080 dwarf2_where (&CURR_SLOT.debug_line);
10082 /* Add unwind entry, if there is one. */
10083 if (unwind.current_entry)
10085 CURR_SLOT.unwind_record = unwind.current_entry;
10086 unwind.current_entry = NULL;
10089 /* Check for dependency violations. */
10093 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10094 if (++md.num_slots_in_use >= NUM_SLOTS)
10095 emit_one_bundle ();
10097 if ((flags & IA64_OPCODE_LAST) != 0)
10098 insn_group_break (1, 0, 0);
10100 md.last_text_seg = now_seg;
10103 input_line_pointer = saved_input_line_pointer;
10106 /* Called when symbol NAME cannot be found in the symbol table.
10107 Should be used for dynamic valued symbols only. */
10110 md_undefined_symbol (name)
10111 char *name ATTRIBUTE_UNUSED;
10116 /* Called for any expression that can not be recognized. When the
10117 function is called, `input_line_pointer' will point to the start of
10124 enum pseudo_type pseudo_type;
10129 switch (*input_line_pointer)
10132 /* Find what relocation pseudo-function we're dealing with. */
10134 ch = *++input_line_pointer;
10135 for (i = 0; i < NELEMS (pseudo_func); ++i)
10136 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
10138 len = strlen (pseudo_func[i].name);
10139 if (strncmp (pseudo_func[i].name + 1,
10140 input_line_pointer + 1, len - 1) == 0
10141 && !is_part_of_name (input_line_pointer[len]))
10143 input_line_pointer += len;
10144 pseudo_type = pseudo_func[i].type;
10148 switch (pseudo_type)
10150 case PSEUDO_FUNC_RELOC:
10151 SKIP_WHITESPACE ();
10152 if (*input_line_pointer != '(')
10154 as_bad ("Expected '('");
10158 ++input_line_pointer;
10160 if (*input_line_pointer++ != ')')
10162 as_bad ("Missing ')'");
10165 if (e->X_op != O_symbol)
10167 if (e->X_op != O_pseudo_fixup)
10169 as_bad ("Not a symbolic expression");
10172 if (i != FUNC_LT_RELATIVE)
10174 as_bad ("Illegal combination of relocation functions");
10177 switch (S_GET_VALUE (e->X_op_symbol))
10179 case FUNC_FPTR_RELATIVE:
10180 i = FUNC_LT_FPTR_RELATIVE; break;
10181 case FUNC_DTP_MODULE:
10182 i = FUNC_LT_DTP_MODULE; break;
10183 case FUNC_DTP_RELATIVE:
10184 i = FUNC_LT_DTP_RELATIVE; break;
10185 case FUNC_TP_RELATIVE:
10186 i = FUNC_LT_TP_RELATIVE; break;
10188 as_bad ("Illegal combination of relocation functions");
10192 /* Make sure gas doesn't get rid of local symbols that are used
10194 e->X_op = O_pseudo_fixup;
10195 e->X_op_symbol = pseudo_func[i].u.sym;
10198 case PSEUDO_FUNC_CONST:
10199 e->X_op = O_constant;
10200 e->X_add_number = pseudo_func[i].u.ival;
10203 case PSEUDO_FUNC_REG:
10204 e->X_op = O_register;
10205 e->X_add_number = pseudo_func[i].u.ival;
10209 name = input_line_pointer - 1;
10211 as_bad ("Unknown pseudo function `%s'", name);
10217 ++input_line_pointer;
10219 if (*input_line_pointer != ']')
10221 as_bad ("Closing bracket misssing");
10226 if (e->X_op != O_register)
10227 as_bad ("Register expected as index");
10229 ++input_line_pointer;
10240 ignore_rest_of_line ();
10243 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10244 a section symbol plus some offset. For relocs involving @fptr(),
10245 directives we don't want such adjustments since we need to have the
10246 original symbol's name in the reloc. */
10248 ia64_fix_adjustable (fix)
10251 /* Prevent all adjustments to global symbols */
10252 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10255 switch (fix->fx_r_type)
10257 case BFD_RELOC_IA64_FPTR64I:
10258 case BFD_RELOC_IA64_FPTR32MSB:
10259 case BFD_RELOC_IA64_FPTR32LSB:
10260 case BFD_RELOC_IA64_FPTR64MSB:
10261 case BFD_RELOC_IA64_FPTR64LSB:
10262 case BFD_RELOC_IA64_LTOFF_FPTR22:
10263 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10273 ia64_force_relocation (fix)
10276 switch (fix->fx_r_type)
10278 case BFD_RELOC_IA64_FPTR64I:
10279 case BFD_RELOC_IA64_FPTR32MSB:
10280 case BFD_RELOC_IA64_FPTR32LSB:
10281 case BFD_RELOC_IA64_FPTR64MSB:
10282 case BFD_RELOC_IA64_FPTR64LSB:
10284 case BFD_RELOC_IA64_LTOFF22:
10285 case BFD_RELOC_IA64_LTOFF64I:
10286 case BFD_RELOC_IA64_LTOFF_FPTR22:
10287 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10288 case BFD_RELOC_IA64_PLTOFF22:
10289 case BFD_RELOC_IA64_PLTOFF64I:
10290 case BFD_RELOC_IA64_PLTOFF64MSB:
10291 case BFD_RELOC_IA64_PLTOFF64LSB:
10293 case BFD_RELOC_IA64_LTOFF22X:
10294 case BFD_RELOC_IA64_LDXMOV:
10301 return generic_force_reloc (fix);
10304 /* Decide from what point a pc-relative relocation is relative to,
10305 relative to the pc-relative fixup. Er, relatively speaking. */
10307 ia64_pcrel_from_section (fix, sec)
10311 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10313 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10320 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10322 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10326 expr.X_op = O_pseudo_fixup;
10327 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10328 expr.X_add_number = 0;
10329 expr.X_add_symbol = symbol;
10330 emit_expr (&expr, size);
10333 /* This is called whenever some data item (not an instruction) needs a
10334 fixup. We pick the right reloc code depending on the byteorder
10335 currently in effect. */
10337 ia64_cons_fix_new (f, where, nbytes, exp)
10343 bfd_reloc_code_real_type code;
10348 /* There are no reloc for 8 and 16 bit quantities, but we allow
10349 them here since they will work fine as long as the expression
10350 is fully defined at the end of the pass over the source file. */
10351 case 1: code = BFD_RELOC_8; break;
10352 case 2: code = BFD_RELOC_16; break;
10354 if (target_big_endian)
10355 code = BFD_RELOC_IA64_DIR32MSB;
10357 code = BFD_RELOC_IA64_DIR32LSB;
10361 /* In 32-bit mode, data8 could mean function descriptors too. */
10362 if (exp->X_op == O_pseudo_fixup
10363 && exp->X_op_symbol
10364 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10365 && !(md.flags & EF_IA_64_ABI64))
10367 if (target_big_endian)
10368 code = BFD_RELOC_IA64_IPLTMSB;
10370 code = BFD_RELOC_IA64_IPLTLSB;
10371 exp->X_op = O_symbol;
10376 if (target_big_endian)
10377 code = BFD_RELOC_IA64_DIR64MSB;
10379 code = BFD_RELOC_IA64_DIR64LSB;
10384 if (exp->X_op == O_pseudo_fixup
10385 && exp->X_op_symbol
10386 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10388 if (target_big_endian)
10389 code = BFD_RELOC_IA64_IPLTMSB;
10391 code = BFD_RELOC_IA64_IPLTLSB;
10392 exp->X_op = O_symbol;
10398 as_bad ("Unsupported fixup size %d", nbytes);
10399 ignore_rest_of_line ();
10403 if (exp->X_op == O_pseudo_fixup)
10405 exp->X_op = O_symbol;
10406 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10407 /* ??? If code unchanged, unsupported. */
10410 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10411 /* We need to store the byte order in effect in case we're going
10412 to fix an 8 or 16 bit relocation (for which there no real
10413 relocs available). See md_apply_fix3(). */
10414 fix->tc_fix_data.bigendian = target_big_endian;
10417 /* Return the actual relocation we wish to associate with the pseudo
10418 reloc described by SYM and R_TYPE. SYM should be one of the
10419 symbols in the pseudo_func array, or NULL. */
10421 static bfd_reloc_code_real_type
10422 ia64_gen_real_reloc_type (sym, r_type)
10423 struct symbol *sym;
10424 bfd_reloc_code_real_type r_type;
10426 bfd_reloc_code_real_type new = 0;
10433 switch (S_GET_VALUE (sym))
10435 case FUNC_FPTR_RELATIVE:
10438 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10439 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10440 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10441 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10442 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10447 case FUNC_GP_RELATIVE:
10450 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10451 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10452 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10453 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10454 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10455 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10460 case FUNC_LT_RELATIVE:
10463 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10464 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10469 case FUNC_LT_RELATIVE_X:
10472 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10477 case FUNC_PC_RELATIVE:
10480 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10481 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10482 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10483 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10484 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10485 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10490 case FUNC_PLT_RELATIVE:
10493 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10494 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10495 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10496 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10501 case FUNC_SEC_RELATIVE:
10504 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10505 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10506 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10507 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10512 case FUNC_SEG_RELATIVE:
10515 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10516 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10517 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10518 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10523 case FUNC_LTV_RELATIVE:
10526 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10527 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10528 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10529 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10534 case FUNC_LT_FPTR_RELATIVE:
10537 case BFD_RELOC_IA64_IMM22:
10538 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10539 case BFD_RELOC_IA64_IMM64:
10540 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10546 case FUNC_TP_RELATIVE:
10549 case BFD_RELOC_IA64_IMM14:
10550 new = BFD_RELOC_IA64_TPREL14; break;
10551 case BFD_RELOC_IA64_IMM22:
10552 new = BFD_RELOC_IA64_TPREL22; break;
10553 case BFD_RELOC_IA64_IMM64:
10554 new = BFD_RELOC_IA64_TPREL64I; break;
10560 case FUNC_LT_TP_RELATIVE:
10563 case BFD_RELOC_IA64_IMM22:
10564 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10570 case FUNC_LT_DTP_MODULE:
10573 case BFD_RELOC_IA64_IMM22:
10574 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10580 case FUNC_DTP_RELATIVE:
10583 case BFD_RELOC_IA64_DIR64MSB:
10584 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10585 case BFD_RELOC_IA64_DIR64LSB:
10586 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10587 case BFD_RELOC_IA64_IMM14:
10588 new = BFD_RELOC_IA64_DTPREL14; break;
10589 case BFD_RELOC_IA64_IMM22:
10590 new = BFD_RELOC_IA64_DTPREL22; break;
10591 case BFD_RELOC_IA64_IMM64:
10592 new = BFD_RELOC_IA64_DTPREL64I; break;
10598 case FUNC_LT_DTP_RELATIVE:
10601 case BFD_RELOC_IA64_IMM22:
10602 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10608 case FUNC_IPLT_RELOC:
10615 /* Hmmmm. Should this ever occur? */
10622 /* Here is where generate the appropriate reloc for pseudo relocation
10625 ia64_validate_fix (fix)
10628 switch (fix->fx_r_type)
10630 case BFD_RELOC_IA64_FPTR64I:
10631 case BFD_RELOC_IA64_FPTR32MSB:
10632 case BFD_RELOC_IA64_FPTR64LSB:
10633 case BFD_RELOC_IA64_LTOFF_FPTR22:
10634 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10635 if (fix->fx_offset != 0)
10636 as_bad_where (fix->fx_file, fix->fx_line,
10637 "No addend allowed in @fptr() relocation");
10645 fix_insn (fix, odesc, value)
10647 const struct ia64_operand *odesc;
10650 bfd_vma insn[3], t0, t1, control_bits;
10655 slot = fix->fx_where & 0x3;
10656 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10658 /* Bundles are always in little-endian byte order */
10659 t0 = bfd_getl64 (fixpos);
10660 t1 = bfd_getl64 (fixpos + 8);
10661 control_bits = t0 & 0x1f;
10662 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10663 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10664 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10667 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10669 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10670 insn[2] |= (((value & 0x7f) << 13)
10671 | (((value >> 7) & 0x1ff) << 27)
10672 | (((value >> 16) & 0x1f) << 22)
10673 | (((value >> 21) & 0x1) << 21)
10674 | (((value >> 63) & 0x1) << 36));
10676 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10678 if (value & ~0x3fffffffffffffffULL)
10679 err = "integer operand out of range";
10680 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10681 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10683 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10686 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10687 insn[2] |= ((((value >> 59) & 0x1) << 36)
10688 | (((value >> 0) & 0xfffff) << 13));
10691 err = (*odesc->insert) (odesc, value, insn + slot);
10694 as_bad_where (fix->fx_file, fix->fx_line, err);
10696 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10697 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10698 number_to_chars_littleendian (fixpos + 0, t0, 8);
10699 number_to_chars_littleendian (fixpos + 8, t1, 8);
10702 /* Attempt to simplify or even eliminate a fixup. The return value is
10703 ignored; perhaps it was once meaningful, but now it is historical.
10704 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10706 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10710 md_apply_fix3 (fix, valP, seg)
10713 segT seg ATTRIBUTE_UNUSED;
10716 valueT value = *valP;
10718 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10722 switch (fix->fx_r_type)
10724 case BFD_RELOC_IA64_DIR32MSB:
10725 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10728 case BFD_RELOC_IA64_DIR32LSB:
10729 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10732 case BFD_RELOC_IA64_DIR64MSB:
10733 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10736 case BFD_RELOC_IA64_DIR64LSB:
10737 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10746 switch (fix->fx_r_type)
10748 case BFD_RELOC_UNUSED:
10749 /* This must be a TAG13 or TAG13b operand. There are no external
10750 relocs defined for them, so we must give an error. */
10751 as_bad_where (fix->fx_file, fix->fx_line,
10752 "%s must have a constant value",
10753 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10757 case BFD_RELOC_IA64_TPREL14:
10758 case BFD_RELOC_IA64_TPREL22:
10759 case BFD_RELOC_IA64_TPREL64I:
10760 case BFD_RELOC_IA64_LTOFF_TPREL22:
10761 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10762 case BFD_RELOC_IA64_DTPREL14:
10763 case BFD_RELOC_IA64_DTPREL22:
10764 case BFD_RELOC_IA64_DTPREL64I:
10765 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10766 S_SET_THREAD_LOCAL (fix->fx_addsy);
10773 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10775 if (fix->tc_fix_data.bigendian)
10776 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10778 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10783 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10788 /* Generate the BFD reloc to be stuck in the object file from the
10789 fixup used internally in the assembler. */
10792 tc_gen_reloc (sec, fixp)
10793 asection *sec ATTRIBUTE_UNUSED;
10798 reloc = xmalloc (sizeof (*reloc));
10799 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10800 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10801 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10802 reloc->addend = fixp->fx_offset;
10803 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10807 as_bad_where (fixp->fx_file, fixp->fx_line,
10808 "Cannot represent %s relocation in object file",
10809 bfd_get_reloc_code_name (fixp->fx_r_type));
10814 /* Turn a string in input_line_pointer into a floating point constant
10815 of type TYPE, and store the appropriate bytes in *LIT. The number
10816 of LITTLENUMS emitted is stored in *SIZE. An error message is
10817 returned, or NULL on OK. */
10819 #define MAX_LITTLENUMS 5
10822 md_atof (type, lit, size)
10827 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10857 return "Bad call to MD_ATOF()";
10859 t = atof_ieee (input_line_pointer, type, words);
10861 input_line_pointer = t;
10863 (*ia64_float_to_chars) (lit, words, prec);
10867 /* It is 10 byte floating point with 6 byte padding. */
10868 memset (&lit [10], 0, 6);
10869 *size = 8 * sizeof (LITTLENUM_TYPE);
10872 *size = prec * sizeof (LITTLENUM_TYPE);
10877 /* Handle ia64 specific semantics of the align directive. */
10880 ia64_md_do_align (n, fill, len, max)
10881 int n ATTRIBUTE_UNUSED;
10882 const char *fill ATTRIBUTE_UNUSED;
10883 int len ATTRIBUTE_UNUSED;
10884 int max ATTRIBUTE_UNUSED;
10886 if (subseg_text_p (now_seg))
10887 ia64_flush_insns ();
10890 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10891 of an rs_align_code fragment. */
10894 ia64_handle_align (fragp)
10897 /* Use mfi bundle of nops with no stop bits. */
10898 static const unsigned char le_nop[]
10899 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10900 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10901 static const unsigned char le_nop_stop[]
10902 = { 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10903 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10907 const unsigned char *nop;
10909 if (fragp->fr_type != rs_align_code)
10912 /* Check if this frag has to end with a stop bit. */
10913 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
10915 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10916 p = fragp->fr_literal + fragp->fr_fix;
10918 /* If no paddings are needed, we check if we need a stop bit. */
10919 if (!bytes && fragp->tc_frag_data)
10921 if (fragp->fr_fix < 16)
10923 /* FIXME: It won't work with
10925 alloc r32=ar.pfs,1,2,4,0
10929 as_bad_where (fragp->fr_file, fragp->fr_line,
10930 _("Can't add stop bit to mark end of instruction group"));
10933 /* Bundles are always in little-endian byte order. Make sure
10934 the previous bundle has the stop bit. */
10938 /* Make sure we are on a 16-byte boundary, in case someone has been
10939 putting data into a text section. */
10942 int fix = bytes & 15;
10943 memset (p, 0, fix);
10946 fragp->fr_fix += fix;
10949 /* Instruction bundles are always little-endian. */
10950 memcpy (p, nop, 16);
10951 fragp->fr_var = 16;
10955 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
10960 number_to_chars_bigendian (lit, (long) (*words++),
10961 sizeof (LITTLENUM_TYPE));
10962 lit += sizeof (LITTLENUM_TYPE);
10967 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
10972 number_to_chars_littleendian (lit, (long) (words[prec]),
10973 sizeof (LITTLENUM_TYPE));
10974 lit += sizeof (LITTLENUM_TYPE);
10979 ia64_elf_section_change_hook (void)
10981 dot_byteorder (-1);
10984 /* Check if a label should be made global. */
10986 ia64_check_label (symbolS *label)
10988 if (*input_line_pointer == ':')
10990 S_SET_EXTERNAL (label);
10991 input_line_pointer++;
10995 /* Used to remember where .alias and .secalias directives are seen. We
10996 will rename symbol and section names when we are about to output
10997 the relocatable file. */
11000 char *file; /* The file where the directive is seen. */
11001 unsigned int line; /* The line number the directive is at. */
11002 const char *name; /* The orignale name of the symbol. */
11005 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11006 .secalias. Otherwise, it is .alias. */
11008 dot_alias (int section)
11010 char *name, *alias;
11014 const char *error_string;
11017 struct hash_control *ahash, *nhash;
11020 name = input_line_pointer;
11021 delim = get_symbol_end ();
11022 end_name = input_line_pointer;
11025 if (name == end_name)
11027 as_bad (_("expected symbol name"));
11028 discard_rest_of_line ();
11032 SKIP_WHITESPACE ();
11034 if (*input_line_pointer != ',')
11037 as_bad (_("expected comma after \"%s\""), name);
11039 ignore_rest_of_line ();
11043 input_line_pointer++;
11046 /* We call demand_copy_C_string to check if alias string is valid.
11047 There should be a closing `"' and no `\0' in the string. */
11048 alias = demand_copy_C_string (&len);
11051 ignore_rest_of_line ();
11055 /* Make a copy of name string. */
11056 len = strlen (name) + 1;
11057 obstack_grow (¬es, name, len);
11058 name = obstack_finish (¬es);
11063 ahash = secalias_hash;
11064 nhash = secalias_name_hash;
11069 ahash = alias_hash;
11070 nhash = alias_name_hash;
11073 /* Check if alias has been used before. */
11074 h = (struct alias *) hash_find (ahash, alias);
11077 if (strcmp (h->name, name))
11078 as_bad (_("`%s' is already the alias of %s `%s'"),
11079 alias, kind, h->name);
11083 /* Check if name already has an alias. */
11084 a = (const char *) hash_find (nhash, name);
11087 if (strcmp (a, alias))
11088 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11092 h = (struct alias *) xmalloc (sizeof (struct alias));
11093 as_where (&h->file, &h->line);
11096 error_string = hash_jam (ahash, alias, (PTR) h);
11099 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11100 alias, kind, error_string);
11104 error_string = hash_jam (nhash, name, (PTR) alias);
11107 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11108 alias, kind, error_string);
11110 obstack_free (¬es, name);
11111 obstack_free (¬es, alias);
11114 demand_empty_rest_of_line ();
11117 /* It renames the original symbol name to its alias. */
11119 do_alias (const char *alias, PTR value)
11121 struct alias *h = (struct alias *) value;
11122 symbolS *sym = symbol_find (h->name);
11125 as_warn_where (h->file, h->line,
11126 _("symbol `%s' aliased to `%s' is not used"),
11129 S_SET_NAME (sym, (char *) alias);
11132 /* Called from write_object_file. */
11134 ia64_adjust_symtab (void)
11136 hash_traverse (alias_hash, do_alias);
11139 /* It renames the original section name to its alias. */
11141 do_secalias (const char *alias, PTR value)
11143 struct alias *h = (struct alias *) value;
11144 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11147 as_warn_where (h->file, h->line,
11148 _("section `%s' aliased to `%s' is not used"),
11154 /* Called from write_object_file. */
11156 ia64_frob_file (void)
11158 hash_traverse (secalias_hash, do_secalias);