1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
34 - labels are wrong if automatic alignment is introduced
35 (e.g., checkout the second real10 definition in test-data.s)
37 <reg>.safe_across_calls and any other DV-related directives I don't
38 have documentation for.
39 verify mod-sched-brs reads/writes are checked/marked (and other
45 #include "safe-ctype.h"
46 #include "dwarf2dbg.h"
49 #include "opcode/ia64.h"
53 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
54 #define MIN(a,b) ((a) < (b) ? (a) : (b))
57 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
58 #define CURR_SLOT md.slot[md.curr_slot]
60 #define O_pseudo_fixup (O_max + 1)
64 /* IA-64 ABI section pseudo-ops. */
65 SPECIAL_SECTION_BSS = 0,
67 SPECIAL_SECTION_SDATA,
68 SPECIAL_SECTION_RODATA,
69 SPECIAL_SECTION_COMMENT,
70 SPECIAL_SECTION_UNWIND,
71 SPECIAL_SECTION_UNWIND_INFO,
72 /* HPUX specific section pseudo-ops. */
73 SPECIAL_SECTION_INIT_ARRAY,
74 SPECIAL_SECTION_FINI_ARRAY,
91 FUNC_LT_FPTR_RELATIVE,
101 REG_FR = (REG_GR + 128),
102 REG_AR = (REG_FR + 128),
103 REG_CR = (REG_AR + 128),
104 REG_P = (REG_CR + 128),
105 REG_BR = (REG_P + 64),
106 REG_IP = (REG_BR + 8),
113 /* The following are pseudo-registers for use by gas only. */
125 /* The following pseudo-registers are used for unwind directives only: */
133 DYNREG_GR = 0, /* dynamic general purpose register */
134 DYNREG_FR, /* dynamic floating point register */
135 DYNREG_PR, /* dynamic predicate register */
139 enum operand_match_result
142 OPERAND_OUT_OF_RANGE,
146 /* On the ia64, we can't know the address of a text label until the
147 instructions are packed into a bundle. To handle this, we keep
148 track of the list of labels that appear in front of each
152 struct label_fix *next;
156 extern int target_big_endian;
158 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
160 static void ia64_float_to_chars_bigendian
161 PARAMS ((char *, LITTLENUM_TYPE *, int));
162 static void ia64_float_to_chars_littleendian
163 PARAMS ((char *, LITTLENUM_TYPE *, int));
164 static void (*ia64_float_to_chars)
165 PARAMS ((char *, LITTLENUM_TYPE *, int));
167 static struct hash_control *alias_hash;
168 static struct hash_control *alias_name_hash;
169 static struct hash_control *secalias_hash;
170 static struct hash_control *secalias_name_hash;
172 /* Characters which always start a comment. */
173 const char comment_chars[] = "";
175 /* Characters which start a comment at the beginning of a line. */
176 const char line_comment_chars[] = "#";
178 /* Characters which may be used to separate multiple commands on a
180 const char line_separator_chars[] = ";";
182 /* Characters which are used to indicate an exponent in a floating
184 const char EXP_CHARS[] = "eE";
186 /* Characters which mean that a number is a floating point constant,
188 const char FLT_CHARS[] = "rRsSfFdDxXpP";
190 /* ia64-specific option processing: */
192 const char *md_shortopts = "m:N:x::";
194 struct option md_longopts[] =
196 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
197 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
198 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
199 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
202 size_t md_longopts_size = sizeof (md_longopts);
206 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
207 struct hash_control *reg_hash; /* register name hash table */
208 struct hash_control *dynreg_hash; /* dynamic register hash table */
209 struct hash_control *const_hash; /* constant hash table */
210 struct hash_control *entry_hash; /* code entry hint hash table */
212 symbolS *regsym[REG_NUM];
214 /* If X_op is != O_absent, the registername for the instruction's
215 qualifying predicate. If NULL, p0 is assumed for instructions
216 that are predicatable. */
223 explicit_mode : 1, /* which mode we're in */
224 default_explicit_mode : 1, /* which mode is the default */
225 mode_explicitly_set : 1, /* was the current mode explicitly set? */
227 keep_pending_output : 1;
229 /* Each bundle consists of up to three instructions. We keep
230 track of four most recent instructions so we can correctly set
231 the end_of_insn_group for the last instruction in a bundle. */
233 int num_slots_in_use;
237 end_of_insn_group : 1,
238 manual_bundling_on : 1,
239 manual_bundling_off : 1;
240 signed char user_template; /* user-selected template, if any */
241 unsigned char qp_regno; /* qualifying predicate */
242 /* This duplicates a good fraction of "struct fix" but we
243 can't use a "struct fix" instead since we can't call
244 fix_new_exp() until we know the address of the instruction. */
248 bfd_reloc_code_real_type code;
249 enum ia64_opnd opnd; /* type of operand in need of fix */
250 unsigned int is_pcrel : 1; /* is operand pc-relative? */
251 expressionS expr; /* the value to be inserted */
253 fixup[2]; /* at most two fixups per insn */
254 struct ia64_opcode *idesc;
255 struct label_fix *label_fixups;
256 struct label_fix *tag_fixups;
257 struct unw_rec_list *unwind_record; /* Unwind directive. */
260 unsigned int src_line;
261 struct dwarf2_line_info debug_line;
269 struct dynreg *next; /* next dynamic register */
271 unsigned short base; /* the base register number */
272 unsigned short num_regs; /* # of registers in this set */
274 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
276 flagword flags; /* ELF-header flags */
279 unsigned hint:1; /* is this hint currently valid? */
280 bfd_vma offset; /* mem.offset offset */
281 bfd_vma base; /* mem.offset base */
284 int path; /* number of alt. entry points seen */
285 const char **entry_labels; /* labels of all alternate paths in
286 the current DV-checking block. */
287 int maxpaths; /* size currently allocated for
289 /* Support for hardware errata workarounds. */
291 /* Record data about the last three insn groups. */
294 /* B-step workaround.
295 For each predicate register, this is set if the corresponding insn
296 group conditionally sets this register with one of the affected
299 /* B-step workaround.
300 For each general register, this is set if the corresponding insn
301 a) is conditional one one of the predicate registers for which
302 P_REG_SET is 1 in the corresponding entry of the previous group,
303 b) sets this general register with one of the affected
305 int g_reg_set_conditionally[128];
309 int pointer_size; /* size in bytes of a pointer */
310 int pointer_size_shift; /* shift size of a pointer for alignment */
314 /* application registers: */
320 #define AR_BSPSTORE 18
335 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
336 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
337 {"ar.rsc", 16}, {"ar.bsp", 17},
338 {"ar.bspstore", 18}, {"ar.rnat", 19},
339 {"ar.fcr", 21}, {"ar.eflag", 24},
340 {"ar.csd", 25}, {"ar.ssd", 26},
341 {"ar.cflg", 27}, {"ar.fsr", 28},
342 {"ar.fir", 29}, {"ar.fdr", 30},
343 {"ar.ccv", 32}, {"ar.unat", 36},
344 {"ar.fpsr", 40}, {"ar.itc", 44},
345 {"ar.pfs", 64}, {"ar.lc", 65},
366 /* control registers: */
408 static const struct const_desc
415 /* PSR constant masks: */
418 {"psr.be", ((valueT) 1) << 1},
419 {"psr.up", ((valueT) 1) << 2},
420 {"psr.ac", ((valueT) 1) << 3},
421 {"psr.mfl", ((valueT) 1) << 4},
422 {"psr.mfh", ((valueT) 1) << 5},
424 {"psr.ic", ((valueT) 1) << 13},
425 {"psr.i", ((valueT) 1) << 14},
426 {"psr.pk", ((valueT) 1) << 15},
428 {"psr.dt", ((valueT) 1) << 17},
429 {"psr.dfl", ((valueT) 1) << 18},
430 {"psr.dfh", ((valueT) 1) << 19},
431 {"psr.sp", ((valueT) 1) << 20},
432 {"psr.pp", ((valueT) 1) << 21},
433 {"psr.di", ((valueT) 1) << 22},
434 {"psr.si", ((valueT) 1) << 23},
435 {"psr.db", ((valueT) 1) << 24},
436 {"psr.lp", ((valueT) 1) << 25},
437 {"psr.tb", ((valueT) 1) << 26},
438 {"psr.rt", ((valueT) 1) << 27},
439 /* 28-31: reserved */
440 /* 32-33: cpl (current privilege level) */
441 {"psr.is", ((valueT) 1) << 34},
442 {"psr.mc", ((valueT) 1) << 35},
443 {"psr.it", ((valueT) 1) << 36},
444 {"psr.id", ((valueT) 1) << 37},
445 {"psr.da", ((valueT) 1) << 38},
446 {"psr.dd", ((valueT) 1) << 39},
447 {"psr.ss", ((valueT) 1) << 40},
448 /* 41-42: ri (restart instruction) */
449 {"psr.ed", ((valueT) 1) << 43},
450 {"psr.bn", ((valueT) 1) << 44},
453 /* indirect register-sets/memory: */
462 { "CPUID", IND_CPUID },
463 { "cpuid", IND_CPUID },
475 /* Pseudo functions used to indicate relocation types (these functions
476 start with an at sign (@). */
498 /* reloc pseudo functions (these must come first!): */
499 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
500 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
501 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
502 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
503 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
504 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
505 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
506 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
507 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
508 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
509 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
510 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
511 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
512 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
513 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
514 { "", 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
515 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
517 /* mbtype4 constants: */
518 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
519 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
520 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
521 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
522 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
524 /* fclass constants: */
525 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
526 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
527 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
528 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
529 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
530 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
531 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
532 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
533 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
535 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
537 /* hint constants: */
538 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
540 /* unwind-related constants: */
541 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
542 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
543 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
544 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
545 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
546 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
547 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
549 /* unwind-related registers: */
550 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
553 /* 41-bit nop opcodes (one per unit): */
554 static const bfd_vma nop[IA64_NUM_UNITS] =
556 0x0000000000LL, /* NIL => break 0 */
557 0x0008000000LL, /* I-unit nop */
558 0x0008000000LL, /* M-unit nop */
559 0x4000000000LL, /* B-unit nop */
560 0x0008000000LL, /* F-unit nop */
561 0x0008000000LL, /* L-"unit" nop */
562 0x0008000000LL, /* X-unit nop */
565 /* Can't be `const' as it's passed to input routines (which have the
566 habit of setting temporary sentinels. */
567 static char special_section_name[][20] =
569 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
570 {".IA_64.unwind"}, {".IA_64.unwind_info"},
571 {".init_array"}, {".fini_array"}
574 static char *special_linkonce_name[] =
576 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
579 /* The best template for a particular sequence of up to three
581 #define N IA64_NUM_TYPES
582 static unsigned char best_template[N][N][N];
585 /* Resource dependencies currently in effect */
587 int depind; /* dependency index */
588 const struct ia64_dependency *dependency; /* actual dependency */
589 unsigned specific:1, /* is this a specific bit/regno? */
590 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
591 int index; /* specific regno/bit within dependency */
592 int note; /* optional qualifying note (0 if none) */
596 int insn_srlz; /* current insn serialization state */
597 int data_srlz; /* current data serialization state */
598 int qp_regno; /* qualifying predicate for this usage */
599 char *file; /* what file marked this dependency */
600 unsigned int line; /* what line marked this dependency */
601 struct mem_offset mem_offset; /* optional memory offset hint */
602 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
603 int path; /* corresponding code entry index */
605 static int regdepslen = 0;
606 static int regdepstotlen = 0;
607 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
608 static const char *dv_sem[] = { "none", "implied", "impliedf",
609 "data", "instr", "specific", "stop", "other" };
610 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
612 /* Current state of PR mutexation */
613 static struct qpmutex {
616 } *qp_mutexes = NULL; /* QP mutex bitmasks */
617 static int qp_mutexeslen = 0;
618 static int qp_mutexestotlen = 0;
619 static valueT qp_safe_across_calls = 0;
621 /* Current state of PR implications */
622 static struct qp_imply {
625 unsigned p2_branched:1;
627 } *qp_implies = NULL;
628 static int qp_implieslen = 0;
629 static int qp_impliestotlen = 0;
631 /* Keep track of static GR values so that indirect register usage can
632 sometimes be tracked. */
637 } gr_values[128] = {{ 1, 0, 0 }};
639 /* These are the routines required to output the various types of
642 /* A slot_number is a frag address plus the slot index (0-2). We use the
643 frag address here so that if there is a section switch in the middle of
644 a function, then instructions emitted to a different section are not
645 counted. Since there may be more than one frag for a function, this
646 means we also need to keep track of which frag this address belongs to
647 so we can compute inter-frag distances. This also nicely solves the
648 problem with nops emitted for align directives, which can't easily be
649 counted, but can easily be derived from frag sizes. */
651 typedef struct unw_rec_list {
653 unsigned long slot_number;
655 struct unw_rec_list *next;
658 #define SLOT_NUM_NOT_SET (unsigned)-1
660 /* Linked list of saved prologue counts. A very poor
661 implementation of a map from label numbers to prologue counts. */
662 typedef struct label_prologue_count
664 struct label_prologue_count *next;
665 unsigned long label_number;
666 unsigned int prologue_count;
667 } label_prologue_count;
671 unsigned long next_slot_number;
672 fragS *next_slot_frag;
674 /* Maintain a list of unwind entries for the current function. */
678 /* Any unwind entires that should be attached to the current slot
679 that an insn is being constructed for. */
680 unw_rec_list *current_entry;
682 /* These are used to create the unwind table entry for this function. */
685 symbolS *info; /* pointer to unwind info */
686 symbolS *personality_routine;
688 subsegT saved_text_subseg;
689 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
691 /* TRUE if processing unwind directives in a prologue region. */
694 unsigned int prologue_count; /* number of .prologues seen so far */
695 /* Prologue counts at previous .label_state directives. */
696 struct label_prologue_count * saved_prologue_counts;
699 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
701 /* Forward delarations: */
702 static int ar_is_in_integer_unit PARAMS ((int regnum));
703 static void set_section PARAMS ((char *name));
704 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
705 unsigned int, unsigned int));
706 static void dot_radix PARAMS ((int));
707 static void dot_special_section PARAMS ((int));
708 static void dot_proc PARAMS ((int));
709 static void dot_fframe PARAMS ((int));
710 static void dot_vframe PARAMS ((int));
711 static void dot_vframesp PARAMS ((int));
712 static void dot_vframepsp PARAMS ((int));
713 static void dot_save PARAMS ((int));
714 static void dot_restore PARAMS ((int));
715 static void dot_restorereg PARAMS ((int));
716 static void dot_restorereg_p PARAMS ((int));
717 static void dot_handlerdata PARAMS ((int));
718 static void dot_unwentry PARAMS ((int));
719 static void dot_altrp PARAMS ((int));
720 static void dot_savemem PARAMS ((int));
721 static void dot_saveg PARAMS ((int));
722 static void dot_savef PARAMS ((int));
723 static void dot_saveb PARAMS ((int));
724 static void dot_savegf PARAMS ((int));
725 static void dot_spill PARAMS ((int));
726 static void dot_spillreg PARAMS ((int));
727 static void dot_spillmem PARAMS ((int));
728 static void dot_spillreg_p PARAMS ((int));
729 static void dot_spillmem_p PARAMS ((int));
730 static void dot_label_state PARAMS ((int));
731 static void dot_copy_state PARAMS ((int));
732 static void dot_unwabi PARAMS ((int));
733 static void dot_personality PARAMS ((int));
734 static void dot_body PARAMS ((int));
735 static void dot_prologue PARAMS ((int));
736 static void dot_endp PARAMS ((int));
737 static void dot_template PARAMS ((int));
738 static void dot_regstk PARAMS ((int));
739 static void dot_rot PARAMS ((int));
740 static void dot_byteorder PARAMS ((int));
741 static void dot_psr PARAMS ((int));
742 static void dot_alias PARAMS ((int));
743 static void dot_ln PARAMS ((int));
744 static char *parse_section_name PARAMS ((void));
745 static void dot_xdata PARAMS ((int));
746 static void stmt_float_cons PARAMS ((int));
747 static void stmt_cons_ua PARAMS ((int));
748 static void dot_xfloat_cons PARAMS ((int));
749 static void dot_xstringer PARAMS ((int));
750 static void dot_xdata_ua PARAMS ((int));
751 static void dot_xfloat_cons_ua PARAMS ((int));
752 static void print_prmask PARAMS ((valueT mask));
753 static void dot_pred_rel PARAMS ((int));
754 static void dot_reg_val PARAMS ((int));
755 static void dot_dv_mode PARAMS ((int));
756 static void dot_entry PARAMS ((int));
757 static void dot_mem_offset PARAMS ((int));
758 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
759 static symbolS *declare_register PARAMS ((const char *name, int regnum));
760 static void declare_register_set PARAMS ((const char *, int, int));
761 static unsigned int operand_width PARAMS ((enum ia64_opnd));
762 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
765 static int parse_operand PARAMS ((expressionS *e));
766 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
767 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
768 static void build_insn PARAMS ((struct slot *, bfd_vma *));
769 static void emit_one_bundle PARAMS ((void));
770 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
771 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
772 bfd_reloc_code_real_type r_type));
773 static void insn_group_break PARAMS ((int, int, int));
774 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
775 struct rsrc *, int depind, int path));
776 static void add_qp_mutex PARAMS((valueT mask));
777 static void add_qp_imply PARAMS((int p1, int p2));
778 static void clear_qp_branch_flag PARAMS((valueT mask));
779 static void clear_qp_mutex PARAMS((valueT mask));
780 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
781 static int has_suffix_p PARAMS((const char *, const char *));
782 static void clear_register_values PARAMS ((void));
783 static void print_dependency PARAMS ((const char *action, int depind));
784 static void instruction_serialization PARAMS ((void));
785 static void data_serialization PARAMS ((void));
786 static void remove_marked_resource PARAMS ((struct rsrc *));
787 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
788 static int is_taken_branch PARAMS ((struct ia64_opcode *));
789 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
790 static int depends_on PARAMS ((int, struct ia64_opcode *));
791 static int specify_resource PARAMS ((const struct ia64_dependency *,
792 struct ia64_opcode *, int, struct rsrc [], int, int));
793 static int check_dv PARAMS((struct ia64_opcode *idesc));
794 static void check_dependencies PARAMS((struct ia64_opcode *));
795 static void mark_resources PARAMS((struct ia64_opcode *));
796 static void update_dependencies PARAMS((struct ia64_opcode *));
797 static void note_register_values PARAMS((struct ia64_opcode *));
798 static int qp_mutex PARAMS ((int, int, int));
799 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
800 static void output_vbyte_mem PARAMS ((int, char *, char *));
801 static void count_output PARAMS ((int, char *, char *));
802 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
803 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
804 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
805 static void output_P1_format PARAMS ((vbyte_func, int));
806 static void output_P2_format PARAMS ((vbyte_func, int, int));
807 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
808 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
809 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
810 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
811 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
812 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
813 static void output_P9_format PARAMS ((vbyte_func, int, int));
814 static void output_P10_format PARAMS ((vbyte_func, int, int));
815 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
816 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
817 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
818 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
819 static char format_ab_reg PARAMS ((int, int));
820 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
822 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
823 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
825 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
826 static void free_list_records PARAMS ((unw_rec_list *));
827 static unw_rec_list *output_prologue PARAMS ((void));
828 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
829 static unw_rec_list *output_body PARAMS ((void));
830 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
831 static unw_rec_list *output_mem_stack_v PARAMS ((void));
832 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
833 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
834 static unw_rec_list *output_rp_when PARAMS ((void));
835 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
836 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
837 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
838 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
839 static unw_rec_list *output_pfs_when PARAMS ((void));
840 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
841 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
842 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
843 static unw_rec_list *output_preds_when PARAMS ((void));
844 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
845 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
846 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
847 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
848 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
849 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
850 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
851 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
852 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
853 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
854 static unw_rec_list *output_unat_when PARAMS ((void));
855 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
856 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
857 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
858 static unw_rec_list *output_lc_when PARAMS ((void));
859 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
860 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
861 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
862 static unw_rec_list *output_fpsr_when PARAMS ((void));
863 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
864 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
865 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
866 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
867 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
868 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
869 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
870 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
871 static unw_rec_list *output_bsp_when PARAMS ((void));
872 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
873 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
874 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
875 static unw_rec_list *output_bspstore_when PARAMS ((void));
876 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
877 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
878 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
879 static unw_rec_list *output_rnat_when PARAMS ((void));
880 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
881 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
882 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
883 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
884 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
885 static unw_rec_list *output_label_state PARAMS ((unsigned long));
886 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
887 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
888 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
889 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
891 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
893 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
895 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
896 unsigned int, unsigned int));
897 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
898 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
899 static int calc_record_size PARAMS ((unw_rec_list *));
900 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
901 static int count_bits PARAMS ((unsigned long));
902 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
903 unsigned long, fragS *));
904 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
905 static void fixup_unw_records PARAMS ((unw_rec_list *));
906 static int output_unw_records PARAMS ((unw_rec_list *, void **));
907 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
908 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
909 static int generate_unwind_image PARAMS ((const char *));
910 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
911 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
912 static void free_saved_prologue_counts PARAMS ((void));
914 /* Build the unwind section name by appending the (possibly stripped)
915 text section NAME to the unwind PREFIX. The resulting string
916 pointer is assigned to RESULT. The string is allocated on the
917 stack, so this must be a macro... */
918 #define make_unw_section_name(special, text_name, result) \
920 const char *_prefix = special_section_name[special]; \
921 const char *_suffix = text_name; \
922 size_t _prefix_len, _suffix_len; \
924 if (strncmp (text_name, ".gnu.linkonce.t.", \
925 sizeof (".gnu.linkonce.t.") - 1) == 0) \
927 _prefix = special_linkonce_name[special - SPECIAL_SECTION_UNWIND]; \
928 _suffix += sizeof (".gnu.linkonce.t.") - 1; \
930 _prefix_len = strlen (_prefix), _suffix_len = strlen (_suffix); \
931 _result = alloca (_prefix_len + _suffix_len + 1); \
932 memcpy (_result, _prefix, _prefix_len); \
933 memcpy (_result + _prefix_len, _suffix, _suffix_len); \
934 _result[_prefix_len + _suffix_len] = '\0'; \
939 /* Determine if application register REGNUM resides in the integer
940 unit (as opposed to the memory unit). */
942 ar_is_in_integer_unit (reg)
947 return (reg == 64 /* pfs */
948 || reg == 65 /* lc */
949 || reg == 66 /* ec */
950 /* ??? ias accepts and puts these in the integer unit. */
951 || (reg >= 112 && reg <= 127));
954 /* Switch to section NAME and create section if necessary. It's
955 rather ugly that we have to manipulate input_line_pointer but I
956 don't see any other way to accomplish the same thing without
957 changing obj-elf.c (which may be the Right Thing, in the end). */
962 char *saved_input_line_pointer;
964 saved_input_line_pointer = input_line_pointer;
965 input_line_pointer = name;
967 input_line_pointer = saved_input_line_pointer;
970 /* Map 's' to SHF_IA_64_SHORT. */
973 ia64_elf_section_letter (letter, ptr_msg)
978 return SHF_IA_64_SHORT;
979 else if (letter == 'o')
980 return SHF_LINK_ORDER;
982 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
986 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
989 ia64_elf_section_flags (flags, attr, type)
991 int attr, type ATTRIBUTE_UNUSED;
993 if (attr & SHF_IA_64_SHORT)
994 flags |= SEC_SMALL_DATA;
999 ia64_elf_section_type (str, len)
1003 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
1005 if (STREQ (ELF_STRING_ia64_unwind_info))
1006 return SHT_PROGBITS;
1008 if (STREQ (ELF_STRING_ia64_unwind_info_once))
1009 return SHT_PROGBITS;
1011 if (STREQ (ELF_STRING_ia64_unwind))
1012 return SHT_IA_64_UNWIND;
1014 if (STREQ (ELF_STRING_ia64_unwind_once))
1015 return SHT_IA_64_UNWIND;
1017 if (STREQ ("unwind"))
1018 return SHT_IA_64_UNWIND;
1020 if (STREQ ("init_array"))
1021 return SHT_INIT_ARRAY;
1023 if (STREQ ("fini_array"))
1024 return SHT_FINI_ARRAY;
1031 set_regstack (ins, locs, outs, rots)
1032 unsigned int ins, locs, outs, rots;
1034 /* Size of frame. */
1037 sof = ins + locs + outs;
1040 as_bad ("Size of frame exceeds maximum of 96 registers");
1045 as_warn ("Size of rotating registers exceeds frame size");
1048 md.in.base = REG_GR + 32;
1049 md.loc.base = md.in.base + ins;
1050 md.out.base = md.loc.base + locs;
1052 md.in.num_regs = ins;
1053 md.loc.num_regs = locs;
1054 md.out.num_regs = outs;
1055 md.rot.num_regs = rots;
1062 struct label_fix *lfix;
1064 subsegT saved_subseg;
1067 if (!md.last_text_seg)
1070 saved_seg = now_seg;
1071 saved_subseg = now_subseg;
1073 subseg_set (md.last_text_seg, 0);
1075 while (md.num_slots_in_use > 0)
1076 emit_one_bundle (); /* force out queued instructions */
1078 /* In case there are labels following the last instruction, resolve
1080 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1082 S_SET_VALUE (lfix->sym, frag_now_fix ());
1083 symbol_set_frag (lfix->sym, frag_now);
1085 CURR_SLOT.label_fixups = 0;
1086 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1088 S_SET_VALUE (lfix->sym, frag_now_fix ());
1089 symbol_set_frag (lfix->sym, frag_now);
1091 CURR_SLOT.tag_fixups = 0;
1093 /* In case there are unwind directives following the last instruction,
1094 resolve those now. We only handle body and prologue directives here.
1095 Give an error for others. */
1096 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1098 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
1099 || ptr->r.type == body)
1101 ptr->slot_number = (unsigned long) frag_more (0);
1102 ptr->slot_frag = frag_now;
1105 as_bad (_("Unwind directive not followed by an instruction."));
1107 unwind.current_entry = NULL;
1109 subseg_set (saved_seg, saved_subseg);
1111 if (md.qp.X_op == O_register)
1112 as_bad ("qualifying predicate not followed by instruction");
1116 ia64_do_align (nbytes)
1119 char *saved_input_line_pointer = input_line_pointer;
1121 input_line_pointer = "";
1122 s_align_bytes (nbytes);
1123 input_line_pointer = saved_input_line_pointer;
1127 ia64_cons_align (nbytes)
1132 char *saved_input_line_pointer = input_line_pointer;
1133 input_line_pointer = "";
1134 s_align_bytes (nbytes);
1135 input_line_pointer = saved_input_line_pointer;
1139 /* Output COUNT bytes to a memory location. */
1140 static unsigned char *vbyte_mem_ptr = NULL;
1143 output_vbyte_mem (count, ptr, comment)
1146 char *comment ATTRIBUTE_UNUSED;
1149 if (vbyte_mem_ptr == NULL)
1154 for (x = 0; x < count; x++)
1155 *(vbyte_mem_ptr++) = ptr[x];
1158 /* Count the number of bytes required for records. */
1159 static int vbyte_count = 0;
1161 count_output (count, ptr, comment)
1163 char *ptr ATTRIBUTE_UNUSED;
1164 char *comment ATTRIBUTE_UNUSED;
1166 vbyte_count += count;
1170 output_R1_format (f, rtype, rlen)
1172 unw_record_type rtype;
1179 output_R3_format (f, rtype, rlen);
1185 else if (rtype != prologue)
1186 as_bad ("record type is not valid");
1188 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1189 (*f) (1, &byte, NULL);
1193 output_R2_format (f, mask, grsave, rlen)
1200 mask = (mask & 0x0f);
1201 grsave = (grsave & 0x7f);
1203 bytes[0] = (UNW_R2 | (mask >> 1));
1204 bytes[1] = (((mask & 0x01) << 7) | grsave);
1205 count += output_leb128 (bytes + 2, rlen, 0);
1206 (*f) (count, bytes, NULL);
1210 output_R3_format (f, rtype, rlen)
1212 unw_record_type rtype;
1219 output_R1_format (f, rtype, rlen);
1225 else if (rtype != prologue)
1226 as_bad ("record type is not valid");
1227 bytes[0] = (UNW_R3 | r);
1228 count = output_leb128 (bytes + 1, rlen, 0);
1229 (*f) (count + 1, bytes, NULL);
1233 output_P1_format (f, brmask)
1238 byte = UNW_P1 | (brmask & 0x1f);
1239 (*f) (1, &byte, NULL);
1243 output_P2_format (f, brmask, gr)
1249 brmask = (brmask & 0x1f);
1250 bytes[0] = UNW_P2 | (brmask >> 1);
1251 bytes[1] = (((brmask & 1) << 7) | gr);
1252 (*f) (2, bytes, NULL);
1256 output_P3_format (f, rtype, reg)
1258 unw_record_type rtype;
1303 as_bad ("Invalid record type for P3 format.");
1305 bytes[0] = (UNW_P3 | (r >> 1));
1306 bytes[1] = (((r & 1) << 7) | reg);
1307 (*f) (2, bytes, NULL);
1311 output_P4_format (f, imask, imask_size)
1313 unsigned char *imask;
1314 unsigned long imask_size;
1317 (*f) (imask_size, imask, NULL);
1321 output_P5_format (f, grmask, frmask)
1324 unsigned long frmask;
1327 grmask = (grmask & 0x0f);
1330 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1331 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1332 bytes[3] = (frmask & 0x000000ff);
1333 (*f) (4, bytes, NULL);
1337 output_P6_format (f, rtype, rmask)
1339 unw_record_type rtype;
1345 if (rtype == gr_mem)
1347 else if (rtype != fr_mem)
1348 as_bad ("Invalid record type for format P6");
1349 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1350 (*f) (1, &byte, NULL);
1354 output_P7_format (f, rtype, w1, w2)
1356 unw_record_type rtype;
1363 count += output_leb128 (bytes + 1, w1, 0);
1368 count += output_leb128 (bytes + count, w2 >> 4, 0);
1418 bytes[0] = (UNW_P7 | r);
1419 (*f) (count, bytes, NULL);
1423 output_P8_format (f, rtype, t)
1425 unw_record_type rtype;
1464 case bspstore_psprel:
1467 case bspstore_sprel:
1479 case priunat_when_gr:
1482 case priunat_psprel:
1488 case priunat_when_mem:
1495 count += output_leb128 (bytes + 2, t, 0);
1496 (*f) (count, bytes, NULL);
1500 output_P9_format (f, grmask, gr)
1507 bytes[1] = (grmask & 0x0f);
1508 bytes[2] = (gr & 0x7f);
1509 (*f) (3, bytes, NULL);
1513 output_P10_format (f, abi, context)
1520 bytes[1] = (abi & 0xff);
1521 bytes[2] = (context & 0xff);
1522 (*f) (3, bytes, NULL);
1526 output_B1_format (f, rtype, label)
1528 unw_record_type rtype;
1529 unsigned long label;
1535 output_B4_format (f, rtype, label);
1538 if (rtype == copy_state)
1540 else if (rtype != label_state)
1541 as_bad ("Invalid record type for format B1");
1543 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1544 (*f) (1, &byte, NULL);
1548 output_B2_format (f, ecount, t)
1550 unsigned long ecount;
1557 output_B3_format (f, ecount, t);
1560 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1561 count += output_leb128 (bytes + 1, t, 0);
1562 (*f) (count, bytes, NULL);
1566 output_B3_format (f, ecount, t)
1568 unsigned long ecount;
1575 output_B2_format (f, ecount, t);
1579 count += output_leb128 (bytes + 1, t, 0);
1580 count += output_leb128 (bytes + count, ecount, 0);
1581 (*f) (count, bytes, NULL);
1585 output_B4_format (f, rtype, label)
1587 unw_record_type rtype;
1588 unsigned long label;
1595 output_B1_format (f, rtype, label);
1599 if (rtype == copy_state)
1601 else if (rtype != label_state)
1602 as_bad ("Invalid record type for format B1");
1604 bytes[0] = (UNW_B4 | (r << 3));
1605 count += output_leb128 (bytes + 1, label, 0);
1606 (*f) (count, bytes, NULL);
1610 format_ab_reg (ab, reg)
1617 ret = (ab << 5) | reg;
1622 output_X1_format (f, rtype, ab, reg, t, w1)
1624 unw_record_type rtype;
1634 if (rtype == spill_sprel)
1636 else if (rtype != spill_psprel)
1637 as_bad ("Invalid record type for format X1");
1638 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1639 count += output_leb128 (bytes + 2, t, 0);
1640 count += output_leb128 (bytes + count, w1, 0);
1641 (*f) (count, bytes, NULL);
1645 output_X2_format (f, ab, reg, x, y, treg, t)
1654 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1655 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1656 count += output_leb128 (bytes + 3, t, 0);
1657 (*f) (count, bytes, NULL);
1661 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1663 unw_record_type rtype;
1674 if (rtype == spill_sprel_p)
1676 else if (rtype != spill_psprel_p)
1677 as_bad ("Invalid record type for format X3");
1678 bytes[1] = ((r << 7) | (qp & 0x3f));
1679 bytes[2] = format_ab_reg (ab, reg);
1680 count += output_leb128 (bytes + 3, t, 0);
1681 count += output_leb128 (bytes + count, w1, 0);
1682 (*f) (count, bytes, NULL);
1686 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1696 bytes[1] = (qp & 0x3f);
1697 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1698 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1699 count += output_leb128 (bytes + 4, t, 0);
1700 (*f) (count, bytes, NULL);
1703 /* This function allocates a record list structure, and initializes fields. */
1705 static unw_rec_list *
1706 alloc_record (unw_record_type t)
1709 ptr = xmalloc (sizeof (*ptr));
1711 ptr->slot_number = SLOT_NUM_NOT_SET;
1716 /* This function frees an entire list of record structures. */
1719 free_list_records (unw_rec_list *first)
1722 for (ptr = first; ptr != NULL;)
1724 unw_rec_list *tmp = ptr;
1726 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1727 && tmp->r.record.r.mask.i)
1728 free (tmp->r.record.r.mask.i);
1735 static unw_rec_list *
1738 unw_rec_list *ptr = alloc_record (prologue);
1739 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1743 static unw_rec_list *
1744 output_prologue_gr (saved_mask, reg)
1745 unsigned int saved_mask;
1748 unw_rec_list *ptr = alloc_record (prologue_gr);
1749 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1750 ptr->r.record.r.grmask = saved_mask;
1751 ptr->r.record.r.grsave = reg;
1755 static unw_rec_list *
1758 unw_rec_list *ptr = alloc_record (body);
1762 static unw_rec_list *
1763 output_mem_stack_f (size)
1766 unw_rec_list *ptr = alloc_record (mem_stack_f);
1767 ptr->r.record.p.size = size;
1771 static unw_rec_list *
1772 output_mem_stack_v ()
1774 unw_rec_list *ptr = alloc_record (mem_stack_v);
1778 static unw_rec_list *
1782 unw_rec_list *ptr = alloc_record (psp_gr);
1783 ptr->r.record.p.gr = gr;
1787 static unw_rec_list *
1788 output_psp_sprel (offset)
1789 unsigned int offset;
1791 unw_rec_list *ptr = alloc_record (psp_sprel);
1792 ptr->r.record.p.spoff = offset / 4;
1796 static unw_rec_list *
1799 unw_rec_list *ptr = alloc_record (rp_when);
1803 static unw_rec_list *
1807 unw_rec_list *ptr = alloc_record (rp_gr);
1808 ptr->r.record.p.gr = gr;
1812 static unw_rec_list *
1816 unw_rec_list *ptr = alloc_record (rp_br);
1817 ptr->r.record.p.br = br;
1821 static unw_rec_list *
1822 output_rp_psprel (offset)
1823 unsigned int offset;
1825 unw_rec_list *ptr = alloc_record (rp_psprel);
1826 ptr->r.record.p.pspoff = offset / 4;
1830 static unw_rec_list *
1831 output_rp_sprel (offset)
1832 unsigned int offset;
1834 unw_rec_list *ptr = alloc_record (rp_sprel);
1835 ptr->r.record.p.spoff = offset / 4;
1839 static unw_rec_list *
1842 unw_rec_list *ptr = alloc_record (pfs_when);
1846 static unw_rec_list *
1850 unw_rec_list *ptr = alloc_record (pfs_gr);
1851 ptr->r.record.p.gr = gr;
1855 static unw_rec_list *
1856 output_pfs_psprel (offset)
1857 unsigned int offset;
1859 unw_rec_list *ptr = alloc_record (pfs_psprel);
1860 ptr->r.record.p.pspoff = offset / 4;
1864 static unw_rec_list *
1865 output_pfs_sprel (offset)
1866 unsigned int offset;
1868 unw_rec_list *ptr = alloc_record (pfs_sprel);
1869 ptr->r.record.p.spoff = offset / 4;
1873 static unw_rec_list *
1874 output_preds_when ()
1876 unw_rec_list *ptr = alloc_record (preds_when);
1880 static unw_rec_list *
1881 output_preds_gr (gr)
1884 unw_rec_list *ptr = alloc_record (preds_gr);
1885 ptr->r.record.p.gr = gr;
1889 static unw_rec_list *
1890 output_preds_psprel (offset)
1891 unsigned int offset;
1893 unw_rec_list *ptr = alloc_record (preds_psprel);
1894 ptr->r.record.p.pspoff = offset / 4;
1898 static unw_rec_list *
1899 output_preds_sprel (offset)
1900 unsigned int offset;
1902 unw_rec_list *ptr = alloc_record (preds_sprel);
1903 ptr->r.record.p.spoff = offset / 4;
1907 static unw_rec_list *
1908 output_fr_mem (mask)
1911 unw_rec_list *ptr = alloc_record (fr_mem);
1912 ptr->r.record.p.rmask = mask;
1916 static unw_rec_list *
1917 output_frgr_mem (gr_mask, fr_mask)
1918 unsigned int gr_mask;
1919 unsigned int fr_mask;
1921 unw_rec_list *ptr = alloc_record (frgr_mem);
1922 ptr->r.record.p.grmask = gr_mask;
1923 ptr->r.record.p.frmask = fr_mask;
1927 static unw_rec_list *
1928 output_gr_gr (mask, reg)
1932 unw_rec_list *ptr = alloc_record (gr_gr);
1933 ptr->r.record.p.grmask = mask;
1934 ptr->r.record.p.gr = reg;
1938 static unw_rec_list *
1939 output_gr_mem (mask)
1942 unw_rec_list *ptr = alloc_record (gr_mem);
1943 ptr->r.record.p.rmask = mask;
1947 static unw_rec_list *
1948 output_br_mem (unsigned int mask)
1950 unw_rec_list *ptr = alloc_record (br_mem);
1951 ptr->r.record.p.brmask = mask;
1955 static unw_rec_list *
1956 output_br_gr (save_mask, reg)
1957 unsigned int save_mask;
1960 unw_rec_list *ptr = alloc_record (br_gr);
1961 ptr->r.record.p.brmask = save_mask;
1962 ptr->r.record.p.gr = reg;
1966 static unw_rec_list *
1967 output_spill_base (offset)
1968 unsigned int offset;
1970 unw_rec_list *ptr = alloc_record (spill_base);
1971 ptr->r.record.p.pspoff = offset / 4;
1975 static unw_rec_list *
1978 unw_rec_list *ptr = alloc_record (unat_when);
1982 static unw_rec_list *
1986 unw_rec_list *ptr = alloc_record (unat_gr);
1987 ptr->r.record.p.gr = gr;
1991 static unw_rec_list *
1992 output_unat_psprel (offset)
1993 unsigned int offset;
1995 unw_rec_list *ptr = alloc_record (unat_psprel);
1996 ptr->r.record.p.pspoff = offset / 4;
2000 static unw_rec_list *
2001 output_unat_sprel (offset)
2002 unsigned int offset;
2004 unw_rec_list *ptr = alloc_record (unat_sprel);
2005 ptr->r.record.p.spoff = offset / 4;
2009 static unw_rec_list *
2012 unw_rec_list *ptr = alloc_record (lc_when);
2016 static unw_rec_list *
2020 unw_rec_list *ptr = alloc_record (lc_gr);
2021 ptr->r.record.p.gr = gr;
2025 static unw_rec_list *
2026 output_lc_psprel (offset)
2027 unsigned int offset;
2029 unw_rec_list *ptr = alloc_record (lc_psprel);
2030 ptr->r.record.p.pspoff = offset / 4;
2034 static unw_rec_list *
2035 output_lc_sprel (offset)
2036 unsigned int offset;
2038 unw_rec_list *ptr = alloc_record (lc_sprel);
2039 ptr->r.record.p.spoff = offset / 4;
2043 static unw_rec_list *
2046 unw_rec_list *ptr = alloc_record (fpsr_when);
2050 static unw_rec_list *
2054 unw_rec_list *ptr = alloc_record (fpsr_gr);
2055 ptr->r.record.p.gr = gr;
2059 static unw_rec_list *
2060 output_fpsr_psprel (offset)
2061 unsigned int offset;
2063 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2064 ptr->r.record.p.pspoff = offset / 4;
2068 static unw_rec_list *
2069 output_fpsr_sprel (offset)
2070 unsigned int offset;
2072 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2073 ptr->r.record.p.spoff = offset / 4;
2077 static unw_rec_list *
2078 output_priunat_when_gr ()
2080 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2084 static unw_rec_list *
2085 output_priunat_when_mem ()
2087 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2091 static unw_rec_list *
2092 output_priunat_gr (gr)
2095 unw_rec_list *ptr = alloc_record (priunat_gr);
2096 ptr->r.record.p.gr = gr;
2100 static unw_rec_list *
2101 output_priunat_psprel (offset)
2102 unsigned int offset;
2104 unw_rec_list *ptr = alloc_record (priunat_psprel);
2105 ptr->r.record.p.pspoff = offset / 4;
2109 static unw_rec_list *
2110 output_priunat_sprel (offset)
2111 unsigned int offset;
2113 unw_rec_list *ptr = alloc_record (priunat_sprel);
2114 ptr->r.record.p.spoff = offset / 4;
2118 static unw_rec_list *
2121 unw_rec_list *ptr = alloc_record (bsp_when);
2125 static unw_rec_list *
2129 unw_rec_list *ptr = alloc_record (bsp_gr);
2130 ptr->r.record.p.gr = gr;
2134 static unw_rec_list *
2135 output_bsp_psprel (offset)
2136 unsigned int offset;
2138 unw_rec_list *ptr = alloc_record (bsp_psprel);
2139 ptr->r.record.p.pspoff = offset / 4;
2143 static unw_rec_list *
2144 output_bsp_sprel (offset)
2145 unsigned int offset;
2147 unw_rec_list *ptr = alloc_record (bsp_sprel);
2148 ptr->r.record.p.spoff = offset / 4;
2152 static unw_rec_list *
2153 output_bspstore_when ()
2155 unw_rec_list *ptr = alloc_record (bspstore_when);
2159 static unw_rec_list *
2160 output_bspstore_gr (gr)
2163 unw_rec_list *ptr = alloc_record (bspstore_gr);
2164 ptr->r.record.p.gr = gr;
2168 static unw_rec_list *
2169 output_bspstore_psprel (offset)
2170 unsigned int offset;
2172 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2173 ptr->r.record.p.pspoff = offset / 4;
2177 static unw_rec_list *
2178 output_bspstore_sprel (offset)
2179 unsigned int offset;
2181 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2182 ptr->r.record.p.spoff = offset / 4;
2186 static unw_rec_list *
2189 unw_rec_list *ptr = alloc_record (rnat_when);
2193 static unw_rec_list *
2197 unw_rec_list *ptr = alloc_record (rnat_gr);
2198 ptr->r.record.p.gr = gr;
2202 static unw_rec_list *
2203 output_rnat_psprel (offset)
2204 unsigned int offset;
2206 unw_rec_list *ptr = alloc_record (rnat_psprel);
2207 ptr->r.record.p.pspoff = offset / 4;
2211 static unw_rec_list *
2212 output_rnat_sprel (offset)
2213 unsigned int offset;
2215 unw_rec_list *ptr = alloc_record (rnat_sprel);
2216 ptr->r.record.p.spoff = offset / 4;
2220 static unw_rec_list *
2221 output_unwabi (abi, context)
2223 unsigned long context;
2225 unw_rec_list *ptr = alloc_record (unwabi);
2226 ptr->r.record.p.abi = abi;
2227 ptr->r.record.p.context = context;
2231 static unw_rec_list *
2232 output_epilogue (unsigned long ecount)
2234 unw_rec_list *ptr = alloc_record (epilogue);
2235 ptr->r.record.b.ecount = ecount;
2239 static unw_rec_list *
2240 output_label_state (unsigned long label)
2242 unw_rec_list *ptr = alloc_record (label_state);
2243 ptr->r.record.b.label = label;
2247 static unw_rec_list *
2248 output_copy_state (unsigned long label)
2250 unw_rec_list *ptr = alloc_record (copy_state);
2251 ptr->r.record.b.label = label;
2255 static unw_rec_list *
2256 output_spill_psprel (ab, reg, offset)
2259 unsigned int offset;
2261 unw_rec_list *ptr = alloc_record (spill_psprel);
2262 ptr->r.record.x.ab = ab;
2263 ptr->r.record.x.reg = reg;
2264 ptr->r.record.x.pspoff = offset / 4;
2268 static unw_rec_list *
2269 output_spill_sprel (ab, reg, offset)
2272 unsigned int offset;
2274 unw_rec_list *ptr = alloc_record (spill_sprel);
2275 ptr->r.record.x.ab = ab;
2276 ptr->r.record.x.reg = reg;
2277 ptr->r.record.x.spoff = offset / 4;
2281 static unw_rec_list *
2282 output_spill_psprel_p (ab, reg, offset, predicate)
2285 unsigned int offset;
2286 unsigned int predicate;
2288 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2289 ptr->r.record.x.ab = ab;
2290 ptr->r.record.x.reg = reg;
2291 ptr->r.record.x.pspoff = offset / 4;
2292 ptr->r.record.x.qp = predicate;
2296 static unw_rec_list *
2297 output_spill_sprel_p (ab, reg, offset, predicate)
2300 unsigned int offset;
2301 unsigned int predicate;
2303 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2304 ptr->r.record.x.ab = ab;
2305 ptr->r.record.x.reg = reg;
2306 ptr->r.record.x.spoff = offset / 4;
2307 ptr->r.record.x.qp = predicate;
2311 static unw_rec_list *
2312 output_spill_reg (ab, reg, targ_reg, xy)
2315 unsigned int targ_reg;
2318 unw_rec_list *ptr = alloc_record (spill_reg);
2319 ptr->r.record.x.ab = ab;
2320 ptr->r.record.x.reg = reg;
2321 ptr->r.record.x.treg = targ_reg;
2322 ptr->r.record.x.xy = xy;
2326 static unw_rec_list *
2327 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2330 unsigned int targ_reg;
2332 unsigned int predicate;
2334 unw_rec_list *ptr = alloc_record (spill_reg_p);
2335 ptr->r.record.x.ab = ab;
2336 ptr->r.record.x.reg = reg;
2337 ptr->r.record.x.treg = targ_reg;
2338 ptr->r.record.x.xy = xy;
2339 ptr->r.record.x.qp = predicate;
2343 /* Given a unw_rec_list process the correct format with the
2344 specified function. */
2347 process_one_record (ptr, f)
2351 unsigned long fr_mask, gr_mask;
2353 switch (ptr->r.type)
2359 /* These are taken care of by prologue/prologue_gr. */
2364 if (ptr->r.type == prologue_gr)
2365 output_R2_format (f, ptr->r.record.r.grmask,
2366 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2368 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2370 /* Output descriptor(s) for union of register spills (if any). */
2371 gr_mask = ptr->r.record.r.mask.gr_mem;
2372 fr_mask = ptr->r.record.r.mask.fr_mem;
2375 if ((fr_mask & ~0xfUL) == 0)
2376 output_P6_format (f, fr_mem, fr_mask);
2379 output_P5_format (f, gr_mask, fr_mask);
2384 output_P6_format (f, gr_mem, gr_mask);
2385 if (ptr->r.record.r.mask.br_mem)
2386 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2388 /* output imask descriptor if necessary: */
2389 if (ptr->r.record.r.mask.i)
2390 output_P4_format (f, ptr->r.record.r.mask.i,
2391 ptr->r.record.r.imask_size);
2395 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2399 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2400 ptr->r.record.p.size);
2413 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2416 output_P3_format (f, rp_br, ptr->r.record.p.br);
2419 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2427 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2436 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2446 case bspstore_sprel:
2448 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2451 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2454 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2457 as_bad ("spill_mask record unimplemented.");
2459 case priunat_when_gr:
2460 case priunat_when_mem:
2464 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2466 case priunat_psprel:
2468 case bspstore_psprel:
2470 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2473 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2476 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2480 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2483 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2484 ptr->r.record.x.reg, ptr->r.record.x.t,
2485 ptr->r.record.x.pspoff);
2488 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2489 ptr->r.record.x.reg, ptr->r.record.x.t,
2490 ptr->r.record.x.spoff);
2493 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2494 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2495 ptr->r.record.x.treg, ptr->r.record.x.t);
2497 case spill_psprel_p:
2498 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2499 ptr->r.record.x.ab, ptr->r.record.x.reg,
2500 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2503 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2504 ptr->r.record.x.ab, ptr->r.record.x.reg,
2505 ptr->r.record.x.t, ptr->r.record.x.spoff);
2508 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2509 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2510 ptr->r.record.x.xy, ptr->r.record.x.treg,
2514 as_bad ("record_type_not_valid");
2519 /* Given a unw_rec_list list, process all the records with
2520 the specified function. */
2522 process_unw_records (list, f)
2527 for (ptr = list; ptr; ptr = ptr->next)
2528 process_one_record (ptr, f);
2531 /* Determine the size of a record list in bytes. */
2533 calc_record_size (list)
2537 process_unw_records (list, count_output);
2541 /* Update IMASK bitmask to reflect the fact that one or more registers
2542 of type TYPE are saved starting at instruction with index T. If N
2543 bits are set in REGMASK, it is assumed that instructions T through
2544 T+N-1 save these registers.
2548 1: instruction saves next fp reg
2549 2: instruction saves next general reg
2550 3: instruction saves next branch reg */
2552 set_imask (region, regmask, t, type)
2553 unw_rec_list *region;
2554 unsigned long regmask;
2558 unsigned char *imask;
2559 unsigned long imask_size;
2563 imask = region->r.record.r.mask.i;
2564 imask_size = region->r.record.r.imask_size;
2567 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2568 imask = xmalloc (imask_size);
2569 memset (imask, 0, imask_size);
2571 region->r.record.r.imask_size = imask_size;
2572 region->r.record.r.mask.i = imask;
2576 pos = 2 * (3 - t % 4);
2579 if (i >= imask_size)
2581 as_bad ("Ignoring attempt to spill beyond end of region");
2585 imask[i] |= (type & 0x3) << pos;
2587 regmask &= (regmask - 1);
2598 count_bits (unsigned long mask)
2610 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2611 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2612 containing FIRST_ADDR. */
2615 slot_index (slot_addr, slot_frag, first_addr, first_frag)
2616 unsigned long slot_addr;
2618 unsigned long first_addr;
2621 unsigned long index = 0;
2623 /* First time we are called, the initial address and frag are invalid. */
2624 if (first_addr == 0)
2627 /* If the two addresses are in different frags, then we need to add in
2628 the remaining size of this frag, and then the entire size of intermediate
2630 while (slot_frag != first_frag)
2632 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2634 /* Add in the full size of the frag converted to instruction slots. */
2635 index += 3 * (first_frag->fr_fix >> 4);
2636 /* Subtract away the initial part before first_addr. */
2637 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2638 + ((first_addr & 0x3) - (start_addr & 0x3)));
2640 /* Move to the beginning of the next frag. */
2641 first_frag = first_frag->fr_next;
2642 first_addr = (unsigned long) &first_frag->fr_literal;
2645 /* Add in the used part of the last frag. */
2646 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2647 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2651 /* Optimize unwind record directives. */
2653 static unw_rec_list *
2654 optimize_unw_records (list)
2660 /* If the only unwind record is ".prologue" or ".prologue" followed
2661 by ".body", then we can optimize the unwind directives away. */
2662 if (list->r.type == prologue
2663 && (list->next == NULL
2664 || (list->next->r.type == body && list->next->next == NULL)))
2670 /* Given a complete record list, process any records which have
2671 unresolved fields, (ie length counts for a prologue). After
2672 this has been run, all neccessary information should be available
2673 within each record to generate an image. */
2676 fixup_unw_records (list)
2679 unw_rec_list *ptr, *region = 0;
2680 unsigned long first_addr = 0, rlen = 0, t;
2681 fragS *first_frag = 0;
2683 for (ptr = list; ptr; ptr = ptr->next)
2685 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2686 as_bad (" Insn slot not set in unwind record.");
2687 t = slot_index (ptr->slot_number, ptr->slot_frag,
2688 first_addr, first_frag);
2689 switch (ptr->r.type)
2696 int size, dir_len = 0;
2697 unsigned long last_addr;
2700 first_addr = ptr->slot_number;
2701 first_frag = ptr->slot_frag;
2702 ptr->slot_number = 0;
2703 /* Find either the next body/prologue start, or the end of
2704 the list, and determine the size of the region. */
2705 last_addr = unwind.next_slot_number;
2706 last_frag = unwind.next_slot_frag;
2707 for (last = ptr->next; last != NULL; last = last->next)
2708 if (last->r.type == prologue || last->r.type == prologue_gr
2709 || last->r.type == body)
2711 last_addr = last->slot_number;
2712 last_frag = last->slot_frag;
2715 else if (!last->next)
2717 /* In the absence of an explicit .body directive,
2718 the prologue ends after the last instruction
2719 covered by an unwind directive. */
2720 if (ptr->r.type != body)
2722 last_addr = last->slot_number;
2723 last_frag = last->slot_frag;
2724 switch (last->r.type)
2727 dir_len = (count_bits (last->r.record.p.frmask)
2728 + count_bits (last->r.record.p.grmask));
2732 dir_len += count_bits (last->r.record.p.rmask);
2736 dir_len += count_bits (last->r.record.p.brmask);
2739 dir_len += count_bits (last->r.record.p.grmask);
2748 size = (slot_index (last_addr, last_frag, first_addr, first_frag)
2750 rlen = ptr->r.record.r.rlen = size;
2751 if (ptr->r.type == body)
2752 /* End of region. */
2759 ptr->r.record.b.t = rlen - 1 - t;
2770 case priunat_when_gr:
2771 case priunat_when_mem:
2775 ptr->r.record.p.t = t;
2783 case spill_psprel_p:
2784 ptr->r.record.x.t = t;
2790 as_bad ("frgr_mem record before region record!\n");
2793 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2794 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2795 set_imask (region, ptr->r.record.p.frmask, t, 1);
2796 set_imask (region, ptr->r.record.p.grmask, t, 2);
2801 as_bad ("fr_mem record before region record!\n");
2804 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2805 set_imask (region, ptr->r.record.p.rmask, t, 1);
2810 as_bad ("gr_mem record before region record!\n");
2813 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2814 set_imask (region, ptr->r.record.p.rmask, t, 2);
2819 as_bad ("br_mem record before region record!\n");
2822 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2823 set_imask (region, ptr->r.record.p.brmask, t, 3);
2829 as_bad ("gr_gr record before region record!\n");
2832 set_imask (region, ptr->r.record.p.grmask, t, 2);
2837 as_bad ("br_gr record before region record!\n");
2840 set_imask (region, ptr->r.record.p.brmask, t, 3);
2849 /* Helper routine for output_unw_records. Emits the header for the unwind
2853 setup_unwind_header (int size, unsigned char **mem)
2858 /* pad to pointer-size boundry. */
2859 x = size % md.pointer_size;
2861 extra = md.pointer_size - x;
2863 /* Add 8 for the header + a pointer for the
2864 personality offset. */
2865 *mem = xmalloc (size + extra + 8 + md.pointer_size);
2867 /* Clear the padding area and personality. */
2868 memset (*mem + 8 + size, 0, extra + md.pointer_size);
2870 /* Initialize the header area. */
2871 if (unwind.personality_routine)
2873 if (md.flags & EF_IA_64_ABI64)
2874 flag_value = (bfd_vma) 3 << 32;
2876 /* 32-bit unwind info block. */
2877 flag_value = (bfd_vma) 0x1003 << 32;
2882 md_number_to_chars (*mem, (((bfd_vma) 1 << 48) /* Version. */
2883 | flag_value /* U & E handler flags. */
2884 | ((size + extra) / md.pointer_size)), /* Length. */
2890 /* Generate an unwind image from a record list. Returns the number of
2891 bytes in the resulting image. The memory image itselof is returned
2892 in the 'ptr' parameter. */
2894 output_unw_records (list, ptr)
2903 list = optimize_unw_records (list);
2904 fixup_unw_records (list);
2905 size = calc_record_size (list);
2907 if (size > 0 || unwind.force_unwind_entry)
2909 unwind.force_unwind_entry = 0;
2910 extra = setup_unwind_header (size, &mem);
2912 vbyte_mem_ptr = mem + 8;
2913 process_unw_records (list, output_vbyte_mem);
2917 size += extra + 8 + md.pointer_size;
2923 convert_expr_to_ab_reg (e, ab, regp)
2930 if (e->X_op != O_register)
2933 reg = e->X_add_number;
2934 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2937 *regp = reg - REG_GR;
2939 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2940 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2943 *regp = reg - REG_FR;
2945 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2948 *regp = reg - REG_BR;
2955 case REG_PR: *regp = 0; break;
2956 case REG_PSP: *regp = 1; break;
2957 case REG_PRIUNAT: *regp = 2; break;
2958 case REG_BR + 0: *regp = 3; break;
2959 case REG_AR + AR_BSP: *regp = 4; break;
2960 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2961 case REG_AR + AR_RNAT: *regp = 6; break;
2962 case REG_AR + AR_UNAT: *regp = 7; break;
2963 case REG_AR + AR_FPSR: *regp = 8; break;
2964 case REG_AR + AR_PFS: *regp = 9; break;
2965 case REG_AR + AR_LC: *regp = 10; break;
2975 convert_expr_to_xy_reg (e, xy, regp)
2982 if (e->X_op != O_register)
2985 reg = e->X_add_number;
2987 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2990 *regp = reg - REG_GR;
2992 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2995 *regp = reg - REG_FR;
2997 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3000 *regp = reg - REG_BR;
3009 int dummy ATTRIBUTE_UNUSED;
3014 radix = *input_line_pointer++;
3016 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3018 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3019 ignore_rest_of_line ();
3024 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3026 dot_special_section (which)
3029 set_section ((char *) special_section_name[which]);
3033 add_unwind_entry (ptr)
3037 unwind.tail->next = ptr;
3042 /* The current entry can in fact be a chain of unwind entries. */
3043 if (unwind.current_entry == NULL)
3044 unwind.current_entry = ptr;
3049 int dummy ATTRIBUTE_UNUSED;
3055 if (e.X_op != O_constant)
3056 as_bad ("Operand to .fframe must be a constant");
3058 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3063 int dummy ATTRIBUTE_UNUSED;
3069 reg = e.X_add_number - REG_GR;
3070 if (e.X_op == O_register && reg < 128)
3072 add_unwind_entry (output_mem_stack_v ());
3073 if (! (unwind.prologue_mask & 2))
3074 add_unwind_entry (output_psp_gr (reg));
3077 as_bad ("First operand to .vframe must be a general register");
3081 dot_vframesp (dummy)
3082 int dummy ATTRIBUTE_UNUSED;
3087 if (e.X_op == O_constant)
3089 add_unwind_entry (output_mem_stack_v ());
3090 add_unwind_entry (output_psp_sprel (e.X_add_number));
3093 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3097 dot_vframepsp (dummy)
3098 int dummy ATTRIBUTE_UNUSED;
3103 if (e.X_op == O_constant)
3105 add_unwind_entry (output_mem_stack_v ());
3106 add_unwind_entry (output_psp_sprel (e.X_add_number));
3109 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3114 int dummy ATTRIBUTE_UNUSED;
3120 sep = parse_operand (&e1);
3122 as_bad ("No second operand to .save");
3123 sep = parse_operand (&e2);
3125 reg1 = e1.X_add_number;
3126 reg2 = e2.X_add_number - REG_GR;
3128 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3129 if (e1.X_op == O_register)
3131 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3135 case REG_AR + AR_BSP:
3136 add_unwind_entry (output_bsp_when ());
3137 add_unwind_entry (output_bsp_gr (reg2));
3139 case REG_AR + AR_BSPSTORE:
3140 add_unwind_entry (output_bspstore_when ());
3141 add_unwind_entry (output_bspstore_gr (reg2));
3143 case REG_AR + AR_RNAT:
3144 add_unwind_entry (output_rnat_when ());
3145 add_unwind_entry (output_rnat_gr (reg2));
3147 case REG_AR + AR_UNAT:
3148 add_unwind_entry (output_unat_when ());
3149 add_unwind_entry (output_unat_gr (reg2));
3151 case REG_AR + AR_FPSR:
3152 add_unwind_entry (output_fpsr_when ());
3153 add_unwind_entry (output_fpsr_gr (reg2));
3155 case REG_AR + AR_PFS:
3156 add_unwind_entry (output_pfs_when ());
3157 if (! (unwind.prologue_mask & 4))
3158 add_unwind_entry (output_pfs_gr (reg2));
3160 case REG_AR + AR_LC:
3161 add_unwind_entry (output_lc_when ());
3162 add_unwind_entry (output_lc_gr (reg2));
3165 add_unwind_entry (output_rp_when ());
3166 if (! (unwind.prologue_mask & 8))
3167 add_unwind_entry (output_rp_gr (reg2));
3170 add_unwind_entry (output_preds_when ());
3171 if (! (unwind.prologue_mask & 1))
3172 add_unwind_entry (output_preds_gr (reg2));
3175 add_unwind_entry (output_priunat_when_gr ());
3176 add_unwind_entry (output_priunat_gr (reg2));
3179 as_bad ("First operand not a valid register");
3183 as_bad (" Second operand not a valid register");
3186 as_bad ("First operand not a register");
3191 int dummy ATTRIBUTE_UNUSED;
3194 unsigned long ecount; /* # of _additional_ regions to pop */
3197 sep = parse_operand (&e1);
3198 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3200 as_bad ("First operand to .restore must be stack pointer (sp)");
3206 parse_operand (&e2);
3207 if (e2.X_op != O_constant || e2.X_add_number < 0)
3209 as_bad ("Second operand to .restore must be a constant >= 0");
3212 ecount = e2.X_add_number;
3215 ecount = unwind.prologue_count - 1;
3217 if (ecount >= unwind.prologue_count)
3219 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3220 ecount + 1, unwind.prologue_count);
3224 add_unwind_entry (output_epilogue (ecount));
3226 if (ecount < unwind.prologue_count)
3227 unwind.prologue_count -= ecount + 1;
3229 unwind.prologue_count = 0;
3233 dot_restorereg (dummy)
3234 int dummy ATTRIBUTE_UNUSED;
3236 unsigned int ab, reg;
3241 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3243 as_bad ("First operand to .restorereg must be a preserved register");
3246 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3250 dot_restorereg_p (dummy)
3251 int dummy ATTRIBUTE_UNUSED;
3253 unsigned int qp, ab, reg;
3257 sep = parse_operand (&e1);
3260 as_bad ("No second operand to .restorereg.p");
3264 parse_operand (&e2);
3266 qp = e1.X_add_number - REG_P;
3267 if (e1.X_op != O_register || qp > 63)
3269 as_bad ("First operand to .restorereg.p must be a predicate");
3273 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3275 as_bad ("Second operand to .restorereg.p must be a preserved register");
3278 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3282 generate_unwind_image (text_name)
3283 const char *text_name;
3288 /* Force out pending instructions, to make sure all unwind records have
3289 a valid slot_number field. */
3290 ia64_flush_insns ();
3292 /* Generate the unwind record. */
3293 size = output_unw_records (unwind.list, &unw_rec);
3294 if (size % md.pointer_size != 0)
3295 as_bad ("Unwind record is not a multiple of %d bytes.", md.pointer_size);
3297 /* If there are unwind records, switch sections, and output the info. */
3300 unsigned char *where;
3303 bfd_reloc_code_real_type reloc;
3305 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3306 set_section (sec_name);
3307 bfd_set_section_flags (stdoutput, now_seg,
3308 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3310 /* Make sure the section has 4 byte alignment for ILP32 and
3311 8 byte alignment for LP64. */
3312 frag_align (md.pointer_size_shift, 0, 0);
3313 record_alignment (now_seg, md.pointer_size_shift);
3315 /* Set expression which points to start of unwind descriptor area. */
3316 unwind.info = expr_build_dot ();
3318 where = (unsigned char *) frag_more (size);
3320 /* Issue a label for this address, and keep track of it to put it
3321 in the unwind section. */
3323 /* Copy the information from the unwind record into this section. The
3324 data is already in the correct byte order. */
3325 memcpy (where, unw_rec, size);
3327 /* Add the personality address to the image. */
3328 if (unwind.personality_routine != 0)
3330 exp.X_op = O_symbol;
3331 exp.X_add_symbol = unwind.personality_routine;
3332 exp.X_add_number = 0;
3334 if (md.flags & EF_IA_64_BE)
3336 if (md.flags & EF_IA_64_ABI64)
3337 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3339 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3343 if (md.flags & EF_IA_64_ABI64)
3344 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3346 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3349 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3350 md.pointer_size, &exp, 0, reloc);
3351 unwind.personality_routine = 0;
3355 free_list_records (unwind.list);
3356 free_saved_prologue_counts ();
3357 unwind.list = unwind.tail = unwind.current_entry = NULL;
3363 dot_handlerdata (dummy)
3364 int dummy ATTRIBUTE_UNUSED;
3366 const char *text_name = segment_name (now_seg);
3368 /* If text section name starts with ".text" (which it should),
3369 strip this prefix off. */
3370 if (strcmp (text_name, ".text") == 0)
3373 unwind.force_unwind_entry = 1;
3375 /* Remember which segment we're in so we can switch back after .endp */
3376 unwind.saved_text_seg = now_seg;
3377 unwind.saved_text_subseg = now_subseg;
3379 /* Generate unwind info into unwind-info section and then leave that
3380 section as the currently active one so dataXX directives go into
3381 the language specific data area of the unwind info block. */
3382 generate_unwind_image (text_name);
3383 demand_empty_rest_of_line ();
3387 dot_unwentry (dummy)
3388 int dummy ATTRIBUTE_UNUSED;
3390 unwind.force_unwind_entry = 1;
3391 demand_empty_rest_of_line ();
3396 int dummy ATTRIBUTE_UNUSED;
3402 reg = e.X_add_number - REG_BR;
3403 if (e.X_op == O_register && reg < 8)
3404 add_unwind_entry (output_rp_br (reg));
3406 as_bad ("First operand not a valid branch register");
3410 dot_savemem (psprel)
3417 sep = parse_operand (&e1);
3419 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3420 sep = parse_operand (&e2);
3422 reg1 = e1.X_add_number;
3423 val = e2.X_add_number;
3425 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3426 if (e1.X_op == O_register)
3428 if (e2.X_op == O_constant)
3432 case REG_AR + AR_BSP:
3433 add_unwind_entry (output_bsp_when ());
3434 add_unwind_entry ((psprel
3436 : output_bsp_sprel) (val));
3438 case REG_AR + AR_BSPSTORE:
3439 add_unwind_entry (output_bspstore_when ());
3440 add_unwind_entry ((psprel
3441 ? output_bspstore_psprel
3442 : output_bspstore_sprel) (val));
3444 case REG_AR + AR_RNAT:
3445 add_unwind_entry (output_rnat_when ());
3446 add_unwind_entry ((psprel
3447 ? output_rnat_psprel
3448 : output_rnat_sprel) (val));
3450 case REG_AR + AR_UNAT:
3451 add_unwind_entry (output_unat_when ());
3452 add_unwind_entry ((psprel
3453 ? output_unat_psprel
3454 : output_unat_sprel) (val));
3456 case REG_AR + AR_FPSR:
3457 add_unwind_entry (output_fpsr_when ());
3458 add_unwind_entry ((psprel
3459 ? output_fpsr_psprel
3460 : output_fpsr_sprel) (val));
3462 case REG_AR + AR_PFS:
3463 add_unwind_entry (output_pfs_when ());
3464 add_unwind_entry ((psprel
3466 : output_pfs_sprel) (val));
3468 case REG_AR + AR_LC:
3469 add_unwind_entry (output_lc_when ());
3470 add_unwind_entry ((psprel
3472 : output_lc_sprel) (val));
3475 add_unwind_entry (output_rp_when ());
3476 add_unwind_entry ((psprel
3478 : output_rp_sprel) (val));
3481 add_unwind_entry (output_preds_when ());
3482 add_unwind_entry ((psprel
3483 ? output_preds_psprel
3484 : output_preds_sprel) (val));
3487 add_unwind_entry (output_priunat_when_mem ());
3488 add_unwind_entry ((psprel
3489 ? output_priunat_psprel
3490 : output_priunat_sprel) (val));
3493 as_bad ("First operand not a valid register");
3497 as_bad (" Second operand not a valid constant");
3500 as_bad ("First operand not a register");
3505 int dummy ATTRIBUTE_UNUSED;
3509 sep = parse_operand (&e1);
3511 parse_operand (&e2);
3513 if (e1.X_op != O_constant)
3514 as_bad ("First operand to .save.g must be a constant.");
3517 int grmask = e1.X_add_number;
3519 add_unwind_entry (output_gr_mem (grmask));
3522 int reg = e2.X_add_number - REG_GR;
3523 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3524 add_unwind_entry (output_gr_gr (grmask, reg));
3526 as_bad ("Second operand is an invalid register.");
3533 int dummy ATTRIBUTE_UNUSED;
3537 sep = parse_operand (&e1);
3539 if (e1.X_op != O_constant)
3540 as_bad ("Operand to .save.f must be a constant.");
3542 add_unwind_entry (output_fr_mem (e1.X_add_number));
3547 int dummy ATTRIBUTE_UNUSED;
3554 sep = parse_operand (&e1);
3555 if (e1.X_op != O_constant)
3557 as_bad ("First operand to .save.b must be a constant.");
3560 brmask = e1.X_add_number;
3564 sep = parse_operand (&e2);
3565 reg = e2.X_add_number - REG_GR;
3566 if (e2.X_op != O_register || reg > 127)
3568 as_bad ("Second operand to .save.b must be a general register.");
3571 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3574 add_unwind_entry (output_br_mem (brmask));
3576 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3577 ignore_rest_of_line ();
3582 int dummy ATTRIBUTE_UNUSED;
3586 sep = parse_operand (&e1);
3588 parse_operand (&e2);
3590 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3591 as_bad ("Both operands of .save.gf must be constants.");
3594 int grmask = e1.X_add_number;
3595 int frmask = e2.X_add_number;
3596 add_unwind_entry (output_frgr_mem (grmask, frmask));
3602 int dummy ATTRIBUTE_UNUSED;
3607 sep = parse_operand (&e);
3608 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3609 ignore_rest_of_line ();
3611 if (e.X_op != O_constant)
3612 as_bad ("Operand to .spill must be a constant");
3614 add_unwind_entry (output_spill_base (e.X_add_number));
3618 dot_spillreg (dummy)
3619 int dummy ATTRIBUTE_UNUSED;
3621 int sep, ab, xy, reg, treg;
3624 sep = parse_operand (&e1);
3627 as_bad ("No second operand to .spillreg");
3631 parse_operand (&e2);
3633 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3635 as_bad ("First operand to .spillreg must be a preserved register");
3639 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3641 as_bad ("Second operand to .spillreg must be a register");
3645 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3649 dot_spillmem (psprel)
3655 sep = parse_operand (&e1);
3658 as_bad ("Second operand missing");
3662 parse_operand (&e2);
3664 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3666 as_bad ("First operand to .spill%s must be a preserved register",
3667 psprel ? "psp" : "sp");
3671 if (e2.X_op != O_constant)
3673 as_bad ("Second operand to .spill%s must be a constant",
3674 psprel ? "psp" : "sp");
3679 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3681 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3685 dot_spillreg_p (dummy)
3686 int dummy ATTRIBUTE_UNUSED;
3688 int sep, ab, xy, reg, treg;
3689 expressionS e1, e2, e3;
3692 sep = parse_operand (&e1);
3695 as_bad ("No second and third operand to .spillreg.p");
3699 sep = parse_operand (&e2);
3702 as_bad ("No third operand to .spillreg.p");
3706 parse_operand (&e3);
3708 qp = e1.X_add_number - REG_P;
3710 if (e1.X_op != O_register || qp > 63)
3712 as_bad ("First operand to .spillreg.p must be a predicate");
3716 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3718 as_bad ("Second operand to .spillreg.p must be a preserved register");
3722 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3724 as_bad ("Third operand to .spillreg.p must be a register");
3728 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3732 dot_spillmem_p (psprel)
3735 expressionS e1, e2, e3;
3739 sep = parse_operand (&e1);
3742 as_bad ("Second operand missing");
3746 parse_operand (&e2);
3749 as_bad ("Second operand missing");
3753 parse_operand (&e3);
3755 qp = e1.X_add_number - REG_P;
3756 if (e1.X_op != O_register || qp > 63)
3758 as_bad ("First operand to .spill%s_p must be a predicate",
3759 psprel ? "psp" : "sp");
3763 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3765 as_bad ("Second operand to .spill%s_p must be a preserved register",
3766 psprel ? "psp" : "sp");
3770 if (e3.X_op != O_constant)
3772 as_bad ("Third operand to .spill%s_p must be a constant",
3773 psprel ? "psp" : "sp");
3778 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3780 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3784 get_saved_prologue_count (lbl)
3787 label_prologue_count *lpc = unwind.saved_prologue_counts;
3789 while (lpc != NULL && lpc->label_number != lbl)
3793 return lpc->prologue_count;
3795 as_bad ("Missing .label_state %ld", lbl);
3800 save_prologue_count (lbl, count)
3804 label_prologue_count *lpc = unwind.saved_prologue_counts;
3806 while (lpc != NULL && lpc->label_number != lbl)
3810 lpc->prologue_count = count;
3813 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3815 new_lpc->next = unwind.saved_prologue_counts;
3816 new_lpc->label_number = lbl;
3817 new_lpc->prologue_count = count;
3818 unwind.saved_prologue_counts = new_lpc;
3823 free_saved_prologue_counts ()
3825 label_prologue_count *lpc = unwind.saved_prologue_counts;
3826 label_prologue_count *next;
3835 unwind.saved_prologue_counts = NULL;
3839 dot_label_state (dummy)
3840 int dummy ATTRIBUTE_UNUSED;
3845 if (e.X_op != O_constant)
3847 as_bad ("Operand to .label_state must be a constant");
3850 add_unwind_entry (output_label_state (e.X_add_number));
3851 save_prologue_count (e.X_add_number, unwind.prologue_count);
3855 dot_copy_state (dummy)
3856 int dummy ATTRIBUTE_UNUSED;
3861 if (e.X_op != O_constant)
3863 as_bad ("Operand to .copy_state must be a constant");
3866 add_unwind_entry (output_copy_state (e.X_add_number));
3867 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3872 int dummy ATTRIBUTE_UNUSED;
3877 sep = parse_operand (&e1);
3880 as_bad ("Second operand to .unwabi missing");
3883 sep = parse_operand (&e2);
3884 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3885 ignore_rest_of_line ();
3887 if (e1.X_op != O_constant)
3889 as_bad ("First operand to .unwabi must be a constant");
3893 if (e2.X_op != O_constant)
3895 as_bad ("Second operand to .unwabi must be a constant");
3899 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3903 dot_personality (dummy)
3904 int dummy ATTRIBUTE_UNUSED;
3908 name = input_line_pointer;
3909 c = get_symbol_end ();
3910 p = input_line_pointer;
3911 unwind.personality_routine = symbol_find_or_make (name);
3912 unwind.force_unwind_entry = 1;
3915 demand_empty_rest_of_line ();
3920 int dummy ATTRIBUTE_UNUSED;
3925 unwind.proc_start = expr_build_dot ();
3926 /* Parse names of main and alternate entry points and mark them as
3927 function symbols: */
3931 name = input_line_pointer;
3932 c = get_symbol_end ();
3933 p = input_line_pointer;
3934 sym = symbol_find_or_make (name);
3935 if (unwind.proc_start == 0)
3937 unwind.proc_start = sym;
3939 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3942 if (*input_line_pointer != ',')
3944 ++input_line_pointer;
3946 demand_empty_rest_of_line ();
3949 unwind.prologue_count = 0;
3950 unwind.list = unwind.tail = unwind.current_entry = NULL;
3951 unwind.personality_routine = 0;
3956 int dummy ATTRIBUTE_UNUSED;
3958 unwind.prologue = 0;
3959 unwind.prologue_mask = 0;
3961 add_unwind_entry (output_body ());
3962 demand_empty_rest_of_line ();
3966 dot_prologue (dummy)
3967 int dummy ATTRIBUTE_UNUSED;
3970 int mask = 0, grsave = 0;
3972 if (!is_it_end_of_statement ())
3975 sep = parse_operand (&e1);
3977 as_bad ("No second operand to .prologue");
3978 sep = parse_operand (&e2);
3979 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3980 ignore_rest_of_line ();
3982 if (e1.X_op == O_constant)
3984 mask = e1.X_add_number;
3986 if (e2.X_op == O_constant)
3987 grsave = e2.X_add_number;
3988 else if (e2.X_op == O_register
3989 && (grsave = e2.X_add_number - REG_GR) < 128)
3992 as_bad ("Second operand not a constant or general register");
3994 add_unwind_entry (output_prologue_gr (mask, grsave));
3997 as_bad ("First operand not a constant");
4000 add_unwind_entry (output_prologue ());
4002 unwind.prologue = 1;
4003 unwind.prologue_mask = mask;
4004 ++unwind.prologue_count;
4009 int dummy ATTRIBUTE_UNUSED;
4013 int bytes_per_address;
4016 subsegT saved_subseg;
4017 const char *sec_name, *text_name;
4021 if (unwind.saved_text_seg)
4023 saved_seg = unwind.saved_text_seg;
4024 saved_subseg = unwind.saved_text_subseg;
4025 unwind.saved_text_seg = NULL;
4029 saved_seg = now_seg;
4030 saved_subseg = now_subseg;
4034 Use a slightly ugly scheme to derive the unwind section names from
4035 the text section name:
4037 text sect. unwind table sect.
4038 name: name: comments:
4039 ---------- ----------------- --------------------------------
4041 .text.foo .IA_64.unwind.text.foo
4042 .foo .IA_64.unwind.foo
4044 .gnu.linkonce.ia64unw.foo
4045 _info .IA_64.unwind_info gas issues error message (ditto)
4046 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
4048 This mapping is done so that:
4050 (a) An object file with unwind info only in .text will use
4051 unwind section names .IA_64.unwind and .IA_64.unwind_info.
4052 This follows the letter of the ABI and also ensures backwards
4053 compatibility with older toolchains.
4055 (b) An object file with unwind info in multiple text sections
4056 will use separate unwind sections for each text section.
4057 This allows us to properly set the "sh_info" and "sh_link"
4058 fields in SHT_IA_64_UNWIND as required by the ABI and also
4059 lets GNU ld support programs with multiple segments
4060 containing unwind info (as might be the case for certain
4061 embedded applications).
4063 (c) An error is issued if there would be a name clash.
4065 text_name = segment_name (saved_seg);
4066 if (strncmp (text_name, "_info", 5) == 0)
4068 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
4070 ignore_rest_of_line ();
4073 if (strcmp (text_name, ".text") == 0)
4076 insn_group_break (1, 0, 0);
4078 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4080 generate_unwind_image (text_name);
4082 if (unwind.info || unwind.force_unwind_entry)
4084 subseg_set (md.last_text_seg, 0);
4085 unwind.proc_end = expr_build_dot ();
4087 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
4088 set_section ((char *) sec_name);
4089 bfd_set_section_flags (stdoutput, now_seg,
4090 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
4092 /* Make sure that section has 4 byte alignment for ILP32 and
4093 8 byte alignment for LP64. */
4094 record_alignment (now_seg, md.pointer_size_shift);
4096 /* Need space for 3 pointers for procedure start, procedure end,
4098 ptr = frag_more (3 * md.pointer_size);
4099 where = frag_now_fix () - (3 * md.pointer_size);
4100 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4102 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4103 e.X_op = O_pseudo_fixup;
4104 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4106 e.X_add_symbol = unwind.proc_start;
4107 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4109 e.X_op = O_pseudo_fixup;
4110 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4112 e.X_add_symbol = unwind.proc_end;
4113 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4114 bytes_per_address, &e);
4118 e.X_op = O_pseudo_fixup;
4119 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4121 e.X_add_symbol = unwind.info;
4122 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4123 bytes_per_address, &e);
4126 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4130 subseg_set (saved_seg, saved_subseg);
4132 /* Parse names of main and alternate entry points and set symbol sizes. */
4136 name = input_line_pointer;
4137 c = get_symbol_end ();
4138 p = input_line_pointer;
4139 sym = symbol_find (name);
4140 if (sym && unwind.proc_start
4141 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4142 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4144 fragS *fr = symbol_get_frag (unwind.proc_start);
4145 fragS *frag = symbol_get_frag (sym);
4147 /* Check whether the function label is at or beyond last
4149 while (fr && fr != frag)
4153 if (frag == frag_now && SEG_NORMAL (now_seg))
4154 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4157 symbol_get_obj (sym)->size =
4158 (expressionS *) xmalloc (sizeof (expressionS));
4159 symbol_get_obj (sym)->size->X_op = O_subtract;
4160 symbol_get_obj (sym)->size->X_add_symbol
4161 = symbol_new (FAKE_LABEL_NAME, now_seg,
4162 frag_now_fix (), frag_now);
4163 symbol_get_obj (sym)->size->X_op_symbol = sym;
4164 symbol_get_obj (sym)->size->X_add_number = 0;
4170 if (*input_line_pointer != ',')
4172 ++input_line_pointer;
4174 demand_empty_rest_of_line ();
4175 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4179 dot_template (template)
4182 CURR_SLOT.user_template = template;
4187 int dummy ATTRIBUTE_UNUSED;
4189 int ins, locs, outs, rots;
4191 if (is_it_end_of_statement ())
4192 ins = locs = outs = rots = 0;
4195 ins = get_absolute_expression ();
4196 if (*input_line_pointer++ != ',')
4198 locs = get_absolute_expression ();
4199 if (*input_line_pointer++ != ',')
4201 outs = get_absolute_expression ();
4202 if (*input_line_pointer++ != ',')
4204 rots = get_absolute_expression ();
4206 set_regstack (ins, locs, outs, rots);
4210 as_bad ("Comma expected");
4211 ignore_rest_of_line ();
4218 unsigned num_regs, num_alloced = 0;
4219 struct dynreg **drpp, *dr;
4220 int ch, base_reg = 0;
4226 case DYNREG_GR: base_reg = REG_GR + 32; break;
4227 case DYNREG_FR: base_reg = REG_FR + 32; break;
4228 case DYNREG_PR: base_reg = REG_P + 16; break;
4232 /* First, remove existing names from hash table. */
4233 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4235 hash_delete (md.dynreg_hash, dr->name);
4239 drpp = &md.dynreg[type];
4242 start = input_line_pointer;
4243 ch = get_symbol_end ();
4244 *input_line_pointer = ch;
4245 len = (input_line_pointer - start);
4248 if (*input_line_pointer != '[')
4250 as_bad ("Expected '['");
4253 ++input_line_pointer; /* skip '[' */
4255 num_regs = get_absolute_expression ();
4257 if (*input_line_pointer++ != ']')
4259 as_bad ("Expected ']'");
4264 num_alloced += num_regs;
4268 if (num_alloced > md.rot.num_regs)
4270 as_bad ("Used more than the declared %d rotating registers",
4276 if (num_alloced > 96)
4278 as_bad ("Used more than the available 96 rotating registers");
4283 if (num_alloced > 48)
4285 as_bad ("Used more than the available 48 rotating registers");
4294 name = obstack_alloc (¬es, len + 1);
4295 memcpy (name, start, len);
4300 *drpp = obstack_alloc (¬es, sizeof (*dr));
4301 memset (*drpp, 0, sizeof (*dr));
4306 dr->num_regs = num_regs;
4307 dr->base = base_reg;
4309 base_reg += num_regs;
4311 if (hash_insert (md.dynreg_hash, name, dr))
4313 as_bad ("Attempt to redefine register set `%s'", name);
4317 if (*input_line_pointer != ',')
4319 ++input_line_pointer; /* skip comma */
4322 demand_empty_rest_of_line ();
4326 ignore_rest_of_line ();
4330 dot_byteorder (byteorder)
4333 segment_info_type *seginfo = seg_info (now_seg);
4335 if (byteorder == -1)
4337 if (seginfo->tc_segment_info_data.endian == 0)
4338 seginfo->tc_segment_info_data.endian
4339 = TARGET_BYTES_BIG_ENDIAN ? 1 : 2;
4340 byteorder = seginfo->tc_segment_info_data.endian == 1;
4343 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4345 if (target_big_endian != byteorder)
4347 target_big_endian = byteorder;
4348 if (target_big_endian)
4350 ia64_number_to_chars = number_to_chars_bigendian;
4351 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4355 ia64_number_to_chars = number_to_chars_littleendian;
4356 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4363 int dummy ATTRIBUTE_UNUSED;
4370 option = input_line_pointer;
4371 ch = get_symbol_end ();
4372 if (strcmp (option, "lsb") == 0)
4373 md.flags &= ~EF_IA_64_BE;
4374 else if (strcmp (option, "msb") == 0)
4375 md.flags |= EF_IA_64_BE;
4376 else if (strcmp (option, "abi32") == 0)
4377 md.flags &= ~EF_IA_64_ABI64;
4378 else if (strcmp (option, "abi64") == 0)
4379 md.flags |= EF_IA_64_ABI64;
4381 as_bad ("Unknown psr option `%s'", option);
4382 *input_line_pointer = ch;
4385 if (*input_line_pointer != ',')
4388 ++input_line_pointer;
4391 demand_empty_rest_of_line ();
4396 int dummy ATTRIBUTE_UNUSED;
4398 new_logical_line (0, get_absolute_expression ());
4399 demand_empty_rest_of_line ();
4403 parse_section_name ()
4409 if (*input_line_pointer != '"')
4411 as_bad ("Missing section name");
4412 ignore_rest_of_line ();
4415 name = demand_copy_C_string (&len);
4418 ignore_rest_of_line ();
4422 if (*input_line_pointer != ',')
4424 as_bad ("Comma expected after section name");
4425 ignore_rest_of_line ();
4428 ++input_line_pointer; /* skip comma */
4436 char *name = parse_section_name ();
4440 md.keep_pending_output = 1;
4443 obj_elf_previous (0);
4444 md.keep_pending_output = 0;
4447 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4450 stmt_float_cons (kind)
4471 ia64_do_align (alignment);
4479 int saved_auto_align = md.auto_align;
4483 md.auto_align = saved_auto_align;
4487 dot_xfloat_cons (kind)
4490 char *name = parse_section_name ();
4494 md.keep_pending_output = 1;
4496 stmt_float_cons (kind);
4497 obj_elf_previous (0);
4498 md.keep_pending_output = 0;
4502 dot_xstringer (zero)
4505 char *name = parse_section_name ();
4509 md.keep_pending_output = 1;
4512 obj_elf_previous (0);
4513 md.keep_pending_output = 0;
4520 int saved_auto_align = md.auto_align;
4521 char *name = parse_section_name ();
4525 md.keep_pending_output = 1;
4529 md.auto_align = saved_auto_align;
4530 obj_elf_previous (0);
4531 md.keep_pending_output = 0;
4535 dot_xfloat_cons_ua (kind)
4538 int saved_auto_align = md.auto_align;
4539 char *name = parse_section_name ();
4543 md.keep_pending_output = 1;
4546 stmt_float_cons (kind);
4547 md.auto_align = saved_auto_align;
4548 obj_elf_previous (0);
4549 md.keep_pending_output = 0;
4552 /* .reg.val <regname>,value */
4556 int dummy ATTRIBUTE_UNUSED;
4561 if (reg.X_op != O_register)
4563 as_bad (_("Register name expected"));
4564 ignore_rest_of_line ();
4566 else if (*input_line_pointer++ != ',')
4568 as_bad (_("Comma expected"));
4569 ignore_rest_of_line ();
4573 valueT value = get_absolute_expression ();
4574 int regno = reg.X_add_number;
4575 if (regno < REG_GR || regno > REG_GR + 128)
4576 as_warn (_("Register value annotation ignored"));
4579 gr_values[regno - REG_GR].known = 1;
4580 gr_values[regno - REG_GR].value = value;
4581 gr_values[regno - REG_GR].path = md.path;
4584 demand_empty_rest_of_line ();
4587 /* select dv checking mode
4592 A stop is inserted when changing modes
4599 if (md.manual_bundling)
4600 as_warn (_("Directive invalid within a bundle"));
4602 if (type == 'E' || type == 'A')
4603 md.mode_explicitly_set = 0;
4605 md.mode_explicitly_set = 1;
4612 if (md.explicit_mode)
4613 insn_group_break (1, 0, 0);
4614 md.explicit_mode = 0;
4618 if (!md.explicit_mode)
4619 insn_group_break (1, 0, 0);
4620 md.explicit_mode = 1;
4624 if (md.explicit_mode != md.default_explicit_mode)
4625 insn_group_break (1, 0, 0);
4626 md.explicit_mode = md.default_explicit_mode;
4627 md.mode_explicitly_set = 0;
4638 for (regno = 0; regno < 64; regno++)
4640 if (mask & ((valueT) 1 << regno))
4642 fprintf (stderr, "%s p%d", comma, regno);
4649 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4650 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4651 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4652 .pred.safe_across_calls p1 [, p2 [,...]]
4661 int p1 = -1, p2 = -1;
4665 if (*input_line_pointer != '"')
4667 as_bad (_("Missing predicate relation type"));
4668 ignore_rest_of_line ();
4674 char *form = demand_copy_C_string (&len);
4675 if (strcmp (form, "mutex") == 0)
4677 else if (strcmp (form, "clear") == 0)
4679 else if (strcmp (form, "imply") == 0)
4683 as_bad (_("Unrecognized predicate relation type"));
4684 ignore_rest_of_line ();
4688 if (*input_line_pointer == ',')
4689 ++input_line_pointer;
4699 if (TOUPPER (*input_line_pointer) != 'P'
4700 || (regno = atoi (++input_line_pointer)) < 0
4703 as_bad (_("Predicate register expected"));
4704 ignore_rest_of_line ();
4707 while (ISDIGIT (*input_line_pointer))
4708 ++input_line_pointer;
4715 as_warn (_("Duplicate predicate register ignored"));
4718 /* See if it's a range. */
4719 if (*input_line_pointer == '-')
4722 ++input_line_pointer;
4724 if (TOUPPER (*input_line_pointer) != 'P'
4725 || (regno = atoi (++input_line_pointer)) < 0
4728 as_bad (_("Predicate register expected"));
4729 ignore_rest_of_line ();
4732 while (ISDIGIT (*input_line_pointer))
4733 ++input_line_pointer;
4737 as_bad (_("Bad register range"));
4738 ignore_rest_of_line ();
4749 if (*input_line_pointer != ',')
4751 ++input_line_pointer;
4760 clear_qp_mutex (mask);
4761 clear_qp_implies (mask, (valueT) 0);
4764 if (count != 2 || p1 == -1 || p2 == -1)
4765 as_bad (_("Predicate source and target required"));
4766 else if (p1 == 0 || p2 == 0)
4767 as_bad (_("Use of p0 is not valid in this context"));
4769 add_qp_imply (p1, p2);
4774 as_bad (_("At least two PR arguments expected"));
4779 as_bad (_("Use of p0 is not valid in this context"));
4782 add_qp_mutex (mask);
4785 /* note that we don't override any existing relations */
4788 as_bad (_("At least one PR argument expected"));
4793 fprintf (stderr, "Safe across calls: ");
4794 print_prmask (mask);
4795 fprintf (stderr, "\n");
4797 qp_safe_across_calls = mask;
4800 demand_empty_rest_of_line ();
4803 /* .entry label [, label [, ...]]
4804 Hint to DV code that the given labels are to be considered entry points.
4805 Otherwise, only global labels are considered entry points. */
4809 int dummy ATTRIBUTE_UNUSED;
4818 name = input_line_pointer;
4819 c = get_symbol_end ();
4820 symbolP = symbol_find_or_make (name);
4822 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4824 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4827 *input_line_pointer = c;
4829 c = *input_line_pointer;
4832 input_line_pointer++;
4834 if (*input_line_pointer == '\n')
4840 demand_empty_rest_of_line ();
4843 /* .mem.offset offset, base
4844 "base" is used to distinguish between offsets from a different base. */
4847 dot_mem_offset (dummy)
4848 int dummy ATTRIBUTE_UNUSED;
4850 md.mem_offset.hint = 1;
4851 md.mem_offset.offset = get_absolute_expression ();
4852 if (*input_line_pointer != ',')
4854 as_bad (_("Comma expected"));
4855 ignore_rest_of_line ();
4858 ++input_line_pointer;
4859 md.mem_offset.base = get_absolute_expression ();
4860 demand_empty_rest_of_line ();
4863 /* ia64-specific pseudo-ops: */
4864 const pseudo_typeS md_pseudo_table[] =
4866 { "radix", dot_radix, 0 },
4867 { "lcomm", s_lcomm_bytes, 1 },
4868 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4869 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4870 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4871 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4872 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4873 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4874 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4875 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4876 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4877 { "proc", dot_proc, 0 },
4878 { "body", dot_body, 0 },
4879 { "prologue", dot_prologue, 0 },
4880 { "endp", dot_endp, 0 },
4882 { "fframe", dot_fframe, 0 },
4883 { "vframe", dot_vframe, 0 },
4884 { "vframesp", dot_vframesp, 0 },
4885 { "vframepsp", dot_vframepsp, 0 },
4886 { "save", dot_save, 0 },
4887 { "restore", dot_restore, 0 },
4888 { "restorereg", dot_restorereg, 0 },
4889 { "restorereg.p", dot_restorereg_p, 0 },
4890 { "handlerdata", dot_handlerdata, 0 },
4891 { "unwentry", dot_unwentry, 0 },
4892 { "altrp", dot_altrp, 0 },
4893 { "savesp", dot_savemem, 0 },
4894 { "savepsp", dot_savemem, 1 },
4895 { "save.g", dot_saveg, 0 },
4896 { "save.f", dot_savef, 0 },
4897 { "save.b", dot_saveb, 0 },
4898 { "save.gf", dot_savegf, 0 },
4899 { "spill", dot_spill, 0 },
4900 { "spillreg", dot_spillreg, 0 },
4901 { "spillsp", dot_spillmem, 0 },
4902 { "spillpsp", dot_spillmem, 1 },
4903 { "spillreg.p", dot_spillreg_p, 0 },
4904 { "spillsp.p", dot_spillmem_p, 0 },
4905 { "spillpsp.p", dot_spillmem_p, 1 },
4906 { "label_state", dot_label_state, 0 },
4907 { "copy_state", dot_copy_state, 0 },
4908 { "unwabi", dot_unwabi, 0 },
4909 { "personality", dot_personality, 0 },
4911 { "estate", dot_estate, 0 },
4913 { "mii", dot_template, 0x0 },
4914 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4915 { "mlx", dot_template, 0x2 },
4916 { "mmi", dot_template, 0x4 },
4917 { "mfi", dot_template, 0x6 },
4918 { "mmf", dot_template, 0x7 },
4919 { "mib", dot_template, 0x8 },
4920 { "mbb", dot_template, 0x9 },
4921 { "bbb", dot_template, 0xb },
4922 { "mmb", dot_template, 0xc },
4923 { "mfb", dot_template, 0xe },
4925 { "lb", dot_scope, 0 },
4926 { "le", dot_scope, 1 },
4928 { "align", s_align_bytes, 0 },
4929 { "regstk", dot_regstk, 0 },
4930 { "rotr", dot_rot, DYNREG_GR },
4931 { "rotf", dot_rot, DYNREG_FR },
4932 { "rotp", dot_rot, DYNREG_PR },
4933 { "lsb", dot_byteorder, 0 },
4934 { "msb", dot_byteorder, 1 },
4935 { "psr", dot_psr, 0 },
4936 { "alias", dot_alias, 0 },
4937 { "secalias", dot_alias, 1 },
4938 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4940 { "xdata1", dot_xdata, 1 },
4941 { "xdata2", dot_xdata, 2 },
4942 { "xdata4", dot_xdata, 4 },
4943 { "xdata8", dot_xdata, 8 },
4944 { "xreal4", dot_xfloat_cons, 'f' },
4945 { "xreal8", dot_xfloat_cons, 'd' },
4946 { "xreal10", dot_xfloat_cons, 'x' },
4947 { "xreal16", dot_xfloat_cons, 'X' },
4948 { "xstring", dot_xstringer, 0 },
4949 { "xstringz", dot_xstringer, 1 },
4951 /* unaligned versions: */
4952 { "xdata2.ua", dot_xdata_ua, 2 },
4953 { "xdata4.ua", dot_xdata_ua, 4 },
4954 { "xdata8.ua", dot_xdata_ua, 8 },
4955 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4956 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4957 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4958 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
4960 /* annotations/DV checking support */
4961 { "entry", dot_entry, 0 },
4962 { "mem.offset", dot_mem_offset, 0 },
4963 { "pred.rel", dot_pred_rel, 0 },
4964 { "pred.rel.clear", dot_pred_rel, 'c' },
4965 { "pred.rel.imply", dot_pred_rel, 'i' },
4966 { "pred.rel.mutex", dot_pred_rel, 'm' },
4967 { "pred.safe_across_calls", dot_pred_rel, 's' },
4968 { "reg.val", dot_reg_val, 0 },
4969 { "auto", dot_dv_mode, 'a' },
4970 { "explicit", dot_dv_mode, 'e' },
4971 { "default", dot_dv_mode, 'd' },
4973 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
4974 IA-64 aligns data allocation pseudo-ops by default, so we have to
4975 tell it that these ones are supposed to be unaligned. Long term,
4976 should rewrite so that only IA-64 specific data allocation pseudo-ops
4977 are aligned by default. */
4978 {"2byte", stmt_cons_ua, 2},
4979 {"4byte", stmt_cons_ua, 4},
4980 {"8byte", stmt_cons_ua, 8},
4985 static const struct pseudo_opcode
4988 void (*handler) (int);
4993 /* these are more like pseudo-ops, but don't start with a dot */
4994 { "data1", cons, 1 },
4995 { "data2", cons, 2 },
4996 { "data4", cons, 4 },
4997 { "data8", cons, 8 },
4998 { "data16", cons, 16 },
4999 { "real4", stmt_float_cons, 'f' },
5000 { "real8", stmt_float_cons, 'd' },
5001 { "real10", stmt_float_cons, 'x' },
5002 { "real16", stmt_float_cons, 'X' },
5003 { "string", stringer, 0 },
5004 { "stringz", stringer, 1 },
5006 /* unaligned versions: */
5007 { "data2.ua", stmt_cons_ua, 2 },
5008 { "data4.ua", stmt_cons_ua, 4 },
5009 { "data8.ua", stmt_cons_ua, 8 },
5010 { "data16.ua", stmt_cons_ua, 16 },
5011 { "real4.ua", float_cons, 'f' },
5012 { "real8.ua", float_cons, 'd' },
5013 { "real10.ua", float_cons, 'x' },
5014 { "real16.ua", float_cons, 'X' },
5017 /* Declare a register by creating a symbol for it and entering it in
5018 the symbol table. */
5021 declare_register (name, regnum)
5028 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5030 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5032 as_fatal ("Inserting \"%s\" into register table failed: %s",
5039 declare_register_set (prefix, num_regs, base_regnum)
5047 for (i = 0; i < num_regs; ++i)
5049 sprintf (name, "%s%u", prefix, i);
5050 declare_register (name, base_regnum + i);
5055 operand_width (opnd)
5056 enum ia64_opnd opnd;
5058 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5059 unsigned int bits = 0;
5063 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5064 bits += odesc->field[i].bits;
5069 static enum operand_match_result
5070 operand_match (idesc, index, e)
5071 const struct ia64_opcode *idesc;
5075 enum ia64_opnd opnd = idesc->operands[index];
5076 int bits, relocatable = 0;
5077 struct insn_fix *fix;
5084 case IA64_OPND_AR_CCV:
5085 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5086 return OPERAND_MATCH;
5089 case IA64_OPND_AR_CSD:
5090 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5091 return OPERAND_MATCH;
5094 case IA64_OPND_AR_PFS:
5095 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5096 return OPERAND_MATCH;
5100 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5101 return OPERAND_MATCH;
5105 if (e->X_op == O_register && e->X_add_number == REG_IP)
5106 return OPERAND_MATCH;
5110 if (e->X_op == O_register && e->X_add_number == REG_PR)
5111 return OPERAND_MATCH;
5114 case IA64_OPND_PR_ROT:
5115 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5116 return OPERAND_MATCH;
5120 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5121 return OPERAND_MATCH;
5124 case IA64_OPND_PSR_L:
5125 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5126 return OPERAND_MATCH;
5129 case IA64_OPND_PSR_UM:
5130 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5131 return OPERAND_MATCH;
5135 if (e->X_op == O_constant)
5137 if (e->X_add_number == 1)
5138 return OPERAND_MATCH;
5140 return OPERAND_OUT_OF_RANGE;
5145 if (e->X_op == O_constant)
5147 if (e->X_add_number == 8)
5148 return OPERAND_MATCH;
5150 return OPERAND_OUT_OF_RANGE;
5155 if (e->X_op == O_constant)
5157 if (e->X_add_number == 16)
5158 return OPERAND_MATCH;
5160 return OPERAND_OUT_OF_RANGE;
5164 /* register operands: */
5167 if (e->X_op == O_register && e->X_add_number >= REG_AR
5168 && e->X_add_number < REG_AR + 128)
5169 return OPERAND_MATCH;
5174 if (e->X_op == O_register && e->X_add_number >= REG_BR
5175 && e->X_add_number < REG_BR + 8)
5176 return OPERAND_MATCH;
5180 if (e->X_op == O_register && e->X_add_number >= REG_CR
5181 && e->X_add_number < REG_CR + 128)
5182 return OPERAND_MATCH;
5189 if (e->X_op == O_register && e->X_add_number >= REG_FR
5190 && e->X_add_number < REG_FR + 128)
5191 return OPERAND_MATCH;
5196 if (e->X_op == O_register && e->X_add_number >= REG_P
5197 && e->X_add_number < REG_P + 64)
5198 return OPERAND_MATCH;
5204 if (e->X_op == O_register && e->X_add_number >= REG_GR
5205 && e->X_add_number < REG_GR + 128)
5206 return OPERAND_MATCH;
5209 case IA64_OPND_R3_2:
5210 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5212 if (e->X_add_number < REG_GR + 4)
5213 return OPERAND_MATCH;
5214 else if (e->X_add_number < REG_GR + 128)
5215 return OPERAND_OUT_OF_RANGE;
5219 /* indirect operands: */
5220 case IA64_OPND_CPUID_R3:
5221 case IA64_OPND_DBR_R3:
5222 case IA64_OPND_DTR_R3:
5223 case IA64_OPND_ITR_R3:
5224 case IA64_OPND_IBR_R3:
5225 case IA64_OPND_MSR_R3:
5226 case IA64_OPND_PKR_R3:
5227 case IA64_OPND_PMC_R3:
5228 case IA64_OPND_PMD_R3:
5229 case IA64_OPND_RR_R3:
5230 if (e->X_op == O_index && e->X_op_symbol
5231 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5232 == opnd - IA64_OPND_CPUID_R3))
5233 return OPERAND_MATCH;
5237 if (e->X_op == O_index && !e->X_op_symbol)
5238 return OPERAND_MATCH;
5241 /* immediate operands: */
5242 case IA64_OPND_CNT2a:
5243 case IA64_OPND_LEN4:
5244 case IA64_OPND_LEN6:
5245 bits = operand_width (idesc->operands[index]);
5246 if (e->X_op == O_constant)
5248 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5249 return OPERAND_MATCH;
5251 return OPERAND_OUT_OF_RANGE;
5255 case IA64_OPND_CNT2b:
5256 if (e->X_op == O_constant)
5258 if ((bfd_vma) (e->X_add_number - 1) < 3)
5259 return OPERAND_MATCH;
5261 return OPERAND_OUT_OF_RANGE;
5265 case IA64_OPND_CNT2c:
5266 val = e->X_add_number;
5267 if (e->X_op == O_constant)
5269 if ((val == 0 || val == 7 || val == 15 || val == 16))
5270 return OPERAND_MATCH;
5272 return OPERAND_OUT_OF_RANGE;
5277 /* SOR must be an integer multiple of 8 */
5278 if (e->X_op == O_constant && e->X_add_number & 0x7)
5279 return OPERAND_OUT_OF_RANGE;
5282 if (e->X_op == O_constant)
5284 if ((bfd_vma) e->X_add_number <= 96)
5285 return OPERAND_MATCH;
5287 return OPERAND_OUT_OF_RANGE;
5291 case IA64_OPND_IMMU62:
5292 if (e->X_op == O_constant)
5294 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5295 return OPERAND_MATCH;
5297 return OPERAND_OUT_OF_RANGE;
5301 /* FIXME -- need 62-bit relocation type */
5302 as_bad (_("62-bit relocation not yet implemented"));
5306 case IA64_OPND_IMMU64:
5307 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5308 || e->X_op == O_subtract)
5310 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5311 fix->code = BFD_RELOC_IA64_IMM64;
5312 if (e->X_op != O_subtract)
5314 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5315 if (e->X_op == O_pseudo_fixup)
5319 fix->opnd = idesc->operands[index];
5322 ++CURR_SLOT.num_fixups;
5323 return OPERAND_MATCH;
5325 else if (e->X_op == O_constant)
5326 return OPERAND_MATCH;
5329 case IA64_OPND_CCNT5:
5330 case IA64_OPND_CNT5:
5331 case IA64_OPND_CNT6:
5332 case IA64_OPND_CPOS6a:
5333 case IA64_OPND_CPOS6b:
5334 case IA64_OPND_CPOS6c:
5335 case IA64_OPND_IMMU2:
5336 case IA64_OPND_IMMU7a:
5337 case IA64_OPND_IMMU7b:
5338 case IA64_OPND_IMMU21:
5339 case IA64_OPND_IMMU24:
5340 case IA64_OPND_MBTYPE4:
5341 case IA64_OPND_MHTYPE8:
5342 case IA64_OPND_POS6:
5343 bits = operand_width (idesc->operands[index]);
5344 if (e->X_op == O_constant)
5346 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5347 return OPERAND_MATCH;
5349 return OPERAND_OUT_OF_RANGE;
5353 case IA64_OPND_IMMU9:
5354 bits = operand_width (idesc->operands[index]);
5355 if (e->X_op == O_constant)
5357 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5359 int lobits = e->X_add_number & 0x3;
5360 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5361 e->X_add_number |= (bfd_vma) 0x3;
5362 return OPERAND_MATCH;
5365 return OPERAND_OUT_OF_RANGE;
5369 case IA64_OPND_IMM44:
5370 /* least 16 bits must be zero */
5371 if ((e->X_add_number & 0xffff) != 0)
5372 /* XXX technically, this is wrong: we should not be issuing warning
5373 messages until we're sure this instruction pattern is going to
5375 as_warn (_("lower 16 bits of mask ignored"));
5377 if (e->X_op == O_constant)
5379 if (((e->X_add_number >= 0
5380 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5381 || (e->X_add_number < 0
5382 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5385 if (e->X_add_number >= 0
5386 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5388 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5390 return OPERAND_MATCH;
5393 return OPERAND_OUT_OF_RANGE;
5397 case IA64_OPND_IMM17:
5398 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5399 if (e->X_op == O_constant)
5401 if (((e->X_add_number >= 0
5402 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5403 || (e->X_add_number < 0
5404 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5407 if (e->X_add_number >= 0
5408 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5410 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5412 return OPERAND_MATCH;
5415 return OPERAND_OUT_OF_RANGE;
5419 case IA64_OPND_IMM14:
5420 case IA64_OPND_IMM22:
5422 case IA64_OPND_IMM1:
5423 case IA64_OPND_IMM8:
5424 case IA64_OPND_IMM8U4:
5425 case IA64_OPND_IMM8M1:
5426 case IA64_OPND_IMM8M1U4:
5427 case IA64_OPND_IMM8M1U8:
5428 case IA64_OPND_IMM9a:
5429 case IA64_OPND_IMM9b:
5430 bits = operand_width (idesc->operands[index]);
5431 if (relocatable && (e->X_op == O_symbol
5432 || e->X_op == O_subtract
5433 || e->X_op == O_pseudo_fixup))
5435 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5437 if (idesc->operands[index] == IA64_OPND_IMM14)
5438 fix->code = BFD_RELOC_IA64_IMM14;
5440 fix->code = BFD_RELOC_IA64_IMM22;
5442 if (e->X_op != O_subtract)
5444 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5445 if (e->X_op == O_pseudo_fixup)
5449 fix->opnd = idesc->operands[index];
5452 ++CURR_SLOT.num_fixups;
5453 return OPERAND_MATCH;
5455 else if (e->X_op != O_constant
5456 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5457 return OPERAND_MISMATCH;
5459 if (opnd == IA64_OPND_IMM8M1U4)
5461 /* Zero is not valid for unsigned compares that take an adjusted
5462 constant immediate range. */
5463 if (e->X_add_number == 0)
5464 return OPERAND_OUT_OF_RANGE;
5466 /* Sign-extend 32-bit unsigned numbers, so that the following range
5467 checks will work. */
5468 val = e->X_add_number;
5469 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5470 && ((val & ((bfd_vma) 1 << 31)) != 0))
5471 val = ((val << 32) >> 32);
5473 /* Check for 0x100000000. This is valid because
5474 0x100000000-1 is the same as ((uint32_t) -1). */
5475 if (val == ((bfd_signed_vma) 1 << 32))
5476 return OPERAND_MATCH;
5480 else if (opnd == IA64_OPND_IMM8M1U8)
5482 /* Zero is not valid for unsigned compares that take an adjusted
5483 constant immediate range. */
5484 if (e->X_add_number == 0)
5485 return OPERAND_OUT_OF_RANGE;
5487 /* Check for 0x10000000000000000. */
5488 if (e->X_op == O_big)
5490 if (generic_bignum[0] == 0
5491 && generic_bignum[1] == 0
5492 && generic_bignum[2] == 0
5493 && generic_bignum[3] == 0
5494 && generic_bignum[4] == 1)
5495 return OPERAND_MATCH;
5497 return OPERAND_OUT_OF_RANGE;
5500 val = e->X_add_number - 1;
5502 else if (opnd == IA64_OPND_IMM8M1)
5503 val = e->X_add_number - 1;
5504 else if (opnd == IA64_OPND_IMM8U4)
5506 /* Sign-extend 32-bit unsigned numbers, so that the following range
5507 checks will work. */
5508 val = e->X_add_number;
5509 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5510 && ((val & ((bfd_vma) 1 << 31)) != 0))
5511 val = ((val << 32) >> 32);
5514 val = e->X_add_number;
5516 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5517 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5518 return OPERAND_MATCH;
5520 return OPERAND_OUT_OF_RANGE;
5522 case IA64_OPND_INC3:
5523 /* +/- 1, 4, 8, 16 */
5524 val = e->X_add_number;
5527 if (e->X_op == O_constant)
5529 if ((val == 1 || val == 4 || val == 8 || val == 16))
5530 return OPERAND_MATCH;
5532 return OPERAND_OUT_OF_RANGE;
5536 case IA64_OPND_TGT25:
5537 case IA64_OPND_TGT25b:
5538 case IA64_OPND_TGT25c:
5539 case IA64_OPND_TGT64:
5540 if (e->X_op == O_symbol)
5542 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5543 if (opnd == IA64_OPND_TGT25)
5544 fix->code = BFD_RELOC_IA64_PCREL21F;
5545 else if (opnd == IA64_OPND_TGT25b)
5546 fix->code = BFD_RELOC_IA64_PCREL21M;
5547 else if (opnd == IA64_OPND_TGT25c)
5548 fix->code = BFD_RELOC_IA64_PCREL21B;
5549 else if (opnd == IA64_OPND_TGT64)
5550 fix->code = BFD_RELOC_IA64_PCREL60B;
5554 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5555 fix->opnd = idesc->operands[index];
5558 ++CURR_SLOT.num_fixups;
5559 return OPERAND_MATCH;
5561 case IA64_OPND_TAG13:
5562 case IA64_OPND_TAG13b:
5566 return OPERAND_MATCH;
5569 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5570 /* There are no external relocs for TAG13/TAG13b fields, so we
5571 create a dummy reloc. This will not live past md_apply_fix3. */
5572 fix->code = BFD_RELOC_UNUSED;
5573 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5574 fix->opnd = idesc->operands[index];
5577 ++CURR_SLOT.num_fixups;
5578 return OPERAND_MATCH;
5585 case IA64_OPND_LDXMOV:
5586 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5587 fix->code = BFD_RELOC_IA64_LDXMOV;
5588 fix->opnd = idesc->operands[index];
5591 ++CURR_SLOT.num_fixups;
5592 return OPERAND_MATCH;
5597 return OPERAND_MISMATCH;
5606 memset (e, 0, sizeof (*e));
5609 if (*input_line_pointer != '}')
5611 sep = *input_line_pointer++;
5615 if (!md.manual_bundling)
5616 as_warn ("Found '}' when manual bundling is off");
5618 CURR_SLOT.manual_bundling_off = 1;
5619 md.manual_bundling = 0;
5625 /* Returns the next entry in the opcode table that matches the one in
5626 IDESC, and frees the entry in IDESC. If no matching entry is
5627 found, NULL is returned instead. */
5629 static struct ia64_opcode *
5630 get_next_opcode (struct ia64_opcode *idesc)
5632 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5633 ia64_free_opcode (idesc);
5637 /* Parse the operands for the opcode and find the opcode variant that
5638 matches the specified operands, or NULL if no match is possible. */
5640 static struct ia64_opcode *
5641 parse_operands (idesc)
5642 struct ia64_opcode *idesc;
5644 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5645 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5646 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5647 enum operand_match_result result;
5649 char *first_arg = 0, *end, *saved_input_pointer;
5652 assert (strlen (idesc->name) <= 128);
5654 strcpy (mnemonic, idesc->name);
5655 if (idesc->operands[2] == IA64_OPND_SOF)
5657 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5658 can't parse the first operand until we have parsed the
5659 remaining operands of the "alloc" instruction. */
5661 first_arg = input_line_pointer;
5662 end = strchr (input_line_pointer, '=');
5665 as_bad ("Expected separator `='");
5668 input_line_pointer = end + 1;
5673 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5675 sep = parse_operand (CURR_SLOT.opnd + i);
5676 if (CURR_SLOT.opnd[i].X_op == O_absent)
5681 if (sep != '=' && sep != ',')
5686 if (num_outputs > 0)
5687 as_bad ("Duplicate equal sign (=) in instruction");
5689 num_outputs = i + 1;
5694 as_bad ("Illegal operand separator `%c'", sep);
5698 if (idesc->operands[2] == IA64_OPND_SOF)
5700 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5701 know (strcmp (idesc->name, "alloc") == 0);
5702 if (num_operands == 5 /* first_arg not included in this count! */
5703 && CURR_SLOT.opnd[2].X_op == O_constant
5704 && CURR_SLOT.opnd[3].X_op == O_constant
5705 && CURR_SLOT.opnd[4].X_op == O_constant
5706 && CURR_SLOT.opnd[5].X_op == O_constant)
5708 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5709 CURR_SLOT.opnd[3].X_add_number,
5710 CURR_SLOT.opnd[4].X_add_number,
5711 CURR_SLOT.opnd[5].X_add_number);
5713 /* now we can parse the first arg: */
5714 saved_input_pointer = input_line_pointer;
5715 input_line_pointer = first_arg;
5716 sep = parse_operand (CURR_SLOT.opnd + 0);
5718 --num_outputs; /* force error */
5719 input_line_pointer = saved_input_pointer;
5721 CURR_SLOT.opnd[2].X_add_number = sof;
5722 CURR_SLOT.opnd[3].X_add_number
5723 = sof - CURR_SLOT.opnd[4].X_add_number;
5724 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5728 highest_unmatched_operand = 0;
5729 curr_out_of_range_pos = -1;
5731 expected_operand = idesc->operands[0];
5732 for (; idesc; idesc = get_next_opcode (idesc))
5734 if (num_outputs != idesc->num_outputs)
5735 continue; /* mismatch in # of outputs */
5737 CURR_SLOT.num_fixups = 0;
5739 /* Try to match all operands. If we see an out-of-range operand,
5740 then continue trying to match the rest of the operands, since if
5741 the rest match, then this idesc will give the best error message. */
5743 out_of_range_pos = -1;
5744 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5746 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5747 if (result != OPERAND_MATCH)
5749 if (result != OPERAND_OUT_OF_RANGE)
5751 if (out_of_range_pos < 0)
5752 /* remember position of the first out-of-range operand: */
5753 out_of_range_pos = i;
5757 /* If we did not match all operands, or if at least one operand was
5758 out-of-range, then this idesc does not match. Keep track of which
5759 idesc matched the most operands before failing. If we have two
5760 idescs that failed at the same position, and one had an out-of-range
5761 operand, then prefer the out-of-range operand. Thus if we have
5762 "add r0=0x1000000,r1" we get an error saying the constant is out
5763 of range instead of an error saying that the constant should have been
5766 if (i != num_operands || out_of_range_pos >= 0)
5768 if (i > highest_unmatched_operand
5769 || (i == highest_unmatched_operand
5770 && out_of_range_pos > curr_out_of_range_pos))
5772 highest_unmatched_operand = i;
5773 if (out_of_range_pos >= 0)
5775 expected_operand = idesc->operands[out_of_range_pos];
5776 error_pos = out_of_range_pos;
5780 expected_operand = idesc->operands[i];
5783 curr_out_of_range_pos = out_of_range_pos;
5788 if (num_operands < NELEMS (idesc->operands)
5789 && idesc->operands[num_operands])
5790 continue; /* mismatch in number of arguments */
5796 if (expected_operand)
5797 as_bad ("Operand %u of `%s' should be %s",
5798 error_pos + 1, mnemonic,
5799 elf64_ia64_operands[expected_operand].desc);
5801 as_bad ("Operand mismatch");
5807 /* Keep track of state necessary to determine whether a NOP is necessary
5808 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5809 detect a case where additional NOPs may be necessary. */
5811 errata_nop_necessary_p (slot, insn_unit)
5813 enum ia64_unit insn_unit;
5816 struct group *this_group = md.last_groups + md.group_idx;
5817 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5818 struct ia64_opcode *idesc = slot->idesc;
5820 /* Test whether this could be the first insn in a problematic sequence. */
5821 if (insn_unit == IA64_UNIT_F)
5823 for (i = 0; i < idesc->num_outputs; i++)
5824 if (idesc->operands[i] == IA64_OPND_P1
5825 || idesc->operands[i] == IA64_OPND_P2)
5827 int regno = slot->opnd[i].X_add_number - REG_P;
5828 /* Ignore invalid operands; they generate errors elsewhere. */
5831 this_group->p_reg_set[regno] = 1;
5835 /* Test whether this could be the second insn in a problematic sequence. */
5836 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5837 && prev_group->p_reg_set[slot->qp_regno])
5839 for (i = 0; i < idesc->num_outputs; i++)
5840 if (idesc->operands[i] == IA64_OPND_R1
5841 || idesc->operands[i] == IA64_OPND_R2
5842 || idesc->operands[i] == IA64_OPND_R3)
5844 int regno = slot->opnd[i].X_add_number - REG_GR;
5845 /* Ignore invalid operands; they generate errors elsewhere. */
5848 if (strncmp (idesc->name, "add", 3) != 0
5849 && strncmp (idesc->name, "sub", 3) != 0
5850 && strncmp (idesc->name, "shladd", 6) != 0
5851 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5852 this_group->g_reg_set_conditionally[regno] = 1;
5856 /* Test whether this could be the third insn in a problematic sequence. */
5857 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5859 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5860 idesc->operands[i] == IA64_OPND_R3
5861 /* For mov indirect. */
5862 || idesc->operands[i] == IA64_OPND_RR_R3
5863 || idesc->operands[i] == IA64_OPND_DBR_R3
5864 || idesc->operands[i] == IA64_OPND_IBR_R3
5865 || idesc->operands[i] == IA64_OPND_PKR_R3
5866 || idesc->operands[i] == IA64_OPND_PMC_R3
5867 || idesc->operands[i] == IA64_OPND_PMD_R3
5868 || idesc->operands[i] == IA64_OPND_MSR_R3
5869 || idesc->operands[i] == IA64_OPND_CPUID_R3
5871 || idesc->operands[i] == IA64_OPND_ITR_R3
5872 || idesc->operands[i] == IA64_OPND_DTR_R3
5873 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5874 || idesc->operands[i] == IA64_OPND_MR3)
5876 int regno = slot->opnd[i].X_add_number - REG_GR;
5877 /* Ignore invalid operands; they generate errors elsewhere. */
5880 if (idesc->operands[i] == IA64_OPND_R3)
5882 if (strcmp (idesc->name, "fc") != 0
5883 && strcmp (idesc->name, "tak") != 0
5884 && strcmp (idesc->name, "thash") != 0
5885 && strcmp (idesc->name, "tpa") != 0
5886 && strcmp (idesc->name, "ttag") != 0
5887 && strncmp (idesc->name, "ptr", 3) != 0
5888 && strncmp (idesc->name, "ptc", 3) != 0
5889 && strncmp (idesc->name, "probe", 5) != 0)
5892 if (prev_group->g_reg_set_conditionally[regno])
5900 build_insn (slot, insnp)
5904 const struct ia64_operand *odesc, *o2desc;
5905 struct ia64_opcode *idesc = slot->idesc;
5906 bfd_signed_vma insn, val;
5910 insn = idesc->opcode | slot->qp_regno;
5912 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5914 if (slot->opnd[i].X_op == O_register
5915 || slot->opnd[i].X_op == O_constant
5916 || slot->opnd[i].X_op == O_index)
5917 val = slot->opnd[i].X_add_number;
5918 else if (slot->opnd[i].X_op == O_big)
5920 /* This must be the value 0x10000000000000000. */
5921 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5927 switch (idesc->operands[i])
5929 case IA64_OPND_IMMU64:
5930 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5931 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5932 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5933 | (((val >> 63) & 0x1) << 36));
5936 case IA64_OPND_IMMU62:
5937 val &= 0x3fffffffffffffffULL;
5938 if (val != slot->opnd[i].X_add_number)
5939 as_warn (_("Value truncated to 62 bits"));
5940 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5941 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5944 case IA64_OPND_TGT64:
5946 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5947 insn |= ((((val >> 59) & 0x1) << 36)
5948 | (((val >> 0) & 0xfffff) << 13));
5979 case IA64_OPND_R3_2:
5980 case IA64_OPND_CPUID_R3:
5981 case IA64_OPND_DBR_R3:
5982 case IA64_OPND_DTR_R3:
5983 case IA64_OPND_ITR_R3:
5984 case IA64_OPND_IBR_R3:
5986 case IA64_OPND_MSR_R3:
5987 case IA64_OPND_PKR_R3:
5988 case IA64_OPND_PMC_R3:
5989 case IA64_OPND_PMD_R3:
5990 case IA64_OPND_RR_R3:
5998 odesc = elf64_ia64_operands + idesc->operands[i];
5999 err = (*odesc->insert) (odesc, val, &insn);
6001 as_bad_where (slot->src_file, slot->src_line,
6002 "Bad operand value: %s", err);
6003 if (idesc->flags & IA64_OPCODE_PSEUDO)
6005 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6006 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6008 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6009 (*o2desc->insert) (o2desc, val, &insn);
6011 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6012 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6013 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6015 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6016 (*o2desc->insert) (o2desc, 64 - val, &insn);
6026 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
6027 unsigned int manual_bundling = 0;
6028 enum ia64_unit required_unit, insn_unit = 0;
6029 enum ia64_insn_type type[3], insn_type;
6030 unsigned int template, orig_template;
6031 bfd_vma insn[3] = { -1, -1, -1 };
6032 struct ia64_opcode *idesc;
6033 int end_of_insn_group = 0, user_template = -1;
6034 int n, i, j, first, curr;
6036 bfd_vma t0 = 0, t1 = 0;
6037 struct label_fix *lfix;
6038 struct insn_fix *ifix;
6043 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6044 know (first >= 0 & first < NUM_SLOTS);
6045 n = MIN (3, md.num_slots_in_use);
6047 /* Determine template: user user_template if specified, best match
6050 if (md.slot[first].user_template >= 0)
6051 user_template = template = md.slot[first].user_template;
6054 /* Auto select appropriate template. */
6055 memset (type, 0, sizeof (type));
6057 for (i = 0; i < n; ++i)
6059 if (md.slot[curr].label_fixups && i != 0)
6061 type[i] = md.slot[curr].idesc->type;
6062 curr = (curr + 1) % NUM_SLOTS;
6064 template = best_template[type[0]][type[1]][type[2]];
6067 /* initialize instructions with appropriate nops: */
6068 for (i = 0; i < 3; ++i)
6069 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6073 /* now fill in slots with as many insns as possible: */
6075 idesc = md.slot[curr].idesc;
6076 end_of_insn_group = 0;
6077 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6079 /* Set the slot number for prologue/body records now as those
6080 refer to the current point, not the point after the
6081 instruction has been issued: */
6082 /* Don't try to delete prologue/body records here, as that will cause
6083 them to also be deleted from the master list of unwind records. */
6084 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6085 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6086 || ptr->r.type == body)
6088 ptr->slot_number = (unsigned long) f + i;
6089 ptr->slot_frag = frag_now;
6092 if (idesc->flags & IA64_OPCODE_SLOT2)
6094 if (manual_bundling && i != 2)
6095 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6096 "`%s' must be last in bundle", idesc->name);
6100 if (idesc->flags & IA64_OPCODE_LAST)
6103 unsigned int required_template;
6105 /* If we need a stop bit after an M slot, our only choice is
6106 template 5 (M;;MI). If we need a stop bit after a B
6107 slot, our only choice is to place it at the end of the
6108 bundle, because the only available templates are MIB,
6109 MBB, BBB, MMB, and MFB. We don't handle anything other
6110 than M and B slots because these are the only kind of
6111 instructions that can have the IA64_OPCODE_LAST bit set. */
6112 required_template = template;
6113 switch (idesc->type)
6117 required_template = 5;
6125 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6126 "Internal error: don't know how to force %s to end"
6127 "of instruction group", idesc->name);
6131 if (manual_bundling && i != required_slot)
6132 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6133 "`%s' must be last in instruction group",
6135 if (required_slot < i)
6136 /* Can't fit this instruction. */
6140 if (required_template != template)
6142 /* If we switch the template, we need to reset the NOPs
6143 after slot i. The slot-types of the instructions ahead
6144 of i never change, so we don't need to worry about
6145 changing NOPs in front of this slot. */
6146 for (j = i; j < 3; ++j)
6147 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6149 template = required_template;
6151 if (curr != first && md.slot[curr].label_fixups)
6153 if (manual_bundling_on)
6154 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6155 "Label must be first in a bundle");
6156 /* This insn must go into the first slot of a bundle. */
6160 manual_bundling_on = md.slot[curr].manual_bundling_on;
6161 manual_bundling_off = md.slot[curr].manual_bundling_off;
6163 if (manual_bundling_on)
6166 manual_bundling = 1;
6168 break; /* need to start a new bundle */
6171 if (end_of_insn_group && md.num_slots_in_use >= 1)
6173 /* We need an instruction group boundary in the middle of a
6174 bundle. See if we can switch to an other template with
6175 an appropriate boundary. */
6177 orig_template = template;
6178 if (i == 1 && (user_template == 4
6179 || (user_template < 0
6180 && (ia64_templ_desc[template].exec_unit[0]
6184 end_of_insn_group = 0;
6186 else if (i == 2 && (user_template == 0
6187 || (user_template < 0
6188 && (ia64_templ_desc[template].exec_unit[1]
6190 /* This test makes sure we don't switch the template if
6191 the next instruction is one that needs to be first in
6192 an instruction group. Since all those instructions are
6193 in the M group, there is no way such an instruction can
6194 fit in this bundle even if we switch the template. The
6195 reason we have to check for this is that otherwise we
6196 may end up generating "MI;;I M.." which has the deadly
6197 effect that the second M instruction is no longer the
6198 first in the bundle! --davidm 99/12/16 */
6199 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6202 end_of_insn_group = 0;
6204 else if (curr != first)
6205 /* can't fit this insn */
6208 if (template != orig_template)
6209 /* if we switch the template, we need to reset the NOPs
6210 after slot i. The slot-types of the instructions ahead
6211 of i never change, so we don't need to worry about
6212 changing NOPs in front of this slot. */
6213 for (j = i; j < 3; ++j)
6214 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6216 required_unit = ia64_templ_desc[template].exec_unit[i];
6218 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6219 if (idesc->type == IA64_TYPE_DYN)
6221 if ((strcmp (idesc->name, "nop") == 0)
6222 || (strcmp (idesc->name, "hint") == 0)
6223 || (strcmp (idesc->name, "break") == 0))
6224 insn_unit = required_unit;
6225 else if (strcmp (idesc->name, "chk.s") == 0)
6227 insn_unit = IA64_UNIT_M;
6228 if (required_unit == IA64_UNIT_I)
6229 insn_unit = IA64_UNIT_I;
6232 as_fatal ("emit_one_bundle: unexpected dynamic op");
6234 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6235 ia64_free_opcode (idesc);
6236 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6238 know (!idesc->next); /* no resolved dynamic ops have collisions */
6243 insn_type = idesc->type;
6244 insn_unit = IA64_UNIT_NIL;
6248 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6249 insn_unit = required_unit;
6251 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6252 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6253 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6254 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6255 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6260 if (insn_unit != required_unit)
6262 if (required_unit == IA64_UNIT_L
6263 && insn_unit == IA64_UNIT_I
6264 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6266 /* we got ourselves an MLX template but the current
6267 instruction isn't an X-unit, or an I-unit instruction
6268 that can go into the X slot of an MLX template. Duh. */
6269 if (md.num_slots_in_use >= NUM_SLOTS)
6271 as_bad_where (md.slot[curr].src_file,
6272 md.slot[curr].src_line,
6273 "`%s' can't go in X slot of "
6274 "MLX template", idesc->name);
6275 /* drop this insn so we don't livelock: */
6276 --md.num_slots_in_use;
6280 continue; /* try next slot */
6286 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6287 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6290 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6291 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6293 build_insn (md.slot + curr, insn + i);
6295 /* Set slot counts for non prologue/body unwind records. */
6296 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6297 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
6298 && ptr->r.type != body)
6300 ptr->slot_number = (unsigned long) f + i;
6301 ptr->slot_frag = frag_now;
6303 md.slot[curr].unwind_record = NULL;
6305 if (required_unit == IA64_UNIT_L)
6308 /* skip one slot for long/X-unit instructions */
6311 --md.num_slots_in_use;
6313 /* now is a good time to fix up the labels for this insn: */
6314 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6316 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6317 symbol_set_frag (lfix->sym, frag_now);
6319 /* and fix up the tags also. */
6320 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6322 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6323 symbol_set_frag (lfix->sym, frag_now);
6326 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6328 ifix = md.slot[curr].fixup + j;
6329 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6330 &ifix->expr, ifix->is_pcrel, ifix->code);
6331 fix->tc_fix_data.opnd = ifix->opnd;
6332 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6333 fix->fx_file = md.slot[curr].src_file;
6334 fix->fx_line = md.slot[curr].src_line;
6337 end_of_insn_group = md.slot[curr].end_of_insn_group;
6339 if (end_of_insn_group)
6341 md.group_idx = (md.group_idx + 1) % 3;
6342 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6346 ia64_free_opcode (md.slot[curr].idesc);
6347 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6348 md.slot[curr].user_template = -1;
6350 if (manual_bundling_off)
6352 manual_bundling = 0;
6355 curr = (curr + 1) % NUM_SLOTS;
6356 idesc = md.slot[curr].idesc;
6358 if (manual_bundling)
6360 if (md.num_slots_in_use > 0)
6361 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6362 "`%s' does not fit into %s template",
6363 idesc->name, ia64_templ_desc[template].name);
6365 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6366 "Missing '}' at end of file");
6368 know (md.num_slots_in_use < NUM_SLOTS);
6370 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6371 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6373 number_to_chars_littleendian (f + 0, t0, 8);
6374 number_to_chars_littleendian (f + 8, t1, 8);
6376 unwind.next_slot_number = (unsigned long) f + 16;
6377 unwind.next_slot_frag = frag_now;
6381 md_parse_option (c, arg)
6388 /* Switches from the Intel assembler. */
6390 if (strcmp (arg, "ilp64") == 0
6391 || strcmp (arg, "lp64") == 0
6392 || strcmp (arg, "p64") == 0)
6394 md.flags |= EF_IA_64_ABI64;
6396 else if (strcmp (arg, "ilp32") == 0)
6398 md.flags &= ~EF_IA_64_ABI64;
6400 else if (strcmp (arg, "le") == 0)
6402 md.flags &= ~EF_IA_64_BE;
6404 else if (strcmp (arg, "be") == 0)
6406 md.flags |= EF_IA_64_BE;
6413 if (strcmp (arg, "so") == 0)
6415 /* Suppress signon message. */
6417 else if (strcmp (arg, "pi") == 0)
6419 /* Reject privileged instructions. FIXME */
6421 else if (strcmp (arg, "us") == 0)
6423 /* Allow union of signed and unsigned range. FIXME */
6425 else if (strcmp (arg, "close_fcalls") == 0)
6427 /* Do not resolve global function calls. */
6434 /* temp[="prefix"] Insert temporary labels into the object file
6435 symbol table prefixed by "prefix".
6436 Default prefix is ":temp:".
6441 /* indirect=<tgt> Assume unannotated indirect branches behavior
6442 according to <tgt> --
6443 exit: branch out from the current context (default)
6444 labels: all labels in context may be branch targets
6446 if (strncmp (arg, "indirect=", 9) != 0)
6451 /* -X conflicts with an ignored option, use -x instead */
6453 if (!arg || strcmp (arg, "explicit") == 0)
6455 /* set default mode to explicit */
6456 md.default_explicit_mode = 1;
6459 else if (strcmp (arg, "auto") == 0)
6461 md.default_explicit_mode = 0;
6463 else if (strcmp (arg, "debug") == 0)
6467 else if (strcmp (arg, "debugx") == 0)
6469 md.default_explicit_mode = 1;
6474 as_bad (_("Unrecognized option '-x%s'"), arg);
6479 /* nops Print nops statistics. */
6482 /* GNU specific switches for gcc. */
6483 case OPTION_MCONSTANT_GP:
6484 md.flags |= EF_IA_64_CONS_GP;
6487 case OPTION_MAUTO_PIC:
6488 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6499 md_show_usage (stream)
6504 --mconstant-gp mark output file as using the constant-GP model\n\
6505 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6506 --mauto-pic mark output file as using the constant-GP model\n\
6507 without function descriptors (sets ELF header flag\n\
6508 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6509 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6510 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6511 -x | -xexplicit turn on dependency violation checking (default)\n\
6512 -xauto automagically remove dependency violations\n\
6513 -xdebug debug dependency violation checker\n"),
6518 ia64_after_parse_args ()
6520 if (debug_type == DEBUG_STABS)
6521 as_fatal (_("--gstabs is not supported for ia64"));
6524 /* Return true if TYPE fits in TEMPL at SLOT. */
6527 match (int templ, int type, int slot)
6529 enum ia64_unit unit;
6532 unit = ia64_templ_desc[templ].exec_unit[slot];
6535 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6537 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6539 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6540 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6541 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6542 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6543 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6544 default: result = 0; break;
6549 /* Add a bit of extra goodness if a nop of type F or B would fit
6550 in TEMPL at SLOT. */
6553 extra_goodness (int templ, int slot)
6555 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6557 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6562 /* This function is called once, at assembler startup time. It sets
6563 up all the tables, etc. that the MD part of the assembler will need
6564 that can be determined before arguments are parsed. */
6568 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6573 md.explicit_mode = md.default_explicit_mode;
6575 bfd_set_section_alignment (stdoutput, text_section, 4);
6577 /* Make sure fucntion pointers get initialized. */
6578 target_big_endian = -1;
6579 dot_byteorder (TARGET_BYTES_BIG_ENDIAN);
6581 alias_hash = hash_new ();
6582 alias_name_hash = hash_new ();
6583 secalias_hash = hash_new ();
6584 secalias_name_hash = hash_new ();
6586 pseudo_func[FUNC_DTP_MODULE].u.sym =
6587 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6588 &zero_address_frag);
6590 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6591 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6592 &zero_address_frag);
6594 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6595 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6596 &zero_address_frag);
6598 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6599 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6600 &zero_address_frag);
6602 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6603 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6604 &zero_address_frag);
6606 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6607 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6608 &zero_address_frag);
6610 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6611 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6612 &zero_address_frag);
6614 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6615 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6616 &zero_address_frag);
6618 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6619 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6620 &zero_address_frag);
6622 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6623 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6624 &zero_address_frag);
6626 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6627 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6628 &zero_address_frag);
6630 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6631 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6632 &zero_address_frag);
6634 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6635 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6636 &zero_address_frag);
6638 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6639 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6640 &zero_address_frag);
6642 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6643 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6644 &zero_address_frag);
6646 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6647 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6648 &zero_address_frag);
6650 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6651 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6652 &zero_address_frag);
6654 /* Compute the table of best templates. We compute goodness as a
6655 base 4 value, in which each match counts for 3, each F counts
6656 for 2, each B counts for 1. This should maximize the number of
6657 F and B nops in the chosen bundles, which is good because these
6658 pipelines are least likely to be overcommitted. */
6659 for (i = 0; i < IA64_NUM_TYPES; ++i)
6660 for (j = 0; j < IA64_NUM_TYPES; ++j)
6661 for (k = 0; k < IA64_NUM_TYPES; ++k)
6664 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6667 if (match (t, i, 0))
6669 if (match (t, j, 1))
6671 if (match (t, k, 2))
6672 goodness = 3 + 3 + 3;
6674 goodness = 3 + 3 + extra_goodness (t, 2);
6676 else if (match (t, j, 2))
6677 goodness = 3 + 3 + extra_goodness (t, 1);
6681 goodness += extra_goodness (t, 1);
6682 goodness += extra_goodness (t, 2);
6685 else if (match (t, i, 1))
6687 if (match (t, j, 2))
6690 goodness = 3 + extra_goodness (t, 2);
6692 else if (match (t, i, 2))
6693 goodness = 3 + extra_goodness (t, 1);
6695 if (goodness > best)
6698 best_template[i][j][k] = t;
6703 for (i = 0; i < NUM_SLOTS; ++i)
6704 md.slot[i].user_template = -1;
6706 md.pseudo_hash = hash_new ();
6707 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6709 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6710 (void *) (pseudo_opcode + i));
6712 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6713 pseudo_opcode[i].name, err);
6716 md.reg_hash = hash_new ();
6717 md.dynreg_hash = hash_new ();
6718 md.const_hash = hash_new ();
6719 md.entry_hash = hash_new ();
6721 /* general registers: */
6724 for (i = 0; i < total; ++i)
6726 sprintf (name, "r%d", i - REG_GR);
6727 md.regsym[i] = declare_register (name, i);
6730 /* floating point registers: */
6732 for (; i < total; ++i)
6734 sprintf (name, "f%d", i - REG_FR);
6735 md.regsym[i] = declare_register (name, i);
6738 /* application registers: */
6741 for (; i < total; ++i)
6743 sprintf (name, "ar%d", i - REG_AR);
6744 md.regsym[i] = declare_register (name, i);
6747 /* control registers: */
6750 for (; i < total; ++i)
6752 sprintf (name, "cr%d", i - REG_CR);
6753 md.regsym[i] = declare_register (name, i);
6756 /* predicate registers: */
6758 for (; i < total; ++i)
6760 sprintf (name, "p%d", i - REG_P);
6761 md.regsym[i] = declare_register (name, i);
6764 /* branch registers: */
6766 for (; i < total; ++i)
6768 sprintf (name, "b%d", i - REG_BR);
6769 md.regsym[i] = declare_register (name, i);
6772 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6773 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6774 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6775 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6776 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6777 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6778 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6780 for (i = 0; i < NELEMS (indirect_reg); ++i)
6782 regnum = indirect_reg[i].regnum;
6783 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6786 /* define synonyms for application registers: */
6787 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6788 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6789 REG_AR + ar[i - REG_AR].regnum);
6791 /* define synonyms for control registers: */
6792 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6793 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6794 REG_CR + cr[i - REG_CR].regnum);
6796 declare_register ("gp", REG_GR + 1);
6797 declare_register ("sp", REG_GR + 12);
6798 declare_register ("rp", REG_BR + 0);
6800 /* pseudo-registers used to specify unwind info: */
6801 declare_register ("psp", REG_PSP);
6803 declare_register_set ("ret", 4, REG_GR + 8);
6804 declare_register_set ("farg", 8, REG_FR + 8);
6805 declare_register_set ("fret", 8, REG_FR + 8);
6807 for (i = 0; i < NELEMS (const_bits); ++i)
6809 err = hash_insert (md.const_hash, const_bits[i].name,
6810 (PTR) (const_bits + i));
6812 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6816 /* Set the architecture and machine depending on defaults and command line
6818 if (md.flags & EF_IA_64_ABI64)
6819 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6821 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6824 as_warn (_("Could not set architecture and machine"));
6826 /* Set the pointer size and pointer shift size depending on md.flags */
6828 if (md.flags & EF_IA_64_ABI64)
6830 md.pointer_size = 8; /* pointers are 8 bytes */
6831 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6835 md.pointer_size = 4; /* pointers are 4 bytes */
6836 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6839 md.mem_offset.hint = 0;
6842 md.entry_labels = NULL;
6845 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6846 because that is called after md_parse_option which is where we do the
6847 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6848 default endianness. */
6851 ia64_init (argc, argv)
6852 int argc ATTRIBUTE_UNUSED;
6853 char **argv ATTRIBUTE_UNUSED;
6855 md.flags = MD_FLAGS_DEFAULT;
6858 /* Return a string for the target object file format. */
6861 ia64_target_format ()
6863 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6865 if (md.flags & EF_IA_64_BE)
6867 if (md.flags & EF_IA_64_ABI64)
6868 #if defined(TE_AIX50)
6869 return "elf64-ia64-aix-big";
6870 #elif defined(TE_HPUX)
6871 return "elf64-ia64-hpux-big";
6873 return "elf64-ia64-big";
6876 #if defined(TE_AIX50)
6877 return "elf32-ia64-aix-big";
6878 #elif defined(TE_HPUX)
6879 return "elf32-ia64-hpux-big";
6881 return "elf32-ia64-big";
6886 if (md.flags & EF_IA_64_ABI64)
6888 return "elf64-ia64-aix-little";
6890 return "elf64-ia64-little";
6894 return "elf32-ia64-aix-little";
6896 return "elf32-ia64-little";
6901 return "unknown-format";
6905 ia64_end_of_source ()
6907 /* terminate insn group upon reaching end of file: */
6908 insn_group_break (1, 0, 0);
6910 /* emits slots we haven't written yet: */
6911 ia64_flush_insns ();
6913 bfd_set_private_flags (stdoutput, md.flags);
6915 md.mem_offset.hint = 0;
6921 if (md.qp.X_op == O_register)
6922 as_bad ("qualifying predicate not followed by instruction");
6923 md.qp.X_op = O_absent;
6925 if (ignore_input ())
6928 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6930 if (md.detect_dv && !md.explicit_mode)
6931 as_warn (_("Explicit stops are ignored in auto mode"));
6933 insn_group_break (1, 0, 0);
6937 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
6939 static int defining_tag = 0;
6942 ia64_unrecognized_line (ch)
6948 expression (&md.qp);
6949 if (*input_line_pointer++ != ')')
6951 as_bad ("Expected ')'");
6954 if (md.qp.X_op != O_register)
6956 as_bad ("Qualifying predicate expected");
6959 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
6961 as_bad ("Predicate register expected");
6967 if (md.manual_bundling)
6968 as_warn ("Found '{' when manual bundling is already turned on");
6970 CURR_SLOT.manual_bundling_on = 1;
6971 md.manual_bundling = 1;
6973 /* Bundling is only acceptable in explicit mode
6974 or when in default automatic mode. */
6975 if (md.detect_dv && !md.explicit_mode)
6977 if (!md.mode_explicitly_set
6978 && !md.default_explicit_mode)
6981 as_warn (_("Found '{' after explicit switch to automatic mode"));
6986 if (!md.manual_bundling)
6987 as_warn ("Found '}' when manual bundling is off");
6989 PREV_SLOT.manual_bundling_off = 1;
6990 md.manual_bundling = 0;
6992 /* switch back to automatic mode, if applicable */
6995 && !md.mode_explicitly_set
6996 && !md.default_explicit_mode)
6999 /* Allow '{' to follow on the same line. We also allow ";;", but that
7000 happens automatically because ';' is an end of line marker. */
7002 if (input_line_pointer[0] == '{')
7004 input_line_pointer++;
7005 return ia64_unrecognized_line ('{');
7008 demand_empty_rest_of_line ();
7018 if (md.qp.X_op == O_register)
7020 as_bad ("Tag must come before qualifying predicate.");
7024 /* This implements just enough of read_a_source_file in read.c to
7025 recognize labels. */
7026 if (is_name_beginner (*input_line_pointer))
7028 s = input_line_pointer;
7029 c = get_symbol_end ();
7031 else if (LOCAL_LABELS_FB
7032 && ISDIGIT (*input_line_pointer))
7035 while (ISDIGIT (*input_line_pointer))
7036 temp = (temp * 10) + *input_line_pointer++ - '0';
7037 fb_label_instance_inc (temp);
7038 s = fb_label_name (temp, 0);
7039 c = *input_line_pointer;
7048 /* Put ':' back for error messages' sake. */
7049 *input_line_pointer++ = ':';
7050 as_bad ("Expected ':'");
7057 /* Put ':' back for error messages' sake. */
7058 *input_line_pointer++ = ':';
7059 if (*input_line_pointer++ != ']')
7061 as_bad ("Expected ']'");
7066 as_bad ("Tag name expected");
7076 /* Not a valid line. */
7081 ia64_frob_label (sym)
7084 struct label_fix *fix;
7086 /* Tags need special handling since they are not bundle breaks like
7090 fix = obstack_alloc (¬es, sizeof (*fix));
7092 fix->next = CURR_SLOT.tag_fixups;
7093 CURR_SLOT.tag_fixups = fix;
7098 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7100 md.last_text_seg = now_seg;
7101 fix = obstack_alloc (¬es, sizeof (*fix));
7103 fix->next = CURR_SLOT.label_fixups;
7104 CURR_SLOT.label_fixups = fix;
7106 /* Keep track of how many code entry points we've seen. */
7107 if (md.path == md.maxpaths)
7110 md.entry_labels = (const char **)
7111 xrealloc ((void *) md.entry_labels,
7112 md.maxpaths * sizeof (char *));
7114 md.entry_labels[md.path++] = S_GET_NAME (sym);
7119 ia64_flush_pending_output ()
7121 if (!md.keep_pending_output
7122 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7124 /* ??? This causes many unnecessary stop bits to be emitted.
7125 Unfortunately, it isn't clear if it is safe to remove this. */
7126 insn_group_break (1, 0, 0);
7127 ia64_flush_insns ();
7131 /* Do ia64-specific expression optimization. All that's done here is
7132 to transform index expressions that are either due to the indexing
7133 of rotating registers or due to the indexing of indirect register
7136 ia64_optimize_expr (l, op, r)
7145 if (l->X_op == O_register && r->X_op == O_constant)
7147 num_regs = (l->X_add_number >> 16);
7148 if ((unsigned) r->X_add_number >= num_regs)
7151 as_bad ("No current frame");
7153 as_bad ("Index out of range 0..%u", num_regs - 1);
7154 r->X_add_number = 0;
7156 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7159 else if (l->X_op == O_register && r->X_op == O_register)
7161 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7162 || l->X_add_number == IND_MEM)
7164 as_bad ("Indirect register set name expected");
7165 l->X_add_number = IND_CPUID;
7168 l->X_op_symbol = md.regsym[l->X_add_number];
7169 l->X_add_number = r->X_add_number;
7177 ia64_parse_name (name, e)
7181 struct const_desc *cdesc;
7182 struct dynreg *dr = 0;
7183 unsigned int regnum;
7187 /* first see if NAME is a known register name: */
7188 sym = hash_find (md.reg_hash, name);
7191 e->X_op = O_register;
7192 e->X_add_number = S_GET_VALUE (sym);
7196 cdesc = hash_find (md.const_hash, name);
7199 e->X_op = O_constant;
7200 e->X_add_number = cdesc->value;
7204 /* check for inN, locN, or outN: */
7208 if (name[1] == 'n' && ISDIGIT (name[2]))
7216 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7224 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7237 /* The name is inN, locN, or outN; parse the register number. */
7238 regnum = strtoul (name, &end, 10);
7239 if (end > name && *end == '\0')
7241 if ((unsigned) regnum >= dr->num_regs)
7244 as_bad ("No current frame");
7246 as_bad ("Register number out of range 0..%u",
7250 e->X_op = O_register;
7251 e->X_add_number = dr->base + regnum;
7256 if ((dr = hash_find (md.dynreg_hash, name)))
7258 /* We've got ourselves the name of a rotating register set.
7259 Store the base register number in the low 16 bits of
7260 X_add_number and the size of the register set in the top 16
7262 e->X_op = O_register;
7263 e->X_add_number = dr->base | (dr->num_regs << 16);
7269 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7272 ia64_canonicalize_symbol_name (name)
7275 size_t len = strlen (name);
7276 if (len > 1 && name[len - 1] == '#')
7277 name[len - 1] = '\0';
7281 /* Return true if idesc is a conditional branch instruction. This excludes
7282 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7283 because they always read/write resources regardless of the value of the
7284 qualifying predicate. br.ia must always use p0, and hence is always
7285 taken. Thus this function returns true for branches which can fall
7286 through, and which use no resources if they do fall through. */
7289 is_conditional_branch (idesc)
7290 struct ia64_opcode *idesc;
7292 /* br is a conditional branch. Everything that starts with br. except
7293 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7294 Everything that starts with brl is a conditional branch. */
7295 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7296 && (idesc->name[2] == '\0'
7297 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7298 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7299 || idesc->name[2] == 'l'
7300 /* br.cond, br.call, br.clr */
7301 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7302 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7303 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7306 /* Return whether the given opcode is a taken branch. If there's any doubt,
7310 is_taken_branch (idesc)
7311 struct ia64_opcode *idesc;
7313 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7314 || strncmp (idesc->name, "br.ia", 5) == 0);
7317 /* Return whether the given opcode is an interruption or rfi. If there's any
7318 doubt, returns zero. */
7321 is_interruption_or_rfi (idesc)
7322 struct ia64_opcode *idesc;
7324 if (strcmp (idesc->name, "rfi") == 0)
7329 /* Returns the index of the given dependency in the opcode's list of chks, or
7330 -1 if there is no dependency. */
7333 depends_on (depind, idesc)
7335 struct ia64_opcode *idesc;
7338 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7339 for (i = 0; i < dep->nchks; i++)
7341 if (depind == DEP (dep->chks[i]))
7347 /* Determine a set of specific resources used for a particular resource
7348 class. Returns the number of specific resources identified For those
7349 cases which are not determinable statically, the resource returned is
7352 Meanings of value in 'NOTE':
7353 1) only read/write when the register number is explicitly encoded in the
7355 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7356 accesses CFM when qualifying predicate is in the rotating region.
7357 3) general register value is used to specify an indirect register; not
7358 determinable statically.
7359 4) only read the given resource when bits 7:0 of the indirect index
7360 register value does not match the register number of the resource; not
7361 determinable statically.
7362 5) all rules are implementation specific.
7363 6) only when both the index specified by the reader and the index specified
7364 by the writer have the same value in bits 63:61; not determinable
7366 7) only access the specified resource when the corresponding mask bit is
7368 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7369 only read when these insns reference FR2-31
7370 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7371 written when these insns write FR32-127
7372 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7374 11) The target predicates are written independently of PR[qp], but source
7375 registers are only read if PR[qp] is true. Since the state of PR[qp]
7376 cannot statically be determined, all source registers are marked used.
7377 12) This insn only reads the specified predicate register when that
7378 register is the PR[qp].
7379 13) This reference to ld-c only applies to teh GR whose value is loaded
7380 with data returned from memory, not the post-incremented address register.
7381 14) The RSE resource includes the implementation-specific RSE internal
7382 state resources. At least one (and possibly more) of these resources are
7383 read by each instruction listed in IC:rse-readers. At least one (and
7384 possibly more) of these resources are written by each insn listed in
7386 15+16) Represents reserved instructions, which the assembler does not
7389 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7390 this code; there are no dependency violations based on memory access.
7393 #define MAX_SPECS 256
7398 specify_resource (dep, idesc, type, specs, note, path)
7399 const struct ia64_dependency *dep;
7400 struct ia64_opcode *idesc;
7401 int type; /* is this a DV chk or a DV reg? */
7402 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7403 int note; /* resource note for this insn's usage */
7404 int path; /* which execution path to examine */
7411 if (dep->mode == IA64_DV_WAW
7412 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7413 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7416 /* template for any resources we identify */
7417 tmpl.dependency = dep;
7419 tmpl.insn_srlz = tmpl.data_srlz = 0;
7420 tmpl.qp_regno = CURR_SLOT.qp_regno;
7421 tmpl.link_to_qp_branch = 1;
7422 tmpl.mem_offset.hint = 0;
7425 tmpl.cmp_type = CMP_NONE;
7428 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7429 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7430 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7432 /* we don't need to track these */
7433 if (dep->semantics == IA64_DVS_NONE)
7436 switch (dep->specifier)
7441 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7443 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7444 if (regno >= 0 && regno <= 7)
7446 specs[count] = tmpl;
7447 specs[count++].index = regno;
7453 for (i = 0; i < 8; i++)
7455 specs[count] = tmpl;
7456 specs[count++].index = i;
7465 case IA64_RS_AR_UNAT:
7466 /* This is a mov =AR or mov AR= instruction. */
7467 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7469 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7470 if (regno == AR_UNAT)
7472 specs[count++] = tmpl;
7477 /* This is a spill/fill, or other instruction that modifies the
7480 /* Unless we can determine the specific bits used, mark the whole
7481 thing; bits 8:3 of the memory address indicate the bit used in
7482 UNAT. The .mem.offset hint may be used to eliminate a small
7483 subset of conflicts. */
7484 specs[count] = tmpl;
7485 if (md.mem_offset.hint)
7488 fprintf (stderr, " Using hint for spill/fill\n");
7489 /* The index isn't actually used, just set it to something
7490 approximating the bit index. */
7491 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7492 specs[count].mem_offset.hint = 1;
7493 specs[count].mem_offset.offset = md.mem_offset.offset;
7494 specs[count++].mem_offset.base = md.mem_offset.base;
7498 specs[count++].specific = 0;
7506 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7508 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7509 if ((regno >= 8 && regno <= 15)
7510 || (regno >= 20 && regno <= 23)
7511 || (regno >= 31 && regno <= 39)
7512 || (regno >= 41 && regno <= 47)
7513 || (regno >= 67 && regno <= 111))
7515 specs[count] = tmpl;
7516 specs[count++].index = regno;
7529 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7531 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7532 if ((regno >= 48 && regno <= 63)
7533 || (regno >= 112 && regno <= 127))
7535 specs[count] = tmpl;
7536 specs[count++].index = regno;
7542 for (i = 48; i < 64; i++)
7544 specs[count] = tmpl;
7545 specs[count++].index = i;
7547 for (i = 112; i < 128; i++)
7549 specs[count] = tmpl;
7550 specs[count++].index = i;
7568 for (i = 0; i < idesc->num_outputs; i++)
7569 if (idesc->operands[i] == IA64_OPND_B1
7570 || idesc->operands[i] == IA64_OPND_B2)
7572 specs[count] = tmpl;
7573 specs[count++].index =
7574 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7579 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7580 if (idesc->operands[i] == IA64_OPND_B1
7581 || idesc->operands[i] == IA64_OPND_B2)
7583 specs[count] = tmpl;
7584 specs[count++].index =
7585 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7591 case IA64_RS_CPUID: /* four or more registers */
7594 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7596 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7597 if (regno >= 0 && regno < NELEMS (gr_values)
7600 specs[count] = tmpl;
7601 specs[count++].index = gr_values[regno].value & 0xFF;
7605 specs[count] = tmpl;
7606 specs[count++].specific = 0;
7616 case IA64_RS_DBR: /* four or more registers */
7619 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7621 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7622 if (regno >= 0 && regno < NELEMS (gr_values)
7625 specs[count] = tmpl;
7626 specs[count++].index = gr_values[regno].value & 0xFF;
7630 specs[count] = tmpl;
7631 specs[count++].specific = 0;
7635 else if (note == 0 && !rsrc_write)
7637 specs[count] = tmpl;
7638 specs[count++].specific = 0;
7646 case IA64_RS_IBR: /* four or more registers */
7649 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7651 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7652 if (regno >= 0 && regno < NELEMS (gr_values)
7655 specs[count] = tmpl;
7656 specs[count++].index = gr_values[regno].value & 0xFF;
7660 specs[count] = tmpl;
7661 specs[count++].specific = 0;
7674 /* These are implementation specific. Force all references to
7675 conflict with all other references. */
7676 specs[count] = tmpl;
7677 specs[count++].specific = 0;
7685 case IA64_RS_PKR: /* 16 or more registers */
7686 if (note == 3 || note == 4)
7688 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7690 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7691 if (regno >= 0 && regno < NELEMS (gr_values)
7696 specs[count] = tmpl;
7697 specs[count++].index = gr_values[regno].value & 0xFF;
7700 for (i = 0; i < NELEMS (gr_values); i++)
7702 /* Uses all registers *except* the one in R3. */
7703 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7705 specs[count] = tmpl;
7706 specs[count++].index = i;
7712 specs[count] = tmpl;
7713 specs[count++].specific = 0;
7720 specs[count] = tmpl;
7721 specs[count++].specific = 0;
7725 case IA64_RS_PMC: /* four or more registers */
7728 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7729 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7732 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7734 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7735 if (regno >= 0 && regno < NELEMS (gr_values)
7738 specs[count] = tmpl;
7739 specs[count++].index = gr_values[regno].value & 0xFF;
7743 specs[count] = tmpl;
7744 specs[count++].specific = 0;
7754 case IA64_RS_PMD: /* four or more registers */
7757 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7759 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7760 if (regno >= 0 && regno < NELEMS (gr_values)
7763 specs[count] = tmpl;
7764 specs[count++].index = gr_values[regno].value & 0xFF;
7768 specs[count] = tmpl;
7769 specs[count++].specific = 0;
7779 case IA64_RS_RR: /* eight registers */
7782 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7784 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7785 if (regno >= 0 && regno < NELEMS (gr_values)
7788 specs[count] = tmpl;
7789 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7793 specs[count] = tmpl;
7794 specs[count++].specific = 0;
7798 else if (note == 0 && !rsrc_write)
7800 specs[count] = tmpl;
7801 specs[count++].specific = 0;
7809 case IA64_RS_CR_IRR:
7812 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7813 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7815 && idesc->operands[1] == IA64_OPND_CR3
7818 for (i = 0; i < 4; i++)
7820 specs[count] = tmpl;
7821 specs[count++].index = CR_IRR0 + i;
7827 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7828 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7830 && regno <= CR_IRR3)
7832 specs[count] = tmpl;
7833 specs[count++].index = regno;
7842 case IA64_RS_CR_LRR:
7849 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7850 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7851 && (regno == CR_LRR0 || regno == CR_LRR1))
7853 specs[count] = tmpl;
7854 specs[count++].index = regno;
7862 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7864 specs[count] = tmpl;
7865 specs[count++].index =
7866 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7881 else if (rsrc_write)
7883 if (dep->specifier == IA64_RS_FRb
7884 && idesc->operands[0] == IA64_OPND_F1)
7886 specs[count] = tmpl;
7887 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7892 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7894 if (idesc->operands[i] == IA64_OPND_F2
7895 || idesc->operands[i] == IA64_OPND_F3
7896 || idesc->operands[i] == IA64_OPND_F4)
7898 specs[count] = tmpl;
7899 specs[count++].index =
7900 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7909 /* This reference applies only to the GR whose value is loaded with
7910 data returned from memory. */
7911 specs[count] = tmpl;
7912 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7918 for (i = 0; i < idesc->num_outputs; i++)
7919 if (idesc->operands[i] == IA64_OPND_R1
7920 || idesc->operands[i] == IA64_OPND_R2
7921 || idesc->operands[i] == IA64_OPND_R3)
7923 specs[count] = tmpl;
7924 specs[count++].index =
7925 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7927 if (idesc->flags & IA64_OPCODE_POSTINC)
7928 for (i = 0; i < NELEMS (idesc->operands); i++)
7929 if (idesc->operands[i] == IA64_OPND_MR3)
7931 specs[count] = tmpl;
7932 specs[count++].index =
7933 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7938 /* Look for anything that reads a GR. */
7939 for (i = 0; i < NELEMS (idesc->operands); i++)
7941 if (idesc->operands[i] == IA64_OPND_MR3
7942 || idesc->operands[i] == IA64_OPND_CPUID_R3
7943 || idesc->operands[i] == IA64_OPND_DBR_R3
7944 || idesc->operands[i] == IA64_OPND_IBR_R3
7945 || idesc->operands[i] == IA64_OPND_MSR_R3
7946 || idesc->operands[i] == IA64_OPND_PKR_R3
7947 || idesc->operands[i] == IA64_OPND_PMC_R3
7948 || idesc->operands[i] == IA64_OPND_PMD_R3
7949 || idesc->operands[i] == IA64_OPND_RR_R3
7950 || ((i >= idesc->num_outputs)
7951 && (idesc->operands[i] == IA64_OPND_R1
7952 || idesc->operands[i] == IA64_OPND_R2
7953 || idesc->operands[i] == IA64_OPND_R3
7954 /* addl source register. */
7955 || idesc->operands[i] == IA64_OPND_R3_2)))
7957 specs[count] = tmpl;
7958 specs[count++].index =
7959 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7970 /* This is the same as IA64_RS_PRr, except that the register range is
7971 from 1 - 15, and there are no rotating register reads/writes here. */
7975 for (i = 1; i < 16; i++)
7977 specs[count] = tmpl;
7978 specs[count++].index = i;
7984 /* Mark only those registers indicated by the mask. */
7987 mask = CURR_SLOT.opnd[2].X_add_number;
7988 for (i = 1; i < 16; i++)
7989 if (mask & ((valueT) 1 << i))
7991 specs[count] = tmpl;
7992 specs[count++].index = i;
8000 else if (note == 11) /* note 11 implies note 1 as well */
8004 for (i = 0; i < idesc->num_outputs; i++)
8006 if (idesc->operands[i] == IA64_OPND_P1
8007 || idesc->operands[i] == IA64_OPND_P2)
8009 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8010 if (regno >= 1 && regno < 16)
8012 specs[count] = tmpl;
8013 specs[count++].index = regno;
8023 else if (note == 12)
8025 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8027 specs[count] = tmpl;
8028 specs[count++].index = CURR_SLOT.qp_regno;
8035 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8036 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8037 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8038 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8040 if ((idesc->operands[0] == IA64_OPND_P1
8041 || idesc->operands[0] == IA64_OPND_P2)
8042 && p1 >= 1 && p1 < 16)
8044 specs[count] = tmpl;
8045 specs[count].cmp_type =
8046 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8047 specs[count++].index = p1;
8049 if ((idesc->operands[1] == IA64_OPND_P1
8050 || idesc->operands[1] == IA64_OPND_P2)
8051 && p2 >= 1 && p2 < 16)
8053 specs[count] = tmpl;
8054 specs[count].cmp_type =
8055 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8056 specs[count++].index = p2;
8061 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8063 specs[count] = tmpl;
8064 specs[count++].index = CURR_SLOT.qp_regno;
8066 if (idesc->operands[1] == IA64_OPND_PR)
8068 for (i = 1; i < 16; i++)
8070 specs[count] = tmpl;
8071 specs[count++].index = i;
8082 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8083 simplified cases of this. */
8087 for (i = 16; i < 63; i++)
8089 specs[count] = tmpl;
8090 specs[count++].index = i;
8096 /* Mark only those registers indicated by the mask. */
8098 && idesc->operands[0] == IA64_OPND_PR)
8100 mask = CURR_SLOT.opnd[2].X_add_number;
8101 if (mask & ((valueT) 1 << 16))
8102 for (i = 16; i < 63; i++)
8104 specs[count] = tmpl;
8105 specs[count++].index = i;
8109 && idesc->operands[0] == IA64_OPND_PR_ROT)
8111 for (i = 16; i < 63; i++)
8113 specs[count] = tmpl;
8114 specs[count++].index = i;
8122 else if (note == 11) /* note 11 implies note 1 as well */
8126 for (i = 0; i < idesc->num_outputs; i++)
8128 if (idesc->operands[i] == IA64_OPND_P1
8129 || idesc->operands[i] == IA64_OPND_P2)
8131 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8132 if (regno >= 16 && regno < 63)
8134 specs[count] = tmpl;
8135 specs[count++].index = regno;
8145 else if (note == 12)
8147 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8149 specs[count] = tmpl;
8150 specs[count++].index = CURR_SLOT.qp_regno;
8157 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8158 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8159 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8160 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8162 if ((idesc->operands[0] == IA64_OPND_P1
8163 || idesc->operands[0] == IA64_OPND_P2)
8164 && p1 >= 16 && p1 < 63)
8166 specs[count] = tmpl;
8167 specs[count].cmp_type =
8168 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8169 specs[count++].index = p1;
8171 if ((idesc->operands[1] == IA64_OPND_P1
8172 || idesc->operands[1] == IA64_OPND_P2)
8173 && p2 >= 16 && p2 < 63)
8175 specs[count] = tmpl;
8176 specs[count].cmp_type =
8177 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8178 specs[count++].index = p2;
8183 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8185 specs[count] = tmpl;
8186 specs[count++].index = CURR_SLOT.qp_regno;
8188 if (idesc->operands[1] == IA64_OPND_PR)
8190 for (i = 16; i < 63; i++)
8192 specs[count] = tmpl;
8193 specs[count++].index = i;
8205 /* Verify that the instruction is using the PSR bit indicated in
8209 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8211 if (dep->regindex < 6)
8213 specs[count++] = tmpl;
8216 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8218 if (dep->regindex < 32
8219 || dep->regindex == 35
8220 || dep->regindex == 36
8221 || (!rsrc_write && dep->regindex == PSR_CPL))
8223 specs[count++] = tmpl;
8226 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8228 if (dep->regindex < 32
8229 || dep->regindex == 35
8230 || dep->regindex == 36
8231 || (rsrc_write && dep->regindex == PSR_CPL))
8233 specs[count++] = tmpl;
8238 /* Several PSR bits have very specific dependencies. */
8239 switch (dep->regindex)
8242 specs[count++] = tmpl;
8247 specs[count++] = tmpl;
8251 /* Only certain CR accesses use PSR.ic */
8252 if (idesc->operands[0] == IA64_OPND_CR3
8253 || idesc->operands[1] == IA64_OPND_CR3)
8256 ((idesc->operands[0] == IA64_OPND_CR3)
8259 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8274 specs[count++] = tmpl;
8283 specs[count++] = tmpl;
8287 /* Only some AR accesses use cpl */
8288 if (idesc->operands[0] == IA64_OPND_AR3
8289 || idesc->operands[1] == IA64_OPND_AR3)
8292 ((idesc->operands[0] == IA64_OPND_AR3)
8295 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8302 && regno <= AR_K7))))
8304 specs[count++] = tmpl;
8309 specs[count++] = tmpl;
8319 if (idesc->operands[0] == IA64_OPND_IMMU24)
8321 mask = CURR_SLOT.opnd[0].X_add_number;
8327 if (mask & ((valueT) 1 << dep->regindex))
8329 specs[count++] = tmpl;
8334 int min = dep->regindex == PSR_DFL ? 2 : 32;
8335 int max = dep->regindex == PSR_DFL ? 31 : 127;
8336 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8337 for (i = 0; i < NELEMS (idesc->operands); i++)
8339 if (idesc->operands[i] == IA64_OPND_F1
8340 || idesc->operands[i] == IA64_OPND_F2
8341 || idesc->operands[i] == IA64_OPND_F3
8342 || idesc->operands[i] == IA64_OPND_F4)
8344 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8345 if (reg >= min && reg <= max)
8347 specs[count++] = tmpl;
8354 int min = dep->regindex == PSR_MFL ? 2 : 32;
8355 int max = dep->regindex == PSR_MFL ? 31 : 127;
8356 /* mfh is read on writes to FR32-127; mfl is read on writes to
8358 for (i = 0; i < idesc->num_outputs; i++)
8360 if (idesc->operands[i] == IA64_OPND_F1)
8362 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8363 if (reg >= min && reg <= max)
8365 specs[count++] = tmpl;
8370 else if (note == 10)
8372 for (i = 0; i < NELEMS (idesc->operands); i++)
8374 if (idesc->operands[i] == IA64_OPND_R1
8375 || idesc->operands[i] == IA64_OPND_R2
8376 || idesc->operands[i] == IA64_OPND_R3)
8378 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8379 if (regno >= 16 && regno <= 31)
8381 specs[count++] = tmpl;
8392 case IA64_RS_AR_FPSR:
8393 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8395 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8396 if (regno == AR_FPSR)
8398 specs[count++] = tmpl;
8403 specs[count++] = tmpl;
8408 /* Handle all AR[REG] resources */
8409 if (note == 0 || note == 1)
8411 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8412 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8413 && regno == dep->regindex)
8415 specs[count++] = tmpl;
8417 /* other AR[REG] resources may be affected by AR accesses */
8418 else if (idesc->operands[0] == IA64_OPND_AR3)
8421 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8422 switch (dep->regindex)
8428 if (regno == AR_BSPSTORE)
8430 specs[count++] = tmpl;
8434 (regno == AR_BSPSTORE
8435 || regno == AR_RNAT))
8437 specs[count++] = tmpl;
8442 else if (idesc->operands[1] == IA64_OPND_AR3)
8445 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8446 switch (dep->regindex)
8451 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8453 specs[count++] = tmpl;
8460 specs[count++] = tmpl;
8470 /* Handle all CR[REG] resources */
8471 if (note == 0 || note == 1)
8473 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8475 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8476 if (regno == dep->regindex)
8478 specs[count++] = tmpl;
8480 else if (!rsrc_write)
8482 /* Reads from CR[IVR] affect other resources. */
8483 if (regno == CR_IVR)
8485 if ((dep->regindex >= CR_IRR0
8486 && dep->regindex <= CR_IRR3)
8487 || dep->regindex == CR_TPR)
8489 specs[count++] = tmpl;
8496 specs[count++] = tmpl;
8505 case IA64_RS_INSERVICE:
8506 /* look for write of EOI (67) or read of IVR (65) */
8507 if ((idesc->operands[0] == IA64_OPND_CR3
8508 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8509 || (idesc->operands[1] == IA64_OPND_CR3
8510 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8512 specs[count++] = tmpl;
8519 specs[count++] = tmpl;
8530 specs[count++] = tmpl;
8534 /* Check if any of the registers accessed are in the rotating region.
8535 mov to/from pr accesses CFM only when qp_regno is in the rotating
8537 for (i = 0; i < NELEMS (idesc->operands); i++)
8539 if (idesc->operands[i] == IA64_OPND_R1
8540 || idesc->operands[i] == IA64_OPND_R2
8541 || idesc->operands[i] == IA64_OPND_R3)
8543 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8544 /* Assumes that md.rot.num_regs is always valid */
8545 if (md.rot.num_regs > 0
8547 && num < 31 + md.rot.num_regs)
8549 specs[count] = tmpl;
8550 specs[count++].specific = 0;
8553 else if (idesc->operands[i] == IA64_OPND_F1
8554 || idesc->operands[i] == IA64_OPND_F2
8555 || idesc->operands[i] == IA64_OPND_F3
8556 || idesc->operands[i] == IA64_OPND_F4)
8558 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8561 specs[count] = tmpl;
8562 specs[count++].specific = 0;
8565 else if (idesc->operands[i] == IA64_OPND_P1
8566 || idesc->operands[i] == IA64_OPND_P2)
8568 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8571 specs[count] = tmpl;
8572 specs[count++].specific = 0;
8576 if (CURR_SLOT.qp_regno > 15)
8578 specs[count] = tmpl;
8579 specs[count++].specific = 0;
8584 /* This is the same as IA64_RS_PRr, except simplified to account for
8585 the fact that there is only one register. */
8589 specs[count++] = tmpl;
8594 if (idesc->operands[2] == IA64_OPND_IMM17)
8595 mask = CURR_SLOT.opnd[2].X_add_number;
8596 if (mask & ((valueT) 1 << 63))
8597 specs[count++] = tmpl;
8599 else if (note == 11)
8601 if ((idesc->operands[0] == IA64_OPND_P1
8602 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8603 || (idesc->operands[1] == IA64_OPND_P2
8604 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8606 specs[count++] = tmpl;
8609 else if (note == 12)
8611 if (CURR_SLOT.qp_regno == 63)
8613 specs[count++] = tmpl;
8620 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8621 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8622 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8623 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8626 && (idesc->operands[0] == IA64_OPND_P1
8627 || idesc->operands[0] == IA64_OPND_P2))
8629 specs[count] = tmpl;
8630 specs[count++].cmp_type =
8631 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8634 && (idesc->operands[1] == IA64_OPND_P1
8635 || idesc->operands[1] == IA64_OPND_P2))
8637 specs[count] = tmpl;
8638 specs[count++].cmp_type =
8639 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8644 if (CURR_SLOT.qp_regno == 63)
8646 specs[count++] = tmpl;
8657 /* FIXME we can identify some individual RSE written resources, but RSE
8658 read resources have not yet been completely identified, so for now
8659 treat RSE as a single resource */
8660 if (strncmp (idesc->name, "mov", 3) == 0)
8664 if (idesc->operands[0] == IA64_OPND_AR3
8665 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8667 specs[count] = tmpl;
8668 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8673 if (idesc->operands[0] == IA64_OPND_AR3)
8675 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8676 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8678 specs[count++] = tmpl;
8681 else if (idesc->operands[1] == IA64_OPND_AR3)
8683 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8684 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8685 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8687 specs[count++] = tmpl;
8694 specs[count++] = tmpl;
8699 /* FIXME -- do any of these need to be non-specific? */
8700 specs[count++] = tmpl;
8704 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8711 /* Clear branch flags on marked resources. This breaks the link between the
8712 QP of the marking instruction and a subsequent branch on the same QP. */
8715 clear_qp_branch_flag (mask)
8719 for (i = 0; i < regdepslen; i++)
8721 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8722 if ((bit & mask) != 0)
8724 regdeps[i].link_to_qp_branch = 0;
8729 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
8730 any mutexes which contain one of the PRs and create new ones when
8734 update_qp_mutex (valueT mask)
8740 while (i < qp_mutexeslen)
8742 if ((qp_mutexes[i].prmask & mask) != 0)
8744 /* If it destroys and creates the same mutex, do nothing. */
8745 if (qp_mutexes[i].prmask == mask
8746 && qp_mutexes[i].path == md.path)
8757 fprintf (stderr, " Clearing mutex relation");
8758 print_prmask (qp_mutexes[i].prmask);
8759 fprintf (stderr, "\n");
8762 /* Deal with the old mutex with more than 3+ PRs only if
8763 the new mutex on the same execution path with it.
8765 FIXME: The 3+ mutex support is incomplete.
8766 dot_pred_rel () may be a better place to fix it. */
8767 if (qp_mutexes[i].path == md.path)
8769 /* If it is a proper subset of the mutex, create a
8772 && (qp_mutexes[i].prmask & mask) == mask)
8775 qp_mutexes[i].prmask &= ~mask;
8776 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
8778 /* Modify the mutex if there are more than one
8786 /* Remove the mutex. */
8787 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8795 add_qp_mutex (mask);
8800 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8802 Any changes to a PR clears the mutex relations which include that PR. */
8805 clear_qp_mutex (mask)
8811 while (i < qp_mutexeslen)
8813 if ((qp_mutexes[i].prmask & mask) != 0)
8817 fprintf (stderr, " Clearing mutex relation");
8818 print_prmask (qp_mutexes[i].prmask);
8819 fprintf (stderr, "\n");
8821 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8828 /* Clear implies relations which contain PRs in the given masks.
8829 P1_MASK indicates the source of the implies relation, while P2_MASK
8830 indicates the implied PR. */
8833 clear_qp_implies (p1_mask, p2_mask)
8840 while (i < qp_implieslen)
8842 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8843 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8846 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8847 qp_implies[i].p1, qp_implies[i].p2);
8848 qp_implies[i] = qp_implies[--qp_implieslen];
8855 /* Add the PRs specified to the list of implied relations. */
8858 add_qp_imply (p1, p2)
8865 /* p0 is not meaningful here. */
8866 if (p1 == 0 || p2 == 0)
8872 /* If it exists already, ignore it. */
8873 for (i = 0; i < qp_implieslen; i++)
8875 if (qp_implies[i].p1 == p1
8876 && qp_implies[i].p2 == p2
8877 && qp_implies[i].path == md.path
8878 && !qp_implies[i].p2_branched)
8882 if (qp_implieslen == qp_impliestotlen)
8884 qp_impliestotlen += 20;
8885 qp_implies = (struct qp_imply *)
8886 xrealloc ((void *) qp_implies,
8887 qp_impliestotlen * sizeof (struct qp_imply));
8890 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8891 qp_implies[qp_implieslen].p1 = p1;
8892 qp_implies[qp_implieslen].p2 = p2;
8893 qp_implies[qp_implieslen].path = md.path;
8894 qp_implies[qp_implieslen++].p2_branched = 0;
8896 /* Add in the implied transitive relations; for everything that p2 implies,
8897 make p1 imply that, too; for everything that implies p1, make it imply p2
8899 for (i = 0; i < qp_implieslen; i++)
8901 if (qp_implies[i].p1 == p2)
8902 add_qp_imply (p1, qp_implies[i].p2);
8903 if (qp_implies[i].p2 == p1)
8904 add_qp_imply (qp_implies[i].p1, p2);
8906 /* Add in mutex relations implied by this implies relation; for each mutex
8907 relation containing p2, duplicate it and replace p2 with p1. */
8908 bit = (valueT) 1 << p1;
8909 mask = (valueT) 1 << p2;
8910 for (i = 0; i < qp_mutexeslen; i++)
8912 if (qp_mutexes[i].prmask & mask)
8913 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8917 /* Add the PRs specified in the mask to the mutex list; this means that only
8918 one of the PRs can be true at any time. PR0 should never be included in
8928 if (qp_mutexeslen == qp_mutexestotlen)
8930 qp_mutexestotlen += 20;
8931 qp_mutexes = (struct qpmutex *)
8932 xrealloc ((void *) qp_mutexes,
8933 qp_mutexestotlen * sizeof (struct qpmutex));
8937 fprintf (stderr, " Registering mutex on");
8938 print_prmask (mask);
8939 fprintf (stderr, "\n");
8941 qp_mutexes[qp_mutexeslen].path = md.path;
8942 qp_mutexes[qp_mutexeslen++].prmask = mask;
8946 has_suffix_p (name, suffix)
8950 size_t namelen = strlen (name);
8951 size_t sufflen = strlen (suffix);
8953 if (namelen <= sufflen)
8955 return strcmp (name + namelen - sufflen, suffix) == 0;
8959 clear_register_values ()
8963 fprintf (stderr, " Clearing register values\n");
8964 for (i = 1; i < NELEMS (gr_values); i++)
8965 gr_values[i].known = 0;
8968 /* Keep track of register values/changes which affect DV tracking.
8970 optimization note: should add a flag to classes of insns where otherwise we
8971 have to examine a group of strings to identify them. */
8974 note_register_values (idesc)
8975 struct ia64_opcode *idesc;
8977 valueT qp_changemask = 0;
8980 /* Invalidate values for registers being written to. */
8981 for (i = 0; i < idesc->num_outputs; i++)
8983 if (idesc->operands[i] == IA64_OPND_R1
8984 || idesc->operands[i] == IA64_OPND_R2
8985 || idesc->operands[i] == IA64_OPND_R3)
8987 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8988 if (regno > 0 && regno < NELEMS (gr_values))
8989 gr_values[regno].known = 0;
8991 else if (idesc->operands[i] == IA64_OPND_R3_2)
8993 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8994 if (regno > 0 && regno < 4)
8995 gr_values[regno].known = 0;
8997 else if (idesc->operands[i] == IA64_OPND_P1
8998 || idesc->operands[i] == IA64_OPND_P2)
9000 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9001 qp_changemask |= (valueT) 1 << regno;
9003 else if (idesc->operands[i] == IA64_OPND_PR)
9005 if (idesc->operands[2] & (valueT) 0x10000)
9006 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9008 qp_changemask = idesc->operands[2];
9011 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9013 if (idesc->operands[1] & ((valueT) 1 << 43))
9014 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9016 qp_changemask = idesc->operands[1];
9017 qp_changemask &= ~(valueT) 0xFFFF;
9022 /* Always clear qp branch flags on any PR change. */
9023 /* FIXME there may be exceptions for certain compares. */
9024 clear_qp_branch_flag (qp_changemask);
9026 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9027 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9029 qp_changemask |= ~(valueT) 0xFFFF;
9030 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9032 for (i = 32; i < 32 + md.rot.num_regs; i++)
9033 gr_values[i].known = 0;
9035 clear_qp_mutex (qp_changemask);
9036 clear_qp_implies (qp_changemask, qp_changemask);
9038 /* After a call, all register values are undefined, except those marked
9040 else if (strncmp (idesc->name, "br.call", 6) == 0
9041 || strncmp (idesc->name, "brl.call", 7) == 0)
9043 /* FIXME keep GR values which are marked as "safe_across_calls" */
9044 clear_register_values ();
9045 clear_qp_mutex (~qp_safe_across_calls);
9046 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9047 clear_qp_branch_flag (~qp_safe_across_calls);
9049 else if (is_interruption_or_rfi (idesc)
9050 || is_taken_branch (idesc))
9052 clear_register_values ();
9053 clear_qp_mutex (~(valueT) 0);
9054 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9056 /* Look for mutex and implies relations. */
9057 else if ((idesc->operands[0] == IA64_OPND_P1
9058 || idesc->operands[0] == IA64_OPND_P2)
9059 && (idesc->operands[1] == IA64_OPND_P1
9060 || idesc->operands[1] == IA64_OPND_P2))
9062 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9063 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9064 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9065 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9067 /* If both PRs are PR0, we can't really do anything. */
9068 if (p1 == 0 && p2 == 0)
9071 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9073 /* In general, clear mutexes and implies which include P1 or P2,
9074 with the following exceptions. */
9075 else if (has_suffix_p (idesc->name, ".or.andcm")
9076 || has_suffix_p (idesc->name, ".and.orcm"))
9078 clear_qp_implies (p2mask, p1mask);
9080 else if (has_suffix_p (idesc->name, ".andcm")
9081 || has_suffix_p (idesc->name, ".and"))
9083 clear_qp_implies (0, p1mask | p2mask);
9085 else if (has_suffix_p (idesc->name, ".orcm")
9086 || has_suffix_p (idesc->name, ".or"))
9088 clear_qp_mutex (p1mask | p2mask);
9089 clear_qp_implies (p1mask | p2mask, 0);
9095 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9097 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9098 if (p1 == 0 || p2 == 0)
9099 clear_qp_mutex (p1mask | p2mask);
9101 added = update_qp_mutex (p1mask | p2mask);
9103 if (CURR_SLOT.qp_regno == 0
9104 || has_suffix_p (idesc->name, ".unc"))
9106 if (added == 0 && p1 && p2)
9107 add_qp_mutex (p1mask | p2mask);
9108 if (CURR_SLOT.qp_regno != 0)
9111 add_qp_imply (p1, CURR_SLOT.qp_regno);
9113 add_qp_imply (p2, CURR_SLOT.qp_regno);
9118 /* Look for mov imm insns into GRs. */
9119 else if (idesc->operands[0] == IA64_OPND_R1
9120 && (idesc->operands[1] == IA64_OPND_IMM22
9121 || idesc->operands[1] == IA64_OPND_IMMU64)
9122 && (strcmp (idesc->name, "mov") == 0
9123 || strcmp (idesc->name, "movl") == 0))
9125 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9126 if (regno > 0 && regno < NELEMS (gr_values))
9128 gr_values[regno].known = 1;
9129 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9130 gr_values[regno].path = md.path;
9133 fprintf (stderr, " Know gr%d = ", regno);
9134 fprintf_vma (stderr, gr_values[regno].value);
9135 fputs ("\n", stderr);
9141 clear_qp_mutex (qp_changemask);
9142 clear_qp_implies (qp_changemask, qp_changemask);
9146 /* Return whether the given predicate registers are currently mutex. */
9149 qp_mutex (p1, p2, path)
9159 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9160 for (i = 0; i < qp_mutexeslen; i++)
9162 if (qp_mutexes[i].path >= path
9163 && (qp_mutexes[i].prmask & mask) == mask)
9170 /* Return whether the given resource is in the given insn's list of chks
9171 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9175 resources_match (rs, idesc, note, qp_regno, path)
9177 struct ia64_opcode *idesc;
9182 struct rsrc specs[MAX_SPECS];
9185 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9186 we don't need to check. One exception is note 11, which indicates that
9187 target predicates are written regardless of PR[qp]. */
9188 if (qp_mutex (rs->qp_regno, qp_regno, path)
9192 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9195 /* UNAT checking is a bit more specific than other resources */
9196 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9197 && specs[count].mem_offset.hint
9198 && rs->mem_offset.hint)
9200 if (rs->mem_offset.base == specs[count].mem_offset.base)
9202 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9203 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9210 /* Skip apparent PR write conflicts where both writes are an AND or both
9211 writes are an OR. */
9212 if (rs->dependency->specifier == IA64_RS_PR
9213 || rs->dependency->specifier == IA64_RS_PRr
9214 || rs->dependency->specifier == IA64_RS_PR63)
9216 if (specs[count].cmp_type != CMP_NONE
9217 && specs[count].cmp_type == rs->cmp_type)
9220 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9221 dv_mode[rs->dependency->mode],
9222 rs->dependency->specifier != IA64_RS_PR63 ?
9223 specs[count].index : 63);
9228 " %s on parallel compare conflict %s vs %s on PR%d\n",
9229 dv_mode[rs->dependency->mode],
9230 dv_cmp_type[rs->cmp_type],
9231 dv_cmp_type[specs[count].cmp_type],
9232 rs->dependency->specifier != IA64_RS_PR63 ?
9233 specs[count].index : 63);
9237 /* If either resource is not specific, conservatively assume a conflict
9239 if (!specs[count].specific || !rs->specific)
9241 else if (specs[count].index == rs->index)
9246 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9252 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9253 insert a stop to create the break. Update all resource dependencies
9254 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9255 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9256 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9260 insn_group_break (insert_stop, qp_regno, save_current)
9267 if (insert_stop && md.num_slots_in_use > 0)
9268 PREV_SLOT.end_of_insn_group = 1;
9272 fprintf (stderr, " Insn group break%s",
9273 (insert_stop ? " (w/stop)" : ""));
9275 fprintf (stderr, " effective for QP=%d", qp_regno);
9276 fprintf (stderr, "\n");
9280 while (i < regdepslen)
9282 const struct ia64_dependency *dep = regdeps[i].dependency;
9285 && regdeps[i].qp_regno != qp_regno)
9292 && CURR_SLOT.src_file == regdeps[i].file
9293 && CURR_SLOT.src_line == regdeps[i].line)
9299 /* clear dependencies which are automatically cleared by a stop, or
9300 those that have reached the appropriate state of insn serialization */
9301 if (dep->semantics == IA64_DVS_IMPLIED
9302 || dep->semantics == IA64_DVS_IMPLIEDF
9303 || regdeps[i].insn_srlz == STATE_SRLZ)
9305 print_dependency ("Removing", i);
9306 regdeps[i] = regdeps[--regdepslen];
9310 if (dep->semantics == IA64_DVS_DATA
9311 || dep->semantics == IA64_DVS_INSTR
9312 || dep->semantics == IA64_DVS_SPECIFIC)
9314 if (regdeps[i].insn_srlz == STATE_NONE)
9315 regdeps[i].insn_srlz = STATE_STOP;
9316 if (regdeps[i].data_srlz == STATE_NONE)
9317 regdeps[i].data_srlz = STATE_STOP;
9324 /* Add the given resource usage spec to the list of active dependencies. */
9327 mark_resource (idesc, dep, spec, depind, path)
9328 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9329 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9334 if (regdepslen == regdepstotlen)
9336 regdepstotlen += 20;
9337 regdeps = (struct rsrc *)
9338 xrealloc ((void *) regdeps,
9339 regdepstotlen * sizeof (struct rsrc));
9342 regdeps[regdepslen] = *spec;
9343 regdeps[regdepslen].depind = depind;
9344 regdeps[regdepslen].path = path;
9345 regdeps[regdepslen].file = CURR_SLOT.src_file;
9346 regdeps[regdepslen].line = CURR_SLOT.src_line;
9348 print_dependency ("Adding", regdepslen);
9354 print_dependency (action, depind)
9360 fprintf (stderr, " %s %s '%s'",
9361 action, dv_mode[(regdeps[depind].dependency)->mode],
9362 (regdeps[depind].dependency)->name);
9363 if (regdeps[depind].specific && regdeps[depind].index != 0)
9364 fprintf (stderr, " (%d)", regdeps[depind].index);
9365 if (regdeps[depind].mem_offset.hint)
9367 fputs (" ", stderr);
9368 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9369 fputs ("+", stderr);
9370 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9372 fprintf (stderr, "\n");
9377 instruction_serialization ()
9381 fprintf (stderr, " Instruction serialization\n");
9382 for (i = 0; i < regdepslen; i++)
9383 if (regdeps[i].insn_srlz == STATE_STOP)
9384 regdeps[i].insn_srlz = STATE_SRLZ;
9388 data_serialization ()
9392 fprintf (stderr, " Data serialization\n");
9393 while (i < regdepslen)
9395 if (regdeps[i].data_srlz == STATE_STOP
9396 /* Note: as of 991210, all "other" dependencies are cleared by a
9397 data serialization. This might change with new tables */
9398 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9400 print_dependency ("Removing", i);
9401 regdeps[i] = regdeps[--regdepslen];
9408 /* Insert stops and serializations as needed to avoid DVs. */
9411 remove_marked_resource (rs)
9414 switch (rs->dependency->semantics)
9416 case IA64_DVS_SPECIFIC:
9418 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9419 /* ...fall through... */
9420 case IA64_DVS_INSTR:
9422 fprintf (stderr, "Inserting instr serialization\n");
9423 if (rs->insn_srlz < STATE_STOP)
9424 insn_group_break (1, 0, 0);
9425 if (rs->insn_srlz < STATE_SRLZ)
9427 int oldqp = CURR_SLOT.qp_regno;
9428 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9429 /* Manually jam a srlz.i insn into the stream */
9430 CURR_SLOT.qp_regno = 0;
9431 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9432 instruction_serialization ();
9433 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9434 if (++md.num_slots_in_use >= NUM_SLOTS)
9436 CURR_SLOT.qp_regno = oldqp;
9437 CURR_SLOT.idesc = oldidesc;
9439 insn_group_break (1, 0, 0);
9441 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9442 "other" types of DV are eliminated
9443 by a data serialization */
9446 fprintf (stderr, "Inserting data serialization\n");
9447 if (rs->data_srlz < STATE_STOP)
9448 insn_group_break (1, 0, 0);
9450 int oldqp = CURR_SLOT.qp_regno;
9451 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9452 /* Manually jam a srlz.d insn into the stream */
9453 CURR_SLOT.qp_regno = 0;
9454 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9455 data_serialization ();
9456 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9457 if (++md.num_slots_in_use >= NUM_SLOTS)
9459 CURR_SLOT.qp_regno = oldqp;
9460 CURR_SLOT.idesc = oldidesc;
9463 case IA64_DVS_IMPLIED:
9464 case IA64_DVS_IMPLIEDF:
9466 fprintf (stderr, "Inserting stop\n");
9467 insn_group_break (1, 0, 0);
9474 /* Check the resources used by the given opcode against the current dependency
9477 The check is run once for each execution path encountered. In this case,
9478 a unique execution path is the sequence of instructions following a code
9479 entry point, e.g. the following has three execution paths, one starting
9480 at L0, one at L1, and one at L2.
9489 check_dependencies (idesc)
9490 struct ia64_opcode *idesc;
9492 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9496 /* Note that the number of marked resources may change within the
9497 loop if in auto mode. */
9499 while (i < regdepslen)
9501 struct rsrc *rs = ®deps[i];
9502 const struct ia64_dependency *dep = rs->dependency;
9507 if (dep->semantics == IA64_DVS_NONE
9508 || (chkind = depends_on (rs->depind, idesc)) == -1)
9514 note = NOTE (opdeps->chks[chkind]);
9516 /* Check this resource against each execution path seen thus far. */
9517 for (path = 0; path <= md.path; path++)
9521 /* If the dependency wasn't on the path being checked, ignore it. */
9522 if (rs->path < path)
9525 /* If the QP for this insn implies a QP which has branched, don't
9526 bother checking. Ed. NOTE: I don't think this check is terribly
9527 useful; what's the point of generating code which will only be
9528 reached if its QP is zero?
9529 This code was specifically inserted to handle the following code,
9530 based on notes from Intel's DV checking code, where p1 implies p2.
9536 if (CURR_SLOT.qp_regno != 0)
9540 for (implies = 0; implies < qp_implieslen; implies++)
9542 if (qp_implies[implies].path >= path
9543 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9544 && qp_implies[implies].p2_branched)
9554 if ((matchtype = resources_match (rs, idesc, note,
9555 CURR_SLOT.qp_regno, path)) != 0)
9558 char pathmsg[256] = "";
9559 char indexmsg[256] = "";
9560 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9563 sprintf (pathmsg, " when entry is at label '%s'",
9564 md.entry_labels[path - 1]);
9565 if (rs->specific && rs->index != 0)
9566 sprintf (indexmsg, ", specific resource number is %d",
9568 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9570 (certain ? "violates" : "may violate"),
9571 dv_mode[dep->mode], dep->name,
9572 dv_sem[dep->semantics],
9575 if (md.explicit_mode)
9577 as_warn ("%s", msg);
9579 as_warn (_("Only the first path encountering the conflict "
9581 as_warn_where (rs->file, rs->line,
9582 _("This is the location of the "
9583 "conflicting usage"));
9584 /* Don't bother checking other paths, to avoid duplicating
9591 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9593 remove_marked_resource (rs);
9595 /* since the set of dependencies has changed, start over */
9596 /* FIXME -- since we're removing dvs as we go, we
9597 probably don't really need to start over... */
9610 /* Register new dependencies based on the given opcode. */
9613 mark_resources (idesc)
9614 struct ia64_opcode *idesc;
9617 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9618 int add_only_qp_reads = 0;
9620 /* A conditional branch only uses its resources if it is taken; if it is
9621 taken, we stop following that path. The other branch types effectively
9622 *always* write their resources. If it's not taken, register only QP
9624 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9626 add_only_qp_reads = 1;
9630 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9632 for (i = 0; i < opdeps->nregs; i++)
9634 const struct ia64_dependency *dep;
9635 struct rsrc specs[MAX_SPECS];
9640 dep = ia64_find_dependency (opdeps->regs[i]);
9641 note = NOTE (opdeps->regs[i]);
9643 if (add_only_qp_reads
9644 && !(dep->mode == IA64_DV_WAR
9645 && (dep->specifier == IA64_RS_PR
9646 || dep->specifier == IA64_RS_PRr
9647 || dep->specifier == IA64_RS_PR63)))
9650 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9653 if (md.debug_dv && !count)
9654 fprintf (stderr, " No %s %s usage found (path %d)\n",
9655 dv_mode[dep->mode], dep->name, md.path);
9660 mark_resource (idesc, dep, &specs[count],
9661 DEP (opdeps->regs[i]), md.path);
9664 /* The execution path may affect register values, which may in turn
9665 affect which indirect-access resources are accessed. */
9666 switch (dep->specifier)
9678 for (path = 0; path < md.path; path++)
9680 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9682 mark_resource (idesc, dep, &specs[count],
9683 DEP (opdeps->regs[i]), path);
9690 /* Remove dependencies when they no longer apply. */
9693 update_dependencies (idesc)
9694 struct ia64_opcode *idesc;
9698 if (strcmp (idesc->name, "srlz.i") == 0)
9700 instruction_serialization ();
9702 else if (strcmp (idesc->name, "srlz.d") == 0)
9704 data_serialization ();
9706 else if (is_interruption_or_rfi (idesc)
9707 || is_taken_branch (idesc))
9709 /* Although technically the taken branch doesn't clear dependencies
9710 which require a srlz.[id], we don't follow the branch; the next
9711 instruction is assumed to start with a clean slate. */
9715 else if (is_conditional_branch (idesc)
9716 && CURR_SLOT.qp_regno != 0)
9718 int is_call = strstr (idesc->name, ".call") != NULL;
9720 for (i = 0; i < qp_implieslen; i++)
9722 /* If the conditional branch's predicate is implied by the predicate
9723 in an existing dependency, remove that dependency. */
9724 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9727 /* Note that this implied predicate takes a branch so that if
9728 a later insn generates a DV but its predicate implies this
9729 one, we can avoid the false DV warning. */
9730 qp_implies[i].p2_branched = 1;
9731 while (depind < regdepslen)
9733 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9735 print_dependency ("Removing", depind);
9736 regdeps[depind] = regdeps[--regdepslen];
9743 /* Any marked resources which have this same predicate should be
9744 cleared, provided that the QP hasn't been modified between the
9745 marking instruction and the branch. */
9748 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9753 while (i < regdepslen)
9755 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9756 && regdeps[i].link_to_qp_branch
9757 && (regdeps[i].file != CURR_SLOT.src_file
9758 || regdeps[i].line != CURR_SLOT.src_line))
9760 /* Treat like a taken branch */
9761 print_dependency ("Removing", i);
9762 regdeps[i] = regdeps[--regdepslen];
9771 /* Examine the current instruction for dependency violations. */
9775 struct ia64_opcode *idesc;
9779 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9780 idesc->name, CURR_SLOT.src_line,
9781 idesc->dependencies->nchks,
9782 idesc->dependencies->nregs);
9785 /* Look through the list of currently marked resources; if the current
9786 instruction has the dependency in its chks list which uses that resource,
9787 check against the specific resources used. */
9788 check_dependencies (idesc);
9790 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9791 then add them to the list of marked resources. */
9792 mark_resources (idesc);
9794 /* There are several types of dependency semantics, and each has its own
9795 requirements for being cleared
9797 Instruction serialization (insns separated by interruption, rfi, or
9798 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9800 Data serialization (instruction serialization, or writer + srlz.d +
9801 reader, where writer and srlz.d are in separate groups) clears
9802 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9803 always be the case).
9805 Instruction group break (groups separated by stop, taken branch,
9806 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9808 update_dependencies (idesc);
9810 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9811 warning. Keep track of as many as possible that are useful. */
9812 note_register_values (idesc);
9814 /* We don't need or want this anymore. */
9815 md.mem_offset.hint = 0;
9820 /* Translate one line of assembly. Pseudo ops and labels do not show
9826 char *saved_input_line_pointer, *mnemonic;
9827 const struct pseudo_opcode *pdesc;
9828 struct ia64_opcode *idesc;
9829 unsigned char qp_regno;
9833 saved_input_line_pointer = input_line_pointer;
9834 input_line_pointer = str;
9836 /* extract the opcode (mnemonic): */
9838 mnemonic = input_line_pointer;
9839 ch = get_symbol_end ();
9840 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9843 *input_line_pointer = ch;
9844 (*pdesc->handler) (pdesc->arg);
9848 /* Find the instruction descriptor matching the arguments. */
9850 idesc = ia64_find_opcode (mnemonic);
9851 *input_line_pointer = ch;
9854 as_bad ("Unknown opcode `%s'", mnemonic);
9858 idesc = parse_operands (idesc);
9862 /* Handle the dynamic ops we can handle now: */
9863 if (idesc->type == IA64_TYPE_DYN)
9865 if (strcmp (idesc->name, "add") == 0)
9867 if (CURR_SLOT.opnd[2].X_op == O_register
9868 && CURR_SLOT.opnd[2].X_add_number < 4)
9872 ia64_free_opcode (idesc);
9873 idesc = ia64_find_opcode (mnemonic);
9875 know (!idesc->next);
9878 else if (strcmp (idesc->name, "mov") == 0)
9880 enum ia64_opnd opnd1, opnd2;
9883 opnd1 = idesc->operands[0];
9884 opnd2 = idesc->operands[1];
9885 if (opnd1 == IA64_OPND_AR3)
9887 else if (opnd2 == IA64_OPND_AR3)
9891 if (CURR_SLOT.opnd[rop].X_op == O_register
9892 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9896 ia64_free_opcode (idesc);
9897 idesc = ia64_find_opcode (mnemonic);
9898 while (idesc != NULL
9899 && (idesc->operands[0] != opnd1
9900 || idesc->operands[1] != opnd2))
9901 idesc = get_next_opcode (idesc);
9906 if (md.qp.X_op == O_register)
9908 qp_regno = md.qp.X_add_number - REG_P;
9909 md.qp.X_op = O_absent;
9912 flags = idesc->flags;
9914 if ((flags & IA64_OPCODE_FIRST) != 0)
9915 insn_group_break (1, 0, 0);
9917 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
9919 as_bad ("`%s' cannot be predicated", idesc->name);
9923 /* Build the instruction. */
9924 CURR_SLOT.qp_regno = qp_regno;
9925 CURR_SLOT.idesc = idesc;
9926 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
9927 dwarf2_where (&CURR_SLOT.debug_line);
9929 /* Add unwind entry, if there is one. */
9930 if (unwind.current_entry)
9932 CURR_SLOT.unwind_record = unwind.current_entry;
9933 unwind.current_entry = NULL;
9936 /* Check for dependency violations. */
9940 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9941 if (++md.num_slots_in_use >= NUM_SLOTS)
9944 if ((flags & IA64_OPCODE_LAST) != 0)
9945 insn_group_break (1, 0, 0);
9947 md.last_text_seg = now_seg;
9950 input_line_pointer = saved_input_line_pointer;
9953 /* Called when symbol NAME cannot be found in the symbol table.
9954 Should be used for dynamic valued symbols only. */
9957 md_undefined_symbol (name)
9958 char *name ATTRIBUTE_UNUSED;
9963 /* Called for any expression that can not be recognized. When the
9964 function is called, `input_line_pointer' will point to the start of
9971 enum pseudo_type pseudo_type;
9976 switch (*input_line_pointer)
9979 /* Find what relocation pseudo-function we're dealing with. */
9981 ch = *++input_line_pointer;
9982 for (i = 0; i < NELEMS (pseudo_func); ++i)
9983 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
9985 len = strlen (pseudo_func[i].name);
9986 if (strncmp (pseudo_func[i].name + 1,
9987 input_line_pointer + 1, len - 1) == 0
9988 && !is_part_of_name (input_line_pointer[len]))
9990 input_line_pointer += len;
9991 pseudo_type = pseudo_func[i].type;
9995 switch (pseudo_type)
9997 case PSEUDO_FUNC_RELOC:
9999 if (*input_line_pointer != '(')
10001 as_bad ("Expected '('");
10005 ++input_line_pointer;
10007 if (*input_line_pointer++ != ')')
10009 as_bad ("Missing ')'");
10012 if (e->X_op != O_symbol)
10014 if (e->X_op != O_pseudo_fixup)
10016 as_bad ("Not a symbolic expression");
10019 if (i != FUNC_LT_RELATIVE)
10021 as_bad ("Illegal combination of relocation functions");
10024 switch (S_GET_VALUE (e->X_op_symbol))
10026 case FUNC_FPTR_RELATIVE:
10027 i = FUNC_LT_FPTR_RELATIVE; break;
10028 case FUNC_DTP_MODULE:
10029 i = FUNC_LT_DTP_MODULE; break;
10030 case FUNC_DTP_RELATIVE:
10031 i = FUNC_LT_DTP_RELATIVE; break;
10032 case FUNC_TP_RELATIVE:
10033 i = FUNC_LT_TP_RELATIVE; break;
10035 as_bad ("Illegal combination of relocation functions");
10039 /* Make sure gas doesn't get rid of local symbols that are used
10041 e->X_op = O_pseudo_fixup;
10042 e->X_op_symbol = pseudo_func[i].u.sym;
10045 case PSEUDO_FUNC_CONST:
10046 e->X_op = O_constant;
10047 e->X_add_number = pseudo_func[i].u.ival;
10050 case PSEUDO_FUNC_REG:
10051 e->X_op = O_register;
10052 e->X_add_number = pseudo_func[i].u.ival;
10056 name = input_line_pointer - 1;
10058 as_bad ("Unknown pseudo function `%s'", name);
10064 ++input_line_pointer;
10066 if (*input_line_pointer != ']')
10068 as_bad ("Closing bracket misssing");
10073 if (e->X_op != O_register)
10074 as_bad ("Register expected as index");
10076 ++input_line_pointer;
10087 ignore_rest_of_line ();
10090 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10091 a section symbol plus some offset. For relocs involving @fptr(),
10092 directives we don't want such adjustments since we need to have the
10093 original symbol's name in the reloc. */
10095 ia64_fix_adjustable (fix)
10098 /* Prevent all adjustments to global symbols */
10099 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10102 switch (fix->fx_r_type)
10104 case BFD_RELOC_IA64_FPTR64I:
10105 case BFD_RELOC_IA64_FPTR32MSB:
10106 case BFD_RELOC_IA64_FPTR32LSB:
10107 case BFD_RELOC_IA64_FPTR64MSB:
10108 case BFD_RELOC_IA64_FPTR64LSB:
10109 case BFD_RELOC_IA64_LTOFF_FPTR22:
10110 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10120 ia64_force_relocation (fix)
10123 switch (fix->fx_r_type)
10125 case BFD_RELOC_IA64_FPTR64I:
10126 case BFD_RELOC_IA64_FPTR32MSB:
10127 case BFD_RELOC_IA64_FPTR32LSB:
10128 case BFD_RELOC_IA64_FPTR64MSB:
10129 case BFD_RELOC_IA64_FPTR64LSB:
10131 case BFD_RELOC_IA64_LTOFF22:
10132 case BFD_RELOC_IA64_LTOFF64I:
10133 case BFD_RELOC_IA64_LTOFF_FPTR22:
10134 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10135 case BFD_RELOC_IA64_PLTOFF22:
10136 case BFD_RELOC_IA64_PLTOFF64I:
10137 case BFD_RELOC_IA64_PLTOFF64MSB:
10138 case BFD_RELOC_IA64_PLTOFF64LSB:
10140 case BFD_RELOC_IA64_LTOFF22X:
10141 case BFD_RELOC_IA64_LDXMOV:
10148 return generic_force_reloc (fix);
10151 /* Decide from what point a pc-relative relocation is relative to,
10152 relative to the pc-relative fixup. Er, relatively speaking. */
10154 ia64_pcrel_from_section (fix, sec)
10158 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10160 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10167 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10169 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10173 expr.X_op = O_pseudo_fixup;
10174 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10175 expr.X_add_number = 0;
10176 expr.X_add_symbol = symbol;
10177 emit_expr (&expr, size);
10180 /* This is called whenever some data item (not an instruction) needs a
10181 fixup. We pick the right reloc code depending on the byteorder
10182 currently in effect. */
10184 ia64_cons_fix_new (f, where, nbytes, exp)
10190 bfd_reloc_code_real_type code;
10195 /* There are no reloc for 8 and 16 bit quantities, but we allow
10196 them here since they will work fine as long as the expression
10197 is fully defined at the end of the pass over the source file. */
10198 case 1: code = BFD_RELOC_8; break;
10199 case 2: code = BFD_RELOC_16; break;
10201 if (target_big_endian)
10202 code = BFD_RELOC_IA64_DIR32MSB;
10204 code = BFD_RELOC_IA64_DIR32LSB;
10208 /* In 32-bit mode, data8 could mean function descriptors too. */
10209 if (exp->X_op == O_pseudo_fixup
10210 && exp->X_op_symbol
10211 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10212 && !(md.flags & EF_IA_64_ABI64))
10214 if (target_big_endian)
10215 code = BFD_RELOC_IA64_IPLTMSB;
10217 code = BFD_RELOC_IA64_IPLTLSB;
10218 exp->X_op = O_symbol;
10223 if (target_big_endian)
10224 code = BFD_RELOC_IA64_DIR64MSB;
10226 code = BFD_RELOC_IA64_DIR64LSB;
10231 if (exp->X_op == O_pseudo_fixup
10232 && exp->X_op_symbol
10233 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10235 if (target_big_endian)
10236 code = BFD_RELOC_IA64_IPLTMSB;
10238 code = BFD_RELOC_IA64_IPLTLSB;
10239 exp->X_op = O_symbol;
10245 as_bad ("Unsupported fixup size %d", nbytes);
10246 ignore_rest_of_line ();
10250 if (exp->X_op == O_pseudo_fixup)
10252 exp->X_op = O_symbol;
10253 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10254 /* ??? If code unchanged, unsupported. */
10257 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10258 /* We need to store the byte order in effect in case we're going
10259 to fix an 8 or 16 bit relocation (for which there no real
10260 relocs available). See md_apply_fix3(). */
10261 fix->tc_fix_data.bigendian = target_big_endian;
10264 /* Return the actual relocation we wish to associate with the pseudo
10265 reloc described by SYM and R_TYPE. SYM should be one of the
10266 symbols in the pseudo_func array, or NULL. */
10268 static bfd_reloc_code_real_type
10269 ia64_gen_real_reloc_type (sym, r_type)
10270 struct symbol *sym;
10271 bfd_reloc_code_real_type r_type;
10273 bfd_reloc_code_real_type new = 0;
10280 switch (S_GET_VALUE (sym))
10282 case FUNC_FPTR_RELATIVE:
10285 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10286 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10287 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10288 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10289 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10294 case FUNC_GP_RELATIVE:
10297 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10298 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10299 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10300 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10301 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10302 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10307 case FUNC_LT_RELATIVE:
10310 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10311 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10316 case FUNC_LT_RELATIVE_X:
10319 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10324 case FUNC_PC_RELATIVE:
10327 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10328 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10329 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10330 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10331 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10332 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10337 case FUNC_PLT_RELATIVE:
10340 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10341 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10342 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10343 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10348 case FUNC_SEC_RELATIVE:
10351 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10352 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10353 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10354 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10359 case FUNC_SEG_RELATIVE:
10362 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10363 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10364 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10365 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10370 case FUNC_LTV_RELATIVE:
10373 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10374 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10375 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10376 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10381 case FUNC_LT_FPTR_RELATIVE:
10384 case BFD_RELOC_IA64_IMM22:
10385 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10386 case BFD_RELOC_IA64_IMM64:
10387 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10393 case FUNC_TP_RELATIVE:
10396 case BFD_RELOC_IA64_IMM14:
10397 new = BFD_RELOC_IA64_TPREL14; break;
10398 case BFD_RELOC_IA64_IMM22:
10399 new = BFD_RELOC_IA64_TPREL22; break;
10400 case BFD_RELOC_IA64_IMM64:
10401 new = BFD_RELOC_IA64_TPREL64I; break;
10407 case FUNC_LT_TP_RELATIVE:
10410 case BFD_RELOC_IA64_IMM22:
10411 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10417 case FUNC_LT_DTP_MODULE:
10420 case BFD_RELOC_IA64_IMM22:
10421 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10427 case FUNC_DTP_RELATIVE:
10430 case BFD_RELOC_IA64_DIR64MSB:
10431 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10432 case BFD_RELOC_IA64_DIR64LSB:
10433 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10434 case BFD_RELOC_IA64_IMM14:
10435 new = BFD_RELOC_IA64_DTPREL14; break;
10436 case BFD_RELOC_IA64_IMM22:
10437 new = BFD_RELOC_IA64_DTPREL22; break;
10438 case BFD_RELOC_IA64_IMM64:
10439 new = BFD_RELOC_IA64_DTPREL64I; break;
10445 case FUNC_LT_DTP_RELATIVE:
10448 case BFD_RELOC_IA64_IMM22:
10449 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10455 case FUNC_IPLT_RELOC:
10462 /* Hmmmm. Should this ever occur? */
10469 /* Here is where generate the appropriate reloc for pseudo relocation
10472 ia64_validate_fix (fix)
10475 switch (fix->fx_r_type)
10477 case BFD_RELOC_IA64_FPTR64I:
10478 case BFD_RELOC_IA64_FPTR32MSB:
10479 case BFD_RELOC_IA64_FPTR64LSB:
10480 case BFD_RELOC_IA64_LTOFF_FPTR22:
10481 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10482 if (fix->fx_offset != 0)
10483 as_bad_where (fix->fx_file, fix->fx_line,
10484 "No addend allowed in @fptr() relocation");
10494 fix_insn (fix, odesc, value)
10496 const struct ia64_operand *odesc;
10499 bfd_vma insn[3], t0, t1, control_bits;
10504 slot = fix->fx_where & 0x3;
10505 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10507 /* Bundles are always in little-endian byte order */
10508 t0 = bfd_getl64 (fixpos);
10509 t1 = bfd_getl64 (fixpos + 8);
10510 control_bits = t0 & 0x1f;
10511 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10512 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10513 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10516 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10518 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10519 insn[2] |= (((value & 0x7f) << 13)
10520 | (((value >> 7) & 0x1ff) << 27)
10521 | (((value >> 16) & 0x1f) << 22)
10522 | (((value >> 21) & 0x1) << 21)
10523 | (((value >> 63) & 0x1) << 36));
10525 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10527 if (value & ~0x3fffffffffffffffULL)
10528 err = "integer operand out of range";
10529 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10530 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10532 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10535 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10536 insn[2] |= ((((value >> 59) & 0x1) << 36)
10537 | (((value >> 0) & 0xfffff) << 13));
10540 err = (*odesc->insert) (odesc, value, insn + slot);
10543 as_bad_where (fix->fx_file, fix->fx_line, err);
10545 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10546 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10547 number_to_chars_littleendian (fixpos + 0, t0, 8);
10548 number_to_chars_littleendian (fixpos + 8, t1, 8);
10551 /* Attempt to simplify or even eliminate a fixup. The return value is
10552 ignored; perhaps it was once meaningful, but now it is historical.
10553 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10555 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10559 md_apply_fix3 (fix, valP, seg)
10562 segT seg ATTRIBUTE_UNUSED;
10565 valueT value = *valP;
10567 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10571 switch (fix->fx_r_type)
10573 case BFD_RELOC_IA64_DIR32MSB:
10574 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10577 case BFD_RELOC_IA64_DIR32LSB:
10578 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10581 case BFD_RELOC_IA64_DIR64MSB:
10582 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10585 case BFD_RELOC_IA64_DIR64LSB:
10586 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10595 switch (fix->fx_r_type)
10597 case BFD_RELOC_UNUSED:
10598 /* This must be a TAG13 or TAG13b operand. There are no external
10599 relocs defined for them, so we must give an error. */
10600 as_bad_where (fix->fx_file, fix->fx_line,
10601 "%s must have a constant value",
10602 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10606 case BFD_RELOC_IA64_TPREL14:
10607 case BFD_RELOC_IA64_TPREL22:
10608 case BFD_RELOC_IA64_TPREL64I:
10609 case BFD_RELOC_IA64_LTOFF_TPREL22:
10610 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10611 case BFD_RELOC_IA64_DTPREL14:
10612 case BFD_RELOC_IA64_DTPREL22:
10613 case BFD_RELOC_IA64_DTPREL64I:
10614 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10615 S_SET_THREAD_LOCAL (fix->fx_addsy);
10622 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10624 if (fix->tc_fix_data.bigendian)
10625 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10627 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10632 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10637 /* Generate the BFD reloc to be stuck in the object file from the
10638 fixup used internally in the assembler. */
10641 tc_gen_reloc (sec, fixp)
10642 asection *sec ATTRIBUTE_UNUSED;
10647 reloc = xmalloc (sizeof (*reloc));
10648 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10649 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10650 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10651 reloc->addend = fixp->fx_offset;
10652 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10656 as_bad_where (fixp->fx_file, fixp->fx_line,
10657 "Cannot represent %s relocation in object file",
10658 bfd_get_reloc_code_name (fixp->fx_r_type));
10663 /* Turn a string in input_line_pointer into a floating point constant
10664 of type TYPE, and store the appropriate bytes in *LIT. The number
10665 of LITTLENUMS emitted is stored in *SIZE. An error message is
10666 returned, or NULL on OK. */
10668 #define MAX_LITTLENUMS 5
10671 md_atof (type, lit, size)
10676 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10706 return "Bad call to MD_ATOF()";
10708 t = atof_ieee (input_line_pointer, type, words);
10710 input_line_pointer = t;
10712 (*ia64_float_to_chars) (lit, words, prec);
10716 /* It is 10 byte floating point with 6 byte padding. */
10717 memset (&lit [10], 0, 6);
10718 *size = 8 * sizeof (LITTLENUM_TYPE);
10721 *size = prec * sizeof (LITTLENUM_TYPE);
10726 /* Handle ia64 specific semantics of the align directive. */
10729 ia64_md_do_align (n, fill, len, max)
10730 int n ATTRIBUTE_UNUSED;
10731 const char *fill ATTRIBUTE_UNUSED;
10732 int len ATTRIBUTE_UNUSED;
10733 int max ATTRIBUTE_UNUSED;
10735 if (subseg_text_p (now_seg))
10736 ia64_flush_insns ();
10739 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10740 of an rs_align_code fragment. */
10743 ia64_handle_align (fragp)
10746 /* Use mfi bundle of nops with no stop bits. */
10747 static const unsigned char be_nop[]
10748 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
10749 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
10750 static const unsigned char le_nop[]
10751 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10752 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10757 if (fragp->fr_type != rs_align_code)
10760 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10761 p = fragp->fr_literal + fragp->fr_fix;
10763 /* Make sure we are on a 16-byte boundary, in case someone has been
10764 putting data into a text section. */
10767 int fix = bytes & 15;
10768 memset (p, 0, fix);
10771 fragp->fr_fix += fix;
10774 memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
10775 fragp->fr_var = 16;
10779 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
10784 number_to_chars_bigendian (lit, (long) (*words++),
10785 sizeof (LITTLENUM_TYPE));
10786 lit += sizeof (LITTLENUM_TYPE);
10791 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
10796 number_to_chars_littleendian (lit, (long) (words[prec]),
10797 sizeof (LITTLENUM_TYPE));
10798 lit += sizeof (LITTLENUM_TYPE);
10803 ia64_elf_section_change_hook (void)
10805 dot_byteorder (-1);
10808 /* Check if a label should be made global. */
10810 ia64_check_label (symbolS *label)
10812 if (*input_line_pointer == ':')
10814 S_SET_EXTERNAL (label);
10815 input_line_pointer++;
10819 /* Used to remember where .alias and .secalias directives are seen. We
10820 will rename symbol and section names when we are about to output
10821 the relocatable file. */
10824 char *file; /* The file where the directive is seen. */
10825 unsigned int line; /* The line number the directive is at. */
10826 const char *name; /* The orignale name of the symbol. */
10829 /* Called for .alias and .secalias directives. If SECTION is 1, it is
10830 .secalias. Otherwise, it is .alias. */
10832 dot_alias (int section)
10834 char *name, *alias;
10838 const char *error_string;
10841 struct hash_control *ahash, *nhash;
10844 name = input_line_pointer;
10845 delim = get_symbol_end ();
10846 end_name = input_line_pointer;
10849 if (name == end_name)
10851 as_bad (_("expected symbol name"));
10852 discard_rest_of_line ();
10856 SKIP_WHITESPACE ();
10858 if (*input_line_pointer != ',')
10861 as_bad (_("expected comma after \"%s\""), name);
10863 ignore_rest_of_line ();
10867 input_line_pointer++;
10870 /* We call demand_copy_C_string to check if alias string is valid.
10871 There should be a closing `"' and no `\0' in the string. */
10872 alias = demand_copy_C_string (&len);
10875 ignore_rest_of_line ();
10879 /* Make a copy of name string. */
10880 len = strlen (name) + 1;
10881 obstack_grow (¬es, name, len);
10882 name = obstack_finish (¬es);
10887 ahash = secalias_hash;
10888 nhash = secalias_name_hash;
10893 ahash = alias_hash;
10894 nhash = alias_name_hash;
10897 /* Check if alias has been used before. */
10898 h = (struct alias *) hash_find (ahash, alias);
10901 if (strcmp (h->name, name))
10902 as_bad (_("`%s' is already the alias of %s `%s'"),
10903 alias, kind, h->name);
10907 /* Check if name already has an alias. */
10908 a = (const char *) hash_find (nhash, name);
10911 if (strcmp (a, alias))
10912 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
10916 h = (struct alias *) xmalloc (sizeof (struct alias));
10917 as_where (&h->file, &h->line);
10920 error_string = hash_jam (ahash, alias, (PTR) h);
10923 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
10924 alias, kind, error_string);
10928 error_string = hash_jam (nhash, name, (PTR) alias);
10931 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
10932 alias, kind, error_string);
10934 obstack_free (¬es, name);
10935 obstack_free (¬es, alias);
10938 demand_empty_rest_of_line ();
10941 /* It renames the original symbol name to its alias. */
10943 do_alias (const char *alias, PTR value)
10945 struct alias *h = (struct alias *) value;
10946 symbolS *sym = symbol_find (h->name);
10949 as_warn_where (h->file, h->line,
10950 _("symbol `%s' aliased to `%s' is not used"),
10953 S_SET_NAME (sym, (char *) alias);
10956 /* Called from write_object_file. */
10958 ia64_adjust_symtab (void)
10960 hash_traverse (alias_hash, do_alias);
10963 /* It renames the original section name to its alias. */
10965 do_secalias (const char *alias, PTR value)
10967 struct alias *h = (struct alias *) value;
10968 segT sec = bfd_get_section_by_name (stdoutput, h->name);
10971 as_warn_where (h->file, h->line,
10972 _("section `%s' aliased to `%s' is not used"),
10978 /* Called from write_object_file. */
10980 ia64_frob_file (void)
10982 hash_traverse (secalias_hash, do_secalias);