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. */
35 - labels are wrong if automatic alignment is introduced
36 (e.g., checkout the second real10 definition in test-data.s)
38 <reg>.safe_across_calls and any other DV-related directives I don't
39 have documentation for.
40 verify mod-sched-brs reads/writes are checked/marked (and other
46 #include "safe-ctype.h"
47 #include "dwarf2dbg.h"
50 #include "opcode/ia64.h"
54 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
55 #define MIN(a,b) ((a) < (b) ? (a) : (b))
58 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
59 #define CURR_SLOT md.slot[md.curr_slot]
61 #define O_pseudo_fixup (O_max + 1)
65 /* IA-64 ABI section pseudo-ops. */
66 SPECIAL_SECTION_BSS = 0,
68 SPECIAL_SECTION_SDATA,
69 SPECIAL_SECTION_RODATA,
70 SPECIAL_SECTION_COMMENT,
71 SPECIAL_SECTION_UNWIND,
72 SPECIAL_SECTION_UNWIND_INFO,
73 /* HPUX specific section pseudo-ops. */
74 SPECIAL_SECTION_INIT_ARRAY,
75 SPECIAL_SECTION_FINI_ARRAY,
92 FUNC_LT_FPTR_RELATIVE,
102 REG_FR = (REG_GR + 128),
103 REG_AR = (REG_FR + 128),
104 REG_CR = (REG_AR + 128),
105 REG_P = (REG_CR + 128),
106 REG_BR = (REG_P + 64),
107 REG_IP = (REG_BR + 8),
114 /* The following are pseudo-registers for use by gas only. */
126 /* The following pseudo-registers are used for unwind directives only: */
134 DYNREG_GR = 0, /* dynamic general purpose register */
135 DYNREG_FR, /* dynamic floating point register */
136 DYNREG_PR, /* dynamic predicate register */
140 enum operand_match_result
143 OPERAND_OUT_OF_RANGE,
147 /* On the ia64, we can't know the address of a text label until the
148 instructions are packed into a bundle. To handle this, we keep
149 track of the list of labels that appear in front of each
153 struct label_fix *next;
157 extern int target_big_endian;
159 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
161 static void ia64_float_to_chars_bigendian
162 PARAMS ((char *, LITTLENUM_TYPE *, int));
163 static void ia64_float_to_chars_littleendian
164 PARAMS ((char *, LITTLENUM_TYPE *, int));
165 static void (*ia64_float_to_chars)
166 PARAMS ((char *, LITTLENUM_TYPE *, int));
168 /* Characters which always start a comment. */
169 const char comment_chars[] = "";
171 /* Characters which start a comment at the beginning of a line. */
172 const char line_comment_chars[] = "#";
174 /* Characters which may be used to separate multiple commands on a
176 const char line_separator_chars[] = ";";
178 /* Characters which are used to indicate an exponent in a floating
180 const char EXP_CHARS[] = "eE";
182 /* Characters which mean that a number is a floating point constant,
184 const char FLT_CHARS[] = "rRsSfFdDxXpP";
186 /* ia64-specific option processing: */
188 const char *md_shortopts = "m:N:x::";
190 struct option md_longopts[] =
192 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
193 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
194 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
195 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
198 size_t md_longopts_size = sizeof (md_longopts);
202 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
203 struct hash_control *reg_hash; /* register name hash table */
204 struct hash_control *dynreg_hash; /* dynamic register hash table */
205 struct hash_control *const_hash; /* constant hash table */
206 struct hash_control *entry_hash; /* code entry hint hash table */
208 symbolS *regsym[REG_NUM];
210 /* If X_op is != O_absent, the registername for the instruction's
211 qualifying predicate. If NULL, p0 is assumed for instructions
212 that are predicatable. */
219 explicit_mode : 1, /* which mode we're in */
220 default_explicit_mode : 1, /* which mode is the default */
221 mode_explicitly_set : 1, /* was the current mode explicitly set? */
223 keep_pending_output : 1;
225 /* Each bundle consists of up to three instructions. We keep
226 track of four most recent instructions so we can correctly set
227 the end_of_insn_group for the last instruction in a bundle. */
229 int num_slots_in_use;
233 end_of_insn_group : 1,
234 manual_bundling_on : 1,
235 manual_bundling_off : 1;
236 signed char user_template; /* user-selected template, if any */
237 unsigned char qp_regno; /* qualifying predicate */
238 /* This duplicates a good fraction of "struct fix" but we
239 can't use a "struct fix" instead since we can't call
240 fix_new_exp() until we know the address of the instruction. */
244 bfd_reloc_code_real_type code;
245 enum ia64_opnd opnd; /* type of operand in need of fix */
246 unsigned int is_pcrel : 1; /* is operand pc-relative? */
247 expressionS expr; /* the value to be inserted */
249 fixup[2]; /* at most two fixups per insn */
250 struct ia64_opcode *idesc;
251 struct label_fix *label_fixups;
252 struct label_fix *tag_fixups;
253 struct unw_rec_list *unwind_record; /* Unwind directive. */
256 unsigned int src_line;
257 struct dwarf2_line_info debug_line;
265 struct dynreg *next; /* next dynamic register */
267 unsigned short base; /* the base register number */
268 unsigned short num_regs; /* # of registers in this set */
270 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
272 flagword flags; /* ELF-header flags */
275 unsigned hint:1; /* is this hint currently valid? */
276 bfd_vma offset; /* mem.offset offset */
277 bfd_vma base; /* mem.offset base */
280 int path; /* number of alt. entry points seen */
281 const char **entry_labels; /* labels of all alternate paths in
282 the current DV-checking block. */
283 int maxpaths; /* size currently allocated for
285 /* Support for hardware errata workarounds. */
287 /* Record data about the last three insn groups. */
290 /* B-step workaround.
291 For each predicate register, this is set if the corresponding insn
292 group conditionally sets this register with one of the affected
295 /* B-step workaround.
296 For each general register, this is set if the corresponding insn
297 a) is conditional one one of the predicate registers for which
298 P_REG_SET is 1 in the corresponding entry of the previous group,
299 b) sets this general register with one of the affected
301 int g_reg_set_conditionally[128];
305 int pointer_size; /* size in bytes of a pointer */
306 int pointer_size_shift; /* shift size of a pointer for alignment */
310 /* application registers: */
316 #define AR_BSPSTORE 18
331 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
332 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
333 {"ar.rsc", 16}, {"ar.bsp", 17},
334 {"ar.bspstore", 18}, {"ar.rnat", 19},
335 {"ar.fcr", 21}, {"ar.eflag", 24},
336 {"ar.csd", 25}, {"ar.ssd", 26},
337 {"ar.cflg", 27}, {"ar.fsr", 28},
338 {"ar.fir", 29}, {"ar.fdr", 30},
339 {"ar.ccv", 32}, {"ar.unat", 36},
340 {"ar.fpsr", 40}, {"ar.itc", 44},
341 {"ar.pfs", 64}, {"ar.lc", 65},
362 /* control registers: */
404 static const struct const_desc
411 /* PSR constant masks: */
414 {"psr.be", ((valueT) 1) << 1},
415 {"psr.up", ((valueT) 1) << 2},
416 {"psr.ac", ((valueT) 1) << 3},
417 {"psr.mfl", ((valueT) 1) << 4},
418 {"psr.mfh", ((valueT) 1) << 5},
420 {"psr.ic", ((valueT) 1) << 13},
421 {"psr.i", ((valueT) 1) << 14},
422 {"psr.pk", ((valueT) 1) << 15},
424 {"psr.dt", ((valueT) 1) << 17},
425 {"psr.dfl", ((valueT) 1) << 18},
426 {"psr.dfh", ((valueT) 1) << 19},
427 {"psr.sp", ((valueT) 1) << 20},
428 {"psr.pp", ((valueT) 1) << 21},
429 {"psr.di", ((valueT) 1) << 22},
430 {"psr.si", ((valueT) 1) << 23},
431 {"psr.db", ((valueT) 1) << 24},
432 {"psr.lp", ((valueT) 1) << 25},
433 {"psr.tb", ((valueT) 1) << 26},
434 {"psr.rt", ((valueT) 1) << 27},
435 /* 28-31: reserved */
436 /* 32-33: cpl (current privilege level) */
437 {"psr.is", ((valueT) 1) << 34},
438 {"psr.mc", ((valueT) 1) << 35},
439 {"psr.it", ((valueT) 1) << 36},
440 {"psr.id", ((valueT) 1) << 37},
441 {"psr.da", ((valueT) 1) << 38},
442 {"psr.dd", ((valueT) 1) << 39},
443 {"psr.ss", ((valueT) 1) << 40},
444 /* 41-42: ri (restart instruction) */
445 {"psr.ed", ((valueT) 1) << 43},
446 {"psr.bn", ((valueT) 1) << 44},
449 /* indirect register-sets/memory: */
458 { "CPUID", IND_CPUID },
459 { "cpuid", IND_CPUID },
471 /* Pseudo functions used to indicate relocation types (these functions
472 start with an at sign (@). */
494 /* reloc pseudo functions (these must come first!): */
495 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
496 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
497 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
498 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
499 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
500 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
501 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
502 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
503 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
504 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
505 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
506 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
507 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
508 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
509 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
510 { "", 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
511 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
513 /* mbtype4 constants: */
514 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
515 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
516 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
517 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
518 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
520 /* fclass constants: */
521 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
522 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
523 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
524 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
525 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
526 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
527 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
528 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
529 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
531 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
533 /* hint constants: */
534 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
536 /* unwind-related constants: */
537 { "svr4", PSEUDO_FUNC_CONST, { 0 } },
538 { "hpux", PSEUDO_FUNC_CONST, { 1 } },
539 { "nt", PSEUDO_FUNC_CONST, { 2 } },
541 /* unwind-related registers: */
542 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
545 /* 41-bit nop opcodes (one per unit): */
546 static const bfd_vma nop[IA64_NUM_UNITS] =
548 0x0000000000LL, /* NIL => break 0 */
549 0x0008000000LL, /* I-unit nop */
550 0x0008000000LL, /* M-unit nop */
551 0x4000000000LL, /* B-unit nop */
552 0x0008000000LL, /* F-unit nop */
553 0x0008000000LL, /* L-"unit" nop */
554 0x0008000000LL, /* X-unit nop */
557 /* Can't be `const' as it's passed to input routines (which have the
558 habit of setting temporary sentinels. */
559 static char special_section_name[][20] =
561 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
562 {".IA_64.unwind"}, {".IA_64.unwind_info"},
563 {".init_array"}, {".fini_array"}
566 static char *special_linkonce_name[] =
568 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
571 /* The best template for a particular sequence of up to three
573 #define N IA64_NUM_TYPES
574 static unsigned char best_template[N][N][N];
577 /* Resource dependencies currently in effect */
579 int depind; /* dependency index */
580 const struct ia64_dependency *dependency; /* actual dependency */
581 unsigned specific:1, /* is this a specific bit/regno? */
582 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
583 int index; /* specific regno/bit within dependency */
584 int note; /* optional qualifying note (0 if none) */
588 int insn_srlz; /* current insn serialization state */
589 int data_srlz; /* current data serialization state */
590 int qp_regno; /* qualifying predicate for this usage */
591 char *file; /* what file marked this dependency */
592 unsigned int line; /* what line marked this dependency */
593 struct mem_offset mem_offset; /* optional memory offset hint */
594 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
595 int path; /* corresponding code entry index */
597 static int regdepslen = 0;
598 static int regdepstotlen = 0;
599 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
600 static const char *dv_sem[] = { "none", "implied", "impliedf",
601 "data", "instr", "specific", "stop", "other" };
602 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
604 /* Current state of PR mutexation */
605 static struct qpmutex {
608 } *qp_mutexes = NULL; /* QP mutex bitmasks */
609 static int qp_mutexeslen = 0;
610 static int qp_mutexestotlen = 0;
611 static valueT qp_safe_across_calls = 0;
613 /* Current state of PR implications */
614 static struct qp_imply {
617 unsigned p2_branched:1;
619 } *qp_implies = NULL;
620 static int qp_implieslen = 0;
621 static int qp_impliestotlen = 0;
623 /* Keep track of static GR values so that indirect register usage can
624 sometimes be tracked. */
629 } gr_values[128] = {{ 1, 0, 0 }};
631 /* These are the routines required to output the various types of
634 /* A slot_number is a frag address plus the slot index (0-2). We use the
635 frag address here so that if there is a section switch in the middle of
636 a function, then instructions emitted to a different section are not
637 counted. Since there may be more than one frag for a function, this
638 means we also need to keep track of which frag this address belongs to
639 so we can compute inter-frag distances. This also nicely solves the
640 problem with nops emitted for align directives, which can't easily be
641 counted, but can easily be derived from frag sizes. */
643 typedef struct unw_rec_list {
645 unsigned long slot_number;
647 struct unw_rec_list *next;
650 #define SLOT_NUM_NOT_SET (unsigned)-1
652 /* Linked list of saved prologue counts. A very poor
653 implementation of a map from label numbers to prologue counts. */
654 typedef struct label_prologue_count
656 struct label_prologue_count *next;
657 unsigned long label_number;
658 unsigned int prologue_count;
659 } label_prologue_count;
663 unsigned long next_slot_number;
664 fragS *next_slot_frag;
666 /* Maintain a list of unwind entries for the current function. */
670 /* Any unwind entires that should be attached to the current slot
671 that an insn is being constructed for. */
672 unw_rec_list *current_entry;
674 /* These are used to create the unwind table entry for this function. */
677 symbolS *info; /* pointer to unwind info */
678 symbolS *personality_routine;
680 subsegT saved_text_subseg;
681 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
683 /* TRUE if processing unwind directives in a prologue region. */
686 unsigned int prologue_count; /* number of .prologues seen so far */
687 /* Prologue counts at previous .label_state directives. */
688 struct label_prologue_count * saved_prologue_counts;
691 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
693 /* Forward delarations: */
694 static int ar_is_in_integer_unit PARAMS ((int regnum));
695 static void set_section PARAMS ((char *name));
696 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
697 unsigned int, unsigned int));
698 static void dot_radix PARAMS ((int));
699 static void dot_special_section PARAMS ((int));
700 static void dot_proc PARAMS ((int));
701 static void dot_fframe PARAMS ((int));
702 static void dot_vframe PARAMS ((int));
703 static void dot_vframesp PARAMS ((int));
704 static void dot_vframepsp PARAMS ((int));
705 static void dot_save PARAMS ((int));
706 static void dot_restore PARAMS ((int));
707 static void dot_restorereg PARAMS ((int));
708 static void dot_restorereg_p PARAMS ((int));
709 static void dot_handlerdata PARAMS ((int));
710 static void dot_unwentry PARAMS ((int));
711 static void dot_altrp PARAMS ((int));
712 static void dot_savemem PARAMS ((int));
713 static void dot_saveg PARAMS ((int));
714 static void dot_savef PARAMS ((int));
715 static void dot_saveb PARAMS ((int));
716 static void dot_savegf PARAMS ((int));
717 static void dot_spill PARAMS ((int));
718 static void dot_spillreg PARAMS ((int));
719 static void dot_spillmem PARAMS ((int));
720 static void dot_spillreg_p PARAMS ((int));
721 static void dot_spillmem_p PARAMS ((int));
722 static void dot_label_state PARAMS ((int));
723 static void dot_copy_state PARAMS ((int));
724 static void dot_unwabi PARAMS ((int));
725 static void dot_personality PARAMS ((int));
726 static void dot_body PARAMS ((int));
727 static void dot_prologue PARAMS ((int));
728 static void dot_endp PARAMS ((int));
729 static void dot_template PARAMS ((int));
730 static void dot_regstk PARAMS ((int));
731 static void dot_rot PARAMS ((int));
732 static void dot_byteorder PARAMS ((int));
733 static void dot_psr PARAMS ((int));
734 static void dot_alias PARAMS ((int));
735 static void dot_ln PARAMS ((int));
736 static char *parse_section_name PARAMS ((void));
737 static void dot_xdata PARAMS ((int));
738 static void stmt_float_cons PARAMS ((int));
739 static void stmt_cons_ua PARAMS ((int));
740 static void dot_xfloat_cons PARAMS ((int));
741 static void dot_xstringer PARAMS ((int));
742 static void dot_xdata_ua PARAMS ((int));
743 static void dot_xfloat_cons_ua PARAMS ((int));
744 static void print_prmask PARAMS ((valueT mask));
745 static void dot_pred_rel PARAMS ((int));
746 static void dot_reg_val PARAMS ((int));
747 static void dot_dv_mode PARAMS ((int));
748 static void dot_entry PARAMS ((int));
749 static void dot_mem_offset PARAMS ((int));
750 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
751 static symbolS *declare_register PARAMS ((const char *name, int regnum));
752 static void declare_register_set PARAMS ((const char *, int, int));
753 static unsigned int operand_width PARAMS ((enum ia64_opnd));
754 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
757 static int parse_operand PARAMS ((expressionS *e));
758 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
759 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
760 static void build_insn PARAMS ((struct slot *, bfd_vma *));
761 static void emit_one_bundle PARAMS ((void));
762 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
763 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
764 bfd_reloc_code_real_type r_type));
765 static void insn_group_break PARAMS ((int, int, int));
766 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
767 struct rsrc *, int depind, int path));
768 static void add_qp_mutex PARAMS((valueT mask));
769 static void add_qp_imply PARAMS((int p1, int p2));
770 static void clear_qp_branch_flag PARAMS((valueT mask));
771 static void clear_qp_mutex PARAMS((valueT mask));
772 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
773 static int has_suffix_p PARAMS((const char *, const char *));
774 static void clear_register_values PARAMS ((void));
775 static void print_dependency PARAMS ((const char *action, int depind));
776 static void instruction_serialization PARAMS ((void));
777 static void data_serialization PARAMS ((void));
778 static void remove_marked_resource PARAMS ((struct rsrc *));
779 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
780 static int is_taken_branch PARAMS ((struct ia64_opcode *));
781 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
782 static int depends_on PARAMS ((int, struct ia64_opcode *));
783 static int specify_resource PARAMS ((const struct ia64_dependency *,
784 struct ia64_opcode *, int, struct rsrc [], int, int));
785 static int check_dv PARAMS((struct ia64_opcode *idesc));
786 static void check_dependencies PARAMS((struct ia64_opcode *));
787 static void mark_resources PARAMS((struct ia64_opcode *));
788 static void update_dependencies PARAMS((struct ia64_opcode *));
789 static void note_register_values PARAMS((struct ia64_opcode *));
790 static int qp_mutex PARAMS ((int, int, int));
791 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
792 static void output_vbyte_mem PARAMS ((int, char *, char *));
793 static void count_output PARAMS ((int, char *, char *));
794 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
795 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
796 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
797 static void output_P1_format PARAMS ((vbyte_func, int));
798 static void output_P2_format PARAMS ((vbyte_func, int, int));
799 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
800 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
801 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
802 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
803 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
804 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
805 static void output_P9_format PARAMS ((vbyte_func, int, int));
806 static void output_P10_format PARAMS ((vbyte_func, int, int));
807 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
808 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
809 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
810 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
811 static char format_ab_reg PARAMS ((int, int));
812 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
814 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
815 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
817 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
818 static void free_list_records PARAMS ((unw_rec_list *));
819 static unw_rec_list *output_prologue PARAMS ((void));
820 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
821 static unw_rec_list *output_body PARAMS ((void));
822 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
823 static unw_rec_list *output_mem_stack_v PARAMS ((void));
824 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
825 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
826 static unw_rec_list *output_rp_when PARAMS ((void));
827 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
828 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
829 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
830 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
831 static unw_rec_list *output_pfs_when PARAMS ((void));
832 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
833 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
834 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
835 static unw_rec_list *output_preds_when PARAMS ((void));
836 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
837 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
838 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
839 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
840 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
841 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
842 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
843 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
844 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
845 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
846 static unw_rec_list *output_unat_when PARAMS ((void));
847 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
848 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
849 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
850 static unw_rec_list *output_lc_when PARAMS ((void));
851 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
852 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
853 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
854 static unw_rec_list *output_fpsr_when PARAMS ((void));
855 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
856 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
857 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
858 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
859 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
860 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
861 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
862 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
863 static unw_rec_list *output_bsp_when PARAMS ((void));
864 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
865 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
866 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
867 static unw_rec_list *output_bspstore_when PARAMS ((void));
868 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
869 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
870 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
871 static unw_rec_list *output_rnat_when PARAMS ((void));
872 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
873 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
874 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
875 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
876 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
877 static unw_rec_list *output_label_state PARAMS ((unsigned long));
878 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
879 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
880 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
881 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
883 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
885 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
887 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
888 unsigned int, unsigned int));
889 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
890 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
891 static int calc_record_size PARAMS ((unw_rec_list *));
892 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
893 static int count_bits PARAMS ((unsigned long));
894 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
895 unsigned long, fragS *));
896 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
897 static void fixup_unw_records PARAMS ((unw_rec_list *));
898 static int output_unw_records PARAMS ((unw_rec_list *, void **));
899 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
900 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
901 static int generate_unwind_image PARAMS ((const char *));
902 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
903 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
904 static void free_saved_prologue_counts PARAMS ((void));
906 /* Build the unwind section name by appending the (possibly stripped)
907 text section NAME to the unwind PREFIX. The resulting string
908 pointer is assigned to RESULT. The string is allocated on the
909 stack, so this must be a macro... */
910 #define make_unw_section_name(special, text_name, result) \
912 const char *_prefix = special_section_name[special]; \
913 const char *_suffix = text_name; \
914 size_t _prefix_len, _suffix_len; \
916 if (strncmp (text_name, ".gnu.linkonce.t.", \
917 sizeof (".gnu.linkonce.t.") - 1) == 0) \
919 _prefix = special_linkonce_name[special - SPECIAL_SECTION_UNWIND]; \
920 _suffix += sizeof (".gnu.linkonce.t.") - 1; \
922 _prefix_len = strlen (_prefix), _suffix_len = strlen (_suffix); \
923 _result = alloca (_prefix_len + _suffix_len + 1); \
924 memcpy (_result, _prefix, _prefix_len); \
925 memcpy (_result + _prefix_len, _suffix, _suffix_len); \
926 _result[_prefix_len + _suffix_len] = '\0'; \
931 /* Determine if application register REGNUM resides in the integer
932 unit (as opposed to the memory unit). */
934 ar_is_in_integer_unit (reg)
939 return (reg == 64 /* pfs */
940 || reg == 65 /* lc */
941 || reg == 66 /* ec */
942 /* ??? ias accepts and puts these in the integer unit. */
943 || (reg >= 112 && reg <= 127));
946 /* Switch to section NAME and create section if necessary. It's
947 rather ugly that we have to manipulate input_line_pointer but I
948 don't see any other way to accomplish the same thing without
949 changing obj-elf.c (which may be the Right Thing, in the end). */
954 char *saved_input_line_pointer;
956 saved_input_line_pointer = input_line_pointer;
957 input_line_pointer = name;
959 input_line_pointer = saved_input_line_pointer;
962 /* Map 's' to SHF_IA_64_SHORT. */
965 ia64_elf_section_letter (letter, ptr_msg)
970 return SHF_IA_64_SHORT;
972 *ptr_msg = _("Bad .section directive: want a,s,w,x,M,S,G,T in string");
976 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
979 ia64_elf_section_flags (flags, attr, type)
981 int attr, type ATTRIBUTE_UNUSED;
983 if (attr & SHF_IA_64_SHORT)
984 flags |= SEC_SMALL_DATA;
989 ia64_elf_section_type (str, len)
993 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
995 if (STREQ (ELF_STRING_ia64_unwind_info))
998 if (STREQ (ELF_STRING_ia64_unwind_info_once))
1001 if (STREQ (ELF_STRING_ia64_unwind))
1002 return SHT_IA_64_UNWIND;
1004 if (STREQ (ELF_STRING_ia64_unwind_once))
1005 return SHT_IA_64_UNWIND;
1007 if (STREQ ("init_array"))
1008 return SHT_INIT_ARRAY;
1010 if (STREQ ("fini_array"))
1011 return SHT_FINI_ARRAY;
1018 set_regstack (ins, locs, outs, rots)
1019 unsigned int ins, locs, outs, rots;
1021 /* Size of frame. */
1024 sof = ins + locs + outs;
1027 as_bad ("Size of frame exceeds maximum of 96 registers");
1032 as_warn ("Size of rotating registers exceeds frame size");
1035 md.in.base = REG_GR + 32;
1036 md.loc.base = md.in.base + ins;
1037 md.out.base = md.loc.base + locs;
1039 md.in.num_regs = ins;
1040 md.loc.num_regs = locs;
1041 md.out.num_regs = outs;
1042 md.rot.num_regs = rots;
1049 struct label_fix *lfix;
1051 subsegT saved_subseg;
1054 if (!md.last_text_seg)
1057 saved_seg = now_seg;
1058 saved_subseg = now_subseg;
1060 subseg_set (md.last_text_seg, 0);
1062 while (md.num_slots_in_use > 0)
1063 emit_one_bundle (); /* force out queued instructions */
1065 /* In case there are labels following the last instruction, resolve
1067 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1069 S_SET_VALUE (lfix->sym, frag_now_fix ());
1070 symbol_set_frag (lfix->sym, frag_now);
1072 CURR_SLOT.label_fixups = 0;
1073 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1075 S_SET_VALUE (lfix->sym, frag_now_fix ());
1076 symbol_set_frag (lfix->sym, frag_now);
1078 CURR_SLOT.tag_fixups = 0;
1080 /* In case there are unwind directives following the last instruction,
1081 resolve those now. We only handle body and prologue directives here.
1082 Give an error for others. */
1083 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1085 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
1086 || ptr->r.type == body)
1088 ptr->slot_number = (unsigned long) frag_more (0);
1089 ptr->slot_frag = frag_now;
1092 as_bad (_("Unwind directive not followed by an instruction."));
1094 unwind.current_entry = NULL;
1096 subseg_set (saved_seg, saved_subseg);
1098 if (md.qp.X_op == O_register)
1099 as_bad ("qualifying predicate not followed by instruction");
1103 ia64_do_align (nbytes)
1106 char *saved_input_line_pointer = input_line_pointer;
1108 input_line_pointer = "";
1109 s_align_bytes (nbytes);
1110 input_line_pointer = saved_input_line_pointer;
1114 ia64_cons_align (nbytes)
1119 char *saved_input_line_pointer = input_line_pointer;
1120 input_line_pointer = "";
1121 s_align_bytes (nbytes);
1122 input_line_pointer = saved_input_line_pointer;
1126 /* Output COUNT bytes to a memory location. */
1127 static unsigned char *vbyte_mem_ptr = NULL;
1130 output_vbyte_mem (count, ptr, comment)
1133 char *comment ATTRIBUTE_UNUSED;
1136 if (vbyte_mem_ptr == NULL)
1141 for (x = 0; x < count; x++)
1142 *(vbyte_mem_ptr++) = ptr[x];
1145 /* Count the number of bytes required for records. */
1146 static int vbyte_count = 0;
1148 count_output (count, ptr, comment)
1150 char *ptr ATTRIBUTE_UNUSED;
1151 char *comment ATTRIBUTE_UNUSED;
1153 vbyte_count += count;
1157 output_R1_format (f, rtype, rlen)
1159 unw_record_type rtype;
1166 output_R3_format (f, rtype, rlen);
1172 else if (rtype != prologue)
1173 as_bad ("record type is not valid");
1175 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1176 (*f) (1, &byte, NULL);
1180 output_R2_format (f, mask, grsave, rlen)
1187 mask = (mask & 0x0f);
1188 grsave = (grsave & 0x7f);
1190 bytes[0] = (UNW_R2 | (mask >> 1));
1191 bytes[1] = (((mask & 0x01) << 7) | grsave);
1192 count += output_leb128 (bytes + 2, rlen, 0);
1193 (*f) (count, bytes, NULL);
1197 output_R3_format (f, rtype, rlen)
1199 unw_record_type rtype;
1206 output_R1_format (f, rtype, rlen);
1212 else if (rtype != prologue)
1213 as_bad ("record type is not valid");
1214 bytes[0] = (UNW_R3 | r);
1215 count = output_leb128 (bytes + 1, rlen, 0);
1216 (*f) (count + 1, bytes, NULL);
1220 output_P1_format (f, brmask)
1225 byte = UNW_P1 | (brmask & 0x1f);
1226 (*f) (1, &byte, NULL);
1230 output_P2_format (f, brmask, gr)
1236 brmask = (brmask & 0x1f);
1237 bytes[0] = UNW_P2 | (brmask >> 1);
1238 bytes[1] = (((brmask & 1) << 7) | gr);
1239 (*f) (2, bytes, NULL);
1243 output_P3_format (f, rtype, reg)
1245 unw_record_type rtype;
1290 as_bad ("Invalid record type for P3 format.");
1292 bytes[0] = (UNW_P3 | (r >> 1));
1293 bytes[1] = (((r & 1) << 7) | reg);
1294 (*f) (2, bytes, NULL);
1298 output_P4_format (f, imask, imask_size)
1300 unsigned char *imask;
1301 unsigned long imask_size;
1304 (*f) (imask_size, imask, NULL);
1308 output_P5_format (f, grmask, frmask)
1311 unsigned long frmask;
1314 grmask = (grmask & 0x0f);
1317 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1318 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1319 bytes[3] = (frmask & 0x000000ff);
1320 (*f) (4, bytes, NULL);
1324 output_P6_format (f, rtype, rmask)
1326 unw_record_type rtype;
1332 if (rtype == gr_mem)
1334 else if (rtype != fr_mem)
1335 as_bad ("Invalid record type for format P6");
1336 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1337 (*f) (1, &byte, NULL);
1341 output_P7_format (f, rtype, w1, w2)
1343 unw_record_type rtype;
1350 count += output_leb128 (bytes + 1, w1, 0);
1355 count += output_leb128 (bytes + count, w2 >> 4, 0);
1405 bytes[0] = (UNW_P7 | r);
1406 (*f) (count, bytes, NULL);
1410 output_P8_format (f, rtype, t)
1412 unw_record_type rtype;
1451 case bspstore_psprel:
1454 case bspstore_sprel:
1466 case priunat_when_gr:
1469 case priunat_psprel:
1475 case priunat_when_mem:
1482 count += output_leb128 (bytes + 2, t, 0);
1483 (*f) (count, bytes, NULL);
1487 output_P9_format (f, grmask, gr)
1494 bytes[1] = (grmask & 0x0f);
1495 bytes[2] = (gr & 0x7f);
1496 (*f) (3, bytes, NULL);
1500 output_P10_format (f, abi, context)
1507 bytes[1] = (abi & 0xff);
1508 bytes[2] = (context & 0xff);
1509 (*f) (3, bytes, NULL);
1513 output_B1_format (f, rtype, label)
1515 unw_record_type rtype;
1516 unsigned long label;
1522 output_B4_format (f, rtype, label);
1525 if (rtype == copy_state)
1527 else if (rtype != label_state)
1528 as_bad ("Invalid record type for format B1");
1530 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1531 (*f) (1, &byte, NULL);
1535 output_B2_format (f, ecount, t)
1537 unsigned long ecount;
1544 output_B3_format (f, ecount, t);
1547 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1548 count += output_leb128 (bytes + 1, t, 0);
1549 (*f) (count, bytes, NULL);
1553 output_B3_format (f, ecount, t)
1555 unsigned long ecount;
1562 output_B2_format (f, ecount, t);
1566 count += output_leb128 (bytes + 1, t, 0);
1567 count += output_leb128 (bytes + count, ecount, 0);
1568 (*f) (count, bytes, NULL);
1572 output_B4_format (f, rtype, label)
1574 unw_record_type rtype;
1575 unsigned long label;
1582 output_B1_format (f, rtype, label);
1586 if (rtype == copy_state)
1588 else if (rtype != label_state)
1589 as_bad ("Invalid record type for format B1");
1591 bytes[0] = (UNW_B4 | (r << 3));
1592 count += output_leb128 (bytes + 1, label, 0);
1593 (*f) (count, bytes, NULL);
1597 format_ab_reg (ab, reg)
1604 ret = (ab << 5) | reg;
1609 output_X1_format (f, rtype, ab, reg, t, w1)
1611 unw_record_type rtype;
1621 if (rtype == spill_sprel)
1623 else if (rtype != spill_psprel)
1624 as_bad ("Invalid record type for format X1");
1625 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1626 count += output_leb128 (bytes + 2, t, 0);
1627 count += output_leb128 (bytes + count, w1, 0);
1628 (*f) (count, bytes, NULL);
1632 output_X2_format (f, ab, reg, x, y, treg, t)
1641 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1642 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1643 count += output_leb128 (bytes + 3, t, 0);
1644 (*f) (count, bytes, NULL);
1648 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1650 unw_record_type rtype;
1661 if (rtype == spill_sprel_p)
1663 else if (rtype != spill_psprel_p)
1664 as_bad ("Invalid record type for format X3");
1665 bytes[1] = ((r << 7) | (qp & 0x3f));
1666 bytes[2] = format_ab_reg (ab, reg);
1667 count += output_leb128 (bytes + 3, t, 0);
1668 count += output_leb128 (bytes + count, w1, 0);
1669 (*f) (count, bytes, NULL);
1673 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1683 bytes[1] = (qp & 0x3f);
1684 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1685 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1686 count += output_leb128 (bytes + 4, t, 0);
1687 (*f) (count, bytes, NULL);
1690 /* This function allocates a record list structure, and initializes fields. */
1692 static unw_rec_list *
1693 alloc_record (unw_record_type t)
1696 ptr = xmalloc (sizeof (*ptr));
1698 ptr->slot_number = SLOT_NUM_NOT_SET;
1703 /* This function frees an entire list of record structures. */
1706 free_list_records (unw_rec_list *first)
1709 for (ptr = first; ptr != NULL;)
1711 unw_rec_list *tmp = ptr;
1713 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1714 && tmp->r.record.r.mask.i)
1715 free (tmp->r.record.r.mask.i);
1722 static unw_rec_list *
1725 unw_rec_list *ptr = alloc_record (prologue);
1726 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1730 static unw_rec_list *
1731 output_prologue_gr (saved_mask, reg)
1732 unsigned int saved_mask;
1735 unw_rec_list *ptr = alloc_record (prologue_gr);
1736 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1737 ptr->r.record.r.grmask = saved_mask;
1738 ptr->r.record.r.grsave = reg;
1742 static unw_rec_list *
1745 unw_rec_list *ptr = alloc_record (body);
1749 static unw_rec_list *
1750 output_mem_stack_f (size)
1753 unw_rec_list *ptr = alloc_record (mem_stack_f);
1754 ptr->r.record.p.size = size;
1758 static unw_rec_list *
1759 output_mem_stack_v ()
1761 unw_rec_list *ptr = alloc_record (mem_stack_v);
1765 static unw_rec_list *
1769 unw_rec_list *ptr = alloc_record (psp_gr);
1770 ptr->r.record.p.gr = gr;
1774 static unw_rec_list *
1775 output_psp_sprel (offset)
1776 unsigned int offset;
1778 unw_rec_list *ptr = alloc_record (psp_sprel);
1779 ptr->r.record.p.spoff = offset / 4;
1783 static unw_rec_list *
1786 unw_rec_list *ptr = alloc_record (rp_when);
1790 static unw_rec_list *
1794 unw_rec_list *ptr = alloc_record (rp_gr);
1795 ptr->r.record.p.gr = gr;
1799 static unw_rec_list *
1803 unw_rec_list *ptr = alloc_record (rp_br);
1804 ptr->r.record.p.br = br;
1808 static unw_rec_list *
1809 output_rp_psprel (offset)
1810 unsigned int offset;
1812 unw_rec_list *ptr = alloc_record (rp_psprel);
1813 ptr->r.record.p.pspoff = offset / 4;
1817 static unw_rec_list *
1818 output_rp_sprel (offset)
1819 unsigned int offset;
1821 unw_rec_list *ptr = alloc_record (rp_sprel);
1822 ptr->r.record.p.spoff = offset / 4;
1826 static unw_rec_list *
1829 unw_rec_list *ptr = alloc_record (pfs_when);
1833 static unw_rec_list *
1837 unw_rec_list *ptr = alloc_record (pfs_gr);
1838 ptr->r.record.p.gr = gr;
1842 static unw_rec_list *
1843 output_pfs_psprel (offset)
1844 unsigned int offset;
1846 unw_rec_list *ptr = alloc_record (pfs_psprel);
1847 ptr->r.record.p.pspoff = offset / 4;
1851 static unw_rec_list *
1852 output_pfs_sprel (offset)
1853 unsigned int offset;
1855 unw_rec_list *ptr = alloc_record (pfs_sprel);
1856 ptr->r.record.p.spoff = offset / 4;
1860 static unw_rec_list *
1861 output_preds_when ()
1863 unw_rec_list *ptr = alloc_record (preds_when);
1867 static unw_rec_list *
1868 output_preds_gr (gr)
1871 unw_rec_list *ptr = alloc_record (preds_gr);
1872 ptr->r.record.p.gr = gr;
1876 static unw_rec_list *
1877 output_preds_psprel (offset)
1878 unsigned int offset;
1880 unw_rec_list *ptr = alloc_record (preds_psprel);
1881 ptr->r.record.p.pspoff = offset / 4;
1885 static unw_rec_list *
1886 output_preds_sprel (offset)
1887 unsigned int offset;
1889 unw_rec_list *ptr = alloc_record (preds_sprel);
1890 ptr->r.record.p.spoff = offset / 4;
1894 static unw_rec_list *
1895 output_fr_mem (mask)
1898 unw_rec_list *ptr = alloc_record (fr_mem);
1899 ptr->r.record.p.rmask = mask;
1903 static unw_rec_list *
1904 output_frgr_mem (gr_mask, fr_mask)
1905 unsigned int gr_mask;
1906 unsigned int fr_mask;
1908 unw_rec_list *ptr = alloc_record (frgr_mem);
1909 ptr->r.record.p.grmask = gr_mask;
1910 ptr->r.record.p.frmask = fr_mask;
1914 static unw_rec_list *
1915 output_gr_gr (mask, reg)
1919 unw_rec_list *ptr = alloc_record (gr_gr);
1920 ptr->r.record.p.grmask = mask;
1921 ptr->r.record.p.gr = reg;
1925 static unw_rec_list *
1926 output_gr_mem (mask)
1929 unw_rec_list *ptr = alloc_record (gr_mem);
1930 ptr->r.record.p.rmask = mask;
1934 static unw_rec_list *
1935 output_br_mem (unsigned int mask)
1937 unw_rec_list *ptr = alloc_record (br_mem);
1938 ptr->r.record.p.brmask = mask;
1942 static unw_rec_list *
1943 output_br_gr (save_mask, reg)
1944 unsigned int save_mask;
1947 unw_rec_list *ptr = alloc_record (br_gr);
1948 ptr->r.record.p.brmask = save_mask;
1949 ptr->r.record.p.gr = reg;
1953 static unw_rec_list *
1954 output_spill_base (offset)
1955 unsigned int offset;
1957 unw_rec_list *ptr = alloc_record (spill_base);
1958 ptr->r.record.p.pspoff = offset / 4;
1962 static unw_rec_list *
1965 unw_rec_list *ptr = alloc_record (unat_when);
1969 static unw_rec_list *
1973 unw_rec_list *ptr = alloc_record (unat_gr);
1974 ptr->r.record.p.gr = gr;
1978 static unw_rec_list *
1979 output_unat_psprel (offset)
1980 unsigned int offset;
1982 unw_rec_list *ptr = alloc_record (unat_psprel);
1983 ptr->r.record.p.pspoff = offset / 4;
1987 static unw_rec_list *
1988 output_unat_sprel (offset)
1989 unsigned int offset;
1991 unw_rec_list *ptr = alloc_record (unat_sprel);
1992 ptr->r.record.p.spoff = offset / 4;
1996 static unw_rec_list *
1999 unw_rec_list *ptr = alloc_record (lc_when);
2003 static unw_rec_list *
2007 unw_rec_list *ptr = alloc_record (lc_gr);
2008 ptr->r.record.p.gr = gr;
2012 static unw_rec_list *
2013 output_lc_psprel (offset)
2014 unsigned int offset;
2016 unw_rec_list *ptr = alloc_record (lc_psprel);
2017 ptr->r.record.p.pspoff = offset / 4;
2021 static unw_rec_list *
2022 output_lc_sprel (offset)
2023 unsigned int offset;
2025 unw_rec_list *ptr = alloc_record (lc_sprel);
2026 ptr->r.record.p.spoff = offset / 4;
2030 static unw_rec_list *
2033 unw_rec_list *ptr = alloc_record (fpsr_when);
2037 static unw_rec_list *
2041 unw_rec_list *ptr = alloc_record (fpsr_gr);
2042 ptr->r.record.p.gr = gr;
2046 static unw_rec_list *
2047 output_fpsr_psprel (offset)
2048 unsigned int offset;
2050 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2051 ptr->r.record.p.pspoff = offset / 4;
2055 static unw_rec_list *
2056 output_fpsr_sprel (offset)
2057 unsigned int offset;
2059 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2060 ptr->r.record.p.spoff = offset / 4;
2064 static unw_rec_list *
2065 output_priunat_when_gr ()
2067 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2071 static unw_rec_list *
2072 output_priunat_when_mem ()
2074 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2078 static unw_rec_list *
2079 output_priunat_gr (gr)
2082 unw_rec_list *ptr = alloc_record (priunat_gr);
2083 ptr->r.record.p.gr = gr;
2087 static unw_rec_list *
2088 output_priunat_psprel (offset)
2089 unsigned int offset;
2091 unw_rec_list *ptr = alloc_record (priunat_psprel);
2092 ptr->r.record.p.pspoff = offset / 4;
2096 static unw_rec_list *
2097 output_priunat_sprel (offset)
2098 unsigned int offset;
2100 unw_rec_list *ptr = alloc_record (priunat_sprel);
2101 ptr->r.record.p.spoff = offset / 4;
2105 static unw_rec_list *
2108 unw_rec_list *ptr = alloc_record (bsp_when);
2112 static unw_rec_list *
2116 unw_rec_list *ptr = alloc_record (bsp_gr);
2117 ptr->r.record.p.gr = gr;
2121 static unw_rec_list *
2122 output_bsp_psprel (offset)
2123 unsigned int offset;
2125 unw_rec_list *ptr = alloc_record (bsp_psprel);
2126 ptr->r.record.p.pspoff = offset / 4;
2130 static unw_rec_list *
2131 output_bsp_sprel (offset)
2132 unsigned int offset;
2134 unw_rec_list *ptr = alloc_record (bsp_sprel);
2135 ptr->r.record.p.spoff = offset / 4;
2139 static unw_rec_list *
2140 output_bspstore_when ()
2142 unw_rec_list *ptr = alloc_record (bspstore_when);
2146 static unw_rec_list *
2147 output_bspstore_gr (gr)
2150 unw_rec_list *ptr = alloc_record (bspstore_gr);
2151 ptr->r.record.p.gr = gr;
2155 static unw_rec_list *
2156 output_bspstore_psprel (offset)
2157 unsigned int offset;
2159 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2160 ptr->r.record.p.pspoff = offset / 4;
2164 static unw_rec_list *
2165 output_bspstore_sprel (offset)
2166 unsigned int offset;
2168 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2169 ptr->r.record.p.spoff = offset / 4;
2173 static unw_rec_list *
2176 unw_rec_list *ptr = alloc_record (rnat_when);
2180 static unw_rec_list *
2184 unw_rec_list *ptr = alloc_record (rnat_gr);
2185 ptr->r.record.p.gr = gr;
2189 static unw_rec_list *
2190 output_rnat_psprel (offset)
2191 unsigned int offset;
2193 unw_rec_list *ptr = alloc_record (rnat_psprel);
2194 ptr->r.record.p.pspoff = offset / 4;
2198 static unw_rec_list *
2199 output_rnat_sprel (offset)
2200 unsigned int offset;
2202 unw_rec_list *ptr = alloc_record (rnat_sprel);
2203 ptr->r.record.p.spoff = offset / 4;
2207 static unw_rec_list *
2208 output_unwabi (abi, context)
2210 unsigned long context;
2212 unw_rec_list *ptr = alloc_record (unwabi);
2213 ptr->r.record.p.abi = abi;
2214 ptr->r.record.p.context = context;
2218 static unw_rec_list *
2219 output_epilogue (unsigned long ecount)
2221 unw_rec_list *ptr = alloc_record (epilogue);
2222 ptr->r.record.b.ecount = ecount;
2226 static unw_rec_list *
2227 output_label_state (unsigned long label)
2229 unw_rec_list *ptr = alloc_record (label_state);
2230 ptr->r.record.b.label = label;
2234 static unw_rec_list *
2235 output_copy_state (unsigned long label)
2237 unw_rec_list *ptr = alloc_record (copy_state);
2238 ptr->r.record.b.label = label;
2242 static unw_rec_list *
2243 output_spill_psprel (ab, reg, offset)
2246 unsigned int offset;
2248 unw_rec_list *ptr = alloc_record (spill_psprel);
2249 ptr->r.record.x.ab = ab;
2250 ptr->r.record.x.reg = reg;
2251 ptr->r.record.x.pspoff = offset / 4;
2255 static unw_rec_list *
2256 output_spill_sprel (ab, reg, offset)
2259 unsigned int offset;
2261 unw_rec_list *ptr = alloc_record (spill_sprel);
2262 ptr->r.record.x.ab = ab;
2263 ptr->r.record.x.reg = reg;
2264 ptr->r.record.x.spoff = offset / 4;
2268 static unw_rec_list *
2269 output_spill_psprel_p (ab, reg, offset, predicate)
2272 unsigned int offset;
2273 unsigned int predicate;
2275 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2276 ptr->r.record.x.ab = ab;
2277 ptr->r.record.x.reg = reg;
2278 ptr->r.record.x.pspoff = offset / 4;
2279 ptr->r.record.x.qp = predicate;
2283 static unw_rec_list *
2284 output_spill_sprel_p (ab, reg, offset, predicate)
2287 unsigned int offset;
2288 unsigned int predicate;
2290 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2291 ptr->r.record.x.ab = ab;
2292 ptr->r.record.x.reg = reg;
2293 ptr->r.record.x.spoff = offset / 4;
2294 ptr->r.record.x.qp = predicate;
2298 static unw_rec_list *
2299 output_spill_reg (ab, reg, targ_reg, xy)
2302 unsigned int targ_reg;
2305 unw_rec_list *ptr = alloc_record (spill_reg);
2306 ptr->r.record.x.ab = ab;
2307 ptr->r.record.x.reg = reg;
2308 ptr->r.record.x.treg = targ_reg;
2309 ptr->r.record.x.xy = xy;
2313 static unw_rec_list *
2314 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2317 unsigned int targ_reg;
2319 unsigned int predicate;
2321 unw_rec_list *ptr = alloc_record (spill_reg_p);
2322 ptr->r.record.x.ab = ab;
2323 ptr->r.record.x.reg = reg;
2324 ptr->r.record.x.treg = targ_reg;
2325 ptr->r.record.x.xy = xy;
2326 ptr->r.record.x.qp = predicate;
2330 /* Given a unw_rec_list process the correct format with the
2331 specified function. */
2334 process_one_record (ptr, f)
2338 unsigned long fr_mask, gr_mask;
2340 switch (ptr->r.type)
2346 /* These are taken care of by prologue/prologue_gr. */
2351 if (ptr->r.type == prologue_gr)
2352 output_R2_format (f, ptr->r.record.r.grmask,
2353 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2355 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2357 /* Output descriptor(s) for union of register spills (if any). */
2358 gr_mask = ptr->r.record.r.mask.gr_mem;
2359 fr_mask = ptr->r.record.r.mask.fr_mem;
2362 if ((fr_mask & ~0xfUL) == 0)
2363 output_P6_format (f, fr_mem, fr_mask);
2366 output_P5_format (f, gr_mask, fr_mask);
2371 output_P6_format (f, gr_mem, gr_mask);
2372 if (ptr->r.record.r.mask.br_mem)
2373 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2375 /* output imask descriptor if necessary: */
2376 if (ptr->r.record.r.mask.i)
2377 output_P4_format (f, ptr->r.record.r.mask.i,
2378 ptr->r.record.r.imask_size);
2382 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2386 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2387 ptr->r.record.p.size);
2400 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2403 output_P3_format (f, rp_br, ptr->r.record.p.br);
2406 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2414 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2423 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2433 case bspstore_sprel:
2435 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2438 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2441 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2444 as_bad ("spill_mask record unimplemented.");
2446 case priunat_when_gr:
2447 case priunat_when_mem:
2451 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2453 case priunat_psprel:
2455 case bspstore_psprel:
2457 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2460 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2463 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2467 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2470 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2471 ptr->r.record.x.reg, ptr->r.record.x.t,
2472 ptr->r.record.x.pspoff);
2475 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2476 ptr->r.record.x.reg, ptr->r.record.x.t,
2477 ptr->r.record.x.spoff);
2480 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2481 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2482 ptr->r.record.x.treg, ptr->r.record.x.t);
2484 case spill_psprel_p:
2485 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2486 ptr->r.record.x.ab, ptr->r.record.x.reg,
2487 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2490 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2491 ptr->r.record.x.ab, ptr->r.record.x.reg,
2492 ptr->r.record.x.t, ptr->r.record.x.spoff);
2495 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2496 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2497 ptr->r.record.x.xy, ptr->r.record.x.treg,
2501 as_bad ("record_type_not_valid");
2506 /* Given a unw_rec_list list, process all the records with
2507 the specified function. */
2509 process_unw_records (list, f)
2514 for (ptr = list; ptr; ptr = ptr->next)
2515 process_one_record (ptr, f);
2518 /* Determine the size of a record list in bytes. */
2520 calc_record_size (list)
2524 process_unw_records (list, count_output);
2528 /* Update IMASK bitmask to reflect the fact that one or more registers
2529 of type TYPE are saved starting at instruction with index T. If N
2530 bits are set in REGMASK, it is assumed that instructions T through
2531 T+N-1 save these registers.
2535 1: instruction saves next fp reg
2536 2: instruction saves next general reg
2537 3: instruction saves next branch reg */
2539 set_imask (region, regmask, t, type)
2540 unw_rec_list *region;
2541 unsigned long regmask;
2545 unsigned char *imask;
2546 unsigned long imask_size;
2550 imask = region->r.record.r.mask.i;
2551 imask_size = region->r.record.r.imask_size;
2554 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2555 imask = xmalloc (imask_size);
2556 memset (imask, 0, imask_size);
2558 region->r.record.r.imask_size = imask_size;
2559 region->r.record.r.mask.i = imask;
2563 pos = 2 * (3 - t % 4);
2566 if (i >= imask_size)
2568 as_bad ("Ignoring attempt to spill beyond end of region");
2572 imask[i] |= (type & 0x3) << pos;
2574 regmask &= (regmask - 1);
2585 count_bits (unsigned long mask)
2597 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2598 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2599 containing FIRST_ADDR. */
2602 slot_index (slot_addr, slot_frag, first_addr, first_frag)
2603 unsigned long slot_addr;
2605 unsigned long first_addr;
2608 unsigned long index = 0;
2610 /* First time we are called, the initial address and frag are invalid. */
2611 if (first_addr == 0)
2614 /* If the two addresses are in different frags, then we need to add in
2615 the remaining size of this frag, and then the entire size of intermediate
2617 while (slot_frag != first_frag)
2619 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2621 /* Add in the full size of the frag converted to instruction slots. */
2622 index += 3 * (first_frag->fr_fix >> 4);
2623 /* Subtract away the initial part before first_addr. */
2624 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2625 + ((first_addr & 0x3) - (start_addr & 0x3)));
2627 /* Move to the beginning of the next frag. */
2628 first_frag = first_frag->fr_next;
2629 first_addr = (unsigned long) &first_frag->fr_literal;
2632 /* Add in the used part of the last frag. */
2633 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2634 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2638 /* Optimize unwind record directives. */
2640 static unw_rec_list *
2641 optimize_unw_records (list)
2647 /* If the only unwind record is ".prologue" or ".prologue" followed
2648 by ".body", then we can optimize the unwind directives away. */
2649 if (list->r.type == prologue
2650 && (list->next == NULL
2651 || (list->next->r.type == body && list->next->next == NULL)))
2657 /* Given a complete record list, process any records which have
2658 unresolved fields, (ie length counts for a prologue). After
2659 this has been run, all neccessary information should be available
2660 within each record to generate an image. */
2663 fixup_unw_records (list)
2666 unw_rec_list *ptr, *region = 0;
2667 unsigned long first_addr = 0, rlen = 0, t;
2668 fragS *first_frag = 0;
2670 for (ptr = list; ptr; ptr = ptr->next)
2672 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2673 as_bad (" Insn slot not set in unwind record.");
2674 t = slot_index (ptr->slot_number, ptr->slot_frag,
2675 first_addr, first_frag);
2676 switch (ptr->r.type)
2683 int size, dir_len = 0;
2684 unsigned long last_addr;
2687 first_addr = ptr->slot_number;
2688 first_frag = ptr->slot_frag;
2689 ptr->slot_number = 0;
2690 /* Find either the next body/prologue start, or the end of
2691 the list, and determine the size of the region. */
2692 last_addr = unwind.next_slot_number;
2693 last_frag = unwind.next_slot_frag;
2694 for (last = ptr->next; last != NULL; last = last->next)
2695 if (last->r.type == prologue || last->r.type == prologue_gr
2696 || last->r.type == body)
2698 last_addr = last->slot_number;
2699 last_frag = last->slot_frag;
2702 else if (!last->next)
2704 /* In the absence of an explicit .body directive,
2705 the prologue ends after the last instruction
2706 covered by an unwind directive. */
2707 if (ptr->r.type != body)
2709 last_addr = last->slot_number;
2710 last_frag = last->slot_frag;
2711 switch (last->r.type)
2714 dir_len = (count_bits (last->r.record.p.frmask)
2715 + count_bits (last->r.record.p.grmask));
2719 dir_len += count_bits (last->r.record.p.rmask);
2723 dir_len += count_bits (last->r.record.p.brmask);
2726 dir_len += count_bits (last->r.record.p.grmask);
2735 size = (slot_index (last_addr, last_frag, first_addr, first_frag)
2737 rlen = ptr->r.record.r.rlen = size;
2738 if (ptr->r.type == body)
2739 /* End of region. */
2746 ptr->r.record.b.t = rlen - 1 - t;
2757 case priunat_when_gr:
2758 case priunat_when_mem:
2762 ptr->r.record.p.t = t;
2770 case spill_psprel_p:
2771 ptr->r.record.x.t = t;
2777 as_bad ("frgr_mem record before region record!\n");
2780 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2781 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2782 set_imask (region, ptr->r.record.p.frmask, t, 1);
2783 set_imask (region, ptr->r.record.p.grmask, t, 2);
2788 as_bad ("fr_mem record before region record!\n");
2791 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2792 set_imask (region, ptr->r.record.p.rmask, t, 1);
2797 as_bad ("gr_mem record before region record!\n");
2800 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2801 set_imask (region, ptr->r.record.p.rmask, t, 2);
2806 as_bad ("br_mem record before region record!\n");
2809 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2810 set_imask (region, ptr->r.record.p.brmask, t, 3);
2816 as_bad ("gr_gr record before region record!\n");
2819 set_imask (region, ptr->r.record.p.grmask, t, 2);
2824 as_bad ("br_gr record before region record!\n");
2827 set_imask (region, ptr->r.record.p.brmask, t, 3);
2836 /* Helper routine for output_unw_records. Emits the header for the unwind
2840 setup_unwind_header (int size, unsigned char **mem)
2845 /* pad to pointer-size boundry. */
2846 x = size % md.pointer_size;
2848 extra = md.pointer_size - x;
2850 /* Add 8 for the header + a pointer for the
2851 personality offset. */
2852 *mem = xmalloc (size + extra + 8 + md.pointer_size);
2854 /* Clear the padding area and personality. */
2855 memset (*mem + 8 + size, 0, extra + md.pointer_size);
2857 /* Initialize the header area. */
2858 if (unwind.personality_routine)
2860 if (md.flags & EF_IA_64_ABI64)
2861 flag_value = (bfd_vma) 3 << 32;
2863 /* 32-bit unwind info block. */
2864 flag_value = (bfd_vma) 0x1003 << 32;
2869 md_number_to_chars (*mem, (((bfd_vma) 1 << 48) /* Version. */
2870 | flag_value /* U & E handler flags. */
2871 | ((size + extra) / md.pointer_size)), /* Length. */
2877 /* Generate an unwind image from a record list. Returns the number of
2878 bytes in the resulting image. The memory image itselof is returned
2879 in the 'ptr' parameter. */
2881 output_unw_records (list, ptr)
2890 list = optimize_unw_records (list);
2891 fixup_unw_records (list);
2892 size = calc_record_size (list);
2894 if (size > 0 || unwind.force_unwind_entry)
2896 unwind.force_unwind_entry = 0;
2897 extra = setup_unwind_header (size, &mem);
2899 vbyte_mem_ptr = mem + 8;
2900 process_unw_records (list, output_vbyte_mem);
2904 size += extra + 8 + md.pointer_size;
2910 convert_expr_to_ab_reg (e, ab, regp)
2917 if (e->X_op != O_register)
2920 reg = e->X_add_number;
2921 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2924 *regp = reg - REG_GR;
2926 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2927 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2930 *regp = reg - REG_FR;
2932 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2935 *regp = reg - REG_BR;
2942 case REG_PR: *regp = 0; break;
2943 case REG_PSP: *regp = 1; break;
2944 case REG_PRIUNAT: *regp = 2; break;
2945 case REG_BR + 0: *regp = 3; break;
2946 case REG_AR + AR_BSP: *regp = 4; break;
2947 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2948 case REG_AR + AR_RNAT: *regp = 6; break;
2949 case REG_AR + AR_UNAT: *regp = 7; break;
2950 case REG_AR + AR_FPSR: *regp = 8; break;
2951 case REG_AR + AR_PFS: *regp = 9; break;
2952 case REG_AR + AR_LC: *regp = 10; break;
2962 convert_expr_to_xy_reg (e, xy, regp)
2969 if (e->X_op != O_register)
2972 reg = e->X_add_number;
2974 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2977 *regp = reg - REG_GR;
2979 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2982 *regp = reg - REG_FR;
2984 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2987 *regp = reg - REG_BR;
2996 int dummy ATTRIBUTE_UNUSED;
3001 radix = *input_line_pointer++;
3003 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3005 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3006 ignore_rest_of_line ();
3011 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3013 dot_special_section (which)
3016 set_section ((char *) special_section_name[which]);
3020 add_unwind_entry (ptr)
3024 unwind.tail->next = ptr;
3029 /* The current entry can in fact be a chain of unwind entries. */
3030 if (unwind.current_entry == NULL)
3031 unwind.current_entry = ptr;
3036 int dummy ATTRIBUTE_UNUSED;
3042 if (e.X_op != O_constant)
3043 as_bad ("Operand to .fframe must be a constant");
3045 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3050 int dummy ATTRIBUTE_UNUSED;
3056 reg = e.X_add_number - REG_GR;
3057 if (e.X_op == O_register && reg < 128)
3059 add_unwind_entry (output_mem_stack_v ());
3060 if (! (unwind.prologue_mask & 2))
3061 add_unwind_entry (output_psp_gr (reg));
3064 as_bad ("First operand to .vframe must be a general register");
3068 dot_vframesp (dummy)
3069 int dummy ATTRIBUTE_UNUSED;
3074 if (e.X_op == O_constant)
3076 add_unwind_entry (output_mem_stack_v ());
3077 add_unwind_entry (output_psp_sprel (e.X_add_number));
3080 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3084 dot_vframepsp (dummy)
3085 int dummy ATTRIBUTE_UNUSED;
3090 if (e.X_op == O_constant)
3092 add_unwind_entry (output_mem_stack_v ());
3093 add_unwind_entry (output_psp_sprel (e.X_add_number));
3096 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3101 int dummy ATTRIBUTE_UNUSED;
3107 sep = parse_operand (&e1);
3109 as_bad ("No second operand to .save");
3110 sep = parse_operand (&e2);
3112 reg1 = e1.X_add_number;
3113 reg2 = e2.X_add_number - REG_GR;
3115 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3116 if (e1.X_op == O_register)
3118 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3122 case REG_AR + AR_BSP:
3123 add_unwind_entry (output_bsp_when ());
3124 add_unwind_entry (output_bsp_gr (reg2));
3126 case REG_AR + AR_BSPSTORE:
3127 add_unwind_entry (output_bspstore_when ());
3128 add_unwind_entry (output_bspstore_gr (reg2));
3130 case REG_AR + AR_RNAT:
3131 add_unwind_entry (output_rnat_when ());
3132 add_unwind_entry (output_rnat_gr (reg2));
3134 case REG_AR + AR_UNAT:
3135 add_unwind_entry (output_unat_when ());
3136 add_unwind_entry (output_unat_gr (reg2));
3138 case REG_AR + AR_FPSR:
3139 add_unwind_entry (output_fpsr_when ());
3140 add_unwind_entry (output_fpsr_gr (reg2));
3142 case REG_AR + AR_PFS:
3143 add_unwind_entry (output_pfs_when ());
3144 if (! (unwind.prologue_mask & 4))
3145 add_unwind_entry (output_pfs_gr (reg2));
3147 case REG_AR + AR_LC:
3148 add_unwind_entry (output_lc_when ());
3149 add_unwind_entry (output_lc_gr (reg2));
3152 add_unwind_entry (output_rp_when ());
3153 if (! (unwind.prologue_mask & 8))
3154 add_unwind_entry (output_rp_gr (reg2));
3157 add_unwind_entry (output_preds_when ());
3158 if (! (unwind.prologue_mask & 1))
3159 add_unwind_entry (output_preds_gr (reg2));
3162 add_unwind_entry (output_priunat_when_gr ());
3163 add_unwind_entry (output_priunat_gr (reg2));
3166 as_bad ("First operand not a valid register");
3170 as_bad (" Second operand not a valid register");
3173 as_bad ("First operand not a register");
3178 int dummy ATTRIBUTE_UNUSED;
3181 unsigned long ecount; /* # of _additional_ regions to pop */
3184 sep = parse_operand (&e1);
3185 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3187 as_bad ("First operand to .restore must be stack pointer (sp)");
3193 parse_operand (&e2);
3194 if (e2.X_op != O_constant || e2.X_add_number < 0)
3196 as_bad ("Second operand to .restore must be a constant >= 0");
3199 ecount = e2.X_add_number;
3202 ecount = unwind.prologue_count - 1;
3204 if (ecount >= unwind.prologue_count)
3206 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3207 ecount + 1, unwind.prologue_count);
3211 add_unwind_entry (output_epilogue (ecount));
3213 if (ecount < unwind.prologue_count)
3214 unwind.prologue_count -= ecount + 1;
3216 unwind.prologue_count = 0;
3220 dot_restorereg (dummy)
3221 int dummy ATTRIBUTE_UNUSED;
3223 unsigned int ab, reg;
3228 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3230 as_bad ("First operand to .restorereg must be a preserved register");
3233 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3237 dot_restorereg_p (dummy)
3238 int dummy ATTRIBUTE_UNUSED;
3240 unsigned int qp, ab, reg;
3244 sep = parse_operand (&e1);
3247 as_bad ("No second operand to .restorereg.p");
3251 parse_operand (&e2);
3253 qp = e1.X_add_number - REG_P;
3254 if (e1.X_op != O_register || qp > 63)
3256 as_bad ("First operand to .restorereg.p must be a predicate");
3260 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3262 as_bad ("Second operand to .restorereg.p must be a preserved register");
3265 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3269 generate_unwind_image (text_name)
3270 const char *text_name;
3275 /* Force out pending instructions, to make sure all unwind records have
3276 a valid slot_number field. */
3277 ia64_flush_insns ();
3279 /* Generate the unwind record. */
3280 size = output_unw_records (unwind.list, &unw_rec);
3281 if (size % md.pointer_size != 0)
3282 as_bad ("Unwind record is not a multiple of %d bytes.", md.pointer_size);
3284 /* If there are unwind records, switch sections, and output the info. */
3287 unsigned char *where;
3290 bfd_reloc_code_real_type reloc;
3292 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3293 set_section (sec_name);
3294 bfd_set_section_flags (stdoutput, now_seg,
3295 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3297 /* Make sure the section has 4 byte alignment for ILP32 and
3298 8 byte alignment for LP64. */
3299 frag_align (md.pointer_size_shift, 0, 0);
3300 record_alignment (now_seg, md.pointer_size_shift);
3302 /* Set expression which points to start of unwind descriptor area. */
3303 unwind.info = expr_build_dot ();
3305 where = (unsigned char *) frag_more (size);
3307 /* Issue a label for this address, and keep track of it to put it
3308 in the unwind section. */
3310 /* Copy the information from the unwind record into this section. The
3311 data is already in the correct byte order. */
3312 memcpy (where, unw_rec, size);
3314 /* Add the personality address to the image. */
3315 if (unwind.personality_routine != 0)
3317 exp.X_op = O_symbol;
3318 exp.X_add_symbol = unwind.personality_routine;
3319 exp.X_add_number = 0;
3321 if (md.flags & EF_IA_64_BE)
3323 if (md.flags & EF_IA_64_ABI64)
3324 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3326 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3330 if (md.flags & EF_IA_64_ABI64)
3331 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3333 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3336 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3337 md.pointer_size, &exp, 0, reloc);
3338 unwind.personality_routine = 0;
3342 free_list_records (unwind.list);
3343 free_saved_prologue_counts ();
3344 unwind.list = unwind.tail = unwind.current_entry = NULL;
3350 dot_handlerdata (dummy)
3351 int dummy ATTRIBUTE_UNUSED;
3353 const char *text_name = segment_name (now_seg);
3355 /* If text section name starts with ".text" (which it should),
3356 strip this prefix off. */
3357 if (strcmp (text_name, ".text") == 0)
3360 unwind.force_unwind_entry = 1;
3362 /* Remember which segment we're in so we can switch back after .endp */
3363 unwind.saved_text_seg = now_seg;
3364 unwind.saved_text_subseg = now_subseg;
3366 /* Generate unwind info into unwind-info section and then leave that
3367 section as the currently active one so dataXX directives go into
3368 the language specific data area of the unwind info block. */
3369 generate_unwind_image (text_name);
3370 demand_empty_rest_of_line ();
3374 dot_unwentry (dummy)
3375 int dummy ATTRIBUTE_UNUSED;
3377 unwind.force_unwind_entry = 1;
3378 demand_empty_rest_of_line ();
3383 int dummy ATTRIBUTE_UNUSED;
3389 reg = e.X_add_number - REG_BR;
3390 if (e.X_op == O_register && reg < 8)
3391 add_unwind_entry (output_rp_br (reg));
3393 as_bad ("First operand not a valid branch register");
3397 dot_savemem (psprel)
3404 sep = parse_operand (&e1);
3406 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3407 sep = parse_operand (&e2);
3409 reg1 = e1.X_add_number;
3410 val = e2.X_add_number;
3412 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3413 if (e1.X_op == O_register)
3415 if (e2.X_op == O_constant)
3419 case REG_AR + AR_BSP:
3420 add_unwind_entry (output_bsp_when ());
3421 add_unwind_entry ((psprel
3423 : output_bsp_sprel) (val));
3425 case REG_AR + AR_BSPSTORE:
3426 add_unwind_entry (output_bspstore_when ());
3427 add_unwind_entry ((psprel
3428 ? output_bspstore_psprel
3429 : output_bspstore_sprel) (val));
3431 case REG_AR + AR_RNAT:
3432 add_unwind_entry (output_rnat_when ());
3433 add_unwind_entry ((psprel
3434 ? output_rnat_psprel
3435 : output_rnat_sprel) (val));
3437 case REG_AR + AR_UNAT:
3438 add_unwind_entry (output_unat_when ());
3439 add_unwind_entry ((psprel
3440 ? output_unat_psprel
3441 : output_unat_sprel) (val));
3443 case REG_AR + AR_FPSR:
3444 add_unwind_entry (output_fpsr_when ());
3445 add_unwind_entry ((psprel
3446 ? output_fpsr_psprel
3447 : output_fpsr_sprel) (val));
3449 case REG_AR + AR_PFS:
3450 add_unwind_entry (output_pfs_when ());
3451 add_unwind_entry ((psprel
3453 : output_pfs_sprel) (val));
3455 case REG_AR + AR_LC:
3456 add_unwind_entry (output_lc_when ());
3457 add_unwind_entry ((psprel
3459 : output_lc_sprel) (val));
3462 add_unwind_entry (output_rp_when ());
3463 add_unwind_entry ((psprel
3465 : output_rp_sprel) (val));
3468 add_unwind_entry (output_preds_when ());
3469 add_unwind_entry ((psprel
3470 ? output_preds_psprel
3471 : output_preds_sprel) (val));
3474 add_unwind_entry (output_priunat_when_mem ());
3475 add_unwind_entry ((psprel
3476 ? output_priunat_psprel
3477 : output_priunat_sprel) (val));
3480 as_bad ("First operand not a valid register");
3484 as_bad (" Second operand not a valid constant");
3487 as_bad ("First operand not a register");
3492 int dummy ATTRIBUTE_UNUSED;
3496 sep = parse_operand (&e1);
3498 parse_operand (&e2);
3500 if (e1.X_op != O_constant)
3501 as_bad ("First operand to .save.g must be a constant.");
3504 int grmask = e1.X_add_number;
3506 add_unwind_entry (output_gr_mem (grmask));
3509 int reg = e2.X_add_number - REG_GR;
3510 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3511 add_unwind_entry (output_gr_gr (grmask, reg));
3513 as_bad ("Second operand is an invalid register.");
3520 int dummy ATTRIBUTE_UNUSED;
3524 sep = parse_operand (&e1);
3526 if (e1.X_op != O_constant)
3527 as_bad ("Operand to .save.f must be a constant.");
3529 add_unwind_entry (output_fr_mem (e1.X_add_number));
3534 int dummy ATTRIBUTE_UNUSED;
3541 sep = parse_operand (&e1);
3542 if (e1.X_op != O_constant)
3544 as_bad ("First operand to .save.b must be a constant.");
3547 brmask = e1.X_add_number;
3551 sep = parse_operand (&e2);
3552 reg = e2.X_add_number - REG_GR;
3553 if (e2.X_op != O_register || reg > 127)
3555 as_bad ("Second operand to .save.b must be a general register.");
3558 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3561 add_unwind_entry (output_br_mem (brmask));
3563 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3564 ignore_rest_of_line ();
3569 int dummy ATTRIBUTE_UNUSED;
3573 sep = parse_operand (&e1);
3575 parse_operand (&e2);
3577 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3578 as_bad ("Both operands of .save.gf must be constants.");
3581 int grmask = e1.X_add_number;
3582 int frmask = e2.X_add_number;
3583 add_unwind_entry (output_frgr_mem (grmask, frmask));
3589 int dummy ATTRIBUTE_UNUSED;
3594 sep = parse_operand (&e);
3595 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3596 ignore_rest_of_line ();
3598 if (e.X_op != O_constant)
3599 as_bad ("Operand to .spill must be a constant");
3601 add_unwind_entry (output_spill_base (e.X_add_number));
3605 dot_spillreg (dummy)
3606 int dummy ATTRIBUTE_UNUSED;
3608 int sep, ab, xy, reg, treg;
3611 sep = parse_operand (&e1);
3614 as_bad ("No second operand to .spillreg");
3618 parse_operand (&e2);
3620 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3622 as_bad ("First operand to .spillreg must be a preserved register");
3626 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3628 as_bad ("Second operand to .spillreg must be a register");
3632 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3636 dot_spillmem (psprel)
3642 sep = parse_operand (&e1);
3645 as_bad ("Second operand missing");
3649 parse_operand (&e2);
3651 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3653 as_bad ("First operand to .spill%s must be a preserved register",
3654 psprel ? "psp" : "sp");
3658 if (e2.X_op != O_constant)
3660 as_bad ("Second operand to .spill%s must be a constant",
3661 psprel ? "psp" : "sp");
3666 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3668 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3672 dot_spillreg_p (dummy)
3673 int dummy ATTRIBUTE_UNUSED;
3675 int sep, ab, xy, reg, treg;
3676 expressionS e1, e2, e3;
3679 sep = parse_operand (&e1);
3682 as_bad ("No second and third operand to .spillreg.p");
3686 sep = parse_operand (&e2);
3689 as_bad ("No third operand to .spillreg.p");
3693 parse_operand (&e3);
3695 qp = e1.X_add_number - REG_P;
3697 if (e1.X_op != O_register || qp > 63)
3699 as_bad ("First operand to .spillreg.p must be a predicate");
3703 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3705 as_bad ("Second operand to .spillreg.p must be a preserved register");
3709 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3711 as_bad ("Third operand to .spillreg.p must be a register");
3715 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3719 dot_spillmem_p (psprel)
3722 expressionS e1, e2, e3;
3726 sep = parse_operand (&e1);
3729 as_bad ("Second operand missing");
3733 parse_operand (&e2);
3736 as_bad ("Second operand missing");
3740 parse_operand (&e3);
3742 qp = e1.X_add_number - REG_P;
3743 if (e1.X_op != O_register || qp > 63)
3745 as_bad ("First operand to .spill%s_p must be a predicate",
3746 psprel ? "psp" : "sp");
3750 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3752 as_bad ("Second operand to .spill%s_p must be a preserved register",
3753 psprel ? "psp" : "sp");
3757 if (e3.X_op != O_constant)
3759 as_bad ("Third operand to .spill%s_p must be a constant",
3760 psprel ? "psp" : "sp");
3765 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3767 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3771 get_saved_prologue_count (lbl)
3774 label_prologue_count *lpc = unwind.saved_prologue_counts;
3776 while (lpc != NULL && lpc->label_number != lbl)
3780 return lpc->prologue_count;
3782 as_bad ("Missing .label_state %ld", lbl);
3787 save_prologue_count (lbl, count)
3791 label_prologue_count *lpc = unwind.saved_prologue_counts;
3793 while (lpc != NULL && lpc->label_number != lbl)
3797 lpc->prologue_count = count;
3800 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3802 new_lpc->next = unwind.saved_prologue_counts;
3803 new_lpc->label_number = lbl;
3804 new_lpc->prologue_count = count;
3805 unwind.saved_prologue_counts = new_lpc;
3810 free_saved_prologue_counts ()
3812 label_prologue_count *lpc = unwind.saved_prologue_counts;
3813 label_prologue_count *next;
3822 unwind.saved_prologue_counts = NULL;
3826 dot_label_state (dummy)
3827 int dummy ATTRIBUTE_UNUSED;
3832 if (e.X_op != O_constant)
3834 as_bad ("Operand to .label_state must be a constant");
3837 add_unwind_entry (output_label_state (e.X_add_number));
3838 save_prologue_count (e.X_add_number, unwind.prologue_count);
3842 dot_copy_state (dummy)
3843 int dummy ATTRIBUTE_UNUSED;
3848 if (e.X_op != O_constant)
3850 as_bad ("Operand to .copy_state must be a constant");
3853 add_unwind_entry (output_copy_state (e.X_add_number));
3854 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3859 int dummy ATTRIBUTE_UNUSED;
3864 sep = parse_operand (&e1);
3867 as_bad ("Second operand to .unwabi missing");
3870 sep = parse_operand (&e2);
3871 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3872 ignore_rest_of_line ();
3874 if (e1.X_op != O_constant)
3876 as_bad ("First operand to .unwabi must be a constant");
3880 if (e2.X_op != O_constant)
3882 as_bad ("Second operand to .unwabi must be a constant");
3886 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3890 dot_personality (dummy)
3891 int dummy ATTRIBUTE_UNUSED;
3895 name = input_line_pointer;
3896 c = get_symbol_end ();
3897 p = input_line_pointer;
3898 unwind.personality_routine = symbol_find_or_make (name);
3899 unwind.force_unwind_entry = 1;
3902 demand_empty_rest_of_line ();
3907 int dummy ATTRIBUTE_UNUSED;
3912 unwind.proc_start = expr_build_dot ();
3913 /* Parse names of main and alternate entry points and mark them as
3914 function symbols: */
3918 name = input_line_pointer;
3919 c = get_symbol_end ();
3920 p = input_line_pointer;
3921 sym = symbol_find_or_make (name);
3922 if (unwind.proc_start == 0)
3924 unwind.proc_start = sym;
3926 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3929 if (*input_line_pointer != ',')
3931 ++input_line_pointer;
3933 demand_empty_rest_of_line ();
3936 unwind.prologue_count = 0;
3937 unwind.list = unwind.tail = unwind.current_entry = NULL;
3938 unwind.personality_routine = 0;
3943 int dummy ATTRIBUTE_UNUSED;
3945 unwind.prologue = 0;
3946 unwind.prologue_mask = 0;
3948 add_unwind_entry (output_body ());
3949 demand_empty_rest_of_line ();
3953 dot_prologue (dummy)
3954 int dummy ATTRIBUTE_UNUSED;
3957 int mask = 0, grsave = 0;
3959 if (!is_it_end_of_statement ())
3962 sep = parse_operand (&e1);
3964 as_bad ("No second operand to .prologue");
3965 sep = parse_operand (&e2);
3966 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3967 ignore_rest_of_line ();
3969 if (e1.X_op == O_constant)
3971 mask = e1.X_add_number;
3973 if (e2.X_op == O_constant)
3974 grsave = e2.X_add_number;
3975 else if (e2.X_op == O_register
3976 && (grsave = e2.X_add_number - REG_GR) < 128)
3979 as_bad ("Second operand not a constant or general register");
3981 add_unwind_entry (output_prologue_gr (mask, grsave));
3984 as_bad ("First operand not a constant");
3987 add_unwind_entry (output_prologue ());
3989 unwind.prologue = 1;
3990 unwind.prologue_mask = mask;
3991 ++unwind.prologue_count;
3996 int dummy ATTRIBUTE_UNUSED;
4000 int bytes_per_address;
4003 subsegT saved_subseg;
4004 const char *sec_name, *text_name;
4008 if (unwind.saved_text_seg)
4010 saved_seg = unwind.saved_text_seg;
4011 saved_subseg = unwind.saved_text_subseg;
4012 unwind.saved_text_seg = NULL;
4016 saved_seg = now_seg;
4017 saved_subseg = now_subseg;
4021 Use a slightly ugly scheme to derive the unwind section names from
4022 the text section name:
4024 text sect. unwind table sect.
4025 name: name: comments:
4026 ---------- ----------------- --------------------------------
4028 .text.foo .IA_64.unwind.text.foo
4029 .foo .IA_64.unwind.foo
4031 .gnu.linkonce.ia64unw.foo
4032 _info .IA_64.unwind_info gas issues error message (ditto)
4033 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
4035 This mapping is done so that:
4037 (a) An object file with unwind info only in .text will use
4038 unwind section names .IA_64.unwind and .IA_64.unwind_info.
4039 This follows the letter of the ABI and also ensures backwards
4040 compatibility with older toolchains.
4042 (b) An object file with unwind info in multiple text sections
4043 will use separate unwind sections for each text section.
4044 This allows us to properly set the "sh_info" and "sh_link"
4045 fields in SHT_IA_64_UNWIND as required by the ABI and also
4046 lets GNU ld support programs with multiple segments
4047 containing unwind info (as might be the case for certain
4048 embedded applications).
4050 (c) An error is issued if there would be a name clash.
4052 text_name = segment_name (saved_seg);
4053 if (strncmp (text_name, "_info", 5) == 0)
4055 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
4057 ignore_rest_of_line ();
4060 if (strcmp (text_name, ".text") == 0)
4063 insn_group_break (1, 0, 0);
4065 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4067 generate_unwind_image (text_name);
4069 if (unwind.info || unwind.force_unwind_entry)
4071 subseg_set (md.last_text_seg, 0);
4072 unwind.proc_end = expr_build_dot ();
4074 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
4075 set_section ((char *) sec_name);
4076 bfd_set_section_flags (stdoutput, now_seg,
4077 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
4079 /* Make sure that section has 4 byte alignment for ILP32 and
4080 8 byte alignment for LP64. */
4081 record_alignment (now_seg, md.pointer_size_shift);
4083 /* Need space for 3 pointers for procedure start, procedure end,
4085 ptr = frag_more (3 * md.pointer_size);
4086 where = frag_now_fix () - (3 * md.pointer_size);
4087 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4089 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4090 e.X_op = O_pseudo_fixup;
4091 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4093 e.X_add_symbol = unwind.proc_start;
4094 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4096 e.X_op = O_pseudo_fixup;
4097 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4099 e.X_add_symbol = unwind.proc_end;
4100 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4101 bytes_per_address, &e);
4105 e.X_op = O_pseudo_fixup;
4106 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4108 e.X_add_symbol = unwind.info;
4109 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4110 bytes_per_address, &e);
4113 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4117 subseg_set (saved_seg, saved_subseg);
4119 /* Parse names of main and alternate entry points and set symbol sizes. */
4123 name = input_line_pointer;
4124 c = get_symbol_end ();
4125 p = input_line_pointer;
4126 sym = symbol_find (name);
4127 if (sym && unwind.proc_start
4128 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4129 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4131 fragS *fr = symbol_get_frag (unwind.proc_start);
4132 fragS *frag = symbol_get_frag (sym);
4134 /* Check whether the function label is at or beyond last
4136 while (fr && fr != frag)
4140 if (frag == frag_now && SEG_NORMAL (now_seg))
4141 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4144 symbol_get_obj (sym)->size =
4145 (expressionS *) xmalloc (sizeof (expressionS));
4146 symbol_get_obj (sym)->size->X_op = O_subtract;
4147 symbol_get_obj (sym)->size->X_add_symbol
4148 = symbol_new (FAKE_LABEL_NAME, now_seg,
4149 frag_now_fix (), frag_now);
4150 symbol_get_obj (sym)->size->X_op_symbol = sym;
4151 symbol_get_obj (sym)->size->X_add_number = 0;
4157 if (*input_line_pointer != ',')
4159 ++input_line_pointer;
4161 demand_empty_rest_of_line ();
4162 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4166 dot_template (template)
4169 CURR_SLOT.user_template = template;
4174 int dummy ATTRIBUTE_UNUSED;
4176 int ins, locs, outs, rots;
4178 if (is_it_end_of_statement ())
4179 ins = locs = outs = rots = 0;
4182 ins = get_absolute_expression ();
4183 if (*input_line_pointer++ != ',')
4185 locs = get_absolute_expression ();
4186 if (*input_line_pointer++ != ',')
4188 outs = get_absolute_expression ();
4189 if (*input_line_pointer++ != ',')
4191 rots = get_absolute_expression ();
4193 set_regstack (ins, locs, outs, rots);
4197 as_bad ("Comma expected");
4198 ignore_rest_of_line ();
4205 unsigned num_regs, num_alloced = 0;
4206 struct dynreg **drpp, *dr;
4207 int ch, base_reg = 0;
4213 case DYNREG_GR: base_reg = REG_GR + 32; break;
4214 case DYNREG_FR: base_reg = REG_FR + 32; break;
4215 case DYNREG_PR: base_reg = REG_P + 16; break;
4219 /* First, remove existing names from hash table. */
4220 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4222 hash_delete (md.dynreg_hash, dr->name);
4226 drpp = &md.dynreg[type];
4229 start = input_line_pointer;
4230 ch = get_symbol_end ();
4231 *input_line_pointer = ch;
4232 len = (input_line_pointer - start);
4235 if (*input_line_pointer != '[')
4237 as_bad ("Expected '['");
4240 ++input_line_pointer; /* skip '[' */
4242 num_regs = get_absolute_expression ();
4244 if (*input_line_pointer++ != ']')
4246 as_bad ("Expected ']'");
4251 num_alloced += num_regs;
4255 if (num_alloced > md.rot.num_regs)
4257 as_bad ("Used more than the declared %d rotating registers",
4263 if (num_alloced > 96)
4265 as_bad ("Used more than the available 96 rotating registers");
4270 if (num_alloced > 48)
4272 as_bad ("Used more than the available 48 rotating registers");
4281 name = obstack_alloc (¬es, len + 1);
4282 memcpy (name, start, len);
4287 *drpp = obstack_alloc (¬es, sizeof (*dr));
4288 memset (*drpp, 0, sizeof (*dr));
4293 dr->num_regs = num_regs;
4294 dr->base = base_reg;
4296 base_reg += num_regs;
4298 if (hash_insert (md.dynreg_hash, name, dr))
4300 as_bad ("Attempt to redefine register set `%s'", name);
4304 if (*input_line_pointer != ',')
4306 ++input_line_pointer; /* skip comma */
4309 demand_empty_rest_of_line ();
4313 ignore_rest_of_line ();
4317 dot_byteorder (byteorder)
4320 segment_info_type *seginfo = seg_info (now_seg);
4322 if (byteorder == -1)
4324 if (seginfo->tc_segment_info_data.endian == 0)
4325 seginfo->tc_segment_info_data.endian
4326 = TARGET_BYTES_BIG_ENDIAN ? 1 : 2;
4327 byteorder = seginfo->tc_segment_info_data.endian == 1;
4330 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4332 if (target_big_endian != byteorder)
4334 target_big_endian = byteorder;
4335 if (target_big_endian)
4337 ia64_number_to_chars = number_to_chars_bigendian;
4338 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4342 ia64_number_to_chars = number_to_chars_littleendian;
4343 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4350 int dummy ATTRIBUTE_UNUSED;
4357 option = input_line_pointer;
4358 ch = get_symbol_end ();
4359 if (strcmp (option, "lsb") == 0)
4360 md.flags &= ~EF_IA_64_BE;
4361 else if (strcmp (option, "msb") == 0)
4362 md.flags |= EF_IA_64_BE;
4363 else if (strcmp (option, "abi32") == 0)
4364 md.flags &= ~EF_IA_64_ABI64;
4365 else if (strcmp (option, "abi64") == 0)
4366 md.flags |= EF_IA_64_ABI64;
4368 as_bad ("Unknown psr option `%s'", option);
4369 *input_line_pointer = ch;
4372 if (*input_line_pointer != ',')
4375 ++input_line_pointer;
4378 demand_empty_rest_of_line ();
4383 int dummy ATTRIBUTE_UNUSED;
4385 as_bad (".alias not implemented yet");
4390 int dummy ATTRIBUTE_UNUSED;
4392 new_logical_line (0, get_absolute_expression ());
4393 demand_empty_rest_of_line ();
4397 parse_section_name ()
4403 if (*input_line_pointer != '"')
4405 as_bad ("Missing section name");
4406 ignore_rest_of_line ();
4409 name = demand_copy_C_string (&len);
4412 ignore_rest_of_line ();
4416 if (*input_line_pointer != ',')
4418 as_bad ("Comma expected after section name");
4419 ignore_rest_of_line ();
4422 ++input_line_pointer; /* skip comma */
4430 char *name = parse_section_name ();
4434 md.keep_pending_output = 1;
4437 obj_elf_previous (0);
4438 md.keep_pending_output = 0;
4441 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4444 stmt_float_cons (kind)
4465 ia64_do_align (alignment);
4473 int saved_auto_align = md.auto_align;
4477 md.auto_align = saved_auto_align;
4481 dot_xfloat_cons (kind)
4484 char *name = parse_section_name ();
4488 md.keep_pending_output = 1;
4490 stmt_float_cons (kind);
4491 obj_elf_previous (0);
4492 md.keep_pending_output = 0;
4496 dot_xstringer (zero)
4499 char *name = parse_section_name ();
4503 md.keep_pending_output = 1;
4506 obj_elf_previous (0);
4507 md.keep_pending_output = 0;
4514 int saved_auto_align = md.auto_align;
4515 char *name = parse_section_name ();
4519 md.keep_pending_output = 1;
4523 md.auto_align = saved_auto_align;
4524 obj_elf_previous (0);
4525 md.keep_pending_output = 0;
4529 dot_xfloat_cons_ua (kind)
4532 int saved_auto_align = md.auto_align;
4533 char *name = parse_section_name ();
4537 md.keep_pending_output = 1;
4540 stmt_float_cons (kind);
4541 md.auto_align = saved_auto_align;
4542 obj_elf_previous (0);
4543 md.keep_pending_output = 0;
4546 /* .reg.val <regname>,value */
4550 int dummy ATTRIBUTE_UNUSED;
4555 if (reg.X_op != O_register)
4557 as_bad (_("Register name expected"));
4558 ignore_rest_of_line ();
4560 else if (*input_line_pointer++ != ',')
4562 as_bad (_("Comma expected"));
4563 ignore_rest_of_line ();
4567 valueT value = get_absolute_expression ();
4568 int regno = reg.X_add_number;
4569 if (regno < REG_GR || regno > REG_GR + 128)
4570 as_warn (_("Register value annotation ignored"));
4573 gr_values[regno - REG_GR].known = 1;
4574 gr_values[regno - REG_GR].value = value;
4575 gr_values[regno - REG_GR].path = md.path;
4578 demand_empty_rest_of_line ();
4581 /* select dv checking mode
4586 A stop is inserted when changing modes
4593 if (md.manual_bundling)
4594 as_warn (_("Directive invalid within a bundle"));
4596 if (type == 'E' || type == 'A')
4597 md.mode_explicitly_set = 0;
4599 md.mode_explicitly_set = 1;
4606 if (md.explicit_mode)
4607 insn_group_break (1, 0, 0);
4608 md.explicit_mode = 0;
4612 if (!md.explicit_mode)
4613 insn_group_break (1, 0, 0);
4614 md.explicit_mode = 1;
4618 if (md.explicit_mode != md.default_explicit_mode)
4619 insn_group_break (1, 0, 0);
4620 md.explicit_mode = md.default_explicit_mode;
4621 md.mode_explicitly_set = 0;
4632 for (regno = 0; regno < 64; regno++)
4634 if (mask & ((valueT) 1 << regno))
4636 fprintf (stderr, "%s p%d", comma, regno);
4643 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4644 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4645 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4646 .pred.safe_across_calls p1 [, p2 [,...]]
4655 int p1 = -1, p2 = -1;
4659 if (*input_line_pointer != '"')
4661 as_bad (_("Missing predicate relation type"));
4662 ignore_rest_of_line ();
4668 char *form = demand_copy_C_string (&len);
4669 if (strcmp (form, "mutex") == 0)
4671 else if (strcmp (form, "clear") == 0)
4673 else if (strcmp (form, "imply") == 0)
4677 as_bad (_("Unrecognized predicate relation type"));
4678 ignore_rest_of_line ();
4682 if (*input_line_pointer == ',')
4683 ++input_line_pointer;
4693 if (TOUPPER (*input_line_pointer) != 'P'
4694 || (regno = atoi (++input_line_pointer)) < 0
4697 as_bad (_("Predicate register expected"));
4698 ignore_rest_of_line ();
4701 while (ISDIGIT (*input_line_pointer))
4702 ++input_line_pointer;
4709 as_warn (_("Duplicate predicate register ignored"));
4712 /* See if it's a range. */
4713 if (*input_line_pointer == '-')
4716 ++input_line_pointer;
4718 if (TOUPPER (*input_line_pointer) != 'P'
4719 || (regno = atoi (++input_line_pointer)) < 0
4722 as_bad (_("Predicate register expected"));
4723 ignore_rest_of_line ();
4726 while (ISDIGIT (*input_line_pointer))
4727 ++input_line_pointer;
4731 as_bad (_("Bad register range"));
4732 ignore_rest_of_line ();
4743 if (*input_line_pointer != ',')
4745 ++input_line_pointer;
4754 clear_qp_mutex (mask);
4755 clear_qp_implies (mask, (valueT) 0);
4758 if (count != 2 || p1 == -1 || p2 == -1)
4759 as_bad (_("Predicate source and target required"));
4760 else if (p1 == 0 || p2 == 0)
4761 as_bad (_("Use of p0 is not valid in this context"));
4763 add_qp_imply (p1, p2);
4768 as_bad (_("At least two PR arguments expected"));
4773 as_bad (_("Use of p0 is not valid in this context"));
4776 add_qp_mutex (mask);
4779 /* note that we don't override any existing relations */
4782 as_bad (_("At least one PR argument expected"));
4787 fprintf (stderr, "Safe across calls: ");
4788 print_prmask (mask);
4789 fprintf (stderr, "\n");
4791 qp_safe_across_calls = mask;
4794 demand_empty_rest_of_line ();
4797 /* .entry label [, label [, ...]]
4798 Hint to DV code that the given labels are to be considered entry points.
4799 Otherwise, only global labels are considered entry points. */
4803 int dummy ATTRIBUTE_UNUSED;
4812 name = input_line_pointer;
4813 c = get_symbol_end ();
4814 symbolP = symbol_find_or_make (name);
4816 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4818 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4821 *input_line_pointer = c;
4823 c = *input_line_pointer;
4826 input_line_pointer++;
4828 if (*input_line_pointer == '\n')
4834 demand_empty_rest_of_line ();
4837 /* .mem.offset offset, base
4838 "base" is used to distinguish between offsets from a different base. */
4841 dot_mem_offset (dummy)
4842 int dummy ATTRIBUTE_UNUSED;
4844 md.mem_offset.hint = 1;
4845 md.mem_offset.offset = get_absolute_expression ();
4846 if (*input_line_pointer != ',')
4848 as_bad (_("Comma expected"));
4849 ignore_rest_of_line ();
4852 ++input_line_pointer;
4853 md.mem_offset.base = get_absolute_expression ();
4854 demand_empty_rest_of_line ();
4857 /* ia64-specific pseudo-ops: */
4858 const pseudo_typeS md_pseudo_table[] =
4860 { "radix", dot_radix, 0 },
4861 { "lcomm", s_lcomm_bytes, 1 },
4862 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4863 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4864 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4865 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4866 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4867 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4868 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4869 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4870 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4871 { "proc", dot_proc, 0 },
4872 { "body", dot_body, 0 },
4873 { "prologue", dot_prologue, 0 },
4874 { "endp", dot_endp, 0 },
4875 { "file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0 },
4876 { "loc", dwarf2_directive_loc, 0 },
4878 { "fframe", dot_fframe, 0 },
4879 { "vframe", dot_vframe, 0 },
4880 { "vframesp", dot_vframesp, 0 },
4881 { "vframepsp", dot_vframepsp, 0 },
4882 { "save", dot_save, 0 },
4883 { "restore", dot_restore, 0 },
4884 { "restorereg", dot_restorereg, 0 },
4885 { "restorereg.p", dot_restorereg_p, 0 },
4886 { "handlerdata", dot_handlerdata, 0 },
4887 { "unwentry", dot_unwentry, 0 },
4888 { "altrp", dot_altrp, 0 },
4889 { "savesp", dot_savemem, 0 },
4890 { "savepsp", dot_savemem, 1 },
4891 { "save.g", dot_saveg, 0 },
4892 { "save.f", dot_savef, 0 },
4893 { "save.b", dot_saveb, 0 },
4894 { "save.gf", dot_savegf, 0 },
4895 { "spill", dot_spill, 0 },
4896 { "spillreg", dot_spillreg, 0 },
4897 { "spillsp", dot_spillmem, 0 },
4898 { "spillpsp", dot_spillmem, 1 },
4899 { "spillreg.p", dot_spillreg_p, 0 },
4900 { "spillsp.p", dot_spillmem_p, 0 },
4901 { "spillpsp.p", dot_spillmem_p, 1 },
4902 { "label_state", dot_label_state, 0 },
4903 { "copy_state", dot_copy_state, 0 },
4904 { "unwabi", dot_unwabi, 0 },
4905 { "personality", dot_personality, 0 },
4907 { "estate", dot_estate, 0 },
4909 { "mii", dot_template, 0x0 },
4910 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4911 { "mlx", dot_template, 0x2 },
4912 { "mmi", dot_template, 0x4 },
4913 { "mfi", dot_template, 0x6 },
4914 { "mmf", dot_template, 0x7 },
4915 { "mib", dot_template, 0x8 },
4916 { "mbb", dot_template, 0x9 },
4917 { "bbb", dot_template, 0xb },
4918 { "mmb", dot_template, 0xc },
4919 { "mfb", dot_template, 0xe },
4921 { "lb", dot_scope, 0 },
4922 { "le", dot_scope, 1 },
4924 { "align", s_align_bytes, 0 },
4925 { "regstk", dot_regstk, 0 },
4926 { "rotr", dot_rot, DYNREG_GR },
4927 { "rotf", dot_rot, DYNREG_FR },
4928 { "rotp", dot_rot, DYNREG_PR },
4929 { "lsb", dot_byteorder, 0 },
4930 { "msb", dot_byteorder, 1 },
4931 { "psr", dot_psr, 0 },
4932 { "alias", dot_alias, 0 },
4933 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4935 { "xdata1", dot_xdata, 1 },
4936 { "xdata2", dot_xdata, 2 },
4937 { "xdata4", dot_xdata, 4 },
4938 { "xdata8", dot_xdata, 8 },
4939 { "xreal4", dot_xfloat_cons, 'f' },
4940 { "xreal8", dot_xfloat_cons, 'd' },
4941 { "xreal10", dot_xfloat_cons, 'x' },
4942 { "xreal16", dot_xfloat_cons, 'X' },
4943 { "xstring", dot_xstringer, 0 },
4944 { "xstringz", dot_xstringer, 1 },
4946 /* unaligned versions: */
4947 { "xdata2.ua", dot_xdata_ua, 2 },
4948 { "xdata4.ua", dot_xdata_ua, 4 },
4949 { "xdata8.ua", dot_xdata_ua, 8 },
4950 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4951 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4952 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4953 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
4955 /* annotations/DV checking support */
4956 { "entry", dot_entry, 0 },
4957 { "mem.offset", dot_mem_offset, 0 },
4958 { "pred.rel", dot_pred_rel, 0 },
4959 { "pred.rel.clear", dot_pred_rel, 'c' },
4960 { "pred.rel.imply", dot_pred_rel, 'i' },
4961 { "pred.rel.mutex", dot_pred_rel, 'm' },
4962 { "pred.safe_across_calls", dot_pred_rel, 's' },
4963 { "reg.val", dot_reg_val, 0 },
4964 { "auto", dot_dv_mode, 'a' },
4965 { "explicit", dot_dv_mode, 'e' },
4966 { "default", dot_dv_mode, 'd' },
4968 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
4969 IA-64 aligns data allocation pseudo-ops by default, so we have to
4970 tell it that these ones are supposed to be unaligned. Long term,
4971 should rewrite so that only IA-64 specific data allocation pseudo-ops
4972 are aligned by default. */
4973 {"2byte", stmt_cons_ua, 2},
4974 {"4byte", stmt_cons_ua, 4},
4975 {"8byte", stmt_cons_ua, 8},
4980 static const struct pseudo_opcode
4983 void (*handler) (int);
4988 /* these are more like pseudo-ops, but don't start with a dot */
4989 { "data1", cons, 1 },
4990 { "data2", cons, 2 },
4991 { "data4", cons, 4 },
4992 { "data8", cons, 8 },
4993 { "data16", cons, 16 },
4994 { "real4", stmt_float_cons, 'f' },
4995 { "real8", stmt_float_cons, 'd' },
4996 { "real10", stmt_float_cons, 'x' },
4997 { "real16", stmt_float_cons, 'X' },
4998 { "string", stringer, 0 },
4999 { "stringz", stringer, 1 },
5001 /* unaligned versions: */
5002 { "data2.ua", stmt_cons_ua, 2 },
5003 { "data4.ua", stmt_cons_ua, 4 },
5004 { "data8.ua", stmt_cons_ua, 8 },
5005 { "data16.ua", stmt_cons_ua, 16 },
5006 { "real4.ua", float_cons, 'f' },
5007 { "real8.ua", float_cons, 'd' },
5008 { "real10.ua", float_cons, 'x' },
5009 { "real16.ua", float_cons, 'X' },
5012 /* Declare a register by creating a symbol for it and entering it in
5013 the symbol table. */
5016 declare_register (name, regnum)
5023 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5025 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5027 as_fatal ("Inserting \"%s\" into register table failed: %s",
5034 declare_register_set (prefix, num_regs, base_regnum)
5042 for (i = 0; i < num_regs; ++i)
5044 sprintf (name, "%s%u", prefix, i);
5045 declare_register (name, base_regnum + i);
5050 operand_width (opnd)
5051 enum ia64_opnd opnd;
5053 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5054 unsigned int bits = 0;
5058 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5059 bits += odesc->field[i].bits;
5064 static enum operand_match_result
5065 operand_match (idesc, index, e)
5066 const struct ia64_opcode *idesc;
5070 enum ia64_opnd opnd = idesc->operands[index];
5071 int bits, relocatable = 0;
5072 struct insn_fix *fix;
5079 case IA64_OPND_AR_CCV:
5080 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5081 return OPERAND_MATCH;
5084 case IA64_OPND_AR_CSD:
5085 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5086 return OPERAND_MATCH;
5089 case IA64_OPND_AR_PFS:
5090 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5091 return OPERAND_MATCH;
5095 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5096 return OPERAND_MATCH;
5100 if (e->X_op == O_register && e->X_add_number == REG_IP)
5101 return OPERAND_MATCH;
5105 if (e->X_op == O_register && e->X_add_number == REG_PR)
5106 return OPERAND_MATCH;
5109 case IA64_OPND_PR_ROT:
5110 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5111 return OPERAND_MATCH;
5115 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5116 return OPERAND_MATCH;
5119 case IA64_OPND_PSR_L:
5120 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5121 return OPERAND_MATCH;
5124 case IA64_OPND_PSR_UM:
5125 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5126 return OPERAND_MATCH;
5130 if (e->X_op == O_constant)
5132 if (e->X_add_number == 1)
5133 return OPERAND_MATCH;
5135 return OPERAND_OUT_OF_RANGE;
5140 if (e->X_op == O_constant)
5142 if (e->X_add_number == 8)
5143 return OPERAND_MATCH;
5145 return OPERAND_OUT_OF_RANGE;
5150 if (e->X_op == O_constant)
5152 if (e->X_add_number == 16)
5153 return OPERAND_MATCH;
5155 return OPERAND_OUT_OF_RANGE;
5159 /* register operands: */
5162 if (e->X_op == O_register && e->X_add_number >= REG_AR
5163 && e->X_add_number < REG_AR + 128)
5164 return OPERAND_MATCH;
5169 if (e->X_op == O_register && e->X_add_number >= REG_BR
5170 && e->X_add_number < REG_BR + 8)
5171 return OPERAND_MATCH;
5175 if (e->X_op == O_register && e->X_add_number >= REG_CR
5176 && e->X_add_number < REG_CR + 128)
5177 return OPERAND_MATCH;
5184 if (e->X_op == O_register && e->X_add_number >= REG_FR
5185 && e->X_add_number < REG_FR + 128)
5186 return OPERAND_MATCH;
5191 if (e->X_op == O_register && e->X_add_number >= REG_P
5192 && e->X_add_number < REG_P + 64)
5193 return OPERAND_MATCH;
5199 if (e->X_op == O_register && e->X_add_number >= REG_GR
5200 && e->X_add_number < REG_GR + 128)
5201 return OPERAND_MATCH;
5204 case IA64_OPND_R3_2:
5205 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5207 if (e->X_add_number < REG_GR + 4)
5208 return OPERAND_MATCH;
5209 else if (e->X_add_number < REG_GR + 128)
5210 return OPERAND_OUT_OF_RANGE;
5214 /* indirect operands: */
5215 case IA64_OPND_CPUID_R3:
5216 case IA64_OPND_DBR_R3:
5217 case IA64_OPND_DTR_R3:
5218 case IA64_OPND_ITR_R3:
5219 case IA64_OPND_IBR_R3:
5220 case IA64_OPND_MSR_R3:
5221 case IA64_OPND_PKR_R3:
5222 case IA64_OPND_PMC_R3:
5223 case IA64_OPND_PMD_R3:
5224 case IA64_OPND_RR_R3:
5225 if (e->X_op == O_index && e->X_op_symbol
5226 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5227 == opnd - IA64_OPND_CPUID_R3))
5228 return OPERAND_MATCH;
5232 if (e->X_op == O_index && !e->X_op_symbol)
5233 return OPERAND_MATCH;
5236 /* immediate operands: */
5237 case IA64_OPND_CNT2a:
5238 case IA64_OPND_LEN4:
5239 case IA64_OPND_LEN6:
5240 bits = operand_width (idesc->operands[index]);
5241 if (e->X_op == O_constant)
5243 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5244 return OPERAND_MATCH;
5246 return OPERAND_OUT_OF_RANGE;
5250 case IA64_OPND_CNT2b:
5251 if (e->X_op == O_constant)
5253 if ((bfd_vma) (e->X_add_number - 1) < 3)
5254 return OPERAND_MATCH;
5256 return OPERAND_OUT_OF_RANGE;
5260 case IA64_OPND_CNT2c:
5261 val = e->X_add_number;
5262 if (e->X_op == O_constant)
5264 if ((val == 0 || val == 7 || val == 15 || val == 16))
5265 return OPERAND_MATCH;
5267 return OPERAND_OUT_OF_RANGE;
5272 /* SOR must be an integer multiple of 8 */
5273 if (e->X_op == O_constant && e->X_add_number & 0x7)
5274 return OPERAND_OUT_OF_RANGE;
5277 if (e->X_op == O_constant)
5279 if ((bfd_vma) e->X_add_number <= 96)
5280 return OPERAND_MATCH;
5282 return OPERAND_OUT_OF_RANGE;
5286 case IA64_OPND_IMMU62:
5287 if (e->X_op == O_constant)
5289 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5290 return OPERAND_MATCH;
5292 return OPERAND_OUT_OF_RANGE;
5296 /* FIXME -- need 62-bit relocation type */
5297 as_bad (_("62-bit relocation not yet implemented"));
5301 case IA64_OPND_IMMU64:
5302 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5303 || e->X_op == O_subtract)
5305 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5306 fix->code = BFD_RELOC_IA64_IMM64;
5307 if (e->X_op != O_subtract)
5309 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5310 if (e->X_op == O_pseudo_fixup)
5314 fix->opnd = idesc->operands[index];
5317 ++CURR_SLOT.num_fixups;
5318 return OPERAND_MATCH;
5320 else if (e->X_op == O_constant)
5321 return OPERAND_MATCH;
5324 case IA64_OPND_CCNT5:
5325 case IA64_OPND_CNT5:
5326 case IA64_OPND_CNT6:
5327 case IA64_OPND_CPOS6a:
5328 case IA64_OPND_CPOS6b:
5329 case IA64_OPND_CPOS6c:
5330 case IA64_OPND_IMMU2:
5331 case IA64_OPND_IMMU7a:
5332 case IA64_OPND_IMMU7b:
5333 case IA64_OPND_IMMU21:
5334 case IA64_OPND_IMMU24:
5335 case IA64_OPND_MBTYPE4:
5336 case IA64_OPND_MHTYPE8:
5337 case IA64_OPND_POS6:
5338 bits = operand_width (idesc->operands[index]);
5339 if (e->X_op == O_constant)
5341 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5342 return OPERAND_MATCH;
5344 return OPERAND_OUT_OF_RANGE;
5348 case IA64_OPND_IMMU9:
5349 bits = operand_width (idesc->operands[index]);
5350 if (e->X_op == O_constant)
5352 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5354 int lobits = e->X_add_number & 0x3;
5355 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5356 e->X_add_number |= (bfd_vma) 0x3;
5357 return OPERAND_MATCH;
5360 return OPERAND_OUT_OF_RANGE;
5364 case IA64_OPND_IMM44:
5365 /* least 16 bits must be zero */
5366 if ((e->X_add_number & 0xffff) != 0)
5367 /* XXX technically, this is wrong: we should not be issuing warning
5368 messages until we're sure this instruction pattern is going to
5370 as_warn (_("lower 16 bits of mask ignored"));
5372 if (e->X_op == O_constant)
5374 if (((e->X_add_number >= 0
5375 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5376 || (e->X_add_number < 0
5377 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5380 if (e->X_add_number >= 0
5381 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5383 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5385 return OPERAND_MATCH;
5388 return OPERAND_OUT_OF_RANGE;
5392 case IA64_OPND_IMM17:
5393 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5394 if (e->X_op == O_constant)
5396 if (((e->X_add_number >= 0
5397 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5398 || (e->X_add_number < 0
5399 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5402 if (e->X_add_number >= 0
5403 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5405 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5407 return OPERAND_MATCH;
5410 return OPERAND_OUT_OF_RANGE;
5414 case IA64_OPND_IMM14:
5415 case IA64_OPND_IMM22:
5417 case IA64_OPND_IMM1:
5418 case IA64_OPND_IMM8:
5419 case IA64_OPND_IMM8U4:
5420 case IA64_OPND_IMM8M1:
5421 case IA64_OPND_IMM8M1U4:
5422 case IA64_OPND_IMM8M1U8:
5423 case IA64_OPND_IMM9a:
5424 case IA64_OPND_IMM9b:
5425 bits = operand_width (idesc->operands[index]);
5426 if (relocatable && (e->X_op == O_symbol
5427 || e->X_op == O_subtract
5428 || e->X_op == O_pseudo_fixup))
5430 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5432 if (idesc->operands[index] == IA64_OPND_IMM14)
5433 fix->code = BFD_RELOC_IA64_IMM14;
5435 fix->code = BFD_RELOC_IA64_IMM22;
5437 if (e->X_op != O_subtract)
5439 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5440 if (e->X_op == O_pseudo_fixup)
5444 fix->opnd = idesc->operands[index];
5447 ++CURR_SLOT.num_fixups;
5448 return OPERAND_MATCH;
5450 else if (e->X_op != O_constant
5451 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5452 return OPERAND_MISMATCH;
5454 if (opnd == IA64_OPND_IMM8M1U4)
5456 /* Zero is not valid for unsigned compares that take an adjusted
5457 constant immediate range. */
5458 if (e->X_add_number == 0)
5459 return OPERAND_OUT_OF_RANGE;
5461 /* Sign-extend 32-bit unsigned numbers, so that the following range
5462 checks will work. */
5463 val = e->X_add_number;
5464 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5465 && ((val & ((bfd_vma) 1 << 31)) != 0))
5466 val = ((val << 32) >> 32);
5468 /* Check for 0x100000000. This is valid because
5469 0x100000000-1 is the same as ((uint32_t) -1). */
5470 if (val == ((bfd_signed_vma) 1 << 32))
5471 return OPERAND_MATCH;
5475 else if (opnd == IA64_OPND_IMM8M1U8)
5477 /* Zero is not valid for unsigned compares that take an adjusted
5478 constant immediate range. */
5479 if (e->X_add_number == 0)
5480 return OPERAND_OUT_OF_RANGE;
5482 /* Check for 0x10000000000000000. */
5483 if (e->X_op == O_big)
5485 if (generic_bignum[0] == 0
5486 && generic_bignum[1] == 0
5487 && generic_bignum[2] == 0
5488 && generic_bignum[3] == 0
5489 && generic_bignum[4] == 1)
5490 return OPERAND_MATCH;
5492 return OPERAND_OUT_OF_RANGE;
5495 val = e->X_add_number - 1;
5497 else if (opnd == IA64_OPND_IMM8M1)
5498 val = e->X_add_number - 1;
5499 else if (opnd == IA64_OPND_IMM8U4)
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);
5509 val = e->X_add_number;
5511 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5512 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5513 return OPERAND_MATCH;
5515 return OPERAND_OUT_OF_RANGE;
5517 case IA64_OPND_INC3:
5518 /* +/- 1, 4, 8, 16 */
5519 val = e->X_add_number;
5522 if (e->X_op == O_constant)
5524 if ((val == 1 || val == 4 || val == 8 || val == 16))
5525 return OPERAND_MATCH;
5527 return OPERAND_OUT_OF_RANGE;
5531 case IA64_OPND_TGT25:
5532 case IA64_OPND_TGT25b:
5533 case IA64_OPND_TGT25c:
5534 case IA64_OPND_TGT64:
5535 if (e->X_op == O_symbol)
5537 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5538 if (opnd == IA64_OPND_TGT25)
5539 fix->code = BFD_RELOC_IA64_PCREL21F;
5540 else if (opnd == IA64_OPND_TGT25b)
5541 fix->code = BFD_RELOC_IA64_PCREL21M;
5542 else if (opnd == IA64_OPND_TGT25c)
5543 fix->code = BFD_RELOC_IA64_PCREL21B;
5544 else if (opnd == IA64_OPND_TGT64)
5545 fix->code = BFD_RELOC_IA64_PCREL60B;
5549 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5550 fix->opnd = idesc->operands[index];
5553 ++CURR_SLOT.num_fixups;
5554 return OPERAND_MATCH;
5556 case IA64_OPND_TAG13:
5557 case IA64_OPND_TAG13b:
5561 return OPERAND_MATCH;
5564 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5565 /* There are no external relocs for TAG13/TAG13b fields, so we
5566 create a dummy reloc. This will not live past md_apply_fix3. */
5567 fix->code = BFD_RELOC_UNUSED;
5568 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5569 fix->opnd = idesc->operands[index];
5572 ++CURR_SLOT.num_fixups;
5573 return OPERAND_MATCH;
5580 case IA64_OPND_LDXMOV:
5581 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5582 fix->code = BFD_RELOC_IA64_LDXMOV;
5583 fix->opnd = idesc->operands[index];
5586 ++CURR_SLOT.num_fixups;
5587 return OPERAND_MATCH;
5592 return OPERAND_MISMATCH;
5601 memset (e, 0, sizeof (*e));
5604 if (*input_line_pointer != '}')
5606 sep = *input_line_pointer++;
5610 if (!md.manual_bundling)
5611 as_warn ("Found '}' when manual bundling is off");
5613 CURR_SLOT.manual_bundling_off = 1;
5614 md.manual_bundling = 0;
5620 /* Returns the next entry in the opcode table that matches the one in
5621 IDESC, and frees the entry in IDESC. If no matching entry is
5622 found, NULL is returned instead. */
5624 static struct ia64_opcode *
5625 get_next_opcode (struct ia64_opcode *idesc)
5627 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5628 ia64_free_opcode (idesc);
5632 /* Parse the operands for the opcode and find the opcode variant that
5633 matches the specified operands, or NULL if no match is possible. */
5635 static struct ia64_opcode *
5636 parse_operands (idesc)
5637 struct ia64_opcode *idesc;
5639 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5640 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5641 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5642 enum operand_match_result result;
5644 char *first_arg = 0, *end, *saved_input_pointer;
5647 assert (strlen (idesc->name) <= 128);
5649 strcpy (mnemonic, idesc->name);
5650 if (idesc->operands[2] == IA64_OPND_SOF)
5652 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5653 can't parse the first operand until we have parsed the
5654 remaining operands of the "alloc" instruction. */
5656 first_arg = input_line_pointer;
5657 end = strchr (input_line_pointer, '=');
5660 as_bad ("Expected separator `='");
5663 input_line_pointer = end + 1;
5668 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5670 sep = parse_operand (CURR_SLOT.opnd + i);
5671 if (CURR_SLOT.opnd[i].X_op == O_absent)
5676 if (sep != '=' && sep != ',')
5681 if (num_outputs > 0)
5682 as_bad ("Duplicate equal sign (=) in instruction");
5684 num_outputs = i + 1;
5689 as_bad ("Illegal operand separator `%c'", sep);
5693 if (idesc->operands[2] == IA64_OPND_SOF)
5695 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5696 know (strcmp (idesc->name, "alloc") == 0);
5697 if (num_operands == 5 /* first_arg not included in this count! */
5698 && CURR_SLOT.opnd[2].X_op == O_constant
5699 && CURR_SLOT.opnd[3].X_op == O_constant
5700 && CURR_SLOT.opnd[4].X_op == O_constant
5701 && CURR_SLOT.opnd[5].X_op == O_constant)
5703 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5704 CURR_SLOT.opnd[3].X_add_number,
5705 CURR_SLOT.opnd[4].X_add_number,
5706 CURR_SLOT.opnd[5].X_add_number);
5708 /* now we can parse the first arg: */
5709 saved_input_pointer = input_line_pointer;
5710 input_line_pointer = first_arg;
5711 sep = parse_operand (CURR_SLOT.opnd + 0);
5713 --num_outputs; /* force error */
5714 input_line_pointer = saved_input_pointer;
5716 CURR_SLOT.opnd[2].X_add_number = sof;
5717 CURR_SLOT.opnd[3].X_add_number
5718 = sof - CURR_SLOT.opnd[4].X_add_number;
5719 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5723 highest_unmatched_operand = 0;
5724 curr_out_of_range_pos = -1;
5726 expected_operand = idesc->operands[0];
5727 for (; idesc; idesc = get_next_opcode (idesc))
5729 if (num_outputs != idesc->num_outputs)
5730 continue; /* mismatch in # of outputs */
5732 CURR_SLOT.num_fixups = 0;
5734 /* Try to match all operands. If we see an out-of-range operand,
5735 then continue trying to match the rest of the operands, since if
5736 the rest match, then this idesc will give the best error message. */
5738 out_of_range_pos = -1;
5739 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5741 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5742 if (result != OPERAND_MATCH)
5744 if (result != OPERAND_OUT_OF_RANGE)
5746 if (out_of_range_pos < 0)
5747 /* remember position of the first out-of-range operand: */
5748 out_of_range_pos = i;
5752 /* If we did not match all operands, or if at least one operand was
5753 out-of-range, then this idesc does not match. Keep track of which
5754 idesc matched the most operands before failing. If we have two
5755 idescs that failed at the same position, and one had an out-of-range
5756 operand, then prefer the out-of-range operand. Thus if we have
5757 "add r0=0x1000000,r1" we get an error saying the constant is out
5758 of range instead of an error saying that the constant should have been
5761 if (i != num_operands || out_of_range_pos >= 0)
5763 if (i > highest_unmatched_operand
5764 || (i == highest_unmatched_operand
5765 && out_of_range_pos > curr_out_of_range_pos))
5767 highest_unmatched_operand = i;
5768 if (out_of_range_pos >= 0)
5770 expected_operand = idesc->operands[out_of_range_pos];
5771 error_pos = out_of_range_pos;
5775 expected_operand = idesc->operands[i];
5778 curr_out_of_range_pos = out_of_range_pos;
5783 if (num_operands < NELEMS (idesc->operands)
5784 && idesc->operands[num_operands])
5785 continue; /* mismatch in number of arguments */
5791 if (expected_operand)
5792 as_bad ("Operand %u of `%s' should be %s",
5793 error_pos + 1, mnemonic,
5794 elf64_ia64_operands[expected_operand].desc);
5796 as_bad ("Operand mismatch");
5802 /* Keep track of state necessary to determine whether a NOP is necessary
5803 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5804 detect a case where additional NOPs may be necessary. */
5806 errata_nop_necessary_p (slot, insn_unit)
5808 enum ia64_unit insn_unit;
5811 struct group *this_group = md.last_groups + md.group_idx;
5812 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5813 struct ia64_opcode *idesc = slot->idesc;
5815 /* Test whether this could be the first insn in a problematic sequence. */
5816 if (insn_unit == IA64_UNIT_F)
5818 for (i = 0; i < idesc->num_outputs; i++)
5819 if (idesc->operands[i] == IA64_OPND_P1
5820 || idesc->operands[i] == IA64_OPND_P2)
5822 int regno = slot->opnd[i].X_add_number - REG_P;
5823 /* Ignore invalid operands; they generate errors elsewhere. */
5826 this_group->p_reg_set[regno] = 1;
5830 /* Test whether this could be the second insn in a problematic sequence. */
5831 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5832 && prev_group->p_reg_set[slot->qp_regno])
5834 for (i = 0; i < idesc->num_outputs; i++)
5835 if (idesc->operands[i] == IA64_OPND_R1
5836 || idesc->operands[i] == IA64_OPND_R2
5837 || idesc->operands[i] == IA64_OPND_R3)
5839 int regno = slot->opnd[i].X_add_number - REG_GR;
5840 /* Ignore invalid operands; they generate errors elsewhere. */
5843 if (strncmp (idesc->name, "add", 3) != 0
5844 && strncmp (idesc->name, "sub", 3) != 0
5845 && strncmp (idesc->name, "shladd", 6) != 0
5846 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5847 this_group->g_reg_set_conditionally[regno] = 1;
5851 /* Test whether this could be the third insn in a problematic sequence. */
5852 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5854 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5855 idesc->operands[i] == IA64_OPND_R3
5856 /* For mov indirect. */
5857 || idesc->operands[i] == IA64_OPND_RR_R3
5858 || idesc->operands[i] == IA64_OPND_DBR_R3
5859 || idesc->operands[i] == IA64_OPND_IBR_R3
5860 || idesc->operands[i] == IA64_OPND_PKR_R3
5861 || idesc->operands[i] == IA64_OPND_PMC_R3
5862 || idesc->operands[i] == IA64_OPND_PMD_R3
5863 || idesc->operands[i] == IA64_OPND_MSR_R3
5864 || idesc->operands[i] == IA64_OPND_CPUID_R3
5866 || idesc->operands[i] == IA64_OPND_ITR_R3
5867 || idesc->operands[i] == IA64_OPND_DTR_R3
5868 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5869 || idesc->operands[i] == IA64_OPND_MR3)
5871 int regno = slot->opnd[i].X_add_number - REG_GR;
5872 /* Ignore invalid operands; they generate errors elsewhere. */
5875 if (idesc->operands[i] == IA64_OPND_R3)
5877 if (strcmp (idesc->name, "fc") != 0
5878 && strcmp (idesc->name, "tak") != 0
5879 && strcmp (idesc->name, "thash") != 0
5880 && strcmp (idesc->name, "tpa") != 0
5881 && strcmp (idesc->name, "ttag") != 0
5882 && strncmp (idesc->name, "ptr", 3) != 0
5883 && strncmp (idesc->name, "ptc", 3) != 0
5884 && strncmp (idesc->name, "probe", 5) != 0)
5887 if (prev_group->g_reg_set_conditionally[regno])
5895 build_insn (slot, insnp)
5899 const struct ia64_operand *odesc, *o2desc;
5900 struct ia64_opcode *idesc = slot->idesc;
5901 bfd_signed_vma insn, val;
5905 insn = idesc->opcode | slot->qp_regno;
5907 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5909 if (slot->opnd[i].X_op == O_register
5910 || slot->opnd[i].X_op == O_constant
5911 || slot->opnd[i].X_op == O_index)
5912 val = slot->opnd[i].X_add_number;
5913 else if (slot->opnd[i].X_op == O_big)
5915 /* This must be the value 0x10000000000000000. */
5916 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5922 switch (idesc->operands[i])
5924 case IA64_OPND_IMMU64:
5925 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5926 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5927 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5928 | (((val >> 63) & 0x1) << 36));
5931 case IA64_OPND_IMMU62:
5932 val &= 0x3fffffffffffffffULL;
5933 if (val != slot->opnd[i].X_add_number)
5934 as_warn (_("Value truncated to 62 bits"));
5935 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5936 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5939 case IA64_OPND_TGT64:
5941 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5942 insn |= ((((val >> 59) & 0x1) << 36)
5943 | (((val >> 0) & 0xfffff) << 13));
5974 case IA64_OPND_R3_2:
5975 case IA64_OPND_CPUID_R3:
5976 case IA64_OPND_DBR_R3:
5977 case IA64_OPND_DTR_R3:
5978 case IA64_OPND_ITR_R3:
5979 case IA64_OPND_IBR_R3:
5981 case IA64_OPND_MSR_R3:
5982 case IA64_OPND_PKR_R3:
5983 case IA64_OPND_PMC_R3:
5984 case IA64_OPND_PMD_R3:
5985 case IA64_OPND_RR_R3:
5993 odesc = elf64_ia64_operands + idesc->operands[i];
5994 err = (*odesc->insert) (odesc, val, &insn);
5996 as_bad_where (slot->src_file, slot->src_line,
5997 "Bad operand value: %s", err);
5998 if (idesc->flags & IA64_OPCODE_PSEUDO)
6000 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6001 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6003 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6004 (*o2desc->insert) (o2desc, val, &insn);
6006 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6007 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6008 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6010 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6011 (*o2desc->insert) (o2desc, 64 - val, &insn);
6021 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
6022 unsigned int manual_bundling = 0;
6023 enum ia64_unit required_unit, insn_unit = 0;
6024 enum ia64_insn_type type[3], insn_type;
6025 unsigned int template, orig_template;
6026 bfd_vma insn[3] = { -1, -1, -1 };
6027 struct ia64_opcode *idesc;
6028 int end_of_insn_group = 0, user_template = -1;
6029 int n, i, j, first, curr;
6031 bfd_vma t0 = 0, t1 = 0;
6032 struct label_fix *lfix;
6033 struct insn_fix *ifix;
6038 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6039 know (first >= 0 & first < NUM_SLOTS);
6040 n = MIN (3, md.num_slots_in_use);
6042 /* Determine template: user user_template if specified, best match
6045 if (md.slot[first].user_template >= 0)
6046 user_template = template = md.slot[first].user_template;
6049 /* Auto select appropriate template. */
6050 memset (type, 0, sizeof (type));
6052 for (i = 0; i < n; ++i)
6054 if (md.slot[curr].label_fixups && i != 0)
6056 type[i] = md.slot[curr].idesc->type;
6057 curr = (curr + 1) % NUM_SLOTS;
6059 template = best_template[type[0]][type[1]][type[2]];
6062 /* initialize instructions with appropriate nops: */
6063 for (i = 0; i < 3; ++i)
6064 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6068 /* now fill in slots with as many insns as possible: */
6070 idesc = md.slot[curr].idesc;
6071 end_of_insn_group = 0;
6072 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6074 /* Set the slot number for prologue/body records now as those
6075 refer to the current point, not the point after the
6076 instruction has been issued: */
6077 /* Don't try to delete prologue/body records here, as that will cause
6078 them to also be deleted from the master list of unwind records. */
6079 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6080 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6081 || ptr->r.type == body)
6083 ptr->slot_number = (unsigned long) f + i;
6084 ptr->slot_frag = frag_now;
6087 if (idesc->flags & IA64_OPCODE_SLOT2)
6089 if (manual_bundling && i != 2)
6090 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6091 "`%s' must be last in bundle", idesc->name);
6095 if (idesc->flags & IA64_OPCODE_LAST)
6098 unsigned int required_template;
6100 /* If we need a stop bit after an M slot, our only choice is
6101 template 5 (M;;MI). If we need a stop bit after a B
6102 slot, our only choice is to place it at the end of the
6103 bundle, because the only available templates are MIB,
6104 MBB, BBB, MMB, and MFB. We don't handle anything other
6105 than M and B slots because these are the only kind of
6106 instructions that can have the IA64_OPCODE_LAST bit set. */
6107 required_template = template;
6108 switch (idesc->type)
6112 required_template = 5;
6120 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6121 "Internal error: don't know how to force %s to end"
6122 "of instruction group", idesc->name);
6126 if (manual_bundling && i != required_slot)
6127 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6128 "`%s' must be last in instruction group",
6130 if (required_slot < i)
6131 /* Can't fit this instruction. */
6135 if (required_template != template)
6137 /* If we switch the template, we need to reset the NOPs
6138 after slot i. The slot-types of the instructions ahead
6139 of i never change, so we don't need to worry about
6140 changing NOPs in front of this slot. */
6141 for (j = i; j < 3; ++j)
6142 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6144 template = required_template;
6146 if (curr != first && md.slot[curr].label_fixups)
6148 if (manual_bundling_on)
6149 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6150 "Label must be first in a bundle");
6151 /* This insn must go into the first slot of a bundle. */
6155 manual_bundling_on = md.slot[curr].manual_bundling_on;
6156 manual_bundling_off = md.slot[curr].manual_bundling_off;
6158 if (manual_bundling_on)
6161 manual_bundling = 1;
6163 break; /* need to start a new bundle */
6166 if (end_of_insn_group && md.num_slots_in_use >= 1)
6168 /* We need an instruction group boundary in the middle of a
6169 bundle. See if we can switch to an other template with
6170 an appropriate boundary. */
6172 orig_template = template;
6173 if (i == 1 && (user_template == 4
6174 || (user_template < 0
6175 && (ia64_templ_desc[template].exec_unit[0]
6179 end_of_insn_group = 0;
6181 else if (i == 2 && (user_template == 0
6182 || (user_template < 0
6183 && (ia64_templ_desc[template].exec_unit[1]
6185 /* This test makes sure we don't switch the template if
6186 the next instruction is one that needs to be first in
6187 an instruction group. Since all those instructions are
6188 in the M group, there is no way such an instruction can
6189 fit in this bundle even if we switch the template. The
6190 reason we have to check for this is that otherwise we
6191 may end up generating "MI;;I M.." which has the deadly
6192 effect that the second M instruction is no longer the
6193 first in the bundle! --davidm 99/12/16 */
6194 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6197 end_of_insn_group = 0;
6199 else if (curr != first)
6200 /* can't fit this insn */
6203 if (template != orig_template)
6204 /* if we switch the template, we need to reset the NOPs
6205 after slot i. The slot-types of the instructions ahead
6206 of i never change, so we don't need to worry about
6207 changing NOPs in front of this slot. */
6208 for (j = i; j < 3; ++j)
6209 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6211 required_unit = ia64_templ_desc[template].exec_unit[i];
6213 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6214 if (idesc->type == IA64_TYPE_DYN)
6216 if ((strcmp (idesc->name, "nop") == 0)
6217 || (strcmp (idesc->name, "hint") == 0)
6218 || (strcmp (idesc->name, "break") == 0))
6219 insn_unit = required_unit;
6220 else if (strcmp (idesc->name, "chk.s") == 0)
6222 insn_unit = IA64_UNIT_M;
6223 if (required_unit == IA64_UNIT_I)
6224 insn_unit = IA64_UNIT_I;
6227 as_fatal ("emit_one_bundle: unexpected dynamic op");
6229 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6230 ia64_free_opcode (idesc);
6231 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6233 know (!idesc->next); /* no resolved dynamic ops have collisions */
6238 insn_type = idesc->type;
6239 insn_unit = IA64_UNIT_NIL;
6243 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6244 insn_unit = required_unit;
6246 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6247 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6248 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6249 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6250 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6255 if (insn_unit != required_unit)
6257 if (required_unit == IA64_UNIT_L
6258 && insn_unit == IA64_UNIT_I
6259 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6261 /* we got ourselves an MLX template but the current
6262 instruction isn't an X-unit, or an I-unit instruction
6263 that can go into the X slot of an MLX template. Duh. */
6264 if (md.num_slots_in_use >= NUM_SLOTS)
6266 as_bad_where (md.slot[curr].src_file,
6267 md.slot[curr].src_line,
6268 "`%s' can't go in X slot of "
6269 "MLX template", idesc->name);
6270 /* drop this insn so we don't livelock: */
6271 --md.num_slots_in_use;
6275 continue; /* try next slot */
6281 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6282 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6285 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6286 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6288 build_insn (md.slot + curr, insn + i);
6290 /* Set slot counts for non prologue/body unwind records. */
6291 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6292 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
6293 && ptr->r.type != body)
6295 ptr->slot_number = (unsigned long) f + i;
6296 ptr->slot_frag = frag_now;
6298 md.slot[curr].unwind_record = NULL;
6300 if (required_unit == IA64_UNIT_L)
6303 /* skip one slot for long/X-unit instructions */
6306 --md.num_slots_in_use;
6308 /* now is a good time to fix up the labels for this insn: */
6309 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6311 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6312 symbol_set_frag (lfix->sym, frag_now);
6314 /* and fix up the tags also. */
6315 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6317 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6318 symbol_set_frag (lfix->sym, frag_now);
6321 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6323 ifix = md.slot[curr].fixup + j;
6324 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6325 &ifix->expr, ifix->is_pcrel, ifix->code);
6326 fix->tc_fix_data.opnd = ifix->opnd;
6327 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6328 fix->fx_file = md.slot[curr].src_file;
6329 fix->fx_line = md.slot[curr].src_line;
6332 end_of_insn_group = md.slot[curr].end_of_insn_group;
6334 if (end_of_insn_group)
6336 md.group_idx = (md.group_idx + 1) % 3;
6337 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6341 ia64_free_opcode (md.slot[curr].idesc);
6342 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6343 md.slot[curr].user_template = -1;
6345 if (manual_bundling_off)
6347 manual_bundling = 0;
6350 curr = (curr + 1) % NUM_SLOTS;
6351 idesc = md.slot[curr].idesc;
6353 if (manual_bundling)
6355 if (md.num_slots_in_use > 0)
6356 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6357 "`%s' does not fit into %s template",
6358 idesc->name, ia64_templ_desc[template].name);
6360 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6361 "Missing '}' at end of file");
6363 know (md.num_slots_in_use < NUM_SLOTS);
6365 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6366 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6368 number_to_chars_littleendian (f + 0, t0, 8);
6369 number_to_chars_littleendian (f + 8, t1, 8);
6371 unwind.next_slot_number = (unsigned long) f + 16;
6372 unwind.next_slot_frag = frag_now;
6376 md_parse_option (c, arg)
6383 /* Switches from the Intel assembler. */
6385 if (strcmp (arg, "ilp64") == 0
6386 || strcmp (arg, "lp64") == 0
6387 || strcmp (arg, "p64") == 0)
6389 md.flags |= EF_IA_64_ABI64;
6391 else if (strcmp (arg, "ilp32") == 0)
6393 md.flags &= ~EF_IA_64_ABI64;
6395 else if (strcmp (arg, "le") == 0)
6397 md.flags &= ~EF_IA_64_BE;
6399 else if (strcmp (arg, "be") == 0)
6401 md.flags |= EF_IA_64_BE;
6408 if (strcmp (arg, "so") == 0)
6410 /* Suppress signon message. */
6412 else if (strcmp (arg, "pi") == 0)
6414 /* Reject privileged instructions. FIXME */
6416 else if (strcmp (arg, "us") == 0)
6418 /* Allow union of signed and unsigned range. FIXME */
6420 else if (strcmp (arg, "close_fcalls") == 0)
6422 /* Do not resolve global function calls. */
6429 /* temp[="prefix"] Insert temporary labels into the object file
6430 symbol table prefixed by "prefix".
6431 Default prefix is ":temp:".
6436 /* indirect=<tgt> Assume unannotated indirect branches behavior
6437 according to <tgt> --
6438 exit: branch out from the current context (default)
6439 labels: all labels in context may be branch targets
6441 if (strncmp (arg, "indirect=", 9) != 0)
6446 /* -X conflicts with an ignored option, use -x instead */
6448 if (!arg || strcmp (arg, "explicit") == 0)
6450 /* set default mode to explicit */
6451 md.default_explicit_mode = 1;
6454 else if (strcmp (arg, "auto") == 0)
6456 md.default_explicit_mode = 0;
6458 else if (strcmp (arg, "debug") == 0)
6462 else if (strcmp (arg, "debugx") == 0)
6464 md.default_explicit_mode = 1;
6469 as_bad (_("Unrecognized option '-x%s'"), arg);
6474 /* nops Print nops statistics. */
6477 /* GNU specific switches for gcc. */
6478 case OPTION_MCONSTANT_GP:
6479 md.flags |= EF_IA_64_CONS_GP;
6482 case OPTION_MAUTO_PIC:
6483 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6494 md_show_usage (stream)
6499 --mconstant-gp mark output file as using the constant-GP model\n\
6500 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6501 --mauto-pic mark output file as using the constant-GP model\n\
6502 without function descriptors (sets ELF header flag\n\
6503 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6504 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6505 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6506 -x | -xexplicit turn on dependency violation checking (default)\n\
6507 -xauto automagically remove dependency violations\n\
6508 -xdebug debug dependency violation checker\n"),
6513 ia64_after_parse_args ()
6515 if (debug_type == DEBUG_STABS)
6516 as_fatal (_("--gstabs is not supported for ia64"));
6519 /* Return true if TYPE fits in TEMPL at SLOT. */
6522 match (int templ, int type, int slot)
6524 enum ia64_unit unit;
6527 unit = ia64_templ_desc[templ].exec_unit[slot];
6530 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6532 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6534 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6535 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6536 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6537 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6538 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6539 default: result = 0; break;
6544 /* Add a bit of extra goodness if a nop of type F or B would fit
6545 in TEMPL at SLOT. */
6548 extra_goodness (int templ, int slot)
6550 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6552 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6557 /* This function is called once, at assembler startup time. It sets
6558 up all the tables, etc. that the MD part of the assembler will need
6559 that can be determined before arguments are parsed. */
6563 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6568 md.explicit_mode = md.default_explicit_mode;
6570 bfd_set_section_alignment (stdoutput, text_section, 4);
6572 /* Make sure fucntion pointers get initialized. */
6573 target_big_endian = -1;
6574 dot_byteorder (TARGET_BYTES_BIG_ENDIAN);
6576 pseudo_func[FUNC_DTP_MODULE].u.sym =
6577 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6578 &zero_address_frag);
6580 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6581 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6582 &zero_address_frag);
6584 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6585 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6586 &zero_address_frag);
6588 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6589 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6590 &zero_address_frag);
6592 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6593 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6594 &zero_address_frag);
6596 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6597 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6598 &zero_address_frag);
6600 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6601 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6602 &zero_address_frag);
6604 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6605 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6606 &zero_address_frag);
6608 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6609 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6610 &zero_address_frag);
6612 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6613 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6614 &zero_address_frag);
6616 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6617 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6618 &zero_address_frag);
6620 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6621 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6622 &zero_address_frag);
6624 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6625 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6626 &zero_address_frag);
6628 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6629 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6630 &zero_address_frag);
6632 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6633 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6634 &zero_address_frag);
6636 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6637 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6638 &zero_address_frag);
6640 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6641 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6642 &zero_address_frag);
6644 /* Compute the table of best templates. We compute goodness as a
6645 base 4 value, in which each match counts for 3, each F counts
6646 for 2, each B counts for 1. This should maximize the number of
6647 F and B nops in the chosen bundles, which is good because these
6648 pipelines are least likely to be overcommitted. */
6649 for (i = 0; i < IA64_NUM_TYPES; ++i)
6650 for (j = 0; j < IA64_NUM_TYPES; ++j)
6651 for (k = 0; k < IA64_NUM_TYPES; ++k)
6654 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6657 if (match (t, i, 0))
6659 if (match (t, j, 1))
6661 if (match (t, k, 2))
6662 goodness = 3 + 3 + 3;
6664 goodness = 3 + 3 + extra_goodness (t, 2);
6666 else if (match (t, j, 2))
6667 goodness = 3 + 3 + extra_goodness (t, 1);
6671 goodness += extra_goodness (t, 1);
6672 goodness += extra_goodness (t, 2);
6675 else if (match (t, i, 1))
6677 if (match (t, j, 2))
6680 goodness = 3 + extra_goodness (t, 2);
6682 else if (match (t, i, 2))
6683 goodness = 3 + extra_goodness (t, 1);
6685 if (goodness > best)
6688 best_template[i][j][k] = t;
6693 for (i = 0; i < NUM_SLOTS; ++i)
6694 md.slot[i].user_template = -1;
6696 md.pseudo_hash = hash_new ();
6697 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6699 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6700 (void *) (pseudo_opcode + i));
6702 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6703 pseudo_opcode[i].name, err);
6706 md.reg_hash = hash_new ();
6707 md.dynreg_hash = hash_new ();
6708 md.const_hash = hash_new ();
6709 md.entry_hash = hash_new ();
6711 /* general registers: */
6714 for (i = 0; i < total; ++i)
6716 sprintf (name, "r%d", i - REG_GR);
6717 md.regsym[i] = declare_register (name, i);
6720 /* floating point registers: */
6722 for (; i < total; ++i)
6724 sprintf (name, "f%d", i - REG_FR);
6725 md.regsym[i] = declare_register (name, i);
6728 /* application registers: */
6731 for (; i < total; ++i)
6733 sprintf (name, "ar%d", i - REG_AR);
6734 md.regsym[i] = declare_register (name, i);
6737 /* control registers: */
6740 for (; i < total; ++i)
6742 sprintf (name, "cr%d", i - REG_CR);
6743 md.regsym[i] = declare_register (name, i);
6746 /* predicate registers: */
6748 for (; i < total; ++i)
6750 sprintf (name, "p%d", i - REG_P);
6751 md.regsym[i] = declare_register (name, i);
6754 /* branch registers: */
6756 for (; i < total; ++i)
6758 sprintf (name, "b%d", i - REG_BR);
6759 md.regsym[i] = declare_register (name, i);
6762 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6763 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6764 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6765 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6766 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6767 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6768 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6770 for (i = 0; i < NELEMS (indirect_reg); ++i)
6772 regnum = indirect_reg[i].regnum;
6773 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6776 /* define synonyms for application registers: */
6777 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6778 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6779 REG_AR + ar[i - REG_AR].regnum);
6781 /* define synonyms for control registers: */
6782 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6783 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6784 REG_CR + cr[i - REG_CR].regnum);
6786 declare_register ("gp", REG_GR + 1);
6787 declare_register ("sp", REG_GR + 12);
6788 declare_register ("rp", REG_BR + 0);
6790 /* pseudo-registers used to specify unwind info: */
6791 declare_register ("psp", REG_PSP);
6793 declare_register_set ("ret", 4, REG_GR + 8);
6794 declare_register_set ("farg", 8, REG_FR + 8);
6795 declare_register_set ("fret", 8, REG_FR + 8);
6797 for (i = 0; i < NELEMS (const_bits); ++i)
6799 err = hash_insert (md.const_hash, const_bits[i].name,
6800 (PTR) (const_bits + i));
6802 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6806 /* Set the architecture and machine depending on defaults and command line
6808 if (md.flags & EF_IA_64_ABI64)
6809 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6811 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6814 as_warn (_("Could not set architecture and machine"));
6816 /* Set the pointer size and pointer shift size depending on md.flags */
6818 if (md.flags & EF_IA_64_ABI64)
6820 md.pointer_size = 8; /* pointers are 8 bytes */
6821 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6825 md.pointer_size = 4; /* pointers are 4 bytes */
6826 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6829 md.mem_offset.hint = 0;
6832 md.entry_labels = NULL;
6835 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6836 because that is called after md_parse_option which is where we do the
6837 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6838 default endianness. */
6841 ia64_init (argc, argv)
6842 int argc ATTRIBUTE_UNUSED;
6843 char **argv ATTRIBUTE_UNUSED;
6845 md.flags = MD_FLAGS_DEFAULT;
6848 /* Return a string for the target object file format. */
6851 ia64_target_format ()
6853 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6855 if (md.flags & EF_IA_64_BE)
6857 if (md.flags & EF_IA_64_ABI64)
6858 #if defined(TE_AIX50)
6859 return "elf64-ia64-aix-big";
6860 #elif defined(TE_HPUX)
6861 return "elf64-ia64-hpux-big";
6863 return "elf64-ia64-big";
6866 #if defined(TE_AIX50)
6867 return "elf32-ia64-aix-big";
6868 #elif defined(TE_HPUX)
6869 return "elf32-ia64-hpux-big";
6871 return "elf32-ia64-big";
6876 if (md.flags & EF_IA_64_ABI64)
6878 return "elf64-ia64-aix-little";
6880 return "elf64-ia64-little";
6884 return "elf32-ia64-aix-little";
6886 return "elf32-ia64-little";
6891 return "unknown-format";
6895 ia64_end_of_source ()
6897 /* terminate insn group upon reaching end of file: */
6898 insn_group_break (1, 0, 0);
6900 /* emits slots we haven't written yet: */
6901 ia64_flush_insns ();
6903 bfd_set_private_flags (stdoutput, md.flags);
6905 md.mem_offset.hint = 0;
6911 if (md.qp.X_op == O_register)
6912 as_bad ("qualifying predicate not followed by instruction");
6913 md.qp.X_op = O_absent;
6915 if (ignore_input ())
6918 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6920 if (md.detect_dv && !md.explicit_mode)
6921 as_warn (_("Explicit stops are ignored in auto mode"));
6923 insn_group_break (1, 0, 0);
6927 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
6929 static int defining_tag = 0;
6932 ia64_unrecognized_line (ch)
6938 expression (&md.qp);
6939 if (*input_line_pointer++ != ')')
6941 as_bad ("Expected ')'");
6944 if (md.qp.X_op != O_register)
6946 as_bad ("Qualifying predicate expected");
6949 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
6951 as_bad ("Predicate register expected");
6957 if (md.manual_bundling)
6958 as_warn ("Found '{' when manual bundling is already turned on");
6960 CURR_SLOT.manual_bundling_on = 1;
6961 md.manual_bundling = 1;
6963 /* Bundling is only acceptable in explicit mode
6964 or when in default automatic mode. */
6965 if (md.detect_dv && !md.explicit_mode)
6967 if (!md.mode_explicitly_set
6968 && !md.default_explicit_mode)
6971 as_warn (_("Found '{' after explicit switch to automatic mode"));
6976 if (!md.manual_bundling)
6977 as_warn ("Found '}' when manual bundling is off");
6979 PREV_SLOT.manual_bundling_off = 1;
6980 md.manual_bundling = 0;
6982 /* switch back to automatic mode, if applicable */
6985 && !md.mode_explicitly_set
6986 && !md.default_explicit_mode)
6989 /* Allow '{' to follow on the same line. We also allow ";;", but that
6990 happens automatically because ';' is an end of line marker. */
6992 if (input_line_pointer[0] == '{')
6994 input_line_pointer++;
6995 return ia64_unrecognized_line ('{');
6998 demand_empty_rest_of_line ();
7008 if (md.qp.X_op == O_register)
7010 as_bad ("Tag must come before qualifying predicate.");
7014 /* This implements just enough of read_a_source_file in read.c to
7015 recognize labels. */
7016 if (is_name_beginner (*input_line_pointer))
7018 s = input_line_pointer;
7019 c = get_symbol_end ();
7021 else if (LOCAL_LABELS_FB
7022 && ISDIGIT (*input_line_pointer))
7025 while (ISDIGIT (*input_line_pointer))
7026 temp = (temp * 10) + *input_line_pointer++ - '0';
7027 fb_label_instance_inc (temp);
7028 s = fb_label_name (temp, 0);
7029 c = *input_line_pointer;
7038 /* Put ':' back for error messages' sake. */
7039 *input_line_pointer++ = ':';
7040 as_bad ("Expected ':'");
7047 /* Put ':' back for error messages' sake. */
7048 *input_line_pointer++ = ':';
7049 if (*input_line_pointer++ != ']')
7051 as_bad ("Expected ']'");
7056 as_bad ("Tag name expected");
7066 /* Not a valid line. */
7071 ia64_frob_label (sym)
7074 struct label_fix *fix;
7076 /* Tags need special handling since they are not bundle breaks like
7080 fix = obstack_alloc (¬es, sizeof (*fix));
7082 fix->next = CURR_SLOT.tag_fixups;
7083 CURR_SLOT.tag_fixups = fix;
7088 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7090 md.last_text_seg = now_seg;
7091 fix = obstack_alloc (¬es, sizeof (*fix));
7093 fix->next = CURR_SLOT.label_fixups;
7094 CURR_SLOT.label_fixups = fix;
7096 /* Keep track of how many code entry points we've seen. */
7097 if (md.path == md.maxpaths)
7100 md.entry_labels = (const char **)
7101 xrealloc ((void *) md.entry_labels,
7102 md.maxpaths * sizeof (char *));
7104 md.entry_labels[md.path++] = S_GET_NAME (sym);
7109 ia64_flush_pending_output ()
7111 if (!md.keep_pending_output
7112 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7114 /* ??? This causes many unnecessary stop bits to be emitted.
7115 Unfortunately, it isn't clear if it is safe to remove this. */
7116 insn_group_break (1, 0, 0);
7117 ia64_flush_insns ();
7121 /* Do ia64-specific expression optimization. All that's done here is
7122 to transform index expressions that are either due to the indexing
7123 of rotating registers or due to the indexing of indirect register
7126 ia64_optimize_expr (l, op, r)
7135 if (l->X_op == O_register && r->X_op == O_constant)
7137 num_regs = (l->X_add_number >> 16);
7138 if ((unsigned) r->X_add_number >= num_regs)
7141 as_bad ("No current frame");
7143 as_bad ("Index out of range 0..%u", num_regs - 1);
7144 r->X_add_number = 0;
7146 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7149 else if (l->X_op == O_register && r->X_op == O_register)
7151 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7152 || l->X_add_number == IND_MEM)
7154 as_bad ("Indirect register set name expected");
7155 l->X_add_number = IND_CPUID;
7158 l->X_op_symbol = md.regsym[l->X_add_number];
7159 l->X_add_number = r->X_add_number;
7167 ia64_parse_name (name, e)
7171 struct const_desc *cdesc;
7172 struct dynreg *dr = 0;
7173 unsigned int regnum;
7177 /* first see if NAME is a known register name: */
7178 sym = hash_find (md.reg_hash, name);
7181 e->X_op = O_register;
7182 e->X_add_number = S_GET_VALUE (sym);
7186 cdesc = hash_find (md.const_hash, name);
7189 e->X_op = O_constant;
7190 e->X_add_number = cdesc->value;
7194 /* check for inN, locN, or outN: */
7198 if (name[1] == 'n' && ISDIGIT (name[2]))
7206 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7214 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7227 /* The name is inN, locN, or outN; parse the register number. */
7228 regnum = strtoul (name, &end, 10);
7229 if (end > name && *end == '\0')
7231 if ((unsigned) regnum >= dr->num_regs)
7234 as_bad ("No current frame");
7236 as_bad ("Register number out of range 0..%u",
7240 e->X_op = O_register;
7241 e->X_add_number = dr->base + regnum;
7246 if ((dr = hash_find (md.dynreg_hash, name)))
7248 /* We've got ourselves the name of a rotating register set.
7249 Store the base register number in the low 16 bits of
7250 X_add_number and the size of the register set in the top 16
7252 e->X_op = O_register;
7253 e->X_add_number = dr->base | (dr->num_regs << 16);
7259 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7262 ia64_canonicalize_symbol_name (name)
7265 size_t len = strlen (name);
7266 if (len > 1 && name[len - 1] == '#')
7267 name[len - 1] = '\0';
7271 /* Return true if idesc is a conditional branch instruction. This excludes
7272 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7273 because they always read/write resources regardless of the value of the
7274 qualifying predicate. br.ia must always use p0, and hence is always
7275 taken. Thus this function returns true for branches which can fall
7276 through, and which use no resources if they do fall through. */
7279 is_conditional_branch (idesc)
7280 struct ia64_opcode *idesc;
7282 /* br is a conditional branch. Everything that starts with br. except
7283 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7284 Everything that starts with brl is a conditional branch. */
7285 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7286 && (idesc->name[2] == '\0'
7287 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7288 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7289 || idesc->name[2] == 'l'
7290 /* br.cond, br.call, br.clr */
7291 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7292 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7293 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7296 /* Return whether the given opcode is a taken branch. If there's any doubt,
7300 is_taken_branch (idesc)
7301 struct ia64_opcode *idesc;
7303 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7304 || strncmp (idesc->name, "br.ia", 5) == 0);
7307 /* Return whether the given opcode is an interruption or rfi. If there's any
7308 doubt, returns zero. */
7311 is_interruption_or_rfi (idesc)
7312 struct ia64_opcode *idesc;
7314 if (strcmp (idesc->name, "rfi") == 0)
7319 /* Returns the index of the given dependency in the opcode's list of chks, or
7320 -1 if there is no dependency. */
7323 depends_on (depind, idesc)
7325 struct ia64_opcode *idesc;
7328 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7329 for (i = 0; i < dep->nchks; i++)
7331 if (depind == DEP (dep->chks[i]))
7337 /* Determine a set of specific resources used for a particular resource
7338 class. Returns the number of specific resources identified For those
7339 cases which are not determinable statically, the resource returned is
7342 Meanings of value in 'NOTE':
7343 1) only read/write when the register number is explicitly encoded in the
7345 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7346 accesses CFM when qualifying predicate is in the rotating region.
7347 3) general register value is used to specify an indirect register; not
7348 determinable statically.
7349 4) only read the given resource when bits 7:0 of the indirect index
7350 register value does not match the register number of the resource; not
7351 determinable statically.
7352 5) all rules are implementation specific.
7353 6) only when both the index specified by the reader and the index specified
7354 by the writer have the same value in bits 63:61; not determinable
7356 7) only access the specified resource when the corresponding mask bit is
7358 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7359 only read when these insns reference FR2-31
7360 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7361 written when these insns write FR32-127
7362 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7364 11) The target predicates are written independently of PR[qp], but source
7365 registers are only read if PR[qp] is true. Since the state of PR[qp]
7366 cannot statically be determined, all source registers are marked used.
7367 12) This insn only reads the specified predicate register when that
7368 register is the PR[qp].
7369 13) This reference to ld-c only applies to teh GR whose value is loaded
7370 with data returned from memory, not the post-incremented address register.
7371 14) The RSE resource includes the implementation-specific RSE internal
7372 state resources. At least one (and possibly more) of these resources are
7373 read by each instruction listed in IC:rse-readers. At least one (and
7374 possibly more) of these resources are written by each insn listed in
7376 15+16) Represents reserved instructions, which the assembler does not
7379 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7380 this code; there are no dependency violations based on memory access.
7383 #define MAX_SPECS 256
7388 specify_resource (dep, idesc, type, specs, note, path)
7389 const struct ia64_dependency *dep;
7390 struct ia64_opcode *idesc;
7391 int type; /* is this a DV chk or a DV reg? */
7392 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7393 int note; /* resource note for this insn's usage */
7394 int path; /* which execution path to examine */
7401 if (dep->mode == IA64_DV_WAW
7402 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7403 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7406 /* template for any resources we identify */
7407 tmpl.dependency = dep;
7409 tmpl.insn_srlz = tmpl.data_srlz = 0;
7410 tmpl.qp_regno = CURR_SLOT.qp_regno;
7411 tmpl.link_to_qp_branch = 1;
7412 tmpl.mem_offset.hint = 0;
7415 tmpl.cmp_type = CMP_NONE;
7418 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7419 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7420 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7422 /* we don't need to track these */
7423 if (dep->semantics == IA64_DVS_NONE)
7426 switch (dep->specifier)
7431 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7433 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7434 if (regno >= 0 && regno <= 7)
7436 specs[count] = tmpl;
7437 specs[count++].index = regno;
7443 for (i = 0; i < 8; i++)
7445 specs[count] = tmpl;
7446 specs[count++].index = i;
7455 case IA64_RS_AR_UNAT:
7456 /* This is a mov =AR or mov AR= instruction. */
7457 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7459 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7460 if (regno == AR_UNAT)
7462 specs[count++] = tmpl;
7467 /* This is a spill/fill, or other instruction that modifies the
7470 /* Unless we can determine the specific bits used, mark the whole
7471 thing; bits 8:3 of the memory address indicate the bit used in
7472 UNAT. The .mem.offset hint may be used to eliminate a small
7473 subset of conflicts. */
7474 specs[count] = tmpl;
7475 if (md.mem_offset.hint)
7478 fprintf (stderr, " Using hint for spill/fill\n");
7479 /* The index isn't actually used, just set it to something
7480 approximating the bit index. */
7481 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7482 specs[count].mem_offset.hint = 1;
7483 specs[count].mem_offset.offset = md.mem_offset.offset;
7484 specs[count++].mem_offset.base = md.mem_offset.base;
7488 specs[count++].specific = 0;
7496 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7498 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7499 if ((regno >= 8 && regno <= 15)
7500 || (regno >= 20 && regno <= 23)
7501 || (regno >= 31 && regno <= 39)
7502 || (regno >= 41 && regno <= 47)
7503 || (regno >= 67 && regno <= 111))
7505 specs[count] = tmpl;
7506 specs[count++].index = regno;
7519 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7521 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7522 if ((regno >= 48 && regno <= 63)
7523 || (regno >= 112 && regno <= 127))
7525 specs[count] = tmpl;
7526 specs[count++].index = regno;
7532 for (i = 48; i < 64; i++)
7534 specs[count] = tmpl;
7535 specs[count++].index = i;
7537 for (i = 112; i < 128; i++)
7539 specs[count] = tmpl;
7540 specs[count++].index = i;
7558 for (i = 0; i < idesc->num_outputs; i++)
7559 if (idesc->operands[i] == IA64_OPND_B1
7560 || idesc->operands[i] == IA64_OPND_B2)
7562 specs[count] = tmpl;
7563 specs[count++].index =
7564 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7569 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7570 if (idesc->operands[i] == IA64_OPND_B1
7571 || idesc->operands[i] == IA64_OPND_B2)
7573 specs[count] = tmpl;
7574 specs[count++].index =
7575 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7581 case IA64_RS_CPUID: /* four or more registers */
7584 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7586 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7587 if (regno >= 0 && regno < NELEMS (gr_values)
7590 specs[count] = tmpl;
7591 specs[count++].index = gr_values[regno].value & 0xFF;
7595 specs[count] = tmpl;
7596 specs[count++].specific = 0;
7606 case IA64_RS_DBR: /* four or more registers */
7609 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7611 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7612 if (regno >= 0 && regno < NELEMS (gr_values)
7615 specs[count] = tmpl;
7616 specs[count++].index = gr_values[regno].value & 0xFF;
7620 specs[count] = tmpl;
7621 specs[count++].specific = 0;
7625 else if (note == 0 && !rsrc_write)
7627 specs[count] = tmpl;
7628 specs[count++].specific = 0;
7636 case IA64_RS_IBR: /* four or more registers */
7639 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7641 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7642 if (regno >= 0 && regno < NELEMS (gr_values)
7645 specs[count] = tmpl;
7646 specs[count++].index = gr_values[regno].value & 0xFF;
7650 specs[count] = tmpl;
7651 specs[count++].specific = 0;
7664 /* These are implementation specific. Force all references to
7665 conflict with all other references. */
7666 specs[count] = tmpl;
7667 specs[count++].specific = 0;
7675 case IA64_RS_PKR: /* 16 or more registers */
7676 if (note == 3 || note == 4)
7678 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7680 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7681 if (regno >= 0 && regno < NELEMS (gr_values)
7686 specs[count] = tmpl;
7687 specs[count++].index = gr_values[regno].value & 0xFF;
7690 for (i = 0; i < NELEMS (gr_values); i++)
7692 /* Uses all registers *except* the one in R3. */
7693 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7695 specs[count] = tmpl;
7696 specs[count++].index = i;
7702 specs[count] = tmpl;
7703 specs[count++].specific = 0;
7710 specs[count] = tmpl;
7711 specs[count++].specific = 0;
7715 case IA64_RS_PMC: /* four or more registers */
7718 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7719 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7722 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7724 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7725 if (regno >= 0 && regno < NELEMS (gr_values)
7728 specs[count] = tmpl;
7729 specs[count++].index = gr_values[regno].value & 0xFF;
7733 specs[count] = tmpl;
7734 specs[count++].specific = 0;
7744 case IA64_RS_PMD: /* four or more registers */
7747 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7749 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7750 if (regno >= 0 && regno < NELEMS (gr_values)
7753 specs[count] = tmpl;
7754 specs[count++].index = gr_values[regno].value & 0xFF;
7758 specs[count] = tmpl;
7759 specs[count++].specific = 0;
7769 case IA64_RS_RR: /* eight registers */
7772 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7774 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7775 if (regno >= 0 && regno < NELEMS (gr_values)
7778 specs[count] = tmpl;
7779 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7783 specs[count] = tmpl;
7784 specs[count++].specific = 0;
7788 else if (note == 0 && !rsrc_write)
7790 specs[count] = tmpl;
7791 specs[count++].specific = 0;
7799 case IA64_RS_CR_IRR:
7802 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7803 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7805 && idesc->operands[1] == IA64_OPND_CR3
7808 for (i = 0; i < 4; i++)
7810 specs[count] = tmpl;
7811 specs[count++].index = CR_IRR0 + i;
7817 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7818 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7820 && regno <= CR_IRR3)
7822 specs[count] = tmpl;
7823 specs[count++].index = regno;
7832 case IA64_RS_CR_LRR:
7839 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7840 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7841 && (regno == CR_LRR0 || regno == CR_LRR1))
7843 specs[count] = tmpl;
7844 specs[count++].index = regno;
7852 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7854 specs[count] = tmpl;
7855 specs[count++].index =
7856 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7871 else if (rsrc_write)
7873 if (dep->specifier == IA64_RS_FRb
7874 && idesc->operands[0] == IA64_OPND_F1)
7876 specs[count] = tmpl;
7877 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7882 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7884 if (idesc->operands[i] == IA64_OPND_F2
7885 || idesc->operands[i] == IA64_OPND_F3
7886 || idesc->operands[i] == IA64_OPND_F4)
7888 specs[count] = tmpl;
7889 specs[count++].index =
7890 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7899 /* This reference applies only to the GR whose value is loaded with
7900 data returned from memory. */
7901 specs[count] = tmpl;
7902 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7908 for (i = 0; i < idesc->num_outputs; i++)
7909 if (idesc->operands[i] == IA64_OPND_R1
7910 || idesc->operands[i] == IA64_OPND_R2
7911 || idesc->operands[i] == IA64_OPND_R3)
7913 specs[count] = tmpl;
7914 specs[count++].index =
7915 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7917 if (idesc->flags & IA64_OPCODE_POSTINC)
7918 for (i = 0; i < NELEMS (idesc->operands); i++)
7919 if (idesc->operands[i] == IA64_OPND_MR3)
7921 specs[count] = tmpl;
7922 specs[count++].index =
7923 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7928 /* Look for anything that reads a GR. */
7929 for (i = 0; i < NELEMS (idesc->operands); i++)
7931 if (idesc->operands[i] == IA64_OPND_MR3
7932 || idesc->operands[i] == IA64_OPND_CPUID_R3
7933 || idesc->operands[i] == IA64_OPND_DBR_R3
7934 || idesc->operands[i] == IA64_OPND_IBR_R3
7935 || idesc->operands[i] == IA64_OPND_MSR_R3
7936 || idesc->operands[i] == IA64_OPND_PKR_R3
7937 || idesc->operands[i] == IA64_OPND_PMC_R3
7938 || idesc->operands[i] == IA64_OPND_PMD_R3
7939 || idesc->operands[i] == IA64_OPND_RR_R3
7940 || ((i >= idesc->num_outputs)
7941 && (idesc->operands[i] == IA64_OPND_R1
7942 || idesc->operands[i] == IA64_OPND_R2
7943 || idesc->operands[i] == IA64_OPND_R3
7944 /* addl source register. */
7945 || idesc->operands[i] == IA64_OPND_R3_2)))
7947 specs[count] = tmpl;
7948 specs[count++].index =
7949 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7960 /* This is the same as IA64_RS_PRr, except that the register range is
7961 from 1 - 15, and there are no rotating register reads/writes here. */
7965 for (i = 1; i < 16; i++)
7967 specs[count] = tmpl;
7968 specs[count++].index = i;
7974 /* Mark only those registers indicated by the mask. */
7977 mask = CURR_SLOT.opnd[2].X_add_number;
7978 for (i = 1; i < 16; i++)
7979 if (mask & ((valueT) 1 << i))
7981 specs[count] = tmpl;
7982 specs[count++].index = i;
7990 else if (note == 11) /* note 11 implies note 1 as well */
7994 for (i = 0; i < idesc->num_outputs; i++)
7996 if (idesc->operands[i] == IA64_OPND_P1
7997 || idesc->operands[i] == IA64_OPND_P2)
7999 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8000 if (regno >= 1 && regno < 16)
8002 specs[count] = tmpl;
8003 specs[count++].index = regno;
8013 else if (note == 12)
8015 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8017 specs[count] = tmpl;
8018 specs[count++].index = CURR_SLOT.qp_regno;
8025 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8026 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8027 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8028 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8030 if ((idesc->operands[0] == IA64_OPND_P1
8031 || idesc->operands[0] == IA64_OPND_P2)
8032 && p1 >= 1 && p1 < 16)
8034 specs[count] = tmpl;
8035 specs[count].cmp_type =
8036 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8037 specs[count++].index = p1;
8039 if ((idesc->operands[1] == IA64_OPND_P1
8040 || idesc->operands[1] == IA64_OPND_P2)
8041 && p2 >= 1 && p2 < 16)
8043 specs[count] = tmpl;
8044 specs[count].cmp_type =
8045 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8046 specs[count++].index = p2;
8051 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8053 specs[count] = tmpl;
8054 specs[count++].index = CURR_SLOT.qp_regno;
8056 if (idesc->operands[1] == IA64_OPND_PR)
8058 for (i = 1; i < 16; i++)
8060 specs[count] = tmpl;
8061 specs[count++].index = i;
8072 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8073 simplified cases of this. */
8077 for (i = 16; i < 63; i++)
8079 specs[count] = tmpl;
8080 specs[count++].index = i;
8086 /* Mark only those registers indicated by the mask. */
8088 && idesc->operands[0] == IA64_OPND_PR)
8090 mask = CURR_SLOT.opnd[2].X_add_number;
8091 if (mask & ((valueT) 1 << 16))
8092 for (i = 16; i < 63; i++)
8094 specs[count] = tmpl;
8095 specs[count++].index = i;
8099 && idesc->operands[0] == IA64_OPND_PR_ROT)
8101 for (i = 16; i < 63; i++)
8103 specs[count] = tmpl;
8104 specs[count++].index = i;
8112 else if (note == 11) /* note 11 implies note 1 as well */
8116 for (i = 0; i < idesc->num_outputs; i++)
8118 if (idesc->operands[i] == IA64_OPND_P1
8119 || idesc->operands[i] == IA64_OPND_P2)
8121 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8122 if (regno >= 16 && regno < 63)
8124 specs[count] = tmpl;
8125 specs[count++].index = regno;
8135 else if (note == 12)
8137 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8139 specs[count] = tmpl;
8140 specs[count++].index = CURR_SLOT.qp_regno;
8147 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8148 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8149 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8150 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8152 if ((idesc->operands[0] == IA64_OPND_P1
8153 || idesc->operands[0] == IA64_OPND_P2)
8154 && p1 >= 16 && p1 < 63)
8156 specs[count] = tmpl;
8157 specs[count].cmp_type =
8158 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8159 specs[count++].index = p1;
8161 if ((idesc->operands[1] == IA64_OPND_P1
8162 || idesc->operands[1] == IA64_OPND_P2)
8163 && p2 >= 16 && p2 < 63)
8165 specs[count] = tmpl;
8166 specs[count].cmp_type =
8167 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8168 specs[count++].index = p2;
8173 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8175 specs[count] = tmpl;
8176 specs[count++].index = CURR_SLOT.qp_regno;
8178 if (idesc->operands[1] == IA64_OPND_PR)
8180 for (i = 16; i < 63; i++)
8182 specs[count] = tmpl;
8183 specs[count++].index = i;
8195 /* Verify that the instruction is using the PSR bit indicated in
8199 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8201 if (dep->regindex < 6)
8203 specs[count++] = tmpl;
8206 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8208 if (dep->regindex < 32
8209 || dep->regindex == 35
8210 || dep->regindex == 36
8211 || (!rsrc_write && dep->regindex == PSR_CPL))
8213 specs[count++] = tmpl;
8216 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8218 if (dep->regindex < 32
8219 || dep->regindex == 35
8220 || dep->regindex == 36
8221 || (rsrc_write && dep->regindex == PSR_CPL))
8223 specs[count++] = tmpl;
8228 /* Several PSR bits have very specific dependencies. */
8229 switch (dep->regindex)
8232 specs[count++] = tmpl;
8237 specs[count++] = tmpl;
8241 /* Only certain CR accesses use PSR.ic */
8242 if (idesc->operands[0] == IA64_OPND_CR3
8243 || idesc->operands[1] == IA64_OPND_CR3)
8246 ((idesc->operands[0] == IA64_OPND_CR3)
8249 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8264 specs[count++] = tmpl;
8273 specs[count++] = tmpl;
8277 /* Only some AR accesses use cpl */
8278 if (idesc->operands[0] == IA64_OPND_AR3
8279 || idesc->operands[1] == IA64_OPND_AR3)
8282 ((idesc->operands[0] == IA64_OPND_AR3)
8285 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8292 && regno <= AR_K7))))
8294 specs[count++] = tmpl;
8299 specs[count++] = tmpl;
8309 if (idesc->operands[0] == IA64_OPND_IMMU24)
8311 mask = CURR_SLOT.opnd[0].X_add_number;
8317 if (mask & ((valueT) 1 << dep->regindex))
8319 specs[count++] = tmpl;
8324 int min = dep->regindex == PSR_DFL ? 2 : 32;
8325 int max = dep->regindex == PSR_DFL ? 31 : 127;
8326 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8327 for (i = 0; i < NELEMS (idesc->operands); i++)
8329 if (idesc->operands[i] == IA64_OPND_F1
8330 || idesc->operands[i] == IA64_OPND_F2
8331 || idesc->operands[i] == IA64_OPND_F3
8332 || idesc->operands[i] == IA64_OPND_F4)
8334 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8335 if (reg >= min && reg <= max)
8337 specs[count++] = tmpl;
8344 int min = dep->regindex == PSR_MFL ? 2 : 32;
8345 int max = dep->regindex == PSR_MFL ? 31 : 127;
8346 /* mfh is read on writes to FR32-127; mfl is read on writes to
8348 for (i = 0; i < idesc->num_outputs; i++)
8350 if (idesc->operands[i] == IA64_OPND_F1)
8352 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8353 if (reg >= min && reg <= max)
8355 specs[count++] = tmpl;
8360 else if (note == 10)
8362 for (i = 0; i < NELEMS (idesc->operands); i++)
8364 if (idesc->operands[i] == IA64_OPND_R1
8365 || idesc->operands[i] == IA64_OPND_R2
8366 || idesc->operands[i] == IA64_OPND_R3)
8368 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8369 if (regno >= 16 && regno <= 31)
8371 specs[count++] = tmpl;
8382 case IA64_RS_AR_FPSR:
8383 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8385 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8386 if (regno == AR_FPSR)
8388 specs[count++] = tmpl;
8393 specs[count++] = tmpl;
8398 /* Handle all AR[REG] resources */
8399 if (note == 0 || note == 1)
8401 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8402 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8403 && regno == dep->regindex)
8405 specs[count++] = tmpl;
8407 /* other AR[REG] resources may be affected by AR accesses */
8408 else if (idesc->operands[0] == IA64_OPND_AR3)
8411 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8412 switch (dep->regindex)
8418 if (regno == AR_BSPSTORE)
8420 specs[count++] = tmpl;
8424 (regno == AR_BSPSTORE
8425 || regno == AR_RNAT))
8427 specs[count++] = tmpl;
8432 else if (idesc->operands[1] == IA64_OPND_AR3)
8435 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8436 switch (dep->regindex)
8441 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8443 specs[count++] = tmpl;
8450 specs[count++] = tmpl;
8460 /* Handle all CR[REG] resources */
8461 if (note == 0 || note == 1)
8463 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8465 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8466 if (regno == dep->regindex)
8468 specs[count++] = tmpl;
8470 else if (!rsrc_write)
8472 /* Reads from CR[IVR] affect other resources. */
8473 if (regno == CR_IVR)
8475 if ((dep->regindex >= CR_IRR0
8476 && dep->regindex <= CR_IRR3)
8477 || dep->regindex == CR_TPR)
8479 specs[count++] = tmpl;
8486 specs[count++] = tmpl;
8495 case IA64_RS_INSERVICE:
8496 /* look for write of EOI (67) or read of IVR (65) */
8497 if ((idesc->operands[0] == IA64_OPND_CR3
8498 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8499 || (idesc->operands[1] == IA64_OPND_CR3
8500 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8502 specs[count++] = tmpl;
8509 specs[count++] = tmpl;
8520 specs[count++] = tmpl;
8524 /* Check if any of the registers accessed are in the rotating region.
8525 mov to/from pr accesses CFM only when qp_regno is in the rotating
8527 for (i = 0; i < NELEMS (idesc->operands); i++)
8529 if (idesc->operands[i] == IA64_OPND_R1
8530 || idesc->operands[i] == IA64_OPND_R2
8531 || idesc->operands[i] == IA64_OPND_R3)
8533 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8534 /* Assumes that md.rot.num_regs is always valid */
8535 if (md.rot.num_regs > 0
8537 && num < 31 + md.rot.num_regs)
8539 specs[count] = tmpl;
8540 specs[count++].specific = 0;
8543 else if (idesc->operands[i] == IA64_OPND_F1
8544 || idesc->operands[i] == IA64_OPND_F2
8545 || idesc->operands[i] == IA64_OPND_F3
8546 || idesc->operands[i] == IA64_OPND_F4)
8548 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8551 specs[count] = tmpl;
8552 specs[count++].specific = 0;
8555 else if (idesc->operands[i] == IA64_OPND_P1
8556 || idesc->operands[i] == IA64_OPND_P2)
8558 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8561 specs[count] = tmpl;
8562 specs[count++].specific = 0;
8566 if (CURR_SLOT.qp_regno > 15)
8568 specs[count] = tmpl;
8569 specs[count++].specific = 0;
8574 /* This is the same as IA64_RS_PRr, except simplified to account for
8575 the fact that there is only one register. */
8579 specs[count++] = tmpl;
8584 if (idesc->operands[2] == IA64_OPND_IMM17)
8585 mask = CURR_SLOT.opnd[2].X_add_number;
8586 if (mask & ((valueT) 1 << 63))
8587 specs[count++] = tmpl;
8589 else if (note == 11)
8591 if ((idesc->operands[0] == IA64_OPND_P1
8592 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8593 || (idesc->operands[1] == IA64_OPND_P2
8594 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8596 specs[count++] = tmpl;
8599 else if (note == 12)
8601 if (CURR_SLOT.qp_regno == 63)
8603 specs[count++] = tmpl;
8610 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8611 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8612 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8613 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8616 && (idesc->operands[0] == IA64_OPND_P1
8617 || idesc->operands[0] == IA64_OPND_P2))
8619 specs[count] = tmpl;
8620 specs[count++].cmp_type =
8621 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8624 && (idesc->operands[1] == IA64_OPND_P1
8625 || idesc->operands[1] == IA64_OPND_P2))
8627 specs[count] = tmpl;
8628 specs[count++].cmp_type =
8629 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8634 if (CURR_SLOT.qp_regno == 63)
8636 specs[count++] = tmpl;
8647 /* FIXME we can identify some individual RSE written resources, but RSE
8648 read resources have not yet been completely identified, so for now
8649 treat RSE as a single resource */
8650 if (strncmp (idesc->name, "mov", 3) == 0)
8654 if (idesc->operands[0] == IA64_OPND_AR3
8655 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8657 specs[count] = tmpl;
8658 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8663 if (idesc->operands[0] == IA64_OPND_AR3)
8665 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8666 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8668 specs[count++] = tmpl;
8671 else if (idesc->operands[1] == IA64_OPND_AR3)
8673 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8674 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8675 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8677 specs[count++] = tmpl;
8684 specs[count++] = tmpl;
8689 /* FIXME -- do any of these need to be non-specific? */
8690 specs[count++] = tmpl;
8694 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8701 /* Clear branch flags on marked resources. This breaks the link between the
8702 QP of the marking instruction and a subsequent branch on the same QP. */
8705 clear_qp_branch_flag (mask)
8709 for (i = 0; i < regdepslen; i++)
8711 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8712 if ((bit & mask) != 0)
8714 regdeps[i].link_to_qp_branch = 0;
8719 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8721 Any changes to a PR clears the mutex relations which include that PR. */
8724 clear_qp_mutex (mask)
8730 while (i < qp_mutexeslen)
8732 if ((qp_mutexes[i].prmask & mask) != 0)
8736 fprintf (stderr, " Clearing mutex relation");
8737 print_prmask (qp_mutexes[i].prmask);
8738 fprintf (stderr, "\n");
8740 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8747 /* Clear implies relations which contain PRs in the given masks.
8748 P1_MASK indicates the source of the implies relation, while P2_MASK
8749 indicates the implied PR. */
8752 clear_qp_implies (p1_mask, p2_mask)
8759 while (i < qp_implieslen)
8761 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8762 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8765 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8766 qp_implies[i].p1, qp_implies[i].p2);
8767 qp_implies[i] = qp_implies[--qp_implieslen];
8774 /* Add the PRs specified to the list of implied relations. */
8777 add_qp_imply (p1, p2)
8784 /* p0 is not meaningful here. */
8785 if (p1 == 0 || p2 == 0)
8791 /* If it exists already, ignore it. */
8792 for (i = 0; i < qp_implieslen; i++)
8794 if (qp_implies[i].p1 == p1
8795 && qp_implies[i].p2 == p2
8796 && qp_implies[i].path == md.path
8797 && !qp_implies[i].p2_branched)
8801 if (qp_implieslen == qp_impliestotlen)
8803 qp_impliestotlen += 20;
8804 qp_implies = (struct qp_imply *)
8805 xrealloc ((void *) qp_implies,
8806 qp_impliestotlen * sizeof (struct qp_imply));
8809 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8810 qp_implies[qp_implieslen].p1 = p1;
8811 qp_implies[qp_implieslen].p2 = p2;
8812 qp_implies[qp_implieslen].path = md.path;
8813 qp_implies[qp_implieslen++].p2_branched = 0;
8815 /* Add in the implied transitive relations; for everything that p2 implies,
8816 make p1 imply that, too; for everything that implies p1, make it imply p2
8818 for (i = 0; i < qp_implieslen; i++)
8820 if (qp_implies[i].p1 == p2)
8821 add_qp_imply (p1, qp_implies[i].p2);
8822 if (qp_implies[i].p2 == p1)
8823 add_qp_imply (qp_implies[i].p1, p2);
8825 /* Add in mutex relations implied by this implies relation; for each mutex
8826 relation containing p2, duplicate it and replace p2 with p1. */
8827 bit = (valueT) 1 << p1;
8828 mask = (valueT) 1 << p2;
8829 for (i = 0; i < qp_mutexeslen; i++)
8831 if (qp_mutexes[i].prmask & mask)
8832 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8836 /* Add the PRs specified in the mask to the mutex list; this means that only
8837 one of the PRs can be true at any time. PR0 should never be included in
8847 if (qp_mutexeslen == qp_mutexestotlen)
8849 qp_mutexestotlen += 20;
8850 qp_mutexes = (struct qpmutex *)
8851 xrealloc ((void *) qp_mutexes,
8852 qp_mutexestotlen * sizeof (struct qpmutex));
8856 fprintf (stderr, " Registering mutex on");
8857 print_prmask (mask);
8858 fprintf (stderr, "\n");
8860 qp_mutexes[qp_mutexeslen].path = md.path;
8861 qp_mutexes[qp_mutexeslen++].prmask = mask;
8865 has_suffix_p (name, suffix)
8869 size_t namelen = strlen (name);
8870 size_t sufflen = strlen (suffix);
8872 if (namelen <= sufflen)
8874 return strcmp (name + namelen - sufflen, suffix) == 0;
8878 clear_register_values ()
8882 fprintf (stderr, " Clearing register values\n");
8883 for (i = 1; i < NELEMS (gr_values); i++)
8884 gr_values[i].known = 0;
8887 /* Keep track of register values/changes which affect DV tracking.
8889 optimization note: should add a flag to classes of insns where otherwise we
8890 have to examine a group of strings to identify them. */
8893 note_register_values (idesc)
8894 struct ia64_opcode *idesc;
8896 valueT qp_changemask = 0;
8899 /* Invalidate values for registers being written to. */
8900 for (i = 0; i < idesc->num_outputs; i++)
8902 if (idesc->operands[i] == IA64_OPND_R1
8903 || idesc->operands[i] == IA64_OPND_R2
8904 || idesc->operands[i] == IA64_OPND_R3)
8906 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8907 if (regno > 0 && regno < NELEMS (gr_values))
8908 gr_values[regno].known = 0;
8910 else if (idesc->operands[i] == IA64_OPND_R3_2)
8912 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8913 if (regno > 0 && regno < 4)
8914 gr_values[regno].known = 0;
8916 else if (idesc->operands[i] == IA64_OPND_P1
8917 || idesc->operands[i] == IA64_OPND_P2)
8919 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8920 qp_changemask |= (valueT) 1 << regno;
8922 else if (idesc->operands[i] == IA64_OPND_PR)
8924 if (idesc->operands[2] & (valueT) 0x10000)
8925 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
8927 qp_changemask = idesc->operands[2];
8930 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
8932 if (idesc->operands[1] & ((valueT) 1 << 43))
8933 qp_changemask = ~(valueT) 0xFFFFFFFFFFF | idesc->operands[1];
8935 qp_changemask = idesc->operands[1];
8936 qp_changemask &= ~(valueT) 0xFFFF;
8941 /* Always clear qp branch flags on any PR change. */
8942 /* FIXME there may be exceptions for certain compares. */
8943 clear_qp_branch_flag (qp_changemask);
8945 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
8946 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
8948 qp_changemask |= ~(valueT) 0xFFFF;
8949 if (strcmp (idesc->name, "clrrrb.pr") != 0)
8951 for (i = 32; i < 32 + md.rot.num_regs; i++)
8952 gr_values[i].known = 0;
8954 clear_qp_mutex (qp_changemask);
8955 clear_qp_implies (qp_changemask, qp_changemask);
8957 /* After a call, all register values are undefined, except those marked
8959 else if (strncmp (idesc->name, "br.call", 6) == 0
8960 || strncmp (idesc->name, "brl.call", 7) == 0)
8962 /* FIXME keep GR values which are marked as "safe_across_calls" */
8963 clear_register_values ();
8964 clear_qp_mutex (~qp_safe_across_calls);
8965 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
8966 clear_qp_branch_flag (~qp_safe_across_calls);
8968 else if (is_interruption_or_rfi (idesc)
8969 || is_taken_branch (idesc))
8971 clear_register_values ();
8972 clear_qp_mutex (~(valueT) 0);
8973 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
8975 /* Look for mutex and implies relations. */
8976 else if ((idesc->operands[0] == IA64_OPND_P1
8977 || idesc->operands[0] == IA64_OPND_P2)
8978 && (idesc->operands[1] == IA64_OPND_P1
8979 || idesc->operands[1] == IA64_OPND_P2))
8981 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8982 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8983 valueT p1mask = (valueT) 1 << p1;
8984 valueT p2mask = (valueT) 1 << p2;
8986 /* If one of the PRs is PR0, we can't really do anything. */
8987 if (p1 == 0 || p2 == 0)
8990 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
8992 /* In general, clear mutexes and implies which include P1 or P2,
8993 with the following exceptions. */
8994 else if (has_suffix_p (idesc->name, ".or.andcm")
8995 || has_suffix_p (idesc->name, ".and.orcm"))
8997 add_qp_mutex (p1mask | p2mask);
8998 clear_qp_implies (p2mask, p1mask);
9000 else if (has_suffix_p (idesc->name, ".andcm")
9001 || has_suffix_p (idesc->name, ".and"))
9003 clear_qp_implies (0, p1mask | p2mask);
9005 else if (has_suffix_p (idesc->name, ".orcm")
9006 || has_suffix_p (idesc->name, ".or"))
9008 clear_qp_mutex (p1mask | p2mask);
9009 clear_qp_implies (p1mask | p2mask, 0);
9013 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9014 if (has_suffix_p (idesc->name, ".unc"))
9016 add_qp_mutex (p1mask | p2mask);
9017 if (CURR_SLOT.qp_regno != 0)
9019 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
9020 CURR_SLOT.qp_regno);
9021 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
9022 CURR_SLOT.qp_regno);
9025 else if (CURR_SLOT.qp_regno == 0)
9027 add_qp_mutex (p1mask | p2mask);
9031 clear_qp_mutex (p1mask | p2mask);
9035 /* Look for mov imm insns into GRs. */
9036 else if (idesc->operands[0] == IA64_OPND_R1
9037 && (idesc->operands[1] == IA64_OPND_IMM22
9038 || idesc->operands[1] == IA64_OPND_IMMU64)
9039 && (strcmp (idesc->name, "mov") == 0
9040 || strcmp (idesc->name, "movl") == 0))
9042 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9043 if (regno > 0 && regno < NELEMS (gr_values))
9045 gr_values[regno].known = 1;
9046 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9047 gr_values[regno].path = md.path;
9050 fprintf (stderr, " Know gr%d = ", regno);
9051 fprintf_vma (stderr, gr_values[regno].value);
9052 fputs ("\n", stderr);
9058 clear_qp_mutex (qp_changemask);
9059 clear_qp_implies (qp_changemask, qp_changemask);
9063 /* Return whether the given predicate registers are currently mutex. */
9066 qp_mutex (p1, p2, path)
9076 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9077 for (i = 0; i < qp_mutexeslen; i++)
9079 if (qp_mutexes[i].path >= path
9080 && (qp_mutexes[i].prmask & mask) == mask)
9087 /* Return whether the given resource is in the given insn's list of chks
9088 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9092 resources_match (rs, idesc, note, qp_regno, path)
9094 struct ia64_opcode *idesc;
9099 struct rsrc specs[MAX_SPECS];
9102 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9103 we don't need to check. One exception is note 11, which indicates that
9104 target predicates are written regardless of PR[qp]. */
9105 if (qp_mutex (rs->qp_regno, qp_regno, path)
9109 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9112 /* UNAT checking is a bit more specific than other resources */
9113 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9114 && specs[count].mem_offset.hint
9115 && rs->mem_offset.hint)
9117 if (rs->mem_offset.base == specs[count].mem_offset.base)
9119 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9120 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9127 /* Skip apparent PR write conflicts where both writes are an AND or both
9128 writes are an OR. */
9129 if (rs->dependency->specifier == IA64_RS_PR
9130 || rs->dependency->specifier == IA64_RS_PRr
9131 || rs->dependency->specifier == IA64_RS_PR63)
9133 if (specs[count].cmp_type != CMP_NONE
9134 && specs[count].cmp_type == rs->cmp_type)
9137 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9138 dv_mode[rs->dependency->mode],
9139 rs->dependency->specifier != IA64_RS_PR63 ?
9140 specs[count].index : 63);
9145 " %s on parallel compare conflict %s vs %s on PR%d\n",
9146 dv_mode[rs->dependency->mode],
9147 dv_cmp_type[rs->cmp_type],
9148 dv_cmp_type[specs[count].cmp_type],
9149 rs->dependency->specifier != IA64_RS_PR63 ?
9150 specs[count].index : 63);
9154 /* If either resource is not specific, conservatively assume a conflict
9156 if (!specs[count].specific || !rs->specific)
9158 else if (specs[count].index == rs->index)
9163 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9169 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9170 insert a stop to create the break. Update all resource dependencies
9171 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9172 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9173 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9177 insn_group_break (insert_stop, qp_regno, save_current)
9184 if (insert_stop && md.num_slots_in_use > 0)
9185 PREV_SLOT.end_of_insn_group = 1;
9189 fprintf (stderr, " Insn group break%s",
9190 (insert_stop ? " (w/stop)" : ""));
9192 fprintf (stderr, " effective for QP=%d", qp_regno);
9193 fprintf (stderr, "\n");
9197 while (i < regdepslen)
9199 const struct ia64_dependency *dep = regdeps[i].dependency;
9202 && regdeps[i].qp_regno != qp_regno)
9209 && CURR_SLOT.src_file == regdeps[i].file
9210 && CURR_SLOT.src_line == regdeps[i].line)
9216 /* clear dependencies which are automatically cleared by a stop, or
9217 those that have reached the appropriate state of insn serialization */
9218 if (dep->semantics == IA64_DVS_IMPLIED
9219 || dep->semantics == IA64_DVS_IMPLIEDF
9220 || regdeps[i].insn_srlz == STATE_SRLZ)
9222 print_dependency ("Removing", i);
9223 regdeps[i] = regdeps[--regdepslen];
9227 if (dep->semantics == IA64_DVS_DATA
9228 || dep->semantics == IA64_DVS_INSTR
9229 || dep->semantics == IA64_DVS_SPECIFIC)
9231 if (regdeps[i].insn_srlz == STATE_NONE)
9232 regdeps[i].insn_srlz = STATE_STOP;
9233 if (regdeps[i].data_srlz == STATE_NONE)
9234 regdeps[i].data_srlz = STATE_STOP;
9241 /* Add the given resource usage spec to the list of active dependencies. */
9244 mark_resource (idesc, dep, spec, depind, path)
9245 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9246 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9251 if (regdepslen == regdepstotlen)
9253 regdepstotlen += 20;
9254 regdeps = (struct rsrc *)
9255 xrealloc ((void *) regdeps,
9256 regdepstotlen * sizeof (struct rsrc));
9259 regdeps[regdepslen] = *spec;
9260 regdeps[regdepslen].depind = depind;
9261 regdeps[regdepslen].path = path;
9262 regdeps[regdepslen].file = CURR_SLOT.src_file;
9263 regdeps[regdepslen].line = CURR_SLOT.src_line;
9265 print_dependency ("Adding", regdepslen);
9271 print_dependency (action, depind)
9277 fprintf (stderr, " %s %s '%s'",
9278 action, dv_mode[(regdeps[depind].dependency)->mode],
9279 (regdeps[depind].dependency)->name);
9280 if (regdeps[depind].specific && regdeps[depind].index != 0)
9281 fprintf (stderr, " (%d)", regdeps[depind].index);
9282 if (regdeps[depind].mem_offset.hint)
9284 fputs (" ", stderr);
9285 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9286 fputs ("+", stderr);
9287 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9289 fprintf (stderr, "\n");
9294 instruction_serialization ()
9298 fprintf (stderr, " Instruction serialization\n");
9299 for (i = 0; i < regdepslen; i++)
9300 if (regdeps[i].insn_srlz == STATE_STOP)
9301 regdeps[i].insn_srlz = STATE_SRLZ;
9305 data_serialization ()
9309 fprintf (stderr, " Data serialization\n");
9310 while (i < regdepslen)
9312 if (regdeps[i].data_srlz == STATE_STOP
9313 /* Note: as of 991210, all "other" dependencies are cleared by a
9314 data serialization. This might change with new tables */
9315 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9317 print_dependency ("Removing", i);
9318 regdeps[i] = regdeps[--regdepslen];
9325 /* Insert stops and serializations as needed to avoid DVs. */
9328 remove_marked_resource (rs)
9331 switch (rs->dependency->semantics)
9333 case IA64_DVS_SPECIFIC:
9335 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9336 /* ...fall through... */
9337 case IA64_DVS_INSTR:
9339 fprintf (stderr, "Inserting instr serialization\n");
9340 if (rs->insn_srlz < STATE_STOP)
9341 insn_group_break (1, 0, 0);
9342 if (rs->insn_srlz < STATE_SRLZ)
9344 int oldqp = CURR_SLOT.qp_regno;
9345 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9346 /* Manually jam a srlz.i insn into the stream */
9347 CURR_SLOT.qp_regno = 0;
9348 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9349 instruction_serialization ();
9350 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9351 if (++md.num_slots_in_use >= NUM_SLOTS)
9353 CURR_SLOT.qp_regno = oldqp;
9354 CURR_SLOT.idesc = oldidesc;
9356 insn_group_break (1, 0, 0);
9358 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9359 "other" types of DV are eliminated
9360 by a data serialization */
9363 fprintf (stderr, "Inserting data serialization\n");
9364 if (rs->data_srlz < STATE_STOP)
9365 insn_group_break (1, 0, 0);
9367 int oldqp = CURR_SLOT.qp_regno;
9368 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9369 /* Manually jam a srlz.d insn into the stream */
9370 CURR_SLOT.qp_regno = 0;
9371 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9372 data_serialization ();
9373 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9374 if (++md.num_slots_in_use >= NUM_SLOTS)
9376 CURR_SLOT.qp_regno = oldqp;
9377 CURR_SLOT.idesc = oldidesc;
9380 case IA64_DVS_IMPLIED:
9381 case IA64_DVS_IMPLIEDF:
9383 fprintf (stderr, "Inserting stop\n");
9384 insn_group_break (1, 0, 0);
9391 /* Check the resources used by the given opcode against the current dependency
9394 The check is run once for each execution path encountered. In this case,
9395 a unique execution path is the sequence of instructions following a code
9396 entry point, e.g. the following has three execution paths, one starting
9397 at L0, one at L1, and one at L2.
9406 check_dependencies (idesc)
9407 struct ia64_opcode *idesc;
9409 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9413 /* Note that the number of marked resources may change within the
9414 loop if in auto mode. */
9416 while (i < regdepslen)
9418 struct rsrc *rs = ®deps[i];
9419 const struct ia64_dependency *dep = rs->dependency;
9424 if (dep->semantics == IA64_DVS_NONE
9425 || (chkind = depends_on (rs->depind, idesc)) == -1)
9431 note = NOTE (opdeps->chks[chkind]);
9433 /* Check this resource against each execution path seen thus far. */
9434 for (path = 0; path <= md.path; path++)
9438 /* If the dependency wasn't on the path being checked, ignore it. */
9439 if (rs->path < path)
9442 /* If the QP for this insn implies a QP which has branched, don't
9443 bother checking. Ed. NOTE: I don't think this check is terribly
9444 useful; what's the point of generating code which will only be
9445 reached if its QP is zero?
9446 This code was specifically inserted to handle the following code,
9447 based on notes from Intel's DV checking code, where p1 implies p2.
9453 if (CURR_SLOT.qp_regno != 0)
9457 for (implies = 0; implies < qp_implieslen; implies++)
9459 if (qp_implies[implies].path >= path
9460 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9461 && qp_implies[implies].p2_branched)
9471 if ((matchtype = resources_match (rs, idesc, note,
9472 CURR_SLOT.qp_regno, path)) != 0)
9475 char pathmsg[256] = "";
9476 char indexmsg[256] = "";
9477 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9480 sprintf (pathmsg, " when entry is at label '%s'",
9481 md.entry_labels[path - 1]);
9482 if (rs->specific && rs->index != 0)
9483 sprintf (indexmsg, ", specific resource number is %d",
9485 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9487 (certain ? "violates" : "may violate"),
9488 dv_mode[dep->mode], dep->name,
9489 dv_sem[dep->semantics],
9492 if (md.explicit_mode)
9494 as_warn ("%s", msg);
9496 as_warn (_("Only the first path encountering the conflict "
9498 as_warn_where (rs->file, rs->line,
9499 _("This is the location of the "
9500 "conflicting usage"));
9501 /* Don't bother checking other paths, to avoid duplicating
9508 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9510 remove_marked_resource (rs);
9512 /* since the set of dependencies has changed, start over */
9513 /* FIXME -- since we're removing dvs as we go, we
9514 probably don't really need to start over... */
9527 /* Register new dependencies based on the given opcode. */
9530 mark_resources (idesc)
9531 struct ia64_opcode *idesc;
9534 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9535 int add_only_qp_reads = 0;
9537 /* A conditional branch only uses its resources if it is taken; if it is
9538 taken, we stop following that path. The other branch types effectively
9539 *always* write their resources. If it's not taken, register only QP
9541 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9543 add_only_qp_reads = 1;
9547 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9549 for (i = 0; i < opdeps->nregs; i++)
9551 const struct ia64_dependency *dep;
9552 struct rsrc specs[MAX_SPECS];
9557 dep = ia64_find_dependency (opdeps->regs[i]);
9558 note = NOTE (opdeps->regs[i]);
9560 if (add_only_qp_reads
9561 && !(dep->mode == IA64_DV_WAR
9562 && (dep->specifier == IA64_RS_PR
9563 || dep->specifier == IA64_RS_PRr
9564 || dep->specifier == IA64_RS_PR63)))
9567 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9570 if (md.debug_dv && !count)
9571 fprintf (stderr, " No %s %s usage found (path %d)\n",
9572 dv_mode[dep->mode], dep->name, md.path);
9577 mark_resource (idesc, dep, &specs[count],
9578 DEP (opdeps->regs[i]), md.path);
9581 /* The execution path may affect register values, which may in turn
9582 affect which indirect-access resources are accessed. */
9583 switch (dep->specifier)
9595 for (path = 0; path < md.path; path++)
9597 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9599 mark_resource (idesc, dep, &specs[count],
9600 DEP (opdeps->regs[i]), path);
9607 /* Remove dependencies when they no longer apply. */
9610 update_dependencies (idesc)
9611 struct ia64_opcode *idesc;
9615 if (strcmp (idesc->name, "srlz.i") == 0)
9617 instruction_serialization ();
9619 else if (strcmp (idesc->name, "srlz.d") == 0)
9621 data_serialization ();
9623 else if (is_interruption_or_rfi (idesc)
9624 || is_taken_branch (idesc))
9626 /* Although technically the taken branch doesn't clear dependencies
9627 which require a srlz.[id], we don't follow the branch; the next
9628 instruction is assumed to start with a clean slate. */
9632 else if (is_conditional_branch (idesc)
9633 && CURR_SLOT.qp_regno != 0)
9635 int is_call = strstr (idesc->name, ".call") != NULL;
9637 for (i = 0; i < qp_implieslen; i++)
9639 /* If the conditional branch's predicate is implied by the predicate
9640 in an existing dependency, remove that dependency. */
9641 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9644 /* Note that this implied predicate takes a branch so that if
9645 a later insn generates a DV but its predicate implies this
9646 one, we can avoid the false DV warning. */
9647 qp_implies[i].p2_branched = 1;
9648 while (depind < regdepslen)
9650 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9652 print_dependency ("Removing", depind);
9653 regdeps[depind] = regdeps[--regdepslen];
9660 /* Any marked resources which have this same predicate should be
9661 cleared, provided that the QP hasn't been modified between the
9662 marking instruction and the branch. */
9665 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9670 while (i < regdepslen)
9672 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9673 && regdeps[i].link_to_qp_branch
9674 && (regdeps[i].file != CURR_SLOT.src_file
9675 || regdeps[i].line != CURR_SLOT.src_line))
9677 /* Treat like a taken branch */
9678 print_dependency ("Removing", i);
9679 regdeps[i] = regdeps[--regdepslen];
9688 /* Examine the current instruction for dependency violations. */
9692 struct ia64_opcode *idesc;
9696 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9697 idesc->name, CURR_SLOT.src_line,
9698 idesc->dependencies->nchks,
9699 idesc->dependencies->nregs);
9702 /* Look through the list of currently marked resources; if the current
9703 instruction has the dependency in its chks list which uses that resource,
9704 check against the specific resources used. */
9705 check_dependencies (idesc);
9707 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9708 then add them to the list of marked resources. */
9709 mark_resources (idesc);
9711 /* There are several types of dependency semantics, and each has its own
9712 requirements for being cleared
9714 Instruction serialization (insns separated by interruption, rfi, or
9715 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9717 Data serialization (instruction serialization, or writer + srlz.d +
9718 reader, where writer and srlz.d are in separate groups) clears
9719 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9720 always be the case).
9722 Instruction group break (groups separated by stop, taken branch,
9723 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9725 update_dependencies (idesc);
9727 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9728 warning. Keep track of as many as possible that are useful. */
9729 note_register_values (idesc);
9731 /* We don't need or want this anymore. */
9732 md.mem_offset.hint = 0;
9737 /* Translate one line of assembly. Pseudo ops and labels do not show
9743 char *saved_input_line_pointer, *mnemonic;
9744 const struct pseudo_opcode *pdesc;
9745 struct ia64_opcode *idesc;
9746 unsigned char qp_regno;
9750 saved_input_line_pointer = input_line_pointer;
9751 input_line_pointer = str;
9753 /* extract the opcode (mnemonic): */
9755 mnemonic = input_line_pointer;
9756 ch = get_symbol_end ();
9757 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9760 *input_line_pointer = ch;
9761 (*pdesc->handler) (pdesc->arg);
9765 /* Find the instruction descriptor matching the arguments. */
9767 idesc = ia64_find_opcode (mnemonic);
9768 *input_line_pointer = ch;
9771 as_bad ("Unknown opcode `%s'", mnemonic);
9775 idesc = parse_operands (idesc);
9779 /* Handle the dynamic ops we can handle now: */
9780 if (idesc->type == IA64_TYPE_DYN)
9782 if (strcmp (idesc->name, "add") == 0)
9784 if (CURR_SLOT.opnd[2].X_op == O_register
9785 && CURR_SLOT.opnd[2].X_add_number < 4)
9789 ia64_free_opcode (idesc);
9790 idesc = ia64_find_opcode (mnemonic);
9792 know (!idesc->next);
9795 else if (strcmp (idesc->name, "mov") == 0)
9797 enum ia64_opnd opnd1, opnd2;
9800 opnd1 = idesc->operands[0];
9801 opnd2 = idesc->operands[1];
9802 if (opnd1 == IA64_OPND_AR3)
9804 else if (opnd2 == IA64_OPND_AR3)
9808 if (CURR_SLOT.opnd[rop].X_op == O_register
9809 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9813 ia64_free_opcode (idesc);
9814 idesc = ia64_find_opcode (mnemonic);
9815 while (idesc != NULL
9816 && (idesc->operands[0] != opnd1
9817 || idesc->operands[1] != opnd2))
9818 idesc = get_next_opcode (idesc);
9823 if (md.qp.X_op == O_register)
9825 qp_regno = md.qp.X_add_number - REG_P;
9826 md.qp.X_op = O_absent;
9829 flags = idesc->flags;
9831 if ((flags & IA64_OPCODE_FIRST) != 0)
9832 insn_group_break (1, 0, 0);
9834 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
9836 as_bad ("`%s' cannot be predicated", idesc->name);
9840 /* Build the instruction. */
9841 CURR_SLOT.qp_regno = qp_regno;
9842 CURR_SLOT.idesc = idesc;
9843 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
9844 dwarf2_where (&CURR_SLOT.debug_line);
9846 /* Add unwind entry, if there is one. */
9847 if (unwind.current_entry)
9849 CURR_SLOT.unwind_record = unwind.current_entry;
9850 unwind.current_entry = NULL;
9853 /* Check for dependency violations. */
9857 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9858 if (++md.num_slots_in_use >= NUM_SLOTS)
9861 if ((flags & IA64_OPCODE_LAST) != 0)
9862 insn_group_break (1, 0, 0);
9864 md.last_text_seg = now_seg;
9867 input_line_pointer = saved_input_line_pointer;
9870 /* Called when symbol NAME cannot be found in the symbol table.
9871 Should be used for dynamic valued symbols only. */
9874 md_undefined_symbol (name)
9875 char *name ATTRIBUTE_UNUSED;
9880 /* Called for any expression that can not be recognized. When the
9881 function is called, `input_line_pointer' will point to the start of
9888 enum pseudo_type pseudo_type;
9893 switch (*input_line_pointer)
9896 /* Find what relocation pseudo-function we're dealing with. */
9898 ch = *++input_line_pointer;
9899 for (i = 0; i < NELEMS (pseudo_func); ++i)
9900 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
9902 len = strlen (pseudo_func[i].name);
9903 if (strncmp (pseudo_func[i].name + 1,
9904 input_line_pointer + 1, len - 1) == 0
9905 && !is_part_of_name (input_line_pointer[len]))
9907 input_line_pointer += len;
9908 pseudo_type = pseudo_func[i].type;
9912 switch (pseudo_type)
9914 case PSEUDO_FUNC_RELOC:
9916 if (*input_line_pointer != '(')
9918 as_bad ("Expected '('");
9922 ++input_line_pointer;
9924 if (*input_line_pointer++ != ')')
9926 as_bad ("Missing ')'");
9929 if (e->X_op != O_symbol)
9931 if (e->X_op != O_pseudo_fixup)
9933 as_bad ("Not a symbolic expression");
9936 if (i != FUNC_LT_RELATIVE)
9938 as_bad ("Illegal combination of relocation functions");
9941 switch (S_GET_VALUE (e->X_op_symbol))
9943 case FUNC_FPTR_RELATIVE:
9944 i = FUNC_LT_FPTR_RELATIVE; break;
9945 case FUNC_DTP_MODULE:
9946 i = FUNC_LT_DTP_MODULE; break;
9947 case FUNC_DTP_RELATIVE:
9948 i = FUNC_LT_DTP_RELATIVE; break;
9949 case FUNC_TP_RELATIVE:
9950 i = FUNC_LT_TP_RELATIVE; break;
9952 as_bad ("Illegal combination of relocation functions");
9956 /* Make sure gas doesn't get rid of local symbols that are used
9958 e->X_op = O_pseudo_fixup;
9959 e->X_op_symbol = pseudo_func[i].u.sym;
9962 case PSEUDO_FUNC_CONST:
9963 e->X_op = O_constant;
9964 e->X_add_number = pseudo_func[i].u.ival;
9967 case PSEUDO_FUNC_REG:
9968 e->X_op = O_register;
9969 e->X_add_number = pseudo_func[i].u.ival;
9973 name = input_line_pointer - 1;
9975 as_bad ("Unknown pseudo function `%s'", name);
9981 ++input_line_pointer;
9983 if (*input_line_pointer != ']')
9985 as_bad ("Closing bracket misssing");
9990 if (e->X_op != O_register)
9991 as_bad ("Register expected as index");
9993 ++input_line_pointer;
10004 ignore_rest_of_line ();
10007 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10008 a section symbol plus some offset. For relocs involving @fptr(),
10009 directives we don't want such adjustments since we need to have the
10010 original symbol's name in the reloc. */
10012 ia64_fix_adjustable (fix)
10015 /* Prevent all adjustments to global symbols */
10016 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10019 switch (fix->fx_r_type)
10021 case BFD_RELOC_IA64_FPTR64I:
10022 case BFD_RELOC_IA64_FPTR32MSB:
10023 case BFD_RELOC_IA64_FPTR32LSB:
10024 case BFD_RELOC_IA64_FPTR64MSB:
10025 case BFD_RELOC_IA64_FPTR64LSB:
10026 case BFD_RELOC_IA64_LTOFF_FPTR22:
10027 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10037 ia64_force_relocation (fix)
10040 switch (fix->fx_r_type)
10042 case BFD_RELOC_IA64_FPTR64I:
10043 case BFD_RELOC_IA64_FPTR32MSB:
10044 case BFD_RELOC_IA64_FPTR32LSB:
10045 case BFD_RELOC_IA64_FPTR64MSB:
10046 case BFD_RELOC_IA64_FPTR64LSB:
10048 case BFD_RELOC_IA64_LTOFF22:
10049 case BFD_RELOC_IA64_LTOFF64I:
10050 case BFD_RELOC_IA64_LTOFF_FPTR22:
10051 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10052 case BFD_RELOC_IA64_PLTOFF22:
10053 case BFD_RELOC_IA64_PLTOFF64I:
10054 case BFD_RELOC_IA64_PLTOFF64MSB:
10055 case BFD_RELOC_IA64_PLTOFF64LSB:
10057 case BFD_RELOC_IA64_LTOFF22X:
10058 case BFD_RELOC_IA64_LDXMOV:
10065 return generic_force_reloc (fix);
10068 /* Decide from what point a pc-relative relocation is relative to,
10069 relative to the pc-relative fixup. Er, relatively speaking. */
10071 ia64_pcrel_from_section (fix, sec)
10075 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10077 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10084 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10086 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10090 expr.X_op = O_pseudo_fixup;
10091 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10092 expr.X_add_number = 0;
10093 expr.X_add_symbol = symbol;
10094 emit_expr (&expr, size);
10097 /* This is called whenever some data item (not an instruction) needs a
10098 fixup. We pick the right reloc code depending on the byteorder
10099 currently in effect. */
10101 ia64_cons_fix_new (f, where, nbytes, exp)
10107 bfd_reloc_code_real_type code;
10112 /* There are no reloc for 8 and 16 bit quantities, but we allow
10113 them here since they will work fine as long as the expression
10114 is fully defined at the end of the pass over the source file. */
10115 case 1: code = BFD_RELOC_8; break;
10116 case 2: code = BFD_RELOC_16; break;
10118 if (target_big_endian)
10119 code = BFD_RELOC_IA64_DIR32MSB;
10121 code = BFD_RELOC_IA64_DIR32LSB;
10125 /* In 32-bit mode, data8 could mean function descriptors too. */
10126 if (exp->X_op == O_pseudo_fixup
10127 && exp->X_op_symbol
10128 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10129 && !(md.flags & EF_IA_64_ABI64))
10131 if (target_big_endian)
10132 code = BFD_RELOC_IA64_IPLTMSB;
10134 code = BFD_RELOC_IA64_IPLTLSB;
10135 exp->X_op = O_symbol;
10140 if (target_big_endian)
10141 code = BFD_RELOC_IA64_DIR64MSB;
10143 code = BFD_RELOC_IA64_DIR64LSB;
10148 if (exp->X_op == O_pseudo_fixup
10149 && exp->X_op_symbol
10150 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10152 if (target_big_endian)
10153 code = BFD_RELOC_IA64_IPLTMSB;
10155 code = BFD_RELOC_IA64_IPLTLSB;
10156 exp->X_op = O_symbol;
10162 as_bad ("Unsupported fixup size %d", nbytes);
10163 ignore_rest_of_line ();
10167 if (exp->X_op == O_pseudo_fixup)
10169 exp->X_op = O_symbol;
10170 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10171 /* ??? If code unchanged, unsupported. */
10174 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10175 /* We need to store the byte order in effect in case we're going
10176 to fix an 8 or 16 bit relocation (for which there no real
10177 relocs available). See md_apply_fix3(). */
10178 fix->tc_fix_data.bigendian = target_big_endian;
10181 /* Return the actual relocation we wish to associate with the pseudo
10182 reloc described by SYM and R_TYPE. SYM should be one of the
10183 symbols in the pseudo_func array, or NULL. */
10185 static bfd_reloc_code_real_type
10186 ia64_gen_real_reloc_type (sym, r_type)
10187 struct symbol *sym;
10188 bfd_reloc_code_real_type r_type;
10190 bfd_reloc_code_real_type new = 0;
10197 switch (S_GET_VALUE (sym))
10199 case FUNC_FPTR_RELATIVE:
10202 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10203 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10204 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10205 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10206 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10211 case FUNC_GP_RELATIVE:
10214 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10215 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10216 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10217 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10218 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10219 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10224 case FUNC_LT_RELATIVE:
10227 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10228 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10233 case FUNC_LT_RELATIVE_X:
10236 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10241 case FUNC_PC_RELATIVE:
10244 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10245 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10246 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10247 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10248 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10249 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10254 case FUNC_PLT_RELATIVE:
10257 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10258 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10259 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10260 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10265 case FUNC_SEC_RELATIVE:
10268 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10269 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10270 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10271 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10276 case FUNC_SEG_RELATIVE:
10279 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10280 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10281 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10282 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10287 case FUNC_LTV_RELATIVE:
10290 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10291 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10292 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10293 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10298 case FUNC_LT_FPTR_RELATIVE:
10301 case BFD_RELOC_IA64_IMM22:
10302 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10303 case BFD_RELOC_IA64_IMM64:
10304 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10310 case FUNC_TP_RELATIVE:
10313 case BFD_RELOC_IA64_IMM14:
10314 new = BFD_RELOC_IA64_TPREL14; break;
10315 case BFD_RELOC_IA64_IMM22:
10316 new = BFD_RELOC_IA64_TPREL22; break;
10317 case BFD_RELOC_IA64_IMM64:
10318 new = BFD_RELOC_IA64_TPREL64I; break;
10324 case FUNC_LT_TP_RELATIVE:
10327 case BFD_RELOC_IA64_IMM22:
10328 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10334 case FUNC_LT_DTP_MODULE:
10337 case BFD_RELOC_IA64_IMM22:
10338 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10344 case FUNC_DTP_RELATIVE:
10347 case BFD_RELOC_IA64_DIR64MSB:
10348 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10349 case BFD_RELOC_IA64_DIR64LSB:
10350 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10351 case BFD_RELOC_IA64_IMM14:
10352 new = BFD_RELOC_IA64_DTPREL14; break;
10353 case BFD_RELOC_IA64_IMM22:
10354 new = BFD_RELOC_IA64_DTPREL22; break;
10355 case BFD_RELOC_IA64_IMM64:
10356 new = BFD_RELOC_IA64_DTPREL64I; break;
10362 case FUNC_LT_DTP_RELATIVE:
10365 case BFD_RELOC_IA64_IMM22:
10366 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10372 case FUNC_IPLT_RELOC:
10379 /* Hmmmm. Should this ever occur? */
10386 /* Here is where generate the appropriate reloc for pseudo relocation
10389 ia64_validate_fix (fix)
10392 switch (fix->fx_r_type)
10394 case BFD_RELOC_IA64_FPTR64I:
10395 case BFD_RELOC_IA64_FPTR32MSB:
10396 case BFD_RELOC_IA64_FPTR64LSB:
10397 case BFD_RELOC_IA64_LTOFF_FPTR22:
10398 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10399 if (fix->fx_offset != 0)
10400 as_bad_where (fix->fx_file, fix->fx_line,
10401 "No addend allowed in @fptr() relocation");
10411 fix_insn (fix, odesc, value)
10413 const struct ia64_operand *odesc;
10416 bfd_vma insn[3], t0, t1, control_bits;
10421 slot = fix->fx_where & 0x3;
10422 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10424 /* Bundles are always in little-endian byte order */
10425 t0 = bfd_getl64 (fixpos);
10426 t1 = bfd_getl64 (fixpos + 8);
10427 control_bits = t0 & 0x1f;
10428 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10429 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10430 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10433 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10435 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10436 insn[2] |= (((value & 0x7f) << 13)
10437 | (((value >> 7) & 0x1ff) << 27)
10438 | (((value >> 16) & 0x1f) << 22)
10439 | (((value >> 21) & 0x1) << 21)
10440 | (((value >> 63) & 0x1) << 36));
10442 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10444 if (value & ~0x3fffffffffffffffULL)
10445 err = "integer operand out of range";
10446 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10447 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10449 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10452 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10453 insn[2] |= ((((value >> 59) & 0x1) << 36)
10454 | (((value >> 0) & 0xfffff) << 13));
10457 err = (*odesc->insert) (odesc, value, insn + slot);
10460 as_bad_where (fix->fx_file, fix->fx_line, err);
10462 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10463 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10464 number_to_chars_littleendian (fixpos + 0, t0, 8);
10465 number_to_chars_littleendian (fixpos + 8, t1, 8);
10468 /* Attempt to simplify or even eliminate a fixup. The return value is
10469 ignored; perhaps it was once meaningful, but now it is historical.
10470 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10472 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10476 md_apply_fix3 (fix, valP, seg)
10479 segT seg ATTRIBUTE_UNUSED;
10482 valueT value = *valP;
10484 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10488 switch (fix->fx_r_type)
10490 case BFD_RELOC_IA64_DIR32MSB:
10491 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10494 case BFD_RELOC_IA64_DIR32LSB:
10495 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10498 case BFD_RELOC_IA64_DIR64MSB:
10499 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10502 case BFD_RELOC_IA64_DIR64LSB:
10503 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10512 switch (fix->fx_r_type)
10514 case BFD_RELOC_UNUSED:
10515 /* This must be a TAG13 or TAG13b operand. There are no external
10516 relocs defined for them, so we must give an error. */
10517 as_bad_where (fix->fx_file, fix->fx_line,
10518 "%s must have a constant value",
10519 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10523 case BFD_RELOC_IA64_TPREL14:
10524 case BFD_RELOC_IA64_TPREL22:
10525 case BFD_RELOC_IA64_TPREL64I:
10526 case BFD_RELOC_IA64_LTOFF_TPREL22:
10527 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10528 case BFD_RELOC_IA64_DTPREL14:
10529 case BFD_RELOC_IA64_DTPREL22:
10530 case BFD_RELOC_IA64_DTPREL64I:
10531 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10532 S_SET_THREAD_LOCAL (fix->fx_addsy);
10539 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10541 if (fix->tc_fix_data.bigendian)
10542 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10544 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10549 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10554 /* Generate the BFD reloc to be stuck in the object file from the
10555 fixup used internally in the assembler. */
10558 tc_gen_reloc (sec, fixp)
10559 asection *sec ATTRIBUTE_UNUSED;
10564 reloc = xmalloc (sizeof (*reloc));
10565 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10566 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10567 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10568 reloc->addend = fixp->fx_offset;
10569 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10573 as_bad_where (fixp->fx_file, fixp->fx_line,
10574 "Cannot represent %s relocation in object file",
10575 bfd_get_reloc_code_name (fixp->fx_r_type));
10580 /* Turn a string in input_line_pointer into a floating point constant
10581 of type TYPE, and store the appropriate bytes in *LIT. The number
10582 of LITTLENUMS emitted is stored in *SIZE. An error message is
10583 returned, or NULL on OK. */
10585 #define MAX_LITTLENUMS 5
10588 md_atof (type, lit, size)
10593 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10623 return "Bad call to MD_ATOF()";
10625 t = atof_ieee (input_line_pointer, type, words);
10627 input_line_pointer = t;
10629 (*ia64_float_to_chars) (lit, words, prec);
10633 /* It is 10 byte floating point with 6 byte padding. */
10634 memset (&lit [10], 0, 6);
10635 *size = 8 * sizeof (LITTLENUM_TYPE);
10638 *size = prec * sizeof (LITTLENUM_TYPE);
10643 /* Handle ia64 specific semantics of the align directive. */
10646 ia64_md_do_align (n, fill, len, max)
10647 int n ATTRIBUTE_UNUSED;
10648 const char *fill ATTRIBUTE_UNUSED;
10649 int len ATTRIBUTE_UNUSED;
10650 int max ATTRIBUTE_UNUSED;
10652 if (subseg_text_p (now_seg))
10653 ia64_flush_insns ();
10656 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10657 of an rs_align_code fragment. */
10660 ia64_handle_align (fragp)
10663 /* Use mfi bundle of nops with no stop bits. */
10664 static const unsigned char be_nop[]
10665 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
10666 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
10667 static const unsigned char le_nop[]
10668 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10669 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10674 if (fragp->fr_type != rs_align_code)
10677 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10678 p = fragp->fr_literal + fragp->fr_fix;
10680 /* Make sure we are on a 16-byte boundary, in case someone has been
10681 putting data into a text section. */
10684 int fix = bytes & 15;
10685 memset (p, 0, fix);
10688 fragp->fr_fix += fix;
10691 memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
10692 fragp->fr_var = 16;
10696 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
10701 number_to_chars_bigendian (lit, (long) (*words++),
10702 sizeof (LITTLENUM_TYPE));
10703 lit += sizeof (LITTLENUM_TYPE);
10708 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
10713 number_to_chars_littleendian (lit, (long) (words[prec]),
10714 sizeof (LITTLENUM_TYPE));
10715 lit += sizeof (LITTLENUM_TYPE);
10720 ia64_elf_section_change_hook (void)
10722 dot_byteorder (-1);
10725 /* Check if a label should be made global. */
10727 ia64_check_label (symbolS *label)
10729 if (*input_line_pointer == ':')
10731 S_SET_EXTERNAL (label);
10732 input_line_pointer++;