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 static char *special_linkonce_name[] =
576 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
579 /* The best template for a particular sequence of up to three
581 #define N IA64_NUM_TYPES
582 static unsigned char best_template[N][N][N];
585 /* Resource dependencies currently in effect */
587 int depind; /* dependency index */
588 const struct ia64_dependency *dependency; /* actual dependency */
589 unsigned specific:1, /* is this a specific bit/regno? */
590 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
591 int index; /* specific regno/bit within dependency */
592 int note; /* optional qualifying note (0 if none) */
596 int insn_srlz; /* current insn serialization state */
597 int data_srlz; /* current data serialization state */
598 int qp_regno; /* qualifying predicate for this usage */
599 char *file; /* what file marked this dependency */
600 unsigned int line; /* what line marked this dependency */
601 struct mem_offset mem_offset; /* optional memory offset hint */
602 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
603 int path; /* corresponding code entry index */
605 static int regdepslen = 0;
606 static int regdepstotlen = 0;
607 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
608 static const char *dv_sem[] = { "none", "implied", "impliedf",
609 "data", "instr", "specific", "stop", "other" };
610 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
612 /* Current state of PR mutexation */
613 static struct qpmutex {
616 } *qp_mutexes = NULL; /* QP mutex bitmasks */
617 static int qp_mutexeslen = 0;
618 static int qp_mutexestotlen = 0;
619 static valueT qp_safe_across_calls = 0;
621 /* Current state of PR implications */
622 static struct qp_imply {
625 unsigned p2_branched:1;
627 } *qp_implies = NULL;
628 static int qp_implieslen = 0;
629 static int qp_impliestotlen = 0;
631 /* Keep track of static GR values so that indirect register usage can
632 sometimes be tracked. */
637 } gr_values[128] = {{ 1, 0, 0 }};
639 /* Remember the alignment frag. */
640 static fragS *align_frag;
642 /* These are the routines required to output the various types of
645 /* A slot_number is a frag address plus the slot index (0-2). We use the
646 frag address here so that if there is a section switch in the middle of
647 a function, then instructions emitted to a different section are not
648 counted. Since there may be more than one frag for a function, this
649 means we also need to keep track of which frag this address belongs to
650 so we can compute inter-frag distances. This also nicely solves the
651 problem with nops emitted for align directives, which can't easily be
652 counted, but can easily be derived from frag sizes. */
654 typedef struct unw_rec_list {
656 unsigned long slot_number;
658 unsigned long next_slot_number;
659 fragS *next_slot_frag;
660 struct unw_rec_list *next;
663 #define SLOT_NUM_NOT_SET (unsigned)-1
665 /* Linked list of saved prologue counts. A very poor
666 implementation of a map from label numbers to prologue counts. */
667 typedef struct label_prologue_count
669 struct label_prologue_count *next;
670 unsigned long label_number;
671 unsigned int prologue_count;
672 } label_prologue_count;
676 /* Maintain a list of unwind entries for the current function. */
680 /* Any unwind entires that should be attached to the current slot
681 that an insn is being constructed for. */
682 unw_rec_list *current_entry;
684 /* These are used to create the unwind table entry for this function. */
687 symbolS *info; /* pointer to unwind info */
688 symbolS *personality_routine;
690 subsegT saved_text_subseg;
691 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
693 /* TRUE if processing unwind directives in a prologue region. */
696 unsigned int prologue_count; /* number of .prologues seen so far */
697 /* Prologue counts at previous .label_state directives. */
698 struct label_prologue_count * saved_prologue_counts;
701 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
703 /* Forward declarations: */
704 static int ar_is_in_integer_unit PARAMS ((int regnum));
705 static void set_section PARAMS ((char *name));
706 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
707 unsigned int, unsigned int));
708 static void dot_radix PARAMS ((int));
709 static void dot_special_section PARAMS ((int));
710 static void dot_proc PARAMS ((int));
711 static void dot_fframe PARAMS ((int));
712 static void dot_vframe PARAMS ((int));
713 static void dot_vframesp PARAMS ((int));
714 static void dot_vframepsp PARAMS ((int));
715 static void dot_save PARAMS ((int));
716 static void dot_restore PARAMS ((int));
717 static void dot_restorereg PARAMS ((int));
718 static void dot_restorereg_p PARAMS ((int));
719 static void dot_handlerdata PARAMS ((int));
720 static void dot_unwentry PARAMS ((int));
721 static void dot_altrp PARAMS ((int));
722 static void dot_savemem PARAMS ((int));
723 static void dot_saveg PARAMS ((int));
724 static void dot_savef PARAMS ((int));
725 static void dot_saveb PARAMS ((int));
726 static void dot_savegf PARAMS ((int));
727 static void dot_spill PARAMS ((int));
728 static void dot_spillreg PARAMS ((int));
729 static void dot_spillmem PARAMS ((int));
730 static void dot_spillreg_p PARAMS ((int));
731 static void dot_spillmem_p PARAMS ((int));
732 static void dot_label_state PARAMS ((int));
733 static void dot_copy_state PARAMS ((int));
734 static void dot_unwabi PARAMS ((int));
735 static void dot_personality PARAMS ((int));
736 static void dot_body PARAMS ((int));
737 static void dot_prologue PARAMS ((int));
738 static void dot_endp PARAMS ((int));
739 static void dot_template PARAMS ((int));
740 static void dot_regstk PARAMS ((int));
741 static void dot_rot PARAMS ((int));
742 static void dot_byteorder PARAMS ((int));
743 static void dot_psr PARAMS ((int));
744 static void dot_alias PARAMS ((int));
745 static void dot_ln PARAMS ((int));
746 static char *parse_section_name PARAMS ((void));
747 static void dot_xdata PARAMS ((int));
748 static void stmt_float_cons PARAMS ((int));
749 static void stmt_cons_ua PARAMS ((int));
750 static void dot_xfloat_cons PARAMS ((int));
751 static void dot_xstringer PARAMS ((int));
752 static void dot_xdata_ua PARAMS ((int));
753 static void dot_xfloat_cons_ua PARAMS ((int));
754 static void print_prmask PARAMS ((valueT mask));
755 static void dot_pred_rel PARAMS ((int));
756 static void dot_reg_val PARAMS ((int));
757 static void dot_dv_mode PARAMS ((int));
758 static void dot_entry PARAMS ((int));
759 static void dot_mem_offset PARAMS ((int));
760 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
761 static symbolS *declare_register PARAMS ((const char *name, int regnum));
762 static void declare_register_set PARAMS ((const char *, int, int));
763 static unsigned int operand_width PARAMS ((enum ia64_opnd));
764 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
767 static int parse_operand PARAMS ((expressionS *e));
768 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
769 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
770 static void build_insn PARAMS ((struct slot *, bfd_vma *));
771 static void emit_one_bundle PARAMS ((void));
772 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
773 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
774 bfd_reloc_code_real_type r_type));
775 static void insn_group_break PARAMS ((int, int, int));
776 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
777 struct rsrc *, int depind, int path));
778 static void add_qp_mutex PARAMS((valueT mask));
779 static void add_qp_imply PARAMS((int p1, int p2));
780 static void clear_qp_branch_flag PARAMS((valueT mask));
781 static void clear_qp_mutex PARAMS((valueT mask));
782 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
783 static int has_suffix_p PARAMS((const char *, const char *));
784 static void clear_register_values PARAMS ((void));
785 static void print_dependency PARAMS ((const char *action, int depind));
786 static void instruction_serialization PARAMS ((void));
787 static void data_serialization PARAMS ((void));
788 static void remove_marked_resource PARAMS ((struct rsrc *));
789 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
790 static int is_taken_branch PARAMS ((struct ia64_opcode *));
791 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
792 static int depends_on PARAMS ((int, struct ia64_opcode *));
793 static int specify_resource PARAMS ((const struct ia64_dependency *,
794 struct ia64_opcode *, int, struct rsrc [], int, int));
795 static int check_dv PARAMS((struct ia64_opcode *idesc));
796 static void check_dependencies PARAMS((struct ia64_opcode *));
797 static void mark_resources PARAMS((struct ia64_opcode *));
798 static void update_dependencies PARAMS((struct ia64_opcode *));
799 static void note_register_values PARAMS((struct ia64_opcode *));
800 static int qp_mutex PARAMS ((int, int, int));
801 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
802 static void output_vbyte_mem PARAMS ((int, char *, char *));
803 static void count_output PARAMS ((int, char *, char *));
804 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
805 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
806 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
807 static void output_P1_format PARAMS ((vbyte_func, int));
808 static void output_P2_format PARAMS ((vbyte_func, int, int));
809 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
810 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
811 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
812 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
813 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
814 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
815 static void output_P9_format PARAMS ((vbyte_func, int, int));
816 static void output_P10_format PARAMS ((vbyte_func, int, int));
817 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
818 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
819 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
820 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
821 static char format_ab_reg PARAMS ((int, int));
822 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
824 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
825 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
827 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
828 static unw_rec_list *output_endp PARAMS ((void));
829 static unw_rec_list *output_prologue PARAMS ((void));
830 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
831 static unw_rec_list *output_body PARAMS ((void));
832 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
833 static unw_rec_list *output_mem_stack_v PARAMS ((void));
834 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
835 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
836 static unw_rec_list *output_rp_when PARAMS ((void));
837 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
838 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
839 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
840 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
841 static unw_rec_list *output_pfs_when PARAMS ((void));
842 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
843 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
844 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
845 static unw_rec_list *output_preds_when PARAMS ((void));
846 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
847 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
848 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
849 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
850 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
851 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
852 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
853 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
854 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
855 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
856 static unw_rec_list *output_unat_when PARAMS ((void));
857 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
858 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
859 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
860 static unw_rec_list *output_lc_when PARAMS ((void));
861 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
862 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
863 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
864 static unw_rec_list *output_fpsr_when PARAMS ((void));
865 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
866 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
867 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
868 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
869 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
870 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
871 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
872 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
873 static unw_rec_list *output_bsp_when PARAMS ((void));
874 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
875 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
876 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
877 static unw_rec_list *output_bspstore_when PARAMS ((void));
878 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
879 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
880 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
881 static unw_rec_list *output_rnat_when PARAMS ((void));
882 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
883 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
884 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
885 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
886 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
887 static unw_rec_list *output_label_state PARAMS ((unsigned long));
888 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
889 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
890 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
891 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
893 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
895 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
897 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
898 unsigned int, unsigned int));
899 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
900 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
901 static int calc_record_size PARAMS ((unw_rec_list *));
902 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
903 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
904 unsigned long, fragS *,
906 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
907 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
908 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
909 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
910 static void generate_unwind_image PARAMS ((const char *));
911 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
912 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
913 static void free_saved_prologue_counts PARAMS ((void));
915 /* Build the unwind section name by appending the (possibly stripped)
916 text section NAME to the unwind PREFIX. The resulting string
917 pointer is assigned to RESULT. The string is allocated on the
918 stack, so this must be a macro... */
919 #define make_unw_section_name(special, text_name, result) \
921 const char *_prefix = special_section_name[special]; \
922 const char *_suffix = text_name; \
923 size_t _prefix_len, _suffix_len; \
925 if (strncmp (text_name, ".gnu.linkonce.t.", \
926 sizeof (".gnu.linkonce.t.") - 1) == 0) \
928 _prefix = special_linkonce_name[special - SPECIAL_SECTION_UNWIND]; \
929 _suffix += sizeof (".gnu.linkonce.t.") - 1; \
931 _prefix_len = strlen (_prefix), _suffix_len = strlen (_suffix); \
932 _result = alloca (_prefix_len + _suffix_len + 1); \
933 memcpy (_result, _prefix, _prefix_len); \
934 memcpy (_result + _prefix_len, _suffix, _suffix_len); \
935 _result[_prefix_len + _suffix_len] = '\0'; \
940 /* Determine if application register REGNUM resides in the integer
941 unit (as opposed to the memory unit). */
943 ar_is_in_integer_unit (reg)
948 return (reg == 64 /* pfs */
949 || reg == 65 /* lc */
950 || reg == 66 /* ec */
951 /* ??? ias accepts and puts these in the integer unit. */
952 || (reg >= 112 && reg <= 127));
955 /* Switch to section NAME and create section if necessary. It's
956 rather ugly that we have to manipulate input_line_pointer but I
957 don't see any other way to accomplish the same thing without
958 changing obj-elf.c (which may be the Right Thing, in the end). */
963 char *saved_input_line_pointer;
965 saved_input_line_pointer = input_line_pointer;
966 input_line_pointer = name;
968 input_line_pointer = saved_input_line_pointer;
971 /* Map 's' to SHF_IA_64_SHORT. */
974 ia64_elf_section_letter (letter, ptr_msg)
979 return SHF_IA_64_SHORT;
980 else if (letter == 'o')
981 return SHF_LINK_ORDER;
983 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
987 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
990 ia64_elf_section_flags (flags, attr, type)
992 int attr, type ATTRIBUTE_UNUSED;
994 if (attr & SHF_IA_64_SHORT)
995 flags |= SEC_SMALL_DATA;
1000 ia64_elf_section_type (str, len)
1004 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
1006 if (STREQ (ELF_STRING_ia64_unwind_info))
1007 return SHT_PROGBITS;
1009 if (STREQ (ELF_STRING_ia64_unwind_info_once))
1010 return SHT_PROGBITS;
1012 if (STREQ (ELF_STRING_ia64_unwind))
1013 return SHT_IA_64_UNWIND;
1015 if (STREQ (ELF_STRING_ia64_unwind_once))
1016 return SHT_IA_64_UNWIND;
1018 if (STREQ ("unwind"))
1019 return SHT_IA_64_UNWIND;
1021 if (STREQ ("init_array"))
1022 return SHT_INIT_ARRAY;
1024 if (STREQ ("fini_array"))
1025 return SHT_FINI_ARRAY;
1032 set_regstack (ins, locs, outs, rots)
1033 unsigned int ins, locs, outs, rots;
1035 /* Size of frame. */
1038 sof = ins + locs + outs;
1041 as_bad ("Size of frame exceeds maximum of 96 registers");
1046 as_warn ("Size of rotating registers exceeds frame size");
1049 md.in.base = REG_GR + 32;
1050 md.loc.base = md.in.base + ins;
1051 md.out.base = md.loc.base + locs;
1053 md.in.num_regs = ins;
1054 md.loc.num_regs = locs;
1055 md.out.num_regs = outs;
1056 md.rot.num_regs = rots;
1063 struct label_fix *lfix;
1065 subsegT saved_subseg;
1068 if (!md.last_text_seg)
1071 saved_seg = now_seg;
1072 saved_subseg = now_subseg;
1074 subseg_set (md.last_text_seg, 0);
1076 while (md.num_slots_in_use > 0)
1077 emit_one_bundle (); /* force out queued instructions */
1079 /* In case there are labels following the last instruction, resolve
1081 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1083 S_SET_VALUE (lfix->sym, frag_now_fix ());
1084 symbol_set_frag (lfix->sym, frag_now);
1086 CURR_SLOT.label_fixups = 0;
1087 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1089 S_SET_VALUE (lfix->sym, frag_now_fix ());
1090 symbol_set_frag (lfix->sym, frag_now);
1092 CURR_SLOT.tag_fixups = 0;
1094 /* In case there are unwind directives following the last instruction,
1095 resolve those now. We only handle prologue, body, and endp directives
1096 here. Give an error for others. */
1097 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1099 switch (ptr->r.type)
1105 ptr->slot_number = (unsigned long) frag_more (0);
1106 ptr->slot_frag = frag_now;
1109 /* Allow any record which doesn't have a "t" field (i.e.,
1110 doesn't relate to a particular instruction). */
1126 as_bad (_("Unwind directive not followed by an instruction."));
1130 unwind.current_entry = NULL;
1132 subseg_set (saved_seg, saved_subseg);
1134 if (md.qp.X_op == O_register)
1135 as_bad ("qualifying predicate not followed by instruction");
1139 ia64_do_align (nbytes)
1142 char *saved_input_line_pointer = input_line_pointer;
1144 input_line_pointer = "";
1145 s_align_bytes (nbytes);
1146 input_line_pointer = saved_input_line_pointer;
1150 ia64_cons_align (nbytes)
1155 char *saved_input_line_pointer = input_line_pointer;
1156 input_line_pointer = "";
1157 s_align_bytes (nbytes);
1158 input_line_pointer = saved_input_line_pointer;
1162 /* Output COUNT bytes to a memory location. */
1163 static unsigned char *vbyte_mem_ptr = NULL;
1166 output_vbyte_mem (count, ptr, comment)
1169 char *comment ATTRIBUTE_UNUSED;
1172 if (vbyte_mem_ptr == NULL)
1177 for (x = 0; x < count; x++)
1178 *(vbyte_mem_ptr++) = ptr[x];
1181 /* Count the number of bytes required for records. */
1182 static int vbyte_count = 0;
1184 count_output (count, ptr, comment)
1186 char *ptr ATTRIBUTE_UNUSED;
1187 char *comment ATTRIBUTE_UNUSED;
1189 vbyte_count += count;
1193 output_R1_format (f, rtype, rlen)
1195 unw_record_type rtype;
1202 output_R3_format (f, rtype, rlen);
1208 else if (rtype != prologue)
1209 as_bad ("record type is not valid");
1211 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1212 (*f) (1, &byte, NULL);
1216 output_R2_format (f, mask, grsave, rlen)
1223 mask = (mask & 0x0f);
1224 grsave = (grsave & 0x7f);
1226 bytes[0] = (UNW_R2 | (mask >> 1));
1227 bytes[1] = (((mask & 0x01) << 7) | grsave);
1228 count += output_leb128 (bytes + 2, rlen, 0);
1229 (*f) (count, bytes, NULL);
1233 output_R3_format (f, rtype, rlen)
1235 unw_record_type rtype;
1242 output_R1_format (f, rtype, rlen);
1248 else if (rtype != prologue)
1249 as_bad ("record type is not valid");
1250 bytes[0] = (UNW_R3 | r);
1251 count = output_leb128 (bytes + 1, rlen, 0);
1252 (*f) (count + 1, bytes, NULL);
1256 output_P1_format (f, brmask)
1261 byte = UNW_P1 | (brmask & 0x1f);
1262 (*f) (1, &byte, NULL);
1266 output_P2_format (f, brmask, gr)
1272 brmask = (brmask & 0x1f);
1273 bytes[0] = UNW_P2 | (brmask >> 1);
1274 bytes[1] = (((brmask & 1) << 7) | gr);
1275 (*f) (2, bytes, NULL);
1279 output_P3_format (f, rtype, reg)
1281 unw_record_type rtype;
1326 as_bad ("Invalid record type for P3 format.");
1328 bytes[0] = (UNW_P3 | (r >> 1));
1329 bytes[1] = (((r & 1) << 7) | reg);
1330 (*f) (2, bytes, NULL);
1334 output_P4_format (f, imask, imask_size)
1336 unsigned char *imask;
1337 unsigned long imask_size;
1340 (*f) (imask_size, imask, NULL);
1344 output_P5_format (f, grmask, frmask)
1347 unsigned long frmask;
1350 grmask = (grmask & 0x0f);
1353 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1354 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1355 bytes[3] = (frmask & 0x000000ff);
1356 (*f) (4, bytes, NULL);
1360 output_P6_format (f, rtype, rmask)
1362 unw_record_type rtype;
1368 if (rtype == gr_mem)
1370 else if (rtype != fr_mem)
1371 as_bad ("Invalid record type for format P6");
1372 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1373 (*f) (1, &byte, NULL);
1377 output_P7_format (f, rtype, w1, w2)
1379 unw_record_type rtype;
1386 count += output_leb128 (bytes + 1, w1, 0);
1391 count += output_leb128 (bytes + count, w2 >> 4, 0);
1441 bytes[0] = (UNW_P7 | r);
1442 (*f) (count, bytes, NULL);
1446 output_P8_format (f, rtype, t)
1448 unw_record_type rtype;
1487 case bspstore_psprel:
1490 case bspstore_sprel:
1502 case priunat_when_gr:
1505 case priunat_psprel:
1511 case priunat_when_mem:
1518 count += output_leb128 (bytes + 2, t, 0);
1519 (*f) (count, bytes, NULL);
1523 output_P9_format (f, grmask, gr)
1530 bytes[1] = (grmask & 0x0f);
1531 bytes[2] = (gr & 0x7f);
1532 (*f) (3, bytes, NULL);
1536 output_P10_format (f, abi, context)
1543 bytes[1] = (abi & 0xff);
1544 bytes[2] = (context & 0xff);
1545 (*f) (3, bytes, NULL);
1549 output_B1_format (f, rtype, label)
1551 unw_record_type rtype;
1552 unsigned long label;
1558 output_B4_format (f, rtype, label);
1561 if (rtype == copy_state)
1563 else if (rtype != label_state)
1564 as_bad ("Invalid record type for format B1");
1566 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1567 (*f) (1, &byte, NULL);
1571 output_B2_format (f, ecount, t)
1573 unsigned long ecount;
1580 output_B3_format (f, ecount, t);
1583 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1584 count += output_leb128 (bytes + 1, t, 0);
1585 (*f) (count, bytes, NULL);
1589 output_B3_format (f, ecount, t)
1591 unsigned long ecount;
1598 output_B2_format (f, ecount, t);
1602 count += output_leb128 (bytes + 1, t, 0);
1603 count += output_leb128 (bytes + count, ecount, 0);
1604 (*f) (count, bytes, NULL);
1608 output_B4_format (f, rtype, label)
1610 unw_record_type rtype;
1611 unsigned long label;
1618 output_B1_format (f, rtype, label);
1622 if (rtype == copy_state)
1624 else if (rtype != label_state)
1625 as_bad ("Invalid record type for format B1");
1627 bytes[0] = (UNW_B4 | (r << 3));
1628 count += output_leb128 (bytes + 1, label, 0);
1629 (*f) (count, bytes, NULL);
1633 format_ab_reg (ab, reg)
1640 ret = (ab << 5) | reg;
1645 output_X1_format (f, rtype, ab, reg, t, w1)
1647 unw_record_type rtype;
1657 if (rtype == spill_sprel)
1659 else if (rtype != spill_psprel)
1660 as_bad ("Invalid record type for format X1");
1661 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1662 count += output_leb128 (bytes + 2, t, 0);
1663 count += output_leb128 (bytes + count, w1, 0);
1664 (*f) (count, bytes, NULL);
1668 output_X2_format (f, ab, reg, x, y, treg, t)
1677 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1678 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1679 count += output_leb128 (bytes + 3, t, 0);
1680 (*f) (count, bytes, NULL);
1684 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1686 unw_record_type rtype;
1697 if (rtype == spill_sprel_p)
1699 else if (rtype != spill_psprel_p)
1700 as_bad ("Invalid record type for format X3");
1701 bytes[1] = ((r << 7) | (qp & 0x3f));
1702 bytes[2] = format_ab_reg (ab, reg);
1703 count += output_leb128 (bytes + 3, t, 0);
1704 count += output_leb128 (bytes + count, w1, 0);
1705 (*f) (count, bytes, NULL);
1709 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1719 bytes[1] = (qp & 0x3f);
1720 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1721 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1722 count += output_leb128 (bytes + 4, t, 0);
1723 (*f) (count, bytes, NULL);
1726 /* This function allocates a record list structure, and initializes fields. */
1728 static unw_rec_list *
1729 alloc_record (unw_record_type t)
1732 ptr = xmalloc (sizeof (*ptr));
1734 ptr->slot_number = SLOT_NUM_NOT_SET;
1736 ptr->next_slot_number = 0;
1737 ptr->next_slot_frag = 0;
1741 /* Dummy unwind record used for calculating the length of the last prologue or
1744 static unw_rec_list *
1747 unw_rec_list *ptr = alloc_record (endp);
1751 static unw_rec_list *
1754 unw_rec_list *ptr = alloc_record (prologue);
1755 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1759 static unw_rec_list *
1760 output_prologue_gr (saved_mask, reg)
1761 unsigned int saved_mask;
1764 unw_rec_list *ptr = alloc_record (prologue_gr);
1765 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1766 ptr->r.record.r.grmask = saved_mask;
1767 ptr->r.record.r.grsave = reg;
1771 static unw_rec_list *
1774 unw_rec_list *ptr = alloc_record (body);
1778 static unw_rec_list *
1779 output_mem_stack_f (size)
1782 unw_rec_list *ptr = alloc_record (mem_stack_f);
1783 ptr->r.record.p.size = size;
1787 static unw_rec_list *
1788 output_mem_stack_v ()
1790 unw_rec_list *ptr = alloc_record (mem_stack_v);
1794 static unw_rec_list *
1798 unw_rec_list *ptr = alloc_record (psp_gr);
1799 ptr->r.record.p.gr = gr;
1803 static unw_rec_list *
1804 output_psp_sprel (offset)
1805 unsigned int offset;
1807 unw_rec_list *ptr = alloc_record (psp_sprel);
1808 ptr->r.record.p.spoff = offset / 4;
1812 static unw_rec_list *
1815 unw_rec_list *ptr = alloc_record (rp_when);
1819 static unw_rec_list *
1823 unw_rec_list *ptr = alloc_record (rp_gr);
1824 ptr->r.record.p.gr = gr;
1828 static unw_rec_list *
1832 unw_rec_list *ptr = alloc_record (rp_br);
1833 ptr->r.record.p.br = br;
1837 static unw_rec_list *
1838 output_rp_psprel (offset)
1839 unsigned int offset;
1841 unw_rec_list *ptr = alloc_record (rp_psprel);
1842 ptr->r.record.p.pspoff = offset / 4;
1846 static unw_rec_list *
1847 output_rp_sprel (offset)
1848 unsigned int offset;
1850 unw_rec_list *ptr = alloc_record (rp_sprel);
1851 ptr->r.record.p.spoff = offset / 4;
1855 static unw_rec_list *
1858 unw_rec_list *ptr = alloc_record (pfs_when);
1862 static unw_rec_list *
1866 unw_rec_list *ptr = alloc_record (pfs_gr);
1867 ptr->r.record.p.gr = gr;
1871 static unw_rec_list *
1872 output_pfs_psprel (offset)
1873 unsigned int offset;
1875 unw_rec_list *ptr = alloc_record (pfs_psprel);
1876 ptr->r.record.p.pspoff = offset / 4;
1880 static unw_rec_list *
1881 output_pfs_sprel (offset)
1882 unsigned int offset;
1884 unw_rec_list *ptr = alloc_record (pfs_sprel);
1885 ptr->r.record.p.spoff = offset / 4;
1889 static unw_rec_list *
1890 output_preds_when ()
1892 unw_rec_list *ptr = alloc_record (preds_when);
1896 static unw_rec_list *
1897 output_preds_gr (gr)
1900 unw_rec_list *ptr = alloc_record (preds_gr);
1901 ptr->r.record.p.gr = gr;
1905 static unw_rec_list *
1906 output_preds_psprel (offset)
1907 unsigned int offset;
1909 unw_rec_list *ptr = alloc_record (preds_psprel);
1910 ptr->r.record.p.pspoff = offset / 4;
1914 static unw_rec_list *
1915 output_preds_sprel (offset)
1916 unsigned int offset;
1918 unw_rec_list *ptr = alloc_record (preds_sprel);
1919 ptr->r.record.p.spoff = offset / 4;
1923 static unw_rec_list *
1924 output_fr_mem (mask)
1927 unw_rec_list *ptr = alloc_record (fr_mem);
1928 ptr->r.record.p.rmask = mask;
1932 static unw_rec_list *
1933 output_frgr_mem (gr_mask, fr_mask)
1934 unsigned int gr_mask;
1935 unsigned int fr_mask;
1937 unw_rec_list *ptr = alloc_record (frgr_mem);
1938 ptr->r.record.p.grmask = gr_mask;
1939 ptr->r.record.p.frmask = fr_mask;
1943 static unw_rec_list *
1944 output_gr_gr (mask, reg)
1948 unw_rec_list *ptr = alloc_record (gr_gr);
1949 ptr->r.record.p.grmask = mask;
1950 ptr->r.record.p.gr = reg;
1954 static unw_rec_list *
1955 output_gr_mem (mask)
1958 unw_rec_list *ptr = alloc_record (gr_mem);
1959 ptr->r.record.p.rmask = mask;
1963 static unw_rec_list *
1964 output_br_mem (unsigned int mask)
1966 unw_rec_list *ptr = alloc_record (br_mem);
1967 ptr->r.record.p.brmask = mask;
1971 static unw_rec_list *
1972 output_br_gr (save_mask, reg)
1973 unsigned int save_mask;
1976 unw_rec_list *ptr = alloc_record (br_gr);
1977 ptr->r.record.p.brmask = save_mask;
1978 ptr->r.record.p.gr = reg;
1982 static unw_rec_list *
1983 output_spill_base (offset)
1984 unsigned int offset;
1986 unw_rec_list *ptr = alloc_record (spill_base);
1987 ptr->r.record.p.pspoff = offset / 4;
1991 static unw_rec_list *
1994 unw_rec_list *ptr = alloc_record (unat_when);
1998 static unw_rec_list *
2002 unw_rec_list *ptr = alloc_record (unat_gr);
2003 ptr->r.record.p.gr = gr;
2007 static unw_rec_list *
2008 output_unat_psprel (offset)
2009 unsigned int offset;
2011 unw_rec_list *ptr = alloc_record (unat_psprel);
2012 ptr->r.record.p.pspoff = offset / 4;
2016 static unw_rec_list *
2017 output_unat_sprel (offset)
2018 unsigned int offset;
2020 unw_rec_list *ptr = alloc_record (unat_sprel);
2021 ptr->r.record.p.spoff = offset / 4;
2025 static unw_rec_list *
2028 unw_rec_list *ptr = alloc_record (lc_when);
2032 static unw_rec_list *
2036 unw_rec_list *ptr = alloc_record (lc_gr);
2037 ptr->r.record.p.gr = gr;
2041 static unw_rec_list *
2042 output_lc_psprel (offset)
2043 unsigned int offset;
2045 unw_rec_list *ptr = alloc_record (lc_psprel);
2046 ptr->r.record.p.pspoff = offset / 4;
2050 static unw_rec_list *
2051 output_lc_sprel (offset)
2052 unsigned int offset;
2054 unw_rec_list *ptr = alloc_record (lc_sprel);
2055 ptr->r.record.p.spoff = offset / 4;
2059 static unw_rec_list *
2062 unw_rec_list *ptr = alloc_record (fpsr_when);
2066 static unw_rec_list *
2070 unw_rec_list *ptr = alloc_record (fpsr_gr);
2071 ptr->r.record.p.gr = gr;
2075 static unw_rec_list *
2076 output_fpsr_psprel (offset)
2077 unsigned int offset;
2079 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2080 ptr->r.record.p.pspoff = offset / 4;
2084 static unw_rec_list *
2085 output_fpsr_sprel (offset)
2086 unsigned int offset;
2088 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2089 ptr->r.record.p.spoff = offset / 4;
2093 static unw_rec_list *
2094 output_priunat_when_gr ()
2096 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2100 static unw_rec_list *
2101 output_priunat_when_mem ()
2103 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2107 static unw_rec_list *
2108 output_priunat_gr (gr)
2111 unw_rec_list *ptr = alloc_record (priunat_gr);
2112 ptr->r.record.p.gr = gr;
2116 static unw_rec_list *
2117 output_priunat_psprel (offset)
2118 unsigned int offset;
2120 unw_rec_list *ptr = alloc_record (priunat_psprel);
2121 ptr->r.record.p.pspoff = offset / 4;
2125 static unw_rec_list *
2126 output_priunat_sprel (offset)
2127 unsigned int offset;
2129 unw_rec_list *ptr = alloc_record (priunat_sprel);
2130 ptr->r.record.p.spoff = offset / 4;
2134 static unw_rec_list *
2137 unw_rec_list *ptr = alloc_record (bsp_when);
2141 static unw_rec_list *
2145 unw_rec_list *ptr = alloc_record (bsp_gr);
2146 ptr->r.record.p.gr = gr;
2150 static unw_rec_list *
2151 output_bsp_psprel (offset)
2152 unsigned int offset;
2154 unw_rec_list *ptr = alloc_record (bsp_psprel);
2155 ptr->r.record.p.pspoff = offset / 4;
2159 static unw_rec_list *
2160 output_bsp_sprel (offset)
2161 unsigned int offset;
2163 unw_rec_list *ptr = alloc_record (bsp_sprel);
2164 ptr->r.record.p.spoff = offset / 4;
2168 static unw_rec_list *
2169 output_bspstore_when ()
2171 unw_rec_list *ptr = alloc_record (bspstore_when);
2175 static unw_rec_list *
2176 output_bspstore_gr (gr)
2179 unw_rec_list *ptr = alloc_record (bspstore_gr);
2180 ptr->r.record.p.gr = gr;
2184 static unw_rec_list *
2185 output_bspstore_psprel (offset)
2186 unsigned int offset;
2188 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2189 ptr->r.record.p.pspoff = offset / 4;
2193 static unw_rec_list *
2194 output_bspstore_sprel (offset)
2195 unsigned int offset;
2197 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2198 ptr->r.record.p.spoff = offset / 4;
2202 static unw_rec_list *
2205 unw_rec_list *ptr = alloc_record (rnat_when);
2209 static unw_rec_list *
2213 unw_rec_list *ptr = alloc_record (rnat_gr);
2214 ptr->r.record.p.gr = gr;
2218 static unw_rec_list *
2219 output_rnat_psprel (offset)
2220 unsigned int offset;
2222 unw_rec_list *ptr = alloc_record (rnat_psprel);
2223 ptr->r.record.p.pspoff = offset / 4;
2227 static unw_rec_list *
2228 output_rnat_sprel (offset)
2229 unsigned int offset;
2231 unw_rec_list *ptr = alloc_record (rnat_sprel);
2232 ptr->r.record.p.spoff = offset / 4;
2236 static unw_rec_list *
2237 output_unwabi (abi, context)
2239 unsigned long context;
2241 unw_rec_list *ptr = alloc_record (unwabi);
2242 ptr->r.record.p.abi = abi;
2243 ptr->r.record.p.context = context;
2247 static unw_rec_list *
2248 output_epilogue (unsigned long ecount)
2250 unw_rec_list *ptr = alloc_record (epilogue);
2251 ptr->r.record.b.ecount = ecount;
2255 static unw_rec_list *
2256 output_label_state (unsigned long label)
2258 unw_rec_list *ptr = alloc_record (label_state);
2259 ptr->r.record.b.label = label;
2263 static unw_rec_list *
2264 output_copy_state (unsigned long label)
2266 unw_rec_list *ptr = alloc_record (copy_state);
2267 ptr->r.record.b.label = label;
2271 static unw_rec_list *
2272 output_spill_psprel (ab, reg, offset)
2275 unsigned int offset;
2277 unw_rec_list *ptr = alloc_record (spill_psprel);
2278 ptr->r.record.x.ab = ab;
2279 ptr->r.record.x.reg = reg;
2280 ptr->r.record.x.pspoff = offset / 4;
2284 static unw_rec_list *
2285 output_spill_sprel (ab, reg, offset)
2288 unsigned int offset;
2290 unw_rec_list *ptr = alloc_record (spill_sprel);
2291 ptr->r.record.x.ab = ab;
2292 ptr->r.record.x.reg = reg;
2293 ptr->r.record.x.spoff = offset / 4;
2297 static unw_rec_list *
2298 output_spill_psprel_p (ab, reg, offset, predicate)
2301 unsigned int offset;
2302 unsigned int predicate;
2304 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2305 ptr->r.record.x.ab = ab;
2306 ptr->r.record.x.reg = reg;
2307 ptr->r.record.x.pspoff = offset / 4;
2308 ptr->r.record.x.qp = predicate;
2312 static unw_rec_list *
2313 output_spill_sprel_p (ab, reg, offset, predicate)
2316 unsigned int offset;
2317 unsigned int predicate;
2319 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2320 ptr->r.record.x.ab = ab;
2321 ptr->r.record.x.reg = reg;
2322 ptr->r.record.x.spoff = offset / 4;
2323 ptr->r.record.x.qp = predicate;
2327 static unw_rec_list *
2328 output_spill_reg (ab, reg, targ_reg, xy)
2331 unsigned int targ_reg;
2334 unw_rec_list *ptr = alloc_record (spill_reg);
2335 ptr->r.record.x.ab = ab;
2336 ptr->r.record.x.reg = reg;
2337 ptr->r.record.x.treg = targ_reg;
2338 ptr->r.record.x.xy = xy;
2342 static unw_rec_list *
2343 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2346 unsigned int targ_reg;
2348 unsigned int predicate;
2350 unw_rec_list *ptr = alloc_record (spill_reg_p);
2351 ptr->r.record.x.ab = ab;
2352 ptr->r.record.x.reg = reg;
2353 ptr->r.record.x.treg = targ_reg;
2354 ptr->r.record.x.xy = xy;
2355 ptr->r.record.x.qp = predicate;
2359 /* Given a unw_rec_list process the correct format with the
2360 specified function. */
2363 process_one_record (ptr, f)
2367 unsigned long fr_mask, gr_mask;
2369 switch (ptr->r.type)
2371 /* This is a dummy record that takes up no space in the output. */
2379 /* These are taken care of by prologue/prologue_gr. */
2384 if (ptr->r.type == prologue_gr)
2385 output_R2_format (f, ptr->r.record.r.grmask,
2386 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2388 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2390 /* Output descriptor(s) for union of register spills (if any). */
2391 gr_mask = ptr->r.record.r.mask.gr_mem;
2392 fr_mask = ptr->r.record.r.mask.fr_mem;
2395 if ((fr_mask & ~0xfUL) == 0)
2396 output_P6_format (f, fr_mem, fr_mask);
2399 output_P5_format (f, gr_mask, fr_mask);
2404 output_P6_format (f, gr_mem, gr_mask);
2405 if (ptr->r.record.r.mask.br_mem)
2406 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2408 /* output imask descriptor if necessary: */
2409 if (ptr->r.record.r.mask.i)
2410 output_P4_format (f, ptr->r.record.r.mask.i,
2411 ptr->r.record.r.imask_size);
2415 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2419 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2420 ptr->r.record.p.size);
2433 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2436 output_P3_format (f, rp_br, ptr->r.record.p.br);
2439 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2447 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2456 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2466 case bspstore_sprel:
2468 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2471 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2474 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2477 as_bad ("spill_mask record unimplemented.");
2479 case priunat_when_gr:
2480 case priunat_when_mem:
2484 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2486 case priunat_psprel:
2488 case bspstore_psprel:
2490 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2493 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2496 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2500 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2503 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2504 ptr->r.record.x.reg, ptr->r.record.x.t,
2505 ptr->r.record.x.pspoff);
2508 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2509 ptr->r.record.x.reg, ptr->r.record.x.t,
2510 ptr->r.record.x.spoff);
2513 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2514 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2515 ptr->r.record.x.treg, ptr->r.record.x.t);
2517 case spill_psprel_p:
2518 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2519 ptr->r.record.x.ab, ptr->r.record.x.reg,
2520 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2523 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2524 ptr->r.record.x.ab, ptr->r.record.x.reg,
2525 ptr->r.record.x.t, ptr->r.record.x.spoff);
2528 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2529 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2530 ptr->r.record.x.xy, ptr->r.record.x.treg,
2534 as_bad ("record_type_not_valid");
2539 /* Given a unw_rec_list list, process all the records with
2540 the specified function. */
2542 process_unw_records (list, f)
2547 for (ptr = list; ptr; ptr = ptr->next)
2548 process_one_record (ptr, f);
2551 /* Determine the size of a record list in bytes. */
2553 calc_record_size (list)
2557 process_unw_records (list, count_output);
2561 /* Update IMASK bitmask to reflect the fact that one or more registers
2562 of type TYPE are saved starting at instruction with index T. If N
2563 bits are set in REGMASK, it is assumed that instructions T through
2564 T+N-1 save these registers.
2568 1: instruction saves next fp reg
2569 2: instruction saves next general reg
2570 3: instruction saves next branch reg */
2572 set_imask (region, regmask, t, type)
2573 unw_rec_list *region;
2574 unsigned long regmask;
2578 unsigned char *imask;
2579 unsigned long imask_size;
2583 imask = region->r.record.r.mask.i;
2584 imask_size = region->r.record.r.imask_size;
2587 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2588 imask = xmalloc (imask_size);
2589 memset (imask, 0, imask_size);
2591 region->r.record.r.imask_size = imask_size;
2592 region->r.record.r.mask.i = imask;
2596 pos = 2 * (3 - t % 4);
2599 if (i >= imask_size)
2601 as_bad ("Ignoring attempt to spill beyond end of region");
2605 imask[i] |= (type & 0x3) << pos;
2607 regmask &= (regmask - 1);
2617 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2618 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2619 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2623 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2624 unsigned long slot_addr;
2626 unsigned long first_addr;
2630 unsigned long index = 0;
2632 /* First time we are called, the initial address and frag are invalid. */
2633 if (first_addr == 0)
2636 /* If the two addresses are in different frags, then we need to add in
2637 the remaining size of this frag, and then the entire size of intermediate
2639 while (slot_frag != first_frag)
2641 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2645 /* We can get the final addresses only during and after
2647 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2648 index += 3 * ((first_frag->fr_next->fr_address
2649 - first_frag->fr_address
2650 - first_frag->fr_fix) >> 4);
2653 /* We don't know what the final addresses will be. We try our
2654 best to estimate. */
2655 switch (first_frag->fr_type)
2661 as_fatal ("only constant space allocation is supported");
2667 /* Take alignment into account. Assume the worst case
2668 before relaxation. */
2669 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2673 if (first_frag->fr_symbol)
2675 as_fatal ("only constant offsets are supported");
2679 index += 3 * (first_frag->fr_offset >> 4);
2683 /* Add in the full size of the frag converted to instruction slots. */
2684 index += 3 * (first_frag->fr_fix >> 4);
2685 /* Subtract away the initial part before first_addr. */
2686 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2687 + ((first_addr & 0x3) - (start_addr & 0x3)));
2689 /* Move to the beginning of the next frag. */
2690 first_frag = first_frag->fr_next;
2691 first_addr = (unsigned long) &first_frag->fr_literal;
2694 /* Add in the used part of the last frag. */
2695 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2696 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2700 /* Optimize unwind record directives. */
2702 static unw_rec_list *
2703 optimize_unw_records (list)
2709 /* If the only unwind record is ".prologue" or ".prologue" followed
2710 by ".body", then we can optimize the unwind directives away. */
2711 if (list->r.type == prologue
2712 && (list->next->r.type == endp
2713 || (list->next->r.type == body && list->next->next->r.type == endp)))
2719 /* Given a complete record list, process any records which have
2720 unresolved fields, (ie length counts for a prologue). After
2721 this has been run, all necessary information should be available
2722 within each record to generate an image. */
2725 fixup_unw_records (list, before_relax)
2729 unw_rec_list *ptr, *region = 0;
2730 unsigned long first_addr = 0, rlen = 0, t;
2731 fragS *first_frag = 0;
2733 for (ptr = list; ptr; ptr = ptr->next)
2735 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2736 as_bad (" Insn slot not set in unwind record.");
2737 t = slot_index (ptr->slot_number, ptr->slot_frag,
2738 first_addr, first_frag, before_relax);
2739 switch (ptr->r.type)
2747 unsigned long last_addr = 0;
2748 fragS *last_frag = NULL;
2750 first_addr = ptr->slot_number;
2751 first_frag = ptr->slot_frag;
2752 /* Find either the next body/prologue start, or the end of
2753 the function, and determine the size of the region. */
2754 for (last = ptr->next; last != NULL; last = last->next)
2755 if (last->r.type == prologue || last->r.type == prologue_gr
2756 || last->r.type == body || last->r.type == endp)
2758 last_addr = last->slot_number;
2759 last_frag = last->slot_frag;
2762 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2764 rlen = ptr->r.record.r.rlen = size;
2765 if (ptr->r.type == body)
2766 /* End of region. */
2773 ptr->r.record.b.t = rlen - 1 - t;
2784 case priunat_when_gr:
2785 case priunat_when_mem:
2789 ptr->r.record.p.t = t;
2797 case spill_psprel_p:
2798 ptr->r.record.x.t = t;
2804 as_bad ("frgr_mem record before region record!\n");
2807 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2808 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2809 set_imask (region, ptr->r.record.p.frmask, t, 1);
2810 set_imask (region, ptr->r.record.p.grmask, t, 2);
2815 as_bad ("fr_mem record before region record!\n");
2818 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2819 set_imask (region, ptr->r.record.p.rmask, t, 1);
2824 as_bad ("gr_mem record before region record!\n");
2827 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2828 set_imask (region, ptr->r.record.p.rmask, t, 2);
2833 as_bad ("br_mem record before region record!\n");
2836 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2837 set_imask (region, ptr->r.record.p.brmask, t, 3);
2843 as_bad ("gr_gr record before region record!\n");
2846 set_imask (region, ptr->r.record.p.grmask, t, 2);
2851 as_bad ("br_gr record before region record!\n");
2854 set_imask (region, ptr->r.record.p.brmask, t, 3);
2863 /* Estimate the size of a frag before relaxing. We only have one type of frag
2864 to handle here, which is the unwind info frag. */
2867 ia64_estimate_size_before_relax (fragS *frag,
2868 asection *segtype ATTRIBUTE_UNUSED)
2873 /* ??? This code is identical to the first part of ia64_convert_frag. */
2874 list = (unw_rec_list *) frag->fr_opcode;
2875 fixup_unw_records (list, 0);
2877 len = calc_record_size (list);
2878 /* pad to pointer-size boundary. */
2879 pad = len % md.pointer_size;
2881 len += md.pointer_size - pad;
2882 /* Add 8 for the header + a pointer for the personality offset. */
2883 size = len + 8 + md.pointer_size;
2885 /* fr_var carries the max_chars that we created the fragment with.
2886 We must, of course, have allocated enough memory earlier. */
2887 assert (frag->fr_var >= size);
2889 return frag->fr_fix + size;
2892 /* This function converts a rs_machine_dependent variant frag into a
2893 normal fill frag with the unwind image from the the record list. */
2895 ia64_convert_frag (fragS *frag)
2901 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2902 list = (unw_rec_list *) frag->fr_opcode;
2903 fixup_unw_records (list, 0);
2905 len = calc_record_size (list);
2906 /* pad to pointer-size boundary. */
2907 pad = len % md.pointer_size;
2909 len += md.pointer_size - pad;
2910 /* Add 8 for the header + a pointer for the personality offset. */
2911 size = len + 8 + md.pointer_size;
2913 /* fr_var carries the max_chars that we created the fragment with.
2914 We must, of course, have allocated enough memory earlier. */
2915 assert (frag->fr_var >= size);
2917 /* Initialize the header area. fr_offset is initialized with
2918 unwind.personality_routine. */
2919 if (frag->fr_offset)
2921 if (md.flags & EF_IA_64_ABI64)
2922 flag_value = (bfd_vma) 3 << 32;
2924 /* 32-bit unwind info block. */
2925 flag_value = (bfd_vma) 0x1003 << 32;
2930 md_number_to_chars (frag->fr_literal,
2931 (((bfd_vma) 1 << 48) /* Version. */
2932 | flag_value /* U & E handler flags. */
2933 | (len / md.pointer_size)), /* Length. */
2936 /* Skip the header. */
2937 vbyte_mem_ptr = frag->fr_literal + 8;
2938 process_unw_records (list, output_vbyte_mem);
2940 /* Fill the padding bytes with zeros. */
2942 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2943 md.pointer_size - pad);
2945 frag->fr_fix += size;
2946 frag->fr_type = rs_fill;
2948 frag->fr_offset = 0;
2952 convert_expr_to_ab_reg (e, ab, regp)
2959 if (e->X_op != O_register)
2962 reg = e->X_add_number;
2963 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2966 *regp = reg - REG_GR;
2968 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2969 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2972 *regp = reg - REG_FR;
2974 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2977 *regp = reg - REG_BR;
2984 case REG_PR: *regp = 0; break;
2985 case REG_PSP: *regp = 1; break;
2986 case REG_PRIUNAT: *regp = 2; break;
2987 case REG_BR + 0: *regp = 3; break;
2988 case REG_AR + AR_BSP: *regp = 4; break;
2989 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2990 case REG_AR + AR_RNAT: *regp = 6; break;
2991 case REG_AR + AR_UNAT: *regp = 7; break;
2992 case REG_AR + AR_FPSR: *regp = 8; break;
2993 case REG_AR + AR_PFS: *regp = 9; break;
2994 case REG_AR + AR_LC: *regp = 10; break;
3004 convert_expr_to_xy_reg (e, xy, regp)
3011 if (e->X_op != O_register)
3014 reg = e->X_add_number;
3016 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
3019 *regp = reg - REG_GR;
3021 else if (reg >= REG_FR && reg <= (REG_FR + 127))
3024 *regp = reg - REG_FR;
3026 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3029 *regp = reg - REG_BR;
3038 int dummy ATTRIBUTE_UNUSED;
3043 radix = *input_line_pointer++;
3045 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3047 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3048 ignore_rest_of_line ();
3053 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3055 dot_special_section (which)
3058 set_section ((char *) special_section_name[which]);
3062 add_unwind_entry (ptr)
3066 unwind.tail->next = ptr;
3071 /* The current entry can in fact be a chain of unwind entries. */
3072 if (unwind.current_entry == NULL)
3073 unwind.current_entry = ptr;
3078 int dummy ATTRIBUTE_UNUSED;
3084 if (e.X_op != O_constant)
3085 as_bad ("Operand to .fframe must be a constant");
3087 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3092 int dummy ATTRIBUTE_UNUSED;
3098 reg = e.X_add_number - REG_GR;
3099 if (e.X_op == O_register && reg < 128)
3101 add_unwind_entry (output_mem_stack_v ());
3102 if (! (unwind.prologue_mask & 2))
3103 add_unwind_entry (output_psp_gr (reg));
3106 as_bad ("First operand to .vframe must be a general register");
3110 dot_vframesp (dummy)
3111 int dummy ATTRIBUTE_UNUSED;
3116 if (e.X_op == O_constant)
3118 add_unwind_entry (output_mem_stack_v ());
3119 add_unwind_entry (output_psp_sprel (e.X_add_number));
3122 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3126 dot_vframepsp (dummy)
3127 int dummy ATTRIBUTE_UNUSED;
3132 if (e.X_op == O_constant)
3134 add_unwind_entry (output_mem_stack_v ());
3135 add_unwind_entry (output_psp_sprel (e.X_add_number));
3138 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3143 int dummy ATTRIBUTE_UNUSED;
3149 sep = parse_operand (&e1);
3151 as_bad ("No second operand to .save");
3152 sep = parse_operand (&e2);
3154 reg1 = e1.X_add_number;
3155 reg2 = e2.X_add_number - REG_GR;
3157 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3158 if (e1.X_op == O_register)
3160 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3164 case REG_AR + AR_BSP:
3165 add_unwind_entry (output_bsp_when ());
3166 add_unwind_entry (output_bsp_gr (reg2));
3168 case REG_AR + AR_BSPSTORE:
3169 add_unwind_entry (output_bspstore_when ());
3170 add_unwind_entry (output_bspstore_gr (reg2));
3172 case REG_AR + AR_RNAT:
3173 add_unwind_entry (output_rnat_when ());
3174 add_unwind_entry (output_rnat_gr (reg2));
3176 case REG_AR + AR_UNAT:
3177 add_unwind_entry (output_unat_when ());
3178 add_unwind_entry (output_unat_gr (reg2));
3180 case REG_AR + AR_FPSR:
3181 add_unwind_entry (output_fpsr_when ());
3182 add_unwind_entry (output_fpsr_gr (reg2));
3184 case REG_AR + AR_PFS:
3185 add_unwind_entry (output_pfs_when ());
3186 if (! (unwind.prologue_mask & 4))
3187 add_unwind_entry (output_pfs_gr (reg2));
3189 case REG_AR + AR_LC:
3190 add_unwind_entry (output_lc_when ());
3191 add_unwind_entry (output_lc_gr (reg2));
3194 add_unwind_entry (output_rp_when ());
3195 if (! (unwind.prologue_mask & 8))
3196 add_unwind_entry (output_rp_gr (reg2));
3199 add_unwind_entry (output_preds_when ());
3200 if (! (unwind.prologue_mask & 1))
3201 add_unwind_entry (output_preds_gr (reg2));
3204 add_unwind_entry (output_priunat_when_gr ());
3205 add_unwind_entry (output_priunat_gr (reg2));
3208 as_bad ("First operand not a valid register");
3212 as_bad (" Second operand not a valid register");
3215 as_bad ("First operand not a register");
3220 int dummy ATTRIBUTE_UNUSED;
3223 unsigned long ecount; /* # of _additional_ regions to pop */
3226 sep = parse_operand (&e1);
3227 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3229 as_bad ("First operand to .restore must be stack pointer (sp)");
3235 parse_operand (&e2);
3236 if (e2.X_op != O_constant || e2.X_add_number < 0)
3238 as_bad ("Second operand to .restore must be a constant >= 0");
3241 ecount = e2.X_add_number;
3244 ecount = unwind.prologue_count - 1;
3246 if (ecount >= unwind.prologue_count)
3248 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3249 ecount + 1, unwind.prologue_count);
3253 add_unwind_entry (output_epilogue (ecount));
3255 if (ecount < unwind.prologue_count)
3256 unwind.prologue_count -= ecount + 1;
3258 unwind.prologue_count = 0;
3262 dot_restorereg (dummy)
3263 int dummy ATTRIBUTE_UNUSED;
3265 unsigned int ab, reg;
3270 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3272 as_bad ("First operand to .restorereg must be a preserved register");
3275 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3279 dot_restorereg_p (dummy)
3280 int dummy ATTRIBUTE_UNUSED;
3282 unsigned int qp, ab, reg;
3286 sep = parse_operand (&e1);
3289 as_bad ("No second operand to .restorereg.p");
3293 parse_operand (&e2);
3295 qp = e1.X_add_number - REG_P;
3296 if (e1.X_op != O_register || qp > 63)
3298 as_bad ("First operand to .restorereg.p must be a predicate");
3302 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3304 as_bad ("Second operand to .restorereg.p must be a preserved register");
3307 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3311 generate_unwind_image (text_name)
3312 const char *text_name;
3317 /* Mark the end of the unwind info, so that we can compute the size of the
3318 last unwind region. */
3319 add_unwind_entry (output_endp ());
3321 /* Force out pending instructions, to make sure all unwind records have
3322 a valid slot_number field. */
3323 ia64_flush_insns ();
3325 /* Generate the unwind record. */
3326 list = optimize_unw_records (unwind.list);
3327 fixup_unw_records (list, 1);
3328 size = calc_record_size (list);
3330 if (size > 0 || unwind.force_unwind_entry)
3332 unwind.force_unwind_entry = 0;
3333 /* pad to pointer-size boundary. */
3334 pad = size % md.pointer_size;
3336 size += md.pointer_size - pad;
3337 /* Add 8 for the header + a pointer for the personality
3339 size += 8 + md.pointer_size;
3342 /* If there are unwind records, switch sections, and output the info. */
3347 bfd_reloc_code_real_type reloc;
3349 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3350 set_section (sec_name);
3351 bfd_set_section_flags (stdoutput, now_seg,
3352 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3354 /* Make sure the section has 4 byte alignment for ILP32 and
3355 8 byte alignment for LP64. */
3356 frag_align (md.pointer_size_shift, 0, 0);
3357 record_alignment (now_seg, md.pointer_size_shift);
3359 /* Set expression which points to start of unwind descriptor area. */
3360 unwind.info = expr_build_dot ();
3362 frag_var (rs_machine_dependent, size, size, 0, 0,
3363 (offsetT) unwind.personality_routine, (char *) list);
3365 /* Add the personality address to the image. */
3366 if (unwind.personality_routine != 0)
3368 exp.X_op = O_symbol;
3369 exp.X_add_symbol = unwind.personality_routine;
3370 exp.X_add_number = 0;
3372 if (md.flags & EF_IA_64_BE)
3374 if (md.flags & EF_IA_64_ABI64)
3375 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3377 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3381 if (md.flags & EF_IA_64_ABI64)
3382 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3384 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3387 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3388 md.pointer_size, &exp, 0, reloc);
3389 unwind.personality_routine = 0;
3393 free_saved_prologue_counts ();
3394 unwind.list = unwind.tail = unwind.current_entry = NULL;
3398 dot_handlerdata (dummy)
3399 int dummy ATTRIBUTE_UNUSED;
3401 const char *text_name = segment_name (now_seg);
3403 /* If text section name starts with ".text" (which it should),
3404 strip this prefix off. */
3405 if (strcmp (text_name, ".text") == 0)
3408 unwind.force_unwind_entry = 1;
3410 /* Remember which segment we're in so we can switch back after .endp */
3411 unwind.saved_text_seg = now_seg;
3412 unwind.saved_text_subseg = now_subseg;
3414 /* Generate unwind info into unwind-info section and then leave that
3415 section as the currently active one so dataXX directives go into
3416 the language specific data area of the unwind info block. */
3417 generate_unwind_image (text_name);
3418 demand_empty_rest_of_line ();
3422 dot_unwentry (dummy)
3423 int dummy ATTRIBUTE_UNUSED;
3425 unwind.force_unwind_entry = 1;
3426 demand_empty_rest_of_line ();
3431 int dummy ATTRIBUTE_UNUSED;
3437 reg = e.X_add_number - REG_BR;
3438 if (e.X_op == O_register && reg < 8)
3439 add_unwind_entry (output_rp_br (reg));
3441 as_bad ("First operand not a valid branch register");
3445 dot_savemem (psprel)
3452 sep = parse_operand (&e1);
3454 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3455 sep = parse_operand (&e2);
3457 reg1 = e1.X_add_number;
3458 val = e2.X_add_number;
3460 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3461 if (e1.X_op == O_register)
3463 if (e2.X_op == O_constant)
3467 case REG_AR + AR_BSP:
3468 add_unwind_entry (output_bsp_when ());
3469 add_unwind_entry ((psprel
3471 : output_bsp_sprel) (val));
3473 case REG_AR + AR_BSPSTORE:
3474 add_unwind_entry (output_bspstore_when ());
3475 add_unwind_entry ((psprel
3476 ? output_bspstore_psprel
3477 : output_bspstore_sprel) (val));
3479 case REG_AR + AR_RNAT:
3480 add_unwind_entry (output_rnat_when ());
3481 add_unwind_entry ((psprel
3482 ? output_rnat_psprel
3483 : output_rnat_sprel) (val));
3485 case REG_AR + AR_UNAT:
3486 add_unwind_entry (output_unat_when ());
3487 add_unwind_entry ((psprel
3488 ? output_unat_psprel
3489 : output_unat_sprel) (val));
3491 case REG_AR + AR_FPSR:
3492 add_unwind_entry (output_fpsr_when ());
3493 add_unwind_entry ((psprel
3494 ? output_fpsr_psprel
3495 : output_fpsr_sprel) (val));
3497 case REG_AR + AR_PFS:
3498 add_unwind_entry (output_pfs_when ());
3499 add_unwind_entry ((psprel
3501 : output_pfs_sprel) (val));
3503 case REG_AR + AR_LC:
3504 add_unwind_entry (output_lc_when ());
3505 add_unwind_entry ((psprel
3507 : output_lc_sprel) (val));
3510 add_unwind_entry (output_rp_when ());
3511 add_unwind_entry ((psprel
3513 : output_rp_sprel) (val));
3516 add_unwind_entry (output_preds_when ());
3517 add_unwind_entry ((psprel
3518 ? output_preds_psprel
3519 : output_preds_sprel) (val));
3522 add_unwind_entry (output_priunat_when_mem ());
3523 add_unwind_entry ((psprel
3524 ? output_priunat_psprel
3525 : output_priunat_sprel) (val));
3528 as_bad ("First operand not a valid register");
3532 as_bad (" Second operand not a valid constant");
3535 as_bad ("First operand not a register");
3540 int dummy ATTRIBUTE_UNUSED;
3544 sep = parse_operand (&e1);
3546 parse_operand (&e2);
3548 if (e1.X_op != O_constant)
3549 as_bad ("First operand to .save.g must be a constant.");
3552 int grmask = e1.X_add_number;
3554 add_unwind_entry (output_gr_mem (grmask));
3557 int reg = e2.X_add_number - REG_GR;
3558 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3559 add_unwind_entry (output_gr_gr (grmask, reg));
3561 as_bad ("Second operand is an invalid register.");
3568 int dummy ATTRIBUTE_UNUSED;
3572 sep = parse_operand (&e1);
3574 if (e1.X_op != O_constant)
3575 as_bad ("Operand to .save.f must be a constant.");
3577 add_unwind_entry (output_fr_mem (e1.X_add_number));
3582 int dummy ATTRIBUTE_UNUSED;
3589 sep = parse_operand (&e1);
3590 if (e1.X_op != O_constant)
3592 as_bad ("First operand to .save.b must be a constant.");
3595 brmask = e1.X_add_number;
3599 sep = parse_operand (&e2);
3600 reg = e2.X_add_number - REG_GR;
3601 if (e2.X_op != O_register || reg > 127)
3603 as_bad ("Second operand to .save.b must be a general register.");
3606 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3609 add_unwind_entry (output_br_mem (brmask));
3611 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3612 ignore_rest_of_line ();
3617 int dummy ATTRIBUTE_UNUSED;
3621 sep = parse_operand (&e1);
3623 parse_operand (&e2);
3625 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3626 as_bad ("Both operands of .save.gf must be constants.");
3629 int grmask = e1.X_add_number;
3630 int frmask = e2.X_add_number;
3631 add_unwind_entry (output_frgr_mem (grmask, frmask));
3637 int dummy ATTRIBUTE_UNUSED;
3642 sep = parse_operand (&e);
3643 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3644 ignore_rest_of_line ();
3646 if (e.X_op != O_constant)
3647 as_bad ("Operand to .spill must be a constant");
3649 add_unwind_entry (output_spill_base (e.X_add_number));
3653 dot_spillreg (dummy)
3654 int dummy ATTRIBUTE_UNUSED;
3656 int sep, ab, xy, reg, treg;
3659 sep = parse_operand (&e1);
3662 as_bad ("No second operand to .spillreg");
3666 parse_operand (&e2);
3668 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3670 as_bad ("First operand to .spillreg must be a preserved register");
3674 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3676 as_bad ("Second operand to .spillreg must be a register");
3680 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3684 dot_spillmem (psprel)
3690 sep = parse_operand (&e1);
3693 as_bad ("Second operand missing");
3697 parse_operand (&e2);
3699 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3701 as_bad ("First operand to .spill%s must be a preserved register",
3702 psprel ? "psp" : "sp");
3706 if (e2.X_op != O_constant)
3708 as_bad ("Second operand to .spill%s must be a constant",
3709 psprel ? "psp" : "sp");
3714 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3716 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3720 dot_spillreg_p (dummy)
3721 int dummy ATTRIBUTE_UNUSED;
3723 int sep, ab, xy, reg, treg;
3724 expressionS e1, e2, e3;
3727 sep = parse_operand (&e1);
3730 as_bad ("No second and third operand to .spillreg.p");
3734 sep = parse_operand (&e2);
3737 as_bad ("No third operand to .spillreg.p");
3741 parse_operand (&e3);
3743 qp = e1.X_add_number - REG_P;
3745 if (e1.X_op != O_register || qp > 63)
3747 as_bad ("First operand to .spillreg.p must be a predicate");
3751 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3753 as_bad ("Second operand to .spillreg.p must be a preserved register");
3757 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3759 as_bad ("Third operand to .spillreg.p must be a register");
3763 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3767 dot_spillmem_p (psprel)
3770 expressionS e1, e2, e3;
3774 sep = parse_operand (&e1);
3777 as_bad ("Second operand missing");
3781 parse_operand (&e2);
3784 as_bad ("Second operand missing");
3788 parse_operand (&e3);
3790 qp = e1.X_add_number - REG_P;
3791 if (e1.X_op != O_register || qp > 63)
3793 as_bad ("First operand to .spill%s_p must be a predicate",
3794 psprel ? "psp" : "sp");
3798 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3800 as_bad ("Second operand to .spill%s_p must be a preserved register",
3801 psprel ? "psp" : "sp");
3805 if (e3.X_op != O_constant)
3807 as_bad ("Third operand to .spill%s_p must be a constant",
3808 psprel ? "psp" : "sp");
3813 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3815 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3819 get_saved_prologue_count (lbl)
3822 label_prologue_count *lpc = unwind.saved_prologue_counts;
3824 while (lpc != NULL && lpc->label_number != lbl)
3828 return lpc->prologue_count;
3830 as_bad ("Missing .label_state %ld", lbl);
3835 save_prologue_count (lbl, count)
3839 label_prologue_count *lpc = unwind.saved_prologue_counts;
3841 while (lpc != NULL && lpc->label_number != lbl)
3845 lpc->prologue_count = count;
3848 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3850 new_lpc->next = unwind.saved_prologue_counts;
3851 new_lpc->label_number = lbl;
3852 new_lpc->prologue_count = count;
3853 unwind.saved_prologue_counts = new_lpc;
3858 free_saved_prologue_counts ()
3860 label_prologue_count *lpc = unwind.saved_prologue_counts;
3861 label_prologue_count *next;
3870 unwind.saved_prologue_counts = NULL;
3874 dot_label_state (dummy)
3875 int dummy ATTRIBUTE_UNUSED;
3880 if (e.X_op != O_constant)
3882 as_bad ("Operand to .label_state must be a constant");
3885 add_unwind_entry (output_label_state (e.X_add_number));
3886 save_prologue_count (e.X_add_number, unwind.prologue_count);
3890 dot_copy_state (dummy)
3891 int dummy ATTRIBUTE_UNUSED;
3896 if (e.X_op != O_constant)
3898 as_bad ("Operand to .copy_state must be a constant");
3901 add_unwind_entry (output_copy_state (e.X_add_number));
3902 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3907 int dummy ATTRIBUTE_UNUSED;
3912 sep = parse_operand (&e1);
3915 as_bad ("Second operand to .unwabi missing");
3918 sep = parse_operand (&e2);
3919 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3920 ignore_rest_of_line ();
3922 if (e1.X_op != O_constant)
3924 as_bad ("First operand to .unwabi must be a constant");
3928 if (e2.X_op != O_constant)
3930 as_bad ("Second operand to .unwabi must be a constant");
3934 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3938 dot_personality (dummy)
3939 int dummy ATTRIBUTE_UNUSED;
3943 name = input_line_pointer;
3944 c = get_symbol_end ();
3945 p = input_line_pointer;
3946 unwind.personality_routine = symbol_find_or_make (name);
3947 unwind.force_unwind_entry = 1;
3950 demand_empty_rest_of_line ();
3955 int dummy ATTRIBUTE_UNUSED;
3960 unwind.proc_start = expr_build_dot ();
3961 /* Parse names of main and alternate entry points and mark them as
3962 function symbols: */
3966 name = input_line_pointer;
3967 c = get_symbol_end ();
3968 p = input_line_pointer;
3969 sym = symbol_find_or_make (name);
3970 if (unwind.proc_start == 0)
3972 unwind.proc_start = sym;
3974 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3977 if (*input_line_pointer != ',')
3979 ++input_line_pointer;
3981 demand_empty_rest_of_line ();
3984 unwind.prologue_count = 0;
3985 unwind.list = unwind.tail = unwind.current_entry = NULL;
3986 unwind.personality_routine = 0;
3991 int dummy ATTRIBUTE_UNUSED;
3993 unwind.prologue = 0;
3994 unwind.prologue_mask = 0;
3996 add_unwind_entry (output_body ());
3997 demand_empty_rest_of_line ();
4001 dot_prologue (dummy)
4002 int dummy ATTRIBUTE_UNUSED;
4005 int mask = 0, grsave = 0;
4007 if (!is_it_end_of_statement ())
4010 sep = parse_operand (&e1);
4012 as_bad ("No second operand to .prologue");
4013 sep = parse_operand (&e2);
4014 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4015 ignore_rest_of_line ();
4017 if (e1.X_op == O_constant)
4019 mask = e1.X_add_number;
4021 if (e2.X_op == O_constant)
4022 grsave = e2.X_add_number;
4023 else if (e2.X_op == O_register
4024 && (grsave = e2.X_add_number - REG_GR) < 128)
4027 as_bad ("Second operand not a constant or general register");
4029 add_unwind_entry (output_prologue_gr (mask, grsave));
4032 as_bad ("First operand not a constant");
4035 add_unwind_entry (output_prologue ());
4037 unwind.prologue = 1;
4038 unwind.prologue_mask = mask;
4039 ++unwind.prologue_count;
4044 int dummy ATTRIBUTE_UNUSED;
4048 int bytes_per_address;
4051 subsegT saved_subseg;
4052 const char *sec_name, *text_name;
4056 if (unwind.saved_text_seg)
4058 saved_seg = unwind.saved_text_seg;
4059 saved_subseg = unwind.saved_text_subseg;
4060 unwind.saved_text_seg = NULL;
4064 saved_seg = now_seg;
4065 saved_subseg = now_subseg;
4069 Use a slightly ugly scheme to derive the unwind section names from
4070 the text section name:
4072 text sect. unwind table sect.
4073 name: name: comments:
4074 ---------- ----------------- --------------------------------
4076 .text.foo .IA_64.unwind.text.foo
4077 .foo .IA_64.unwind.foo
4079 .gnu.linkonce.ia64unw.foo
4080 _info .IA_64.unwind_info gas issues error message (ditto)
4081 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
4083 This mapping is done so that:
4085 (a) An object file with unwind info only in .text will use
4086 unwind section names .IA_64.unwind and .IA_64.unwind_info.
4087 This follows the letter of the ABI and also ensures backwards
4088 compatibility with older toolchains.
4090 (b) An object file with unwind info in multiple text sections
4091 will use separate unwind sections for each text section.
4092 This allows us to properly set the "sh_info" and "sh_link"
4093 fields in SHT_IA_64_UNWIND as required by the ABI and also
4094 lets GNU ld support programs with multiple segments
4095 containing unwind info (as might be the case for certain
4096 embedded applications).
4098 (c) An error is issued if there would be a name clash.
4100 text_name = segment_name (saved_seg);
4101 if (strncmp (text_name, "_info", 5) == 0)
4103 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
4105 ignore_rest_of_line ();
4108 if (strcmp (text_name, ".text") == 0)
4111 insn_group_break (1, 0, 0);
4113 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4115 generate_unwind_image (text_name);
4117 if (unwind.info || unwind.force_unwind_entry)
4119 subseg_set (md.last_text_seg, 0);
4120 unwind.proc_end = expr_build_dot ();
4122 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
4123 set_section ((char *) sec_name);
4124 bfd_set_section_flags (stdoutput, now_seg,
4125 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
4127 /* Make sure that section has 4 byte alignment for ILP32 and
4128 8 byte alignment for LP64. */
4129 record_alignment (now_seg, md.pointer_size_shift);
4131 /* Need space for 3 pointers for procedure start, procedure end,
4133 ptr = frag_more (3 * md.pointer_size);
4134 where = frag_now_fix () - (3 * md.pointer_size);
4135 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4137 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4138 e.X_op = O_pseudo_fixup;
4139 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4141 e.X_add_symbol = unwind.proc_start;
4142 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4144 e.X_op = O_pseudo_fixup;
4145 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4147 e.X_add_symbol = unwind.proc_end;
4148 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4149 bytes_per_address, &e);
4153 e.X_op = O_pseudo_fixup;
4154 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4156 e.X_add_symbol = unwind.info;
4157 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4158 bytes_per_address, &e);
4161 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4165 subseg_set (saved_seg, saved_subseg);
4167 /* Parse names of main and alternate entry points and set symbol sizes. */
4171 name = input_line_pointer;
4172 c = get_symbol_end ();
4173 p = input_line_pointer;
4174 sym = symbol_find (name);
4175 if (sym && unwind.proc_start
4176 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4177 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4179 fragS *fr = symbol_get_frag (unwind.proc_start);
4180 fragS *frag = symbol_get_frag (sym);
4182 /* Check whether the function label is at or beyond last
4184 while (fr && fr != frag)
4188 if (frag == frag_now && SEG_NORMAL (now_seg))
4189 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4192 symbol_get_obj (sym)->size =
4193 (expressionS *) xmalloc (sizeof (expressionS));
4194 symbol_get_obj (sym)->size->X_op = O_subtract;
4195 symbol_get_obj (sym)->size->X_add_symbol
4196 = symbol_new (FAKE_LABEL_NAME, now_seg,
4197 frag_now_fix (), frag_now);
4198 symbol_get_obj (sym)->size->X_op_symbol = sym;
4199 symbol_get_obj (sym)->size->X_add_number = 0;
4205 if (*input_line_pointer != ',')
4207 ++input_line_pointer;
4209 demand_empty_rest_of_line ();
4210 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4214 dot_template (template)
4217 CURR_SLOT.user_template = template;
4222 int dummy ATTRIBUTE_UNUSED;
4224 int ins, locs, outs, rots;
4226 if (is_it_end_of_statement ())
4227 ins = locs = outs = rots = 0;
4230 ins = get_absolute_expression ();
4231 if (*input_line_pointer++ != ',')
4233 locs = get_absolute_expression ();
4234 if (*input_line_pointer++ != ',')
4236 outs = get_absolute_expression ();
4237 if (*input_line_pointer++ != ',')
4239 rots = get_absolute_expression ();
4241 set_regstack (ins, locs, outs, rots);
4245 as_bad ("Comma expected");
4246 ignore_rest_of_line ();
4253 unsigned num_regs, num_alloced = 0;
4254 struct dynreg **drpp, *dr;
4255 int ch, base_reg = 0;
4261 case DYNREG_GR: base_reg = REG_GR + 32; break;
4262 case DYNREG_FR: base_reg = REG_FR + 32; break;
4263 case DYNREG_PR: base_reg = REG_P + 16; break;
4267 /* First, remove existing names from hash table. */
4268 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4270 hash_delete (md.dynreg_hash, dr->name);
4274 drpp = &md.dynreg[type];
4277 start = input_line_pointer;
4278 ch = get_symbol_end ();
4279 *input_line_pointer = ch;
4280 len = (input_line_pointer - start);
4283 if (*input_line_pointer != '[')
4285 as_bad ("Expected '['");
4288 ++input_line_pointer; /* skip '[' */
4290 num_regs = get_absolute_expression ();
4292 if (*input_line_pointer++ != ']')
4294 as_bad ("Expected ']'");
4299 num_alloced += num_regs;
4303 if (num_alloced > md.rot.num_regs)
4305 as_bad ("Used more than the declared %d rotating registers",
4311 if (num_alloced > 96)
4313 as_bad ("Used more than the available 96 rotating registers");
4318 if (num_alloced > 48)
4320 as_bad ("Used more than the available 48 rotating registers");
4329 name = obstack_alloc (¬es, len + 1);
4330 memcpy (name, start, len);
4335 *drpp = obstack_alloc (¬es, sizeof (*dr));
4336 memset (*drpp, 0, sizeof (*dr));
4341 dr->num_regs = num_regs;
4342 dr->base = base_reg;
4344 base_reg += num_regs;
4346 if (hash_insert (md.dynreg_hash, name, dr))
4348 as_bad ("Attempt to redefine register set `%s'", name);
4352 if (*input_line_pointer != ',')
4354 ++input_line_pointer; /* skip comma */
4357 demand_empty_rest_of_line ();
4361 ignore_rest_of_line ();
4365 dot_byteorder (byteorder)
4368 segment_info_type *seginfo = seg_info (now_seg);
4370 if (byteorder == -1)
4372 if (seginfo->tc_segment_info_data.endian == 0)
4373 seginfo->tc_segment_info_data.endian
4374 = TARGET_BYTES_BIG_ENDIAN ? 1 : 2;
4375 byteorder = seginfo->tc_segment_info_data.endian == 1;
4378 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4380 if (target_big_endian != byteorder)
4382 target_big_endian = byteorder;
4383 if (target_big_endian)
4385 ia64_number_to_chars = number_to_chars_bigendian;
4386 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4390 ia64_number_to_chars = number_to_chars_littleendian;
4391 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4398 int dummy ATTRIBUTE_UNUSED;
4405 option = input_line_pointer;
4406 ch = get_symbol_end ();
4407 if (strcmp (option, "lsb") == 0)
4408 md.flags &= ~EF_IA_64_BE;
4409 else if (strcmp (option, "msb") == 0)
4410 md.flags |= EF_IA_64_BE;
4411 else if (strcmp (option, "abi32") == 0)
4412 md.flags &= ~EF_IA_64_ABI64;
4413 else if (strcmp (option, "abi64") == 0)
4414 md.flags |= EF_IA_64_ABI64;
4416 as_bad ("Unknown psr option `%s'", option);
4417 *input_line_pointer = ch;
4420 if (*input_line_pointer != ',')
4423 ++input_line_pointer;
4426 demand_empty_rest_of_line ();
4431 int dummy ATTRIBUTE_UNUSED;
4433 new_logical_line (0, get_absolute_expression ());
4434 demand_empty_rest_of_line ();
4438 parse_section_name ()
4444 if (*input_line_pointer != '"')
4446 as_bad ("Missing section name");
4447 ignore_rest_of_line ();
4450 name = demand_copy_C_string (&len);
4453 ignore_rest_of_line ();
4457 if (*input_line_pointer != ',')
4459 as_bad ("Comma expected after section name");
4460 ignore_rest_of_line ();
4463 ++input_line_pointer; /* skip comma */
4471 char *name = parse_section_name ();
4475 md.keep_pending_output = 1;
4478 obj_elf_previous (0);
4479 md.keep_pending_output = 0;
4482 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4485 stmt_float_cons (kind)
4506 ia64_do_align (alignment);
4514 int saved_auto_align = md.auto_align;
4518 md.auto_align = saved_auto_align;
4522 dot_xfloat_cons (kind)
4525 char *name = parse_section_name ();
4529 md.keep_pending_output = 1;
4531 stmt_float_cons (kind);
4532 obj_elf_previous (0);
4533 md.keep_pending_output = 0;
4537 dot_xstringer (zero)
4540 char *name = parse_section_name ();
4544 md.keep_pending_output = 1;
4547 obj_elf_previous (0);
4548 md.keep_pending_output = 0;
4555 int saved_auto_align = md.auto_align;
4556 char *name = parse_section_name ();
4560 md.keep_pending_output = 1;
4564 md.auto_align = saved_auto_align;
4565 obj_elf_previous (0);
4566 md.keep_pending_output = 0;
4570 dot_xfloat_cons_ua (kind)
4573 int saved_auto_align = md.auto_align;
4574 char *name = parse_section_name ();
4578 md.keep_pending_output = 1;
4581 stmt_float_cons (kind);
4582 md.auto_align = saved_auto_align;
4583 obj_elf_previous (0);
4584 md.keep_pending_output = 0;
4587 /* .reg.val <regname>,value */
4591 int dummy ATTRIBUTE_UNUSED;
4596 if (reg.X_op != O_register)
4598 as_bad (_("Register name expected"));
4599 ignore_rest_of_line ();
4601 else if (*input_line_pointer++ != ',')
4603 as_bad (_("Comma expected"));
4604 ignore_rest_of_line ();
4608 valueT value = get_absolute_expression ();
4609 int regno = reg.X_add_number;
4610 if (regno < REG_GR || regno > REG_GR + 128)
4611 as_warn (_("Register value annotation ignored"));
4614 gr_values[regno - REG_GR].known = 1;
4615 gr_values[regno - REG_GR].value = value;
4616 gr_values[regno - REG_GR].path = md.path;
4619 demand_empty_rest_of_line ();
4622 /* select dv checking mode
4627 A stop is inserted when changing modes
4634 if (md.manual_bundling)
4635 as_warn (_("Directive invalid within a bundle"));
4637 if (type == 'E' || type == 'A')
4638 md.mode_explicitly_set = 0;
4640 md.mode_explicitly_set = 1;
4647 if (md.explicit_mode)
4648 insn_group_break (1, 0, 0);
4649 md.explicit_mode = 0;
4653 if (!md.explicit_mode)
4654 insn_group_break (1, 0, 0);
4655 md.explicit_mode = 1;
4659 if (md.explicit_mode != md.default_explicit_mode)
4660 insn_group_break (1, 0, 0);
4661 md.explicit_mode = md.default_explicit_mode;
4662 md.mode_explicitly_set = 0;
4673 for (regno = 0; regno < 64; regno++)
4675 if (mask & ((valueT) 1 << regno))
4677 fprintf (stderr, "%s p%d", comma, regno);
4684 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4685 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4686 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4687 .pred.safe_across_calls p1 [, p2 [,...]]
4696 int p1 = -1, p2 = -1;
4700 if (*input_line_pointer != '"')
4702 as_bad (_("Missing predicate relation type"));
4703 ignore_rest_of_line ();
4709 char *form = demand_copy_C_string (&len);
4710 if (strcmp (form, "mutex") == 0)
4712 else if (strcmp (form, "clear") == 0)
4714 else if (strcmp (form, "imply") == 0)
4718 as_bad (_("Unrecognized predicate relation type"));
4719 ignore_rest_of_line ();
4723 if (*input_line_pointer == ',')
4724 ++input_line_pointer;
4734 if (TOUPPER (*input_line_pointer) != 'P'
4735 || (regno = atoi (++input_line_pointer)) < 0
4738 as_bad (_("Predicate register expected"));
4739 ignore_rest_of_line ();
4742 while (ISDIGIT (*input_line_pointer))
4743 ++input_line_pointer;
4750 as_warn (_("Duplicate predicate register ignored"));
4753 /* See if it's a range. */
4754 if (*input_line_pointer == '-')
4757 ++input_line_pointer;
4759 if (TOUPPER (*input_line_pointer) != 'P'
4760 || (regno = atoi (++input_line_pointer)) < 0
4763 as_bad (_("Predicate register expected"));
4764 ignore_rest_of_line ();
4767 while (ISDIGIT (*input_line_pointer))
4768 ++input_line_pointer;
4772 as_bad (_("Bad register range"));
4773 ignore_rest_of_line ();
4784 if (*input_line_pointer != ',')
4786 ++input_line_pointer;
4795 clear_qp_mutex (mask);
4796 clear_qp_implies (mask, (valueT) 0);
4799 if (count != 2 || p1 == -1 || p2 == -1)
4800 as_bad (_("Predicate source and target required"));
4801 else if (p1 == 0 || p2 == 0)
4802 as_bad (_("Use of p0 is not valid in this context"));
4804 add_qp_imply (p1, p2);
4809 as_bad (_("At least two PR arguments expected"));
4814 as_bad (_("Use of p0 is not valid in this context"));
4817 add_qp_mutex (mask);
4820 /* note that we don't override any existing relations */
4823 as_bad (_("At least one PR argument expected"));
4828 fprintf (stderr, "Safe across calls: ");
4829 print_prmask (mask);
4830 fprintf (stderr, "\n");
4832 qp_safe_across_calls = mask;
4835 demand_empty_rest_of_line ();
4838 /* .entry label [, label [, ...]]
4839 Hint to DV code that the given labels are to be considered entry points.
4840 Otherwise, only global labels are considered entry points. */
4844 int dummy ATTRIBUTE_UNUSED;
4853 name = input_line_pointer;
4854 c = get_symbol_end ();
4855 symbolP = symbol_find_or_make (name);
4857 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4859 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4862 *input_line_pointer = c;
4864 c = *input_line_pointer;
4867 input_line_pointer++;
4869 if (*input_line_pointer == '\n')
4875 demand_empty_rest_of_line ();
4878 /* .mem.offset offset, base
4879 "base" is used to distinguish between offsets from a different base. */
4882 dot_mem_offset (dummy)
4883 int dummy ATTRIBUTE_UNUSED;
4885 md.mem_offset.hint = 1;
4886 md.mem_offset.offset = get_absolute_expression ();
4887 if (*input_line_pointer != ',')
4889 as_bad (_("Comma expected"));
4890 ignore_rest_of_line ();
4893 ++input_line_pointer;
4894 md.mem_offset.base = get_absolute_expression ();
4895 demand_empty_rest_of_line ();
4898 /* ia64-specific pseudo-ops: */
4899 const pseudo_typeS md_pseudo_table[] =
4901 { "radix", dot_radix, 0 },
4902 { "lcomm", s_lcomm_bytes, 1 },
4903 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4904 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4905 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4906 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4907 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4908 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4909 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4910 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4911 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4912 { "proc", dot_proc, 0 },
4913 { "body", dot_body, 0 },
4914 { "prologue", dot_prologue, 0 },
4915 { "endp", dot_endp, 0 },
4917 { "fframe", dot_fframe, 0 },
4918 { "vframe", dot_vframe, 0 },
4919 { "vframesp", dot_vframesp, 0 },
4920 { "vframepsp", dot_vframepsp, 0 },
4921 { "save", dot_save, 0 },
4922 { "restore", dot_restore, 0 },
4923 { "restorereg", dot_restorereg, 0 },
4924 { "restorereg.p", dot_restorereg_p, 0 },
4925 { "handlerdata", dot_handlerdata, 0 },
4926 { "unwentry", dot_unwentry, 0 },
4927 { "altrp", dot_altrp, 0 },
4928 { "savesp", dot_savemem, 0 },
4929 { "savepsp", dot_savemem, 1 },
4930 { "save.g", dot_saveg, 0 },
4931 { "save.f", dot_savef, 0 },
4932 { "save.b", dot_saveb, 0 },
4933 { "save.gf", dot_savegf, 0 },
4934 { "spill", dot_spill, 0 },
4935 { "spillreg", dot_spillreg, 0 },
4936 { "spillsp", dot_spillmem, 0 },
4937 { "spillpsp", dot_spillmem, 1 },
4938 { "spillreg.p", dot_spillreg_p, 0 },
4939 { "spillsp.p", dot_spillmem_p, 0 },
4940 { "spillpsp.p", dot_spillmem_p, 1 },
4941 { "label_state", dot_label_state, 0 },
4942 { "copy_state", dot_copy_state, 0 },
4943 { "unwabi", dot_unwabi, 0 },
4944 { "personality", dot_personality, 0 },
4946 { "estate", dot_estate, 0 },
4948 { "mii", dot_template, 0x0 },
4949 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4950 { "mlx", dot_template, 0x2 },
4951 { "mmi", dot_template, 0x4 },
4952 { "mfi", dot_template, 0x6 },
4953 { "mmf", dot_template, 0x7 },
4954 { "mib", dot_template, 0x8 },
4955 { "mbb", dot_template, 0x9 },
4956 { "bbb", dot_template, 0xb },
4957 { "mmb", dot_template, 0xc },
4958 { "mfb", dot_template, 0xe },
4960 { "lb", dot_scope, 0 },
4961 { "le", dot_scope, 1 },
4963 { "align", s_align_bytes, 0 },
4964 { "regstk", dot_regstk, 0 },
4965 { "rotr", dot_rot, DYNREG_GR },
4966 { "rotf", dot_rot, DYNREG_FR },
4967 { "rotp", dot_rot, DYNREG_PR },
4968 { "lsb", dot_byteorder, 0 },
4969 { "msb", dot_byteorder, 1 },
4970 { "psr", dot_psr, 0 },
4971 { "alias", dot_alias, 0 },
4972 { "secalias", dot_alias, 1 },
4973 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4975 { "xdata1", dot_xdata, 1 },
4976 { "xdata2", dot_xdata, 2 },
4977 { "xdata4", dot_xdata, 4 },
4978 { "xdata8", dot_xdata, 8 },
4979 { "xreal4", dot_xfloat_cons, 'f' },
4980 { "xreal8", dot_xfloat_cons, 'd' },
4981 { "xreal10", dot_xfloat_cons, 'x' },
4982 { "xreal16", dot_xfloat_cons, 'X' },
4983 { "xstring", dot_xstringer, 0 },
4984 { "xstringz", dot_xstringer, 1 },
4986 /* unaligned versions: */
4987 { "xdata2.ua", dot_xdata_ua, 2 },
4988 { "xdata4.ua", dot_xdata_ua, 4 },
4989 { "xdata8.ua", dot_xdata_ua, 8 },
4990 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4991 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4992 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4993 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
4995 /* annotations/DV checking support */
4996 { "entry", dot_entry, 0 },
4997 { "mem.offset", dot_mem_offset, 0 },
4998 { "pred.rel", dot_pred_rel, 0 },
4999 { "pred.rel.clear", dot_pred_rel, 'c' },
5000 { "pred.rel.imply", dot_pred_rel, 'i' },
5001 { "pred.rel.mutex", dot_pred_rel, 'm' },
5002 { "pred.safe_across_calls", dot_pred_rel, 's' },
5003 { "reg.val", dot_reg_val, 0 },
5004 { "auto", dot_dv_mode, 'a' },
5005 { "explicit", dot_dv_mode, 'e' },
5006 { "default", dot_dv_mode, 'd' },
5008 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5009 IA-64 aligns data allocation pseudo-ops by default, so we have to
5010 tell it that these ones are supposed to be unaligned. Long term,
5011 should rewrite so that only IA-64 specific data allocation pseudo-ops
5012 are aligned by default. */
5013 {"2byte", stmt_cons_ua, 2},
5014 {"4byte", stmt_cons_ua, 4},
5015 {"8byte", stmt_cons_ua, 8},
5020 static const struct pseudo_opcode
5023 void (*handler) (int);
5028 /* these are more like pseudo-ops, but don't start with a dot */
5029 { "data1", cons, 1 },
5030 { "data2", cons, 2 },
5031 { "data4", cons, 4 },
5032 { "data8", cons, 8 },
5033 { "data16", cons, 16 },
5034 { "real4", stmt_float_cons, 'f' },
5035 { "real8", stmt_float_cons, 'd' },
5036 { "real10", stmt_float_cons, 'x' },
5037 { "real16", stmt_float_cons, 'X' },
5038 { "string", stringer, 0 },
5039 { "stringz", stringer, 1 },
5041 /* unaligned versions: */
5042 { "data2.ua", stmt_cons_ua, 2 },
5043 { "data4.ua", stmt_cons_ua, 4 },
5044 { "data8.ua", stmt_cons_ua, 8 },
5045 { "data16.ua", stmt_cons_ua, 16 },
5046 { "real4.ua", float_cons, 'f' },
5047 { "real8.ua", float_cons, 'd' },
5048 { "real10.ua", float_cons, 'x' },
5049 { "real16.ua", float_cons, 'X' },
5052 /* Declare a register by creating a symbol for it and entering it in
5053 the symbol table. */
5056 declare_register (name, regnum)
5063 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5065 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5067 as_fatal ("Inserting \"%s\" into register table failed: %s",
5074 declare_register_set (prefix, num_regs, base_regnum)
5082 for (i = 0; i < num_regs; ++i)
5084 sprintf (name, "%s%u", prefix, i);
5085 declare_register (name, base_regnum + i);
5090 operand_width (opnd)
5091 enum ia64_opnd opnd;
5093 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5094 unsigned int bits = 0;
5098 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5099 bits += odesc->field[i].bits;
5104 static enum operand_match_result
5105 operand_match (idesc, index, e)
5106 const struct ia64_opcode *idesc;
5110 enum ia64_opnd opnd = idesc->operands[index];
5111 int bits, relocatable = 0;
5112 struct insn_fix *fix;
5119 case IA64_OPND_AR_CCV:
5120 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5121 return OPERAND_MATCH;
5124 case IA64_OPND_AR_CSD:
5125 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5126 return OPERAND_MATCH;
5129 case IA64_OPND_AR_PFS:
5130 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5131 return OPERAND_MATCH;
5135 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5136 return OPERAND_MATCH;
5140 if (e->X_op == O_register && e->X_add_number == REG_IP)
5141 return OPERAND_MATCH;
5145 if (e->X_op == O_register && e->X_add_number == REG_PR)
5146 return OPERAND_MATCH;
5149 case IA64_OPND_PR_ROT:
5150 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5151 return OPERAND_MATCH;
5155 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5156 return OPERAND_MATCH;
5159 case IA64_OPND_PSR_L:
5160 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5161 return OPERAND_MATCH;
5164 case IA64_OPND_PSR_UM:
5165 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5166 return OPERAND_MATCH;
5170 if (e->X_op == O_constant)
5172 if (e->X_add_number == 1)
5173 return OPERAND_MATCH;
5175 return OPERAND_OUT_OF_RANGE;
5180 if (e->X_op == O_constant)
5182 if (e->X_add_number == 8)
5183 return OPERAND_MATCH;
5185 return OPERAND_OUT_OF_RANGE;
5190 if (e->X_op == O_constant)
5192 if (e->X_add_number == 16)
5193 return OPERAND_MATCH;
5195 return OPERAND_OUT_OF_RANGE;
5199 /* register operands: */
5202 if (e->X_op == O_register && e->X_add_number >= REG_AR
5203 && e->X_add_number < REG_AR + 128)
5204 return OPERAND_MATCH;
5209 if (e->X_op == O_register && e->X_add_number >= REG_BR
5210 && e->X_add_number < REG_BR + 8)
5211 return OPERAND_MATCH;
5215 if (e->X_op == O_register && e->X_add_number >= REG_CR
5216 && e->X_add_number < REG_CR + 128)
5217 return OPERAND_MATCH;
5224 if (e->X_op == O_register && e->X_add_number >= REG_FR
5225 && e->X_add_number < REG_FR + 128)
5226 return OPERAND_MATCH;
5231 if (e->X_op == O_register && e->X_add_number >= REG_P
5232 && e->X_add_number < REG_P + 64)
5233 return OPERAND_MATCH;
5239 if (e->X_op == O_register && e->X_add_number >= REG_GR
5240 && e->X_add_number < REG_GR + 128)
5241 return OPERAND_MATCH;
5244 case IA64_OPND_R3_2:
5245 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5247 if (e->X_add_number < REG_GR + 4)
5248 return OPERAND_MATCH;
5249 else if (e->X_add_number < REG_GR + 128)
5250 return OPERAND_OUT_OF_RANGE;
5254 /* indirect operands: */
5255 case IA64_OPND_CPUID_R3:
5256 case IA64_OPND_DBR_R3:
5257 case IA64_OPND_DTR_R3:
5258 case IA64_OPND_ITR_R3:
5259 case IA64_OPND_IBR_R3:
5260 case IA64_OPND_MSR_R3:
5261 case IA64_OPND_PKR_R3:
5262 case IA64_OPND_PMC_R3:
5263 case IA64_OPND_PMD_R3:
5264 case IA64_OPND_RR_R3:
5265 if (e->X_op == O_index && e->X_op_symbol
5266 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5267 == opnd - IA64_OPND_CPUID_R3))
5268 return OPERAND_MATCH;
5272 if (e->X_op == O_index && !e->X_op_symbol)
5273 return OPERAND_MATCH;
5276 /* immediate operands: */
5277 case IA64_OPND_CNT2a:
5278 case IA64_OPND_LEN4:
5279 case IA64_OPND_LEN6:
5280 bits = operand_width (idesc->operands[index]);
5281 if (e->X_op == O_constant)
5283 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5284 return OPERAND_MATCH;
5286 return OPERAND_OUT_OF_RANGE;
5290 case IA64_OPND_CNT2b:
5291 if (e->X_op == O_constant)
5293 if ((bfd_vma) (e->X_add_number - 1) < 3)
5294 return OPERAND_MATCH;
5296 return OPERAND_OUT_OF_RANGE;
5300 case IA64_OPND_CNT2c:
5301 val = e->X_add_number;
5302 if (e->X_op == O_constant)
5304 if ((val == 0 || val == 7 || val == 15 || val == 16))
5305 return OPERAND_MATCH;
5307 return OPERAND_OUT_OF_RANGE;
5312 /* SOR must be an integer multiple of 8 */
5313 if (e->X_op == O_constant && e->X_add_number & 0x7)
5314 return OPERAND_OUT_OF_RANGE;
5317 if (e->X_op == O_constant)
5319 if ((bfd_vma) e->X_add_number <= 96)
5320 return OPERAND_MATCH;
5322 return OPERAND_OUT_OF_RANGE;
5326 case IA64_OPND_IMMU62:
5327 if (e->X_op == O_constant)
5329 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5330 return OPERAND_MATCH;
5332 return OPERAND_OUT_OF_RANGE;
5336 /* FIXME -- need 62-bit relocation type */
5337 as_bad (_("62-bit relocation not yet implemented"));
5341 case IA64_OPND_IMMU64:
5342 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5343 || e->X_op == O_subtract)
5345 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5346 fix->code = BFD_RELOC_IA64_IMM64;
5347 if (e->X_op != O_subtract)
5349 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5350 if (e->X_op == O_pseudo_fixup)
5354 fix->opnd = idesc->operands[index];
5357 ++CURR_SLOT.num_fixups;
5358 return OPERAND_MATCH;
5360 else if (e->X_op == O_constant)
5361 return OPERAND_MATCH;
5364 case IA64_OPND_CCNT5:
5365 case IA64_OPND_CNT5:
5366 case IA64_OPND_CNT6:
5367 case IA64_OPND_CPOS6a:
5368 case IA64_OPND_CPOS6b:
5369 case IA64_OPND_CPOS6c:
5370 case IA64_OPND_IMMU2:
5371 case IA64_OPND_IMMU7a:
5372 case IA64_OPND_IMMU7b:
5373 case IA64_OPND_IMMU21:
5374 case IA64_OPND_IMMU24:
5375 case IA64_OPND_MBTYPE4:
5376 case IA64_OPND_MHTYPE8:
5377 case IA64_OPND_POS6:
5378 bits = operand_width (idesc->operands[index]);
5379 if (e->X_op == O_constant)
5381 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5382 return OPERAND_MATCH;
5384 return OPERAND_OUT_OF_RANGE;
5388 case IA64_OPND_IMMU9:
5389 bits = operand_width (idesc->operands[index]);
5390 if (e->X_op == O_constant)
5392 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5394 int lobits = e->X_add_number & 0x3;
5395 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5396 e->X_add_number |= (bfd_vma) 0x3;
5397 return OPERAND_MATCH;
5400 return OPERAND_OUT_OF_RANGE;
5404 case IA64_OPND_IMM44:
5405 /* least 16 bits must be zero */
5406 if ((e->X_add_number & 0xffff) != 0)
5407 /* XXX technically, this is wrong: we should not be issuing warning
5408 messages until we're sure this instruction pattern is going to
5410 as_warn (_("lower 16 bits of mask ignored"));
5412 if (e->X_op == O_constant)
5414 if (((e->X_add_number >= 0
5415 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5416 || (e->X_add_number < 0
5417 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5420 if (e->X_add_number >= 0
5421 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5423 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5425 return OPERAND_MATCH;
5428 return OPERAND_OUT_OF_RANGE;
5432 case IA64_OPND_IMM17:
5433 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5434 if (e->X_op == O_constant)
5436 if (((e->X_add_number >= 0
5437 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5438 || (e->X_add_number < 0
5439 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5442 if (e->X_add_number >= 0
5443 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5445 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5447 return OPERAND_MATCH;
5450 return OPERAND_OUT_OF_RANGE;
5454 case IA64_OPND_IMM14:
5455 case IA64_OPND_IMM22:
5457 case IA64_OPND_IMM1:
5458 case IA64_OPND_IMM8:
5459 case IA64_OPND_IMM8U4:
5460 case IA64_OPND_IMM8M1:
5461 case IA64_OPND_IMM8M1U4:
5462 case IA64_OPND_IMM8M1U8:
5463 case IA64_OPND_IMM9a:
5464 case IA64_OPND_IMM9b:
5465 bits = operand_width (idesc->operands[index]);
5466 if (relocatable && (e->X_op == O_symbol
5467 || e->X_op == O_subtract
5468 || e->X_op == O_pseudo_fixup))
5470 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5472 if (idesc->operands[index] == IA64_OPND_IMM14)
5473 fix->code = BFD_RELOC_IA64_IMM14;
5475 fix->code = BFD_RELOC_IA64_IMM22;
5477 if (e->X_op != O_subtract)
5479 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5480 if (e->X_op == O_pseudo_fixup)
5484 fix->opnd = idesc->operands[index];
5487 ++CURR_SLOT.num_fixups;
5488 return OPERAND_MATCH;
5490 else if (e->X_op != O_constant
5491 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5492 return OPERAND_MISMATCH;
5494 if (opnd == IA64_OPND_IMM8M1U4)
5496 /* Zero is not valid for unsigned compares that take an adjusted
5497 constant immediate range. */
5498 if (e->X_add_number == 0)
5499 return OPERAND_OUT_OF_RANGE;
5501 /* Sign-extend 32-bit unsigned numbers, so that the following range
5502 checks will work. */
5503 val = e->X_add_number;
5504 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5505 && ((val & ((bfd_vma) 1 << 31)) != 0))
5506 val = ((val << 32) >> 32);
5508 /* Check for 0x100000000. This is valid because
5509 0x100000000-1 is the same as ((uint32_t) -1). */
5510 if (val == ((bfd_signed_vma) 1 << 32))
5511 return OPERAND_MATCH;
5515 else if (opnd == IA64_OPND_IMM8M1U8)
5517 /* Zero is not valid for unsigned compares that take an adjusted
5518 constant immediate range. */
5519 if (e->X_add_number == 0)
5520 return OPERAND_OUT_OF_RANGE;
5522 /* Check for 0x10000000000000000. */
5523 if (e->X_op == O_big)
5525 if (generic_bignum[0] == 0
5526 && generic_bignum[1] == 0
5527 && generic_bignum[2] == 0
5528 && generic_bignum[3] == 0
5529 && generic_bignum[4] == 1)
5530 return OPERAND_MATCH;
5532 return OPERAND_OUT_OF_RANGE;
5535 val = e->X_add_number - 1;
5537 else if (opnd == IA64_OPND_IMM8M1)
5538 val = e->X_add_number - 1;
5539 else if (opnd == IA64_OPND_IMM8U4)
5541 /* Sign-extend 32-bit unsigned numbers, so that the following range
5542 checks will work. */
5543 val = e->X_add_number;
5544 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5545 && ((val & ((bfd_vma) 1 << 31)) != 0))
5546 val = ((val << 32) >> 32);
5549 val = e->X_add_number;
5551 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5552 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5553 return OPERAND_MATCH;
5555 return OPERAND_OUT_OF_RANGE;
5557 case IA64_OPND_INC3:
5558 /* +/- 1, 4, 8, 16 */
5559 val = e->X_add_number;
5562 if (e->X_op == O_constant)
5564 if ((val == 1 || val == 4 || val == 8 || val == 16))
5565 return OPERAND_MATCH;
5567 return OPERAND_OUT_OF_RANGE;
5571 case IA64_OPND_TGT25:
5572 case IA64_OPND_TGT25b:
5573 case IA64_OPND_TGT25c:
5574 case IA64_OPND_TGT64:
5575 if (e->X_op == O_symbol)
5577 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5578 if (opnd == IA64_OPND_TGT25)
5579 fix->code = BFD_RELOC_IA64_PCREL21F;
5580 else if (opnd == IA64_OPND_TGT25b)
5581 fix->code = BFD_RELOC_IA64_PCREL21M;
5582 else if (opnd == IA64_OPND_TGT25c)
5583 fix->code = BFD_RELOC_IA64_PCREL21B;
5584 else if (opnd == IA64_OPND_TGT64)
5585 fix->code = BFD_RELOC_IA64_PCREL60B;
5589 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5590 fix->opnd = idesc->operands[index];
5593 ++CURR_SLOT.num_fixups;
5594 return OPERAND_MATCH;
5596 case IA64_OPND_TAG13:
5597 case IA64_OPND_TAG13b:
5601 return OPERAND_MATCH;
5604 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5605 /* There are no external relocs for TAG13/TAG13b fields, so we
5606 create a dummy reloc. This will not live past md_apply_fix3. */
5607 fix->code = BFD_RELOC_UNUSED;
5608 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5609 fix->opnd = idesc->operands[index];
5612 ++CURR_SLOT.num_fixups;
5613 return OPERAND_MATCH;
5620 case IA64_OPND_LDXMOV:
5621 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5622 fix->code = BFD_RELOC_IA64_LDXMOV;
5623 fix->opnd = idesc->operands[index];
5626 ++CURR_SLOT.num_fixups;
5627 return OPERAND_MATCH;
5632 return OPERAND_MISMATCH;
5641 memset (e, 0, sizeof (*e));
5644 if (*input_line_pointer != '}')
5646 sep = *input_line_pointer++;
5650 if (!md.manual_bundling)
5651 as_warn ("Found '}' when manual bundling is off");
5653 CURR_SLOT.manual_bundling_off = 1;
5654 md.manual_bundling = 0;
5660 /* Returns the next entry in the opcode table that matches the one in
5661 IDESC, and frees the entry in IDESC. If no matching entry is
5662 found, NULL is returned instead. */
5664 static struct ia64_opcode *
5665 get_next_opcode (struct ia64_opcode *idesc)
5667 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5668 ia64_free_opcode (idesc);
5672 /* Parse the operands for the opcode and find the opcode variant that
5673 matches the specified operands, or NULL if no match is possible. */
5675 static struct ia64_opcode *
5676 parse_operands (idesc)
5677 struct ia64_opcode *idesc;
5679 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5680 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5681 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5682 enum operand_match_result result;
5684 char *first_arg = 0, *end, *saved_input_pointer;
5687 assert (strlen (idesc->name) <= 128);
5689 strcpy (mnemonic, idesc->name);
5690 if (idesc->operands[2] == IA64_OPND_SOF)
5692 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5693 can't parse the first operand until we have parsed the
5694 remaining operands of the "alloc" instruction. */
5696 first_arg = input_line_pointer;
5697 end = strchr (input_line_pointer, '=');
5700 as_bad ("Expected separator `='");
5703 input_line_pointer = end + 1;
5708 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5710 sep = parse_operand (CURR_SLOT.opnd + i);
5711 if (CURR_SLOT.opnd[i].X_op == O_absent)
5716 if (sep != '=' && sep != ',')
5721 if (num_outputs > 0)
5722 as_bad ("Duplicate equal sign (=) in instruction");
5724 num_outputs = i + 1;
5729 as_bad ("Illegal operand separator `%c'", sep);
5733 if (idesc->operands[2] == IA64_OPND_SOF)
5735 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5736 know (strcmp (idesc->name, "alloc") == 0);
5737 if (num_operands == 5 /* first_arg not included in this count! */
5738 && CURR_SLOT.opnd[2].X_op == O_constant
5739 && CURR_SLOT.opnd[3].X_op == O_constant
5740 && CURR_SLOT.opnd[4].X_op == O_constant
5741 && CURR_SLOT.opnd[5].X_op == O_constant)
5743 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5744 CURR_SLOT.opnd[3].X_add_number,
5745 CURR_SLOT.opnd[4].X_add_number,
5746 CURR_SLOT.opnd[5].X_add_number);
5748 /* now we can parse the first arg: */
5749 saved_input_pointer = input_line_pointer;
5750 input_line_pointer = first_arg;
5751 sep = parse_operand (CURR_SLOT.opnd + 0);
5753 --num_outputs; /* force error */
5754 input_line_pointer = saved_input_pointer;
5756 CURR_SLOT.opnd[2].X_add_number = sof;
5757 CURR_SLOT.opnd[3].X_add_number
5758 = sof - CURR_SLOT.opnd[4].X_add_number;
5759 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5763 highest_unmatched_operand = 0;
5764 curr_out_of_range_pos = -1;
5766 expected_operand = idesc->operands[0];
5767 for (; idesc; idesc = get_next_opcode (idesc))
5769 if (num_outputs != idesc->num_outputs)
5770 continue; /* mismatch in # of outputs */
5772 CURR_SLOT.num_fixups = 0;
5774 /* Try to match all operands. If we see an out-of-range operand,
5775 then continue trying to match the rest of the operands, since if
5776 the rest match, then this idesc will give the best error message. */
5778 out_of_range_pos = -1;
5779 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5781 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5782 if (result != OPERAND_MATCH)
5784 if (result != OPERAND_OUT_OF_RANGE)
5786 if (out_of_range_pos < 0)
5787 /* remember position of the first out-of-range operand: */
5788 out_of_range_pos = i;
5792 /* If we did not match all operands, or if at least one operand was
5793 out-of-range, then this idesc does not match. Keep track of which
5794 idesc matched the most operands before failing. If we have two
5795 idescs that failed at the same position, and one had an out-of-range
5796 operand, then prefer the out-of-range operand. Thus if we have
5797 "add r0=0x1000000,r1" we get an error saying the constant is out
5798 of range instead of an error saying that the constant should have been
5801 if (i != num_operands || out_of_range_pos >= 0)
5803 if (i > highest_unmatched_operand
5804 || (i == highest_unmatched_operand
5805 && out_of_range_pos > curr_out_of_range_pos))
5807 highest_unmatched_operand = i;
5808 if (out_of_range_pos >= 0)
5810 expected_operand = idesc->operands[out_of_range_pos];
5811 error_pos = out_of_range_pos;
5815 expected_operand = idesc->operands[i];
5818 curr_out_of_range_pos = out_of_range_pos;
5823 if (num_operands < NELEMS (idesc->operands)
5824 && idesc->operands[num_operands])
5825 continue; /* mismatch in number of arguments */
5831 if (expected_operand)
5832 as_bad ("Operand %u of `%s' should be %s",
5833 error_pos + 1, mnemonic,
5834 elf64_ia64_operands[expected_operand].desc);
5836 as_bad ("Operand mismatch");
5842 /* Keep track of state necessary to determine whether a NOP is necessary
5843 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5844 detect a case where additional NOPs may be necessary. */
5846 errata_nop_necessary_p (slot, insn_unit)
5848 enum ia64_unit insn_unit;
5851 struct group *this_group = md.last_groups + md.group_idx;
5852 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5853 struct ia64_opcode *idesc = slot->idesc;
5855 /* Test whether this could be the first insn in a problematic sequence. */
5856 if (insn_unit == IA64_UNIT_F)
5858 for (i = 0; i < idesc->num_outputs; i++)
5859 if (idesc->operands[i] == IA64_OPND_P1
5860 || idesc->operands[i] == IA64_OPND_P2)
5862 int regno = slot->opnd[i].X_add_number - REG_P;
5863 /* Ignore invalid operands; they generate errors elsewhere. */
5866 this_group->p_reg_set[regno] = 1;
5870 /* Test whether this could be the second insn in a problematic sequence. */
5871 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5872 && prev_group->p_reg_set[slot->qp_regno])
5874 for (i = 0; i < idesc->num_outputs; i++)
5875 if (idesc->operands[i] == IA64_OPND_R1
5876 || idesc->operands[i] == IA64_OPND_R2
5877 || idesc->operands[i] == IA64_OPND_R3)
5879 int regno = slot->opnd[i].X_add_number - REG_GR;
5880 /* Ignore invalid operands; they generate errors elsewhere. */
5883 if (strncmp (idesc->name, "add", 3) != 0
5884 && strncmp (idesc->name, "sub", 3) != 0
5885 && strncmp (idesc->name, "shladd", 6) != 0
5886 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5887 this_group->g_reg_set_conditionally[regno] = 1;
5891 /* Test whether this could be the third insn in a problematic sequence. */
5892 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5894 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5895 idesc->operands[i] == IA64_OPND_R3
5896 /* For mov indirect. */
5897 || idesc->operands[i] == IA64_OPND_RR_R3
5898 || idesc->operands[i] == IA64_OPND_DBR_R3
5899 || idesc->operands[i] == IA64_OPND_IBR_R3
5900 || idesc->operands[i] == IA64_OPND_PKR_R3
5901 || idesc->operands[i] == IA64_OPND_PMC_R3
5902 || idesc->operands[i] == IA64_OPND_PMD_R3
5903 || idesc->operands[i] == IA64_OPND_MSR_R3
5904 || idesc->operands[i] == IA64_OPND_CPUID_R3
5906 || idesc->operands[i] == IA64_OPND_ITR_R3
5907 || idesc->operands[i] == IA64_OPND_DTR_R3
5908 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5909 || idesc->operands[i] == IA64_OPND_MR3)
5911 int regno = slot->opnd[i].X_add_number - REG_GR;
5912 /* Ignore invalid operands; they generate errors elsewhere. */
5915 if (idesc->operands[i] == IA64_OPND_R3)
5917 if (strcmp (idesc->name, "fc") != 0
5918 && strcmp (idesc->name, "tak") != 0
5919 && strcmp (idesc->name, "thash") != 0
5920 && strcmp (idesc->name, "tpa") != 0
5921 && strcmp (idesc->name, "ttag") != 0
5922 && strncmp (idesc->name, "ptr", 3) != 0
5923 && strncmp (idesc->name, "ptc", 3) != 0
5924 && strncmp (idesc->name, "probe", 5) != 0)
5927 if (prev_group->g_reg_set_conditionally[regno])
5935 build_insn (slot, insnp)
5939 const struct ia64_operand *odesc, *o2desc;
5940 struct ia64_opcode *idesc = slot->idesc;
5941 bfd_signed_vma insn, val;
5945 insn = idesc->opcode | slot->qp_regno;
5947 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5949 if (slot->opnd[i].X_op == O_register
5950 || slot->opnd[i].X_op == O_constant
5951 || slot->opnd[i].X_op == O_index)
5952 val = slot->opnd[i].X_add_number;
5953 else if (slot->opnd[i].X_op == O_big)
5955 /* This must be the value 0x10000000000000000. */
5956 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5962 switch (idesc->operands[i])
5964 case IA64_OPND_IMMU64:
5965 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5966 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5967 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5968 | (((val >> 63) & 0x1) << 36));
5971 case IA64_OPND_IMMU62:
5972 val &= 0x3fffffffffffffffULL;
5973 if (val != slot->opnd[i].X_add_number)
5974 as_warn (_("Value truncated to 62 bits"));
5975 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5976 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5979 case IA64_OPND_TGT64:
5981 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5982 insn |= ((((val >> 59) & 0x1) << 36)
5983 | (((val >> 0) & 0xfffff) << 13));
6014 case IA64_OPND_R3_2:
6015 case IA64_OPND_CPUID_R3:
6016 case IA64_OPND_DBR_R3:
6017 case IA64_OPND_DTR_R3:
6018 case IA64_OPND_ITR_R3:
6019 case IA64_OPND_IBR_R3:
6021 case IA64_OPND_MSR_R3:
6022 case IA64_OPND_PKR_R3:
6023 case IA64_OPND_PMC_R3:
6024 case IA64_OPND_PMD_R3:
6025 case IA64_OPND_RR_R3:
6033 odesc = elf64_ia64_operands + idesc->operands[i];
6034 err = (*odesc->insert) (odesc, val, &insn);
6036 as_bad_where (slot->src_file, slot->src_line,
6037 "Bad operand value: %s", err);
6038 if (idesc->flags & IA64_OPCODE_PSEUDO)
6040 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6041 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6043 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6044 (*o2desc->insert) (o2desc, val, &insn);
6046 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6047 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6048 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6050 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6051 (*o2desc->insert) (o2desc, 64 - val, &insn);
6061 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
6062 unsigned int manual_bundling = 0;
6063 enum ia64_unit required_unit, insn_unit = 0;
6064 enum ia64_insn_type type[3], insn_type;
6065 unsigned int template, orig_template;
6066 bfd_vma insn[3] = { -1, -1, -1 };
6067 struct ia64_opcode *idesc;
6068 int end_of_insn_group = 0, user_template = -1;
6069 int n, i, j, first, curr;
6070 unw_rec_list *ptr, *last_ptr, *end_ptr;
6071 bfd_vma t0 = 0, t1 = 0;
6072 struct label_fix *lfix;
6073 struct insn_fix *ifix;
6078 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6079 know (first >= 0 & first < NUM_SLOTS);
6080 n = MIN (3, md.num_slots_in_use);
6082 /* Determine template: user user_template if specified, best match
6085 if (md.slot[first].user_template >= 0)
6086 user_template = template = md.slot[first].user_template;
6089 /* Auto select appropriate template. */
6090 memset (type, 0, sizeof (type));
6092 for (i = 0; i < n; ++i)
6094 if (md.slot[curr].label_fixups && i != 0)
6096 type[i] = md.slot[curr].idesc->type;
6097 curr = (curr + 1) % NUM_SLOTS;
6099 template = best_template[type[0]][type[1]][type[2]];
6102 /* initialize instructions with appropriate nops: */
6103 for (i = 0; i < 3; ++i)
6104 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6108 /* now fill in slots with as many insns as possible: */
6110 idesc = md.slot[curr].idesc;
6111 end_of_insn_group = 0;
6112 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6114 /* If we have unwind records, we may need to update some now. */
6115 ptr = md.slot[curr].unwind_record;
6118 /* Find the last prologue/body record in the list for the current
6119 insn, and set the slot number for all records up to that point.
6120 This needs to be done now, because prologue/body records refer to
6121 the current point, not the point after the instruction has been
6122 issued. This matters because there may have been nops emitted
6123 meanwhile. Any non-prologue non-body record followed by a
6124 prologue/body record must also refer to the current point. */
6126 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6127 for (; ptr != end_ptr; ptr = ptr->next)
6128 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6129 || ptr->r.type == body)
6133 /* Make last_ptr point one after the last prologue/body
6135 last_ptr = last_ptr->next;
6136 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6139 ptr->slot_number = (unsigned long) f + i;
6140 ptr->slot_frag = frag_now;
6142 /* Remove the initialized records, so that we won't accidentally
6143 update them again if we insert a nop and continue. */
6144 md.slot[curr].unwind_record = last_ptr;
6148 if (idesc->flags & IA64_OPCODE_SLOT2)
6150 if (manual_bundling && i != 2)
6151 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6152 "`%s' must be last in bundle", idesc->name);
6156 if (idesc->flags & IA64_OPCODE_LAST)
6159 unsigned int required_template;
6161 /* If we need a stop bit after an M slot, our only choice is
6162 template 5 (M;;MI). If we need a stop bit after a B
6163 slot, our only choice is to place it at the end of the
6164 bundle, because the only available templates are MIB,
6165 MBB, BBB, MMB, and MFB. We don't handle anything other
6166 than M and B slots because these are the only kind of
6167 instructions that can have the IA64_OPCODE_LAST bit set. */
6168 required_template = template;
6169 switch (idesc->type)
6173 required_template = 5;
6181 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6182 "Internal error: don't know how to force %s to end"
6183 "of instruction group", idesc->name);
6187 if (manual_bundling && i != required_slot)
6188 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6189 "`%s' must be last in instruction group",
6191 if (required_slot < i)
6192 /* Can't fit this instruction. */
6196 if (required_template != template)
6198 /* If we switch the template, we need to reset the NOPs
6199 after slot i. The slot-types of the instructions ahead
6200 of i never change, so we don't need to worry about
6201 changing NOPs in front of this slot. */
6202 for (j = i; j < 3; ++j)
6203 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6205 template = required_template;
6207 if (curr != first && md.slot[curr].label_fixups)
6209 if (manual_bundling_on)
6210 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6211 "Label must be first in a bundle");
6212 /* This insn must go into the first slot of a bundle. */
6216 manual_bundling_on = md.slot[curr].manual_bundling_on;
6217 manual_bundling_off = md.slot[curr].manual_bundling_off;
6219 if (manual_bundling_on)
6222 manual_bundling = 1;
6224 break; /* need to start a new bundle */
6227 if (end_of_insn_group && md.num_slots_in_use >= 1)
6229 /* We need an instruction group boundary in the middle of a
6230 bundle. See if we can switch to an other template with
6231 an appropriate boundary. */
6233 orig_template = template;
6234 if (i == 1 && (user_template == 4
6235 || (user_template < 0
6236 && (ia64_templ_desc[template].exec_unit[0]
6240 end_of_insn_group = 0;
6242 else if (i == 2 && (user_template == 0
6243 || (user_template < 0
6244 && (ia64_templ_desc[template].exec_unit[1]
6246 /* This test makes sure we don't switch the template if
6247 the next instruction is one that needs to be first in
6248 an instruction group. Since all those instructions are
6249 in the M group, there is no way such an instruction can
6250 fit in this bundle even if we switch the template. The
6251 reason we have to check for this is that otherwise we
6252 may end up generating "MI;;I M.." which has the deadly
6253 effect that the second M instruction is no longer the
6254 first in the bundle! --davidm 99/12/16 */
6255 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6258 end_of_insn_group = 0;
6260 else if (curr != first)
6261 /* can't fit this insn */
6264 if (template != orig_template)
6265 /* if we switch the template, we need to reset the NOPs
6266 after slot i. The slot-types of the instructions ahead
6267 of i never change, so we don't need to worry about
6268 changing NOPs in front of this slot. */
6269 for (j = i; j < 3; ++j)
6270 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6272 required_unit = ia64_templ_desc[template].exec_unit[i];
6274 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6275 if (idesc->type == IA64_TYPE_DYN)
6277 if ((strcmp (idesc->name, "nop") == 0)
6278 || (strcmp (idesc->name, "hint") == 0)
6279 || (strcmp (idesc->name, "break") == 0))
6280 insn_unit = required_unit;
6281 else if (strcmp (idesc->name, "chk.s") == 0)
6283 insn_unit = IA64_UNIT_M;
6284 if (required_unit == IA64_UNIT_I)
6285 insn_unit = IA64_UNIT_I;
6288 as_fatal ("emit_one_bundle: unexpected dynamic op");
6290 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6291 ia64_free_opcode (idesc);
6292 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6294 know (!idesc->next); /* no resolved dynamic ops have collisions */
6299 insn_type = idesc->type;
6300 insn_unit = IA64_UNIT_NIL;
6304 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6305 insn_unit = required_unit;
6307 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6308 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6309 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6310 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6311 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6316 if (insn_unit != required_unit)
6318 if (required_unit == IA64_UNIT_L
6319 && insn_unit == IA64_UNIT_I
6320 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6322 /* we got ourselves an MLX template but the current
6323 instruction isn't an X-unit, or an I-unit instruction
6324 that can go into the X slot of an MLX template. Duh. */
6325 if (md.num_slots_in_use >= NUM_SLOTS)
6327 as_bad_where (md.slot[curr].src_file,
6328 md.slot[curr].src_line,
6329 "`%s' can't go in X slot of "
6330 "MLX template", idesc->name);
6331 /* drop this insn so we don't livelock: */
6332 --md.num_slots_in_use;
6336 continue; /* try next slot */
6342 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6343 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6346 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6347 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6349 build_insn (md.slot + curr, insn + i);
6351 ptr = md.slot[curr].unwind_record;
6354 /* Set slot numbers for all remaining unwind records belonging to the
6355 current insn. There can not be any prologue/body unwind records
6357 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6358 for (; ptr != end_ptr; ptr = ptr->next)
6360 ptr->slot_number = (unsigned long) f + i;
6361 ptr->slot_frag = frag_now;
6363 md.slot[curr].unwind_record = NULL;
6366 if (required_unit == IA64_UNIT_L)
6369 /* skip one slot for long/X-unit instructions */
6372 --md.num_slots_in_use;
6374 /* now is a good time to fix up the labels for this insn: */
6375 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6377 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6378 symbol_set_frag (lfix->sym, frag_now);
6380 /* and fix up the tags also. */
6381 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6383 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6384 symbol_set_frag (lfix->sym, frag_now);
6387 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6389 ifix = md.slot[curr].fixup + j;
6390 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6391 &ifix->expr, ifix->is_pcrel, ifix->code);
6392 fix->tc_fix_data.opnd = ifix->opnd;
6393 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6394 fix->fx_file = md.slot[curr].src_file;
6395 fix->fx_line = md.slot[curr].src_line;
6398 end_of_insn_group = md.slot[curr].end_of_insn_group;
6400 if (end_of_insn_group)
6402 md.group_idx = (md.group_idx + 1) % 3;
6403 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6407 ia64_free_opcode (md.slot[curr].idesc);
6408 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6409 md.slot[curr].user_template = -1;
6411 if (manual_bundling_off)
6413 manual_bundling = 0;
6416 curr = (curr + 1) % NUM_SLOTS;
6417 idesc = md.slot[curr].idesc;
6419 if (manual_bundling)
6421 if (md.num_slots_in_use > 0)
6422 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6423 "`%s' does not fit into %s template",
6424 idesc->name, ia64_templ_desc[template].name);
6426 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6427 "Missing '}' at end of file");
6429 know (md.num_slots_in_use < NUM_SLOTS);
6431 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6432 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6434 number_to_chars_littleendian (f + 0, t0, 8);
6435 number_to_chars_littleendian (f + 8, t1, 8);
6439 unwind.list->next_slot_number = (unsigned long) f + 16;
6440 unwind.list->next_slot_frag = frag_now;
6445 md_parse_option (c, arg)
6452 /* Switches from the Intel assembler. */
6454 if (strcmp (arg, "ilp64") == 0
6455 || strcmp (arg, "lp64") == 0
6456 || strcmp (arg, "p64") == 0)
6458 md.flags |= EF_IA_64_ABI64;
6460 else if (strcmp (arg, "ilp32") == 0)
6462 md.flags &= ~EF_IA_64_ABI64;
6464 else if (strcmp (arg, "le") == 0)
6466 md.flags &= ~EF_IA_64_BE;
6468 else if (strcmp (arg, "be") == 0)
6470 md.flags |= EF_IA_64_BE;
6477 if (strcmp (arg, "so") == 0)
6479 /* Suppress signon message. */
6481 else if (strcmp (arg, "pi") == 0)
6483 /* Reject privileged instructions. FIXME */
6485 else if (strcmp (arg, "us") == 0)
6487 /* Allow union of signed and unsigned range. FIXME */
6489 else if (strcmp (arg, "close_fcalls") == 0)
6491 /* Do not resolve global function calls. */
6498 /* temp[="prefix"] Insert temporary labels into the object file
6499 symbol table prefixed by "prefix".
6500 Default prefix is ":temp:".
6505 /* indirect=<tgt> Assume unannotated indirect branches behavior
6506 according to <tgt> --
6507 exit: branch out from the current context (default)
6508 labels: all labels in context may be branch targets
6510 if (strncmp (arg, "indirect=", 9) != 0)
6515 /* -X conflicts with an ignored option, use -x instead */
6517 if (!arg || strcmp (arg, "explicit") == 0)
6519 /* set default mode to explicit */
6520 md.default_explicit_mode = 1;
6523 else if (strcmp (arg, "auto") == 0)
6525 md.default_explicit_mode = 0;
6527 else if (strcmp (arg, "debug") == 0)
6531 else if (strcmp (arg, "debugx") == 0)
6533 md.default_explicit_mode = 1;
6538 as_bad (_("Unrecognized option '-x%s'"), arg);
6543 /* nops Print nops statistics. */
6546 /* GNU specific switches for gcc. */
6547 case OPTION_MCONSTANT_GP:
6548 md.flags |= EF_IA_64_CONS_GP;
6551 case OPTION_MAUTO_PIC:
6552 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6563 md_show_usage (stream)
6568 --mconstant-gp mark output file as using the constant-GP model\n\
6569 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6570 --mauto-pic mark output file as using the constant-GP model\n\
6571 without function descriptors (sets ELF header flag\n\
6572 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6573 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6574 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6575 -x | -xexplicit turn on dependency violation checking (default)\n\
6576 -xauto automagically remove dependency violations\n\
6577 -xdebug debug dependency violation checker\n"),
6582 ia64_after_parse_args ()
6584 if (debug_type == DEBUG_STABS)
6585 as_fatal (_("--gstabs is not supported for ia64"));
6588 /* Return true if TYPE fits in TEMPL at SLOT. */
6591 match (int templ, int type, int slot)
6593 enum ia64_unit unit;
6596 unit = ia64_templ_desc[templ].exec_unit[slot];
6599 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6601 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6603 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6604 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6605 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6606 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6607 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6608 default: result = 0; break;
6613 /* Add a bit of extra goodness if a nop of type F or B would fit
6614 in TEMPL at SLOT. */
6617 extra_goodness (int templ, int slot)
6619 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6621 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6626 /* This function is called once, at assembler startup time. It sets
6627 up all the tables, etc. that the MD part of the assembler will need
6628 that can be determined before arguments are parsed. */
6632 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6637 md.explicit_mode = md.default_explicit_mode;
6639 bfd_set_section_alignment (stdoutput, text_section, 4);
6641 /* Make sure function pointers get initialized. */
6642 target_big_endian = -1;
6643 dot_byteorder (TARGET_BYTES_BIG_ENDIAN);
6645 alias_hash = hash_new ();
6646 alias_name_hash = hash_new ();
6647 secalias_hash = hash_new ();
6648 secalias_name_hash = hash_new ();
6650 pseudo_func[FUNC_DTP_MODULE].u.sym =
6651 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6652 &zero_address_frag);
6654 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6655 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6656 &zero_address_frag);
6658 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6659 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6660 &zero_address_frag);
6662 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6663 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6664 &zero_address_frag);
6666 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6667 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6668 &zero_address_frag);
6670 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6671 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6672 &zero_address_frag);
6674 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6675 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6676 &zero_address_frag);
6678 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6679 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6680 &zero_address_frag);
6682 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6683 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6684 &zero_address_frag);
6686 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6687 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6688 &zero_address_frag);
6690 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6691 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6692 &zero_address_frag);
6694 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6695 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6696 &zero_address_frag);
6698 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6699 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6700 &zero_address_frag);
6702 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6703 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6704 &zero_address_frag);
6706 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6707 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6708 &zero_address_frag);
6710 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6711 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6712 &zero_address_frag);
6714 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6715 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6716 &zero_address_frag);
6718 /* Compute the table of best templates. We compute goodness as a
6719 base 4 value, in which each match counts for 3, each F counts
6720 for 2, each B counts for 1. This should maximize the number of
6721 F and B nops in the chosen bundles, which is good because these
6722 pipelines are least likely to be overcommitted. */
6723 for (i = 0; i < IA64_NUM_TYPES; ++i)
6724 for (j = 0; j < IA64_NUM_TYPES; ++j)
6725 for (k = 0; k < IA64_NUM_TYPES; ++k)
6728 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6731 if (match (t, i, 0))
6733 if (match (t, j, 1))
6735 if (match (t, k, 2))
6736 goodness = 3 + 3 + 3;
6738 goodness = 3 + 3 + extra_goodness (t, 2);
6740 else if (match (t, j, 2))
6741 goodness = 3 + 3 + extra_goodness (t, 1);
6745 goodness += extra_goodness (t, 1);
6746 goodness += extra_goodness (t, 2);
6749 else if (match (t, i, 1))
6751 if (match (t, j, 2))
6754 goodness = 3 + extra_goodness (t, 2);
6756 else if (match (t, i, 2))
6757 goodness = 3 + extra_goodness (t, 1);
6759 if (goodness > best)
6762 best_template[i][j][k] = t;
6767 for (i = 0; i < NUM_SLOTS; ++i)
6768 md.slot[i].user_template = -1;
6770 md.pseudo_hash = hash_new ();
6771 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6773 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6774 (void *) (pseudo_opcode + i));
6776 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6777 pseudo_opcode[i].name, err);
6780 md.reg_hash = hash_new ();
6781 md.dynreg_hash = hash_new ();
6782 md.const_hash = hash_new ();
6783 md.entry_hash = hash_new ();
6785 /* general registers: */
6788 for (i = 0; i < total; ++i)
6790 sprintf (name, "r%d", i - REG_GR);
6791 md.regsym[i] = declare_register (name, i);
6794 /* floating point registers: */
6796 for (; i < total; ++i)
6798 sprintf (name, "f%d", i - REG_FR);
6799 md.regsym[i] = declare_register (name, i);
6802 /* application registers: */
6805 for (; i < total; ++i)
6807 sprintf (name, "ar%d", i - REG_AR);
6808 md.regsym[i] = declare_register (name, i);
6811 /* control registers: */
6814 for (; i < total; ++i)
6816 sprintf (name, "cr%d", i - REG_CR);
6817 md.regsym[i] = declare_register (name, i);
6820 /* predicate registers: */
6822 for (; i < total; ++i)
6824 sprintf (name, "p%d", i - REG_P);
6825 md.regsym[i] = declare_register (name, i);
6828 /* branch registers: */
6830 for (; i < total; ++i)
6832 sprintf (name, "b%d", i - REG_BR);
6833 md.regsym[i] = declare_register (name, i);
6836 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6837 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6838 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6839 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6840 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6841 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6842 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6844 for (i = 0; i < NELEMS (indirect_reg); ++i)
6846 regnum = indirect_reg[i].regnum;
6847 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6850 /* define synonyms for application registers: */
6851 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6852 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6853 REG_AR + ar[i - REG_AR].regnum);
6855 /* define synonyms for control registers: */
6856 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6857 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6858 REG_CR + cr[i - REG_CR].regnum);
6860 declare_register ("gp", REG_GR + 1);
6861 declare_register ("sp", REG_GR + 12);
6862 declare_register ("rp", REG_BR + 0);
6864 /* pseudo-registers used to specify unwind info: */
6865 declare_register ("psp", REG_PSP);
6867 declare_register_set ("ret", 4, REG_GR + 8);
6868 declare_register_set ("farg", 8, REG_FR + 8);
6869 declare_register_set ("fret", 8, REG_FR + 8);
6871 for (i = 0; i < NELEMS (const_bits); ++i)
6873 err = hash_insert (md.const_hash, const_bits[i].name,
6874 (PTR) (const_bits + i));
6876 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6880 /* Set the architecture and machine depending on defaults and command line
6882 if (md.flags & EF_IA_64_ABI64)
6883 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6885 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6888 as_warn (_("Could not set architecture and machine"));
6890 /* Set the pointer size and pointer shift size depending on md.flags */
6892 if (md.flags & EF_IA_64_ABI64)
6894 md.pointer_size = 8; /* pointers are 8 bytes */
6895 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6899 md.pointer_size = 4; /* pointers are 4 bytes */
6900 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6903 md.mem_offset.hint = 0;
6906 md.entry_labels = NULL;
6909 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6910 because that is called after md_parse_option which is where we do the
6911 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6912 default endianness. */
6915 ia64_init (argc, argv)
6916 int argc ATTRIBUTE_UNUSED;
6917 char **argv ATTRIBUTE_UNUSED;
6919 md.flags = MD_FLAGS_DEFAULT;
6922 /* Return a string for the target object file format. */
6925 ia64_target_format ()
6927 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6929 if (md.flags & EF_IA_64_BE)
6931 if (md.flags & EF_IA_64_ABI64)
6932 #if defined(TE_AIX50)
6933 return "elf64-ia64-aix-big";
6934 #elif defined(TE_HPUX)
6935 return "elf64-ia64-hpux-big";
6937 return "elf64-ia64-big";
6940 #if defined(TE_AIX50)
6941 return "elf32-ia64-aix-big";
6942 #elif defined(TE_HPUX)
6943 return "elf32-ia64-hpux-big";
6945 return "elf32-ia64-big";
6950 if (md.flags & EF_IA_64_ABI64)
6952 return "elf64-ia64-aix-little";
6954 return "elf64-ia64-little";
6958 return "elf32-ia64-aix-little";
6960 return "elf32-ia64-little";
6965 return "unknown-format";
6969 ia64_end_of_source ()
6971 /* terminate insn group upon reaching end of file: */
6972 insn_group_break (1, 0, 0);
6974 /* emits slots we haven't written yet: */
6975 ia64_flush_insns ();
6977 bfd_set_private_flags (stdoutput, md.flags);
6979 md.mem_offset.hint = 0;
6985 if (md.qp.X_op == O_register)
6986 as_bad ("qualifying predicate not followed by instruction");
6987 md.qp.X_op = O_absent;
6989 if (ignore_input ())
6992 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6994 if (md.detect_dv && !md.explicit_mode)
6995 as_warn (_("Explicit stops are ignored in auto mode"));
6997 insn_group_break (1, 0, 0);
7001 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7003 static int defining_tag = 0;
7006 ia64_unrecognized_line (ch)
7012 expression (&md.qp);
7013 if (*input_line_pointer++ != ')')
7015 as_bad ("Expected ')'");
7018 if (md.qp.X_op != O_register)
7020 as_bad ("Qualifying predicate expected");
7023 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7025 as_bad ("Predicate register expected");
7031 if (md.manual_bundling)
7032 as_warn ("Found '{' when manual bundling is already turned on");
7034 CURR_SLOT.manual_bundling_on = 1;
7035 md.manual_bundling = 1;
7037 /* Bundling is only acceptable in explicit mode
7038 or when in default automatic mode. */
7039 if (md.detect_dv && !md.explicit_mode)
7041 if (!md.mode_explicitly_set
7042 && !md.default_explicit_mode)
7045 as_warn (_("Found '{' after explicit switch to automatic mode"));
7050 if (!md.manual_bundling)
7051 as_warn ("Found '}' when manual bundling is off");
7053 PREV_SLOT.manual_bundling_off = 1;
7054 md.manual_bundling = 0;
7056 /* switch back to automatic mode, if applicable */
7059 && !md.mode_explicitly_set
7060 && !md.default_explicit_mode)
7063 /* Allow '{' to follow on the same line. We also allow ";;", but that
7064 happens automatically because ';' is an end of line marker. */
7066 if (input_line_pointer[0] == '{')
7068 input_line_pointer++;
7069 return ia64_unrecognized_line ('{');
7072 demand_empty_rest_of_line ();
7082 if (md.qp.X_op == O_register)
7084 as_bad ("Tag must come before qualifying predicate.");
7088 /* This implements just enough of read_a_source_file in read.c to
7089 recognize labels. */
7090 if (is_name_beginner (*input_line_pointer))
7092 s = input_line_pointer;
7093 c = get_symbol_end ();
7095 else if (LOCAL_LABELS_FB
7096 && ISDIGIT (*input_line_pointer))
7099 while (ISDIGIT (*input_line_pointer))
7100 temp = (temp * 10) + *input_line_pointer++ - '0';
7101 fb_label_instance_inc (temp);
7102 s = fb_label_name (temp, 0);
7103 c = *input_line_pointer;
7112 /* Put ':' back for error messages' sake. */
7113 *input_line_pointer++ = ':';
7114 as_bad ("Expected ':'");
7121 /* Put ':' back for error messages' sake. */
7122 *input_line_pointer++ = ':';
7123 if (*input_line_pointer++ != ']')
7125 as_bad ("Expected ']'");
7130 as_bad ("Tag name expected");
7140 /* Not a valid line. */
7145 ia64_frob_label (sym)
7148 struct label_fix *fix;
7150 /* Tags need special handling since they are not bundle breaks like
7154 fix = obstack_alloc (¬es, sizeof (*fix));
7156 fix->next = CURR_SLOT.tag_fixups;
7157 CURR_SLOT.tag_fixups = fix;
7162 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7164 md.last_text_seg = now_seg;
7165 fix = obstack_alloc (¬es, sizeof (*fix));
7167 fix->next = CURR_SLOT.label_fixups;
7168 CURR_SLOT.label_fixups = fix;
7170 /* Keep track of how many code entry points we've seen. */
7171 if (md.path == md.maxpaths)
7174 md.entry_labels = (const char **)
7175 xrealloc ((void *) md.entry_labels,
7176 md.maxpaths * sizeof (char *));
7178 md.entry_labels[md.path++] = S_GET_NAME (sym);
7183 /* The HP-UX linker will give unresolved symbol errors for symbols
7184 that are declared but unused. This routine removes declared,
7185 unused symbols from an object. */
7187 ia64_frob_symbol (sym)
7190 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7191 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7192 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7193 && ! S_IS_EXTERNAL (sym)))
7200 ia64_flush_pending_output ()
7202 if (!md.keep_pending_output
7203 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7205 /* ??? This causes many unnecessary stop bits to be emitted.
7206 Unfortunately, it isn't clear if it is safe to remove this. */
7207 insn_group_break (1, 0, 0);
7208 ia64_flush_insns ();
7212 /* Do ia64-specific expression optimization. All that's done here is
7213 to transform index expressions that are either due to the indexing
7214 of rotating registers or due to the indexing of indirect register
7217 ia64_optimize_expr (l, op, r)
7226 if (l->X_op == O_register && r->X_op == O_constant)
7228 num_regs = (l->X_add_number >> 16);
7229 if ((unsigned) r->X_add_number >= num_regs)
7232 as_bad ("No current frame");
7234 as_bad ("Index out of range 0..%u", num_regs - 1);
7235 r->X_add_number = 0;
7237 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7240 else if (l->X_op == O_register && r->X_op == O_register)
7242 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7243 || l->X_add_number == IND_MEM)
7245 as_bad ("Indirect register set name expected");
7246 l->X_add_number = IND_CPUID;
7249 l->X_op_symbol = md.regsym[l->X_add_number];
7250 l->X_add_number = r->X_add_number;
7258 ia64_parse_name (name, e)
7262 struct const_desc *cdesc;
7263 struct dynreg *dr = 0;
7264 unsigned int regnum;
7268 /* first see if NAME is a known register name: */
7269 sym = hash_find (md.reg_hash, name);
7272 e->X_op = O_register;
7273 e->X_add_number = S_GET_VALUE (sym);
7277 cdesc = hash_find (md.const_hash, name);
7280 e->X_op = O_constant;
7281 e->X_add_number = cdesc->value;
7285 /* check for inN, locN, or outN: */
7289 if (name[1] == 'n' && ISDIGIT (name[2]))
7297 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7305 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7318 /* The name is inN, locN, or outN; parse the register number. */
7319 regnum = strtoul (name, &end, 10);
7320 if (end > name && *end == '\0')
7322 if ((unsigned) regnum >= dr->num_regs)
7325 as_bad ("No current frame");
7327 as_bad ("Register number out of range 0..%u",
7331 e->X_op = O_register;
7332 e->X_add_number = dr->base + regnum;
7337 if ((dr = hash_find (md.dynreg_hash, name)))
7339 /* We've got ourselves the name of a rotating register set.
7340 Store the base register number in the low 16 bits of
7341 X_add_number and the size of the register set in the top 16
7343 e->X_op = O_register;
7344 e->X_add_number = dr->base | (dr->num_regs << 16);
7350 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7353 ia64_canonicalize_symbol_name (name)
7356 size_t len = strlen (name);
7357 if (len > 1 && name[len - 1] == '#')
7358 name[len - 1] = '\0';
7362 /* Return true if idesc is a conditional branch instruction. This excludes
7363 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7364 because they always read/write resources regardless of the value of the
7365 qualifying predicate. br.ia must always use p0, and hence is always
7366 taken. Thus this function returns true for branches which can fall
7367 through, and which use no resources if they do fall through. */
7370 is_conditional_branch (idesc)
7371 struct ia64_opcode *idesc;
7373 /* br is a conditional branch. Everything that starts with br. except
7374 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7375 Everything that starts with brl is a conditional branch. */
7376 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7377 && (idesc->name[2] == '\0'
7378 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7379 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7380 || idesc->name[2] == 'l'
7381 /* br.cond, br.call, br.clr */
7382 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7383 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7384 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7387 /* Return whether the given opcode is a taken branch. If there's any doubt,
7391 is_taken_branch (idesc)
7392 struct ia64_opcode *idesc;
7394 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7395 || strncmp (idesc->name, "br.ia", 5) == 0);
7398 /* Return whether the given opcode is an interruption or rfi. If there's any
7399 doubt, returns zero. */
7402 is_interruption_or_rfi (idesc)
7403 struct ia64_opcode *idesc;
7405 if (strcmp (idesc->name, "rfi") == 0)
7410 /* Returns the index of the given dependency in the opcode's list of chks, or
7411 -1 if there is no dependency. */
7414 depends_on (depind, idesc)
7416 struct ia64_opcode *idesc;
7419 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7420 for (i = 0; i < dep->nchks; i++)
7422 if (depind == DEP (dep->chks[i]))
7428 /* Determine a set of specific resources used for a particular resource
7429 class. Returns the number of specific resources identified For those
7430 cases which are not determinable statically, the resource returned is
7433 Meanings of value in 'NOTE':
7434 1) only read/write when the register number is explicitly encoded in the
7436 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7437 accesses CFM when qualifying predicate is in the rotating region.
7438 3) general register value is used to specify an indirect register; not
7439 determinable statically.
7440 4) only read the given resource when bits 7:0 of the indirect index
7441 register value does not match the register number of the resource; not
7442 determinable statically.
7443 5) all rules are implementation specific.
7444 6) only when both the index specified by the reader and the index specified
7445 by the writer have the same value in bits 63:61; not determinable
7447 7) only access the specified resource when the corresponding mask bit is
7449 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7450 only read when these insns reference FR2-31
7451 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7452 written when these insns write FR32-127
7453 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7455 11) The target predicates are written independently of PR[qp], but source
7456 registers are only read if PR[qp] is true. Since the state of PR[qp]
7457 cannot statically be determined, all source registers are marked used.
7458 12) This insn only reads the specified predicate register when that
7459 register is the PR[qp].
7460 13) This reference to ld-c only applies to teh GR whose value is loaded
7461 with data returned from memory, not the post-incremented address register.
7462 14) The RSE resource includes the implementation-specific RSE internal
7463 state resources. At least one (and possibly more) of these resources are
7464 read by each instruction listed in IC:rse-readers. At least one (and
7465 possibly more) of these resources are written by each insn listed in
7467 15+16) Represents reserved instructions, which the assembler does not
7470 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7471 this code; there are no dependency violations based on memory access.
7474 #define MAX_SPECS 256
7479 specify_resource (dep, idesc, type, specs, note, path)
7480 const struct ia64_dependency *dep;
7481 struct ia64_opcode *idesc;
7482 int type; /* is this a DV chk or a DV reg? */
7483 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7484 int note; /* resource note for this insn's usage */
7485 int path; /* which execution path to examine */
7492 if (dep->mode == IA64_DV_WAW
7493 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7494 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7497 /* template for any resources we identify */
7498 tmpl.dependency = dep;
7500 tmpl.insn_srlz = tmpl.data_srlz = 0;
7501 tmpl.qp_regno = CURR_SLOT.qp_regno;
7502 tmpl.link_to_qp_branch = 1;
7503 tmpl.mem_offset.hint = 0;
7506 tmpl.cmp_type = CMP_NONE;
7509 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7510 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7511 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7513 /* we don't need to track these */
7514 if (dep->semantics == IA64_DVS_NONE)
7517 switch (dep->specifier)
7522 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7524 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7525 if (regno >= 0 && regno <= 7)
7527 specs[count] = tmpl;
7528 specs[count++].index = regno;
7534 for (i = 0; i < 8; i++)
7536 specs[count] = tmpl;
7537 specs[count++].index = i;
7546 case IA64_RS_AR_UNAT:
7547 /* This is a mov =AR or mov AR= instruction. */
7548 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7550 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7551 if (regno == AR_UNAT)
7553 specs[count++] = tmpl;
7558 /* This is a spill/fill, or other instruction that modifies the
7561 /* Unless we can determine the specific bits used, mark the whole
7562 thing; bits 8:3 of the memory address indicate the bit used in
7563 UNAT. The .mem.offset hint may be used to eliminate a small
7564 subset of conflicts. */
7565 specs[count] = tmpl;
7566 if (md.mem_offset.hint)
7569 fprintf (stderr, " Using hint for spill/fill\n");
7570 /* The index isn't actually used, just set it to something
7571 approximating the bit index. */
7572 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7573 specs[count].mem_offset.hint = 1;
7574 specs[count].mem_offset.offset = md.mem_offset.offset;
7575 specs[count++].mem_offset.base = md.mem_offset.base;
7579 specs[count++].specific = 0;
7587 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7589 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7590 if ((regno >= 8 && regno <= 15)
7591 || (regno >= 20 && regno <= 23)
7592 || (regno >= 31 && regno <= 39)
7593 || (regno >= 41 && regno <= 47)
7594 || (regno >= 67 && regno <= 111))
7596 specs[count] = tmpl;
7597 specs[count++].index = regno;
7610 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7612 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7613 if ((regno >= 48 && regno <= 63)
7614 || (regno >= 112 && regno <= 127))
7616 specs[count] = tmpl;
7617 specs[count++].index = regno;
7623 for (i = 48; i < 64; i++)
7625 specs[count] = tmpl;
7626 specs[count++].index = i;
7628 for (i = 112; i < 128; i++)
7630 specs[count] = tmpl;
7631 specs[count++].index = i;
7649 for (i = 0; i < idesc->num_outputs; i++)
7650 if (idesc->operands[i] == IA64_OPND_B1
7651 || idesc->operands[i] == IA64_OPND_B2)
7653 specs[count] = tmpl;
7654 specs[count++].index =
7655 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7660 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7661 if (idesc->operands[i] == IA64_OPND_B1
7662 || idesc->operands[i] == IA64_OPND_B2)
7664 specs[count] = tmpl;
7665 specs[count++].index =
7666 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7672 case IA64_RS_CPUID: /* four or more registers */
7675 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7677 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7678 if (regno >= 0 && regno < NELEMS (gr_values)
7681 specs[count] = tmpl;
7682 specs[count++].index = gr_values[regno].value & 0xFF;
7686 specs[count] = tmpl;
7687 specs[count++].specific = 0;
7697 case IA64_RS_DBR: /* four or more registers */
7700 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7702 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7703 if (regno >= 0 && regno < NELEMS (gr_values)
7706 specs[count] = tmpl;
7707 specs[count++].index = gr_values[regno].value & 0xFF;
7711 specs[count] = tmpl;
7712 specs[count++].specific = 0;
7716 else if (note == 0 && !rsrc_write)
7718 specs[count] = tmpl;
7719 specs[count++].specific = 0;
7727 case IA64_RS_IBR: /* four or more registers */
7730 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7732 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7733 if (regno >= 0 && regno < NELEMS (gr_values)
7736 specs[count] = tmpl;
7737 specs[count++].index = gr_values[regno].value & 0xFF;
7741 specs[count] = tmpl;
7742 specs[count++].specific = 0;
7755 /* These are implementation specific. Force all references to
7756 conflict with all other references. */
7757 specs[count] = tmpl;
7758 specs[count++].specific = 0;
7766 case IA64_RS_PKR: /* 16 or more registers */
7767 if (note == 3 || note == 4)
7769 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7771 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7772 if (regno >= 0 && regno < NELEMS (gr_values)
7777 specs[count] = tmpl;
7778 specs[count++].index = gr_values[regno].value & 0xFF;
7781 for (i = 0; i < NELEMS (gr_values); i++)
7783 /* Uses all registers *except* the one in R3. */
7784 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7786 specs[count] = tmpl;
7787 specs[count++].index = i;
7793 specs[count] = tmpl;
7794 specs[count++].specific = 0;
7801 specs[count] = tmpl;
7802 specs[count++].specific = 0;
7806 case IA64_RS_PMC: /* four or more registers */
7809 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7810 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7813 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7815 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7816 if (regno >= 0 && regno < NELEMS (gr_values)
7819 specs[count] = tmpl;
7820 specs[count++].index = gr_values[regno].value & 0xFF;
7824 specs[count] = tmpl;
7825 specs[count++].specific = 0;
7835 case IA64_RS_PMD: /* four or more registers */
7838 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7840 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7841 if (regno >= 0 && regno < NELEMS (gr_values)
7844 specs[count] = tmpl;
7845 specs[count++].index = gr_values[regno].value & 0xFF;
7849 specs[count] = tmpl;
7850 specs[count++].specific = 0;
7860 case IA64_RS_RR: /* eight registers */
7863 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7865 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7866 if (regno >= 0 && regno < NELEMS (gr_values)
7869 specs[count] = tmpl;
7870 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7874 specs[count] = tmpl;
7875 specs[count++].specific = 0;
7879 else if (note == 0 && !rsrc_write)
7881 specs[count] = tmpl;
7882 specs[count++].specific = 0;
7890 case IA64_RS_CR_IRR:
7893 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7894 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7896 && idesc->operands[1] == IA64_OPND_CR3
7899 for (i = 0; i < 4; i++)
7901 specs[count] = tmpl;
7902 specs[count++].index = CR_IRR0 + i;
7908 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7909 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7911 && regno <= CR_IRR3)
7913 specs[count] = tmpl;
7914 specs[count++].index = regno;
7923 case IA64_RS_CR_LRR:
7930 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7931 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7932 && (regno == CR_LRR0 || regno == CR_LRR1))
7934 specs[count] = tmpl;
7935 specs[count++].index = regno;
7943 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7945 specs[count] = tmpl;
7946 specs[count++].index =
7947 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7962 else if (rsrc_write)
7964 if (dep->specifier == IA64_RS_FRb
7965 && idesc->operands[0] == IA64_OPND_F1)
7967 specs[count] = tmpl;
7968 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7973 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7975 if (idesc->operands[i] == IA64_OPND_F2
7976 || idesc->operands[i] == IA64_OPND_F3
7977 || idesc->operands[i] == IA64_OPND_F4)
7979 specs[count] = tmpl;
7980 specs[count++].index =
7981 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7990 /* This reference applies only to the GR whose value is loaded with
7991 data returned from memory. */
7992 specs[count] = tmpl;
7993 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7999 for (i = 0; i < idesc->num_outputs; i++)
8000 if (idesc->operands[i] == IA64_OPND_R1
8001 || idesc->operands[i] == IA64_OPND_R2
8002 || idesc->operands[i] == IA64_OPND_R3)
8004 specs[count] = tmpl;
8005 specs[count++].index =
8006 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8008 if (idesc->flags & IA64_OPCODE_POSTINC)
8009 for (i = 0; i < NELEMS (idesc->operands); i++)
8010 if (idesc->operands[i] == IA64_OPND_MR3)
8012 specs[count] = tmpl;
8013 specs[count++].index =
8014 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8019 /* Look for anything that reads a GR. */
8020 for (i = 0; i < NELEMS (idesc->operands); i++)
8022 if (idesc->operands[i] == IA64_OPND_MR3
8023 || idesc->operands[i] == IA64_OPND_CPUID_R3
8024 || idesc->operands[i] == IA64_OPND_DBR_R3
8025 || idesc->operands[i] == IA64_OPND_IBR_R3
8026 || idesc->operands[i] == IA64_OPND_MSR_R3
8027 || idesc->operands[i] == IA64_OPND_PKR_R3
8028 || idesc->operands[i] == IA64_OPND_PMC_R3
8029 || idesc->operands[i] == IA64_OPND_PMD_R3
8030 || idesc->operands[i] == IA64_OPND_RR_R3
8031 || ((i >= idesc->num_outputs)
8032 && (idesc->operands[i] == IA64_OPND_R1
8033 || idesc->operands[i] == IA64_OPND_R2
8034 || idesc->operands[i] == IA64_OPND_R3
8035 /* addl source register. */
8036 || idesc->operands[i] == IA64_OPND_R3_2)))
8038 specs[count] = tmpl;
8039 specs[count++].index =
8040 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8051 /* This is the same as IA64_RS_PRr, except that the register range is
8052 from 1 - 15, and there are no rotating register reads/writes here. */
8056 for (i = 1; i < 16; i++)
8058 specs[count] = tmpl;
8059 specs[count++].index = i;
8065 /* Mark only those registers indicated by the mask. */
8068 mask = CURR_SLOT.opnd[2].X_add_number;
8069 for (i = 1; i < 16; i++)
8070 if (mask & ((valueT) 1 << i))
8072 specs[count] = tmpl;
8073 specs[count++].index = i;
8081 else if (note == 11) /* note 11 implies note 1 as well */
8085 for (i = 0; i < idesc->num_outputs; i++)
8087 if (idesc->operands[i] == IA64_OPND_P1
8088 || idesc->operands[i] == IA64_OPND_P2)
8090 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8091 if (regno >= 1 && regno < 16)
8093 specs[count] = tmpl;
8094 specs[count++].index = regno;
8104 else if (note == 12)
8106 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8108 specs[count] = tmpl;
8109 specs[count++].index = CURR_SLOT.qp_regno;
8116 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8117 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8118 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8119 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8121 if ((idesc->operands[0] == IA64_OPND_P1
8122 || idesc->operands[0] == IA64_OPND_P2)
8123 && p1 >= 1 && p1 < 16)
8125 specs[count] = tmpl;
8126 specs[count].cmp_type =
8127 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8128 specs[count++].index = p1;
8130 if ((idesc->operands[1] == IA64_OPND_P1
8131 || idesc->operands[1] == IA64_OPND_P2)
8132 && p2 >= 1 && p2 < 16)
8134 specs[count] = tmpl;
8135 specs[count].cmp_type =
8136 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8137 specs[count++].index = p2;
8142 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8144 specs[count] = tmpl;
8145 specs[count++].index = CURR_SLOT.qp_regno;
8147 if (idesc->operands[1] == IA64_OPND_PR)
8149 for (i = 1; i < 16; i++)
8151 specs[count] = tmpl;
8152 specs[count++].index = i;
8163 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8164 simplified cases of this. */
8168 for (i = 16; i < 63; i++)
8170 specs[count] = tmpl;
8171 specs[count++].index = i;
8177 /* Mark only those registers indicated by the mask. */
8179 && idesc->operands[0] == IA64_OPND_PR)
8181 mask = CURR_SLOT.opnd[2].X_add_number;
8182 if (mask & ((valueT) 1 << 16))
8183 for (i = 16; i < 63; i++)
8185 specs[count] = tmpl;
8186 specs[count++].index = i;
8190 && idesc->operands[0] == IA64_OPND_PR_ROT)
8192 for (i = 16; i < 63; i++)
8194 specs[count] = tmpl;
8195 specs[count++].index = i;
8203 else if (note == 11) /* note 11 implies note 1 as well */
8207 for (i = 0; i < idesc->num_outputs; i++)
8209 if (idesc->operands[i] == IA64_OPND_P1
8210 || idesc->operands[i] == IA64_OPND_P2)
8212 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8213 if (regno >= 16 && regno < 63)
8215 specs[count] = tmpl;
8216 specs[count++].index = regno;
8226 else if (note == 12)
8228 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8230 specs[count] = tmpl;
8231 specs[count++].index = CURR_SLOT.qp_regno;
8238 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8239 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8240 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8241 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8243 if ((idesc->operands[0] == IA64_OPND_P1
8244 || idesc->operands[0] == IA64_OPND_P2)
8245 && p1 >= 16 && p1 < 63)
8247 specs[count] = tmpl;
8248 specs[count].cmp_type =
8249 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8250 specs[count++].index = p1;
8252 if ((idesc->operands[1] == IA64_OPND_P1
8253 || idesc->operands[1] == IA64_OPND_P2)
8254 && p2 >= 16 && p2 < 63)
8256 specs[count] = tmpl;
8257 specs[count].cmp_type =
8258 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8259 specs[count++].index = p2;
8264 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8266 specs[count] = tmpl;
8267 specs[count++].index = CURR_SLOT.qp_regno;
8269 if (idesc->operands[1] == IA64_OPND_PR)
8271 for (i = 16; i < 63; i++)
8273 specs[count] = tmpl;
8274 specs[count++].index = i;
8286 /* Verify that the instruction is using the PSR bit indicated in
8290 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8292 if (dep->regindex < 6)
8294 specs[count++] = tmpl;
8297 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8299 if (dep->regindex < 32
8300 || dep->regindex == 35
8301 || dep->regindex == 36
8302 || (!rsrc_write && dep->regindex == PSR_CPL))
8304 specs[count++] = tmpl;
8307 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8309 if (dep->regindex < 32
8310 || dep->regindex == 35
8311 || dep->regindex == 36
8312 || (rsrc_write && dep->regindex == PSR_CPL))
8314 specs[count++] = tmpl;
8319 /* Several PSR bits have very specific dependencies. */
8320 switch (dep->regindex)
8323 specs[count++] = tmpl;
8328 specs[count++] = tmpl;
8332 /* Only certain CR accesses use PSR.ic */
8333 if (idesc->operands[0] == IA64_OPND_CR3
8334 || idesc->operands[1] == IA64_OPND_CR3)
8337 ((idesc->operands[0] == IA64_OPND_CR3)
8340 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8355 specs[count++] = tmpl;
8364 specs[count++] = tmpl;
8368 /* Only some AR accesses use cpl */
8369 if (idesc->operands[0] == IA64_OPND_AR3
8370 || idesc->operands[1] == IA64_OPND_AR3)
8373 ((idesc->operands[0] == IA64_OPND_AR3)
8376 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8383 && regno <= AR_K7))))
8385 specs[count++] = tmpl;
8390 specs[count++] = tmpl;
8400 if (idesc->operands[0] == IA64_OPND_IMMU24)
8402 mask = CURR_SLOT.opnd[0].X_add_number;
8408 if (mask & ((valueT) 1 << dep->regindex))
8410 specs[count++] = tmpl;
8415 int min = dep->regindex == PSR_DFL ? 2 : 32;
8416 int max = dep->regindex == PSR_DFL ? 31 : 127;
8417 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8418 for (i = 0; i < NELEMS (idesc->operands); i++)
8420 if (idesc->operands[i] == IA64_OPND_F1
8421 || idesc->operands[i] == IA64_OPND_F2
8422 || idesc->operands[i] == IA64_OPND_F3
8423 || idesc->operands[i] == IA64_OPND_F4)
8425 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8426 if (reg >= min && reg <= max)
8428 specs[count++] = tmpl;
8435 int min = dep->regindex == PSR_MFL ? 2 : 32;
8436 int max = dep->regindex == PSR_MFL ? 31 : 127;
8437 /* mfh is read on writes to FR32-127; mfl is read on writes to
8439 for (i = 0; i < idesc->num_outputs; i++)
8441 if (idesc->operands[i] == IA64_OPND_F1)
8443 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8444 if (reg >= min && reg <= max)
8446 specs[count++] = tmpl;
8451 else if (note == 10)
8453 for (i = 0; i < NELEMS (idesc->operands); i++)
8455 if (idesc->operands[i] == IA64_OPND_R1
8456 || idesc->operands[i] == IA64_OPND_R2
8457 || idesc->operands[i] == IA64_OPND_R3)
8459 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8460 if (regno >= 16 && regno <= 31)
8462 specs[count++] = tmpl;
8473 case IA64_RS_AR_FPSR:
8474 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8476 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8477 if (regno == AR_FPSR)
8479 specs[count++] = tmpl;
8484 specs[count++] = tmpl;
8489 /* Handle all AR[REG] resources */
8490 if (note == 0 || note == 1)
8492 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8493 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8494 && regno == dep->regindex)
8496 specs[count++] = tmpl;
8498 /* other AR[REG] resources may be affected by AR accesses */
8499 else if (idesc->operands[0] == IA64_OPND_AR3)
8502 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8503 switch (dep->regindex)
8509 if (regno == AR_BSPSTORE)
8511 specs[count++] = tmpl;
8515 (regno == AR_BSPSTORE
8516 || regno == AR_RNAT))
8518 specs[count++] = tmpl;
8523 else if (idesc->operands[1] == IA64_OPND_AR3)
8526 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8527 switch (dep->regindex)
8532 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8534 specs[count++] = tmpl;
8541 specs[count++] = tmpl;
8551 /* Handle all CR[REG] resources */
8552 if (note == 0 || note == 1)
8554 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8556 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8557 if (regno == dep->regindex)
8559 specs[count++] = tmpl;
8561 else if (!rsrc_write)
8563 /* Reads from CR[IVR] affect other resources. */
8564 if (regno == CR_IVR)
8566 if ((dep->regindex >= CR_IRR0
8567 && dep->regindex <= CR_IRR3)
8568 || dep->regindex == CR_TPR)
8570 specs[count++] = tmpl;
8577 specs[count++] = tmpl;
8586 case IA64_RS_INSERVICE:
8587 /* look for write of EOI (67) or read of IVR (65) */
8588 if ((idesc->operands[0] == IA64_OPND_CR3
8589 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8590 || (idesc->operands[1] == IA64_OPND_CR3
8591 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8593 specs[count++] = tmpl;
8600 specs[count++] = tmpl;
8611 specs[count++] = tmpl;
8615 /* Check if any of the registers accessed are in the rotating region.
8616 mov to/from pr accesses CFM only when qp_regno is in the rotating
8618 for (i = 0; i < NELEMS (idesc->operands); i++)
8620 if (idesc->operands[i] == IA64_OPND_R1
8621 || idesc->operands[i] == IA64_OPND_R2
8622 || idesc->operands[i] == IA64_OPND_R3)
8624 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8625 /* Assumes that md.rot.num_regs is always valid */
8626 if (md.rot.num_regs > 0
8628 && num < 31 + md.rot.num_regs)
8630 specs[count] = tmpl;
8631 specs[count++].specific = 0;
8634 else if (idesc->operands[i] == IA64_OPND_F1
8635 || idesc->operands[i] == IA64_OPND_F2
8636 || idesc->operands[i] == IA64_OPND_F3
8637 || idesc->operands[i] == IA64_OPND_F4)
8639 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8642 specs[count] = tmpl;
8643 specs[count++].specific = 0;
8646 else if (idesc->operands[i] == IA64_OPND_P1
8647 || idesc->operands[i] == IA64_OPND_P2)
8649 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8652 specs[count] = tmpl;
8653 specs[count++].specific = 0;
8657 if (CURR_SLOT.qp_regno > 15)
8659 specs[count] = tmpl;
8660 specs[count++].specific = 0;
8665 /* This is the same as IA64_RS_PRr, except simplified to account for
8666 the fact that there is only one register. */
8670 specs[count++] = tmpl;
8675 if (idesc->operands[2] == IA64_OPND_IMM17)
8676 mask = CURR_SLOT.opnd[2].X_add_number;
8677 if (mask & ((valueT) 1 << 63))
8678 specs[count++] = tmpl;
8680 else if (note == 11)
8682 if ((idesc->operands[0] == IA64_OPND_P1
8683 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8684 || (idesc->operands[1] == IA64_OPND_P2
8685 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8687 specs[count++] = tmpl;
8690 else if (note == 12)
8692 if (CURR_SLOT.qp_regno == 63)
8694 specs[count++] = tmpl;
8701 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8702 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8703 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8704 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8707 && (idesc->operands[0] == IA64_OPND_P1
8708 || idesc->operands[0] == IA64_OPND_P2))
8710 specs[count] = tmpl;
8711 specs[count++].cmp_type =
8712 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8715 && (idesc->operands[1] == IA64_OPND_P1
8716 || idesc->operands[1] == IA64_OPND_P2))
8718 specs[count] = tmpl;
8719 specs[count++].cmp_type =
8720 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8725 if (CURR_SLOT.qp_regno == 63)
8727 specs[count++] = tmpl;
8738 /* FIXME we can identify some individual RSE written resources, but RSE
8739 read resources have not yet been completely identified, so for now
8740 treat RSE as a single resource */
8741 if (strncmp (idesc->name, "mov", 3) == 0)
8745 if (idesc->operands[0] == IA64_OPND_AR3
8746 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8748 specs[count] = tmpl;
8749 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8754 if (idesc->operands[0] == IA64_OPND_AR3)
8756 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8757 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8759 specs[count++] = tmpl;
8762 else if (idesc->operands[1] == IA64_OPND_AR3)
8764 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8765 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8766 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8768 specs[count++] = tmpl;
8775 specs[count++] = tmpl;
8780 /* FIXME -- do any of these need to be non-specific? */
8781 specs[count++] = tmpl;
8785 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8792 /* Clear branch flags on marked resources. This breaks the link between the
8793 QP of the marking instruction and a subsequent branch on the same QP. */
8796 clear_qp_branch_flag (mask)
8800 for (i = 0; i < regdepslen; i++)
8802 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8803 if ((bit & mask) != 0)
8805 regdeps[i].link_to_qp_branch = 0;
8810 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
8811 any mutexes which contain one of the PRs and create new ones when
8815 update_qp_mutex (valueT mask)
8821 while (i < qp_mutexeslen)
8823 if ((qp_mutexes[i].prmask & mask) != 0)
8825 /* If it destroys and creates the same mutex, do nothing. */
8826 if (qp_mutexes[i].prmask == mask
8827 && qp_mutexes[i].path == md.path)
8838 fprintf (stderr, " Clearing mutex relation");
8839 print_prmask (qp_mutexes[i].prmask);
8840 fprintf (stderr, "\n");
8843 /* Deal with the old mutex with more than 3+ PRs only if
8844 the new mutex on the same execution path with it.
8846 FIXME: The 3+ mutex support is incomplete.
8847 dot_pred_rel () may be a better place to fix it. */
8848 if (qp_mutexes[i].path == md.path)
8850 /* If it is a proper subset of the mutex, create a
8853 && (qp_mutexes[i].prmask & mask) == mask)
8856 qp_mutexes[i].prmask &= ~mask;
8857 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
8859 /* Modify the mutex if there are more than one
8867 /* Remove the mutex. */
8868 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8876 add_qp_mutex (mask);
8881 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8883 Any changes to a PR clears the mutex relations which include that PR. */
8886 clear_qp_mutex (mask)
8892 while (i < qp_mutexeslen)
8894 if ((qp_mutexes[i].prmask & mask) != 0)
8898 fprintf (stderr, " Clearing mutex relation");
8899 print_prmask (qp_mutexes[i].prmask);
8900 fprintf (stderr, "\n");
8902 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8909 /* Clear implies relations which contain PRs in the given masks.
8910 P1_MASK indicates the source of the implies relation, while P2_MASK
8911 indicates the implied PR. */
8914 clear_qp_implies (p1_mask, p2_mask)
8921 while (i < qp_implieslen)
8923 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8924 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8927 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8928 qp_implies[i].p1, qp_implies[i].p2);
8929 qp_implies[i] = qp_implies[--qp_implieslen];
8936 /* Add the PRs specified to the list of implied relations. */
8939 add_qp_imply (p1, p2)
8946 /* p0 is not meaningful here. */
8947 if (p1 == 0 || p2 == 0)
8953 /* If it exists already, ignore it. */
8954 for (i = 0; i < qp_implieslen; i++)
8956 if (qp_implies[i].p1 == p1
8957 && qp_implies[i].p2 == p2
8958 && qp_implies[i].path == md.path
8959 && !qp_implies[i].p2_branched)
8963 if (qp_implieslen == qp_impliestotlen)
8965 qp_impliestotlen += 20;
8966 qp_implies = (struct qp_imply *)
8967 xrealloc ((void *) qp_implies,
8968 qp_impliestotlen * sizeof (struct qp_imply));
8971 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8972 qp_implies[qp_implieslen].p1 = p1;
8973 qp_implies[qp_implieslen].p2 = p2;
8974 qp_implies[qp_implieslen].path = md.path;
8975 qp_implies[qp_implieslen++].p2_branched = 0;
8977 /* Add in the implied transitive relations; for everything that p2 implies,
8978 make p1 imply that, too; for everything that implies p1, make it imply p2
8980 for (i = 0; i < qp_implieslen; i++)
8982 if (qp_implies[i].p1 == p2)
8983 add_qp_imply (p1, qp_implies[i].p2);
8984 if (qp_implies[i].p2 == p1)
8985 add_qp_imply (qp_implies[i].p1, p2);
8987 /* Add in mutex relations implied by this implies relation; for each mutex
8988 relation containing p2, duplicate it and replace p2 with p1. */
8989 bit = (valueT) 1 << p1;
8990 mask = (valueT) 1 << p2;
8991 for (i = 0; i < qp_mutexeslen; i++)
8993 if (qp_mutexes[i].prmask & mask)
8994 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8998 /* Add the PRs specified in the mask to the mutex list; this means that only
8999 one of the PRs can be true at any time. PR0 should never be included in
9009 if (qp_mutexeslen == qp_mutexestotlen)
9011 qp_mutexestotlen += 20;
9012 qp_mutexes = (struct qpmutex *)
9013 xrealloc ((void *) qp_mutexes,
9014 qp_mutexestotlen * sizeof (struct qpmutex));
9018 fprintf (stderr, " Registering mutex on");
9019 print_prmask (mask);
9020 fprintf (stderr, "\n");
9022 qp_mutexes[qp_mutexeslen].path = md.path;
9023 qp_mutexes[qp_mutexeslen++].prmask = mask;
9027 has_suffix_p (name, suffix)
9031 size_t namelen = strlen (name);
9032 size_t sufflen = strlen (suffix);
9034 if (namelen <= sufflen)
9036 return strcmp (name + namelen - sufflen, suffix) == 0;
9040 clear_register_values ()
9044 fprintf (stderr, " Clearing register values\n");
9045 for (i = 1; i < NELEMS (gr_values); i++)
9046 gr_values[i].known = 0;
9049 /* Keep track of register values/changes which affect DV tracking.
9051 optimization note: should add a flag to classes of insns where otherwise we
9052 have to examine a group of strings to identify them. */
9055 note_register_values (idesc)
9056 struct ia64_opcode *idesc;
9058 valueT qp_changemask = 0;
9061 /* Invalidate values for registers being written to. */
9062 for (i = 0; i < idesc->num_outputs; i++)
9064 if (idesc->operands[i] == IA64_OPND_R1
9065 || idesc->operands[i] == IA64_OPND_R2
9066 || idesc->operands[i] == IA64_OPND_R3)
9068 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9069 if (regno > 0 && regno < NELEMS (gr_values))
9070 gr_values[regno].known = 0;
9072 else if (idesc->operands[i] == IA64_OPND_R3_2)
9074 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9075 if (regno > 0 && regno < 4)
9076 gr_values[regno].known = 0;
9078 else if (idesc->operands[i] == IA64_OPND_P1
9079 || idesc->operands[i] == IA64_OPND_P2)
9081 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9082 qp_changemask |= (valueT) 1 << regno;
9084 else if (idesc->operands[i] == IA64_OPND_PR)
9086 if (idesc->operands[2] & (valueT) 0x10000)
9087 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9089 qp_changemask = idesc->operands[2];
9092 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9094 if (idesc->operands[1] & ((valueT) 1 << 43))
9095 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9097 qp_changemask = idesc->operands[1];
9098 qp_changemask &= ~(valueT) 0xFFFF;
9103 /* Always clear qp branch flags on any PR change. */
9104 /* FIXME there may be exceptions for certain compares. */
9105 clear_qp_branch_flag (qp_changemask);
9107 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9108 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9110 qp_changemask |= ~(valueT) 0xFFFF;
9111 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9113 for (i = 32; i < 32 + md.rot.num_regs; i++)
9114 gr_values[i].known = 0;
9116 clear_qp_mutex (qp_changemask);
9117 clear_qp_implies (qp_changemask, qp_changemask);
9119 /* After a call, all register values are undefined, except those marked
9121 else if (strncmp (idesc->name, "br.call", 6) == 0
9122 || strncmp (idesc->name, "brl.call", 7) == 0)
9124 /* FIXME keep GR values which are marked as "safe_across_calls" */
9125 clear_register_values ();
9126 clear_qp_mutex (~qp_safe_across_calls);
9127 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9128 clear_qp_branch_flag (~qp_safe_across_calls);
9130 else if (is_interruption_or_rfi (idesc)
9131 || is_taken_branch (idesc))
9133 clear_register_values ();
9134 clear_qp_mutex (~(valueT) 0);
9135 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9137 /* Look for mutex and implies relations. */
9138 else if ((idesc->operands[0] == IA64_OPND_P1
9139 || idesc->operands[0] == IA64_OPND_P2)
9140 && (idesc->operands[1] == IA64_OPND_P1
9141 || idesc->operands[1] == IA64_OPND_P2))
9143 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9144 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9145 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9146 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9148 /* If both PRs are PR0, we can't really do anything. */
9149 if (p1 == 0 && p2 == 0)
9152 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9154 /* In general, clear mutexes and implies which include P1 or P2,
9155 with the following exceptions. */
9156 else if (has_suffix_p (idesc->name, ".or.andcm")
9157 || has_suffix_p (idesc->name, ".and.orcm"))
9159 clear_qp_implies (p2mask, p1mask);
9161 else if (has_suffix_p (idesc->name, ".andcm")
9162 || has_suffix_p (idesc->name, ".and"))
9164 clear_qp_implies (0, p1mask | p2mask);
9166 else if (has_suffix_p (idesc->name, ".orcm")
9167 || has_suffix_p (idesc->name, ".or"))
9169 clear_qp_mutex (p1mask | p2mask);
9170 clear_qp_implies (p1mask | p2mask, 0);
9176 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9178 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9179 if (p1 == 0 || p2 == 0)
9180 clear_qp_mutex (p1mask | p2mask);
9182 added = update_qp_mutex (p1mask | p2mask);
9184 if (CURR_SLOT.qp_regno == 0
9185 || has_suffix_p (idesc->name, ".unc"))
9187 if (added == 0 && p1 && p2)
9188 add_qp_mutex (p1mask | p2mask);
9189 if (CURR_SLOT.qp_regno != 0)
9192 add_qp_imply (p1, CURR_SLOT.qp_regno);
9194 add_qp_imply (p2, CURR_SLOT.qp_regno);
9199 /* Look for mov imm insns into GRs. */
9200 else if (idesc->operands[0] == IA64_OPND_R1
9201 && (idesc->operands[1] == IA64_OPND_IMM22
9202 || idesc->operands[1] == IA64_OPND_IMMU64)
9203 && (strcmp (idesc->name, "mov") == 0
9204 || strcmp (idesc->name, "movl") == 0))
9206 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9207 if (regno > 0 && regno < NELEMS (gr_values))
9209 gr_values[regno].known = 1;
9210 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9211 gr_values[regno].path = md.path;
9214 fprintf (stderr, " Know gr%d = ", regno);
9215 fprintf_vma (stderr, gr_values[regno].value);
9216 fputs ("\n", stderr);
9222 clear_qp_mutex (qp_changemask);
9223 clear_qp_implies (qp_changemask, qp_changemask);
9227 /* Return whether the given predicate registers are currently mutex. */
9230 qp_mutex (p1, p2, path)
9240 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9241 for (i = 0; i < qp_mutexeslen; i++)
9243 if (qp_mutexes[i].path >= path
9244 && (qp_mutexes[i].prmask & mask) == mask)
9251 /* Return whether the given resource is in the given insn's list of chks
9252 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9256 resources_match (rs, idesc, note, qp_regno, path)
9258 struct ia64_opcode *idesc;
9263 struct rsrc specs[MAX_SPECS];
9266 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9267 we don't need to check. One exception is note 11, which indicates that
9268 target predicates are written regardless of PR[qp]. */
9269 if (qp_mutex (rs->qp_regno, qp_regno, path)
9273 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9276 /* UNAT checking is a bit more specific than other resources */
9277 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9278 && specs[count].mem_offset.hint
9279 && rs->mem_offset.hint)
9281 if (rs->mem_offset.base == specs[count].mem_offset.base)
9283 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9284 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9291 /* Skip apparent PR write conflicts where both writes are an AND or both
9292 writes are an OR. */
9293 if (rs->dependency->specifier == IA64_RS_PR
9294 || rs->dependency->specifier == IA64_RS_PRr
9295 || rs->dependency->specifier == IA64_RS_PR63)
9297 if (specs[count].cmp_type != CMP_NONE
9298 && specs[count].cmp_type == rs->cmp_type)
9301 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9302 dv_mode[rs->dependency->mode],
9303 rs->dependency->specifier != IA64_RS_PR63 ?
9304 specs[count].index : 63);
9309 " %s on parallel compare conflict %s vs %s on PR%d\n",
9310 dv_mode[rs->dependency->mode],
9311 dv_cmp_type[rs->cmp_type],
9312 dv_cmp_type[specs[count].cmp_type],
9313 rs->dependency->specifier != IA64_RS_PR63 ?
9314 specs[count].index : 63);
9318 /* If either resource is not specific, conservatively assume a conflict
9320 if (!specs[count].specific || !rs->specific)
9322 else if (specs[count].index == rs->index)
9327 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9333 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9334 insert a stop to create the break. Update all resource dependencies
9335 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9336 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9337 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9341 insn_group_break (insert_stop, qp_regno, save_current)
9348 if (insert_stop && md.num_slots_in_use > 0)
9349 PREV_SLOT.end_of_insn_group = 1;
9353 fprintf (stderr, " Insn group break%s",
9354 (insert_stop ? " (w/stop)" : ""));
9356 fprintf (stderr, " effective for QP=%d", qp_regno);
9357 fprintf (stderr, "\n");
9361 while (i < regdepslen)
9363 const struct ia64_dependency *dep = regdeps[i].dependency;
9366 && regdeps[i].qp_regno != qp_regno)
9373 && CURR_SLOT.src_file == regdeps[i].file
9374 && CURR_SLOT.src_line == regdeps[i].line)
9380 /* clear dependencies which are automatically cleared by a stop, or
9381 those that have reached the appropriate state of insn serialization */
9382 if (dep->semantics == IA64_DVS_IMPLIED
9383 || dep->semantics == IA64_DVS_IMPLIEDF
9384 || regdeps[i].insn_srlz == STATE_SRLZ)
9386 print_dependency ("Removing", i);
9387 regdeps[i] = regdeps[--regdepslen];
9391 if (dep->semantics == IA64_DVS_DATA
9392 || dep->semantics == IA64_DVS_INSTR
9393 || dep->semantics == IA64_DVS_SPECIFIC)
9395 if (regdeps[i].insn_srlz == STATE_NONE)
9396 regdeps[i].insn_srlz = STATE_STOP;
9397 if (regdeps[i].data_srlz == STATE_NONE)
9398 regdeps[i].data_srlz = STATE_STOP;
9405 /* Add the given resource usage spec to the list of active dependencies. */
9408 mark_resource (idesc, dep, spec, depind, path)
9409 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9410 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9415 if (regdepslen == regdepstotlen)
9417 regdepstotlen += 20;
9418 regdeps = (struct rsrc *)
9419 xrealloc ((void *) regdeps,
9420 regdepstotlen * sizeof (struct rsrc));
9423 regdeps[regdepslen] = *spec;
9424 regdeps[regdepslen].depind = depind;
9425 regdeps[regdepslen].path = path;
9426 regdeps[regdepslen].file = CURR_SLOT.src_file;
9427 regdeps[regdepslen].line = CURR_SLOT.src_line;
9429 print_dependency ("Adding", regdepslen);
9435 print_dependency (action, depind)
9441 fprintf (stderr, " %s %s '%s'",
9442 action, dv_mode[(regdeps[depind].dependency)->mode],
9443 (regdeps[depind].dependency)->name);
9444 if (regdeps[depind].specific && regdeps[depind].index != 0)
9445 fprintf (stderr, " (%d)", regdeps[depind].index);
9446 if (regdeps[depind].mem_offset.hint)
9448 fputs (" ", stderr);
9449 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9450 fputs ("+", stderr);
9451 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9453 fprintf (stderr, "\n");
9458 instruction_serialization ()
9462 fprintf (stderr, " Instruction serialization\n");
9463 for (i = 0; i < regdepslen; i++)
9464 if (regdeps[i].insn_srlz == STATE_STOP)
9465 regdeps[i].insn_srlz = STATE_SRLZ;
9469 data_serialization ()
9473 fprintf (stderr, " Data serialization\n");
9474 while (i < regdepslen)
9476 if (regdeps[i].data_srlz == STATE_STOP
9477 /* Note: as of 991210, all "other" dependencies are cleared by a
9478 data serialization. This might change with new tables */
9479 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9481 print_dependency ("Removing", i);
9482 regdeps[i] = regdeps[--regdepslen];
9489 /* Insert stops and serializations as needed to avoid DVs. */
9492 remove_marked_resource (rs)
9495 switch (rs->dependency->semantics)
9497 case IA64_DVS_SPECIFIC:
9499 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9500 /* ...fall through... */
9501 case IA64_DVS_INSTR:
9503 fprintf (stderr, "Inserting instr serialization\n");
9504 if (rs->insn_srlz < STATE_STOP)
9505 insn_group_break (1, 0, 0);
9506 if (rs->insn_srlz < STATE_SRLZ)
9508 int oldqp = CURR_SLOT.qp_regno;
9509 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9510 /* Manually jam a srlz.i insn into the stream */
9511 CURR_SLOT.qp_regno = 0;
9512 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9513 instruction_serialization ();
9514 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9515 if (++md.num_slots_in_use >= NUM_SLOTS)
9517 CURR_SLOT.qp_regno = oldqp;
9518 CURR_SLOT.idesc = oldidesc;
9520 insn_group_break (1, 0, 0);
9522 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9523 "other" types of DV are eliminated
9524 by a data serialization */
9527 fprintf (stderr, "Inserting data serialization\n");
9528 if (rs->data_srlz < STATE_STOP)
9529 insn_group_break (1, 0, 0);
9531 int oldqp = CURR_SLOT.qp_regno;
9532 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9533 /* Manually jam a srlz.d insn into the stream */
9534 CURR_SLOT.qp_regno = 0;
9535 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9536 data_serialization ();
9537 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9538 if (++md.num_slots_in_use >= NUM_SLOTS)
9540 CURR_SLOT.qp_regno = oldqp;
9541 CURR_SLOT.idesc = oldidesc;
9544 case IA64_DVS_IMPLIED:
9545 case IA64_DVS_IMPLIEDF:
9547 fprintf (stderr, "Inserting stop\n");
9548 insn_group_break (1, 0, 0);
9555 /* Check the resources used by the given opcode against the current dependency
9558 The check is run once for each execution path encountered. In this case,
9559 a unique execution path is the sequence of instructions following a code
9560 entry point, e.g. the following has three execution paths, one starting
9561 at L0, one at L1, and one at L2.
9570 check_dependencies (idesc)
9571 struct ia64_opcode *idesc;
9573 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9577 /* Note that the number of marked resources may change within the
9578 loop if in auto mode. */
9580 while (i < regdepslen)
9582 struct rsrc *rs = ®deps[i];
9583 const struct ia64_dependency *dep = rs->dependency;
9588 if (dep->semantics == IA64_DVS_NONE
9589 || (chkind = depends_on (rs->depind, idesc)) == -1)
9595 note = NOTE (opdeps->chks[chkind]);
9597 /* Check this resource against each execution path seen thus far. */
9598 for (path = 0; path <= md.path; path++)
9602 /* If the dependency wasn't on the path being checked, ignore it. */
9603 if (rs->path < path)
9606 /* If the QP for this insn implies a QP which has branched, don't
9607 bother checking. Ed. NOTE: I don't think this check is terribly
9608 useful; what's the point of generating code which will only be
9609 reached if its QP is zero?
9610 This code was specifically inserted to handle the following code,
9611 based on notes from Intel's DV checking code, where p1 implies p2.
9617 if (CURR_SLOT.qp_regno != 0)
9621 for (implies = 0; implies < qp_implieslen; implies++)
9623 if (qp_implies[implies].path >= path
9624 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9625 && qp_implies[implies].p2_branched)
9635 if ((matchtype = resources_match (rs, idesc, note,
9636 CURR_SLOT.qp_regno, path)) != 0)
9639 char pathmsg[256] = "";
9640 char indexmsg[256] = "";
9641 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9644 sprintf (pathmsg, " when entry is at label '%s'",
9645 md.entry_labels[path - 1]);
9646 if (rs->specific && rs->index != 0)
9647 sprintf (indexmsg, ", specific resource number is %d",
9649 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9651 (certain ? "violates" : "may violate"),
9652 dv_mode[dep->mode], dep->name,
9653 dv_sem[dep->semantics],
9656 if (md.explicit_mode)
9658 as_warn ("%s", msg);
9660 as_warn (_("Only the first path encountering the conflict "
9662 as_warn_where (rs->file, rs->line,
9663 _("This is the location of the "
9664 "conflicting usage"));
9665 /* Don't bother checking other paths, to avoid duplicating
9672 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9674 remove_marked_resource (rs);
9676 /* since the set of dependencies has changed, start over */
9677 /* FIXME -- since we're removing dvs as we go, we
9678 probably don't really need to start over... */
9691 /* Register new dependencies based on the given opcode. */
9694 mark_resources (idesc)
9695 struct ia64_opcode *idesc;
9698 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9699 int add_only_qp_reads = 0;
9701 /* A conditional branch only uses its resources if it is taken; if it is
9702 taken, we stop following that path. The other branch types effectively
9703 *always* write their resources. If it's not taken, register only QP
9705 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9707 add_only_qp_reads = 1;
9711 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9713 for (i = 0; i < opdeps->nregs; i++)
9715 const struct ia64_dependency *dep;
9716 struct rsrc specs[MAX_SPECS];
9721 dep = ia64_find_dependency (opdeps->regs[i]);
9722 note = NOTE (opdeps->regs[i]);
9724 if (add_only_qp_reads
9725 && !(dep->mode == IA64_DV_WAR
9726 && (dep->specifier == IA64_RS_PR
9727 || dep->specifier == IA64_RS_PRr
9728 || dep->specifier == IA64_RS_PR63)))
9731 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9734 if (md.debug_dv && !count)
9735 fprintf (stderr, " No %s %s usage found (path %d)\n",
9736 dv_mode[dep->mode], dep->name, md.path);
9741 mark_resource (idesc, dep, &specs[count],
9742 DEP (opdeps->regs[i]), md.path);
9745 /* The execution path may affect register values, which may in turn
9746 affect which indirect-access resources are accessed. */
9747 switch (dep->specifier)
9759 for (path = 0; path < md.path; path++)
9761 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9763 mark_resource (idesc, dep, &specs[count],
9764 DEP (opdeps->regs[i]), path);
9771 /* Remove dependencies when they no longer apply. */
9774 update_dependencies (idesc)
9775 struct ia64_opcode *idesc;
9779 if (strcmp (idesc->name, "srlz.i") == 0)
9781 instruction_serialization ();
9783 else if (strcmp (idesc->name, "srlz.d") == 0)
9785 data_serialization ();
9787 else if (is_interruption_or_rfi (idesc)
9788 || is_taken_branch (idesc))
9790 /* Although technically the taken branch doesn't clear dependencies
9791 which require a srlz.[id], we don't follow the branch; the next
9792 instruction is assumed to start with a clean slate. */
9796 else if (is_conditional_branch (idesc)
9797 && CURR_SLOT.qp_regno != 0)
9799 int is_call = strstr (idesc->name, ".call") != NULL;
9801 for (i = 0; i < qp_implieslen; i++)
9803 /* If the conditional branch's predicate is implied by the predicate
9804 in an existing dependency, remove that dependency. */
9805 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9808 /* Note that this implied predicate takes a branch so that if
9809 a later insn generates a DV but its predicate implies this
9810 one, we can avoid the false DV warning. */
9811 qp_implies[i].p2_branched = 1;
9812 while (depind < regdepslen)
9814 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9816 print_dependency ("Removing", depind);
9817 regdeps[depind] = regdeps[--regdepslen];
9824 /* Any marked resources which have this same predicate should be
9825 cleared, provided that the QP hasn't been modified between the
9826 marking instruction and the branch. */
9829 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9834 while (i < regdepslen)
9836 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9837 && regdeps[i].link_to_qp_branch
9838 && (regdeps[i].file != CURR_SLOT.src_file
9839 || regdeps[i].line != CURR_SLOT.src_line))
9841 /* Treat like a taken branch */
9842 print_dependency ("Removing", i);
9843 regdeps[i] = regdeps[--regdepslen];
9852 /* Examine the current instruction for dependency violations. */
9856 struct ia64_opcode *idesc;
9860 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9861 idesc->name, CURR_SLOT.src_line,
9862 idesc->dependencies->nchks,
9863 idesc->dependencies->nregs);
9866 /* Look through the list of currently marked resources; if the current
9867 instruction has the dependency in its chks list which uses that resource,
9868 check against the specific resources used. */
9869 check_dependencies (idesc);
9871 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9872 then add them to the list of marked resources. */
9873 mark_resources (idesc);
9875 /* There are several types of dependency semantics, and each has its own
9876 requirements for being cleared
9878 Instruction serialization (insns separated by interruption, rfi, or
9879 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9881 Data serialization (instruction serialization, or writer + srlz.d +
9882 reader, where writer and srlz.d are in separate groups) clears
9883 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9884 always be the case).
9886 Instruction group break (groups separated by stop, taken branch,
9887 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9889 update_dependencies (idesc);
9891 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9892 warning. Keep track of as many as possible that are useful. */
9893 note_register_values (idesc);
9895 /* We don't need or want this anymore. */
9896 md.mem_offset.hint = 0;
9901 /* Translate one line of assembly. Pseudo ops and labels do not show
9907 char *saved_input_line_pointer, *mnemonic;
9908 const struct pseudo_opcode *pdesc;
9909 struct ia64_opcode *idesc;
9910 unsigned char qp_regno;
9914 saved_input_line_pointer = input_line_pointer;
9915 input_line_pointer = str;
9917 /* extract the opcode (mnemonic): */
9919 mnemonic = input_line_pointer;
9920 ch = get_symbol_end ();
9921 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9924 *input_line_pointer = ch;
9925 (*pdesc->handler) (pdesc->arg);
9929 /* Find the instruction descriptor matching the arguments. */
9931 idesc = ia64_find_opcode (mnemonic);
9932 *input_line_pointer = ch;
9935 as_bad ("Unknown opcode `%s'", mnemonic);
9939 idesc = parse_operands (idesc);
9943 /* Handle the dynamic ops we can handle now: */
9944 if (idesc->type == IA64_TYPE_DYN)
9946 if (strcmp (idesc->name, "add") == 0)
9948 if (CURR_SLOT.opnd[2].X_op == O_register
9949 && CURR_SLOT.opnd[2].X_add_number < 4)
9953 ia64_free_opcode (idesc);
9954 idesc = ia64_find_opcode (mnemonic);
9956 know (!idesc->next);
9959 else if (strcmp (idesc->name, "mov") == 0)
9961 enum ia64_opnd opnd1, opnd2;
9964 opnd1 = idesc->operands[0];
9965 opnd2 = idesc->operands[1];
9966 if (opnd1 == IA64_OPND_AR3)
9968 else if (opnd2 == IA64_OPND_AR3)
9972 if (CURR_SLOT.opnd[rop].X_op == O_register
9973 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9977 ia64_free_opcode (idesc);
9978 idesc = ia64_find_opcode (mnemonic);
9979 while (idesc != NULL
9980 && (idesc->operands[0] != opnd1
9981 || idesc->operands[1] != opnd2))
9982 idesc = get_next_opcode (idesc);
9987 if (md.qp.X_op == O_register)
9989 qp_regno = md.qp.X_add_number - REG_P;
9990 md.qp.X_op = O_absent;
9993 flags = idesc->flags;
9995 if ((flags & IA64_OPCODE_FIRST) != 0)
9997 /* The alignment frag has to end with a stop bit only if the
9998 next instruction after the alignment directive has to be
9999 the first instruction in an instruction group. */
10002 while (align_frag->fr_type != rs_align_code)
10004 align_frag = align_frag->fr_next;
10005 assert (align_frag);
10007 if (align_frag->fr_next == frag_now)
10008 align_frag->tc_frag_data = 1;
10011 insn_group_break (1, 0, 0);
10015 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10017 as_bad ("`%s' cannot be predicated", idesc->name);
10021 /* Build the instruction. */
10022 CURR_SLOT.qp_regno = qp_regno;
10023 CURR_SLOT.idesc = idesc;
10024 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10025 dwarf2_where (&CURR_SLOT.debug_line);
10027 /* Add unwind entry, if there is one. */
10028 if (unwind.current_entry)
10030 CURR_SLOT.unwind_record = unwind.current_entry;
10031 unwind.current_entry = NULL;
10034 /* Check for dependency violations. */
10038 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10039 if (++md.num_slots_in_use >= NUM_SLOTS)
10040 emit_one_bundle ();
10042 if ((flags & IA64_OPCODE_LAST) != 0)
10043 insn_group_break (1, 0, 0);
10045 md.last_text_seg = now_seg;
10048 input_line_pointer = saved_input_line_pointer;
10051 /* Called when symbol NAME cannot be found in the symbol table.
10052 Should be used for dynamic valued symbols only. */
10055 md_undefined_symbol (name)
10056 char *name ATTRIBUTE_UNUSED;
10061 /* Called for any expression that can not be recognized. When the
10062 function is called, `input_line_pointer' will point to the start of
10069 enum pseudo_type pseudo_type;
10074 switch (*input_line_pointer)
10077 /* Find what relocation pseudo-function we're dealing with. */
10079 ch = *++input_line_pointer;
10080 for (i = 0; i < NELEMS (pseudo_func); ++i)
10081 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
10083 len = strlen (pseudo_func[i].name);
10084 if (strncmp (pseudo_func[i].name + 1,
10085 input_line_pointer + 1, len - 1) == 0
10086 && !is_part_of_name (input_line_pointer[len]))
10088 input_line_pointer += len;
10089 pseudo_type = pseudo_func[i].type;
10093 switch (pseudo_type)
10095 case PSEUDO_FUNC_RELOC:
10096 SKIP_WHITESPACE ();
10097 if (*input_line_pointer != '(')
10099 as_bad ("Expected '('");
10103 ++input_line_pointer;
10105 if (*input_line_pointer++ != ')')
10107 as_bad ("Missing ')'");
10110 if (e->X_op != O_symbol)
10112 if (e->X_op != O_pseudo_fixup)
10114 as_bad ("Not a symbolic expression");
10117 if (i != FUNC_LT_RELATIVE)
10119 as_bad ("Illegal combination of relocation functions");
10122 switch (S_GET_VALUE (e->X_op_symbol))
10124 case FUNC_FPTR_RELATIVE:
10125 i = FUNC_LT_FPTR_RELATIVE; break;
10126 case FUNC_DTP_MODULE:
10127 i = FUNC_LT_DTP_MODULE; break;
10128 case FUNC_DTP_RELATIVE:
10129 i = FUNC_LT_DTP_RELATIVE; break;
10130 case FUNC_TP_RELATIVE:
10131 i = FUNC_LT_TP_RELATIVE; break;
10133 as_bad ("Illegal combination of relocation functions");
10137 /* Make sure gas doesn't get rid of local symbols that are used
10139 e->X_op = O_pseudo_fixup;
10140 e->X_op_symbol = pseudo_func[i].u.sym;
10143 case PSEUDO_FUNC_CONST:
10144 e->X_op = O_constant;
10145 e->X_add_number = pseudo_func[i].u.ival;
10148 case PSEUDO_FUNC_REG:
10149 e->X_op = O_register;
10150 e->X_add_number = pseudo_func[i].u.ival;
10154 name = input_line_pointer - 1;
10156 as_bad ("Unknown pseudo function `%s'", name);
10162 ++input_line_pointer;
10164 if (*input_line_pointer != ']')
10166 as_bad ("Closing bracket misssing");
10171 if (e->X_op != O_register)
10172 as_bad ("Register expected as index");
10174 ++input_line_pointer;
10185 ignore_rest_of_line ();
10188 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10189 a section symbol plus some offset. For relocs involving @fptr(),
10190 directives we don't want such adjustments since we need to have the
10191 original symbol's name in the reloc. */
10193 ia64_fix_adjustable (fix)
10196 /* Prevent all adjustments to global symbols */
10197 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10200 switch (fix->fx_r_type)
10202 case BFD_RELOC_IA64_FPTR64I:
10203 case BFD_RELOC_IA64_FPTR32MSB:
10204 case BFD_RELOC_IA64_FPTR32LSB:
10205 case BFD_RELOC_IA64_FPTR64MSB:
10206 case BFD_RELOC_IA64_FPTR64LSB:
10207 case BFD_RELOC_IA64_LTOFF_FPTR22:
10208 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10218 ia64_force_relocation (fix)
10221 switch (fix->fx_r_type)
10223 case BFD_RELOC_IA64_FPTR64I:
10224 case BFD_RELOC_IA64_FPTR32MSB:
10225 case BFD_RELOC_IA64_FPTR32LSB:
10226 case BFD_RELOC_IA64_FPTR64MSB:
10227 case BFD_RELOC_IA64_FPTR64LSB:
10229 case BFD_RELOC_IA64_LTOFF22:
10230 case BFD_RELOC_IA64_LTOFF64I:
10231 case BFD_RELOC_IA64_LTOFF_FPTR22:
10232 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10233 case BFD_RELOC_IA64_PLTOFF22:
10234 case BFD_RELOC_IA64_PLTOFF64I:
10235 case BFD_RELOC_IA64_PLTOFF64MSB:
10236 case BFD_RELOC_IA64_PLTOFF64LSB:
10238 case BFD_RELOC_IA64_LTOFF22X:
10239 case BFD_RELOC_IA64_LDXMOV:
10246 return generic_force_reloc (fix);
10249 /* Decide from what point a pc-relative relocation is relative to,
10250 relative to the pc-relative fixup. Er, relatively speaking. */
10252 ia64_pcrel_from_section (fix, sec)
10256 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10258 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10265 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10267 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10271 expr.X_op = O_pseudo_fixup;
10272 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10273 expr.X_add_number = 0;
10274 expr.X_add_symbol = symbol;
10275 emit_expr (&expr, size);
10278 /* This is called whenever some data item (not an instruction) needs a
10279 fixup. We pick the right reloc code depending on the byteorder
10280 currently in effect. */
10282 ia64_cons_fix_new (f, where, nbytes, exp)
10288 bfd_reloc_code_real_type code;
10293 /* There are no reloc for 8 and 16 bit quantities, but we allow
10294 them here since they will work fine as long as the expression
10295 is fully defined at the end of the pass over the source file. */
10296 case 1: code = BFD_RELOC_8; break;
10297 case 2: code = BFD_RELOC_16; break;
10299 if (target_big_endian)
10300 code = BFD_RELOC_IA64_DIR32MSB;
10302 code = BFD_RELOC_IA64_DIR32LSB;
10306 /* In 32-bit mode, data8 could mean function descriptors too. */
10307 if (exp->X_op == O_pseudo_fixup
10308 && exp->X_op_symbol
10309 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10310 && !(md.flags & EF_IA_64_ABI64))
10312 if (target_big_endian)
10313 code = BFD_RELOC_IA64_IPLTMSB;
10315 code = BFD_RELOC_IA64_IPLTLSB;
10316 exp->X_op = O_symbol;
10321 if (target_big_endian)
10322 code = BFD_RELOC_IA64_DIR64MSB;
10324 code = BFD_RELOC_IA64_DIR64LSB;
10329 if (exp->X_op == O_pseudo_fixup
10330 && exp->X_op_symbol
10331 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10333 if (target_big_endian)
10334 code = BFD_RELOC_IA64_IPLTMSB;
10336 code = BFD_RELOC_IA64_IPLTLSB;
10337 exp->X_op = O_symbol;
10343 as_bad ("Unsupported fixup size %d", nbytes);
10344 ignore_rest_of_line ();
10348 if (exp->X_op == O_pseudo_fixup)
10350 exp->X_op = O_symbol;
10351 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10352 /* ??? If code unchanged, unsupported. */
10355 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10356 /* We need to store the byte order in effect in case we're going
10357 to fix an 8 or 16 bit relocation (for which there no real
10358 relocs available). See md_apply_fix3(). */
10359 fix->tc_fix_data.bigendian = target_big_endian;
10362 /* Return the actual relocation we wish to associate with the pseudo
10363 reloc described by SYM and R_TYPE. SYM should be one of the
10364 symbols in the pseudo_func array, or NULL. */
10366 static bfd_reloc_code_real_type
10367 ia64_gen_real_reloc_type (sym, r_type)
10368 struct symbol *sym;
10369 bfd_reloc_code_real_type r_type;
10371 bfd_reloc_code_real_type new = 0;
10378 switch (S_GET_VALUE (sym))
10380 case FUNC_FPTR_RELATIVE:
10383 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10384 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10385 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10386 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10387 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10392 case FUNC_GP_RELATIVE:
10395 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10396 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10397 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10398 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10399 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10400 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10405 case FUNC_LT_RELATIVE:
10408 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10409 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10414 case FUNC_LT_RELATIVE_X:
10417 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10422 case FUNC_PC_RELATIVE:
10425 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10426 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10427 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10428 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10429 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10430 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10435 case FUNC_PLT_RELATIVE:
10438 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10439 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10440 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10441 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10446 case FUNC_SEC_RELATIVE:
10449 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10450 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10451 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10452 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10457 case FUNC_SEG_RELATIVE:
10460 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10461 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10462 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10463 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10468 case FUNC_LTV_RELATIVE:
10471 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10472 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10473 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10474 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10479 case FUNC_LT_FPTR_RELATIVE:
10482 case BFD_RELOC_IA64_IMM22:
10483 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10484 case BFD_RELOC_IA64_IMM64:
10485 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10491 case FUNC_TP_RELATIVE:
10494 case BFD_RELOC_IA64_IMM14:
10495 new = BFD_RELOC_IA64_TPREL14; break;
10496 case BFD_RELOC_IA64_IMM22:
10497 new = BFD_RELOC_IA64_TPREL22; break;
10498 case BFD_RELOC_IA64_IMM64:
10499 new = BFD_RELOC_IA64_TPREL64I; break;
10505 case FUNC_LT_TP_RELATIVE:
10508 case BFD_RELOC_IA64_IMM22:
10509 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10515 case FUNC_LT_DTP_MODULE:
10518 case BFD_RELOC_IA64_IMM22:
10519 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10525 case FUNC_DTP_RELATIVE:
10528 case BFD_RELOC_IA64_DIR64MSB:
10529 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10530 case BFD_RELOC_IA64_DIR64LSB:
10531 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10532 case BFD_RELOC_IA64_IMM14:
10533 new = BFD_RELOC_IA64_DTPREL14; break;
10534 case BFD_RELOC_IA64_IMM22:
10535 new = BFD_RELOC_IA64_DTPREL22; break;
10536 case BFD_RELOC_IA64_IMM64:
10537 new = BFD_RELOC_IA64_DTPREL64I; break;
10543 case FUNC_LT_DTP_RELATIVE:
10546 case BFD_RELOC_IA64_IMM22:
10547 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10553 case FUNC_IPLT_RELOC:
10560 /* Hmmmm. Should this ever occur? */
10567 /* Here is where generate the appropriate reloc for pseudo relocation
10570 ia64_validate_fix (fix)
10573 switch (fix->fx_r_type)
10575 case BFD_RELOC_IA64_FPTR64I:
10576 case BFD_RELOC_IA64_FPTR32MSB:
10577 case BFD_RELOC_IA64_FPTR64LSB:
10578 case BFD_RELOC_IA64_LTOFF_FPTR22:
10579 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10580 if (fix->fx_offset != 0)
10581 as_bad_where (fix->fx_file, fix->fx_line,
10582 "No addend allowed in @fptr() relocation");
10590 fix_insn (fix, odesc, value)
10592 const struct ia64_operand *odesc;
10595 bfd_vma insn[3], t0, t1, control_bits;
10600 slot = fix->fx_where & 0x3;
10601 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10603 /* Bundles are always in little-endian byte order */
10604 t0 = bfd_getl64 (fixpos);
10605 t1 = bfd_getl64 (fixpos + 8);
10606 control_bits = t0 & 0x1f;
10607 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10608 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10609 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10612 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10614 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10615 insn[2] |= (((value & 0x7f) << 13)
10616 | (((value >> 7) & 0x1ff) << 27)
10617 | (((value >> 16) & 0x1f) << 22)
10618 | (((value >> 21) & 0x1) << 21)
10619 | (((value >> 63) & 0x1) << 36));
10621 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10623 if (value & ~0x3fffffffffffffffULL)
10624 err = "integer operand out of range";
10625 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10626 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10628 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10631 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10632 insn[2] |= ((((value >> 59) & 0x1) << 36)
10633 | (((value >> 0) & 0xfffff) << 13));
10636 err = (*odesc->insert) (odesc, value, insn + slot);
10639 as_bad_where (fix->fx_file, fix->fx_line, err);
10641 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10642 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10643 number_to_chars_littleendian (fixpos + 0, t0, 8);
10644 number_to_chars_littleendian (fixpos + 8, t1, 8);
10647 /* Attempt to simplify or even eliminate a fixup. The return value is
10648 ignored; perhaps it was once meaningful, but now it is historical.
10649 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10651 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10655 md_apply_fix3 (fix, valP, seg)
10658 segT seg ATTRIBUTE_UNUSED;
10661 valueT value = *valP;
10663 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10667 switch (fix->fx_r_type)
10669 case BFD_RELOC_IA64_DIR32MSB:
10670 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10673 case BFD_RELOC_IA64_DIR32LSB:
10674 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10677 case BFD_RELOC_IA64_DIR64MSB:
10678 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10681 case BFD_RELOC_IA64_DIR64LSB:
10682 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10691 switch (fix->fx_r_type)
10693 case BFD_RELOC_UNUSED:
10694 /* This must be a TAG13 or TAG13b operand. There are no external
10695 relocs defined for them, so we must give an error. */
10696 as_bad_where (fix->fx_file, fix->fx_line,
10697 "%s must have a constant value",
10698 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10702 case BFD_RELOC_IA64_TPREL14:
10703 case BFD_RELOC_IA64_TPREL22:
10704 case BFD_RELOC_IA64_TPREL64I:
10705 case BFD_RELOC_IA64_LTOFF_TPREL22:
10706 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10707 case BFD_RELOC_IA64_DTPREL14:
10708 case BFD_RELOC_IA64_DTPREL22:
10709 case BFD_RELOC_IA64_DTPREL64I:
10710 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10711 S_SET_THREAD_LOCAL (fix->fx_addsy);
10718 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10720 if (fix->tc_fix_data.bigendian)
10721 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10723 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10728 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10733 /* Generate the BFD reloc to be stuck in the object file from the
10734 fixup used internally in the assembler. */
10737 tc_gen_reloc (sec, fixp)
10738 asection *sec ATTRIBUTE_UNUSED;
10743 reloc = xmalloc (sizeof (*reloc));
10744 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10745 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10746 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10747 reloc->addend = fixp->fx_offset;
10748 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10752 as_bad_where (fixp->fx_file, fixp->fx_line,
10753 "Cannot represent %s relocation in object file",
10754 bfd_get_reloc_code_name (fixp->fx_r_type));
10759 /* Turn a string in input_line_pointer into a floating point constant
10760 of type TYPE, and store the appropriate bytes in *LIT. The number
10761 of LITTLENUMS emitted is stored in *SIZE. An error message is
10762 returned, or NULL on OK. */
10764 #define MAX_LITTLENUMS 5
10767 md_atof (type, lit, size)
10772 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10802 return "Bad call to MD_ATOF()";
10804 t = atof_ieee (input_line_pointer, type, words);
10806 input_line_pointer = t;
10808 (*ia64_float_to_chars) (lit, words, prec);
10812 /* It is 10 byte floating point with 6 byte padding. */
10813 memset (&lit [10], 0, 6);
10814 *size = 8 * sizeof (LITTLENUM_TYPE);
10817 *size = prec * sizeof (LITTLENUM_TYPE);
10822 /* Handle ia64 specific semantics of the align directive. */
10825 ia64_md_do_align (n, fill, len, max)
10826 int n ATTRIBUTE_UNUSED;
10827 const char *fill ATTRIBUTE_UNUSED;
10828 int len ATTRIBUTE_UNUSED;
10829 int max ATTRIBUTE_UNUSED;
10831 /* The current frag is an alignment frag. */
10832 align_frag = frag_now;
10833 if (subseg_text_p (now_seg))
10834 ia64_flush_insns ();
10837 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10838 of an rs_align_code fragment. */
10841 ia64_handle_align (fragp)
10844 /* Use mfi bundle of nops with no stop bits. */
10845 static const unsigned char le_nop[]
10846 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10847 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10848 static const unsigned char le_nop_stop[]
10849 = { 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10850 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10854 const unsigned char *nop;
10856 if (fragp->fr_type != rs_align_code)
10859 /* Check if this frag has to end with a stop bit. */
10860 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
10862 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10863 p = fragp->fr_literal + fragp->fr_fix;
10865 /* Make sure we are on a 16-byte boundary, in case someone has been
10866 putting data into a text section. */
10869 int fix = bytes & 15;
10870 memset (p, 0, fix);
10873 fragp->fr_fix += fix;
10876 /* Instruction bundles are always little-endian. */
10877 memcpy (p, nop, 16);
10878 fragp->fr_var = 16;
10882 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
10887 number_to_chars_bigendian (lit, (long) (*words++),
10888 sizeof (LITTLENUM_TYPE));
10889 lit += sizeof (LITTLENUM_TYPE);
10894 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
10899 number_to_chars_littleendian (lit, (long) (words[prec]),
10900 sizeof (LITTLENUM_TYPE));
10901 lit += sizeof (LITTLENUM_TYPE);
10906 ia64_elf_section_change_hook (void)
10908 dot_byteorder (-1);
10911 /* Check if a label should be made global. */
10913 ia64_check_label (symbolS *label)
10915 if (*input_line_pointer == ':')
10917 S_SET_EXTERNAL (label);
10918 input_line_pointer++;
10922 /* Used to remember where .alias and .secalias directives are seen. We
10923 will rename symbol and section names when we are about to output
10924 the relocatable file. */
10927 char *file; /* The file where the directive is seen. */
10928 unsigned int line; /* The line number the directive is at. */
10929 const char *name; /* The orignale name of the symbol. */
10932 /* Called for .alias and .secalias directives. If SECTION is 1, it is
10933 .secalias. Otherwise, it is .alias. */
10935 dot_alias (int section)
10937 char *name, *alias;
10941 const char *error_string;
10944 struct hash_control *ahash, *nhash;
10947 name = input_line_pointer;
10948 delim = get_symbol_end ();
10949 end_name = input_line_pointer;
10952 if (name == end_name)
10954 as_bad (_("expected symbol name"));
10955 discard_rest_of_line ();
10959 SKIP_WHITESPACE ();
10961 if (*input_line_pointer != ',')
10964 as_bad (_("expected comma after \"%s\""), name);
10966 ignore_rest_of_line ();
10970 input_line_pointer++;
10973 /* We call demand_copy_C_string to check if alias string is valid.
10974 There should be a closing `"' and no `\0' in the string. */
10975 alias = demand_copy_C_string (&len);
10978 ignore_rest_of_line ();
10982 /* Make a copy of name string. */
10983 len = strlen (name) + 1;
10984 obstack_grow (¬es, name, len);
10985 name = obstack_finish (¬es);
10990 ahash = secalias_hash;
10991 nhash = secalias_name_hash;
10996 ahash = alias_hash;
10997 nhash = alias_name_hash;
11000 /* Check if alias has been used before. */
11001 h = (struct alias *) hash_find (ahash, alias);
11004 if (strcmp (h->name, name))
11005 as_bad (_("`%s' is already the alias of %s `%s'"),
11006 alias, kind, h->name);
11010 /* Check if name already has an alias. */
11011 a = (const char *) hash_find (nhash, name);
11014 if (strcmp (a, alias))
11015 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11019 h = (struct alias *) xmalloc (sizeof (struct alias));
11020 as_where (&h->file, &h->line);
11023 error_string = hash_jam (ahash, alias, (PTR) h);
11026 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11027 alias, kind, error_string);
11031 error_string = hash_jam (nhash, name, (PTR) alias);
11034 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11035 alias, kind, error_string);
11037 obstack_free (¬es, name);
11038 obstack_free (¬es, alias);
11041 demand_empty_rest_of_line ();
11044 /* It renames the original symbol name to its alias. */
11046 do_alias (const char *alias, PTR value)
11048 struct alias *h = (struct alias *) value;
11049 symbolS *sym = symbol_find (h->name);
11052 as_warn_where (h->file, h->line,
11053 _("symbol `%s' aliased to `%s' is not used"),
11056 S_SET_NAME (sym, (char *) alias);
11059 /* Called from write_object_file. */
11061 ia64_adjust_symtab (void)
11063 hash_traverse (alias_hash, do_alias);
11066 /* It renames the original section name to its alias. */
11068 do_secalias (const char *alias, PTR value)
11070 struct alias *h = (struct alias *) value;
11071 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11074 as_warn_where (h->file, h->line,
11075 _("section `%s' aliased to `%s' is not used"),
11081 /* Called from write_object_file. */
11083 ia64_frob_file (void)
11085 hash_traverse (secalias_hash, do_secalias);