1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
35 - labels are wrong if automatic alignment is introduced
36 (e.g., checkout the second real10 definition in test-data.s)
38 <reg>.safe_across_calls and any other DV-related directives I don't
39 have documentation for.
40 verify mod-sched-brs reads/writes are checked/marked (and other
46 #include "safe-ctype.h"
47 #include "dwarf2dbg.h"
50 #include "opcode/ia64.h"
54 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
55 #define MIN(a,b) ((a) < (b) ? (a) : (b))
58 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
59 #define CURR_SLOT md.slot[md.curr_slot]
61 #define O_pseudo_fixup (O_max + 1)
65 /* IA-64 ABI section pseudo-ops. */
66 SPECIAL_SECTION_BSS = 0,
68 SPECIAL_SECTION_SDATA,
69 SPECIAL_SECTION_RODATA,
70 SPECIAL_SECTION_COMMENT,
71 SPECIAL_SECTION_UNWIND,
72 SPECIAL_SECTION_UNWIND_INFO,
73 /* HPUX specific section pseudo-ops. */
74 SPECIAL_SECTION_INIT_ARRAY,
75 SPECIAL_SECTION_FINI_ARRAY,
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 /* Characters which always start a comment. */
159 const char comment_chars[] = "";
161 /* Characters which start a comment at the beginning of a line. */
162 const char line_comment_chars[] = "#";
164 /* Characters which may be used to separate multiple commands on a
166 const char line_separator_chars[] = ";";
168 /* Characters which are used to indicate an exponent in a floating
170 const char EXP_CHARS[] = "eE";
172 /* Characters which mean that a number is a floating point constant,
174 const char FLT_CHARS[] = "rRsSfFdDxXpP";
176 /* ia64-specific option processing: */
178 const char *md_shortopts = "m:N:x::";
180 struct option md_longopts[] =
182 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
183 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
184 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
185 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
188 size_t md_longopts_size = sizeof (md_longopts);
192 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
193 struct hash_control *reg_hash; /* register name hash table */
194 struct hash_control *dynreg_hash; /* dynamic register hash table */
195 struct hash_control *const_hash; /* constant hash table */
196 struct hash_control *entry_hash; /* code entry hint hash table */
198 symbolS *regsym[REG_NUM];
200 /* If X_op is != O_absent, the registername for the instruction's
201 qualifying predicate. If NULL, p0 is assumed for instructions
202 that are predicatable. */
209 explicit_mode : 1, /* which mode we're in */
210 default_explicit_mode : 1, /* which mode is the default */
211 mode_explicitly_set : 1, /* was the current mode explicitly set? */
213 keep_pending_output : 1;
215 /* Each bundle consists of up to three instructions. We keep
216 track of four most recent instructions so we can correctly set
217 the end_of_insn_group for the last instruction in a bundle. */
219 int num_slots_in_use;
223 end_of_insn_group : 1,
224 manual_bundling_on : 1,
225 manual_bundling_off : 1;
226 signed char user_template; /* user-selected template, if any */
227 unsigned char qp_regno; /* qualifying predicate */
228 /* This duplicates a good fraction of "struct fix" but we
229 can't use a "struct fix" instead since we can't call
230 fix_new_exp() until we know the address of the instruction. */
234 bfd_reloc_code_real_type code;
235 enum ia64_opnd opnd; /* type of operand in need of fix */
236 unsigned int is_pcrel : 1; /* is operand pc-relative? */
237 expressionS expr; /* the value to be inserted */
239 fixup[2]; /* at most two fixups per insn */
240 struct ia64_opcode *idesc;
241 struct label_fix *label_fixups;
242 struct label_fix *tag_fixups;
243 struct unw_rec_list *unwind_record; /* Unwind directive. */
246 unsigned int src_line;
247 struct dwarf2_line_info debug_line;
255 struct dynreg *next; /* next dynamic register */
257 unsigned short base; /* the base register number */
258 unsigned short num_regs; /* # of registers in this set */
260 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
262 flagword flags; /* ELF-header flags */
265 unsigned hint:1; /* is this hint currently valid? */
266 bfd_vma offset; /* mem.offset offset */
267 bfd_vma base; /* mem.offset base */
270 int path; /* number of alt. entry points seen */
271 const char **entry_labels; /* labels of all alternate paths in
272 the current DV-checking block. */
273 int maxpaths; /* size currently allocated for
275 /* Support for hardware errata workarounds. */
277 /* Record data about the last three insn groups. */
280 /* B-step workaround.
281 For each predicate register, this is set if the corresponding insn
282 group conditionally sets this register with one of the affected
285 /* B-step workaround.
286 For each general register, this is set if the corresponding insn
287 a) is conditional one one of the predicate registers for which
288 P_REG_SET is 1 in the corresponding entry of the previous group,
289 b) sets this general register with one of the affected
291 int g_reg_set_conditionally[128];
295 int pointer_size; /* size in bytes of a pointer */
296 int pointer_size_shift; /* shift size of a pointer for alignment */
300 /* application registers: */
306 #define AR_BSPSTORE 18
321 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
322 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
323 {"ar.rsc", 16}, {"ar.bsp", 17},
324 {"ar.bspstore", 18}, {"ar.rnat", 19},
325 {"ar.fcr", 21}, {"ar.eflag", 24},
326 {"ar.csd", 25}, {"ar.ssd", 26},
327 {"ar.cflg", 27}, {"ar.fsr", 28},
328 {"ar.fir", 29}, {"ar.fdr", 30},
329 {"ar.ccv", 32}, {"ar.unat", 36},
330 {"ar.fpsr", 40}, {"ar.itc", 44},
331 {"ar.pfs", 64}, {"ar.lc", 65},
352 /* control registers: */
394 static const struct const_desc
401 /* PSR constant masks: */
404 {"psr.be", ((valueT) 1) << 1},
405 {"psr.up", ((valueT) 1) << 2},
406 {"psr.ac", ((valueT) 1) << 3},
407 {"psr.mfl", ((valueT) 1) << 4},
408 {"psr.mfh", ((valueT) 1) << 5},
410 {"psr.ic", ((valueT) 1) << 13},
411 {"psr.i", ((valueT) 1) << 14},
412 {"psr.pk", ((valueT) 1) << 15},
414 {"psr.dt", ((valueT) 1) << 17},
415 {"psr.dfl", ((valueT) 1) << 18},
416 {"psr.dfh", ((valueT) 1) << 19},
417 {"psr.sp", ((valueT) 1) << 20},
418 {"psr.pp", ((valueT) 1) << 21},
419 {"psr.di", ((valueT) 1) << 22},
420 {"psr.si", ((valueT) 1) << 23},
421 {"psr.db", ((valueT) 1) << 24},
422 {"psr.lp", ((valueT) 1) << 25},
423 {"psr.tb", ((valueT) 1) << 26},
424 {"psr.rt", ((valueT) 1) << 27},
425 /* 28-31: reserved */
426 /* 32-33: cpl (current privilege level) */
427 {"psr.is", ((valueT) 1) << 34},
428 {"psr.mc", ((valueT) 1) << 35},
429 {"psr.it", ((valueT) 1) << 36},
430 {"psr.id", ((valueT) 1) << 37},
431 {"psr.da", ((valueT) 1) << 38},
432 {"psr.dd", ((valueT) 1) << 39},
433 {"psr.ss", ((valueT) 1) << 40},
434 /* 41-42: ri (restart instruction) */
435 {"psr.ed", ((valueT) 1) << 43},
436 {"psr.bn", ((valueT) 1) << 44},
439 /* indirect register-sets/memory: */
448 { "CPUID", IND_CPUID },
449 { "cpuid", IND_CPUID },
461 /* Pseudo functions used to indicate relocation types (these functions
462 start with an at sign (@). */
484 /* reloc pseudo functions (these must come first!): */
485 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
486 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
487 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
488 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
489 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
490 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
491 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
492 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
493 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
494 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
495 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
496 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
497 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
498 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
499 { "", 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
500 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
502 /* mbtype4 constants: */
503 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
504 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
505 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
506 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
507 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
509 /* fclass constants: */
510 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
511 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
512 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
513 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
514 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
515 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
516 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
517 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
518 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
520 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
522 /* unwind-related constants: */
523 { "svr4", PSEUDO_FUNC_CONST, { 0 } },
524 { "hpux", PSEUDO_FUNC_CONST, { 1 } },
525 { "nt", PSEUDO_FUNC_CONST, { 2 } },
527 /* unwind-related registers: */
528 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
531 /* 41-bit nop opcodes (one per unit): */
532 static const bfd_vma nop[IA64_NUM_UNITS] =
534 0x0000000000LL, /* NIL => break 0 */
535 0x0008000000LL, /* I-unit nop */
536 0x0008000000LL, /* M-unit nop */
537 0x4000000000LL, /* B-unit nop */
538 0x0008000000LL, /* F-unit nop */
539 0x0008000000LL, /* L-"unit" nop */
540 0x0008000000LL, /* X-unit nop */
543 /* Can't be `const' as it's passed to input routines (which have the
544 habit of setting temporary sentinels. */
545 static char special_section_name[][20] =
547 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
548 {".IA_64.unwind"}, {".IA_64.unwind_info"},
549 {".init_array"}, {".fini_array"}
552 static char *special_linkonce_name[] =
554 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
557 /* The best template for a particular sequence of up to three
559 #define N IA64_NUM_TYPES
560 static unsigned char best_template[N][N][N];
563 /* Resource dependencies currently in effect */
565 int depind; /* dependency index */
566 const struct ia64_dependency *dependency; /* actual dependency */
567 unsigned specific:1, /* is this a specific bit/regno? */
568 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
569 int index; /* specific regno/bit within dependency */
570 int note; /* optional qualifying note (0 if none) */
574 int insn_srlz; /* current insn serialization state */
575 int data_srlz; /* current data serialization state */
576 int qp_regno; /* qualifying predicate for this usage */
577 char *file; /* what file marked this dependency */
578 unsigned int line; /* what line marked this dependency */
579 struct mem_offset mem_offset; /* optional memory offset hint */
580 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
581 int path; /* corresponding code entry index */
583 static int regdepslen = 0;
584 static int regdepstotlen = 0;
585 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
586 static const char *dv_sem[] = { "none", "implied", "impliedf",
587 "data", "instr", "specific", "stop", "other" };
588 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
590 /* Current state of PR mutexation */
591 static struct qpmutex {
594 } *qp_mutexes = NULL; /* QP mutex bitmasks */
595 static int qp_mutexeslen = 0;
596 static int qp_mutexestotlen = 0;
597 static valueT qp_safe_across_calls = 0;
599 /* Current state of PR implications */
600 static struct qp_imply {
603 unsigned p2_branched:1;
605 } *qp_implies = NULL;
606 static int qp_implieslen = 0;
607 static int qp_impliestotlen = 0;
609 /* Keep track of static GR values so that indirect register usage can
610 sometimes be tracked. */
615 } gr_values[128] = {{ 1, 0, 0 }};
617 /* These are the routines required to output the various types of
620 /* A slot_number is a frag address plus the slot index (0-2). We use the
621 frag address here so that if there is a section switch in the middle of
622 a function, then instructions emitted to a different section are not
623 counted. Since there may be more than one frag for a function, this
624 means we also need to keep track of which frag this address belongs to
625 so we can compute inter-frag distances. This also nicely solves the
626 problem with nops emitted for align directives, which can't easily be
627 counted, but can easily be derived from frag sizes. */
629 typedef struct unw_rec_list {
631 unsigned long slot_number;
633 struct unw_rec_list *next;
636 #define SLOT_NUM_NOT_SET (unsigned)-1
638 /* Linked list of saved prologue counts. A very poor
639 implementation of a map from label numbers to prologue counts. */
640 typedef struct label_prologue_count
642 struct label_prologue_count *next;
643 unsigned long label_number;
644 unsigned int prologue_count;
645 } label_prologue_count;
649 unsigned long next_slot_number;
650 fragS *next_slot_frag;
652 /* Maintain a list of unwind entries for the current function. */
656 /* Any unwind entires that should be attached to the current slot
657 that an insn is being constructed for. */
658 unw_rec_list *current_entry;
660 /* These are used to create the unwind table entry for this function. */
663 symbolS *info; /* pointer to unwind info */
664 symbolS *personality_routine;
666 subsegT saved_text_subseg;
667 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
669 /* TRUE if processing unwind directives in a prologue region. */
672 unsigned int prologue_count; /* number of .prologues seen so far */
673 /* Prologue counts at previous .label_state directives. */
674 struct label_prologue_count * saved_prologue_counts;
677 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
679 /* Forward delarations: */
680 static int ar_is_in_integer_unit PARAMS ((int regnum));
681 static void set_section PARAMS ((char *name));
682 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
683 unsigned int, unsigned int));
684 static void dot_radix PARAMS ((int));
685 static void dot_special_section PARAMS ((int));
686 static void dot_proc PARAMS ((int));
687 static void dot_fframe PARAMS ((int));
688 static void dot_vframe PARAMS ((int));
689 static void dot_vframesp PARAMS ((int));
690 static void dot_vframepsp PARAMS ((int));
691 static void dot_save PARAMS ((int));
692 static void dot_restore PARAMS ((int));
693 static void dot_restorereg PARAMS ((int));
694 static void dot_restorereg_p PARAMS ((int));
695 static void dot_handlerdata PARAMS ((int));
696 static void dot_unwentry PARAMS ((int));
697 static void dot_altrp PARAMS ((int));
698 static void dot_savemem PARAMS ((int));
699 static void dot_saveg PARAMS ((int));
700 static void dot_savef PARAMS ((int));
701 static void dot_saveb PARAMS ((int));
702 static void dot_savegf PARAMS ((int));
703 static void dot_spill PARAMS ((int));
704 static void dot_spillreg PARAMS ((int));
705 static void dot_spillmem PARAMS ((int));
706 static void dot_spillreg_p PARAMS ((int));
707 static void dot_spillmem_p PARAMS ((int));
708 static void dot_label_state PARAMS ((int));
709 static void dot_copy_state PARAMS ((int));
710 static void dot_unwabi PARAMS ((int));
711 static void dot_personality PARAMS ((int));
712 static void dot_body PARAMS ((int));
713 static void dot_prologue PARAMS ((int));
714 static void dot_endp PARAMS ((int));
715 static void dot_template PARAMS ((int));
716 static void dot_regstk PARAMS ((int));
717 static void dot_rot PARAMS ((int));
718 static void dot_byteorder PARAMS ((int));
719 static void dot_psr PARAMS ((int));
720 static void dot_alias PARAMS ((int));
721 static void dot_ln PARAMS ((int));
722 static char *parse_section_name PARAMS ((void));
723 static void dot_xdata PARAMS ((int));
724 static void stmt_float_cons PARAMS ((int));
725 static void stmt_cons_ua PARAMS ((int));
726 static void dot_xfloat_cons PARAMS ((int));
727 static void dot_xstringer PARAMS ((int));
728 static void dot_xdata_ua PARAMS ((int));
729 static void dot_xfloat_cons_ua PARAMS ((int));
730 static void print_prmask PARAMS ((valueT mask));
731 static void dot_pred_rel PARAMS ((int));
732 static void dot_reg_val PARAMS ((int));
733 static void dot_dv_mode PARAMS ((int));
734 static void dot_entry PARAMS ((int));
735 static void dot_mem_offset PARAMS ((int));
736 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
737 static symbolS *declare_register PARAMS ((const char *name, int regnum));
738 static void declare_register_set PARAMS ((const char *, int, int));
739 static unsigned int operand_width PARAMS ((enum ia64_opnd));
740 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
743 static int parse_operand PARAMS ((expressionS *e));
744 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
745 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
746 static void build_insn PARAMS ((struct slot *, bfd_vma *));
747 static void emit_one_bundle PARAMS ((void));
748 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
749 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
750 bfd_reloc_code_real_type r_type));
751 static void insn_group_break PARAMS ((int, int, int));
752 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
753 struct rsrc *, int depind, int path));
754 static void add_qp_mutex PARAMS((valueT mask));
755 static void add_qp_imply PARAMS((int p1, int p2));
756 static void clear_qp_branch_flag PARAMS((valueT mask));
757 static void clear_qp_mutex PARAMS((valueT mask));
758 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
759 static int has_suffix_p PARAMS((const char *, const char *));
760 static void clear_register_values PARAMS ((void));
761 static void print_dependency PARAMS ((const char *action, int depind));
762 static void instruction_serialization PARAMS ((void));
763 static void data_serialization PARAMS ((void));
764 static void remove_marked_resource PARAMS ((struct rsrc *));
765 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
766 static int is_taken_branch PARAMS ((struct ia64_opcode *));
767 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
768 static int depends_on PARAMS ((int, struct ia64_opcode *));
769 static int specify_resource PARAMS ((const struct ia64_dependency *,
770 struct ia64_opcode *, int, struct rsrc [], int, int));
771 static int check_dv PARAMS((struct ia64_opcode *idesc));
772 static void check_dependencies PARAMS((struct ia64_opcode *));
773 static void mark_resources PARAMS((struct ia64_opcode *));
774 static void update_dependencies PARAMS((struct ia64_opcode *));
775 static void note_register_values PARAMS((struct ia64_opcode *));
776 static int qp_mutex PARAMS ((int, int, int));
777 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
778 static void output_vbyte_mem PARAMS ((int, char *, char *));
779 static void count_output PARAMS ((int, char *, char *));
780 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
781 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
782 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
783 static void output_P1_format PARAMS ((vbyte_func, int));
784 static void output_P2_format PARAMS ((vbyte_func, int, int));
785 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
786 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
787 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
788 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
789 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
790 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
791 static void output_P9_format PARAMS ((vbyte_func, int, int));
792 static void output_P10_format PARAMS ((vbyte_func, int, int));
793 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
794 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
795 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
796 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
797 static char format_ab_reg PARAMS ((int, int));
798 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
800 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
801 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
803 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
804 static void free_list_records PARAMS ((unw_rec_list *));
805 static unw_rec_list *output_prologue PARAMS ((void));
806 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
807 static unw_rec_list *output_body PARAMS ((void));
808 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
809 static unw_rec_list *output_mem_stack_v PARAMS ((void));
810 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
811 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
812 static unw_rec_list *output_rp_when PARAMS ((void));
813 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
814 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
815 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
816 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
817 static unw_rec_list *output_pfs_when PARAMS ((void));
818 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
819 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
820 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
821 static unw_rec_list *output_preds_when PARAMS ((void));
822 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
823 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
824 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
825 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
826 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
827 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
828 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
829 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
830 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
831 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
832 static unw_rec_list *output_unat_when PARAMS ((void));
833 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
834 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
835 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
836 static unw_rec_list *output_lc_when PARAMS ((void));
837 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
838 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
839 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
840 static unw_rec_list *output_fpsr_when PARAMS ((void));
841 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
842 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
843 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
844 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
845 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
846 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
847 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
848 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
849 static unw_rec_list *output_bsp_when PARAMS ((void));
850 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
851 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
852 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
853 static unw_rec_list *output_bspstore_when PARAMS ((void));
854 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
855 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
856 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
857 static unw_rec_list *output_rnat_when PARAMS ((void));
858 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
859 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
860 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
861 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
862 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
863 static unw_rec_list *output_label_state PARAMS ((unsigned long));
864 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
865 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
866 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
867 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
869 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
871 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
873 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
874 unsigned int, unsigned int));
875 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
876 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
877 static int calc_record_size PARAMS ((unw_rec_list *));
878 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
879 static int count_bits PARAMS ((unsigned long));
880 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
881 unsigned long, fragS *));
882 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
883 static void fixup_unw_records PARAMS ((unw_rec_list *));
884 static int output_unw_records PARAMS ((unw_rec_list *, void **));
885 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
886 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
887 static int generate_unwind_image PARAMS ((const char *));
888 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
889 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
890 static void free_saved_prologue_counts PARAMS ((void));
892 /* Build the unwind section name by appending the (possibly stripped)
893 text section NAME to the unwind PREFIX. The resulting string
894 pointer is assigned to RESULT. The string is allocated on the
895 stack, so this must be a macro... */
896 #define make_unw_section_name(special, text_name, result) \
898 const char *_prefix = special_section_name[special]; \
899 const char *_suffix = text_name; \
900 size_t _prefix_len, _suffix_len; \
902 if (strncmp (text_name, ".gnu.linkonce.t.", \
903 sizeof (".gnu.linkonce.t.") - 1) == 0) \
905 _prefix = special_linkonce_name[special - SPECIAL_SECTION_UNWIND]; \
906 _suffix += sizeof (".gnu.linkonce.t.") - 1; \
908 _prefix_len = strlen (_prefix), _suffix_len = strlen (_suffix); \
909 _result = alloca (_prefix_len + _suffix_len + 1); \
910 memcpy (_result, _prefix, _prefix_len); \
911 memcpy (_result + _prefix_len, _suffix, _suffix_len); \
912 _result[_prefix_len + _suffix_len] = '\0'; \
917 /* Determine if application register REGNUM resides in the integer
918 unit (as opposed to the memory unit). */
920 ar_is_in_integer_unit (reg)
925 return (reg == 64 /* pfs */
926 || reg == 65 /* lc */
927 || reg == 66 /* ec */
928 /* ??? ias accepts and puts these in the integer unit. */
929 || (reg >= 112 && reg <= 127));
932 /* Switch to section NAME and create section if necessary. It's
933 rather ugly that we have to manipulate input_line_pointer but I
934 don't see any other way to accomplish the same thing without
935 changing obj-elf.c (which may be the Right Thing, in the end). */
940 char *saved_input_line_pointer;
942 saved_input_line_pointer = input_line_pointer;
943 input_line_pointer = name;
945 input_line_pointer = saved_input_line_pointer;
948 /* Map 's' to SHF_IA_64_SHORT. */
951 ia64_elf_section_letter (letter, ptr_msg)
956 return SHF_IA_64_SHORT;
958 *ptr_msg = _("Bad .section directive: want a,s,w,x,M,S,G,T in string");
962 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
965 ia64_elf_section_flags (flags, attr, type)
967 int attr, type ATTRIBUTE_UNUSED;
969 if (attr & SHF_IA_64_SHORT)
970 flags |= SEC_SMALL_DATA;
975 ia64_elf_section_type (str, len)
979 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
981 if (STREQ (ELF_STRING_ia64_unwind_info))
984 if (STREQ (ELF_STRING_ia64_unwind_info_once))
987 if (STREQ (ELF_STRING_ia64_unwind))
988 return SHT_IA_64_UNWIND;
990 if (STREQ (ELF_STRING_ia64_unwind_once))
991 return SHT_IA_64_UNWIND;
993 if (STREQ ("init_array"))
994 return SHT_INIT_ARRAY;
996 if (STREQ ("fini_array"))
997 return SHT_FINI_ARRAY;
1004 set_regstack (ins, locs, outs, rots)
1005 unsigned int ins, locs, outs, rots;
1007 /* Size of frame. */
1010 sof = ins + locs + outs;
1013 as_bad ("Size of frame exceeds maximum of 96 registers");
1018 as_warn ("Size of rotating registers exceeds frame size");
1021 md.in.base = REG_GR + 32;
1022 md.loc.base = md.in.base + ins;
1023 md.out.base = md.loc.base + locs;
1025 md.in.num_regs = ins;
1026 md.loc.num_regs = locs;
1027 md.out.num_regs = outs;
1028 md.rot.num_regs = rots;
1035 struct label_fix *lfix;
1037 subsegT saved_subseg;
1040 if (!md.last_text_seg)
1043 saved_seg = now_seg;
1044 saved_subseg = now_subseg;
1046 subseg_set (md.last_text_seg, 0);
1048 while (md.num_slots_in_use > 0)
1049 emit_one_bundle (); /* force out queued instructions */
1051 /* In case there are labels following the last instruction, resolve
1053 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1055 S_SET_VALUE (lfix->sym, frag_now_fix ());
1056 symbol_set_frag (lfix->sym, frag_now);
1058 CURR_SLOT.label_fixups = 0;
1059 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1061 S_SET_VALUE (lfix->sym, frag_now_fix ());
1062 symbol_set_frag (lfix->sym, frag_now);
1064 CURR_SLOT.tag_fixups = 0;
1066 /* In case there are unwind directives following the last instruction,
1067 resolve those now. We only handle body and prologue directives here.
1068 Give an error for others. */
1069 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1071 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
1072 || ptr->r.type == body)
1074 ptr->slot_number = (unsigned long) frag_more (0);
1075 ptr->slot_frag = frag_now;
1078 as_bad (_("Unwind directive not followed by an instruction."));
1080 unwind.current_entry = NULL;
1082 subseg_set (saved_seg, saved_subseg);
1084 if (md.qp.X_op == O_register)
1085 as_bad ("qualifying predicate not followed by instruction");
1089 ia64_do_align (nbytes)
1092 char *saved_input_line_pointer = input_line_pointer;
1094 input_line_pointer = "";
1095 s_align_bytes (nbytes);
1096 input_line_pointer = saved_input_line_pointer;
1100 ia64_cons_align (nbytes)
1105 char *saved_input_line_pointer = input_line_pointer;
1106 input_line_pointer = "";
1107 s_align_bytes (nbytes);
1108 input_line_pointer = saved_input_line_pointer;
1112 /* Output COUNT bytes to a memory location. */
1113 static unsigned char *vbyte_mem_ptr = NULL;
1116 output_vbyte_mem (count, ptr, comment)
1119 char *comment ATTRIBUTE_UNUSED;
1122 if (vbyte_mem_ptr == NULL)
1127 for (x = 0; x < count; x++)
1128 *(vbyte_mem_ptr++) = ptr[x];
1131 /* Count the number of bytes required for records. */
1132 static int vbyte_count = 0;
1134 count_output (count, ptr, comment)
1136 char *ptr ATTRIBUTE_UNUSED;
1137 char *comment ATTRIBUTE_UNUSED;
1139 vbyte_count += count;
1143 output_R1_format (f, rtype, rlen)
1145 unw_record_type rtype;
1152 output_R3_format (f, rtype, rlen);
1158 else if (rtype != prologue)
1159 as_bad ("record type is not valid");
1161 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1162 (*f) (1, &byte, NULL);
1166 output_R2_format (f, mask, grsave, rlen)
1173 mask = (mask & 0x0f);
1174 grsave = (grsave & 0x7f);
1176 bytes[0] = (UNW_R2 | (mask >> 1));
1177 bytes[1] = (((mask & 0x01) << 7) | grsave);
1178 count += output_leb128 (bytes + 2, rlen, 0);
1179 (*f) (count, bytes, NULL);
1183 output_R3_format (f, rtype, rlen)
1185 unw_record_type rtype;
1192 output_R1_format (f, rtype, rlen);
1198 else if (rtype != prologue)
1199 as_bad ("record type is not valid");
1200 bytes[0] = (UNW_R3 | r);
1201 count = output_leb128 (bytes + 1, rlen, 0);
1202 (*f) (count + 1, bytes, NULL);
1206 output_P1_format (f, brmask)
1211 byte = UNW_P1 | (brmask & 0x1f);
1212 (*f) (1, &byte, NULL);
1216 output_P2_format (f, brmask, gr)
1222 brmask = (brmask & 0x1f);
1223 bytes[0] = UNW_P2 | (brmask >> 1);
1224 bytes[1] = (((brmask & 1) << 7) | gr);
1225 (*f) (2, bytes, NULL);
1229 output_P3_format (f, rtype, reg)
1231 unw_record_type rtype;
1276 as_bad ("Invalid record type for P3 format.");
1278 bytes[0] = (UNW_P3 | (r >> 1));
1279 bytes[1] = (((r & 1) << 7) | reg);
1280 (*f) (2, bytes, NULL);
1284 output_P4_format (f, imask, imask_size)
1286 unsigned char *imask;
1287 unsigned long imask_size;
1290 (*f) (imask_size, imask, NULL);
1294 output_P5_format (f, grmask, frmask)
1297 unsigned long frmask;
1300 grmask = (grmask & 0x0f);
1303 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1304 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1305 bytes[3] = (frmask & 0x000000ff);
1306 (*f) (4, bytes, NULL);
1310 output_P6_format (f, rtype, rmask)
1312 unw_record_type rtype;
1318 if (rtype == gr_mem)
1320 else if (rtype != fr_mem)
1321 as_bad ("Invalid record type for format P6");
1322 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1323 (*f) (1, &byte, NULL);
1327 output_P7_format (f, rtype, w1, w2)
1329 unw_record_type rtype;
1336 count += output_leb128 (bytes + 1, w1, 0);
1341 count += output_leb128 (bytes + count, w2 >> 4, 0);
1391 bytes[0] = (UNW_P7 | r);
1392 (*f) (count, bytes, NULL);
1396 output_P8_format (f, rtype, t)
1398 unw_record_type rtype;
1437 case bspstore_psprel:
1440 case bspstore_sprel:
1452 case priunat_when_gr:
1455 case priunat_psprel:
1461 case priunat_when_mem:
1468 count += output_leb128 (bytes + 2, t, 0);
1469 (*f) (count, bytes, NULL);
1473 output_P9_format (f, grmask, gr)
1480 bytes[1] = (grmask & 0x0f);
1481 bytes[2] = (gr & 0x7f);
1482 (*f) (3, bytes, NULL);
1486 output_P10_format (f, abi, context)
1493 bytes[1] = (abi & 0xff);
1494 bytes[2] = (context & 0xff);
1495 (*f) (3, bytes, NULL);
1499 output_B1_format (f, rtype, label)
1501 unw_record_type rtype;
1502 unsigned long label;
1508 output_B4_format (f, rtype, label);
1511 if (rtype == copy_state)
1513 else if (rtype != label_state)
1514 as_bad ("Invalid record type for format B1");
1516 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1517 (*f) (1, &byte, NULL);
1521 output_B2_format (f, ecount, t)
1523 unsigned long ecount;
1530 output_B3_format (f, ecount, t);
1533 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1534 count += output_leb128 (bytes + 1, t, 0);
1535 (*f) (count, bytes, NULL);
1539 output_B3_format (f, ecount, t)
1541 unsigned long ecount;
1548 output_B2_format (f, ecount, t);
1552 count += output_leb128 (bytes + 1, t, 0);
1553 count += output_leb128 (bytes + count, ecount, 0);
1554 (*f) (count, bytes, NULL);
1558 output_B4_format (f, rtype, label)
1560 unw_record_type rtype;
1561 unsigned long label;
1568 output_B1_format (f, rtype, label);
1572 if (rtype == copy_state)
1574 else if (rtype != label_state)
1575 as_bad ("Invalid record type for format B1");
1577 bytes[0] = (UNW_B4 | (r << 3));
1578 count += output_leb128 (bytes + 1, label, 0);
1579 (*f) (count, bytes, NULL);
1583 format_ab_reg (ab, reg)
1590 ret = (ab << 5) | reg;
1595 output_X1_format (f, rtype, ab, reg, t, w1)
1597 unw_record_type rtype;
1607 if (rtype == spill_sprel)
1609 else if (rtype != spill_psprel)
1610 as_bad ("Invalid record type for format X1");
1611 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1612 count += output_leb128 (bytes + 2, t, 0);
1613 count += output_leb128 (bytes + count, w1, 0);
1614 (*f) (count, bytes, NULL);
1618 output_X2_format (f, ab, reg, x, y, treg, t)
1627 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1628 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1629 count += output_leb128 (bytes + 3, t, 0);
1630 (*f) (count, bytes, NULL);
1634 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1636 unw_record_type rtype;
1647 if (rtype == spill_sprel_p)
1649 else if (rtype != spill_psprel_p)
1650 as_bad ("Invalid record type for format X3");
1651 bytes[1] = ((r << 7) | (qp & 0x3f));
1652 bytes[2] = format_ab_reg (ab, reg);
1653 count += output_leb128 (bytes + 3, t, 0);
1654 count += output_leb128 (bytes + count, w1, 0);
1655 (*f) (count, bytes, NULL);
1659 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1669 bytes[1] = (qp & 0x3f);
1670 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1671 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1672 count += output_leb128 (bytes + 4, t, 0);
1673 (*f) (count, bytes, NULL);
1676 /* This function allocates a record list structure, and initializes fields. */
1678 static unw_rec_list *
1679 alloc_record (unw_record_type t)
1682 ptr = xmalloc (sizeof (*ptr));
1684 ptr->slot_number = SLOT_NUM_NOT_SET;
1689 /* This function frees an entire list of record structures. */
1692 free_list_records (unw_rec_list *first)
1695 for (ptr = first; ptr != NULL;)
1697 unw_rec_list *tmp = ptr;
1699 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1700 && tmp->r.record.r.mask.i)
1701 free (tmp->r.record.r.mask.i);
1708 static unw_rec_list *
1711 unw_rec_list *ptr = alloc_record (prologue);
1712 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1716 static unw_rec_list *
1717 output_prologue_gr (saved_mask, reg)
1718 unsigned int saved_mask;
1721 unw_rec_list *ptr = alloc_record (prologue_gr);
1722 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1723 ptr->r.record.r.grmask = saved_mask;
1724 ptr->r.record.r.grsave = reg;
1728 static unw_rec_list *
1731 unw_rec_list *ptr = alloc_record (body);
1735 static unw_rec_list *
1736 output_mem_stack_f (size)
1739 unw_rec_list *ptr = alloc_record (mem_stack_f);
1740 ptr->r.record.p.size = size;
1744 static unw_rec_list *
1745 output_mem_stack_v ()
1747 unw_rec_list *ptr = alloc_record (mem_stack_v);
1751 static unw_rec_list *
1755 unw_rec_list *ptr = alloc_record (psp_gr);
1756 ptr->r.record.p.gr = gr;
1760 static unw_rec_list *
1761 output_psp_sprel (offset)
1762 unsigned int offset;
1764 unw_rec_list *ptr = alloc_record (psp_sprel);
1765 ptr->r.record.p.spoff = offset / 4;
1769 static unw_rec_list *
1772 unw_rec_list *ptr = alloc_record (rp_when);
1776 static unw_rec_list *
1780 unw_rec_list *ptr = alloc_record (rp_gr);
1781 ptr->r.record.p.gr = gr;
1785 static unw_rec_list *
1789 unw_rec_list *ptr = alloc_record (rp_br);
1790 ptr->r.record.p.br = br;
1794 static unw_rec_list *
1795 output_rp_psprel (offset)
1796 unsigned int offset;
1798 unw_rec_list *ptr = alloc_record (rp_psprel);
1799 ptr->r.record.p.pspoff = offset / 4;
1803 static unw_rec_list *
1804 output_rp_sprel (offset)
1805 unsigned int offset;
1807 unw_rec_list *ptr = alloc_record (rp_sprel);
1808 ptr->r.record.p.spoff = offset / 4;
1812 static unw_rec_list *
1815 unw_rec_list *ptr = alloc_record (pfs_when);
1819 static unw_rec_list *
1823 unw_rec_list *ptr = alloc_record (pfs_gr);
1824 ptr->r.record.p.gr = gr;
1828 static unw_rec_list *
1829 output_pfs_psprel (offset)
1830 unsigned int offset;
1832 unw_rec_list *ptr = alloc_record (pfs_psprel);
1833 ptr->r.record.p.pspoff = offset / 4;
1837 static unw_rec_list *
1838 output_pfs_sprel (offset)
1839 unsigned int offset;
1841 unw_rec_list *ptr = alloc_record (pfs_sprel);
1842 ptr->r.record.p.spoff = offset / 4;
1846 static unw_rec_list *
1847 output_preds_when ()
1849 unw_rec_list *ptr = alloc_record (preds_when);
1853 static unw_rec_list *
1854 output_preds_gr (gr)
1857 unw_rec_list *ptr = alloc_record (preds_gr);
1858 ptr->r.record.p.gr = gr;
1862 static unw_rec_list *
1863 output_preds_psprel (offset)
1864 unsigned int offset;
1866 unw_rec_list *ptr = alloc_record (preds_psprel);
1867 ptr->r.record.p.pspoff = offset / 4;
1871 static unw_rec_list *
1872 output_preds_sprel (offset)
1873 unsigned int offset;
1875 unw_rec_list *ptr = alloc_record (preds_sprel);
1876 ptr->r.record.p.spoff = offset / 4;
1880 static unw_rec_list *
1881 output_fr_mem (mask)
1884 unw_rec_list *ptr = alloc_record (fr_mem);
1885 ptr->r.record.p.rmask = mask;
1889 static unw_rec_list *
1890 output_frgr_mem (gr_mask, fr_mask)
1891 unsigned int gr_mask;
1892 unsigned int fr_mask;
1894 unw_rec_list *ptr = alloc_record (frgr_mem);
1895 ptr->r.record.p.grmask = gr_mask;
1896 ptr->r.record.p.frmask = fr_mask;
1900 static unw_rec_list *
1901 output_gr_gr (mask, reg)
1905 unw_rec_list *ptr = alloc_record (gr_gr);
1906 ptr->r.record.p.grmask = mask;
1907 ptr->r.record.p.gr = reg;
1911 static unw_rec_list *
1912 output_gr_mem (mask)
1915 unw_rec_list *ptr = alloc_record (gr_mem);
1916 ptr->r.record.p.rmask = mask;
1920 static unw_rec_list *
1921 output_br_mem (unsigned int mask)
1923 unw_rec_list *ptr = alloc_record (br_mem);
1924 ptr->r.record.p.brmask = mask;
1928 static unw_rec_list *
1929 output_br_gr (save_mask, reg)
1930 unsigned int save_mask;
1933 unw_rec_list *ptr = alloc_record (br_gr);
1934 ptr->r.record.p.brmask = save_mask;
1935 ptr->r.record.p.gr = reg;
1939 static unw_rec_list *
1940 output_spill_base (offset)
1941 unsigned int offset;
1943 unw_rec_list *ptr = alloc_record (spill_base);
1944 ptr->r.record.p.pspoff = offset / 4;
1948 static unw_rec_list *
1951 unw_rec_list *ptr = alloc_record (unat_when);
1955 static unw_rec_list *
1959 unw_rec_list *ptr = alloc_record (unat_gr);
1960 ptr->r.record.p.gr = gr;
1964 static unw_rec_list *
1965 output_unat_psprel (offset)
1966 unsigned int offset;
1968 unw_rec_list *ptr = alloc_record (unat_psprel);
1969 ptr->r.record.p.pspoff = offset / 4;
1973 static unw_rec_list *
1974 output_unat_sprel (offset)
1975 unsigned int offset;
1977 unw_rec_list *ptr = alloc_record (unat_sprel);
1978 ptr->r.record.p.spoff = offset / 4;
1982 static unw_rec_list *
1985 unw_rec_list *ptr = alloc_record (lc_when);
1989 static unw_rec_list *
1993 unw_rec_list *ptr = alloc_record (lc_gr);
1994 ptr->r.record.p.gr = gr;
1998 static unw_rec_list *
1999 output_lc_psprel (offset)
2000 unsigned int offset;
2002 unw_rec_list *ptr = alloc_record (lc_psprel);
2003 ptr->r.record.p.pspoff = offset / 4;
2007 static unw_rec_list *
2008 output_lc_sprel (offset)
2009 unsigned int offset;
2011 unw_rec_list *ptr = alloc_record (lc_sprel);
2012 ptr->r.record.p.spoff = offset / 4;
2016 static unw_rec_list *
2019 unw_rec_list *ptr = alloc_record (fpsr_when);
2023 static unw_rec_list *
2027 unw_rec_list *ptr = alloc_record (fpsr_gr);
2028 ptr->r.record.p.gr = gr;
2032 static unw_rec_list *
2033 output_fpsr_psprel (offset)
2034 unsigned int offset;
2036 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2037 ptr->r.record.p.pspoff = offset / 4;
2041 static unw_rec_list *
2042 output_fpsr_sprel (offset)
2043 unsigned int offset;
2045 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2046 ptr->r.record.p.spoff = offset / 4;
2050 static unw_rec_list *
2051 output_priunat_when_gr ()
2053 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2057 static unw_rec_list *
2058 output_priunat_when_mem ()
2060 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2064 static unw_rec_list *
2065 output_priunat_gr (gr)
2068 unw_rec_list *ptr = alloc_record (priunat_gr);
2069 ptr->r.record.p.gr = gr;
2073 static unw_rec_list *
2074 output_priunat_psprel (offset)
2075 unsigned int offset;
2077 unw_rec_list *ptr = alloc_record (priunat_psprel);
2078 ptr->r.record.p.pspoff = offset / 4;
2082 static unw_rec_list *
2083 output_priunat_sprel (offset)
2084 unsigned int offset;
2086 unw_rec_list *ptr = alloc_record (priunat_sprel);
2087 ptr->r.record.p.spoff = offset / 4;
2091 static unw_rec_list *
2094 unw_rec_list *ptr = alloc_record (bsp_when);
2098 static unw_rec_list *
2102 unw_rec_list *ptr = alloc_record (bsp_gr);
2103 ptr->r.record.p.gr = gr;
2107 static unw_rec_list *
2108 output_bsp_psprel (offset)
2109 unsigned int offset;
2111 unw_rec_list *ptr = alloc_record (bsp_psprel);
2112 ptr->r.record.p.pspoff = offset / 4;
2116 static unw_rec_list *
2117 output_bsp_sprel (offset)
2118 unsigned int offset;
2120 unw_rec_list *ptr = alloc_record (bsp_sprel);
2121 ptr->r.record.p.spoff = offset / 4;
2125 static unw_rec_list *
2126 output_bspstore_when ()
2128 unw_rec_list *ptr = alloc_record (bspstore_when);
2132 static unw_rec_list *
2133 output_bspstore_gr (gr)
2136 unw_rec_list *ptr = alloc_record (bspstore_gr);
2137 ptr->r.record.p.gr = gr;
2141 static unw_rec_list *
2142 output_bspstore_psprel (offset)
2143 unsigned int offset;
2145 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2146 ptr->r.record.p.pspoff = offset / 4;
2150 static unw_rec_list *
2151 output_bspstore_sprel (offset)
2152 unsigned int offset;
2154 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2155 ptr->r.record.p.spoff = offset / 4;
2159 static unw_rec_list *
2162 unw_rec_list *ptr = alloc_record (rnat_when);
2166 static unw_rec_list *
2170 unw_rec_list *ptr = alloc_record (rnat_gr);
2171 ptr->r.record.p.gr = gr;
2175 static unw_rec_list *
2176 output_rnat_psprel (offset)
2177 unsigned int offset;
2179 unw_rec_list *ptr = alloc_record (rnat_psprel);
2180 ptr->r.record.p.pspoff = offset / 4;
2184 static unw_rec_list *
2185 output_rnat_sprel (offset)
2186 unsigned int offset;
2188 unw_rec_list *ptr = alloc_record (rnat_sprel);
2189 ptr->r.record.p.spoff = offset / 4;
2193 static unw_rec_list *
2194 output_unwabi (abi, context)
2196 unsigned long context;
2198 unw_rec_list *ptr = alloc_record (unwabi);
2199 ptr->r.record.p.abi = abi;
2200 ptr->r.record.p.context = context;
2204 static unw_rec_list *
2205 output_epilogue (unsigned long ecount)
2207 unw_rec_list *ptr = alloc_record (epilogue);
2208 ptr->r.record.b.ecount = ecount;
2212 static unw_rec_list *
2213 output_label_state (unsigned long label)
2215 unw_rec_list *ptr = alloc_record (label_state);
2216 ptr->r.record.b.label = label;
2220 static unw_rec_list *
2221 output_copy_state (unsigned long label)
2223 unw_rec_list *ptr = alloc_record (copy_state);
2224 ptr->r.record.b.label = label;
2228 static unw_rec_list *
2229 output_spill_psprel (ab, reg, offset)
2232 unsigned int offset;
2234 unw_rec_list *ptr = alloc_record (spill_psprel);
2235 ptr->r.record.x.ab = ab;
2236 ptr->r.record.x.reg = reg;
2237 ptr->r.record.x.pspoff = offset / 4;
2241 static unw_rec_list *
2242 output_spill_sprel (ab, reg, offset)
2245 unsigned int offset;
2247 unw_rec_list *ptr = alloc_record (spill_sprel);
2248 ptr->r.record.x.ab = ab;
2249 ptr->r.record.x.reg = reg;
2250 ptr->r.record.x.spoff = offset / 4;
2254 static unw_rec_list *
2255 output_spill_psprel_p (ab, reg, offset, predicate)
2258 unsigned int offset;
2259 unsigned int predicate;
2261 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2262 ptr->r.record.x.ab = ab;
2263 ptr->r.record.x.reg = reg;
2264 ptr->r.record.x.pspoff = offset / 4;
2265 ptr->r.record.x.qp = predicate;
2269 static unw_rec_list *
2270 output_spill_sprel_p (ab, reg, offset, predicate)
2273 unsigned int offset;
2274 unsigned int predicate;
2276 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2277 ptr->r.record.x.ab = ab;
2278 ptr->r.record.x.reg = reg;
2279 ptr->r.record.x.spoff = offset / 4;
2280 ptr->r.record.x.qp = predicate;
2284 static unw_rec_list *
2285 output_spill_reg (ab, reg, targ_reg, xy)
2288 unsigned int targ_reg;
2291 unw_rec_list *ptr = alloc_record (spill_reg);
2292 ptr->r.record.x.ab = ab;
2293 ptr->r.record.x.reg = reg;
2294 ptr->r.record.x.treg = targ_reg;
2295 ptr->r.record.x.xy = xy;
2299 static unw_rec_list *
2300 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2303 unsigned int targ_reg;
2305 unsigned int predicate;
2307 unw_rec_list *ptr = alloc_record (spill_reg_p);
2308 ptr->r.record.x.ab = ab;
2309 ptr->r.record.x.reg = reg;
2310 ptr->r.record.x.treg = targ_reg;
2311 ptr->r.record.x.xy = xy;
2312 ptr->r.record.x.qp = predicate;
2316 /* Given a unw_rec_list process the correct format with the
2317 specified function. */
2320 process_one_record (ptr, f)
2324 unsigned long fr_mask, gr_mask;
2326 switch (ptr->r.type)
2332 /* These are taken care of by prologue/prologue_gr. */
2337 if (ptr->r.type == prologue_gr)
2338 output_R2_format (f, ptr->r.record.r.grmask,
2339 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2341 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2343 /* Output descriptor(s) for union of register spills (if any). */
2344 gr_mask = ptr->r.record.r.mask.gr_mem;
2345 fr_mask = ptr->r.record.r.mask.fr_mem;
2348 if ((fr_mask & ~0xfUL) == 0)
2349 output_P6_format (f, fr_mem, fr_mask);
2352 output_P5_format (f, gr_mask, fr_mask);
2357 output_P6_format (f, gr_mem, gr_mask);
2358 if (ptr->r.record.r.mask.br_mem)
2359 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2361 /* output imask descriptor if necessary: */
2362 if (ptr->r.record.r.mask.i)
2363 output_P4_format (f, ptr->r.record.r.mask.i,
2364 ptr->r.record.r.imask_size);
2368 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2372 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2373 ptr->r.record.p.size);
2386 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2389 output_P3_format (f, rp_br, ptr->r.record.p.br);
2392 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2400 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2409 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2419 case bspstore_sprel:
2421 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2424 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2427 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2430 as_bad ("spill_mask record unimplemented.");
2432 case priunat_when_gr:
2433 case priunat_when_mem:
2437 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2439 case priunat_psprel:
2441 case bspstore_psprel:
2443 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2446 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2449 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2453 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2456 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2457 ptr->r.record.x.reg, ptr->r.record.x.t,
2458 ptr->r.record.x.pspoff);
2461 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2462 ptr->r.record.x.reg, ptr->r.record.x.t,
2463 ptr->r.record.x.spoff);
2466 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2467 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2468 ptr->r.record.x.treg, ptr->r.record.x.t);
2470 case spill_psprel_p:
2471 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2472 ptr->r.record.x.ab, ptr->r.record.x.reg,
2473 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2476 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2477 ptr->r.record.x.ab, ptr->r.record.x.reg,
2478 ptr->r.record.x.t, ptr->r.record.x.spoff);
2481 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2482 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2483 ptr->r.record.x.xy, ptr->r.record.x.treg,
2487 as_bad ("record_type_not_valid");
2492 /* Given a unw_rec_list list, process all the records with
2493 the specified function. */
2495 process_unw_records (list, f)
2500 for (ptr = list; ptr; ptr = ptr->next)
2501 process_one_record (ptr, f);
2504 /* Determine the size of a record list in bytes. */
2506 calc_record_size (list)
2510 process_unw_records (list, count_output);
2514 /* Update IMASK bitmask to reflect the fact that one or more registers
2515 of type TYPE are saved starting at instruction with index T. If N
2516 bits are set in REGMASK, it is assumed that instructions T through
2517 T+N-1 save these registers.
2521 1: instruction saves next fp reg
2522 2: instruction saves next general reg
2523 3: instruction saves next branch reg */
2525 set_imask (region, regmask, t, type)
2526 unw_rec_list *region;
2527 unsigned long regmask;
2531 unsigned char *imask;
2532 unsigned long imask_size;
2536 imask = region->r.record.r.mask.i;
2537 imask_size = region->r.record.r.imask_size;
2540 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2541 imask = xmalloc (imask_size);
2542 memset (imask, 0, imask_size);
2544 region->r.record.r.imask_size = imask_size;
2545 region->r.record.r.mask.i = imask;
2549 pos = 2 * (3 - t % 4);
2552 if (i >= imask_size)
2554 as_bad ("Ignoring attempt to spill beyond end of region");
2558 imask[i] |= (type & 0x3) << pos;
2560 regmask &= (regmask - 1);
2571 count_bits (unsigned long mask)
2583 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2584 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2585 containing FIRST_ADDR. */
2588 slot_index (slot_addr, slot_frag, first_addr, first_frag)
2589 unsigned long slot_addr;
2591 unsigned long first_addr;
2594 unsigned long index = 0;
2596 /* First time we are called, the initial address and frag are invalid. */
2597 if (first_addr == 0)
2600 /* If the two addresses are in different frags, then we need to add in
2601 the remaining size of this frag, and then the entire size of intermediate
2603 while (slot_frag != first_frag)
2605 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2607 /* Add in the full size of the frag converted to instruction slots. */
2608 index += 3 * (first_frag->fr_fix >> 4);
2609 /* Subtract away the initial part before first_addr. */
2610 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2611 + ((first_addr & 0x3) - (start_addr & 0x3)));
2613 /* Move to the beginning of the next frag. */
2614 first_frag = first_frag->fr_next;
2615 first_addr = (unsigned long) &first_frag->fr_literal;
2618 /* Add in the used part of the last frag. */
2619 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2620 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2624 /* Optimize unwind record directives. */
2626 static unw_rec_list *
2627 optimize_unw_records (list)
2633 /* If the only unwind record is ".prologue" or ".prologue" followed
2634 by ".body", then we can optimize the unwind directives away. */
2635 if (list->r.type == prologue
2636 && (list->next == NULL
2637 || (list->next->r.type == body && list->next->next == NULL)))
2643 /* Given a complete record list, process any records which have
2644 unresolved fields, (ie length counts for a prologue). After
2645 this has been run, all neccessary information should be available
2646 within each record to generate an image. */
2649 fixup_unw_records (list)
2652 unw_rec_list *ptr, *region = 0;
2653 unsigned long first_addr = 0, rlen = 0, t;
2654 fragS *first_frag = 0;
2656 for (ptr = list; ptr; ptr = ptr->next)
2658 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2659 as_bad (" Insn slot not set in unwind record.");
2660 t = slot_index (ptr->slot_number, ptr->slot_frag,
2661 first_addr, first_frag);
2662 switch (ptr->r.type)
2669 int size, dir_len = 0;
2670 unsigned long last_addr;
2673 first_addr = ptr->slot_number;
2674 first_frag = ptr->slot_frag;
2675 ptr->slot_number = 0;
2676 /* Find either the next body/prologue start, or the end of
2677 the list, and determine the size of the region. */
2678 last_addr = unwind.next_slot_number;
2679 last_frag = unwind.next_slot_frag;
2680 for (last = ptr->next; last != NULL; last = last->next)
2681 if (last->r.type == prologue || last->r.type == prologue_gr
2682 || last->r.type == body)
2684 last_addr = last->slot_number;
2685 last_frag = last->slot_frag;
2688 else if (!last->next)
2690 /* In the absence of an explicit .body directive,
2691 the prologue ends after the last instruction
2692 covered by an unwind directive. */
2693 if (ptr->r.type != body)
2695 last_addr = last->slot_number;
2696 last_frag = last->slot_frag;
2697 switch (last->r.type)
2700 dir_len = (count_bits (last->r.record.p.frmask)
2701 + count_bits (last->r.record.p.grmask));
2705 dir_len += count_bits (last->r.record.p.rmask);
2709 dir_len += count_bits (last->r.record.p.brmask);
2712 dir_len += count_bits (last->r.record.p.grmask);
2721 size = (slot_index (last_addr, last_frag, first_addr, first_frag)
2723 rlen = ptr->r.record.r.rlen = size;
2724 if (ptr->r.type == body)
2725 /* End of region. */
2732 ptr->r.record.b.t = rlen - 1 - t;
2743 case priunat_when_gr:
2744 case priunat_when_mem:
2748 ptr->r.record.p.t = t;
2756 case spill_psprel_p:
2757 ptr->r.record.x.t = t;
2763 as_bad ("frgr_mem record before region record!\n");
2766 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2767 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2768 set_imask (region, ptr->r.record.p.frmask, t, 1);
2769 set_imask (region, ptr->r.record.p.grmask, t, 2);
2774 as_bad ("fr_mem record before region record!\n");
2777 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2778 set_imask (region, ptr->r.record.p.rmask, t, 1);
2783 as_bad ("gr_mem record before region record!\n");
2786 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2787 set_imask (region, ptr->r.record.p.rmask, t, 2);
2792 as_bad ("br_mem record before region record!\n");
2795 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2796 set_imask (region, ptr->r.record.p.brmask, t, 3);
2802 as_bad ("gr_gr record before region record!\n");
2805 set_imask (region, ptr->r.record.p.grmask, t, 2);
2810 as_bad ("br_gr record before region record!\n");
2813 set_imask (region, ptr->r.record.p.brmask, t, 3);
2822 /* Helper routine for output_unw_records. Emits the header for the unwind
2826 setup_unwind_header (int size, unsigned char **mem)
2831 /* pad to pointer-size boundry. */
2832 x = size % md.pointer_size;
2834 extra = md.pointer_size - x;
2836 /* Add 8 for the header + a pointer for the
2837 personality offset. */
2838 *mem = xmalloc (size + extra + 8 + md.pointer_size);
2840 /* Clear the padding area and personality. */
2841 memset (*mem + 8 + size, 0, extra + md.pointer_size);
2843 /* Initialize the header area. */
2844 if (unwind.personality_routine)
2846 if (md.flags & EF_IA_64_ABI64)
2847 flag_value = (bfd_vma) 3 << 32;
2849 /* 32-bit unwind info block. */
2850 flag_value = (bfd_vma) 0x1003 << 32;
2855 md_number_to_chars (*mem, (((bfd_vma) 1 << 48) /* Version. */
2856 | flag_value /* U & E handler flags. */
2857 | ((size + extra) / md.pointer_size)), /* Length. */
2863 /* Generate an unwind image from a record list. Returns the number of
2864 bytes in the resulting image. The memory image itselof is returned
2865 in the 'ptr' parameter. */
2867 output_unw_records (list, ptr)
2876 list = optimize_unw_records (list);
2877 fixup_unw_records (list);
2878 size = calc_record_size (list);
2880 if (size > 0 || unwind.force_unwind_entry)
2882 unwind.force_unwind_entry = 0;
2883 extra = setup_unwind_header (size, &mem);
2885 vbyte_mem_ptr = mem + 8;
2886 process_unw_records (list, output_vbyte_mem);
2890 size += extra + 8 + md.pointer_size;
2896 convert_expr_to_ab_reg (e, ab, regp)
2903 if (e->X_op != O_register)
2906 reg = e->X_add_number;
2907 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2910 *regp = reg - REG_GR;
2912 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2913 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2916 *regp = reg - REG_FR;
2918 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2921 *regp = reg - REG_BR;
2928 case REG_PR: *regp = 0; break;
2929 case REG_PSP: *regp = 1; break;
2930 case REG_PRIUNAT: *regp = 2; break;
2931 case REG_BR + 0: *regp = 3; break;
2932 case REG_AR + AR_BSP: *regp = 4; break;
2933 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2934 case REG_AR + AR_RNAT: *regp = 6; break;
2935 case REG_AR + AR_UNAT: *regp = 7; break;
2936 case REG_AR + AR_FPSR: *regp = 8; break;
2937 case REG_AR + AR_PFS: *regp = 9; break;
2938 case REG_AR + AR_LC: *regp = 10; break;
2948 convert_expr_to_xy_reg (e, xy, regp)
2955 if (e->X_op != O_register)
2958 reg = e->X_add_number;
2960 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2963 *regp = reg - REG_GR;
2965 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2968 *regp = reg - REG_FR;
2970 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2973 *regp = reg - REG_BR;
2982 int dummy ATTRIBUTE_UNUSED;
2987 radix = *input_line_pointer++;
2989 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
2991 as_bad ("Radix `%c' unsupported", *input_line_pointer);
2992 ignore_rest_of_line ();
2997 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
2999 dot_special_section (which)
3002 set_section ((char *) special_section_name[which]);
3006 add_unwind_entry (ptr)
3010 unwind.tail->next = ptr;
3015 /* The current entry can in fact be a chain of unwind entries. */
3016 if (unwind.current_entry == NULL)
3017 unwind.current_entry = ptr;
3022 int dummy ATTRIBUTE_UNUSED;
3028 if (e.X_op != O_constant)
3029 as_bad ("Operand to .fframe must be a constant");
3031 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3036 int dummy ATTRIBUTE_UNUSED;
3042 reg = e.X_add_number - REG_GR;
3043 if (e.X_op == O_register && reg < 128)
3045 add_unwind_entry (output_mem_stack_v ());
3046 if (! (unwind.prologue_mask & 2))
3047 add_unwind_entry (output_psp_gr (reg));
3050 as_bad ("First operand to .vframe must be a general register");
3054 dot_vframesp (dummy)
3055 int dummy ATTRIBUTE_UNUSED;
3060 if (e.X_op == O_constant)
3062 add_unwind_entry (output_mem_stack_v ());
3063 add_unwind_entry (output_psp_sprel (e.X_add_number));
3066 as_bad ("First operand to .vframesp must be a general register");
3070 dot_vframepsp (dummy)
3071 int dummy ATTRIBUTE_UNUSED;
3076 if (e.X_op == O_constant)
3078 add_unwind_entry (output_mem_stack_v ());
3079 add_unwind_entry (output_psp_sprel (e.X_add_number));
3082 as_bad ("First operand to .vframepsp must be a general register");
3087 int dummy ATTRIBUTE_UNUSED;
3093 sep = parse_operand (&e1);
3095 as_bad ("No second operand to .save");
3096 sep = parse_operand (&e2);
3098 reg1 = e1.X_add_number;
3099 reg2 = e2.X_add_number - REG_GR;
3101 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3102 if (e1.X_op == O_register)
3104 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3108 case REG_AR + AR_BSP:
3109 add_unwind_entry (output_bsp_when ());
3110 add_unwind_entry (output_bsp_gr (reg2));
3112 case REG_AR + AR_BSPSTORE:
3113 add_unwind_entry (output_bspstore_when ());
3114 add_unwind_entry (output_bspstore_gr (reg2));
3116 case REG_AR + AR_RNAT:
3117 add_unwind_entry (output_rnat_when ());
3118 add_unwind_entry (output_rnat_gr (reg2));
3120 case REG_AR + AR_UNAT:
3121 add_unwind_entry (output_unat_when ());
3122 add_unwind_entry (output_unat_gr (reg2));
3124 case REG_AR + AR_FPSR:
3125 add_unwind_entry (output_fpsr_when ());
3126 add_unwind_entry (output_fpsr_gr (reg2));
3128 case REG_AR + AR_PFS:
3129 add_unwind_entry (output_pfs_when ());
3130 if (! (unwind.prologue_mask & 4))
3131 add_unwind_entry (output_pfs_gr (reg2));
3133 case REG_AR + AR_LC:
3134 add_unwind_entry (output_lc_when ());
3135 add_unwind_entry (output_lc_gr (reg2));
3138 add_unwind_entry (output_rp_when ());
3139 if (! (unwind.prologue_mask & 8))
3140 add_unwind_entry (output_rp_gr (reg2));
3143 add_unwind_entry (output_preds_when ());
3144 if (! (unwind.prologue_mask & 1))
3145 add_unwind_entry (output_preds_gr (reg2));
3148 add_unwind_entry (output_priunat_when_gr ());
3149 add_unwind_entry (output_priunat_gr (reg2));
3152 as_bad ("First operand not a valid register");
3156 as_bad (" Second operand not a valid register");
3159 as_bad ("First operand not a register");
3164 int dummy ATTRIBUTE_UNUSED;
3167 unsigned long ecount; /* # of _additional_ regions to pop */
3170 sep = parse_operand (&e1);
3171 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3173 as_bad ("First operand to .restore must be stack pointer (sp)");
3179 parse_operand (&e2);
3180 if (e2.X_op != O_constant || e2.X_add_number < 0)
3182 as_bad ("Second operand to .restore must be a constant >= 0");
3185 ecount = e2.X_add_number;
3188 ecount = unwind.prologue_count - 1;
3190 if (ecount >= unwind.prologue_count)
3192 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3193 ecount + 1, unwind.prologue_count);
3197 add_unwind_entry (output_epilogue (ecount));
3199 if (ecount < unwind.prologue_count)
3200 unwind.prologue_count -= ecount + 1;
3202 unwind.prologue_count = 0;
3206 dot_restorereg (dummy)
3207 int dummy ATTRIBUTE_UNUSED;
3209 unsigned int ab, reg;
3214 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3216 as_bad ("First operand to .restorereg must be a preserved register");
3219 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3223 dot_restorereg_p (dummy)
3224 int dummy ATTRIBUTE_UNUSED;
3226 unsigned int qp, ab, reg;
3230 sep = parse_operand (&e1);
3233 as_bad ("No second operand to .restorereg.p");
3237 parse_operand (&e2);
3239 qp = e1.X_add_number - REG_P;
3240 if (e1.X_op != O_register || qp > 63)
3242 as_bad ("First operand to .restorereg.p must be a predicate");
3246 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3248 as_bad ("Second operand to .restorereg.p must be a preserved register");
3251 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3255 generate_unwind_image (text_name)
3256 const char *text_name;
3259 unsigned char *unw_rec;
3261 /* Force out pending instructions, to make sure all unwind records have
3262 a valid slot_number field. */
3263 ia64_flush_insns ();
3265 /* Generate the unwind record. */
3266 size = output_unw_records (unwind.list, (void **) &unw_rec);
3267 if (size % md.pointer_size != 0)
3268 as_bad ("Unwind record is not a multiple of %d bytes.", md.pointer_size);
3270 /* If there are unwind records, switch sections, and output the info. */
3273 unsigned char *where;
3276 bfd_reloc_code_real_type reloc;
3278 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3279 set_section (sec_name);
3280 bfd_set_section_flags (stdoutput, now_seg,
3281 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3283 /* Make sure the section has 4 byte alignment for ILP32 and
3284 8 byte alignment for LP64. */
3285 frag_align (md.pointer_size_shift, 0, 0);
3286 record_alignment (now_seg, md.pointer_size_shift);
3288 /* Set expression which points to start of unwind descriptor area. */
3289 unwind.info = expr_build_dot ();
3291 where = (unsigned char *) frag_more (size);
3293 /* Issue a label for this address, and keep track of it to put it
3294 in the unwind section. */
3296 /* Copy the information from the unwind record into this section. The
3297 data is already in the correct byte order. */
3298 memcpy (where, unw_rec, size);
3300 /* Add the personality address to the image. */
3301 if (unwind.personality_routine != 0)
3303 exp.X_op = O_symbol;
3304 exp.X_add_symbol = unwind.personality_routine;
3305 exp.X_add_number = 0;
3307 if (md.flags & EF_IA_64_BE)
3309 if (md.flags & EF_IA_64_ABI64)
3310 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3312 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3316 if (md.flags & EF_IA_64_ABI64)
3317 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3319 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3322 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3323 md.pointer_size, &exp, 0, reloc);
3324 unwind.personality_routine = 0;
3328 free_list_records (unwind.list);
3329 free_saved_prologue_counts ();
3330 unwind.list = unwind.tail = unwind.current_entry = NULL;
3336 dot_handlerdata (dummy)
3337 int dummy ATTRIBUTE_UNUSED;
3339 const char *text_name = segment_name (now_seg);
3341 /* If text section name starts with ".text" (which it should),
3342 strip this prefix off. */
3343 if (strcmp (text_name, ".text") == 0)
3346 unwind.force_unwind_entry = 1;
3348 /* Remember which segment we're in so we can switch back after .endp */
3349 unwind.saved_text_seg = now_seg;
3350 unwind.saved_text_subseg = now_subseg;
3352 /* Generate unwind info into unwind-info section and then leave that
3353 section as the currently active one so dataXX directives go into
3354 the language specific data area of the unwind info block. */
3355 generate_unwind_image (text_name);
3356 demand_empty_rest_of_line ();
3360 dot_unwentry (dummy)
3361 int dummy ATTRIBUTE_UNUSED;
3363 unwind.force_unwind_entry = 1;
3364 demand_empty_rest_of_line ();
3369 int dummy ATTRIBUTE_UNUSED;
3375 reg = e.X_add_number - REG_BR;
3376 if (e.X_op == O_register && reg < 8)
3377 add_unwind_entry (output_rp_br (reg));
3379 as_bad ("First operand not a valid branch register");
3383 dot_savemem (psprel)
3390 sep = parse_operand (&e1);
3392 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3393 sep = parse_operand (&e2);
3395 reg1 = e1.X_add_number;
3396 val = e2.X_add_number;
3398 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3399 if (e1.X_op == O_register)
3401 if (e2.X_op == O_constant)
3405 case REG_AR + AR_BSP:
3406 add_unwind_entry (output_bsp_when ());
3407 add_unwind_entry ((psprel
3409 : output_bsp_sprel) (val));
3411 case REG_AR + AR_BSPSTORE:
3412 add_unwind_entry (output_bspstore_when ());
3413 add_unwind_entry ((psprel
3414 ? output_bspstore_psprel
3415 : output_bspstore_sprel) (val));
3417 case REG_AR + AR_RNAT:
3418 add_unwind_entry (output_rnat_when ());
3419 add_unwind_entry ((psprel
3420 ? output_rnat_psprel
3421 : output_rnat_sprel) (val));
3423 case REG_AR + AR_UNAT:
3424 add_unwind_entry (output_unat_when ());
3425 add_unwind_entry ((psprel
3426 ? output_unat_psprel
3427 : output_unat_sprel) (val));
3429 case REG_AR + AR_FPSR:
3430 add_unwind_entry (output_fpsr_when ());
3431 add_unwind_entry ((psprel
3432 ? output_fpsr_psprel
3433 : output_fpsr_sprel) (val));
3435 case REG_AR + AR_PFS:
3436 add_unwind_entry (output_pfs_when ());
3437 add_unwind_entry ((psprel
3439 : output_pfs_sprel) (val));
3441 case REG_AR + AR_LC:
3442 add_unwind_entry (output_lc_when ());
3443 add_unwind_entry ((psprel
3445 : output_lc_sprel) (val));
3448 add_unwind_entry (output_rp_when ());
3449 add_unwind_entry ((psprel
3451 : output_rp_sprel) (val));
3454 add_unwind_entry (output_preds_when ());
3455 add_unwind_entry ((psprel
3456 ? output_preds_psprel
3457 : output_preds_sprel) (val));
3460 add_unwind_entry (output_priunat_when_mem ());
3461 add_unwind_entry ((psprel
3462 ? output_priunat_psprel
3463 : output_priunat_sprel) (val));
3466 as_bad ("First operand not a valid register");
3470 as_bad (" Second operand not a valid constant");
3473 as_bad ("First operand not a register");
3478 int dummy ATTRIBUTE_UNUSED;
3482 sep = parse_operand (&e1);
3484 parse_operand (&e2);
3486 if (e1.X_op != O_constant)
3487 as_bad ("First operand to .save.g must be a constant.");
3490 int grmask = e1.X_add_number;
3492 add_unwind_entry (output_gr_mem (grmask));
3495 int reg = e2.X_add_number - REG_GR;
3496 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3497 add_unwind_entry (output_gr_gr (grmask, reg));
3499 as_bad ("Second operand is an invalid register.");
3506 int dummy ATTRIBUTE_UNUSED;
3510 sep = parse_operand (&e1);
3512 if (e1.X_op != O_constant)
3513 as_bad ("Operand to .save.f must be a constant.");
3515 add_unwind_entry (output_fr_mem (e1.X_add_number));
3520 int dummy ATTRIBUTE_UNUSED;
3527 sep = parse_operand (&e1);
3528 if (e1.X_op != O_constant)
3530 as_bad ("First operand to .save.b must be a constant.");
3533 brmask = e1.X_add_number;
3537 sep = parse_operand (&e2);
3538 reg = e2.X_add_number - REG_GR;
3539 if (e2.X_op != O_register || reg > 127)
3541 as_bad ("Second operand to .save.b must be a general register.");
3544 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3547 add_unwind_entry (output_br_mem (brmask));
3549 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3550 ignore_rest_of_line ();
3555 int dummy ATTRIBUTE_UNUSED;
3559 sep = parse_operand (&e1);
3561 parse_operand (&e2);
3563 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3564 as_bad ("Both operands of .save.gf must be constants.");
3567 int grmask = e1.X_add_number;
3568 int frmask = e2.X_add_number;
3569 add_unwind_entry (output_frgr_mem (grmask, frmask));
3575 int dummy ATTRIBUTE_UNUSED;
3580 sep = parse_operand (&e);
3581 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3582 ignore_rest_of_line ();
3584 if (e.X_op != O_constant)
3585 as_bad ("Operand to .spill must be a constant");
3587 add_unwind_entry (output_spill_base (e.X_add_number));
3591 dot_spillreg (dummy)
3592 int dummy ATTRIBUTE_UNUSED;
3594 int sep, ab, xy, reg, treg;
3597 sep = parse_operand (&e1);
3600 as_bad ("No second operand to .spillreg");
3604 parse_operand (&e2);
3606 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3608 as_bad ("First operand to .spillreg must be a preserved register");
3612 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3614 as_bad ("Second operand to .spillreg must be a register");
3618 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3622 dot_spillmem (psprel)
3628 sep = parse_operand (&e1);
3631 as_bad ("Second operand missing");
3635 parse_operand (&e2);
3637 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3639 as_bad ("First operand to .spill%s must be a preserved register",
3640 psprel ? "psp" : "sp");
3644 if (e2.X_op != O_constant)
3646 as_bad ("Second operand to .spill%s must be a constant",
3647 psprel ? "psp" : "sp");
3652 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3654 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3658 dot_spillreg_p (dummy)
3659 int dummy ATTRIBUTE_UNUSED;
3661 int sep, ab, xy, reg, treg;
3662 expressionS e1, e2, e3;
3665 sep = parse_operand (&e1);
3668 as_bad ("No second and third operand to .spillreg.p");
3672 sep = parse_operand (&e2);
3675 as_bad ("No third operand to .spillreg.p");
3679 parse_operand (&e3);
3681 qp = e1.X_add_number - REG_P;
3683 if (e1.X_op != O_register || qp > 63)
3685 as_bad ("First operand to .spillreg.p must be a predicate");
3689 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3691 as_bad ("Second operand to .spillreg.p must be a preserved register");
3695 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3697 as_bad ("Third operand to .spillreg.p must be a register");
3701 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3705 dot_spillmem_p (psprel)
3708 expressionS e1, e2, e3;
3712 sep = parse_operand (&e1);
3715 as_bad ("Second operand missing");
3719 parse_operand (&e2);
3722 as_bad ("Second operand missing");
3726 parse_operand (&e3);
3728 qp = e1.X_add_number - REG_P;
3729 if (e1.X_op != O_register || qp > 63)
3731 as_bad ("First operand to .spill%s_p must be a predicate",
3732 psprel ? "psp" : "sp");
3736 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3738 as_bad ("Second operand to .spill%s_p must be a preserved register",
3739 psprel ? "psp" : "sp");
3743 if (e3.X_op != O_constant)
3745 as_bad ("Third operand to .spill%s_p must be a constant",
3746 psprel ? "psp" : "sp");
3751 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3753 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3757 get_saved_prologue_count (lbl)
3760 label_prologue_count *lpc = unwind.saved_prologue_counts;
3762 while (lpc != NULL && lpc->label_number != lbl)
3766 return lpc->prologue_count;
3768 as_bad ("Missing .label_state %ld", lbl);
3773 save_prologue_count (lbl, count)
3777 label_prologue_count *lpc = unwind.saved_prologue_counts;
3779 while (lpc != NULL && lpc->label_number != lbl)
3783 lpc->prologue_count = count;
3786 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3788 new_lpc->next = unwind.saved_prologue_counts;
3789 new_lpc->label_number = lbl;
3790 new_lpc->prologue_count = count;
3791 unwind.saved_prologue_counts = new_lpc;
3796 free_saved_prologue_counts ()
3798 label_prologue_count *lpc = unwind.saved_prologue_counts;
3799 label_prologue_count *next;
3808 unwind.saved_prologue_counts = NULL;
3812 dot_label_state (dummy)
3813 int dummy ATTRIBUTE_UNUSED;
3818 if (e.X_op != O_constant)
3820 as_bad ("Operand to .label_state must be a constant");
3823 add_unwind_entry (output_label_state (e.X_add_number));
3824 save_prologue_count (e.X_add_number, unwind.prologue_count);
3828 dot_copy_state (dummy)
3829 int dummy ATTRIBUTE_UNUSED;
3834 if (e.X_op != O_constant)
3836 as_bad ("Operand to .copy_state must be a constant");
3839 add_unwind_entry (output_copy_state (e.X_add_number));
3840 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3845 int dummy ATTRIBUTE_UNUSED;
3850 sep = parse_operand (&e1);
3853 as_bad ("Second operand to .unwabi missing");
3856 sep = parse_operand (&e2);
3857 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3858 ignore_rest_of_line ();
3860 if (e1.X_op != O_constant)
3862 as_bad ("First operand to .unwabi must be a constant");
3866 if (e2.X_op != O_constant)
3868 as_bad ("Second operand to .unwabi must be a constant");
3872 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3876 dot_personality (dummy)
3877 int dummy ATTRIBUTE_UNUSED;
3881 name = input_line_pointer;
3882 c = get_symbol_end ();
3883 p = input_line_pointer;
3884 unwind.personality_routine = symbol_find_or_make (name);
3885 unwind.force_unwind_entry = 1;
3888 demand_empty_rest_of_line ();
3893 int dummy ATTRIBUTE_UNUSED;
3898 unwind.proc_start = expr_build_dot ();
3899 /* Parse names of main and alternate entry points and mark them as
3900 function symbols: */
3904 name = input_line_pointer;
3905 c = get_symbol_end ();
3906 p = input_line_pointer;
3907 sym = symbol_find_or_make (name);
3908 if (unwind.proc_start == 0)
3910 unwind.proc_start = sym;
3912 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3915 if (*input_line_pointer != ',')
3917 ++input_line_pointer;
3919 demand_empty_rest_of_line ();
3922 unwind.prologue_count = 0;
3923 unwind.list = unwind.tail = unwind.current_entry = NULL;
3924 unwind.personality_routine = 0;
3929 int dummy ATTRIBUTE_UNUSED;
3931 unwind.prologue = 0;
3932 unwind.prologue_mask = 0;
3934 add_unwind_entry (output_body ());
3935 demand_empty_rest_of_line ();
3939 dot_prologue (dummy)
3940 int dummy ATTRIBUTE_UNUSED;
3943 int mask = 0, grsave = 0;
3945 if (!is_it_end_of_statement ())
3948 sep = parse_operand (&e1);
3950 as_bad ("No second operand to .prologue");
3951 sep = parse_operand (&e2);
3952 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3953 ignore_rest_of_line ();
3955 if (e1.X_op == O_constant)
3957 mask = e1.X_add_number;
3959 if (e2.X_op == O_constant)
3960 grsave = e2.X_add_number;
3961 else if (e2.X_op == O_register
3962 && (grsave = e2.X_add_number - REG_GR) < 128)
3965 as_bad ("Second operand not a constant or general register");
3967 add_unwind_entry (output_prologue_gr (mask, grsave));
3970 as_bad ("First operand not a constant");
3973 add_unwind_entry (output_prologue ());
3975 unwind.prologue = 1;
3976 unwind.prologue_mask = mask;
3977 ++unwind.prologue_count;
3982 int dummy ATTRIBUTE_UNUSED;
3986 int bytes_per_address;
3989 subsegT saved_subseg;
3990 const char *sec_name, *text_name;
3994 if (unwind.saved_text_seg)
3996 saved_seg = unwind.saved_text_seg;
3997 saved_subseg = unwind.saved_text_subseg;
3998 unwind.saved_text_seg = NULL;
4002 saved_seg = now_seg;
4003 saved_subseg = now_subseg;
4007 Use a slightly ugly scheme to derive the unwind section names from
4008 the text section name:
4010 text sect. unwind table sect.
4011 name: name: comments:
4012 ---------- ----------------- --------------------------------
4014 .text.foo .IA_64.unwind.text.foo
4015 .foo .IA_64.unwind.foo
4017 .gnu.linkonce.ia64unw.foo
4018 _info .IA_64.unwind_info gas issues error message (ditto)
4019 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
4021 This mapping is done so that:
4023 (a) An object file with unwind info only in .text will use
4024 unwind section names .IA_64.unwind and .IA_64.unwind_info.
4025 This follows the letter of the ABI and also ensures backwards
4026 compatibility with older toolchains.
4028 (b) An object file with unwind info in multiple text sections
4029 will use separate unwind sections for each text section.
4030 This allows us to properly set the "sh_info" and "sh_link"
4031 fields in SHT_IA_64_UNWIND as required by the ABI and also
4032 lets GNU ld support programs with multiple segments
4033 containing unwind info (as might be the case for certain
4034 embedded applications).
4036 (c) An error is issued if there would be a name clash.
4038 text_name = segment_name (saved_seg);
4039 if (strncmp (text_name, "_info", 5) == 0)
4041 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
4043 ignore_rest_of_line ();
4046 if (strcmp (text_name, ".text") == 0)
4049 insn_group_break (1, 0, 0);
4051 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4053 generate_unwind_image (text_name);
4055 if (unwind.info || unwind.force_unwind_entry)
4057 subseg_set (md.last_text_seg, 0);
4058 unwind.proc_end = expr_build_dot ();
4060 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
4061 set_section ((char *) sec_name);
4062 bfd_set_section_flags (stdoutput, now_seg,
4063 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
4065 /* Make sure that section has 4 byte alignment for ILP32 and
4066 8 byte alignment for LP64. */
4067 record_alignment (now_seg, md.pointer_size_shift);
4069 /* Need space for 3 pointers for procedure start, procedure end,
4071 ptr = frag_more (3 * md.pointer_size);
4072 where = frag_now_fix () - (3 * md.pointer_size);
4073 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4075 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4076 e.X_op = O_pseudo_fixup;
4077 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4079 e.X_add_symbol = unwind.proc_start;
4080 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4082 e.X_op = O_pseudo_fixup;
4083 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4085 e.X_add_symbol = unwind.proc_end;
4086 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4087 bytes_per_address, &e);
4091 e.X_op = O_pseudo_fixup;
4092 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4094 e.X_add_symbol = unwind.info;
4095 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4096 bytes_per_address, &e);
4099 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4103 subseg_set (saved_seg, saved_subseg);
4105 /* Parse names of main and alternate entry points and set symbol sizes. */
4109 name = input_line_pointer;
4110 c = get_symbol_end ();
4111 p = input_line_pointer;
4112 sym = symbol_find (name);
4113 if (sym && unwind.proc_start
4114 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4115 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4117 fragS *fr = symbol_get_frag (unwind.proc_start);
4118 fragS *frag = symbol_get_frag (sym);
4120 /* Check whether the function label is at or beyond last
4122 while (fr && fr != frag)
4126 if (frag == frag_now && SEG_NORMAL (now_seg))
4127 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4130 symbol_get_obj (sym)->size =
4131 (expressionS *) xmalloc (sizeof (expressionS));
4132 symbol_get_obj (sym)->size->X_op = O_subtract;
4133 symbol_get_obj (sym)->size->X_add_symbol
4134 = symbol_new (FAKE_LABEL_NAME, now_seg,
4135 frag_now_fix (), frag_now);
4136 symbol_get_obj (sym)->size->X_op_symbol = sym;
4137 symbol_get_obj (sym)->size->X_add_number = 0;
4143 if (*input_line_pointer != ',')
4145 ++input_line_pointer;
4147 demand_empty_rest_of_line ();
4148 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4152 dot_template (template)
4155 CURR_SLOT.user_template = template;
4160 int dummy ATTRIBUTE_UNUSED;
4162 int ins, locs, outs, rots;
4164 if (is_it_end_of_statement ())
4165 ins = locs = outs = rots = 0;
4168 ins = get_absolute_expression ();
4169 if (*input_line_pointer++ != ',')
4171 locs = get_absolute_expression ();
4172 if (*input_line_pointer++ != ',')
4174 outs = get_absolute_expression ();
4175 if (*input_line_pointer++ != ',')
4177 rots = get_absolute_expression ();
4179 set_regstack (ins, locs, outs, rots);
4183 as_bad ("Comma expected");
4184 ignore_rest_of_line ();
4191 unsigned num_regs, num_alloced = 0;
4192 struct dynreg **drpp, *dr;
4193 int ch, base_reg = 0;
4199 case DYNREG_GR: base_reg = REG_GR + 32; break;
4200 case DYNREG_FR: base_reg = REG_FR + 32; break;
4201 case DYNREG_PR: base_reg = REG_P + 16; break;
4205 /* First, remove existing names from hash table. */
4206 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4208 hash_delete (md.dynreg_hash, dr->name);
4212 drpp = &md.dynreg[type];
4215 start = input_line_pointer;
4216 ch = get_symbol_end ();
4217 *input_line_pointer = ch;
4218 len = (input_line_pointer - start);
4221 if (*input_line_pointer != '[')
4223 as_bad ("Expected '['");
4226 ++input_line_pointer; /* skip '[' */
4228 num_regs = get_absolute_expression ();
4230 if (*input_line_pointer++ != ']')
4232 as_bad ("Expected ']'");
4237 num_alloced += num_regs;
4241 if (num_alloced > md.rot.num_regs)
4243 as_bad ("Used more than the declared %d rotating registers",
4249 if (num_alloced > 96)
4251 as_bad ("Used more than the available 96 rotating registers");
4256 if (num_alloced > 48)
4258 as_bad ("Used more than the available 48 rotating registers");
4267 name = obstack_alloc (¬es, len + 1);
4268 memcpy (name, start, len);
4273 *drpp = obstack_alloc (¬es, sizeof (*dr));
4274 memset (*drpp, 0, sizeof (*dr));
4279 dr->num_regs = num_regs;
4280 dr->base = base_reg;
4282 base_reg += num_regs;
4284 if (hash_insert (md.dynreg_hash, name, dr))
4286 as_bad ("Attempt to redefine register set `%s'", name);
4290 if (*input_line_pointer != ',')
4292 ++input_line_pointer; /* skip comma */
4295 demand_empty_rest_of_line ();
4299 ignore_rest_of_line ();
4303 dot_byteorder (byteorder)
4306 target_big_endian = byteorder;
4311 int dummy ATTRIBUTE_UNUSED;
4318 option = input_line_pointer;
4319 ch = get_symbol_end ();
4320 if (strcmp (option, "lsb") == 0)
4321 md.flags &= ~EF_IA_64_BE;
4322 else if (strcmp (option, "msb") == 0)
4323 md.flags |= EF_IA_64_BE;
4324 else if (strcmp (option, "abi32") == 0)
4325 md.flags &= ~EF_IA_64_ABI64;
4326 else if (strcmp (option, "abi64") == 0)
4327 md.flags |= EF_IA_64_ABI64;
4329 as_bad ("Unknown psr option `%s'", option);
4330 *input_line_pointer = ch;
4333 if (*input_line_pointer != ',')
4336 ++input_line_pointer;
4339 demand_empty_rest_of_line ();
4344 int dummy ATTRIBUTE_UNUSED;
4346 as_bad (".alias not implemented yet");
4351 int dummy ATTRIBUTE_UNUSED;
4353 new_logical_line (0, get_absolute_expression ());
4354 demand_empty_rest_of_line ();
4358 parse_section_name ()
4364 if (*input_line_pointer != '"')
4366 as_bad ("Missing section name");
4367 ignore_rest_of_line ();
4370 name = demand_copy_C_string (&len);
4373 ignore_rest_of_line ();
4377 if (*input_line_pointer != ',')
4379 as_bad ("Comma expected after section name");
4380 ignore_rest_of_line ();
4383 ++input_line_pointer; /* skip comma */
4391 char *name = parse_section_name ();
4395 md.keep_pending_output = 1;
4398 obj_elf_previous (0);
4399 md.keep_pending_output = 0;
4402 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4405 stmt_float_cons (kind)
4412 case 'd': size = 8; break;
4413 case 'x': size = 10; break;
4420 ia64_do_align (size);
4428 int saved_auto_align = md.auto_align;
4432 md.auto_align = saved_auto_align;
4436 dot_xfloat_cons (kind)
4439 char *name = parse_section_name ();
4443 md.keep_pending_output = 1;
4445 stmt_float_cons (kind);
4446 obj_elf_previous (0);
4447 md.keep_pending_output = 0;
4451 dot_xstringer (zero)
4454 char *name = parse_section_name ();
4458 md.keep_pending_output = 1;
4461 obj_elf_previous (0);
4462 md.keep_pending_output = 0;
4469 int saved_auto_align = md.auto_align;
4470 char *name = parse_section_name ();
4474 md.keep_pending_output = 1;
4478 md.auto_align = saved_auto_align;
4479 obj_elf_previous (0);
4480 md.keep_pending_output = 0;
4484 dot_xfloat_cons_ua (kind)
4487 int saved_auto_align = md.auto_align;
4488 char *name = parse_section_name ();
4492 md.keep_pending_output = 1;
4495 stmt_float_cons (kind);
4496 md.auto_align = saved_auto_align;
4497 obj_elf_previous (0);
4498 md.keep_pending_output = 0;
4501 /* .reg.val <regname>,value */
4505 int dummy ATTRIBUTE_UNUSED;
4510 if (reg.X_op != O_register)
4512 as_bad (_("Register name expected"));
4513 ignore_rest_of_line ();
4515 else if (*input_line_pointer++ != ',')
4517 as_bad (_("Comma expected"));
4518 ignore_rest_of_line ();
4522 valueT value = get_absolute_expression ();
4523 int regno = reg.X_add_number;
4524 if (regno < REG_GR || regno > REG_GR + 128)
4525 as_warn (_("Register value annotation ignored"));
4528 gr_values[regno - REG_GR].known = 1;
4529 gr_values[regno - REG_GR].value = value;
4530 gr_values[regno - REG_GR].path = md.path;
4533 demand_empty_rest_of_line ();
4536 /* select dv checking mode
4541 A stop is inserted when changing modes
4548 if (md.manual_bundling)
4549 as_warn (_("Directive invalid within a bundle"));
4551 if (type == 'E' || type == 'A')
4552 md.mode_explicitly_set = 0;
4554 md.mode_explicitly_set = 1;
4561 if (md.explicit_mode)
4562 insn_group_break (1, 0, 0);
4563 md.explicit_mode = 0;
4567 if (!md.explicit_mode)
4568 insn_group_break (1, 0, 0);
4569 md.explicit_mode = 1;
4573 if (md.explicit_mode != md.default_explicit_mode)
4574 insn_group_break (1, 0, 0);
4575 md.explicit_mode = md.default_explicit_mode;
4576 md.mode_explicitly_set = 0;
4587 for (regno = 0; regno < 64; regno++)
4589 if (mask & ((valueT) 1 << regno))
4591 fprintf (stderr, "%s p%d", comma, regno);
4598 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4599 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4600 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4601 .pred.safe_across_calls p1 [, p2 [,...]]
4610 int p1 = -1, p2 = -1;
4614 if (*input_line_pointer != '"')
4616 as_bad (_("Missing predicate relation type"));
4617 ignore_rest_of_line ();
4623 char *form = demand_copy_C_string (&len);
4624 if (strcmp (form, "mutex") == 0)
4626 else if (strcmp (form, "clear") == 0)
4628 else if (strcmp (form, "imply") == 0)
4632 as_bad (_("Unrecognized predicate relation type"));
4633 ignore_rest_of_line ();
4637 if (*input_line_pointer == ',')
4638 ++input_line_pointer;
4648 if (TOUPPER (*input_line_pointer) != 'P'
4649 || (regno = atoi (++input_line_pointer)) < 0
4652 as_bad (_("Predicate register expected"));
4653 ignore_rest_of_line ();
4656 while (ISDIGIT (*input_line_pointer))
4657 ++input_line_pointer;
4664 as_warn (_("Duplicate predicate register ignored"));
4667 /* See if it's a range. */
4668 if (*input_line_pointer == '-')
4671 ++input_line_pointer;
4673 if (TOUPPER (*input_line_pointer) != 'P'
4674 || (regno = atoi (++input_line_pointer)) < 0
4677 as_bad (_("Predicate register expected"));
4678 ignore_rest_of_line ();
4681 while (ISDIGIT (*input_line_pointer))
4682 ++input_line_pointer;
4686 as_bad (_("Bad register range"));
4687 ignore_rest_of_line ();
4698 if (*input_line_pointer != ',')
4700 ++input_line_pointer;
4709 clear_qp_mutex (mask);
4710 clear_qp_implies (mask, (valueT) 0);
4713 if (count != 2 || p1 == -1 || p2 == -1)
4714 as_bad (_("Predicate source and target required"));
4715 else if (p1 == 0 || p2 == 0)
4716 as_bad (_("Use of p0 is not valid in this context"));
4718 add_qp_imply (p1, p2);
4723 as_bad (_("At least two PR arguments expected"));
4728 as_bad (_("Use of p0 is not valid in this context"));
4731 add_qp_mutex (mask);
4734 /* note that we don't override any existing relations */
4737 as_bad (_("At least one PR argument expected"));
4742 fprintf (stderr, "Safe across calls: ");
4743 print_prmask (mask);
4744 fprintf (stderr, "\n");
4746 qp_safe_across_calls = mask;
4749 demand_empty_rest_of_line ();
4752 /* .entry label [, label [, ...]]
4753 Hint to DV code that the given labels are to be considered entry points.
4754 Otherwise, only global labels are considered entry points. */
4758 int dummy ATTRIBUTE_UNUSED;
4767 name = input_line_pointer;
4768 c = get_symbol_end ();
4769 symbolP = symbol_find_or_make (name);
4771 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4773 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4776 *input_line_pointer = c;
4778 c = *input_line_pointer;
4781 input_line_pointer++;
4783 if (*input_line_pointer == '\n')
4789 demand_empty_rest_of_line ();
4792 /* .mem.offset offset, base
4793 "base" is used to distinguish between offsets from a different base. */
4796 dot_mem_offset (dummy)
4797 int dummy ATTRIBUTE_UNUSED;
4799 md.mem_offset.hint = 1;
4800 md.mem_offset.offset = get_absolute_expression ();
4801 if (*input_line_pointer != ',')
4803 as_bad (_("Comma expected"));
4804 ignore_rest_of_line ();
4807 ++input_line_pointer;
4808 md.mem_offset.base = get_absolute_expression ();
4809 demand_empty_rest_of_line ();
4812 /* ia64-specific pseudo-ops: */
4813 const pseudo_typeS md_pseudo_table[] =
4815 { "radix", dot_radix, 0 },
4816 { "lcomm", s_lcomm_bytes, 1 },
4817 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4818 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4819 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4820 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4821 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4822 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4823 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4824 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4825 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4826 { "proc", dot_proc, 0 },
4827 { "body", dot_body, 0 },
4828 { "prologue", dot_prologue, 0 },
4829 { "endp", dot_endp, 0 },
4830 { "file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0 },
4831 { "loc", dwarf2_directive_loc, 0 },
4833 { "fframe", dot_fframe, 0 },
4834 { "vframe", dot_vframe, 0 },
4835 { "vframesp", dot_vframesp, 0 },
4836 { "vframepsp", dot_vframepsp, 0 },
4837 { "save", dot_save, 0 },
4838 { "restore", dot_restore, 0 },
4839 { "restorereg", dot_restorereg, 0 },
4840 { "restorereg.p", dot_restorereg_p, 0 },
4841 { "handlerdata", dot_handlerdata, 0 },
4842 { "unwentry", dot_unwentry, 0 },
4843 { "altrp", dot_altrp, 0 },
4844 { "savesp", dot_savemem, 0 },
4845 { "savepsp", dot_savemem, 1 },
4846 { "save.g", dot_saveg, 0 },
4847 { "save.f", dot_savef, 0 },
4848 { "save.b", dot_saveb, 0 },
4849 { "save.gf", dot_savegf, 0 },
4850 { "spill", dot_spill, 0 },
4851 { "spillreg", dot_spillreg, 0 },
4852 { "spillsp", dot_spillmem, 0 },
4853 { "spillpsp", dot_spillmem, 1 },
4854 { "spillreg.p", dot_spillreg_p, 0 },
4855 { "spillsp.p", dot_spillmem_p, 0 },
4856 { "spillpsp.p", dot_spillmem_p, 1 },
4857 { "label_state", dot_label_state, 0 },
4858 { "copy_state", dot_copy_state, 0 },
4859 { "unwabi", dot_unwabi, 0 },
4860 { "personality", dot_personality, 0 },
4862 { "estate", dot_estate, 0 },
4864 { "mii", dot_template, 0x0 },
4865 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4866 { "mlx", dot_template, 0x2 },
4867 { "mmi", dot_template, 0x4 },
4868 { "mfi", dot_template, 0x6 },
4869 { "mmf", dot_template, 0x7 },
4870 { "mib", dot_template, 0x8 },
4871 { "mbb", dot_template, 0x9 },
4872 { "bbb", dot_template, 0xb },
4873 { "mmb", dot_template, 0xc },
4874 { "mfb", dot_template, 0xe },
4876 { "lb", dot_scope, 0 },
4877 { "le", dot_scope, 1 },
4879 { "align", s_align_bytes, 0 },
4880 { "regstk", dot_regstk, 0 },
4881 { "rotr", dot_rot, DYNREG_GR },
4882 { "rotf", dot_rot, DYNREG_FR },
4883 { "rotp", dot_rot, DYNREG_PR },
4884 { "lsb", dot_byteorder, 0 },
4885 { "msb", dot_byteorder, 1 },
4886 { "psr", dot_psr, 0 },
4887 { "alias", dot_alias, 0 },
4888 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4890 { "xdata1", dot_xdata, 1 },
4891 { "xdata2", dot_xdata, 2 },
4892 { "xdata4", dot_xdata, 4 },
4893 { "xdata8", dot_xdata, 8 },
4894 { "xreal4", dot_xfloat_cons, 'f' },
4895 { "xreal8", dot_xfloat_cons, 'd' },
4896 { "xreal10", dot_xfloat_cons, 'x' },
4897 { "xstring", dot_xstringer, 0 },
4898 { "xstringz", dot_xstringer, 1 },
4900 /* unaligned versions: */
4901 { "xdata2.ua", dot_xdata_ua, 2 },
4902 { "xdata4.ua", dot_xdata_ua, 4 },
4903 { "xdata8.ua", dot_xdata_ua, 8 },
4904 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4905 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4906 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4908 /* annotations/DV checking support */
4909 { "entry", dot_entry, 0 },
4910 { "mem.offset", dot_mem_offset, 0 },
4911 { "pred.rel", dot_pred_rel, 0 },
4912 { "pred.rel.clear", dot_pred_rel, 'c' },
4913 { "pred.rel.imply", dot_pred_rel, 'i' },
4914 { "pred.rel.mutex", dot_pred_rel, 'm' },
4915 { "pred.safe_across_calls", dot_pred_rel, 's' },
4916 { "reg.val", dot_reg_val, 0 },
4917 { "auto", dot_dv_mode, 'a' },
4918 { "explicit", dot_dv_mode, 'e' },
4919 { "default", dot_dv_mode, 'd' },
4921 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
4922 IA-64 aligns data allocation pseudo-ops by default, so we have to
4923 tell it that these ones are supposed to be unaligned. Long term,
4924 should rewrite so that only IA-64 specific data allocation pseudo-ops
4925 are aligned by default. */
4926 {"2byte", stmt_cons_ua, 2},
4927 {"4byte", stmt_cons_ua, 4},
4928 {"8byte", stmt_cons_ua, 8},
4933 static const struct pseudo_opcode
4936 void (*handler) (int);
4941 /* these are more like pseudo-ops, but don't start with a dot */
4942 { "data1", cons, 1 },
4943 { "data2", cons, 2 },
4944 { "data4", cons, 4 },
4945 { "data8", cons, 8 },
4946 { "data16", cons, 16 },
4947 { "real4", stmt_float_cons, 'f' },
4948 { "real8", stmt_float_cons, 'd' },
4949 { "real10", stmt_float_cons, 'x' },
4950 { "string", stringer, 0 },
4951 { "stringz", stringer, 1 },
4953 /* unaligned versions: */
4954 { "data2.ua", stmt_cons_ua, 2 },
4955 { "data4.ua", stmt_cons_ua, 4 },
4956 { "data8.ua", stmt_cons_ua, 8 },
4957 { "data16.ua", stmt_cons_ua, 16 },
4958 { "real4.ua", float_cons, 'f' },
4959 { "real8.ua", float_cons, 'd' },
4960 { "real10.ua", float_cons, 'x' },
4963 /* Declare a register by creating a symbol for it and entering it in
4964 the symbol table. */
4967 declare_register (name, regnum)
4974 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
4976 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
4978 as_fatal ("Inserting \"%s\" into register table failed: %s",
4985 declare_register_set (prefix, num_regs, base_regnum)
4993 for (i = 0; i < num_regs; ++i)
4995 sprintf (name, "%s%u", prefix, i);
4996 declare_register (name, base_regnum + i);
5001 operand_width (opnd)
5002 enum ia64_opnd opnd;
5004 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5005 unsigned int bits = 0;
5009 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5010 bits += odesc->field[i].bits;
5015 static enum operand_match_result
5016 operand_match (idesc, index, e)
5017 const struct ia64_opcode *idesc;
5021 enum ia64_opnd opnd = idesc->operands[index];
5022 int bits, relocatable = 0;
5023 struct insn_fix *fix;
5030 case IA64_OPND_AR_CCV:
5031 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5032 return OPERAND_MATCH;
5035 case IA64_OPND_AR_PFS:
5036 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5037 return OPERAND_MATCH;
5041 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5042 return OPERAND_MATCH;
5046 if (e->X_op == O_register && e->X_add_number == REG_IP)
5047 return OPERAND_MATCH;
5051 if (e->X_op == O_register && e->X_add_number == REG_PR)
5052 return OPERAND_MATCH;
5055 case IA64_OPND_PR_ROT:
5056 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5057 return OPERAND_MATCH;
5061 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5062 return OPERAND_MATCH;
5065 case IA64_OPND_PSR_L:
5066 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5067 return OPERAND_MATCH;
5070 case IA64_OPND_PSR_UM:
5071 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5072 return OPERAND_MATCH;
5076 if (e->X_op == O_constant)
5078 if (e->X_add_number == 1)
5079 return OPERAND_MATCH;
5081 return OPERAND_OUT_OF_RANGE;
5086 if (e->X_op == O_constant)
5088 if (e->X_add_number == 8)
5089 return OPERAND_MATCH;
5091 return OPERAND_OUT_OF_RANGE;
5096 if (e->X_op == O_constant)
5098 if (e->X_add_number == 16)
5099 return OPERAND_MATCH;
5101 return OPERAND_OUT_OF_RANGE;
5105 /* register operands: */
5108 if (e->X_op == O_register && e->X_add_number >= REG_AR
5109 && e->X_add_number < REG_AR + 128)
5110 return OPERAND_MATCH;
5115 if (e->X_op == O_register && e->X_add_number >= REG_BR
5116 && e->X_add_number < REG_BR + 8)
5117 return OPERAND_MATCH;
5121 if (e->X_op == O_register && e->X_add_number >= REG_CR
5122 && e->X_add_number < REG_CR + 128)
5123 return OPERAND_MATCH;
5130 if (e->X_op == O_register && e->X_add_number >= REG_FR
5131 && e->X_add_number < REG_FR + 128)
5132 return OPERAND_MATCH;
5137 if (e->X_op == O_register && e->X_add_number >= REG_P
5138 && e->X_add_number < REG_P + 64)
5139 return OPERAND_MATCH;
5145 if (e->X_op == O_register && e->X_add_number >= REG_GR
5146 && e->X_add_number < REG_GR + 128)
5147 return OPERAND_MATCH;
5150 case IA64_OPND_R3_2:
5151 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5153 if (e->X_add_number < REG_GR + 4)
5154 return OPERAND_MATCH;
5155 else if (e->X_add_number < REG_GR + 128)
5156 return OPERAND_OUT_OF_RANGE;
5160 /* indirect operands: */
5161 case IA64_OPND_CPUID_R3:
5162 case IA64_OPND_DBR_R3:
5163 case IA64_OPND_DTR_R3:
5164 case IA64_OPND_ITR_R3:
5165 case IA64_OPND_IBR_R3:
5166 case IA64_OPND_MSR_R3:
5167 case IA64_OPND_PKR_R3:
5168 case IA64_OPND_PMC_R3:
5169 case IA64_OPND_PMD_R3:
5170 case IA64_OPND_RR_R3:
5171 if (e->X_op == O_index && e->X_op_symbol
5172 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5173 == opnd - IA64_OPND_CPUID_R3))
5174 return OPERAND_MATCH;
5178 if (e->X_op == O_index && !e->X_op_symbol)
5179 return OPERAND_MATCH;
5182 /* immediate operands: */
5183 case IA64_OPND_CNT2a:
5184 case IA64_OPND_LEN4:
5185 case IA64_OPND_LEN6:
5186 bits = operand_width (idesc->operands[index]);
5187 if (e->X_op == O_constant)
5189 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5190 return OPERAND_MATCH;
5192 return OPERAND_OUT_OF_RANGE;
5196 case IA64_OPND_CNT2b:
5197 if (e->X_op == O_constant)
5199 if ((bfd_vma) (e->X_add_number - 1) < 3)
5200 return OPERAND_MATCH;
5202 return OPERAND_OUT_OF_RANGE;
5206 case IA64_OPND_CNT2c:
5207 val = e->X_add_number;
5208 if (e->X_op == O_constant)
5210 if ((val == 0 || val == 7 || val == 15 || val == 16))
5211 return OPERAND_MATCH;
5213 return OPERAND_OUT_OF_RANGE;
5218 /* SOR must be an integer multiple of 8 */
5219 if (e->X_op == O_constant && e->X_add_number & 0x7)
5220 return OPERAND_OUT_OF_RANGE;
5223 if (e->X_op == O_constant)
5225 if ((bfd_vma) e->X_add_number <= 96)
5226 return OPERAND_MATCH;
5228 return OPERAND_OUT_OF_RANGE;
5232 case IA64_OPND_IMMU62:
5233 if (e->X_op == O_constant)
5235 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5236 return OPERAND_MATCH;
5238 return OPERAND_OUT_OF_RANGE;
5242 /* FIXME -- need 62-bit relocation type */
5243 as_bad (_("62-bit relocation not yet implemented"));
5247 case IA64_OPND_IMMU64:
5248 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5249 || e->X_op == O_subtract)
5251 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5252 fix->code = BFD_RELOC_IA64_IMM64;
5253 if (e->X_op != O_subtract)
5255 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5256 if (e->X_op == O_pseudo_fixup)
5260 fix->opnd = idesc->operands[index];
5263 ++CURR_SLOT.num_fixups;
5264 return OPERAND_MATCH;
5266 else if (e->X_op == O_constant)
5267 return OPERAND_MATCH;
5270 case IA64_OPND_CCNT5:
5271 case IA64_OPND_CNT5:
5272 case IA64_OPND_CNT6:
5273 case IA64_OPND_CPOS6a:
5274 case IA64_OPND_CPOS6b:
5275 case IA64_OPND_CPOS6c:
5276 case IA64_OPND_IMMU2:
5277 case IA64_OPND_IMMU7a:
5278 case IA64_OPND_IMMU7b:
5279 case IA64_OPND_IMMU21:
5280 case IA64_OPND_IMMU24:
5281 case IA64_OPND_MBTYPE4:
5282 case IA64_OPND_MHTYPE8:
5283 case IA64_OPND_POS6:
5284 bits = operand_width (idesc->operands[index]);
5285 if (e->X_op == O_constant)
5287 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5288 return OPERAND_MATCH;
5290 return OPERAND_OUT_OF_RANGE;
5294 case IA64_OPND_IMMU9:
5295 bits = operand_width (idesc->operands[index]);
5296 if (e->X_op == O_constant)
5298 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5300 int lobits = e->X_add_number & 0x3;
5301 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5302 e->X_add_number |= (bfd_vma) 0x3;
5303 return OPERAND_MATCH;
5306 return OPERAND_OUT_OF_RANGE;
5310 case IA64_OPND_IMM44:
5311 /* least 16 bits must be zero */
5312 if ((e->X_add_number & 0xffff) != 0)
5313 /* XXX technically, this is wrong: we should not be issuing warning
5314 messages until we're sure this instruction pattern is going to
5316 as_warn (_("lower 16 bits of mask ignored"));
5318 if (e->X_op == O_constant)
5320 if (((e->X_add_number >= 0
5321 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5322 || (e->X_add_number < 0
5323 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5326 if (e->X_add_number >= 0
5327 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5329 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5331 return OPERAND_MATCH;
5334 return OPERAND_OUT_OF_RANGE;
5338 case IA64_OPND_IMM17:
5339 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5340 if (e->X_op == O_constant)
5342 if (((e->X_add_number >= 0
5343 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5344 || (e->X_add_number < 0
5345 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5348 if (e->X_add_number >= 0
5349 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5351 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5353 return OPERAND_MATCH;
5356 return OPERAND_OUT_OF_RANGE;
5360 case IA64_OPND_IMM14:
5361 case IA64_OPND_IMM22:
5363 case IA64_OPND_IMM1:
5364 case IA64_OPND_IMM8:
5365 case IA64_OPND_IMM8U4:
5366 case IA64_OPND_IMM8M1:
5367 case IA64_OPND_IMM8M1U4:
5368 case IA64_OPND_IMM8M1U8:
5369 case IA64_OPND_IMM9a:
5370 case IA64_OPND_IMM9b:
5371 bits = operand_width (idesc->operands[index]);
5372 if (relocatable && (e->X_op == O_symbol
5373 || e->X_op == O_subtract
5374 || e->X_op == O_pseudo_fixup))
5376 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5378 if (idesc->operands[index] == IA64_OPND_IMM14)
5379 fix->code = BFD_RELOC_IA64_IMM14;
5381 fix->code = BFD_RELOC_IA64_IMM22;
5383 if (e->X_op != O_subtract)
5385 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5386 if (e->X_op == O_pseudo_fixup)
5390 fix->opnd = idesc->operands[index];
5393 ++CURR_SLOT.num_fixups;
5394 return OPERAND_MATCH;
5396 else if (e->X_op != O_constant
5397 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5398 return OPERAND_MISMATCH;
5400 if (opnd == IA64_OPND_IMM8M1U4)
5402 /* Zero is not valid for unsigned compares that take an adjusted
5403 constant immediate range. */
5404 if (e->X_add_number == 0)
5405 return OPERAND_OUT_OF_RANGE;
5407 /* Sign-extend 32-bit unsigned numbers, so that the following range
5408 checks will work. */
5409 val = e->X_add_number;
5410 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5411 && ((val & ((bfd_vma) 1 << 31)) != 0))
5412 val = ((val << 32) >> 32);
5414 /* Check for 0x100000000. This is valid because
5415 0x100000000-1 is the same as ((uint32_t) -1). */
5416 if (val == ((bfd_signed_vma) 1 << 32))
5417 return OPERAND_MATCH;
5421 else if (opnd == IA64_OPND_IMM8M1U8)
5423 /* Zero is not valid for unsigned compares that take an adjusted
5424 constant immediate range. */
5425 if (e->X_add_number == 0)
5426 return OPERAND_OUT_OF_RANGE;
5428 /* Check for 0x10000000000000000. */
5429 if (e->X_op == O_big)
5431 if (generic_bignum[0] == 0
5432 && generic_bignum[1] == 0
5433 && generic_bignum[2] == 0
5434 && generic_bignum[3] == 0
5435 && generic_bignum[4] == 1)
5436 return OPERAND_MATCH;
5438 return OPERAND_OUT_OF_RANGE;
5441 val = e->X_add_number - 1;
5443 else if (opnd == IA64_OPND_IMM8M1)
5444 val = e->X_add_number - 1;
5445 else if (opnd == IA64_OPND_IMM8U4)
5447 /* Sign-extend 32-bit unsigned numbers, so that the following range
5448 checks will work. */
5449 val = e->X_add_number;
5450 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5451 && ((val & ((bfd_vma) 1 << 31)) != 0))
5452 val = ((val << 32) >> 32);
5455 val = e->X_add_number;
5457 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5458 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5459 return OPERAND_MATCH;
5461 return OPERAND_OUT_OF_RANGE;
5463 case IA64_OPND_INC3:
5464 /* +/- 1, 4, 8, 16 */
5465 val = e->X_add_number;
5468 if (e->X_op == O_constant)
5470 if ((val == 1 || val == 4 || val == 8 || val == 16))
5471 return OPERAND_MATCH;
5473 return OPERAND_OUT_OF_RANGE;
5477 case IA64_OPND_TGT25:
5478 case IA64_OPND_TGT25b:
5479 case IA64_OPND_TGT25c:
5480 case IA64_OPND_TGT64:
5481 if (e->X_op == O_symbol)
5483 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5484 if (opnd == IA64_OPND_TGT25)
5485 fix->code = BFD_RELOC_IA64_PCREL21F;
5486 else if (opnd == IA64_OPND_TGT25b)
5487 fix->code = BFD_RELOC_IA64_PCREL21M;
5488 else if (opnd == IA64_OPND_TGT25c)
5489 fix->code = BFD_RELOC_IA64_PCREL21B;
5490 else if (opnd == IA64_OPND_TGT64)
5491 fix->code = BFD_RELOC_IA64_PCREL60B;
5495 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5496 fix->opnd = idesc->operands[index];
5499 ++CURR_SLOT.num_fixups;
5500 return OPERAND_MATCH;
5502 case IA64_OPND_TAG13:
5503 case IA64_OPND_TAG13b:
5507 return OPERAND_MATCH;
5510 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5511 /* There are no external relocs for TAG13/TAG13b fields, so we
5512 create a dummy reloc. This will not live past md_apply_fix3. */
5513 fix->code = BFD_RELOC_UNUSED;
5514 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5515 fix->opnd = idesc->operands[index];
5518 ++CURR_SLOT.num_fixups;
5519 return OPERAND_MATCH;
5526 case IA64_OPND_LDXMOV:
5527 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5528 fix->code = BFD_RELOC_IA64_LDXMOV;
5529 fix->opnd = idesc->operands[index];
5532 ++CURR_SLOT.num_fixups;
5533 return OPERAND_MATCH;
5538 return OPERAND_MISMATCH;
5547 memset (e, 0, sizeof (*e));
5550 if (*input_line_pointer != '}')
5552 sep = *input_line_pointer++;
5556 if (!md.manual_bundling)
5557 as_warn ("Found '}' when manual bundling is off");
5559 CURR_SLOT.manual_bundling_off = 1;
5560 md.manual_bundling = 0;
5566 /* Returns the next entry in the opcode table that matches the one in
5567 IDESC, and frees the entry in IDESC. If no matching entry is
5568 found, NULL is returned instead. */
5570 static struct ia64_opcode *
5571 get_next_opcode (struct ia64_opcode *idesc)
5573 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5574 ia64_free_opcode (idesc);
5578 /* Parse the operands for the opcode and find the opcode variant that
5579 matches the specified operands, or NULL if no match is possible. */
5581 static struct ia64_opcode *
5582 parse_operands (idesc)
5583 struct ia64_opcode *idesc;
5585 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5586 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5587 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5588 enum operand_match_result result;
5590 char *first_arg = 0, *end, *saved_input_pointer;
5593 assert (strlen (idesc->name) <= 128);
5595 strcpy (mnemonic, idesc->name);
5596 if (idesc->operands[2] == IA64_OPND_SOF)
5598 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5599 can't parse the first operand until we have parsed the
5600 remaining operands of the "alloc" instruction. */
5602 first_arg = input_line_pointer;
5603 end = strchr (input_line_pointer, '=');
5606 as_bad ("Expected separator `='");
5609 input_line_pointer = end + 1;
5614 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5616 sep = parse_operand (CURR_SLOT.opnd + i);
5617 if (CURR_SLOT.opnd[i].X_op == O_absent)
5622 if (sep != '=' && sep != ',')
5627 if (num_outputs > 0)
5628 as_bad ("Duplicate equal sign (=) in instruction");
5630 num_outputs = i + 1;
5635 as_bad ("Illegal operand separator `%c'", sep);
5639 if (idesc->operands[2] == IA64_OPND_SOF)
5641 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5642 know (strcmp (idesc->name, "alloc") == 0);
5643 if (num_operands == 5 /* first_arg not included in this count! */
5644 && CURR_SLOT.opnd[2].X_op == O_constant
5645 && CURR_SLOT.opnd[3].X_op == O_constant
5646 && CURR_SLOT.opnd[4].X_op == O_constant
5647 && CURR_SLOT.opnd[5].X_op == O_constant)
5649 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5650 CURR_SLOT.opnd[3].X_add_number,
5651 CURR_SLOT.opnd[4].X_add_number,
5652 CURR_SLOT.opnd[5].X_add_number);
5654 /* now we can parse the first arg: */
5655 saved_input_pointer = input_line_pointer;
5656 input_line_pointer = first_arg;
5657 sep = parse_operand (CURR_SLOT.opnd + 0);
5659 --num_outputs; /* force error */
5660 input_line_pointer = saved_input_pointer;
5662 CURR_SLOT.opnd[2].X_add_number = sof;
5663 CURR_SLOT.opnd[3].X_add_number
5664 = sof - CURR_SLOT.opnd[4].X_add_number;
5665 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5669 highest_unmatched_operand = 0;
5670 curr_out_of_range_pos = -1;
5672 expected_operand = idesc->operands[0];
5673 for (; idesc; idesc = get_next_opcode (idesc))
5675 if (num_outputs != idesc->num_outputs)
5676 continue; /* mismatch in # of outputs */
5678 CURR_SLOT.num_fixups = 0;
5680 /* Try to match all operands. If we see an out-of-range operand,
5681 then continue trying to match the rest of the operands, since if
5682 the rest match, then this idesc will give the best error message. */
5684 out_of_range_pos = -1;
5685 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5687 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5688 if (result != OPERAND_MATCH)
5690 if (result != OPERAND_OUT_OF_RANGE)
5692 if (out_of_range_pos < 0)
5693 /* remember position of the first out-of-range operand: */
5694 out_of_range_pos = i;
5698 /* If we did not match all operands, or if at least one operand was
5699 out-of-range, then this idesc does not match. Keep track of which
5700 idesc matched the most operands before failing. If we have two
5701 idescs that failed at the same position, and one had an out-of-range
5702 operand, then prefer the out-of-range operand. Thus if we have
5703 "add r0=0x1000000,r1" we get an error saying the constant is out
5704 of range instead of an error saying that the constant should have been
5707 if (i != num_operands || out_of_range_pos >= 0)
5709 if (i > highest_unmatched_operand
5710 || (i == highest_unmatched_operand
5711 && out_of_range_pos > curr_out_of_range_pos))
5713 highest_unmatched_operand = i;
5714 if (out_of_range_pos >= 0)
5716 expected_operand = idesc->operands[out_of_range_pos];
5717 error_pos = out_of_range_pos;
5721 expected_operand = idesc->operands[i];
5724 curr_out_of_range_pos = out_of_range_pos;
5729 if (num_operands < NELEMS (idesc->operands)
5730 && idesc->operands[num_operands])
5731 continue; /* mismatch in number of arguments */
5737 if (expected_operand)
5738 as_bad ("Operand %u of `%s' should be %s",
5739 error_pos + 1, mnemonic,
5740 elf64_ia64_operands[expected_operand].desc);
5742 as_bad ("Operand mismatch");
5748 /* Keep track of state necessary to determine whether a NOP is necessary
5749 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5750 detect a case where additional NOPs may be necessary. */
5752 errata_nop_necessary_p (slot, insn_unit)
5754 enum ia64_unit insn_unit;
5757 struct group *this_group = md.last_groups + md.group_idx;
5758 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5759 struct ia64_opcode *idesc = slot->idesc;
5761 /* Test whether this could be the first insn in a problematic sequence. */
5762 if (insn_unit == IA64_UNIT_F)
5764 for (i = 0; i < idesc->num_outputs; i++)
5765 if (idesc->operands[i] == IA64_OPND_P1
5766 || idesc->operands[i] == IA64_OPND_P2)
5768 int regno = slot->opnd[i].X_add_number - REG_P;
5769 /* Ignore invalid operands; they generate errors elsewhere. */
5772 this_group->p_reg_set[regno] = 1;
5776 /* Test whether this could be the second insn in a problematic sequence. */
5777 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5778 && prev_group->p_reg_set[slot->qp_regno])
5780 for (i = 0; i < idesc->num_outputs; i++)
5781 if (idesc->operands[i] == IA64_OPND_R1
5782 || idesc->operands[i] == IA64_OPND_R2
5783 || idesc->operands[i] == IA64_OPND_R3)
5785 int regno = slot->opnd[i].X_add_number - REG_GR;
5786 /* Ignore invalid operands; they generate errors elsewhere. */
5789 if (strncmp (idesc->name, "add", 3) != 0
5790 && strncmp (idesc->name, "sub", 3) != 0
5791 && strncmp (idesc->name, "shladd", 6) != 0
5792 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5793 this_group->g_reg_set_conditionally[regno] = 1;
5797 /* Test whether this could be the third insn in a problematic sequence. */
5798 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5800 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5801 idesc->operands[i] == IA64_OPND_R3
5802 /* For mov indirect. */
5803 || idesc->operands[i] == IA64_OPND_RR_R3
5804 || idesc->operands[i] == IA64_OPND_DBR_R3
5805 || idesc->operands[i] == IA64_OPND_IBR_R3
5806 || idesc->operands[i] == IA64_OPND_PKR_R3
5807 || idesc->operands[i] == IA64_OPND_PMC_R3
5808 || idesc->operands[i] == IA64_OPND_PMD_R3
5809 || idesc->operands[i] == IA64_OPND_MSR_R3
5810 || idesc->operands[i] == IA64_OPND_CPUID_R3
5812 || idesc->operands[i] == IA64_OPND_ITR_R3
5813 || idesc->operands[i] == IA64_OPND_DTR_R3
5814 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5815 || idesc->operands[i] == IA64_OPND_MR3)
5817 int regno = slot->opnd[i].X_add_number - REG_GR;
5818 /* Ignore invalid operands; they generate errors elsewhere. */
5821 if (idesc->operands[i] == IA64_OPND_R3)
5823 if (strcmp (idesc->name, "fc") != 0
5824 && strcmp (idesc->name, "tak") != 0
5825 && strcmp (idesc->name, "thash") != 0
5826 && strcmp (idesc->name, "tpa") != 0
5827 && strcmp (idesc->name, "ttag") != 0
5828 && strncmp (idesc->name, "ptr", 3) != 0
5829 && strncmp (idesc->name, "ptc", 3) != 0
5830 && strncmp (idesc->name, "probe", 5) != 0)
5833 if (prev_group->g_reg_set_conditionally[regno])
5841 build_insn (slot, insnp)
5845 const struct ia64_operand *odesc, *o2desc;
5846 struct ia64_opcode *idesc = slot->idesc;
5847 bfd_signed_vma insn, val;
5851 insn = idesc->opcode | slot->qp_regno;
5853 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5855 if (slot->opnd[i].X_op == O_register
5856 || slot->opnd[i].X_op == O_constant
5857 || slot->opnd[i].X_op == O_index)
5858 val = slot->opnd[i].X_add_number;
5859 else if (slot->opnd[i].X_op == O_big)
5861 /* This must be the value 0x10000000000000000. */
5862 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5868 switch (idesc->operands[i])
5870 case IA64_OPND_IMMU64:
5871 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5872 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5873 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5874 | (((val >> 63) & 0x1) << 36));
5877 case IA64_OPND_IMMU62:
5878 val &= 0x3fffffffffffffffULL;
5879 if (val != slot->opnd[i].X_add_number)
5880 as_warn (_("Value truncated to 62 bits"));
5881 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5882 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5885 case IA64_OPND_TGT64:
5887 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5888 insn |= ((((val >> 59) & 0x1) << 36)
5889 | (((val >> 0) & 0xfffff) << 13));
5920 case IA64_OPND_R3_2:
5921 case IA64_OPND_CPUID_R3:
5922 case IA64_OPND_DBR_R3:
5923 case IA64_OPND_DTR_R3:
5924 case IA64_OPND_ITR_R3:
5925 case IA64_OPND_IBR_R3:
5927 case IA64_OPND_MSR_R3:
5928 case IA64_OPND_PKR_R3:
5929 case IA64_OPND_PMC_R3:
5930 case IA64_OPND_PMD_R3:
5931 case IA64_OPND_RR_R3:
5939 odesc = elf64_ia64_operands + idesc->operands[i];
5940 err = (*odesc->insert) (odesc, val, &insn);
5942 as_bad_where (slot->src_file, slot->src_line,
5943 "Bad operand value: %s", err);
5944 if (idesc->flags & IA64_OPCODE_PSEUDO)
5946 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
5947 && odesc == elf64_ia64_operands + IA64_OPND_F3)
5949 o2desc = elf64_ia64_operands + IA64_OPND_F2;
5950 (*o2desc->insert) (o2desc, val, &insn);
5952 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
5953 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
5954 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
5956 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
5957 (*o2desc->insert) (o2desc, 64 - val, &insn);
5967 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
5968 unsigned int manual_bundling = 0;
5969 enum ia64_unit required_unit, insn_unit = 0;
5970 enum ia64_insn_type type[3], insn_type;
5971 unsigned int template, orig_template;
5972 bfd_vma insn[3] = { -1, -1, -1 };
5973 struct ia64_opcode *idesc;
5974 int end_of_insn_group = 0, user_template = -1;
5975 int n, i, j, first, curr;
5977 bfd_vma t0 = 0, t1 = 0;
5978 struct label_fix *lfix;
5979 struct insn_fix *ifix;
5984 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
5985 know (first >= 0 & first < NUM_SLOTS);
5986 n = MIN (3, md.num_slots_in_use);
5988 /* Determine template: user user_template if specified, best match
5991 if (md.slot[first].user_template >= 0)
5992 user_template = template = md.slot[first].user_template;
5995 /* Auto select appropriate template. */
5996 memset (type, 0, sizeof (type));
5998 for (i = 0; i < n; ++i)
6000 if (md.slot[curr].label_fixups && i != 0)
6002 type[i] = md.slot[curr].idesc->type;
6003 curr = (curr + 1) % NUM_SLOTS;
6005 template = best_template[type[0]][type[1]][type[2]];
6008 /* initialize instructions with appropriate nops: */
6009 for (i = 0; i < 3; ++i)
6010 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6014 /* now fill in slots with as many insns as possible: */
6016 idesc = md.slot[curr].idesc;
6017 end_of_insn_group = 0;
6018 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6020 /* Set the slot number for prologue/body records now as those
6021 refer to the current point, not the point after the
6022 instruction has been issued: */
6023 /* Don't try to delete prologue/body records here, as that will cause
6024 them to also be deleted from the master list of unwind records. */
6025 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6026 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6027 || ptr->r.type == body)
6029 ptr->slot_number = (unsigned long) f + i;
6030 ptr->slot_frag = frag_now;
6033 if (idesc->flags & IA64_OPCODE_SLOT2)
6035 if (manual_bundling && i != 2)
6036 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6037 "`%s' must be last in bundle", idesc->name);
6041 if (idesc->flags & IA64_OPCODE_LAST)
6044 unsigned int required_template;
6046 /* If we need a stop bit after an M slot, our only choice is
6047 template 5 (M;;MI). If we need a stop bit after a B
6048 slot, our only choice is to place it at the end of the
6049 bundle, because the only available templates are MIB,
6050 MBB, BBB, MMB, and MFB. We don't handle anything other
6051 than M and B slots because these are the only kind of
6052 instructions that can have the IA64_OPCODE_LAST bit set. */
6053 required_template = template;
6054 switch (idesc->type)
6058 required_template = 5;
6066 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6067 "Internal error: don't know how to force %s to end"
6068 "of instruction group", idesc->name);
6072 if (manual_bundling && i != required_slot)
6073 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6074 "`%s' must be last in instruction group",
6076 if (required_slot < i)
6077 /* Can't fit this instruction. */
6081 if (required_template != template)
6083 /* If we switch the template, we need to reset the NOPs
6084 after slot i. The slot-types of the instructions ahead
6085 of i never change, so we don't need to worry about
6086 changing NOPs in front of this slot. */
6087 for (j = i; j < 3; ++j)
6088 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6090 template = required_template;
6092 if (curr != first && md.slot[curr].label_fixups)
6094 if (manual_bundling_on)
6095 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6096 "Label must be first in a bundle");
6097 /* This insn must go into the first slot of a bundle. */
6101 manual_bundling_on = md.slot[curr].manual_bundling_on;
6102 manual_bundling_off = md.slot[curr].manual_bundling_off;
6104 if (manual_bundling_on)
6107 manual_bundling = 1;
6109 break; /* need to start a new bundle */
6112 if (end_of_insn_group && md.num_slots_in_use >= 1)
6114 /* We need an instruction group boundary in the middle of a
6115 bundle. See if we can switch to an other template with
6116 an appropriate boundary. */
6118 orig_template = template;
6119 if (i == 1 && (user_template == 4
6120 || (user_template < 0
6121 && (ia64_templ_desc[template].exec_unit[0]
6125 end_of_insn_group = 0;
6127 else if (i == 2 && (user_template == 0
6128 || (user_template < 0
6129 && (ia64_templ_desc[template].exec_unit[1]
6131 /* This test makes sure we don't switch the template if
6132 the next instruction is one that needs to be first in
6133 an instruction group. Since all those instructions are
6134 in the M group, there is no way such an instruction can
6135 fit in this bundle even if we switch the template. The
6136 reason we have to check for this is that otherwise we
6137 may end up generating "MI;;I M.." which has the deadly
6138 effect that the second M instruction is no longer the
6139 first in the bundle! --davidm 99/12/16 */
6140 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6143 end_of_insn_group = 0;
6145 else if (curr != first)
6146 /* can't fit this insn */
6149 if (template != orig_template)
6150 /* if we switch the template, we need to reset the NOPs
6151 after slot i. The slot-types of the instructions ahead
6152 of i never change, so we don't need to worry about
6153 changing NOPs in front of this slot. */
6154 for (j = i; j < 3; ++j)
6155 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6157 required_unit = ia64_templ_desc[template].exec_unit[i];
6159 /* resolve dynamic opcodes such as "break" and "nop": */
6160 if (idesc->type == IA64_TYPE_DYN)
6162 if ((strcmp (idesc->name, "nop") == 0)
6163 || (strcmp (idesc->name, "break") == 0))
6164 insn_unit = required_unit;
6165 else if (strcmp (idesc->name, "chk.s") == 0)
6167 insn_unit = IA64_UNIT_M;
6168 if (required_unit == IA64_UNIT_I)
6169 insn_unit = IA64_UNIT_I;
6172 as_fatal ("emit_one_bundle: unexpected dynamic op");
6174 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6175 ia64_free_opcode (idesc);
6176 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6178 know (!idesc->next); /* no resolved dynamic ops have collisions */
6183 insn_type = idesc->type;
6184 insn_unit = IA64_UNIT_NIL;
6188 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6189 insn_unit = required_unit;
6191 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6192 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6193 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6194 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6195 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6200 if (insn_unit != required_unit)
6202 if (required_unit == IA64_UNIT_L
6203 && insn_unit == IA64_UNIT_I
6204 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6206 /* we got ourselves an MLX template but the current
6207 instruction isn't an X-unit, or an I-unit instruction
6208 that can go into the X slot of an MLX template. Duh. */
6209 if (md.num_slots_in_use >= NUM_SLOTS)
6211 as_bad_where (md.slot[curr].src_file,
6212 md.slot[curr].src_line,
6213 "`%s' can't go in X slot of "
6214 "MLX template", idesc->name);
6215 /* drop this insn so we don't livelock: */
6216 --md.num_slots_in_use;
6220 continue; /* try next slot */
6226 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6227 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6230 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6231 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6233 build_insn (md.slot + curr, insn + i);
6235 /* Set slot counts for non prologue/body unwind records. */
6236 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6237 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
6238 && ptr->r.type != body)
6240 ptr->slot_number = (unsigned long) f + i;
6241 ptr->slot_frag = frag_now;
6243 md.slot[curr].unwind_record = NULL;
6245 if (required_unit == IA64_UNIT_L)
6248 /* skip one slot for long/X-unit instructions */
6251 --md.num_slots_in_use;
6253 /* now is a good time to fix up the labels for this insn: */
6254 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6256 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6257 symbol_set_frag (lfix->sym, frag_now);
6259 /* and fix up the tags also. */
6260 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6262 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6263 symbol_set_frag (lfix->sym, frag_now);
6266 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6268 ifix = md.slot[curr].fixup + j;
6269 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6270 &ifix->expr, ifix->is_pcrel, ifix->code);
6271 fix->tc_fix_data.opnd = ifix->opnd;
6272 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6273 fix->fx_file = md.slot[curr].src_file;
6274 fix->fx_line = md.slot[curr].src_line;
6277 end_of_insn_group = md.slot[curr].end_of_insn_group;
6279 if (end_of_insn_group)
6281 md.group_idx = (md.group_idx + 1) % 3;
6282 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6286 ia64_free_opcode (md.slot[curr].idesc);
6287 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6288 md.slot[curr].user_template = -1;
6290 if (manual_bundling_off)
6292 manual_bundling = 0;
6295 curr = (curr + 1) % NUM_SLOTS;
6296 idesc = md.slot[curr].idesc;
6298 if (manual_bundling)
6300 if (md.num_slots_in_use > 0)
6301 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6302 "`%s' does not fit into %s template",
6303 idesc->name, ia64_templ_desc[template].name);
6305 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6306 "Missing '}' at end of file");
6308 know (md.num_slots_in_use < NUM_SLOTS);
6310 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6311 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6313 number_to_chars_littleendian (f + 0, t0, 8);
6314 number_to_chars_littleendian (f + 8, t1, 8);
6316 unwind.next_slot_number = (unsigned long) f + 16;
6317 unwind.next_slot_frag = frag_now;
6321 md_parse_option (c, arg)
6328 /* Switches from the Intel assembler. */
6330 if (strcmp (arg, "ilp64") == 0
6331 || strcmp (arg, "lp64") == 0
6332 || strcmp (arg, "p64") == 0)
6334 md.flags |= EF_IA_64_ABI64;
6336 else if (strcmp (arg, "ilp32") == 0)
6338 md.flags &= ~EF_IA_64_ABI64;
6340 else if (strcmp (arg, "le") == 0)
6342 md.flags &= ~EF_IA_64_BE;
6344 else if (strcmp (arg, "be") == 0)
6346 md.flags |= EF_IA_64_BE;
6353 if (strcmp (arg, "so") == 0)
6355 /* Suppress signon message. */
6357 else if (strcmp (arg, "pi") == 0)
6359 /* Reject privileged instructions. FIXME */
6361 else if (strcmp (arg, "us") == 0)
6363 /* Allow union of signed and unsigned range. FIXME */
6365 else if (strcmp (arg, "close_fcalls") == 0)
6367 /* Do not resolve global function calls. */
6374 /* temp[="prefix"] Insert temporary labels into the object file
6375 symbol table prefixed by "prefix".
6376 Default prefix is ":temp:".
6381 /* indirect=<tgt> Assume unannotated indirect branches behavior
6382 according to <tgt> --
6383 exit: branch out from the current context (default)
6384 labels: all labels in context may be branch targets
6386 if (strncmp (arg, "indirect=", 9) != 0)
6391 /* -X conflicts with an ignored option, use -x instead */
6393 if (!arg || strcmp (arg, "explicit") == 0)
6395 /* set default mode to explicit */
6396 md.default_explicit_mode = 1;
6399 else if (strcmp (arg, "auto") == 0)
6401 md.default_explicit_mode = 0;
6403 else if (strcmp (arg, "debug") == 0)
6407 else if (strcmp (arg, "debugx") == 0)
6409 md.default_explicit_mode = 1;
6414 as_bad (_("Unrecognized option '-x%s'"), arg);
6419 /* nops Print nops statistics. */
6422 /* GNU specific switches for gcc. */
6423 case OPTION_MCONSTANT_GP:
6424 md.flags |= EF_IA_64_CONS_GP;
6427 case OPTION_MAUTO_PIC:
6428 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6439 md_show_usage (stream)
6444 --mconstant-gp mark output file as using the constant-GP model\n\
6445 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6446 --mauto-pic mark output file as using the constant-GP model\n\
6447 without function descriptors (sets ELF header flag\n\
6448 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6449 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6450 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6451 -x | -xexplicit turn on dependency violation checking (default)\n\
6452 -xauto automagically remove dependency violations\n\
6453 -xdebug debug dependency violation checker\n"),
6458 ia64_after_parse_args ()
6460 if (debug_type == DEBUG_STABS)
6461 as_fatal (_("--gstabs is not supported for ia64"));
6464 /* Return true if TYPE fits in TEMPL at SLOT. */
6467 match (int templ, int type, int slot)
6469 enum ia64_unit unit;
6472 unit = ia64_templ_desc[templ].exec_unit[slot];
6475 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6477 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6479 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6480 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6481 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6482 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6483 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6484 default: result = 0; break;
6489 /* Add a bit of extra goodness if a nop of type F or B would fit
6490 in TEMPL at SLOT. */
6493 extra_goodness (int templ, int slot)
6495 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6497 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6502 /* This function is called once, at assembler startup time. It sets
6503 up all the tables, etc. that the MD part of the assembler will need
6504 that can be determined before arguments are parsed. */
6508 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6513 md.explicit_mode = md.default_explicit_mode;
6515 bfd_set_section_alignment (stdoutput, text_section, 4);
6517 target_big_endian = TARGET_BYTES_BIG_ENDIAN;
6518 pseudo_func[FUNC_DTP_MODULE].u.sym =
6519 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6520 &zero_address_frag);
6522 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6523 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6524 &zero_address_frag);
6526 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6527 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6528 &zero_address_frag);
6530 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6531 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6532 &zero_address_frag);
6534 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6535 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6536 &zero_address_frag);
6538 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6539 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6540 &zero_address_frag);
6542 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6543 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6544 &zero_address_frag);
6546 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6547 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6548 &zero_address_frag);
6550 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6551 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6552 &zero_address_frag);
6554 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6555 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6556 &zero_address_frag);
6558 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6559 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6560 &zero_address_frag);
6562 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6563 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6564 &zero_address_frag);
6566 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6567 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6568 &zero_address_frag);
6570 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6571 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6572 &zero_address_frag);
6574 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6575 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6576 &zero_address_frag);
6578 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6579 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6580 &zero_address_frag);
6582 /* Compute the table of best templates. We compute goodness as a
6583 base 4 value, in which each match counts for 3, each F counts
6584 for 2, each B counts for 1. This should maximize the number of
6585 F and B nops in the chosen bundles, which is good because these
6586 pipelines are least likely to be overcommitted. */
6587 for (i = 0; i < IA64_NUM_TYPES; ++i)
6588 for (j = 0; j < IA64_NUM_TYPES; ++j)
6589 for (k = 0; k < IA64_NUM_TYPES; ++k)
6592 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6595 if (match (t, i, 0))
6597 if (match (t, j, 1))
6599 if (match (t, k, 2))
6600 goodness = 3 + 3 + 3;
6602 goodness = 3 + 3 + extra_goodness (t, 2);
6604 else if (match (t, j, 2))
6605 goodness = 3 + 3 + extra_goodness (t, 1);
6609 goodness += extra_goodness (t, 1);
6610 goodness += extra_goodness (t, 2);
6613 else if (match (t, i, 1))
6615 if (match (t, j, 2))
6618 goodness = 3 + extra_goodness (t, 2);
6620 else if (match (t, i, 2))
6621 goodness = 3 + extra_goodness (t, 1);
6623 if (goodness > best)
6626 best_template[i][j][k] = t;
6631 for (i = 0; i < NUM_SLOTS; ++i)
6632 md.slot[i].user_template = -1;
6634 md.pseudo_hash = hash_new ();
6635 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6637 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6638 (void *) (pseudo_opcode + i));
6640 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6641 pseudo_opcode[i].name, err);
6644 md.reg_hash = hash_new ();
6645 md.dynreg_hash = hash_new ();
6646 md.const_hash = hash_new ();
6647 md.entry_hash = hash_new ();
6649 /* general registers: */
6652 for (i = 0; i < total; ++i)
6654 sprintf (name, "r%d", i - REG_GR);
6655 md.regsym[i] = declare_register (name, i);
6658 /* floating point registers: */
6660 for (; i < total; ++i)
6662 sprintf (name, "f%d", i - REG_FR);
6663 md.regsym[i] = declare_register (name, i);
6666 /* application registers: */
6669 for (; i < total; ++i)
6671 sprintf (name, "ar%d", i - REG_AR);
6672 md.regsym[i] = declare_register (name, i);
6675 /* control registers: */
6678 for (; i < total; ++i)
6680 sprintf (name, "cr%d", i - REG_CR);
6681 md.regsym[i] = declare_register (name, i);
6684 /* predicate registers: */
6686 for (; i < total; ++i)
6688 sprintf (name, "p%d", i - REG_P);
6689 md.regsym[i] = declare_register (name, i);
6692 /* branch registers: */
6694 for (; i < total; ++i)
6696 sprintf (name, "b%d", i - REG_BR);
6697 md.regsym[i] = declare_register (name, i);
6700 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6701 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6702 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6703 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6704 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6705 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6706 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6708 for (i = 0; i < NELEMS (indirect_reg); ++i)
6710 regnum = indirect_reg[i].regnum;
6711 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6714 /* define synonyms for application registers: */
6715 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6716 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6717 REG_AR + ar[i - REG_AR].regnum);
6719 /* define synonyms for control registers: */
6720 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6721 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6722 REG_CR + cr[i - REG_CR].regnum);
6724 declare_register ("gp", REG_GR + 1);
6725 declare_register ("sp", REG_GR + 12);
6726 declare_register ("rp", REG_BR + 0);
6728 /* pseudo-registers used to specify unwind info: */
6729 declare_register ("psp", REG_PSP);
6731 declare_register_set ("ret", 4, REG_GR + 8);
6732 declare_register_set ("farg", 8, REG_FR + 8);
6733 declare_register_set ("fret", 8, REG_FR + 8);
6735 for (i = 0; i < NELEMS (const_bits); ++i)
6737 err = hash_insert (md.const_hash, const_bits[i].name,
6738 (PTR) (const_bits + i));
6740 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6744 /* Set the architecture and machine depending on defaults and command line
6746 if (md.flags & EF_IA_64_ABI64)
6747 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6749 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6752 as_warn (_("Could not set architecture and machine"));
6754 /* Set the pointer size and pointer shift size depending on md.flags */
6756 if (md.flags & EF_IA_64_ABI64)
6758 md.pointer_size = 8; /* pointers are 8 bytes */
6759 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6763 md.pointer_size = 4; /* pointers are 4 bytes */
6764 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6767 md.mem_offset.hint = 0;
6770 md.entry_labels = NULL;
6773 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6774 because that is called after md_parse_option which is where we do the
6775 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6776 default endianness. */
6779 ia64_init (argc, argv)
6780 int argc ATTRIBUTE_UNUSED;
6781 char **argv ATTRIBUTE_UNUSED;
6783 md.flags = MD_FLAGS_DEFAULT;
6786 /* Return a string for the target object file format. */
6789 ia64_target_format ()
6791 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6793 if (md.flags & EF_IA_64_BE)
6795 if (md.flags & EF_IA_64_ABI64)
6796 #if defined(TE_AIX50)
6797 return "elf64-ia64-aix-big";
6798 #elif defined(TE_HPUX)
6799 return "elf64-ia64-hpux-big";
6801 return "elf64-ia64-big";
6804 #if defined(TE_AIX50)
6805 return "elf32-ia64-aix-big";
6806 #elif defined(TE_HPUX)
6807 return "elf32-ia64-hpux-big";
6809 return "elf32-ia64-big";
6814 if (md.flags & EF_IA_64_ABI64)
6816 return "elf64-ia64-aix-little";
6818 return "elf64-ia64-little";
6822 return "elf32-ia64-aix-little";
6824 return "elf32-ia64-little";
6829 return "unknown-format";
6833 ia64_end_of_source ()
6835 /* terminate insn group upon reaching end of file: */
6836 insn_group_break (1, 0, 0);
6838 /* emits slots we haven't written yet: */
6839 ia64_flush_insns ();
6841 bfd_set_private_flags (stdoutput, md.flags);
6843 md.mem_offset.hint = 0;
6849 if (md.qp.X_op == O_register)
6850 as_bad ("qualifying predicate not followed by instruction");
6851 md.qp.X_op = O_absent;
6853 if (ignore_input ())
6856 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6858 if (md.detect_dv && !md.explicit_mode)
6859 as_warn (_("Explicit stops are ignored in auto mode"));
6861 insn_group_break (1, 0, 0);
6865 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
6867 static int defining_tag = 0;
6870 ia64_unrecognized_line (ch)
6876 expression (&md.qp);
6877 if (*input_line_pointer++ != ')')
6879 as_bad ("Expected ')'");
6882 if (md.qp.X_op != O_register)
6884 as_bad ("Qualifying predicate expected");
6887 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
6889 as_bad ("Predicate register expected");
6895 if (md.manual_bundling)
6896 as_warn ("Found '{' when manual bundling is already turned on");
6898 CURR_SLOT.manual_bundling_on = 1;
6899 md.manual_bundling = 1;
6901 /* Bundling is only acceptable in explicit mode
6902 or when in default automatic mode. */
6903 if (md.detect_dv && !md.explicit_mode)
6905 if (!md.mode_explicitly_set
6906 && !md.default_explicit_mode)
6909 as_warn (_("Found '{' after explicit switch to automatic mode"));
6914 if (!md.manual_bundling)
6915 as_warn ("Found '}' when manual bundling is off");
6917 PREV_SLOT.manual_bundling_off = 1;
6918 md.manual_bundling = 0;
6920 /* switch back to automatic mode, if applicable */
6923 && !md.mode_explicitly_set
6924 && !md.default_explicit_mode)
6927 /* Allow '{' to follow on the same line. We also allow ";;", but that
6928 happens automatically because ';' is an end of line marker. */
6930 if (input_line_pointer[0] == '{')
6932 input_line_pointer++;
6933 return ia64_unrecognized_line ('{');
6936 demand_empty_rest_of_line ();
6946 if (md.qp.X_op == O_register)
6948 as_bad ("Tag must come before qualifying predicate.");
6952 /* This implements just enough of read_a_source_file in read.c to
6953 recognize labels. */
6954 if (is_name_beginner (*input_line_pointer))
6956 s = input_line_pointer;
6957 c = get_symbol_end ();
6959 else if (LOCAL_LABELS_FB
6960 && ISDIGIT (*input_line_pointer))
6963 while (ISDIGIT (*input_line_pointer))
6964 temp = (temp * 10) + *input_line_pointer++ - '0';
6965 fb_label_instance_inc (temp);
6966 s = fb_label_name (temp, 0);
6967 c = *input_line_pointer;
6976 /* Put ':' back for error messages' sake. */
6977 *input_line_pointer++ = ':';
6978 as_bad ("Expected ':'");
6985 /* Put ':' back for error messages' sake. */
6986 *input_line_pointer++ = ':';
6987 if (*input_line_pointer++ != ']')
6989 as_bad ("Expected ']'");
6994 as_bad ("Tag name expected");
7004 /* Not a valid line. */
7009 ia64_frob_label (sym)
7012 struct label_fix *fix;
7014 /* Tags need special handling since they are not bundle breaks like
7018 fix = obstack_alloc (¬es, sizeof (*fix));
7020 fix->next = CURR_SLOT.tag_fixups;
7021 CURR_SLOT.tag_fixups = fix;
7026 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7028 md.last_text_seg = now_seg;
7029 fix = obstack_alloc (¬es, sizeof (*fix));
7031 fix->next = CURR_SLOT.label_fixups;
7032 CURR_SLOT.label_fixups = fix;
7034 /* Keep track of how many code entry points we've seen. */
7035 if (md.path == md.maxpaths)
7038 md.entry_labels = (const char **)
7039 xrealloc ((void *) md.entry_labels,
7040 md.maxpaths * sizeof (char *));
7042 md.entry_labels[md.path++] = S_GET_NAME (sym);
7047 ia64_flush_pending_output ()
7049 if (!md.keep_pending_output
7050 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7052 /* ??? This causes many unnecessary stop bits to be emitted.
7053 Unfortunately, it isn't clear if it is safe to remove this. */
7054 insn_group_break (1, 0, 0);
7055 ia64_flush_insns ();
7059 /* Do ia64-specific expression optimization. All that's done here is
7060 to transform index expressions that are either due to the indexing
7061 of rotating registers or due to the indexing of indirect register
7064 ia64_optimize_expr (l, op, r)
7073 if (l->X_op == O_register && r->X_op == O_constant)
7075 num_regs = (l->X_add_number >> 16);
7076 if ((unsigned) r->X_add_number >= num_regs)
7079 as_bad ("No current frame");
7081 as_bad ("Index out of range 0..%u", num_regs - 1);
7082 r->X_add_number = 0;
7084 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7087 else if (l->X_op == O_register && r->X_op == O_register)
7089 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7090 || l->X_add_number == IND_MEM)
7092 as_bad ("Indirect register set name expected");
7093 l->X_add_number = IND_CPUID;
7096 l->X_op_symbol = md.regsym[l->X_add_number];
7097 l->X_add_number = r->X_add_number;
7105 ia64_parse_name (name, e)
7109 struct const_desc *cdesc;
7110 struct dynreg *dr = 0;
7111 unsigned int regnum;
7115 /* first see if NAME is a known register name: */
7116 sym = hash_find (md.reg_hash, name);
7119 e->X_op = O_register;
7120 e->X_add_number = S_GET_VALUE (sym);
7124 cdesc = hash_find (md.const_hash, name);
7127 e->X_op = O_constant;
7128 e->X_add_number = cdesc->value;
7132 /* check for inN, locN, or outN: */
7136 if (name[1] == 'n' && ISDIGIT (name[2]))
7144 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7152 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7165 /* The name is inN, locN, or outN; parse the register number. */
7166 regnum = strtoul (name, &end, 10);
7167 if (end > name && *end == '\0')
7169 if ((unsigned) regnum >= dr->num_regs)
7172 as_bad ("No current frame");
7174 as_bad ("Register number out of range 0..%u",
7178 e->X_op = O_register;
7179 e->X_add_number = dr->base + regnum;
7184 if ((dr = hash_find (md.dynreg_hash, name)))
7186 /* We've got ourselves the name of a rotating register set.
7187 Store the base register number in the low 16 bits of
7188 X_add_number and the size of the register set in the top 16
7190 e->X_op = O_register;
7191 e->X_add_number = dr->base | (dr->num_regs << 16);
7197 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7200 ia64_canonicalize_symbol_name (name)
7203 size_t len = strlen (name);
7204 if (len > 1 && name[len - 1] == '#')
7205 name[len - 1] = '\0';
7209 /* Return true if idesc is a conditional branch instruction. This excludes
7210 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7211 because they always read/write resources regardless of the value of the
7212 qualifying predicate. br.ia must always use p0, and hence is always
7213 taken. Thus this function returns true for branches which can fall
7214 through, and which use no resources if they do fall through. */
7217 is_conditional_branch (idesc)
7218 struct ia64_opcode *idesc;
7220 /* br is a conditional branch. Everything that starts with br. except
7221 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7222 Everything that starts with brl is a conditional branch. */
7223 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7224 && (idesc->name[2] == '\0'
7225 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7226 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7227 || idesc->name[2] == 'l'
7228 /* br.cond, br.call, br.clr */
7229 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7230 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7231 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7234 /* Return whether the given opcode is a taken branch. If there's any doubt,
7238 is_taken_branch (idesc)
7239 struct ia64_opcode *idesc;
7241 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7242 || strncmp (idesc->name, "br.ia", 5) == 0);
7245 /* Return whether the given opcode is an interruption or rfi. If there's any
7246 doubt, returns zero. */
7249 is_interruption_or_rfi (idesc)
7250 struct ia64_opcode *idesc;
7252 if (strcmp (idesc->name, "rfi") == 0)
7257 /* Returns the index of the given dependency in the opcode's list of chks, or
7258 -1 if there is no dependency. */
7261 depends_on (depind, idesc)
7263 struct ia64_opcode *idesc;
7266 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7267 for (i = 0; i < dep->nchks; i++)
7269 if (depind == DEP (dep->chks[i]))
7275 /* Determine a set of specific resources used for a particular resource
7276 class. Returns the number of specific resources identified For those
7277 cases which are not determinable statically, the resource returned is
7280 Meanings of value in 'NOTE':
7281 1) only read/write when the register number is explicitly encoded in the
7283 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7284 accesses CFM when qualifying predicate is in the rotating region.
7285 3) general register value is used to specify an indirect register; not
7286 determinable statically.
7287 4) only read the given resource when bits 7:0 of the indirect index
7288 register value does not match the register number of the resource; not
7289 determinable statically.
7290 5) all rules are implementation specific.
7291 6) only when both the index specified by the reader and the index specified
7292 by the writer have the same value in bits 63:61; not determinable
7294 7) only access the specified resource when the corresponding mask bit is
7296 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7297 only read when these insns reference FR2-31
7298 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7299 written when these insns write FR32-127
7300 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7302 11) The target predicates are written independently of PR[qp], but source
7303 registers are only read if PR[qp] is true. Since the state of PR[qp]
7304 cannot statically be determined, all source registers are marked used.
7305 12) This insn only reads the specified predicate register when that
7306 register is the PR[qp].
7307 13) This reference to ld-c only applies to teh GR whose value is loaded
7308 with data returned from memory, not the post-incremented address register.
7309 14) The RSE resource includes the implementation-specific RSE internal
7310 state resources. At least one (and possibly more) of these resources are
7311 read by each instruction listed in IC:rse-readers. At least one (and
7312 possibly more) of these resources are written by each insn listed in
7314 15+16) Represents reserved instructions, which the assembler does not
7317 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7318 this code; there are no dependency violations based on memory access.
7321 #define MAX_SPECS 256
7326 specify_resource (dep, idesc, type, specs, note, path)
7327 const struct ia64_dependency *dep;
7328 struct ia64_opcode *idesc;
7329 int type; /* is this a DV chk or a DV reg? */
7330 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7331 int note; /* resource note for this insn's usage */
7332 int path; /* which execution path to examine */
7339 if (dep->mode == IA64_DV_WAW
7340 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7341 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7344 /* template for any resources we identify */
7345 tmpl.dependency = dep;
7347 tmpl.insn_srlz = tmpl.data_srlz = 0;
7348 tmpl.qp_regno = CURR_SLOT.qp_regno;
7349 tmpl.link_to_qp_branch = 1;
7350 tmpl.mem_offset.hint = 0;
7353 tmpl.cmp_type = CMP_NONE;
7356 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7357 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7358 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7360 /* we don't need to track these */
7361 if (dep->semantics == IA64_DVS_NONE)
7364 switch (dep->specifier)
7369 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7371 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7372 if (regno >= 0 && regno <= 7)
7374 specs[count] = tmpl;
7375 specs[count++].index = regno;
7381 for (i = 0; i < 8; i++)
7383 specs[count] = tmpl;
7384 specs[count++].index = i;
7393 case IA64_RS_AR_UNAT:
7394 /* This is a mov =AR or mov AR= instruction. */
7395 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7397 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7398 if (regno == AR_UNAT)
7400 specs[count++] = tmpl;
7405 /* This is a spill/fill, or other instruction that modifies the
7408 /* Unless we can determine the specific bits used, mark the whole
7409 thing; bits 8:3 of the memory address indicate the bit used in
7410 UNAT. The .mem.offset hint may be used to eliminate a small
7411 subset of conflicts. */
7412 specs[count] = tmpl;
7413 if (md.mem_offset.hint)
7416 fprintf (stderr, " Using hint for spill/fill\n");
7417 /* The index isn't actually used, just set it to something
7418 approximating the bit index. */
7419 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7420 specs[count].mem_offset.hint = 1;
7421 specs[count].mem_offset.offset = md.mem_offset.offset;
7422 specs[count++].mem_offset.base = md.mem_offset.base;
7426 specs[count++].specific = 0;
7434 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7436 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7437 if ((regno >= 8 && regno <= 15)
7438 || (regno >= 20 && regno <= 23)
7439 || (regno >= 31 && regno <= 39)
7440 || (regno >= 41 && regno <= 47)
7441 || (regno >= 67 && regno <= 111))
7443 specs[count] = tmpl;
7444 specs[count++].index = regno;
7457 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7459 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7460 if ((regno >= 48 && regno <= 63)
7461 || (regno >= 112 && regno <= 127))
7463 specs[count] = tmpl;
7464 specs[count++].index = regno;
7470 for (i = 48; i < 64; i++)
7472 specs[count] = tmpl;
7473 specs[count++].index = i;
7475 for (i = 112; i < 128; i++)
7477 specs[count] = tmpl;
7478 specs[count++].index = i;
7496 for (i = 0; i < idesc->num_outputs; i++)
7497 if (idesc->operands[i] == IA64_OPND_B1
7498 || idesc->operands[i] == IA64_OPND_B2)
7500 specs[count] = tmpl;
7501 specs[count++].index =
7502 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7507 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7508 if (idesc->operands[i] == IA64_OPND_B1
7509 || idesc->operands[i] == IA64_OPND_B2)
7511 specs[count] = tmpl;
7512 specs[count++].index =
7513 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7519 case IA64_RS_CPUID: /* four or more registers */
7522 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7524 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7525 if (regno >= 0 && regno < NELEMS (gr_values)
7528 specs[count] = tmpl;
7529 specs[count++].index = gr_values[regno].value & 0xFF;
7533 specs[count] = tmpl;
7534 specs[count++].specific = 0;
7544 case IA64_RS_DBR: /* four or more registers */
7547 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7549 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7550 if (regno >= 0 && regno < NELEMS (gr_values)
7553 specs[count] = tmpl;
7554 specs[count++].index = gr_values[regno].value & 0xFF;
7558 specs[count] = tmpl;
7559 specs[count++].specific = 0;
7563 else if (note == 0 && !rsrc_write)
7565 specs[count] = tmpl;
7566 specs[count++].specific = 0;
7574 case IA64_RS_IBR: /* four or more registers */
7577 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7579 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7580 if (regno >= 0 && regno < NELEMS (gr_values)
7583 specs[count] = tmpl;
7584 specs[count++].index = gr_values[regno].value & 0xFF;
7588 specs[count] = tmpl;
7589 specs[count++].specific = 0;
7602 /* These are implementation specific. Force all references to
7603 conflict with all other references. */
7604 specs[count] = tmpl;
7605 specs[count++].specific = 0;
7613 case IA64_RS_PKR: /* 16 or more registers */
7614 if (note == 3 || note == 4)
7616 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7618 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7619 if (regno >= 0 && regno < NELEMS (gr_values)
7624 specs[count] = tmpl;
7625 specs[count++].index = gr_values[regno].value & 0xFF;
7628 for (i = 0; i < NELEMS (gr_values); i++)
7630 /* Uses all registers *except* the one in R3. */
7631 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7633 specs[count] = tmpl;
7634 specs[count++].index = i;
7640 specs[count] = tmpl;
7641 specs[count++].specific = 0;
7648 specs[count] = tmpl;
7649 specs[count++].specific = 0;
7653 case IA64_RS_PMC: /* four or more registers */
7656 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7657 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7660 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7662 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7663 if (regno >= 0 && regno < NELEMS (gr_values)
7666 specs[count] = tmpl;
7667 specs[count++].index = gr_values[regno].value & 0xFF;
7671 specs[count] = tmpl;
7672 specs[count++].specific = 0;
7682 case IA64_RS_PMD: /* four or more registers */
7685 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7687 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7688 if (regno >= 0 && regno < NELEMS (gr_values)
7691 specs[count] = tmpl;
7692 specs[count++].index = gr_values[regno].value & 0xFF;
7696 specs[count] = tmpl;
7697 specs[count++].specific = 0;
7707 case IA64_RS_RR: /* eight registers */
7710 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7712 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7713 if (regno >= 0 && regno < NELEMS (gr_values)
7716 specs[count] = tmpl;
7717 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7721 specs[count] = tmpl;
7722 specs[count++].specific = 0;
7726 else if (note == 0 && !rsrc_write)
7728 specs[count] = tmpl;
7729 specs[count++].specific = 0;
7737 case IA64_RS_CR_IRR:
7740 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7741 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7743 && idesc->operands[1] == IA64_OPND_CR3
7746 for (i = 0; i < 4; i++)
7748 specs[count] = tmpl;
7749 specs[count++].index = CR_IRR0 + i;
7755 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7756 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7758 && regno <= CR_IRR3)
7760 specs[count] = tmpl;
7761 specs[count++].index = regno;
7770 case IA64_RS_CR_LRR:
7777 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7778 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7779 && (regno == CR_LRR0 || regno == CR_LRR1))
7781 specs[count] = tmpl;
7782 specs[count++].index = regno;
7790 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7792 specs[count] = tmpl;
7793 specs[count++].index =
7794 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7809 else if (rsrc_write)
7811 if (dep->specifier == IA64_RS_FRb
7812 && idesc->operands[0] == IA64_OPND_F1)
7814 specs[count] = tmpl;
7815 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7820 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7822 if (idesc->operands[i] == IA64_OPND_F2
7823 || idesc->operands[i] == IA64_OPND_F3
7824 || idesc->operands[i] == IA64_OPND_F4)
7826 specs[count] = tmpl;
7827 specs[count++].index =
7828 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7837 /* This reference applies only to the GR whose value is loaded with
7838 data returned from memory. */
7839 specs[count] = tmpl;
7840 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7846 for (i = 0; i < idesc->num_outputs; i++)
7847 if (idesc->operands[i] == IA64_OPND_R1
7848 || idesc->operands[i] == IA64_OPND_R2
7849 || idesc->operands[i] == IA64_OPND_R3)
7851 specs[count] = tmpl;
7852 specs[count++].index =
7853 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7855 if (idesc->flags & IA64_OPCODE_POSTINC)
7856 for (i = 0; i < NELEMS (idesc->operands); i++)
7857 if (idesc->operands[i] == IA64_OPND_MR3)
7859 specs[count] = tmpl;
7860 specs[count++].index =
7861 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7866 /* Look for anything that reads a GR. */
7867 for (i = 0; i < NELEMS (idesc->operands); i++)
7869 if (idesc->operands[i] == IA64_OPND_MR3
7870 || idesc->operands[i] == IA64_OPND_CPUID_R3
7871 || idesc->operands[i] == IA64_OPND_DBR_R3
7872 || idesc->operands[i] == IA64_OPND_IBR_R3
7873 || idesc->operands[i] == IA64_OPND_MSR_R3
7874 || idesc->operands[i] == IA64_OPND_PKR_R3
7875 || idesc->operands[i] == IA64_OPND_PMC_R3
7876 || idesc->operands[i] == IA64_OPND_PMD_R3
7877 || idesc->operands[i] == IA64_OPND_RR_R3
7878 || ((i >= idesc->num_outputs)
7879 && (idesc->operands[i] == IA64_OPND_R1
7880 || idesc->operands[i] == IA64_OPND_R2
7881 || idesc->operands[i] == IA64_OPND_R3
7882 /* addl source register. */
7883 || idesc->operands[i] == IA64_OPND_R3_2)))
7885 specs[count] = tmpl;
7886 specs[count++].index =
7887 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7898 /* This is the same as IA64_RS_PRr, except that the register range is
7899 from 1 - 15, and there are no rotating register reads/writes here. */
7903 for (i = 1; i < 16; i++)
7905 specs[count] = tmpl;
7906 specs[count++].index = i;
7912 /* Mark only those registers indicated by the mask. */
7915 mask = CURR_SLOT.opnd[2].X_add_number;
7916 for (i = 1; i < 16; i++)
7917 if (mask & ((valueT) 1 << i))
7919 specs[count] = tmpl;
7920 specs[count++].index = i;
7928 else if (note == 11) /* note 11 implies note 1 as well */
7932 for (i = 0; i < idesc->num_outputs; i++)
7934 if (idesc->operands[i] == IA64_OPND_P1
7935 || idesc->operands[i] == IA64_OPND_P2)
7937 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
7938 if (regno >= 1 && regno < 16)
7940 specs[count] = tmpl;
7941 specs[count++].index = regno;
7951 else if (note == 12)
7953 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
7955 specs[count] = tmpl;
7956 specs[count++].index = CURR_SLOT.qp_regno;
7963 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7964 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7965 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
7966 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
7968 if ((idesc->operands[0] == IA64_OPND_P1
7969 || idesc->operands[0] == IA64_OPND_P2)
7970 && p1 >= 1 && p1 < 16)
7972 specs[count] = tmpl;
7973 specs[count].cmp_type =
7974 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
7975 specs[count++].index = p1;
7977 if ((idesc->operands[1] == IA64_OPND_P1
7978 || idesc->operands[1] == IA64_OPND_P2)
7979 && p2 >= 1 && p2 < 16)
7981 specs[count] = tmpl;
7982 specs[count].cmp_type =
7983 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
7984 specs[count++].index = p2;
7989 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
7991 specs[count] = tmpl;
7992 specs[count++].index = CURR_SLOT.qp_regno;
7994 if (idesc->operands[1] == IA64_OPND_PR)
7996 for (i = 1; i < 16; i++)
7998 specs[count] = tmpl;
7999 specs[count++].index = i;
8010 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8011 simplified cases of this. */
8015 for (i = 16; i < 63; i++)
8017 specs[count] = tmpl;
8018 specs[count++].index = i;
8024 /* Mark only those registers indicated by the mask. */
8026 && idesc->operands[0] == IA64_OPND_PR)
8028 mask = CURR_SLOT.opnd[2].X_add_number;
8029 if (mask & ((valueT) 1 << 16))
8030 for (i = 16; i < 63; i++)
8032 specs[count] = tmpl;
8033 specs[count++].index = i;
8037 && idesc->operands[0] == IA64_OPND_PR_ROT)
8039 for (i = 16; i < 63; i++)
8041 specs[count] = tmpl;
8042 specs[count++].index = i;
8050 else if (note == 11) /* note 11 implies note 1 as well */
8054 for (i = 0; i < idesc->num_outputs; i++)
8056 if (idesc->operands[i] == IA64_OPND_P1
8057 || idesc->operands[i] == IA64_OPND_P2)
8059 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8060 if (regno >= 16 && regno < 63)
8062 specs[count] = tmpl;
8063 specs[count++].index = regno;
8073 else if (note == 12)
8075 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8077 specs[count] = tmpl;
8078 specs[count++].index = CURR_SLOT.qp_regno;
8085 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8086 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8087 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8088 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8090 if ((idesc->operands[0] == IA64_OPND_P1
8091 || idesc->operands[0] == IA64_OPND_P2)
8092 && p1 >= 16 && p1 < 63)
8094 specs[count] = tmpl;
8095 specs[count].cmp_type =
8096 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8097 specs[count++].index = p1;
8099 if ((idesc->operands[1] == IA64_OPND_P1
8100 || idesc->operands[1] == IA64_OPND_P2)
8101 && p2 >= 16 && p2 < 63)
8103 specs[count] = tmpl;
8104 specs[count].cmp_type =
8105 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8106 specs[count++].index = p2;
8111 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8113 specs[count] = tmpl;
8114 specs[count++].index = CURR_SLOT.qp_regno;
8116 if (idesc->operands[1] == IA64_OPND_PR)
8118 for (i = 16; i < 63; i++)
8120 specs[count] = tmpl;
8121 specs[count++].index = i;
8133 /* Verify that the instruction is using the PSR bit indicated in
8137 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8139 if (dep->regindex < 6)
8141 specs[count++] = tmpl;
8144 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8146 if (dep->regindex < 32
8147 || dep->regindex == 35
8148 || dep->regindex == 36
8149 || (!rsrc_write && dep->regindex == PSR_CPL))
8151 specs[count++] = tmpl;
8154 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8156 if (dep->regindex < 32
8157 || dep->regindex == 35
8158 || dep->regindex == 36
8159 || (rsrc_write && dep->regindex == PSR_CPL))
8161 specs[count++] = tmpl;
8166 /* Several PSR bits have very specific dependencies. */
8167 switch (dep->regindex)
8170 specs[count++] = tmpl;
8175 specs[count++] = tmpl;
8179 /* Only certain CR accesses use PSR.ic */
8180 if (idesc->operands[0] == IA64_OPND_CR3
8181 || idesc->operands[1] == IA64_OPND_CR3)
8184 ((idesc->operands[0] == IA64_OPND_CR3)
8187 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8202 specs[count++] = tmpl;
8211 specs[count++] = tmpl;
8215 /* Only some AR accesses use cpl */
8216 if (idesc->operands[0] == IA64_OPND_AR3
8217 || idesc->operands[1] == IA64_OPND_AR3)
8220 ((idesc->operands[0] == IA64_OPND_AR3)
8223 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8230 && regno <= AR_K7))))
8232 specs[count++] = tmpl;
8237 specs[count++] = tmpl;
8247 if (idesc->operands[0] == IA64_OPND_IMMU24)
8249 mask = CURR_SLOT.opnd[0].X_add_number;
8255 if (mask & ((valueT) 1 << dep->regindex))
8257 specs[count++] = tmpl;
8262 int min = dep->regindex == PSR_DFL ? 2 : 32;
8263 int max = dep->regindex == PSR_DFL ? 31 : 127;
8264 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8265 for (i = 0; i < NELEMS (idesc->operands); i++)
8267 if (idesc->operands[i] == IA64_OPND_F1
8268 || idesc->operands[i] == IA64_OPND_F2
8269 || idesc->operands[i] == IA64_OPND_F3
8270 || idesc->operands[i] == IA64_OPND_F4)
8272 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8273 if (reg >= min && reg <= max)
8275 specs[count++] = tmpl;
8282 int min = dep->regindex == PSR_MFL ? 2 : 32;
8283 int max = dep->regindex == PSR_MFL ? 31 : 127;
8284 /* mfh is read on writes to FR32-127; mfl is read on writes to
8286 for (i = 0; i < idesc->num_outputs; i++)
8288 if (idesc->operands[i] == IA64_OPND_F1)
8290 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8291 if (reg >= min && reg <= max)
8293 specs[count++] = tmpl;
8298 else if (note == 10)
8300 for (i = 0; i < NELEMS (idesc->operands); i++)
8302 if (idesc->operands[i] == IA64_OPND_R1
8303 || idesc->operands[i] == IA64_OPND_R2
8304 || idesc->operands[i] == IA64_OPND_R3)
8306 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8307 if (regno >= 16 && regno <= 31)
8309 specs[count++] = tmpl;
8320 case IA64_RS_AR_FPSR:
8321 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8323 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8324 if (regno == AR_FPSR)
8326 specs[count++] = tmpl;
8331 specs[count++] = tmpl;
8336 /* Handle all AR[REG] resources */
8337 if (note == 0 || note == 1)
8339 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8340 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8341 && regno == dep->regindex)
8343 specs[count++] = tmpl;
8345 /* other AR[REG] resources may be affected by AR accesses */
8346 else if (idesc->operands[0] == IA64_OPND_AR3)
8349 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8350 switch (dep->regindex)
8356 if (regno == AR_BSPSTORE)
8358 specs[count++] = tmpl;
8362 (regno == AR_BSPSTORE
8363 || regno == AR_RNAT))
8365 specs[count++] = tmpl;
8370 else if (idesc->operands[1] == IA64_OPND_AR3)
8373 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8374 switch (dep->regindex)
8379 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8381 specs[count++] = tmpl;
8388 specs[count++] = tmpl;
8398 /* Handle all CR[REG] resources */
8399 if (note == 0 || note == 1)
8401 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8403 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8404 if (regno == dep->regindex)
8406 specs[count++] = tmpl;
8408 else if (!rsrc_write)
8410 /* Reads from CR[IVR] affect other resources. */
8411 if (regno == CR_IVR)
8413 if ((dep->regindex >= CR_IRR0
8414 && dep->regindex <= CR_IRR3)
8415 || dep->regindex == CR_TPR)
8417 specs[count++] = tmpl;
8424 specs[count++] = tmpl;
8433 case IA64_RS_INSERVICE:
8434 /* look for write of EOI (67) or read of IVR (65) */
8435 if ((idesc->operands[0] == IA64_OPND_CR3
8436 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8437 || (idesc->operands[1] == IA64_OPND_CR3
8438 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8440 specs[count++] = tmpl;
8447 specs[count++] = tmpl;
8458 specs[count++] = tmpl;
8462 /* Check if any of the registers accessed are in the rotating region.
8463 mov to/from pr accesses CFM only when qp_regno is in the rotating
8465 for (i = 0; i < NELEMS (idesc->operands); i++)
8467 if (idesc->operands[i] == IA64_OPND_R1
8468 || idesc->operands[i] == IA64_OPND_R2
8469 || idesc->operands[i] == IA64_OPND_R3)
8471 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8472 /* Assumes that md.rot.num_regs is always valid */
8473 if (md.rot.num_regs > 0
8475 && num < 31 + md.rot.num_regs)
8477 specs[count] = tmpl;
8478 specs[count++].specific = 0;
8481 else if (idesc->operands[i] == IA64_OPND_F1
8482 || idesc->operands[i] == IA64_OPND_F2
8483 || idesc->operands[i] == IA64_OPND_F3
8484 || idesc->operands[i] == IA64_OPND_F4)
8486 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8489 specs[count] = tmpl;
8490 specs[count++].specific = 0;
8493 else if (idesc->operands[i] == IA64_OPND_P1
8494 || idesc->operands[i] == IA64_OPND_P2)
8496 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8499 specs[count] = tmpl;
8500 specs[count++].specific = 0;
8504 if (CURR_SLOT.qp_regno > 15)
8506 specs[count] = tmpl;
8507 specs[count++].specific = 0;
8512 /* This is the same as IA64_RS_PRr, except simplified to account for
8513 the fact that there is only one register. */
8517 specs[count++] = tmpl;
8522 if (idesc->operands[2] == IA64_OPND_IMM17)
8523 mask = CURR_SLOT.opnd[2].X_add_number;
8524 if (mask & ((valueT) 1 << 63))
8525 specs[count++] = tmpl;
8527 else if (note == 11)
8529 if ((idesc->operands[0] == IA64_OPND_P1
8530 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8531 || (idesc->operands[1] == IA64_OPND_P2
8532 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8534 specs[count++] = tmpl;
8537 else if (note == 12)
8539 if (CURR_SLOT.qp_regno == 63)
8541 specs[count++] = tmpl;
8548 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8549 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8550 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8551 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8554 && (idesc->operands[0] == IA64_OPND_P1
8555 || idesc->operands[0] == IA64_OPND_P2))
8557 specs[count] = tmpl;
8558 specs[count++].cmp_type =
8559 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8562 && (idesc->operands[1] == IA64_OPND_P1
8563 || idesc->operands[1] == IA64_OPND_P2))
8565 specs[count] = tmpl;
8566 specs[count++].cmp_type =
8567 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8572 if (CURR_SLOT.qp_regno == 63)
8574 specs[count++] = tmpl;
8585 /* FIXME we can identify some individual RSE written resources, but RSE
8586 read resources have not yet been completely identified, so for now
8587 treat RSE as a single resource */
8588 if (strncmp (idesc->name, "mov", 3) == 0)
8592 if (idesc->operands[0] == IA64_OPND_AR3
8593 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8595 specs[count] = tmpl;
8596 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8601 if (idesc->operands[0] == IA64_OPND_AR3)
8603 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8604 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8606 specs[count++] = tmpl;
8609 else if (idesc->operands[1] == IA64_OPND_AR3)
8611 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8612 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8613 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8615 specs[count++] = tmpl;
8622 specs[count++] = tmpl;
8627 /* FIXME -- do any of these need to be non-specific? */
8628 specs[count++] = tmpl;
8632 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8639 /* Clear branch flags on marked resources. This breaks the link between the
8640 QP of the marking instruction and a subsequent branch on the same QP. */
8643 clear_qp_branch_flag (mask)
8647 for (i = 0; i < regdepslen; i++)
8649 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8650 if ((bit & mask) != 0)
8652 regdeps[i].link_to_qp_branch = 0;
8657 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8659 Any changes to a PR clears the mutex relations which include that PR. */
8662 clear_qp_mutex (mask)
8668 while (i < qp_mutexeslen)
8670 if ((qp_mutexes[i].prmask & mask) != 0)
8674 fprintf (stderr, " Clearing mutex relation");
8675 print_prmask (qp_mutexes[i].prmask);
8676 fprintf (stderr, "\n");
8678 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8685 /* Clear implies relations which contain PRs in the given masks.
8686 P1_MASK indicates the source of the implies relation, while P2_MASK
8687 indicates the implied PR. */
8690 clear_qp_implies (p1_mask, p2_mask)
8697 while (i < qp_implieslen)
8699 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8700 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8703 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8704 qp_implies[i].p1, qp_implies[i].p2);
8705 qp_implies[i] = qp_implies[--qp_implieslen];
8712 /* Add the PRs specified to the list of implied relations. */
8715 add_qp_imply (p1, p2)
8722 /* p0 is not meaningful here. */
8723 if (p1 == 0 || p2 == 0)
8729 /* If it exists already, ignore it. */
8730 for (i = 0; i < qp_implieslen; i++)
8732 if (qp_implies[i].p1 == p1
8733 && qp_implies[i].p2 == p2
8734 && qp_implies[i].path == md.path
8735 && !qp_implies[i].p2_branched)
8739 if (qp_implieslen == qp_impliestotlen)
8741 qp_impliestotlen += 20;
8742 qp_implies = (struct qp_imply *)
8743 xrealloc ((void *) qp_implies,
8744 qp_impliestotlen * sizeof (struct qp_imply));
8747 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8748 qp_implies[qp_implieslen].p1 = p1;
8749 qp_implies[qp_implieslen].p2 = p2;
8750 qp_implies[qp_implieslen].path = md.path;
8751 qp_implies[qp_implieslen++].p2_branched = 0;
8753 /* Add in the implied transitive relations; for everything that p2 implies,
8754 make p1 imply that, too; for everything that implies p1, make it imply p2
8756 for (i = 0; i < qp_implieslen; i++)
8758 if (qp_implies[i].p1 == p2)
8759 add_qp_imply (p1, qp_implies[i].p2);
8760 if (qp_implies[i].p2 == p1)
8761 add_qp_imply (qp_implies[i].p1, p2);
8763 /* Add in mutex relations implied by this implies relation; for each mutex
8764 relation containing p2, duplicate it and replace p2 with p1. */
8765 bit = (valueT) 1 << p1;
8766 mask = (valueT) 1 << p2;
8767 for (i = 0; i < qp_mutexeslen; i++)
8769 if (qp_mutexes[i].prmask & mask)
8770 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8774 /* Add the PRs specified in the mask to the mutex list; this means that only
8775 one of the PRs can be true at any time. PR0 should never be included in
8785 if (qp_mutexeslen == qp_mutexestotlen)
8787 qp_mutexestotlen += 20;
8788 qp_mutexes = (struct qpmutex *)
8789 xrealloc ((void *) qp_mutexes,
8790 qp_mutexestotlen * sizeof (struct qpmutex));
8794 fprintf (stderr, " Registering mutex on");
8795 print_prmask (mask);
8796 fprintf (stderr, "\n");
8798 qp_mutexes[qp_mutexeslen].path = md.path;
8799 qp_mutexes[qp_mutexeslen++].prmask = mask;
8803 has_suffix_p (name, suffix)
8807 size_t namelen = strlen (name);
8808 size_t sufflen = strlen (suffix);
8810 if (namelen <= sufflen)
8812 return strcmp (name + namelen - sufflen, suffix) == 0;
8816 clear_register_values ()
8820 fprintf (stderr, " Clearing register values\n");
8821 for (i = 1; i < NELEMS (gr_values); i++)
8822 gr_values[i].known = 0;
8825 /* Keep track of register values/changes which affect DV tracking.
8827 optimization note: should add a flag to classes of insns where otherwise we
8828 have to examine a group of strings to identify them. */
8831 note_register_values (idesc)
8832 struct ia64_opcode *idesc;
8834 valueT qp_changemask = 0;
8837 /* Invalidate values for registers being written to. */
8838 for (i = 0; i < idesc->num_outputs; i++)
8840 if (idesc->operands[i] == IA64_OPND_R1
8841 || idesc->operands[i] == IA64_OPND_R2
8842 || idesc->operands[i] == IA64_OPND_R3)
8844 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8845 if (regno > 0 && regno < NELEMS (gr_values))
8846 gr_values[regno].known = 0;
8848 else if (idesc->operands[i] == IA64_OPND_R3_2)
8850 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8851 if (regno > 0 && regno < 4)
8852 gr_values[regno].known = 0;
8854 else if (idesc->operands[i] == IA64_OPND_P1
8855 || idesc->operands[i] == IA64_OPND_P2)
8857 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8858 qp_changemask |= (valueT) 1 << regno;
8860 else if (idesc->operands[i] == IA64_OPND_PR)
8862 if (idesc->operands[2] & (valueT) 0x10000)
8863 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
8865 qp_changemask = idesc->operands[2];
8868 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
8870 if (idesc->operands[1] & ((valueT) 1 << 43))
8871 qp_changemask = ~(valueT) 0xFFFFFFFFFFF | idesc->operands[1];
8873 qp_changemask = idesc->operands[1];
8874 qp_changemask &= ~(valueT) 0xFFFF;
8879 /* Always clear qp branch flags on any PR change. */
8880 /* FIXME there may be exceptions for certain compares. */
8881 clear_qp_branch_flag (qp_changemask);
8883 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
8884 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
8886 qp_changemask |= ~(valueT) 0xFFFF;
8887 if (strcmp (idesc->name, "clrrrb.pr") != 0)
8889 for (i = 32; i < 32 + md.rot.num_regs; i++)
8890 gr_values[i].known = 0;
8892 clear_qp_mutex (qp_changemask);
8893 clear_qp_implies (qp_changemask, qp_changemask);
8895 /* After a call, all register values are undefined, except those marked
8897 else if (strncmp (idesc->name, "br.call", 6) == 0
8898 || strncmp (idesc->name, "brl.call", 7) == 0)
8900 /* FIXME keep GR values which are marked as "safe_across_calls" */
8901 clear_register_values ();
8902 clear_qp_mutex (~qp_safe_across_calls);
8903 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
8904 clear_qp_branch_flag (~qp_safe_across_calls);
8906 else if (is_interruption_or_rfi (idesc)
8907 || is_taken_branch (idesc))
8909 clear_register_values ();
8910 clear_qp_mutex (~(valueT) 0);
8911 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
8913 /* Look for mutex and implies relations. */
8914 else if ((idesc->operands[0] == IA64_OPND_P1
8915 || idesc->operands[0] == IA64_OPND_P2)
8916 && (idesc->operands[1] == IA64_OPND_P1
8917 || idesc->operands[1] == IA64_OPND_P2))
8919 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8920 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8921 valueT p1mask = (valueT) 1 << p1;
8922 valueT p2mask = (valueT) 1 << p2;
8924 /* If one of the PRs is PR0, we can't really do anything. */
8925 if (p1 == 0 || p2 == 0)
8928 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
8930 /* In general, clear mutexes and implies which include P1 or P2,
8931 with the following exceptions. */
8932 else if (has_suffix_p (idesc->name, ".or.andcm")
8933 || has_suffix_p (idesc->name, ".and.orcm"))
8935 add_qp_mutex (p1mask | p2mask);
8936 clear_qp_implies (p2mask, p1mask);
8938 else if (has_suffix_p (idesc->name, ".andcm")
8939 || has_suffix_p (idesc->name, ".and"))
8941 clear_qp_implies (0, p1mask | p2mask);
8943 else if (has_suffix_p (idesc->name, ".orcm")
8944 || has_suffix_p (idesc->name, ".or"))
8946 clear_qp_mutex (p1mask | p2mask);
8947 clear_qp_implies (p1mask | p2mask, 0);
8951 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
8952 if (has_suffix_p (idesc->name, ".unc"))
8954 add_qp_mutex (p1mask | p2mask);
8955 if (CURR_SLOT.qp_regno != 0)
8957 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
8958 CURR_SLOT.qp_regno);
8959 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
8960 CURR_SLOT.qp_regno);
8963 else if (CURR_SLOT.qp_regno == 0)
8965 add_qp_mutex (p1mask | p2mask);
8969 clear_qp_mutex (p1mask | p2mask);
8973 /* Look for mov imm insns into GRs. */
8974 else if (idesc->operands[0] == IA64_OPND_R1
8975 && (idesc->operands[1] == IA64_OPND_IMM22
8976 || idesc->operands[1] == IA64_OPND_IMMU64)
8977 && (strcmp (idesc->name, "mov") == 0
8978 || strcmp (idesc->name, "movl") == 0))
8980 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8981 if (regno > 0 && regno < NELEMS (gr_values))
8983 gr_values[regno].known = 1;
8984 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
8985 gr_values[regno].path = md.path;
8988 fprintf (stderr, " Know gr%d = ", regno);
8989 fprintf_vma (stderr, gr_values[regno].value);
8990 fputs ("\n", stderr);
8996 clear_qp_mutex (qp_changemask);
8997 clear_qp_implies (qp_changemask, qp_changemask);
9001 /* Return whether the given predicate registers are currently mutex. */
9004 qp_mutex (p1, p2, path)
9014 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9015 for (i = 0; i < qp_mutexeslen; i++)
9017 if (qp_mutexes[i].path >= path
9018 && (qp_mutexes[i].prmask & mask) == mask)
9025 /* Return whether the given resource is in the given insn's list of chks
9026 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9030 resources_match (rs, idesc, note, qp_regno, path)
9032 struct ia64_opcode *idesc;
9037 struct rsrc specs[MAX_SPECS];
9040 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9041 we don't need to check. One exception is note 11, which indicates that
9042 target predicates are written regardless of PR[qp]. */
9043 if (qp_mutex (rs->qp_regno, qp_regno, path)
9047 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9050 /* UNAT checking is a bit more specific than other resources */
9051 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9052 && specs[count].mem_offset.hint
9053 && rs->mem_offset.hint)
9055 if (rs->mem_offset.base == specs[count].mem_offset.base)
9057 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9058 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9065 /* Skip apparent PR write conflicts where both writes are an AND or both
9066 writes are an OR. */
9067 if (rs->dependency->specifier == IA64_RS_PR
9068 || rs->dependency->specifier == IA64_RS_PRr
9069 || rs->dependency->specifier == IA64_RS_PR63)
9071 if (specs[count].cmp_type != CMP_NONE
9072 && specs[count].cmp_type == rs->cmp_type)
9075 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9076 dv_mode[rs->dependency->mode],
9077 rs->dependency->specifier != IA64_RS_PR63 ?
9078 specs[count].index : 63);
9083 " %s on parallel compare conflict %s vs %s on PR%d\n",
9084 dv_mode[rs->dependency->mode],
9085 dv_cmp_type[rs->cmp_type],
9086 dv_cmp_type[specs[count].cmp_type],
9087 rs->dependency->specifier != IA64_RS_PR63 ?
9088 specs[count].index : 63);
9092 /* If either resource is not specific, conservatively assume a conflict
9094 if (!specs[count].specific || !rs->specific)
9096 else if (specs[count].index == rs->index)
9101 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9107 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9108 insert a stop to create the break. Update all resource dependencies
9109 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9110 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9111 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9115 insn_group_break (insert_stop, qp_regno, save_current)
9122 if (insert_stop && md.num_slots_in_use > 0)
9123 PREV_SLOT.end_of_insn_group = 1;
9127 fprintf (stderr, " Insn group break%s",
9128 (insert_stop ? " (w/stop)" : ""));
9130 fprintf (stderr, " effective for QP=%d", qp_regno);
9131 fprintf (stderr, "\n");
9135 while (i < regdepslen)
9137 const struct ia64_dependency *dep = regdeps[i].dependency;
9140 && regdeps[i].qp_regno != qp_regno)
9147 && CURR_SLOT.src_file == regdeps[i].file
9148 && CURR_SLOT.src_line == regdeps[i].line)
9154 /* clear dependencies which are automatically cleared by a stop, or
9155 those that have reached the appropriate state of insn serialization */
9156 if (dep->semantics == IA64_DVS_IMPLIED
9157 || dep->semantics == IA64_DVS_IMPLIEDF
9158 || regdeps[i].insn_srlz == STATE_SRLZ)
9160 print_dependency ("Removing", i);
9161 regdeps[i] = regdeps[--regdepslen];
9165 if (dep->semantics == IA64_DVS_DATA
9166 || dep->semantics == IA64_DVS_INSTR
9167 || dep->semantics == IA64_DVS_SPECIFIC)
9169 if (regdeps[i].insn_srlz == STATE_NONE)
9170 regdeps[i].insn_srlz = STATE_STOP;
9171 if (regdeps[i].data_srlz == STATE_NONE)
9172 regdeps[i].data_srlz = STATE_STOP;
9179 /* Add the given resource usage spec to the list of active dependencies. */
9182 mark_resource (idesc, dep, spec, depind, path)
9183 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9184 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9189 if (regdepslen == regdepstotlen)
9191 regdepstotlen += 20;
9192 regdeps = (struct rsrc *)
9193 xrealloc ((void *) regdeps,
9194 regdepstotlen * sizeof (struct rsrc));
9197 regdeps[regdepslen] = *spec;
9198 regdeps[regdepslen].depind = depind;
9199 regdeps[regdepslen].path = path;
9200 regdeps[regdepslen].file = CURR_SLOT.src_file;
9201 regdeps[regdepslen].line = CURR_SLOT.src_line;
9203 print_dependency ("Adding", regdepslen);
9209 print_dependency (action, depind)
9215 fprintf (stderr, " %s %s '%s'",
9216 action, dv_mode[(regdeps[depind].dependency)->mode],
9217 (regdeps[depind].dependency)->name);
9218 if (regdeps[depind].specific && regdeps[depind].index != 0)
9219 fprintf (stderr, " (%d)", regdeps[depind].index);
9220 if (regdeps[depind].mem_offset.hint)
9222 fputs (" ", stderr);
9223 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9224 fputs ("+", stderr);
9225 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9227 fprintf (stderr, "\n");
9232 instruction_serialization ()
9236 fprintf (stderr, " Instruction serialization\n");
9237 for (i = 0; i < regdepslen; i++)
9238 if (regdeps[i].insn_srlz == STATE_STOP)
9239 regdeps[i].insn_srlz = STATE_SRLZ;
9243 data_serialization ()
9247 fprintf (stderr, " Data serialization\n");
9248 while (i < regdepslen)
9250 if (regdeps[i].data_srlz == STATE_STOP
9251 /* Note: as of 991210, all "other" dependencies are cleared by a
9252 data serialization. This might change with new tables */
9253 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9255 print_dependency ("Removing", i);
9256 regdeps[i] = regdeps[--regdepslen];
9263 /* Insert stops and serializations as needed to avoid DVs. */
9266 remove_marked_resource (rs)
9269 switch (rs->dependency->semantics)
9271 case IA64_DVS_SPECIFIC:
9273 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9274 /* ...fall through... */
9275 case IA64_DVS_INSTR:
9277 fprintf (stderr, "Inserting instr serialization\n");
9278 if (rs->insn_srlz < STATE_STOP)
9279 insn_group_break (1, 0, 0);
9280 if (rs->insn_srlz < STATE_SRLZ)
9282 int oldqp = CURR_SLOT.qp_regno;
9283 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9284 /* Manually jam a srlz.i insn into the stream */
9285 CURR_SLOT.qp_regno = 0;
9286 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9287 instruction_serialization ();
9288 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9289 if (++md.num_slots_in_use >= NUM_SLOTS)
9291 CURR_SLOT.qp_regno = oldqp;
9292 CURR_SLOT.idesc = oldidesc;
9294 insn_group_break (1, 0, 0);
9296 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9297 "other" types of DV are eliminated
9298 by a data serialization */
9301 fprintf (stderr, "Inserting data serialization\n");
9302 if (rs->data_srlz < STATE_STOP)
9303 insn_group_break (1, 0, 0);
9305 int oldqp = CURR_SLOT.qp_regno;
9306 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9307 /* Manually jam a srlz.d insn into the stream */
9308 CURR_SLOT.qp_regno = 0;
9309 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9310 data_serialization ();
9311 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9312 if (++md.num_slots_in_use >= NUM_SLOTS)
9314 CURR_SLOT.qp_regno = oldqp;
9315 CURR_SLOT.idesc = oldidesc;
9318 case IA64_DVS_IMPLIED:
9319 case IA64_DVS_IMPLIEDF:
9321 fprintf (stderr, "Inserting stop\n");
9322 insn_group_break (1, 0, 0);
9329 /* Check the resources used by the given opcode against the current dependency
9332 The check is run once for each execution path encountered. In this case,
9333 a unique execution path is the sequence of instructions following a code
9334 entry point, e.g. the following has three execution paths, one starting
9335 at L0, one at L1, and one at L2.
9344 check_dependencies (idesc)
9345 struct ia64_opcode *idesc;
9347 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9351 /* Note that the number of marked resources may change within the
9352 loop if in auto mode. */
9354 while (i < regdepslen)
9356 struct rsrc *rs = ®deps[i];
9357 const struct ia64_dependency *dep = rs->dependency;
9362 if (dep->semantics == IA64_DVS_NONE
9363 || (chkind = depends_on (rs->depind, idesc)) == -1)
9369 note = NOTE (opdeps->chks[chkind]);
9371 /* Check this resource against each execution path seen thus far. */
9372 for (path = 0; path <= md.path; path++)
9376 /* If the dependency wasn't on the path being checked, ignore it. */
9377 if (rs->path < path)
9380 /* If the QP for this insn implies a QP which has branched, don't
9381 bother checking. Ed. NOTE: I don't think this check is terribly
9382 useful; what's the point of generating code which will only be
9383 reached if its QP is zero?
9384 This code was specifically inserted to handle the following code,
9385 based on notes from Intel's DV checking code, where p1 implies p2.
9391 if (CURR_SLOT.qp_regno != 0)
9395 for (implies = 0; implies < qp_implieslen; implies++)
9397 if (qp_implies[implies].path >= path
9398 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9399 && qp_implies[implies].p2_branched)
9409 if ((matchtype = resources_match (rs, idesc, note,
9410 CURR_SLOT.qp_regno, path)) != 0)
9413 char pathmsg[256] = "";
9414 char indexmsg[256] = "";
9415 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9418 sprintf (pathmsg, " when entry is at label '%s'",
9419 md.entry_labels[path - 1]);
9420 if (rs->specific && rs->index != 0)
9421 sprintf (indexmsg, ", specific resource number is %d",
9423 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9425 (certain ? "violates" : "may violate"),
9426 dv_mode[dep->mode], dep->name,
9427 dv_sem[dep->semantics],
9430 if (md.explicit_mode)
9432 as_warn ("%s", msg);
9434 as_warn (_("Only the first path encountering the conflict "
9436 as_warn_where (rs->file, rs->line,
9437 _("This is the location of the "
9438 "conflicting usage"));
9439 /* Don't bother checking other paths, to avoid duplicating
9446 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9448 remove_marked_resource (rs);
9450 /* since the set of dependencies has changed, start over */
9451 /* FIXME -- since we're removing dvs as we go, we
9452 probably don't really need to start over... */
9465 /* Register new dependencies based on the given opcode. */
9468 mark_resources (idesc)
9469 struct ia64_opcode *idesc;
9472 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9473 int add_only_qp_reads = 0;
9475 /* A conditional branch only uses its resources if it is taken; if it is
9476 taken, we stop following that path. The other branch types effectively
9477 *always* write their resources. If it's not taken, register only QP
9479 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9481 add_only_qp_reads = 1;
9485 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9487 for (i = 0; i < opdeps->nregs; i++)
9489 const struct ia64_dependency *dep;
9490 struct rsrc specs[MAX_SPECS];
9495 dep = ia64_find_dependency (opdeps->regs[i]);
9496 note = NOTE (opdeps->regs[i]);
9498 if (add_only_qp_reads
9499 && !(dep->mode == IA64_DV_WAR
9500 && (dep->specifier == IA64_RS_PR
9501 || dep->specifier == IA64_RS_PRr
9502 || dep->specifier == IA64_RS_PR63)))
9505 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9508 if (md.debug_dv && !count)
9509 fprintf (stderr, " No %s %s usage found (path %d)\n",
9510 dv_mode[dep->mode], dep->name, md.path);
9515 mark_resource (idesc, dep, &specs[count],
9516 DEP (opdeps->regs[i]), md.path);
9519 /* The execution path may affect register values, which may in turn
9520 affect which indirect-access resources are accessed. */
9521 switch (dep->specifier)
9533 for (path = 0; path < md.path; path++)
9535 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9537 mark_resource (idesc, dep, &specs[count],
9538 DEP (opdeps->regs[i]), path);
9545 /* Remove dependencies when they no longer apply. */
9548 update_dependencies (idesc)
9549 struct ia64_opcode *idesc;
9553 if (strcmp (idesc->name, "srlz.i") == 0)
9555 instruction_serialization ();
9557 else if (strcmp (idesc->name, "srlz.d") == 0)
9559 data_serialization ();
9561 else if (is_interruption_or_rfi (idesc)
9562 || is_taken_branch (idesc))
9564 /* Although technically the taken branch doesn't clear dependencies
9565 which require a srlz.[id], we don't follow the branch; the next
9566 instruction is assumed to start with a clean slate. */
9570 else if (is_conditional_branch (idesc)
9571 && CURR_SLOT.qp_regno != 0)
9573 int is_call = strstr (idesc->name, ".call") != NULL;
9575 for (i = 0; i < qp_implieslen; i++)
9577 /* If the conditional branch's predicate is implied by the predicate
9578 in an existing dependency, remove that dependency. */
9579 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9582 /* Note that this implied predicate takes a branch so that if
9583 a later insn generates a DV but its predicate implies this
9584 one, we can avoid the false DV warning. */
9585 qp_implies[i].p2_branched = 1;
9586 while (depind < regdepslen)
9588 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9590 print_dependency ("Removing", depind);
9591 regdeps[depind] = regdeps[--regdepslen];
9598 /* Any marked resources which have this same predicate should be
9599 cleared, provided that the QP hasn't been modified between the
9600 marking instruction and the branch. */
9603 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9608 while (i < regdepslen)
9610 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9611 && regdeps[i].link_to_qp_branch
9612 && (regdeps[i].file != CURR_SLOT.src_file
9613 || regdeps[i].line != CURR_SLOT.src_line))
9615 /* Treat like a taken branch */
9616 print_dependency ("Removing", i);
9617 regdeps[i] = regdeps[--regdepslen];
9626 /* Examine the current instruction for dependency violations. */
9630 struct ia64_opcode *idesc;
9634 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9635 idesc->name, CURR_SLOT.src_line,
9636 idesc->dependencies->nchks,
9637 idesc->dependencies->nregs);
9640 /* Look through the list of currently marked resources; if the current
9641 instruction has the dependency in its chks list which uses that resource,
9642 check against the specific resources used. */
9643 check_dependencies (idesc);
9645 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9646 then add them to the list of marked resources. */
9647 mark_resources (idesc);
9649 /* There are several types of dependency semantics, and each has its own
9650 requirements for being cleared
9652 Instruction serialization (insns separated by interruption, rfi, or
9653 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9655 Data serialization (instruction serialization, or writer + srlz.d +
9656 reader, where writer and srlz.d are in separate groups) clears
9657 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9658 always be the case).
9660 Instruction group break (groups separated by stop, taken branch,
9661 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9663 update_dependencies (idesc);
9665 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9666 warning. Keep track of as many as possible that are useful. */
9667 note_register_values (idesc);
9669 /* We don't need or want this anymore. */
9670 md.mem_offset.hint = 0;
9675 /* Translate one line of assembly. Pseudo ops and labels do not show
9681 char *saved_input_line_pointer, *mnemonic;
9682 const struct pseudo_opcode *pdesc;
9683 struct ia64_opcode *idesc;
9684 unsigned char qp_regno;
9688 saved_input_line_pointer = input_line_pointer;
9689 input_line_pointer = str;
9691 /* extract the opcode (mnemonic): */
9693 mnemonic = input_line_pointer;
9694 ch = get_symbol_end ();
9695 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9698 *input_line_pointer = ch;
9699 (*pdesc->handler) (pdesc->arg);
9703 /* Find the instruction descriptor matching the arguments. */
9705 idesc = ia64_find_opcode (mnemonic);
9706 *input_line_pointer = ch;
9709 as_bad ("Unknown opcode `%s'", mnemonic);
9713 idesc = parse_operands (idesc);
9717 /* Handle the dynamic ops we can handle now: */
9718 if (idesc->type == IA64_TYPE_DYN)
9720 if (strcmp (idesc->name, "add") == 0)
9722 if (CURR_SLOT.opnd[2].X_op == O_register
9723 && CURR_SLOT.opnd[2].X_add_number < 4)
9727 ia64_free_opcode (idesc);
9728 idesc = ia64_find_opcode (mnemonic);
9730 know (!idesc->next);
9733 else if (strcmp (idesc->name, "mov") == 0)
9735 enum ia64_opnd opnd1, opnd2;
9738 opnd1 = idesc->operands[0];
9739 opnd2 = idesc->operands[1];
9740 if (opnd1 == IA64_OPND_AR3)
9742 else if (opnd2 == IA64_OPND_AR3)
9746 if (CURR_SLOT.opnd[rop].X_op == O_register
9747 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9751 ia64_free_opcode (idesc);
9752 idesc = ia64_find_opcode (mnemonic);
9753 while (idesc != NULL
9754 && (idesc->operands[0] != opnd1
9755 || idesc->operands[1] != opnd2))
9756 idesc = get_next_opcode (idesc);
9761 if (md.qp.X_op == O_register)
9763 qp_regno = md.qp.X_add_number - REG_P;
9764 md.qp.X_op = O_absent;
9767 flags = idesc->flags;
9769 if ((flags & IA64_OPCODE_FIRST) != 0)
9770 insn_group_break (1, 0, 0);
9772 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
9774 as_bad ("`%s' cannot be predicated", idesc->name);
9778 /* Build the instruction. */
9779 CURR_SLOT.qp_regno = qp_regno;
9780 CURR_SLOT.idesc = idesc;
9781 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
9782 dwarf2_where (&CURR_SLOT.debug_line);
9784 /* Add unwind entry, if there is one. */
9785 if (unwind.current_entry)
9787 CURR_SLOT.unwind_record = unwind.current_entry;
9788 unwind.current_entry = NULL;
9791 /* Check for dependency violations. */
9795 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9796 if (++md.num_slots_in_use >= NUM_SLOTS)
9799 if ((flags & IA64_OPCODE_LAST) != 0)
9800 insn_group_break (1, 0, 0);
9802 md.last_text_seg = now_seg;
9805 input_line_pointer = saved_input_line_pointer;
9808 /* Called when symbol NAME cannot be found in the symbol table.
9809 Should be used for dynamic valued symbols only. */
9812 md_undefined_symbol (name)
9813 char *name ATTRIBUTE_UNUSED;
9818 /* Called for any expression that can not be recognized. When the
9819 function is called, `input_line_pointer' will point to the start of
9826 enum pseudo_type pseudo_type;
9831 switch (*input_line_pointer)
9834 /* Find what relocation pseudo-function we're dealing with. */
9836 ch = *++input_line_pointer;
9837 for (i = 0; i < NELEMS (pseudo_func); ++i)
9838 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
9840 len = strlen (pseudo_func[i].name);
9841 if (strncmp (pseudo_func[i].name + 1,
9842 input_line_pointer + 1, len - 1) == 0
9843 && !is_part_of_name (input_line_pointer[len]))
9845 input_line_pointer += len;
9846 pseudo_type = pseudo_func[i].type;
9850 switch (pseudo_type)
9852 case PSEUDO_FUNC_RELOC:
9854 if (*input_line_pointer != '(')
9856 as_bad ("Expected '('");
9860 ++input_line_pointer;
9862 if (*input_line_pointer++ != ')')
9864 as_bad ("Missing ')'");
9867 if (e->X_op != O_symbol)
9869 if (e->X_op != O_pseudo_fixup)
9871 as_bad ("Not a symbolic expression");
9874 if (i != FUNC_LT_RELATIVE)
9876 as_bad ("Illegal combination of relocation functions");
9879 switch (S_GET_VALUE (e->X_op_symbol))
9881 case FUNC_FPTR_RELATIVE:
9882 i = FUNC_LT_FPTR_RELATIVE; break;
9883 case FUNC_DTP_MODULE:
9884 i = FUNC_LT_DTP_MODULE; break;
9885 case FUNC_DTP_RELATIVE:
9886 i = FUNC_LT_DTP_RELATIVE; break;
9887 case FUNC_TP_RELATIVE:
9888 i = FUNC_LT_TP_RELATIVE; break;
9890 as_bad ("Illegal combination of relocation functions");
9894 /* Make sure gas doesn't get rid of local symbols that are used
9896 e->X_op = O_pseudo_fixup;
9897 e->X_op_symbol = pseudo_func[i].u.sym;
9900 case PSEUDO_FUNC_CONST:
9901 e->X_op = O_constant;
9902 e->X_add_number = pseudo_func[i].u.ival;
9905 case PSEUDO_FUNC_REG:
9906 e->X_op = O_register;
9907 e->X_add_number = pseudo_func[i].u.ival;
9911 name = input_line_pointer - 1;
9913 as_bad ("Unknown pseudo function `%s'", name);
9919 ++input_line_pointer;
9921 if (*input_line_pointer != ']')
9923 as_bad ("Closing bracket misssing");
9928 if (e->X_op != O_register)
9929 as_bad ("Register expected as index");
9931 ++input_line_pointer;
9942 ignore_rest_of_line ();
9945 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
9946 a section symbol plus some offset. For relocs involving @fptr(),
9947 directives we don't want such adjustments since we need to have the
9948 original symbol's name in the reloc. */
9950 ia64_fix_adjustable (fix)
9953 /* Prevent all adjustments to global symbols */
9954 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
9957 switch (fix->fx_r_type)
9959 case BFD_RELOC_IA64_FPTR64I:
9960 case BFD_RELOC_IA64_FPTR32MSB:
9961 case BFD_RELOC_IA64_FPTR32LSB:
9962 case BFD_RELOC_IA64_FPTR64MSB:
9963 case BFD_RELOC_IA64_FPTR64LSB:
9964 case BFD_RELOC_IA64_LTOFF_FPTR22:
9965 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9975 ia64_force_relocation (fix)
9978 switch (fix->fx_r_type)
9980 case BFD_RELOC_IA64_FPTR64I:
9981 case BFD_RELOC_IA64_FPTR32MSB:
9982 case BFD_RELOC_IA64_FPTR32LSB:
9983 case BFD_RELOC_IA64_FPTR64MSB:
9984 case BFD_RELOC_IA64_FPTR64LSB:
9986 case BFD_RELOC_IA64_LTOFF22:
9987 case BFD_RELOC_IA64_LTOFF64I:
9988 case BFD_RELOC_IA64_LTOFF_FPTR22:
9989 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9990 case BFD_RELOC_IA64_PLTOFF22:
9991 case BFD_RELOC_IA64_PLTOFF64I:
9992 case BFD_RELOC_IA64_PLTOFF64MSB:
9993 case BFD_RELOC_IA64_PLTOFF64LSB:
10000 return S_FORCE_RELOC (fix->fx_addsy);
10003 /* Decide from what point a pc-relative relocation is relative to,
10004 relative to the pc-relative fixup. Er, relatively speaking. */
10006 ia64_pcrel_from_section (fix, sec)
10010 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10012 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10018 /* This is called whenever some data item (not an instruction) needs a
10019 fixup. We pick the right reloc code depending on the byteorder
10020 currently in effect. */
10022 ia64_cons_fix_new (f, where, nbytes, exp)
10028 bfd_reloc_code_real_type code;
10033 /* There are no reloc for 8 and 16 bit quantities, but we allow
10034 them here since they will work fine as long as the expression
10035 is fully defined at the end of the pass over the source file. */
10036 case 1: code = BFD_RELOC_8; break;
10037 case 2: code = BFD_RELOC_16; break;
10039 if (target_big_endian)
10040 code = BFD_RELOC_IA64_DIR32MSB;
10042 code = BFD_RELOC_IA64_DIR32LSB;
10046 /* In 32-bit mode, data8 could mean function descriptors too. */
10047 if (exp->X_op == O_pseudo_fixup
10048 && exp->X_op_symbol
10049 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10050 && !(md.flags & EF_IA_64_ABI64))
10052 if (target_big_endian)
10053 code = BFD_RELOC_IA64_IPLTMSB;
10055 code = BFD_RELOC_IA64_IPLTLSB;
10056 exp->X_op = O_symbol;
10061 if (target_big_endian)
10062 code = BFD_RELOC_IA64_DIR64MSB;
10064 code = BFD_RELOC_IA64_DIR64LSB;
10069 if (exp->X_op == O_pseudo_fixup
10070 && exp->X_op_symbol
10071 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10073 if (target_big_endian)
10074 code = BFD_RELOC_IA64_IPLTMSB;
10076 code = BFD_RELOC_IA64_IPLTLSB;
10078 exp->X_op = O_symbol;
10084 as_bad ("Unsupported fixup size %d", nbytes);
10085 ignore_rest_of_line ();
10088 if (exp->X_op == O_pseudo_fixup)
10091 exp->X_op = O_symbol;
10092 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10095 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10096 /* We need to store the byte order in effect in case we're going
10097 to fix an 8 or 16 bit relocation (for which there no real
10098 relocs available). See md_apply_fix3(). */
10099 fix->tc_fix_data.bigendian = target_big_endian;
10102 /* Return the actual relocation we wish to associate with the pseudo
10103 reloc described by SYM and R_TYPE. SYM should be one of the
10104 symbols in the pseudo_func array, or NULL. */
10106 static bfd_reloc_code_real_type
10107 ia64_gen_real_reloc_type (sym, r_type)
10108 struct symbol *sym;
10109 bfd_reloc_code_real_type r_type;
10111 bfd_reloc_code_real_type new = 0;
10118 switch (S_GET_VALUE (sym))
10120 case FUNC_FPTR_RELATIVE:
10123 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10124 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10125 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10126 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10127 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10132 case FUNC_GP_RELATIVE:
10135 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10136 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10137 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10138 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10139 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10140 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10145 case FUNC_LT_RELATIVE:
10148 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10149 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10154 case FUNC_PC_RELATIVE:
10157 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10158 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10159 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10160 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10161 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10162 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10167 case FUNC_PLT_RELATIVE:
10170 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10171 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10172 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10173 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10178 case FUNC_SEC_RELATIVE:
10181 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10182 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10183 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10184 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10189 case FUNC_SEG_RELATIVE:
10192 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10193 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10194 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10195 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10200 case FUNC_LTV_RELATIVE:
10203 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10204 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10205 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10206 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10211 case FUNC_LT_FPTR_RELATIVE:
10214 case BFD_RELOC_IA64_IMM22:
10215 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10216 case BFD_RELOC_IA64_IMM64:
10217 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10223 case FUNC_TP_RELATIVE:
10226 case BFD_RELOC_IA64_IMM14:
10227 new = BFD_RELOC_IA64_TPREL14; break;
10228 case BFD_RELOC_IA64_IMM22:
10229 new = BFD_RELOC_IA64_TPREL22; break;
10230 case BFD_RELOC_IA64_IMM64:
10231 new = BFD_RELOC_IA64_TPREL64I; break;
10237 case FUNC_LT_TP_RELATIVE:
10240 case BFD_RELOC_IA64_IMM22:
10241 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10247 case FUNC_LT_DTP_MODULE:
10250 case BFD_RELOC_IA64_IMM22:
10251 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10257 case FUNC_DTP_RELATIVE:
10260 case BFD_RELOC_IA64_IMM14:
10261 new = BFD_RELOC_IA64_DTPREL14; break;
10262 case BFD_RELOC_IA64_IMM22:
10263 new = BFD_RELOC_IA64_DTPREL22; break;
10264 case BFD_RELOC_IA64_IMM64:
10265 new = BFD_RELOC_IA64_DTPREL64I; break;
10271 case FUNC_LT_DTP_RELATIVE:
10274 case BFD_RELOC_IA64_IMM22:
10275 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10281 case FUNC_IPLT_RELOC:
10287 /* Hmmmm. Should this ever occur? */
10294 /* Here is where generate the appropriate reloc for pseudo relocation
10297 ia64_validate_fix (fix)
10300 switch (fix->fx_r_type)
10302 case BFD_RELOC_IA64_FPTR64I:
10303 case BFD_RELOC_IA64_FPTR32MSB:
10304 case BFD_RELOC_IA64_FPTR64LSB:
10305 case BFD_RELOC_IA64_LTOFF_FPTR22:
10306 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10307 if (fix->fx_offset != 0)
10308 as_bad_where (fix->fx_file, fix->fx_line,
10309 "No addend allowed in @fptr() relocation");
10319 fix_insn (fix, odesc, value)
10321 const struct ia64_operand *odesc;
10324 bfd_vma insn[3], t0, t1, control_bits;
10329 slot = fix->fx_where & 0x3;
10330 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10332 /* Bundles are always in little-endian byte order */
10333 t0 = bfd_getl64 (fixpos);
10334 t1 = bfd_getl64 (fixpos + 8);
10335 control_bits = t0 & 0x1f;
10336 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10337 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10338 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10341 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10343 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10344 insn[2] |= (((value & 0x7f) << 13)
10345 | (((value >> 7) & 0x1ff) << 27)
10346 | (((value >> 16) & 0x1f) << 22)
10347 | (((value >> 21) & 0x1) << 21)
10348 | (((value >> 63) & 0x1) << 36));
10350 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10352 if (value & ~0x3fffffffffffffffULL)
10353 err = "integer operand out of range";
10354 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10355 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10357 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10360 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10361 insn[2] |= ((((value >> 59) & 0x1) << 36)
10362 | (((value >> 0) & 0xfffff) << 13));
10365 err = (*odesc->insert) (odesc, value, insn + slot);
10368 as_bad_where (fix->fx_file, fix->fx_line, err);
10370 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10371 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10372 number_to_chars_littleendian (fixpos + 0, t0, 8);
10373 number_to_chars_littleendian (fixpos + 8, t1, 8);
10376 /* Attempt to simplify or even eliminate a fixup. The return value is
10377 ignored; perhaps it was once meaningful, but now it is historical.
10378 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10380 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10384 md_apply_fix3 (fix, valP, seg)
10387 segT seg ATTRIBUTE_UNUSED;
10390 valueT value = *valP;
10393 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10397 switch (fix->fx_r_type)
10399 case BFD_RELOC_IA64_DIR32MSB:
10400 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10404 case BFD_RELOC_IA64_DIR32LSB:
10405 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10409 case BFD_RELOC_IA64_DIR64MSB:
10410 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10414 case BFD_RELOC_IA64_DIR64LSB:
10415 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10425 switch (fix->fx_r_type)
10427 case BFD_RELOC_UNUSED:
10428 /* This must be a TAG13 or TAG13b operand. There are no external
10429 relocs defined for them, so we must give an error. */
10430 as_bad_where (fix->fx_file, fix->fx_line,
10431 "%s must have a constant value",
10432 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10436 case BFD_RELOC_IA64_TPREL14:
10437 case BFD_RELOC_IA64_TPREL22:
10438 case BFD_RELOC_IA64_TPREL64I:
10439 case BFD_RELOC_IA64_LTOFF_TPREL22:
10440 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10441 case BFD_RELOC_IA64_DTPREL14:
10442 case BFD_RELOC_IA64_DTPREL22:
10443 case BFD_RELOC_IA64_DTPREL64I:
10444 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10445 S_SET_THREAD_LOCAL (fix->fx_addsy);
10452 /* ??? This is a hack copied from tc-i386.c to make PCREL relocs
10453 work. There should be a better way to handle this. */
10455 fix->fx_offset += fix->fx_where + fix->fx_frag->fr_address;
10457 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10459 if (fix->tc_fix_data.bigendian)
10460 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10462 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10467 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10472 /* Generate the BFD reloc to be stuck in the object file from the
10473 fixup used internally in the assembler. */
10476 tc_gen_reloc (sec, fixp)
10477 asection *sec ATTRIBUTE_UNUSED;
10482 reloc = xmalloc (sizeof (*reloc));
10483 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10484 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10485 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10486 reloc->addend = fixp->fx_offset;
10487 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10491 as_bad_where (fixp->fx_file, fixp->fx_line,
10492 "Cannot represent %s relocation in object file",
10493 bfd_get_reloc_code_name (fixp->fx_r_type));
10498 /* Turn a string in input_line_pointer into a floating point constant
10499 of type TYPE, and store the appropriate bytes in *LIT. The number
10500 of LITTLENUMS emitted is stored in *SIZE. An error message is
10501 returned, or NULL on OK. */
10503 #define MAX_LITTLENUMS 5
10506 md_atof (type, lit, size)
10511 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10512 LITTLENUM_TYPE *word;
10542 return "Bad call to MD_ATOF()";
10544 t = atof_ieee (input_line_pointer, type, words);
10546 input_line_pointer = t;
10547 *size = prec * sizeof (LITTLENUM_TYPE);
10549 for (word = words + prec - 1; prec--;)
10551 md_number_to_chars (lit, (long) (*word--), sizeof (LITTLENUM_TYPE));
10552 lit += sizeof (LITTLENUM_TYPE);
10557 /* Round up a section's size to the appropriate boundary. */
10559 md_section_align (seg, size)
10563 int align = bfd_get_section_alignment (stdoutput, seg);
10564 valueT mask = ((valueT) 1 << align) - 1;
10566 return (size + mask) & ~mask;
10569 /* Handle ia64 specific semantics of the align directive. */
10572 ia64_md_do_align (n, fill, len, max)
10573 int n ATTRIBUTE_UNUSED;
10574 const char *fill ATTRIBUTE_UNUSED;
10575 int len ATTRIBUTE_UNUSED;
10576 int max ATTRIBUTE_UNUSED;
10578 if (subseg_text_p (now_seg))
10579 ia64_flush_insns ();
10582 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10583 of an rs_align_code fragment. */
10586 ia64_handle_align (fragp)
10589 /* Use mfi bundle of nops with no stop bits. */
10590 static const unsigned char be_nop[]
10591 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
10592 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
10593 static const unsigned char le_nop[]
10594 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10595 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10600 if (fragp->fr_type != rs_align_code)
10603 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10604 p = fragp->fr_literal + fragp->fr_fix;
10606 /* Make sure we are on a 16-byte boundary, in case someone has been
10607 putting data into a text section. */
10610 int fix = bytes & 15;
10611 memset (p, 0, fix);
10614 fragp->fr_fix += fix;
10617 memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
10618 fragp->fr_var = 16;