1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001 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 "dwarf2dbg.h"
49 #include "opcode/ia64.h"
53 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
54 #define MIN(a,b) ((a) < (b) ? (a) : (b))
57 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
58 #define CURR_SLOT md.slot[md.curr_slot]
60 #define O_pseudo_fixup (O_max + 1)
64 /* IA-64 ABI section pseudo-ops. */
65 SPECIAL_SECTION_BSS = 0,
67 SPECIAL_SECTION_SDATA,
68 SPECIAL_SECTION_RODATA,
69 SPECIAL_SECTION_COMMENT,
70 SPECIAL_SECTION_UNWIND,
71 SPECIAL_SECTION_UNWIND_INFO,
72 /* HPUX specific section pseudo-ops. */
73 SPECIAL_SECTION_INIT_ARRAY,
74 SPECIAL_SECTION_FINI_ARRAY,
87 FUNC_LT_FPTR_RELATIVE,
94 REG_FR = (REG_GR + 128),
95 REG_AR = (REG_FR + 128),
96 REG_CR = (REG_AR + 128),
97 REG_P = (REG_CR + 128),
98 REG_BR = (REG_P + 64),
99 REG_IP = (REG_BR + 8),
106 /* The following are pseudo-registers for use by gas only. */
118 /* The following pseudo-registers are used for unwind directives only: */
126 DYNREG_GR = 0, /* dynamic general purpose register */
127 DYNREG_FR, /* dynamic floating point register */
128 DYNREG_PR, /* dynamic predicate register */
132 enum operand_match_result
135 OPERAND_OUT_OF_RANGE,
139 /* On the ia64, we can't know the address of a text label until the
140 instructions are packed into a bundle. To handle this, we keep
141 track of the list of labels that appear in front of each
145 struct label_fix *next;
149 extern int target_big_endian;
151 /* Characters which always start a comment. */
152 const char comment_chars[] = "";
154 /* Characters which start a comment at the beginning of a line. */
155 const char line_comment_chars[] = "#";
157 /* Characters which may be used to separate multiple commands on a
159 const char line_separator_chars[] = ";";
161 /* Characters which are used to indicate an exponent in a floating
163 const char EXP_CHARS[] = "eE";
165 /* Characters which mean that a number is a floating point constant,
167 const char FLT_CHARS[] = "rRsSfFdDxXpP";
169 /* ia64-specific option processing: */
171 const char *md_shortopts = "m:N:x::";
173 struct option md_longopts[] =
175 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
176 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
177 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
178 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
181 size_t md_longopts_size = sizeof (md_longopts);
185 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
186 struct hash_control *reg_hash; /* register name hash table */
187 struct hash_control *dynreg_hash; /* dynamic register hash table */
188 struct hash_control *const_hash; /* constant hash table */
189 struct hash_control *entry_hash; /* code entry hint hash table */
191 symbolS *regsym[REG_NUM];
193 /* If X_op is != O_absent, the registername for the instruction's
194 qualifying predicate. If NULL, p0 is assumed for instructions
195 that are predicatable. */
202 explicit_mode : 1, /* which mode we're in */
203 default_explicit_mode : 1, /* which mode is the default */
204 mode_explicitly_set : 1, /* was the current mode explicitly set? */
206 keep_pending_output : 1;
208 /* Each bundle consists of up to three instructions. We keep
209 track of four most recent instructions so we can correctly set
210 the end_of_insn_group for the last instruction in a bundle. */
212 int num_slots_in_use;
216 end_of_insn_group : 1,
217 manual_bundling_on : 1,
218 manual_bundling_off : 1;
219 signed char user_template; /* user-selected template, if any */
220 unsigned char qp_regno; /* qualifying predicate */
221 /* This duplicates a good fraction of "struct fix" but we
222 can't use a "struct fix" instead since we can't call
223 fix_new_exp() until we know the address of the instruction. */
227 bfd_reloc_code_real_type code;
228 enum ia64_opnd opnd; /* type of operand in need of fix */
229 unsigned int is_pcrel : 1; /* is operand pc-relative? */
230 expressionS expr; /* the value to be inserted */
232 fixup[2]; /* at most two fixups per insn */
233 struct ia64_opcode *idesc;
234 struct label_fix *label_fixups;
235 struct label_fix *tag_fixups;
236 struct unw_rec_list *unwind_record; /* Unwind directive. */
239 unsigned int src_line;
240 struct dwarf2_line_info debug_line;
248 struct dynreg *next; /* next dynamic register */
250 unsigned short base; /* the base register number */
251 unsigned short num_regs; /* # of registers in this set */
253 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
255 flagword flags; /* ELF-header flags */
258 unsigned hint:1; /* is this hint currently valid? */
259 bfd_vma offset; /* mem.offset offset */
260 bfd_vma base; /* mem.offset base */
263 int path; /* number of alt. entry points seen */
264 const char **entry_labels; /* labels of all alternate paths in
265 the current DV-checking block. */
266 int maxpaths; /* size currently allocated for
268 /* Support for hardware errata workarounds. */
270 /* Record data about the last three insn groups. */
273 /* B-step workaround.
274 For each predicate register, this is set if the corresponding insn
275 group conditionally sets this register with one of the affected
278 /* B-step workaround.
279 For each general register, this is set if the corresponding insn
280 a) is conditional one one of the predicate registers for which
281 P_REG_SET is 1 in the corresponding entry of the previous group,
282 b) sets this general register with one of the affected
284 int g_reg_set_conditionally[128];
288 int pointer_size; /* size in bytes of a pointer */
289 int pointer_size_shift; /* shift size of a pointer for alignment */
293 /* application registers: */
299 #define AR_BSPSTORE 18
314 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
315 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
316 {"ar.rsc", 16}, {"ar.bsp", 17},
317 {"ar.bspstore", 18}, {"ar.rnat", 19},
318 {"ar.fcr", 21}, {"ar.eflag", 24},
319 {"ar.csd", 25}, {"ar.ssd", 26},
320 {"ar.cflg", 27}, {"ar.fsr", 28},
321 {"ar.fir", 29}, {"ar.fdr", 30},
322 {"ar.ccv", 32}, {"ar.unat", 36},
323 {"ar.fpsr", 40}, {"ar.itc", 44},
324 {"ar.pfs", 64}, {"ar.lc", 65},
345 /* control registers: */
387 static const struct const_desc
394 /* PSR constant masks: */
397 {"psr.be", ((valueT) 1) << 1},
398 {"psr.up", ((valueT) 1) << 2},
399 {"psr.ac", ((valueT) 1) << 3},
400 {"psr.mfl", ((valueT) 1) << 4},
401 {"psr.mfh", ((valueT) 1) << 5},
403 {"psr.ic", ((valueT) 1) << 13},
404 {"psr.i", ((valueT) 1) << 14},
405 {"psr.pk", ((valueT) 1) << 15},
407 {"psr.dt", ((valueT) 1) << 17},
408 {"psr.dfl", ((valueT) 1) << 18},
409 {"psr.dfh", ((valueT) 1) << 19},
410 {"psr.sp", ((valueT) 1) << 20},
411 {"psr.pp", ((valueT) 1) << 21},
412 {"psr.di", ((valueT) 1) << 22},
413 {"psr.si", ((valueT) 1) << 23},
414 {"psr.db", ((valueT) 1) << 24},
415 {"psr.lp", ((valueT) 1) << 25},
416 {"psr.tb", ((valueT) 1) << 26},
417 {"psr.rt", ((valueT) 1) << 27},
418 /* 28-31: reserved */
419 /* 32-33: cpl (current privilege level) */
420 {"psr.is", ((valueT) 1) << 34},
421 {"psr.mc", ((valueT) 1) << 35},
422 {"psr.it", ((valueT) 1) << 36},
423 {"psr.id", ((valueT) 1) << 37},
424 {"psr.da", ((valueT) 1) << 38},
425 {"psr.dd", ((valueT) 1) << 39},
426 {"psr.ss", ((valueT) 1) << 40},
427 /* 41-42: ri (restart instruction) */
428 {"psr.ed", ((valueT) 1) << 43},
429 {"psr.bn", ((valueT) 1) << 44},
432 /* indirect register-sets/memory: */
441 { "CPUID", IND_CPUID },
442 { "cpuid", IND_CPUID },
454 /* Pseudo functions used to indicate relocation types (these functions
455 start with an at sign (@). */
477 /* reloc pseudo functions (these must come first!): */
478 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
479 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
480 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
481 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
482 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
483 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
484 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
485 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
486 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
487 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
489 /* mbtype4 constants: */
490 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
491 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
492 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
493 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
494 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
496 /* fclass constants: */
497 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
498 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
499 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
500 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
501 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
502 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
503 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
504 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
505 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
507 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
509 /* unwind-related constants: */
510 { "svr4", PSEUDO_FUNC_CONST, { 0 } },
511 { "hpux", PSEUDO_FUNC_CONST, { 1 } },
512 { "nt", PSEUDO_FUNC_CONST, { 2 } },
514 /* unwind-related registers: */
515 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
518 /* 41-bit nop opcodes (one per unit): */
519 static const bfd_vma nop[IA64_NUM_UNITS] =
521 0x0000000000LL, /* NIL => break 0 */
522 0x0008000000LL, /* I-unit nop */
523 0x0008000000LL, /* M-unit nop */
524 0x4000000000LL, /* B-unit nop */
525 0x0008000000LL, /* F-unit nop */
526 0x0008000000LL, /* L-"unit" nop */
527 0x0008000000LL, /* X-unit nop */
530 /* Can't be `const' as it's passed to input routines (which have the
531 habit of setting temporary sentinels. */
532 static char special_section_name[][20] =
534 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
535 {".IA_64.unwind"}, {".IA_64.unwind_info"},
536 {".init_array"}, {".fini_array"}
539 static char *special_linkonce_name[] =
541 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
544 /* The best template for a particular sequence of up to three
546 #define N IA64_NUM_TYPES
547 static unsigned char best_template[N][N][N];
550 /* Resource dependencies currently in effect */
552 int depind; /* dependency index */
553 const struct ia64_dependency *dependency; /* actual dependency */
554 unsigned specific:1, /* is this a specific bit/regno? */
555 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
556 int index; /* specific regno/bit within dependency */
557 int note; /* optional qualifying note (0 if none) */
561 int insn_srlz; /* current insn serialization state */
562 int data_srlz; /* current data serialization state */
563 int qp_regno; /* qualifying predicate for this usage */
564 char *file; /* what file marked this dependency */
565 unsigned int line; /* what line marked this dependency */
566 struct mem_offset mem_offset; /* optional memory offset hint */
567 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
568 int path; /* corresponding code entry index */
570 static int regdepslen = 0;
571 static int regdepstotlen = 0;
572 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
573 static const char *dv_sem[] = { "none", "implied", "impliedf",
574 "data", "instr", "specific", "stop", "other" };
575 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
577 /* Current state of PR mutexation */
578 static struct qpmutex {
581 } *qp_mutexes = NULL; /* QP mutex bitmasks */
582 static int qp_mutexeslen = 0;
583 static int qp_mutexestotlen = 0;
584 static valueT qp_safe_across_calls = 0;
586 /* Current state of PR implications */
587 static struct qp_imply {
590 unsigned p2_branched:1;
592 } *qp_implies = NULL;
593 static int qp_implieslen = 0;
594 static int qp_impliestotlen = 0;
596 /* Keep track of static GR values so that indirect register usage can
597 sometimes be tracked. */
602 } gr_values[128] = {{ 1, 0, 0 }};
604 /* These are the routines required to output the various types of
607 /* A slot_number is a frag address plus the slot index (0-2). We use the
608 frag address here so that if there is a section switch in the middle of
609 a function, then instructions emitted to a different section are not
610 counted. Since there may be more than one frag for a function, this
611 means we also need to keep track of which frag this address belongs to
612 so we can compute inter-frag distances. This also nicely solves the
613 problem with nops emitted for align directives, which can't easily be
614 counted, but can easily be derived from frag sizes. */
616 typedef struct unw_rec_list {
618 unsigned long slot_number;
620 struct unw_rec_list *next;
623 #define SLOT_NUM_NOT_SET (unsigned)-1
627 unsigned long next_slot_number;
628 fragS *next_slot_frag;
630 /* Maintain a list of unwind entries for the current function. */
634 /* Any unwind entires that should be attached to the current slot
635 that an insn is being constructed for. */
636 unw_rec_list *current_entry;
638 /* These are used to create the unwind table entry for this function. */
641 symbolS *info; /* pointer to unwind info */
642 symbolS *personality_routine;
644 subsegT saved_text_subseg;
645 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
647 /* TRUE if processing unwind directives in a prologue region. */
650 unsigned int prologue_count; /* number of .prologues seen so far */
653 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
655 /* Forward delarations: */
656 static int ar_is_in_integer_unit PARAMS ((int regnum));
657 static void set_section PARAMS ((char *name));
658 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
659 unsigned int, unsigned int));
660 static void dot_radix PARAMS ((int));
661 static void dot_special_section PARAMS ((int));
662 static void dot_proc PARAMS ((int));
663 static void dot_fframe PARAMS ((int));
664 static void dot_vframe PARAMS ((int));
665 static void dot_vframesp PARAMS ((int));
666 static void dot_vframepsp PARAMS ((int));
667 static void dot_save PARAMS ((int));
668 static void dot_restore PARAMS ((int));
669 static void dot_restorereg PARAMS ((int));
670 static void dot_restorereg_p PARAMS ((int));
671 static void dot_handlerdata PARAMS ((int));
672 static void dot_unwentry PARAMS ((int));
673 static void dot_altrp PARAMS ((int));
674 static void dot_savemem PARAMS ((int));
675 static void dot_saveg PARAMS ((int));
676 static void dot_savef PARAMS ((int));
677 static void dot_saveb PARAMS ((int));
678 static void dot_savegf PARAMS ((int));
679 static void dot_spill PARAMS ((int));
680 static void dot_spillreg PARAMS ((int));
681 static void dot_spillmem PARAMS ((int));
682 static void dot_spillreg_p PARAMS ((int));
683 static void dot_spillmem_p PARAMS ((int));
684 static void dot_label_state PARAMS ((int));
685 static void dot_copy_state PARAMS ((int));
686 static void dot_unwabi PARAMS ((int));
687 static void dot_personality PARAMS ((int));
688 static void dot_body PARAMS ((int));
689 static void dot_prologue PARAMS ((int));
690 static void dot_endp PARAMS ((int));
691 static void dot_template PARAMS ((int));
692 static void dot_regstk PARAMS ((int));
693 static void dot_rot PARAMS ((int));
694 static void dot_byteorder PARAMS ((int));
695 static void dot_psr PARAMS ((int));
696 static void dot_alias PARAMS ((int));
697 static void dot_ln PARAMS ((int));
698 static char *parse_section_name PARAMS ((void));
699 static void dot_xdata PARAMS ((int));
700 static void stmt_float_cons PARAMS ((int));
701 static void stmt_cons_ua PARAMS ((int));
702 static void dot_xfloat_cons PARAMS ((int));
703 static void dot_xstringer PARAMS ((int));
704 static void dot_xdata_ua PARAMS ((int));
705 static void dot_xfloat_cons_ua PARAMS ((int));
706 static void print_prmask PARAMS ((valueT mask));
707 static void dot_pred_rel PARAMS ((int));
708 static void dot_reg_val PARAMS ((int));
709 static void dot_dv_mode PARAMS ((int));
710 static void dot_entry PARAMS ((int));
711 static void dot_mem_offset PARAMS ((int));
712 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
713 static symbolS *declare_register PARAMS ((const char *name, int regnum));
714 static void declare_register_set PARAMS ((const char *, int, int));
715 static unsigned int operand_width PARAMS ((enum ia64_opnd));
716 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
719 static int parse_operand PARAMS ((expressionS *e));
720 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
721 static void build_insn PARAMS ((struct slot *, bfd_vma *));
722 static void emit_one_bundle PARAMS ((void));
723 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
724 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
725 bfd_reloc_code_real_type r_type));
726 static void insn_group_break PARAMS ((int, int, int));
727 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
728 struct rsrc *, int depind, int path));
729 static void add_qp_mutex PARAMS((valueT mask));
730 static void add_qp_imply PARAMS((int p1, int p2));
731 static void clear_qp_branch_flag PARAMS((valueT mask));
732 static void clear_qp_mutex PARAMS((valueT mask));
733 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
734 static void clear_register_values PARAMS ((void));
735 static void print_dependency PARAMS ((const char *action, int depind));
736 static void instruction_serialization PARAMS ((void));
737 static void data_serialization PARAMS ((void));
738 static void remove_marked_resource PARAMS ((struct rsrc *));
739 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
740 static int is_taken_branch PARAMS ((struct ia64_opcode *));
741 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
742 static int depends_on PARAMS ((int, struct ia64_opcode *));
743 static int specify_resource PARAMS ((const struct ia64_dependency *,
744 struct ia64_opcode *, int, struct rsrc [], int, int));
745 static int check_dv PARAMS((struct ia64_opcode *idesc));
746 static void check_dependencies PARAMS((struct ia64_opcode *));
747 static void mark_resources PARAMS((struct ia64_opcode *));
748 static void update_dependencies PARAMS((struct ia64_opcode *));
749 static void note_register_values PARAMS((struct ia64_opcode *));
750 static int qp_mutex PARAMS ((int, int, int));
751 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
752 static void output_vbyte_mem PARAMS ((int, char *, char *));
753 static void count_output PARAMS ((int, char *, char *));
754 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
755 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
756 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
757 static void output_P1_format PARAMS ((vbyte_func, int));
758 static void output_P2_format PARAMS ((vbyte_func, int, int));
759 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
760 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
761 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
762 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
763 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
764 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
765 static void output_P9_format PARAMS ((vbyte_func, int, int));
766 static void output_P10_format PARAMS ((vbyte_func, int, int));
767 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
768 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
769 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
770 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
771 static char format_ab_reg PARAMS ((int, int));
772 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
774 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
775 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
777 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
778 static void free_list_records PARAMS ((unw_rec_list *));
779 static unw_rec_list *output_prologue PARAMS ((void));
780 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
781 static unw_rec_list *output_body PARAMS ((void));
782 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
783 static unw_rec_list *output_mem_stack_v PARAMS ((void));
784 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
785 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
786 static unw_rec_list *output_rp_when PARAMS ((void));
787 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
788 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
789 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
790 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
791 static unw_rec_list *output_pfs_when PARAMS ((void));
792 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
793 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
794 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
795 static unw_rec_list *output_preds_when PARAMS ((void));
796 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
797 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
798 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
799 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
800 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
801 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
802 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
803 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
804 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
805 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
806 static unw_rec_list *output_unat_when PARAMS ((void));
807 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
808 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
809 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
810 static unw_rec_list *output_lc_when PARAMS ((void));
811 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
812 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
813 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
814 static unw_rec_list *output_fpsr_when PARAMS ((void));
815 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
816 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
817 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
818 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
819 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
820 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
821 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
822 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
823 static unw_rec_list *output_bsp_when PARAMS ((void));
824 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
825 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
826 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
827 static unw_rec_list *output_bspstore_when PARAMS ((void));
828 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
829 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
830 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
831 static unw_rec_list *output_rnat_when PARAMS ((void));
832 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
833 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
834 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
835 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
836 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
837 static unw_rec_list *output_label_state PARAMS ((unsigned long));
838 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
839 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
840 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
841 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
843 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
845 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
847 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
848 unsigned int, unsigned int));
849 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
850 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
851 static int calc_record_size PARAMS ((unw_rec_list *));
852 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
853 static int count_bits PARAMS ((unsigned long));
854 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
855 unsigned long, fragS *));
856 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
857 static void fixup_unw_records PARAMS ((unw_rec_list *));
858 static int output_unw_records PARAMS ((unw_rec_list *, void **));
859 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
860 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
861 static int generate_unwind_image PARAMS ((const char *));
863 /* Build the unwind section name by appending the (possibly stripped)
864 text section NAME to the unwind PREFIX. The resulting string
865 pointer is assigned to RESULT. The string is allocated on the
866 stack, so this must be a macro... */
867 #define make_unw_section_name(special, text_name, result) \
869 char *_prefix = special_section_name[special]; \
870 char *_suffix = text_name; \
871 size_t _prefix_len, _suffix_len; \
873 if (strncmp (text_name, ".gnu.linkonce.t.", \
874 sizeof (".gnu.linkonce.t.") - 1) == 0) \
876 _prefix = special_linkonce_name[special - SPECIAL_SECTION_UNWIND]; \
877 _suffix += sizeof (".gnu.linkonce.t.") - 1; \
879 _prefix_len = strlen (_prefix), _suffix_len = strlen (_suffix); \
880 _result = alloca (_prefix_len + _suffix_len + 1); \
881 memcpy (_result, _prefix, _prefix_len); \
882 memcpy (_result + _prefix_len, _suffix, _suffix_len); \
883 _result[_prefix_len + _suffix_len] = '\0'; \
888 /* Determine if application register REGNUM resides in the integer
889 unit (as opposed to the memory unit). */
891 ar_is_in_integer_unit (reg)
896 return (reg == 64 /* pfs */
897 || reg == 65 /* lc */
898 || reg == 66 /* ec */
899 /* ??? ias accepts and puts these in the integer unit. */
900 || (reg >= 112 && reg <= 127));
903 /* Switch to section NAME and create section if necessary. It's
904 rather ugly that we have to manipulate input_line_pointer but I
905 don't see any other way to accomplish the same thing without
906 changing obj-elf.c (which may be the Right Thing, in the end). */
911 char *saved_input_line_pointer;
913 saved_input_line_pointer = input_line_pointer;
914 input_line_pointer = name;
916 input_line_pointer = saved_input_line_pointer;
919 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
922 ia64_elf_section_flags (flags, attr, type)
924 int attr, type ATTRIBUTE_UNUSED;
926 if (attr & SHF_IA_64_SHORT)
927 flags |= SEC_SMALL_DATA;
932 ia64_elf_section_type (str, len)
936 len = sizeof (ELF_STRING_ia64_unwind_info) - 1;
937 if (strncmp (str, ELF_STRING_ia64_unwind_info, len) == 0)
940 len = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
941 if (strncmp (str, ELF_STRING_ia64_unwind_info_once, len) == 0)
944 len = sizeof (ELF_STRING_ia64_unwind) - 1;
945 if (strncmp (str, ELF_STRING_ia64_unwind, len) == 0)
946 return SHT_IA_64_UNWIND;
948 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
949 if (strncmp (str, ELF_STRING_ia64_unwind_once, len) == 0)
950 return SHT_IA_64_UNWIND;
956 set_regstack (ins, locs, outs, rots)
957 unsigned int ins, locs, outs, rots;
962 sof = ins + locs + outs;
965 as_bad ("Size of frame exceeds maximum of 96 registers");
970 as_warn ("Size of rotating registers exceeds frame size");
973 md.in.base = REG_GR + 32;
974 md.loc.base = md.in.base + ins;
975 md.out.base = md.loc.base + locs;
977 md.in.num_regs = ins;
978 md.loc.num_regs = locs;
979 md.out.num_regs = outs;
980 md.rot.num_regs = rots;
987 struct label_fix *lfix;
989 subsegT saved_subseg;
992 if (!md.last_text_seg)
996 saved_subseg = now_subseg;
998 subseg_set (md.last_text_seg, 0);
1000 while (md.num_slots_in_use > 0)
1001 emit_one_bundle (); /* force out queued instructions */
1003 /* In case there are labels following the last instruction, resolve
1005 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1007 S_SET_VALUE (lfix->sym, frag_now_fix ());
1008 symbol_set_frag (lfix->sym, frag_now);
1010 CURR_SLOT.label_fixups = 0;
1011 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1013 S_SET_VALUE (lfix->sym, frag_now_fix ());
1014 symbol_set_frag (lfix->sym, frag_now);
1016 CURR_SLOT.tag_fixups = 0;
1018 /* In case there are unwind directives following the last instruction,
1019 resolve those now. We only handle body and prologue directives here.
1020 Give an error for others. */
1021 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1023 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
1024 || ptr->r.type == body)
1026 ptr->slot_number = (unsigned long) frag_more (0);
1027 ptr->slot_frag = frag_now;
1030 as_bad (_("Unwind directive not followed by an instruction."));
1032 unwind.current_entry = NULL;
1034 subseg_set (saved_seg, saved_subseg);
1036 if (md.qp.X_op == O_register)
1037 as_bad ("qualifying predicate not followed by instruction");
1041 ia64_do_align (nbytes)
1044 char *saved_input_line_pointer = input_line_pointer;
1046 input_line_pointer = "";
1047 s_align_bytes (nbytes);
1048 input_line_pointer = saved_input_line_pointer;
1052 ia64_cons_align (nbytes)
1057 char *saved_input_line_pointer = input_line_pointer;
1058 input_line_pointer = "";
1059 s_align_bytes (nbytes);
1060 input_line_pointer = saved_input_line_pointer;
1064 /* Output COUNT bytes to a memory location. */
1065 static unsigned char *vbyte_mem_ptr = NULL;
1068 output_vbyte_mem (count, ptr, comment)
1071 char *comment ATTRIBUTE_UNUSED;
1074 if (vbyte_mem_ptr == NULL)
1079 for (x = 0; x < count; x++)
1080 *(vbyte_mem_ptr++) = ptr[x];
1083 /* Count the number of bytes required for records. */
1084 static int vbyte_count = 0;
1086 count_output (count, ptr, comment)
1088 char *ptr ATTRIBUTE_UNUSED;
1089 char *comment ATTRIBUTE_UNUSED;
1091 vbyte_count += count;
1095 output_R1_format (f, rtype, rlen)
1097 unw_record_type rtype;
1104 output_R3_format (f, rtype, rlen);
1110 else if (rtype != prologue)
1111 as_bad ("record type is not valid");
1113 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1114 (*f) (1, &byte, NULL);
1118 output_R2_format (f, mask, grsave, rlen)
1125 mask = (mask & 0x0f);
1126 grsave = (grsave & 0x7f);
1128 bytes[0] = (UNW_R2 | (mask >> 1));
1129 bytes[1] = (((mask & 0x01) << 7) | grsave);
1130 count += output_leb128 (bytes + 2, rlen, 0);
1131 (*f) (count, bytes, NULL);
1135 output_R3_format (f, rtype, rlen)
1137 unw_record_type rtype;
1144 output_R1_format (f, rtype, rlen);
1150 else if (rtype != prologue)
1151 as_bad ("record type is not valid");
1152 bytes[0] = (UNW_R3 | r);
1153 count = output_leb128 (bytes + 1, rlen, 0);
1154 (*f) (count + 1, bytes, NULL);
1158 output_P1_format (f, brmask)
1163 byte = UNW_P1 | (brmask & 0x1f);
1164 (*f) (1, &byte, NULL);
1168 output_P2_format (f, brmask, gr)
1174 brmask = (brmask & 0x1f);
1175 bytes[0] = UNW_P2 | (brmask >> 1);
1176 bytes[1] = (((brmask & 1) << 7) | gr);
1177 (*f) (2, bytes, NULL);
1181 output_P3_format (f, rtype, reg)
1183 unw_record_type rtype;
1228 as_bad ("Invalid record type for P3 format.");
1230 bytes[0] = (UNW_P3 | (r >> 1));
1231 bytes[1] = (((r & 1) << 7) | reg);
1232 (*f) (2, bytes, NULL);
1236 output_P4_format (f, imask, imask_size)
1238 unsigned char *imask;
1239 unsigned long imask_size;
1242 (*f) (imask_size, imask, NULL);
1246 output_P5_format (f, grmask, frmask)
1249 unsigned long frmask;
1252 grmask = (grmask & 0x0f);
1255 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1256 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1257 bytes[3] = (frmask & 0x000000ff);
1258 (*f) (4, bytes, NULL);
1262 output_P6_format (f, rtype, rmask)
1264 unw_record_type rtype;
1270 if (rtype == gr_mem)
1272 else if (rtype != fr_mem)
1273 as_bad ("Invalid record type for format P6");
1274 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1275 (*f) (1, &byte, NULL);
1279 output_P7_format (f, rtype, w1, w2)
1281 unw_record_type rtype;
1288 count += output_leb128 (bytes + 1, w1, 0);
1293 count += output_leb128 (bytes + count, w2 >> 4, 0);
1343 bytes[0] = (UNW_P7 | r);
1344 (*f) (count, bytes, NULL);
1348 output_P8_format (f, rtype, t)
1350 unw_record_type rtype;
1389 case bspstore_psprel:
1392 case bspstore_sprel:
1404 case priunat_when_gr:
1407 case priunat_psprel:
1413 case priunat_when_mem:
1420 count += output_leb128 (bytes + 2, t, 0);
1421 (*f) (count, bytes, NULL);
1425 output_P9_format (f, grmask, gr)
1432 bytes[1] = (grmask & 0x0f);
1433 bytes[2] = (gr & 0x7f);
1434 (*f) (3, bytes, NULL);
1438 output_P10_format (f, abi, context)
1445 bytes[1] = (abi & 0xff);
1446 bytes[2] = (context & 0xff);
1447 (*f) (3, bytes, NULL);
1451 output_B1_format (f, rtype, label)
1453 unw_record_type rtype;
1454 unsigned long label;
1460 output_B4_format (f, rtype, label);
1463 if (rtype == copy_state)
1465 else if (rtype != label_state)
1466 as_bad ("Invalid record type for format B1");
1468 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1469 (*f) (1, &byte, NULL);
1473 output_B2_format (f, ecount, t)
1475 unsigned long ecount;
1482 output_B3_format (f, ecount, t);
1485 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1486 count += output_leb128 (bytes + 1, t, 0);
1487 (*f) (count, bytes, NULL);
1491 output_B3_format (f, ecount, t)
1493 unsigned long ecount;
1500 output_B2_format (f, ecount, t);
1504 count += output_leb128 (bytes + 1, t, 0);
1505 count += output_leb128 (bytes + count, ecount, 0);
1506 (*f) (count, bytes, NULL);
1510 output_B4_format (f, rtype, label)
1512 unw_record_type rtype;
1513 unsigned long label;
1520 output_B1_format (f, rtype, label);
1524 if (rtype == copy_state)
1526 else if (rtype != label_state)
1527 as_bad ("Invalid record type for format B1");
1529 bytes[0] = (UNW_B4 | (r << 3));
1530 count += output_leb128 (bytes + 1, label, 0);
1531 (*f) (count, bytes, NULL);
1535 format_ab_reg (ab, reg)
1542 ret = (ab << 5) | reg;
1547 output_X1_format (f, rtype, ab, reg, t, w1)
1549 unw_record_type rtype;
1559 if (rtype == spill_sprel)
1561 else if (rtype != spill_psprel)
1562 as_bad ("Invalid record type for format X1");
1563 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1564 count += output_leb128 (bytes + 2, t, 0);
1565 count += output_leb128 (bytes + count, w1, 0);
1566 (*f) (count, bytes, NULL);
1570 output_X2_format (f, ab, reg, x, y, treg, t)
1579 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1580 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1581 count += output_leb128 (bytes + 3, t, 0);
1582 (*f) (count, bytes, NULL);
1586 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1588 unw_record_type rtype;
1599 if (rtype == spill_sprel_p)
1601 else if (rtype != spill_psprel_p)
1602 as_bad ("Invalid record type for format X3");
1603 bytes[1] = ((r << 7) | (qp & 0x3f));
1604 bytes[2] = format_ab_reg (ab, reg);
1605 count += output_leb128 (bytes + 3, t, 0);
1606 count += output_leb128 (bytes + count, w1, 0);
1607 (*f) (count, bytes, NULL);
1611 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1621 bytes[1] = (qp & 0x3f);
1622 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1623 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1624 count += output_leb128 (bytes + 4, t, 0);
1625 (*f) (count, bytes, NULL);
1628 /* This function allocates a record list structure, and initializes fields. */
1630 static unw_rec_list *
1631 alloc_record (unw_record_type t)
1634 ptr = xmalloc (sizeof (*ptr));
1636 ptr->slot_number = SLOT_NUM_NOT_SET;
1641 /* This function frees an entire list of record structures. */
1644 free_list_records (unw_rec_list *first)
1647 for (ptr = first; ptr != NULL;)
1649 unw_rec_list *tmp = ptr;
1651 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1652 && tmp->r.record.r.mask.i)
1653 free (tmp->r.record.r.mask.i);
1660 static unw_rec_list *
1663 unw_rec_list *ptr = alloc_record (prologue);
1664 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1668 static unw_rec_list *
1669 output_prologue_gr (saved_mask, reg)
1670 unsigned int saved_mask;
1673 unw_rec_list *ptr = alloc_record (prologue_gr);
1674 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1675 ptr->r.record.r.grmask = saved_mask;
1676 ptr->r.record.r.grsave = reg;
1680 static unw_rec_list *
1683 unw_rec_list *ptr = alloc_record (body);
1687 static unw_rec_list *
1688 output_mem_stack_f (size)
1691 unw_rec_list *ptr = alloc_record (mem_stack_f);
1692 ptr->r.record.p.size = size;
1696 static unw_rec_list *
1697 output_mem_stack_v ()
1699 unw_rec_list *ptr = alloc_record (mem_stack_v);
1703 static unw_rec_list *
1707 unw_rec_list *ptr = alloc_record (psp_gr);
1708 ptr->r.record.p.gr = gr;
1712 static unw_rec_list *
1713 output_psp_sprel (offset)
1714 unsigned int offset;
1716 unw_rec_list *ptr = alloc_record (psp_sprel);
1717 ptr->r.record.p.spoff = offset / 4;
1721 static unw_rec_list *
1724 unw_rec_list *ptr = alloc_record (rp_when);
1728 static unw_rec_list *
1732 unw_rec_list *ptr = alloc_record (rp_gr);
1733 ptr->r.record.p.gr = gr;
1737 static unw_rec_list *
1741 unw_rec_list *ptr = alloc_record (rp_br);
1742 ptr->r.record.p.br = br;
1746 static unw_rec_list *
1747 output_rp_psprel (offset)
1748 unsigned int offset;
1750 unw_rec_list *ptr = alloc_record (rp_psprel);
1751 ptr->r.record.p.pspoff = offset / 4;
1755 static unw_rec_list *
1756 output_rp_sprel (offset)
1757 unsigned int offset;
1759 unw_rec_list *ptr = alloc_record (rp_sprel);
1760 ptr->r.record.p.spoff = offset / 4;
1764 static unw_rec_list *
1767 unw_rec_list *ptr = alloc_record (pfs_when);
1771 static unw_rec_list *
1775 unw_rec_list *ptr = alloc_record (pfs_gr);
1776 ptr->r.record.p.gr = gr;
1780 static unw_rec_list *
1781 output_pfs_psprel (offset)
1782 unsigned int offset;
1784 unw_rec_list *ptr = alloc_record (pfs_psprel);
1785 ptr->r.record.p.pspoff = offset / 4;
1789 static unw_rec_list *
1790 output_pfs_sprel (offset)
1791 unsigned int offset;
1793 unw_rec_list *ptr = alloc_record (pfs_sprel);
1794 ptr->r.record.p.spoff = offset / 4;
1798 static unw_rec_list *
1799 output_preds_when ()
1801 unw_rec_list *ptr = alloc_record (preds_when);
1805 static unw_rec_list *
1806 output_preds_gr (gr)
1809 unw_rec_list *ptr = alloc_record (preds_gr);
1810 ptr->r.record.p.gr = gr;
1814 static unw_rec_list *
1815 output_preds_psprel (offset)
1816 unsigned int offset;
1818 unw_rec_list *ptr = alloc_record (preds_psprel);
1819 ptr->r.record.p.pspoff = offset / 4;
1823 static unw_rec_list *
1824 output_preds_sprel (offset)
1825 unsigned int offset;
1827 unw_rec_list *ptr = alloc_record (preds_sprel);
1828 ptr->r.record.p.spoff = offset / 4;
1832 static unw_rec_list *
1833 output_fr_mem (mask)
1836 unw_rec_list *ptr = alloc_record (fr_mem);
1837 ptr->r.record.p.rmask = mask;
1841 static unw_rec_list *
1842 output_frgr_mem (gr_mask, fr_mask)
1843 unsigned int gr_mask;
1844 unsigned int fr_mask;
1846 unw_rec_list *ptr = alloc_record (frgr_mem);
1847 ptr->r.record.p.grmask = gr_mask;
1848 ptr->r.record.p.frmask = fr_mask;
1852 static unw_rec_list *
1853 output_gr_gr (mask, reg)
1857 unw_rec_list *ptr = alloc_record (gr_gr);
1858 ptr->r.record.p.grmask = mask;
1859 ptr->r.record.p.gr = reg;
1863 static unw_rec_list *
1864 output_gr_mem (mask)
1867 unw_rec_list *ptr = alloc_record (gr_mem);
1868 ptr->r.record.p.rmask = mask;
1872 static unw_rec_list *
1873 output_br_mem (unsigned int mask)
1875 unw_rec_list *ptr = alloc_record (br_mem);
1876 ptr->r.record.p.brmask = mask;
1880 static unw_rec_list *
1881 output_br_gr (save_mask, reg)
1882 unsigned int save_mask;
1885 unw_rec_list *ptr = alloc_record (br_gr);
1886 ptr->r.record.p.brmask = save_mask;
1887 ptr->r.record.p.gr = reg;
1891 static unw_rec_list *
1892 output_spill_base (offset)
1893 unsigned int offset;
1895 unw_rec_list *ptr = alloc_record (spill_base);
1896 ptr->r.record.p.pspoff = offset / 4;
1900 static unw_rec_list *
1903 unw_rec_list *ptr = alloc_record (unat_when);
1907 static unw_rec_list *
1911 unw_rec_list *ptr = alloc_record (unat_gr);
1912 ptr->r.record.p.gr = gr;
1916 static unw_rec_list *
1917 output_unat_psprel (offset)
1918 unsigned int offset;
1920 unw_rec_list *ptr = alloc_record (unat_psprel);
1921 ptr->r.record.p.pspoff = offset / 4;
1925 static unw_rec_list *
1926 output_unat_sprel (offset)
1927 unsigned int offset;
1929 unw_rec_list *ptr = alloc_record (unat_sprel);
1930 ptr->r.record.p.spoff = offset / 4;
1934 static unw_rec_list *
1937 unw_rec_list *ptr = alloc_record (lc_when);
1941 static unw_rec_list *
1945 unw_rec_list *ptr = alloc_record (lc_gr);
1946 ptr->r.record.p.gr = gr;
1950 static unw_rec_list *
1951 output_lc_psprel (offset)
1952 unsigned int offset;
1954 unw_rec_list *ptr = alloc_record (lc_psprel);
1955 ptr->r.record.p.pspoff = offset / 4;
1959 static unw_rec_list *
1960 output_lc_sprel (offset)
1961 unsigned int offset;
1963 unw_rec_list *ptr = alloc_record (lc_sprel);
1964 ptr->r.record.p.spoff = offset / 4;
1968 static unw_rec_list *
1971 unw_rec_list *ptr = alloc_record (fpsr_when);
1975 static unw_rec_list *
1979 unw_rec_list *ptr = alloc_record (fpsr_gr);
1980 ptr->r.record.p.gr = gr;
1984 static unw_rec_list *
1985 output_fpsr_psprel (offset)
1986 unsigned int offset;
1988 unw_rec_list *ptr = alloc_record (fpsr_psprel);
1989 ptr->r.record.p.pspoff = offset / 4;
1993 static unw_rec_list *
1994 output_fpsr_sprel (offset)
1995 unsigned int offset;
1997 unw_rec_list *ptr = alloc_record (fpsr_sprel);
1998 ptr->r.record.p.spoff = offset / 4;
2002 static unw_rec_list *
2003 output_priunat_when_gr ()
2005 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2009 static unw_rec_list *
2010 output_priunat_when_mem ()
2012 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2016 static unw_rec_list *
2017 output_priunat_gr (gr)
2020 unw_rec_list *ptr = alloc_record (priunat_gr);
2021 ptr->r.record.p.gr = gr;
2025 static unw_rec_list *
2026 output_priunat_psprel (offset)
2027 unsigned int offset;
2029 unw_rec_list *ptr = alloc_record (priunat_psprel);
2030 ptr->r.record.p.pspoff = offset / 4;
2034 static unw_rec_list *
2035 output_priunat_sprel (offset)
2036 unsigned int offset;
2038 unw_rec_list *ptr = alloc_record (priunat_sprel);
2039 ptr->r.record.p.spoff = offset / 4;
2043 static unw_rec_list *
2046 unw_rec_list *ptr = alloc_record (bsp_when);
2050 static unw_rec_list *
2054 unw_rec_list *ptr = alloc_record (bsp_gr);
2055 ptr->r.record.p.gr = gr;
2059 static unw_rec_list *
2060 output_bsp_psprel (offset)
2061 unsigned int offset;
2063 unw_rec_list *ptr = alloc_record (bsp_psprel);
2064 ptr->r.record.p.pspoff = offset / 4;
2068 static unw_rec_list *
2069 output_bsp_sprel (offset)
2070 unsigned int offset;
2072 unw_rec_list *ptr = alloc_record (bsp_sprel);
2073 ptr->r.record.p.spoff = offset / 4;
2077 static unw_rec_list *
2078 output_bspstore_when ()
2080 unw_rec_list *ptr = alloc_record (bspstore_when);
2084 static unw_rec_list *
2085 output_bspstore_gr (gr)
2088 unw_rec_list *ptr = alloc_record (bspstore_gr);
2089 ptr->r.record.p.gr = gr;
2093 static unw_rec_list *
2094 output_bspstore_psprel (offset)
2095 unsigned int offset;
2097 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2098 ptr->r.record.p.pspoff = offset / 4;
2102 static unw_rec_list *
2103 output_bspstore_sprel (offset)
2104 unsigned int offset;
2106 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2107 ptr->r.record.p.spoff = offset / 4;
2111 static unw_rec_list *
2114 unw_rec_list *ptr = alloc_record (rnat_when);
2118 static unw_rec_list *
2122 unw_rec_list *ptr = alloc_record (rnat_gr);
2123 ptr->r.record.p.gr = gr;
2127 static unw_rec_list *
2128 output_rnat_psprel (offset)
2129 unsigned int offset;
2131 unw_rec_list *ptr = alloc_record (rnat_psprel);
2132 ptr->r.record.p.pspoff = offset / 4;
2136 static unw_rec_list *
2137 output_rnat_sprel (offset)
2138 unsigned int offset;
2140 unw_rec_list *ptr = alloc_record (rnat_sprel);
2141 ptr->r.record.p.spoff = offset / 4;
2145 static unw_rec_list *
2146 output_unwabi (abi, context)
2148 unsigned long context;
2150 unw_rec_list *ptr = alloc_record (unwabi);
2151 ptr->r.record.p.abi = abi;
2152 ptr->r.record.p.context = context;
2156 static unw_rec_list *
2157 output_epilogue (unsigned long ecount)
2159 unw_rec_list *ptr = alloc_record (epilogue);
2160 ptr->r.record.b.ecount = ecount;
2164 static unw_rec_list *
2165 output_label_state (unsigned long label)
2167 unw_rec_list *ptr = alloc_record (label_state);
2168 ptr->r.record.b.label = label;
2172 static unw_rec_list *
2173 output_copy_state (unsigned long label)
2175 unw_rec_list *ptr = alloc_record (copy_state);
2176 ptr->r.record.b.label = label;
2180 static unw_rec_list *
2181 output_spill_psprel (ab, reg, offset)
2184 unsigned int offset;
2186 unw_rec_list *ptr = alloc_record (spill_psprel);
2187 ptr->r.record.x.ab = ab;
2188 ptr->r.record.x.reg = reg;
2189 ptr->r.record.x.pspoff = offset / 4;
2193 static unw_rec_list *
2194 output_spill_sprel (ab, reg, offset)
2197 unsigned int offset;
2199 unw_rec_list *ptr = alloc_record (spill_sprel);
2200 ptr->r.record.x.ab = ab;
2201 ptr->r.record.x.reg = reg;
2202 ptr->r.record.x.spoff = offset / 4;
2206 static unw_rec_list *
2207 output_spill_psprel_p (ab, reg, offset, predicate)
2210 unsigned int offset;
2211 unsigned int predicate;
2213 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2214 ptr->r.record.x.ab = ab;
2215 ptr->r.record.x.reg = reg;
2216 ptr->r.record.x.pspoff = offset / 4;
2217 ptr->r.record.x.qp = predicate;
2221 static unw_rec_list *
2222 output_spill_sprel_p (ab, reg, offset, predicate)
2225 unsigned int offset;
2226 unsigned int predicate;
2228 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2229 ptr->r.record.x.ab = ab;
2230 ptr->r.record.x.reg = reg;
2231 ptr->r.record.x.spoff = offset / 4;
2232 ptr->r.record.x.qp = predicate;
2236 static unw_rec_list *
2237 output_spill_reg (ab, reg, targ_reg, xy)
2240 unsigned int targ_reg;
2243 unw_rec_list *ptr = alloc_record (spill_reg);
2244 ptr->r.record.x.ab = ab;
2245 ptr->r.record.x.reg = reg;
2246 ptr->r.record.x.treg = targ_reg;
2247 ptr->r.record.x.xy = xy;
2251 static unw_rec_list *
2252 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2255 unsigned int targ_reg;
2257 unsigned int predicate;
2259 unw_rec_list *ptr = alloc_record (spill_reg_p);
2260 ptr->r.record.x.ab = ab;
2261 ptr->r.record.x.reg = reg;
2262 ptr->r.record.x.treg = targ_reg;
2263 ptr->r.record.x.xy = xy;
2264 ptr->r.record.x.qp = predicate;
2268 /* Given a unw_rec_list process the correct format with the
2269 specified function. */
2272 process_one_record (ptr, f)
2276 unsigned long fr_mask, gr_mask;
2278 switch (ptr->r.type)
2284 /* These are taken care of by prologue/prologue_gr. */
2289 if (ptr->r.type == prologue_gr)
2290 output_R2_format (f, ptr->r.record.r.grmask,
2291 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2293 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2295 /* Output descriptor(s) for union of register spills (if any). */
2296 gr_mask = ptr->r.record.r.mask.gr_mem;
2297 fr_mask = ptr->r.record.r.mask.fr_mem;
2300 if ((fr_mask & ~0xfUL) == 0)
2301 output_P6_format (f, fr_mem, fr_mask);
2304 output_P5_format (f, gr_mask, fr_mask);
2309 output_P6_format (f, gr_mem, gr_mask);
2310 if (ptr->r.record.r.mask.br_mem)
2311 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2313 /* output imask descriptor if necessary: */
2314 if (ptr->r.record.r.mask.i)
2315 output_P4_format (f, ptr->r.record.r.mask.i,
2316 ptr->r.record.r.imask_size);
2320 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2324 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2325 ptr->r.record.p.size);
2338 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2341 output_P3_format (f, rp_br, ptr->r.record.p.br);
2344 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2352 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2361 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2371 case bspstore_sprel:
2373 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2376 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2379 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2382 as_bad ("spill_mask record unimplemented.");
2384 case priunat_when_gr:
2385 case priunat_when_mem:
2389 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2391 case priunat_psprel:
2393 case bspstore_psprel:
2395 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2398 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2401 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2405 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2408 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2409 ptr->r.record.x.reg, ptr->r.record.x.t,
2410 ptr->r.record.x.pspoff);
2413 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2414 ptr->r.record.x.reg, ptr->r.record.x.t,
2415 ptr->r.record.x.spoff);
2418 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2419 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2420 ptr->r.record.x.treg, ptr->r.record.x.t);
2422 case spill_psprel_p:
2423 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2424 ptr->r.record.x.ab, ptr->r.record.x.reg,
2425 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2428 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2429 ptr->r.record.x.ab, ptr->r.record.x.reg,
2430 ptr->r.record.x.t, ptr->r.record.x.spoff);
2433 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2434 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2435 ptr->r.record.x.xy, ptr->r.record.x.treg,
2439 as_bad ("record_type_not_valid");
2444 /* Given a unw_rec_list list, process all the records with
2445 the specified function. */
2447 process_unw_records (list, f)
2452 for (ptr = list; ptr; ptr = ptr->next)
2453 process_one_record (ptr, f);
2456 /* Determine the size of a record list in bytes. */
2458 calc_record_size (list)
2462 process_unw_records (list, count_output);
2466 /* Update IMASK bitmask to reflect the fact that one or more registers
2467 of type TYPE are saved starting at instruction with index T. If N
2468 bits are set in REGMASK, it is assumed that instructions T through
2469 T+N-1 save these registers.
2473 1: instruction saves next fp reg
2474 2: instruction saves next general reg
2475 3: instruction saves next branch reg */
2477 set_imask (region, regmask, t, type)
2478 unw_rec_list *region;
2479 unsigned long regmask;
2483 unsigned char *imask;
2484 unsigned long imask_size;
2488 imask = region->r.record.r.mask.i;
2489 imask_size = region->r.record.r.imask_size;
2492 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2493 imask = xmalloc (imask_size);
2494 memset (imask, 0, imask_size);
2496 region->r.record.r.imask_size = imask_size;
2497 region->r.record.r.mask.i = imask;
2501 pos = 2 * (3 - t % 4);
2504 if (i >= imask_size)
2506 as_bad ("Ignoring attempt to spill beyond end of region");
2510 imask[i] |= (type & 0x3) << pos;
2512 regmask &= (regmask - 1);
2523 count_bits (unsigned long mask)
2535 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2536 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2537 containing FIRST_ADDR. */
2540 slot_index (slot_addr, slot_frag, first_addr, first_frag)
2541 unsigned long slot_addr;
2543 unsigned long first_addr;
2546 unsigned long index = 0;
2548 /* First time we are called, the initial address and frag are invalid. */
2549 if (first_addr == 0)
2552 /* If the two addresses are in different frags, then we need to add in
2553 the remaining size of this frag, and then the entire size of intermediate
2555 while (slot_frag != first_frag)
2557 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2559 /* Add in the full size of the frag converted to instruction slots. */
2560 index += 3 * (first_frag->fr_fix >> 4);
2561 /* Subtract away the initial part before first_addr. */
2562 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2563 + ((first_addr & 0x3) - (start_addr & 0x3)));
2565 /* Move to the beginning of the next frag. */
2566 first_frag = first_frag->fr_next;
2567 first_addr = (unsigned long) &first_frag->fr_literal;
2570 /* Add in the used part of the last frag. */
2571 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2572 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2576 /* Optimize unwind record directives. */
2578 static unw_rec_list *
2579 optimize_unw_records (list)
2585 /* If the only unwind record is ".prologue" or ".prologue" followed
2586 by ".body", then we can optimize the unwind directives away. */
2587 if (list->r.type == prologue
2588 && (list->next == NULL
2589 || (list->next->r.type == body && list->next->next == NULL)))
2595 /* Given a complete record list, process any records which have
2596 unresolved fields, (ie length counts for a prologue). After
2597 this has been run, all neccessary information should be available
2598 within each record to generate an image. */
2601 fixup_unw_records (list)
2604 unw_rec_list *ptr, *region = 0;
2605 unsigned long first_addr = 0, rlen = 0, t;
2606 fragS *first_frag = 0;
2608 for (ptr = list; ptr; ptr = ptr->next)
2610 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2611 as_bad (" Insn slot not set in unwind record.");
2612 t = slot_index (ptr->slot_number, ptr->slot_frag,
2613 first_addr, first_frag);
2614 switch (ptr->r.type)
2621 int size, dir_len = 0;
2622 unsigned long last_addr;
2625 first_addr = ptr->slot_number;
2626 first_frag = ptr->slot_frag;
2627 ptr->slot_number = 0;
2628 /* Find either the next body/prologue start, or the end of
2629 the list, and determine the size of the region. */
2630 last_addr = unwind.next_slot_number;
2631 last_frag = unwind.next_slot_frag;
2632 for (last = ptr->next; last != NULL; last = last->next)
2633 if (last->r.type == prologue || last->r.type == prologue_gr
2634 || last->r.type == body)
2636 last_addr = last->slot_number;
2637 last_frag = last->slot_frag;
2640 else if (!last->next)
2642 /* In the absence of an explicit .body directive,
2643 the prologue ends after the last instruction
2644 covered by an unwind directive. */
2645 if (ptr->r.type != body)
2647 last_addr = last->slot_number;
2648 last_frag = last->slot_frag;
2649 switch (last->r.type)
2652 dir_len = (count_bits (last->r.record.p.frmask)
2653 + count_bits (last->r.record.p.grmask));
2657 dir_len += count_bits (last->r.record.p.rmask);
2661 dir_len += count_bits (last->r.record.p.brmask);
2664 dir_len += count_bits (last->r.record.p.grmask);
2673 size = (slot_index (last_addr, last_frag, first_addr, first_frag)
2675 rlen = ptr->r.record.r.rlen = size;
2680 ptr->r.record.b.t = rlen - 1 - t;
2691 case priunat_when_gr:
2692 case priunat_when_mem:
2696 ptr->r.record.p.t = t;
2704 case spill_psprel_p:
2705 ptr->r.record.x.t = t;
2711 as_bad ("frgr_mem record before region record!\n");
2714 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2715 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2716 set_imask (region, ptr->r.record.p.frmask, t, 1);
2717 set_imask (region, ptr->r.record.p.grmask, t, 2);
2722 as_bad ("fr_mem record before region record!\n");
2725 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2726 set_imask (region, ptr->r.record.p.rmask, t, 1);
2731 as_bad ("gr_mem record before region record!\n");
2734 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2735 set_imask (region, ptr->r.record.p.rmask, t, 2);
2740 as_bad ("br_mem record before region record!\n");
2743 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2744 set_imask (region, ptr->r.record.p.brmask, t, 3);
2750 as_bad ("gr_gr record before region record!\n");
2753 set_imask (region, ptr->r.record.p.grmask, t, 2);
2758 as_bad ("br_gr record before region record!\n");
2761 set_imask (region, ptr->r.record.p.brmask, t, 3);
2770 /* Helper routine for output_unw_records. Emits the header for the unwind
2774 setup_unwind_header (int size, unsigned char **mem)
2778 /* pad to pointer-size boundry. */
2779 x = size % md.pointer_size;
2781 extra = md.pointer_size - x;
2783 /* Add 8 for the header + a pointer for the
2784 personality offset. */
2785 *mem = xmalloc (size + extra + 8 + md.pointer_size);
2787 /* Clear the padding area and personality. */
2788 memset (*mem + 8 + size, 0 , extra + md.pointer_size);
2789 /* Initialize the header area. */
2791 md_number_to_chars (*mem, (((bfd_vma) 1 << 48) /* version */
2792 | (unwind.personality_routine
2793 ? ((bfd_vma) 3 << 32) /* U & E handler flags */
2795 | ((size + extra) / md.pointer_size)), /* length */
2801 /* Generate an unwind image from a record list. Returns the number of
2802 bytes in the resulting image. The memory image itselof is returned
2803 in the 'ptr' parameter. */
2805 output_unw_records (list, ptr)
2814 list = optimize_unw_records (list);
2815 fixup_unw_records (list);
2816 size = calc_record_size (list);
2818 if (size > 0 || unwind.force_unwind_entry)
2820 unwind.force_unwind_entry = 0;
2821 extra = setup_unwind_header (size, &mem);
2823 vbyte_mem_ptr = mem + 8;
2824 process_unw_records (list, output_vbyte_mem);
2828 size += extra + 8 + md.pointer_size;
2834 convert_expr_to_ab_reg (e, ab, regp)
2841 if (e->X_op != O_register)
2844 reg = e->X_add_number;
2845 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2848 *regp = reg - REG_GR;
2850 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2851 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2854 *regp = reg - REG_FR;
2856 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2859 *regp = reg - REG_BR;
2866 case REG_PR: *regp = 0; break;
2867 case REG_PSP: *regp = 1; break;
2868 case REG_PRIUNAT: *regp = 2; break;
2869 case REG_BR + 0: *regp = 3; break;
2870 case REG_AR + AR_BSP: *regp = 4; break;
2871 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2872 case REG_AR + AR_RNAT: *regp = 6; break;
2873 case REG_AR + AR_UNAT: *regp = 7; break;
2874 case REG_AR + AR_FPSR: *regp = 8; break;
2875 case REG_AR + AR_PFS: *regp = 9; break;
2876 case REG_AR + AR_LC: *regp = 10; break;
2886 convert_expr_to_xy_reg (e, xy, regp)
2893 if (e->X_op != O_register)
2896 reg = e->X_add_number;
2898 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2901 *regp = reg - REG_GR;
2903 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2906 *regp = reg - REG_FR;
2908 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2911 *regp = reg - REG_BR;
2920 int dummy ATTRIBUTE_UNUSED;
2925 radix = *input_line_pointer++;
2927 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
2929 as_bad ("Radix `%c' unsupported", *input_line_pointer);
2930 ignore_rest_of_line ();
2935 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
2937 dot_special_section (which)
2940 set_section ((char *) special_section_name[which]);
2944 add_unwind_entry (ptr)
2948 unwind.tail->next = ptr;
2953 /* The current entry can in fact be a chain of unwind entries. */
2954 if (unwind.current_entry == NULL)
2955 unwind.current_entry = ptr;
2960 int dummy ATTRIBUTE_UNUSED;
2966 if (e.X_op != O_constant)
2967 as_bad ("Operand to .fframe must be a constant");
2969 add_unwind_entry (output_mem_stack_f (e.X_add_number));
2974 int dummy ATTRIBUTE_UNUSED;
2980 reg = e.X_add_number - REG_GR;
2981 if (e.X_op == O_register && reg < 128)
2983 add_unwind_entry (output_mem_stack_v ());
2984 if (! (unwind.prologue_mask & 2))
2985 add_unwind_entry (output_psp_gr (reg));
2988 as_bad ("First operand to .vframe must be a general register");
2992 dot_vframesp (dummy)
2993 int dummy ATTRIBUTE_UNUSED;
2998 if (e.X_op == O_constant)
3000 add_unwind_entry (output_mem_stack_v ());
3001 add_unwind_entry (output_psp_sprel (e.X_add_number));
3004 as_bad ("First operand to .vframesp must be a general register");
3008 dot_vframepsp (dummy)
3009 int dummy ATTRIBUTE_UNUSED;
3014 if (e.X_op == O_constant)
3016 add_unwind_entry (output_mem_stack_v ());
3017 add_unwind_entry (output_psp_sprel (e.X_add_number));
3020 as_bad ("First operand to .vframepsp must be a general register");
3025 int dummy ATTRIBUTE_UNUSED;
3031 sep = parse_operand (&e1);
3033 as_bad ("No second operand to .save");
3034 sep = parse_operand (&e2);
3036 reg1 = e1.X_add_number;
3037 reg2 = e2.X_add_number - REG_GR;
3039 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3040 if (e1.X_op == O_register)
3042 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3046 case REG_AR + AR_BSP:
3047 add_unwind_entry (output_bsp_when ());
3048 add_unwind_entry (output_bsp_gr (reg2));
3050 case REG_AR + AR_BSPSTORE:
3051 add_unwind_entry (output_bspstore_when ());
3052 add_unwind_entry (output_bspstore_gr (reg2));
3054 case REG_AR + AR_RNAT:
3055 add_unwind_entry (output_rnat_when ());
3056 add_unwind_entry (output_rnat_gr (reg2));
3058 case REG_AR + AR_UNAT:
3059 add_unwind_entry (output_unat_when ());
3060 add_unwind_entry (output_unat_gr (reg2));
3062 case REG_AR + AR_FPSR:
3063 add_unwind_entry (output_fpsr_when ());
3064 add_unwind_entry (output_fpsr_gr (reg2));
3066 case REG_AR + AR_PFS:
3067 add_unwind_entry (output_pfs_when ());
3068 if (! (unwind.prologue_mask & 4))
3069 add_unwind_entry (output_pfs_gr (reg2));
3071 case REG_AR + AR_LC:
3072 add_unwind_entry (output_lc_when ());
3073 add_unwind_entry (output_lc_gr (reg2));
3076 add_unwind_entry (output_rp_when ());
3077 if (! (unwind.prologue_mask & 8))
3078 add_unwind_entry (output_rp_gr (reg2));
3081 add_unwind_entry (output_preds_when ());
3082 if (! (unwind.prologue_mask & 1))
3083 add_unwind_entry (output_preds_gr (reg2));
3086 add_unwind_entry (output_priunat_when_gr ());
3087 add_unwind_entry (output_priunat_gr (reg2));
3090 as_bad ("First operand not a valid register");
3094 as_bad (" Second operand not a valid register");
3097 as_bad ("First operand not a register");
3102 int dummy ATTRIBUTE_UNUSED;
3105 unsigned long ecount; /* # of _additional_ regions to pop */
3108 sep = parse_operand (&e1);
3109 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3111 as_bad ("First operand to .restore must be stack pointer (sp)");
3117 parse_operand (&e2);
3118 if (e2.X_op != O_constant || e2.X_add_number < 0)
3120 as_bad ("Second operand to .restore must be a constant >= 0");
3123 ecount = e2.X_add_number;
3126 ecount = unwind.prologue_count - 1;
3127 add_unwind_entry (output_epilogue (ecount));
3129 if (ecount < unwind.prologue_count)
3130 unwind.prologue_count -= ecount + 1;
3132 unwind.prologue_count = 0;
3136 dot_restorereg (dummy)
3137 int dummy ATTRIBUTE_UNUSED;
3139 unsigned int ab, reg;
3144 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3146 as_bad ("First operand to .restorereg must be a preserved register");
3149 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3153 dot_restorereg_p (dummy)
3154 int dummy ATTRIBUTE_UNUSED;
3156 unsigned int qp, ab, reg;
3160 sep = parse_operand (&e1);
3163 as_bad ("No second operand to .restorereg.p");
3167 parse_operand (&e2);
3169 qp = e1.X_add_number - REG_P;
3170 if (e1.X_op != O_register || qp > 63)
3172 as_bad ("First operand to .restorereg.p must be a predicate");
3176 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3178 as_bad ("Second operand to .restorereg.p must be a preserved register");
3181 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3185 generate_unwind_image (text_name)
3186 const char *text_name;
3189 unsigned char *unw_rec;
3191 /* Force out pending instructions, to make sure all unwind records have
3192 a valid slot_number field. */
3193 ia64_flush_insns ();
3195 /* Generate the unwind record. */
3196 size = output_unw_records (unwind.list, (void **) &unw_rec);
3197 if (size % md.pointer_size != 0)
3198 as_bad ("Unwind record is not a multiple of %d bytes.", md.pointer_size);
3200 /* If there are unwind records, switch sections, and output the info. */
3203 unsigned char *where;
3207 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3208 set_section (sec_name);
3209 bfd_set_section_flags (stdoutput, now_seg,
3210 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3212 /* Make sure the section has 4 byte alignment for ILP32 and
3213 8 byte alignment for LP64. */
3214 frag_align (md.pointer_size_shift, 0, 0);
3215 record_alignment (now_seg, md.pointer_size_shift);
3217 /* Set expression which points to start of unwind descriptor area. */
3218 unwind.info = expr_build_dot ();
3220 where = (unsigned char *) frag_more (size);
3222 /* Issue a label for this address, and keep track of it to put it
3223 in the unwind section. */
3225 /* Copy the information from the unwind record into this section. The
3226 data is already in the correct byte order. */
3227 memcpy (where, unw_rec, size);
3229 /* Add the personality address to the image. */
3230 if (unwind.personality_routine != 0)
3232 exp.X_op = O_symbol;
3233 exp.X_add_symbol = unwind.personality_routine;
3234 exp.X_add_number = 0;
3235 fix_new_exp (frag_now, frag_now_fix () - 8, 8,
3236 &exp, 0, BFD_RELOC_IA64_LTOFF_FPTR64LSB);
3237 unwind.personality_routine = 0;
3241 free_list_records (unwind.list);
3242 unwind.list = unwind.tail = unwind.current_entry = NULL;
3248 dot_handlerdata (dummy)
3249 int dummy ATTRIBUTE_UNUSED;
3251 const char *text_name = segment_name (now_seg);
3253 /* If text section name starts with ".text" (which it should),
3254 strip this prefix off. */
3255 if (strcmp (text_name, ".text") == 0)
3258 unwind.force_unwind_entry = 1;
3260 /* Remember which segment we're in so we can switch back after .endp */
3261 unwind.saved_text_seg = now_seg;
3262 unwind.saved_text_subseg = now_subseg;
3264 /* Generate unwind info into unwind-info section and then leave that
3265 section as the currently active one so dataXX directives go into
3266 the language specific data area of the unwind info block. */
3267 generate_unwind_image (text_name);
3268 demand_empty_rest_of_line ();
3272 dot_unwentry (dummy)
3273 int dummy ATTRIBUTE_UNUSED;
3275 unwind.force_unwind_entry = 1;
3276 demand_empty_rest_of_line ();
3281 int dummy ATTRIBUTE_UNUSED;
3287 reg = e.X_add_number - REG_BR;
3288 if (e.X_op == O_register && reg < 8)
3289 add_unwind_entry (output_rp_br (reg));
3291 as_bad ("First operand not a valid branch register");
3295 dot_savemem (psprel)
3302 sep = parse_operand (&e1);
3304 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3305 sep = parse_operand (&e2);
3307 reg1 = e1.X_add_number;
3308 val = e2.X_add_number;
3310 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3311 if (e1.X_op == O_register)
3313 if (e2.X_op == O_constant)
3317 case REG_AR + AR_BSP:
3318 add_unwind_entry (output_bsp_when ());
3319 add_unwind_entry ((psprel
3321 : output_bsp_sprel) (val));
3323 case REG_AR + AR_BSPSTORE:
3324 add_unwind_entry (output_bspstore_when ());
3325 add_unwind_entry ((psprel
3326 ? output_bspstore_psprel
3327 : output_bspstore_sprel) (val));
3329 case REG_AR + AR_RNAT:
3330 add_unwind_entry (output_rnat_when ());
3331 add_unwind_entry ((psprel
3332 ? output_rnat_psprel
3333 : output_rnat_sprel) (val));
3335 case REG_AR + AR_UNAT:
3336 add_unwind_entry (output_unat_when ());
3337 add_unwind_entry ((psprel
3338 ? output_unat_psprel
3339 : output_unat_sprel) (val));
3341 case REG_AR + AR_FPSR:
3342 add_unwind_entry (output_fpsr_when ());
3343 add_unwind_entry ((psprel
3344 ? output_fpsr_psprel
3345 : output_fpsr_sprel) (val));
3347 case REG_AR + AR_PFS:
3348 add_unwind_entry (output_pfs_when ());
3349 add_unwind_entry ((psprel
3351 : output_pfs_sprel) (val));
3353 case REG_AR + AR_LC:
3354 add_unwind_entry (output_lc_when ());
3355 add_unwind_entry ((psprel
3357 : output_lc_sprel) (val));
3360 add_unwind_entry (output_rp_when ());
3361 add_unwind_entry ((psprel
3363 : output_rp_sprel) (val));
3366 add_unwind_entry (output_preds_when ());
3367 add_unwind_entry ((psprel
3368 ? output_preds_psprel
3369 : output_preds_sprel) (val));
3372 add_unwind_entry (output_priunat_when_mem ());
3373 add_unwind_entry ((psprel
3374 ? output_priunat_psprel
3375 : output_priunat_sprel) (val));
3378 as_bad ("First operand not a valid register");
3382 as_bad (" Second operand not a valid constant");
3385 as_bad ("First operand not a register");
3390 int dummy ATTRIBUTE_UNUSED;
3394 sep = parse_operand (&e1);
3396 parse_operand (&e2);
3398 if (e1.X_op != O_constant)
3399 as_bad ("First operand to .save.g must be a constant.");
3402 int grmask = e1.X_add_number;
3404 add_unwind_entry (output_gr_mem (grmask));
3407 int reg = e2.X_add_number - REG_GR;
3408 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3409 add_unwind_entry (output_gr_gr (grmask, reg));
3411 as_bad ("Second operand is an invalid register.");
3418 int dummy ATTRIBUTE_UNUSED;
3422 sep = parse_operand (&e1);
3424 if (e1.X_op != O_constant)
3425 as_bad ("Operand to .save.f must be a constant.");
3427 add_unwind_entry (output_fr_mem (e1.X_add_number));
3432 int dummy ATTRIBUTE_UNUSED;
3439 sep = parse_operand (&e1);
3440 if (e1.X_op != O_constant)
3442 as_bad ("First operand to .save.b must be a constant.");
3445 brmask = e1.X_add_number;
3449 sep = parse_operand (&e2);
3450 reg = e2.X_add_number - REG_GR;
3451 if (e2.X_op != O_register || reg > 127)
3453 as_bad ("Second operand to .save.b must be a general register.");
3456 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3459 add_unwind_entry (output_br_mem (brmask));
3461 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3462 ignore_rest_of_line ();
3467 int dummy ATTRIBUTE_UNUSED;
3471 sep = parse_operand (&e1);
3473 parse_operand (&e2);
3475 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3476 as_bad ("Both operands of .save.gf must be constants.");
3479 int grmask = e1.X_add_number;
3480 int frmask = e2.X_add_number;
3481 add_unwind_entry (output_frgr_mem (grmask, frmask));
3487 int dummy ATTRIBUTE_UNUSED;
3492 sep = parse_operand (&e);
3493 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3494 ignore_rest_of_line ();
3496 if (e.X_op != O_constant)
3497 as_bad ("Operand to .spill must be a constant");
3499 add_unwind_entry (output_spill_base (e.X_add_number));
3503 dot_spillreg (dummy)
3504 int dummy ATTRIBUTE_UNUSED;
3506 int sep, ab, xy, reg, treg;
3509 sep = parse_operand (&e1);
3512 as_bad ("No second operand to .spillreg");
3516 parse_operand (&e2);
3518 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3520 as_bad ("First operand to .spillreg must be a preserved register");
3524 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3526 as_bad ("Second operand to .spillreg must be a register");
3530 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3534 dot_spillmem (psprel)
3540 sep = parse_operand (&e1);
3543 as_bad ("Second operand missing");
3547 parse_operand (&e2);
3549 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3551 as_bad ("First operand to .spill%s must be a preserved register",
3552 psprel ? "psp" : "sp");
3556 if (e2.X_op != O_constant)
3558 as_bad ("Second operand to .spill%s must be a constant",
3559 psprel ? "psp" : "sp");
3564 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3566 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3570 dot_spillreg_p (dummy)
3571 int dummy ATTRIBUTE_UNUSED;
3573 int sep, ab, xy, reg, treg;
3574 expressionS e1, e2, e3;
3577 sep = parse_operand (&e1);
3580 as_bad ("No second and third operand to .spillreg.p");
3584 sep = parse_operand (&e2);
3587 as_bad ("No third operand to .spillreg.p");
3591 parse_operand (&e3);
3593 qp = e1.X_add_number - REG_P;
3595 if (e1.X_op != O_register || qp > 63)
3597 as_bad ("First operand to .spillreg.p must be a predicate");
3601 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3603 as_bad ("Second operand to .spillreg.p must be a preserved register");
3607 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3609 as_bad ("Third operand to .spillreg.p must be a register");
3613 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3617 dot_spillmem_p (psprel)
3620 expressionS e1, e2, e3;
3624 sep = parse_operand (&e1);
3627 as_bad ("Second operand missing");
3631 parse_operand (&e2);
3634 as_bad ("Second operand missing");
3638 parse_operand (&e3);
3640 qp = e1.X_add_number - REG_P;
3641 if (e1.X_op != O_register || qp > 63)
3643 as_bad ("First operand to .spill%s_p must be a predicate",
3644 psprel ? "psp" : "sp");
3648 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3650 as_bad ("Second operand to .spill%s_p must be a preserved register",
3651 psprel ? "psp" : "sp");
3655 if (e3.X_op != O_constant)
3657 as_bad ("Third operand to .spill%s_p must be a constant",
3658 psprel ? "psp" : "sp");
3663 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3665 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3669 dot_label_state (dummy)
3670 int dummy ATTRIBUTE_UNUSED;
3675 if (e.X_op != O_constant)
3677 as_bad ("Operand to .label_state must be a constant");
3680 add_unwind_entry (output_label_state (e.X_add_number));
3684 dot_copy_state (dummy)
3685 int dummy ATTRIBUTE_UNUSED;
3690 if (e.X_op != O_constant)
3692 as_bad ("Operand to .copy_state must be a constant");
3695 add_unwind_entry (output_copy_state (e.X_add_number));
3700 int dummy ATTRIBUTE_UNUSED;
3705 sep = parse_operand (&e1);
3708 as_bad ("Second operand to .unwabi missing");
3711 sep = parse_operand (&e2);
3712 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3713 ignore_rest_of_line ();
3715 if (e1.X_op != O_constant)
3717 as_bad ("First operand to .unwabi must be a constant");
3721 if (e2.X_op != O_constant)
3723 as_bad ("Second operand to .unwabi must be a constant");
3727 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3731 dot_personality (dummy)
3732 int dummy ATTRIBUTE_UNUSED;
3736 name = input_line_pointer;
3737 c = get_symbol_end ();
3738 p = input_line_pointer;
3739 unwind.personality_routine = symbol_find_or_make (name);
3740 unwind.force_unwind_entry = 1;
3743 demand_empty_rest_of_line ();
3748 int dummy ATTRIBUTE_UNUSED;
3753 unwind.proc_start = expr_build_dot ();
3754 /* Parse names of main and alternate entry points and mark them as
3755 function symbols: */
3759 name = input_line_pointer;
3760 c = get_symbol_end ();
3761 p = input_line_pointer;
3762 sym = symbol_find_or_make (name);
3763 if (unwind.proc_start == 0)
3765 unwind.proc_start = sym;
3767 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3770 if (*input_line_pointer != ',')
3772 ++input_line_pointer;
3774 demand_empty_rest_of_line ();
3777 unwind.prologue_count = 0;
3778 unwind.list = unwind.tail = unwind.current_entry = NULL;
3779 unwind.personality_routine = 0;
3784 int dummy ATTRIBUTE_UNUSED;
3786 unwind.prologue = 0;
3787 unwind.prologue_mask = 0;
3789 add_unwind_entry (output_body ());
3790 demand_empty_rest_of_line ();
3794 dot_prologue (dummy)
3795 int dummy ATTRIBUTE_UNUSED;
3798 int mask = 0, grsave = 0;
3800 if (!is_it_end_of_statement ())
3803 sep = parse_operand (&e1);
3805 as_bad ("No second operand to .prologue");
3806 sep = parse_operand (&e2);
3807 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3808 ignore_rest_of_line ();
3810 if (e1.X_op == O_constant)
3812 mask = e1.X_add_number;
3814 if (e2.X_op == O_constant)
3815 grsave = e2.X_add_number;
3816 else if (e2.X_op == O_register
3817 && (grsave = e2.X_add_number - REG_GR) < 128)
3820 as_bad ("Second operand not a constant or general register");
3822 add_unwind_entry (output_prologue_gr (mask, grsave));
3825 as_bad ("First operand not a constant");
3828 add_unwind_entry (output_prologue ());
3830 unwind.prologue = 1;
3831 unwind.prologue_mask = mask;
3832 ++unwind.prologue_count;
3837 int dummy ATTRIBUTE_UNUSED;
3841 int bytes_per_address;
3844 subsegT saved_subseg;
3845 const char *sec_name, *text_name;
3849 if (unwind.saved_text_seg)
3851 saved_seg = unwind.saved_text_seg;
3852 saved_subseg = unwind.saved_text_subseg;
3853 unwind.saved_text_seg = NULL;
3857 saved_seg = now_seg;
3858 saved_subseg = now_subseg;
3862 Use a slightly ugly scheme to derive the unwind section names from
3863 the text section name:
3865 text sect. unwind table sect.
3866 name: name: comments:
3867 ---------- ----------------- --------------------------------
3869 .text.foo .IA_64.unwind.text.foo
3870 .foo .IA_64.unwind.foo
3872 .gnu.linkonce.ia64unw.foo
3873 _info .IA_64.unwind_info gas issues error message (ditto)
3874 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3876 This mapping is done so that:
3878 (a) An object file with unwind info only in .text will use
3879 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3880 This follows the letter of the ABI and also ensures backwards
3881 compatibility with older toolchains.
3883 (b) An object file with unwind info in multiple text sections
3884 will use separate unwind sections for each text section.
3885 This allows us to properly set the "sh_info" and "sh_link"
3886 fields in SHT_IA_64_UNWIND as required by the ABI and also
3887 lets GNU ld support programs with multiple segments
3888 containing unwind info (as might be the case for certain
3889 embedded applications).
3891 (c) An error is issued if there would be a name clash.
3893 text_name = segment_name (saved_seg);
3894 if (strncmp (text_name, "_info", 5) == 0)
3896 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3898 ignore_rest_of_line ();
3901 if (strcmp (text_name, ".text") == 0)
3904 insn_group_break (1, 0, 0);
3906 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
3908 generate_unwind_image (text_name);
3910 if (unwind.info || unwind.force_unwind_entry)
3912 subseg_set (md.last_text_seg, 0);
3913 unwind.proc_end = expr_build_dot ();
3915 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
3916 set_section ((char *) sec_name);
3917 bfd_set_section_flags (stdoutput, now_seg,
3918 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3920 /* Make sure that section has 4 byte alignment for ILP32 and
3921 8 byte alignment for LP64. */
3922 record_alignment (now_seg, md.pointer_size_shift);
3924 /* Need space for 3 pointers for procedure start, procedure end,
3926 ptr = frag_more (3 * md.pointer_size);
3927 where = frag_now_fix () - (3 * md.pointer_size);
3928 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
3930 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
3931 e.X_op = O_pseudo_fixup;
3932 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3934 e.X_add_symbol = unwind.proc_start;
3935 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
3937 e.X_op = O_pseudo_fixup;
3938 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3940 e.X_add_symbol = unwind.proc_end;
3941 ia64_cons_fix_new (frag_now, where + bytes_per_address,
3942 bytes_per_address, &e);
3946 e.X_op = O_pseudo_fixup;
3947 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3949 e.X_add_symbol = unwind.info;
3950 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
3951 bytes_per_address, &e);
3954 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
3958 subseg_set (saved_seg, saved_subseg);
3960 /* Parse names of main and alternate entry points and set symbol sizes. */
3964 name = input_line_pointer;
3965 c = get_symbol_end ();
3966 p = input_line_pointer;
3967 sym = symbol_find (name);
3968 if (sym && unwind.proc_start
3969 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
3970 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
3972 fragS *fr = symbol_get_frag (unwind.proc_start);
3973 fragS *frag = symbol_get_frag (sym);
3975 /* Check whether the function label is at or beyond last
3977 while (fr && fr != frag)
3981 if (frag == frag_now && SEG_NORMAL (now_seg))
3982 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
3985 symbol_get_obj (sym)->size =
3986 (expressionS *) xmalloc (sizeof (expressionS));
3987 symbol_get_obj (sym)->size->X_op = O_subtract;
3988 symbol_get_obj (sym)->size->X_add_symbol
3989 = symbol_new (FAKE_LABEL_NAME, now_seg,
3990 frag_now_fix (), frag_now);
3991 symbol_get_obj (sym)->size->X_op_symbol = sym;
3992 symbol_get_obj (sym)->size->X_add_number = 0;
3998 if (*input_line_pointer != ',')
4000 ++input_line_pointer;
4002 demand_empty_rest_of_line ();
4003 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4007 dot_template (template)
4010 CURR_SLOT.user_template = template;
4015 int dummy ATTRIBUTE_UNUSED;
4017 int ins, locs, outs, rots;
4019 if (is_it_end_of_statement ())
4020 ins = locs = outs = rots = 0;
4023 ins = get_absolute_expression ();
4024 if (*input_line_pointer++ != ',')
4026 locs = get_absolute_expression ();
4027 if (*input_line_pointer++ != ',')
4029 outs = get_absolute_expression ();
4030 if (*input_line_pointer++ != ',')
4032 rots = get_absolute_expression ();
4034 set_regstack (ins, locs, outs, rots);
4038 as_bad ("Comma expected");
4039 ignore_rest_of_line ();
4046 unsigned num_regs, num_alloced = 0;
4047 struct dynreg **drpp, *dr;
4048 int ch, base_reg = 0;
4054 case DYNREG_GR: base_reg = REG_GR + 32; break;
4055 case DYNREG_FR: base_reg = REG_FR + 32; break;
4056 case DYNREG_PR: base_reg = REG_P + 16; break;
4060 /* First, remove existing names from hash table. */
4061 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4063 hash_delete (md.dynreg_hash, dr->name);
4067 drpp = &md.dynreg[type];
4070 start = input_line_pointer;
4071 ch = get_symbol_end ();
4072 *input_line_pointer = ch;
4073 len = (input_line_pointer - start);
4076 if (*input_line_pointer != '[')
4078 as_bad ("Expected '['");
4081 ++input_line_pointer; /* skip '[' */
4083 num_regs = get_absolute_expression ();
4085 if (*input_line_pointer++ != ']')
4087 as_bad ("Expected ']'");
4092 num_alloced += num_regs;
4096 if (num_alloced > md.rot.num_regs)
4098 as_bad ("Used more than the declared %d rotating registers",
4104 if (num_alloced > 96)
4106 as_bad ("Used more than the available 96 rotating registers");
4111 if (num_alloced > 48)
4113 as_bad ("Used more than the available 48 rotating registers");
4122 name = obstack_alloc (¬es, len + 1);
4123 memcpy (name, start, len);
4128 *drpp = obstack_alloc (¬es, sizeof (*dr));
4129 memset (*drpp, 0, sizeof (*dr));
4134 dr->num_regs = num_regs;
4135 dr->base = base_reg;
4137 base_reg += num_regs;
4139 if (hash_insert (md.dynreg_hash, name, dr))
4141 as_bad ("Attempt to redefine register set `%s'", name);
4145 if (*input_line_pointer != ',')
4147 ++input_line_pointer; /* skip comma */
4150 demand_empty_rest_of_line ();
4154 ignore_rest_of_line ();
4158 dot_byteorder (byteorder)
4161 target_big_endian = byteorder;
4166 int dummy ATTRIBUTE_UNUSED;
4173 option = input_line_pointer;
4174 ch = get_symbol_end ();
4175 if (strcmp (option, "lsb") == 0)
4176 md.flags &= ~EF_IA_64_BE;
4177 else if (strcmp (option, "msb") == 0)
4178 md.flags |= EF_IA_64_BE;
4179 else if (strcmp (option, "abi32") == 0)
4180 md.flags &= ~EF_IA_64_ABI64;
4181 else if (strcmp (option, "abi64") == 0)
4182 md.flags |= EF_IA_64_ABI64;
4184 as_bad ("Unknown psr option `%s'", option);
4185 *input_line_pointer = ch;
4188 if (*input_line_pointer != ',')
4191 ++input_line_pointer;
4194 demand_empty_rest_of_line ();
4199 int dummy ATTRIBUTE_UNUSED;
4201 as_bad (".alias not implemented yet");
4206 int dummy ATTRIBUTE_UNUSED;
4208 new_logical_line (0, get_absolute_expression ());
4209 demand_empty_rest_of_line ();
4213 parse_section_name ()
4219 if (*input_line_pointer != '"')
4221 as_bad ("Missing section name");
4222 ignore_rest_of_line ();
4225 name = demand_copy_C_string (&len);
4228 ignore_rest_of_line ();
4232 if (*input_line_pointer != ',')
4234 as_bad ("Comma expected after section name");
4235 ignore_rest_of_line ();
4238 ++input_line_pointer; /* skip comma */
4246 char *name = parse_section_name ();
4250 md.keep_pending_output = 1;
4253 obj_elf_previous (0);
4254 md.keep_pending_output = 0;
4257 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4260 stmt_float_cons (kind)
4267 case 'd': size = 8; break;
4268 case 'x': size = 10; break;
4275 ia64_do_align (size);
4283 int saved_auto_align = md.auto_align;
4287 md.auto_align = saved_auto_align;
4291 dot_xfloat_cons (kind)
4294 char *name = parse_section_name ();
4298 md.keep_pending_output = 1;
4300 stmt_float_cons (kind);
4301 obj_elf_previous (0);
4302 md.keep_pending_output = 0;
4306 dot_xstringer (zero)
4309 char *name = parse_section_name ();
4313 md.keep_pending_output = 1;
4316 obj_elf_previous (0);
4317 md.keep_pending_output = 0;
4324 int saved_auto_align = md.auto_align;
4325 char *name = parse_section_name ();
4329 md.keep_pending_output = 1;
4333 md.auto_align = saved_auto_align;
4334 obj_elf_previous (0);
4335 md.keep_pending_output = 0;
4339 dot_xfloat_cons_ua (kind)
4342 int saved_auto_align = md.auto_align;
4343 char *name = parse_section_name ();
4347 md.keep_pending_output = 1;
4350 stmt_float_cons (kind);
4351 md.auto_align = saved_auto_align;
4352 obj_elf_previous (0);
4353 md.keep_pending_output = 0;
4356 /* .reg.val <regname>,value */
4360 int dummy ATTRIBUTE_UNUSED;
4365 if (reg.X_op != O_register)
4367 as_bad (_("Register name expected"));
4368 ignore_rest_of_line ();
4370 else if (*input_line_pointer++ != ',')
4372 as_bad (_("Comma expected"));
4373 ignore_rest_of_line ();
4377 valueT value = get_absolute_expression ();
4378 int regno = reg.X_add_number;
4379 if (regno < REG_GR || regno > REG_GR + 128)
4380 as_warn (_("Register value annotation ignored"));
4383 gr_values[regno - REG_GR].known = 1;
4384 gr_values[regno - REG_GR].value = value;
4385 gr_values[regno - REG_GR].path = md.path;
4388 demand_empty_rest_of_line ();
4391 /* select dv checking mode
4396 A stop is inserted when changing modes
4403 if (md.manual_bundling)
4404 as_warn (_("Directive invalid within a bundle"));
4406 if (type == 'E' || type == 'A')
4407 md.mode_explicitly_set = 0;
4409 md.mode_explicitly_set = 1;
4416 if (md.explicit_mode)
4417 insn_group_break (1, 0, 0);
4418 md.explicit_mode = 0;
4422 if (!md.explicit_mode)
4423 insn_group_break (1, 0, 0);
4424 md.explicit_mode = 1;
4428 if (md.explicit_mode != md.default_explicit_mode)
4429 insn_group_break (1, 0, 0);
4430 md.explicit_mode = md.default_explicit_mode;
4431 md.mode_explicitly_set = 0;
4442 for (regno = 0; regno < 64; regno++)
4444 if (mask & ((valueT) 1 << regno))
4446 fprintf (stderr, "%s p%d", comma, regno);
4453 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4454 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4455 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4456 .pred.safe_across_calls p1 [, p2 [,...]]
4465 int p1 = -1, p2 = -1;
4469 if (*input_line_pointer != '"')
4471 as_bad (_("Missing predicate relation type"));
4472 ignore_rest_of_line ();
4478 char *form = demand_copy_C_string (&len);
4479 if (strcmp (form, "mutex") == 0)
4481 else if (strcmp (form, "clear") == 0)
4483 else if (strcmp (form, "imply") == 0)
4487 as_bad (_("Unrecognized predicate relation type"));
4488 ignore_rest_of_line ();
4492 if (*input_line_pointer == ',')
4493 ++input_line_pointer;
4503 if (toupper (*input_line_pointer) != 'P'
4504 || (regno = atoi (++input_line_pointer)) < 0
4507 as_bad (_("Predicate register expected"));
4508 ignore_rest_of_line ();
4511 while (isdigit (*input_line_pointer))
4512 ++input_line_pointer;
4519 as_warn (_("Duplicate predicate register ignored"));
4522 /* See if it's a range. */
4523 if (*input_line_pointer == '-')
4526 ++input_line_pointer;
4528 if (toupper (*input_line_pointer) != 'P'
4529 || (regno = atoi (++input_line_pointer)) < 0
4532 as_bad (_("Predicate register expected"));
4533 ignore_rest_of_line ();
4536 while (isdigit (*input_line_pointer))
4537 ++input_line_pointer;
4541 as_bad (_("Bad register range"));
4542 ignore_rest_of_line ();
4553 if (*input_line_pointer != ',')
4555 ++input_line_pointer;
4564 clear_qp_mutex (mask);
4565 clear_qp_implies (mask, (valueT) 0);
4568 if (count != 2 || p1 == -1 || p2 == -1)
4569 as_bad (_("Predicate source and target required"));
4570 else if (p1 == 0 || p2 == 0)
4571 as_bad (_("Use of p0 is not valid in this context"));
4573 add_qp_imply (p1, p2);
4578 as_bad (_("At least two PR arguments expected"));
4583 as_bad (_("Use of p0 is not valid in this context"));
4586 add_qp_mutex (mask);
4589 /* note that we don't override any existing relations */
4592 as_bad (_("At least one PR argument expected"));
4597 fprintf (stderr, "Safe across calls: ");
4598 print_prmask (mask);
4599 fprintf (stderr, "\n");
4601 qp_safe_across_calls = mask;
4604 demand_empty_rest_of_line ();
4607 /* .entry label [, label [, ...]]
4608 Hint to DV code that the given labels are to be considered entry points.
4609 Otherwise, only global labels are considered entry points. */
4613 int dummy ATTRIBUTE_UNUSED;
4622 name = input_line_pointer;
4623 c = get_symbol_end ();
4624 symbolP = symbol_find_or_make (name);
4626 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4628 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4631 *input_line_pointer = c;
4633 c = *input_line_pointer;
4636 input_line_pointer++;
4638 if (*input_line_pointer == '\n')
4644 demand_empty_rest_of_line ();
4647 /* .mem.offset offset, base
4648 "base" is used to distinguish between offsets from a different base. */
4651 dot_mem_offset (dummy)
4652 int dummy ATTRIBUTE_UNUSED;
4654 md.mem_offset.hint = 1;
4655 md.mem_offset.offset = get_absolute_expression ();
4656 if (*input_line_pointer != ',')
4658 as_bad (_("Comma expected"));
4659 ignore_rest_of_line ();
4662 ++input_line_pointer;
4663 md.mem_offset.base = get_absolute_expression ();
4664 demand_empty_rest_of_line ();
4667 /* ia64-specific pseudo-ops: */
4668 const pseudo_typeS md_pseudo_table[] =
4670 { "radix", dot_radix, 0 },
4671 { "lcomm", s_lcomm_bytes, 1 },
4672 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4673 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4674 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4675 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4676 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4677 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4678 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4679 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4680 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4681 { "proc", dot_proc, 0 },
4682 { "body", dot_body, 0 },
4683 { "prologue", dot_prologue, 0 },
4684 { "endp", dot_endp, 0 },
4685 { "file", dwarf2_directive_file, 0 },
4686 { "loc", dwarf2_directive_loc, 0 },
4688 { "fframe", dot_fframe, 0 },
4689 { "vframe", dot_vframe, 0 },
4690 { "vframesp", dot_vframesp, 0 },
4691 { "vframepsp", dot_vframepsp, 0 },
4692 { "save", dot_save, 0 },
4693 { "restore", dot_restore, 0 },
4694 { "restorereg", dot_restorereg, 0 },
4695 { "restorereg.p", dot_restorereg_p, 0 },
4696 { "handlerdata", dot_handlerdata, 0 },
4697 { "unwentry", dot_unwentry, 0 },
4698 { "altrp", dot_altrp, 0 },
4699 { "savesp", dot_savemem, 0 },
4700 { "savepsp", dot_savemem, 1 },
4701 { "save.g", dot_saveg, 0 },
4702 { "save.f", dot_savef, 0 },
4703 { "save.b", dot_saveb, 0 },
4704 { "save.gf", dot_savegf, 0 },
4705 { "spill", dot_spill, 0 },
4706 { "spillreg", dot_spillreg, 0 },
4707 { "spillsp", dot_spillmem, 0 },
4708 { "spillpsp", dot_spillmem, 1 },
4709 { "spillreg.p", dot_spillreg_p, 0 },
4710 { "spillsp.p", dot_spillmem_p, 0 },
4711 { "spillpsp.p", dot_spillmem_p, 1 },
4712 { "label_state", dot_label_state, 0 },
4713 { "copy_state", dot_copy_state, 0 },
4714 { "unwabi", dot_unwabi, 0 },
4715 { "personality", dot_personality, 0 },
4717 { "estate", dot_estate, 0 },
4719 { "mii", dot_template, 0x0 },
4720 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4721 { "mlx", dot_template, 0x2 },
4722 { "mmi", dot_template, 0x4 },
4723 { "mfi", dot_template, 0x6 },
4724 { "mmf", dot_template, 0x7 },
4725 { "mib", dot_template, 0x8 },
4726 { "mbb", dot_template, 0x9 },
4727 { "bbb", dot_template, 0xb },
4728 { "mmb", dot_template, 0xc },
4729 { "mfb", dot_template, 0xe },
4731 { "lb", dot_scope, 0 },
4732 { "le", dot_scope, 1 },
4734 { "align", s_align_bytes, 0 },
4735 { "regstk", dot_regstk, 0 },
4736 { "rotr", dot_rot, DYNREG_GR },
4737 { "rotf", dot_rot, DYNREG_FR },
4738 { "rotp", dot_rot, DYNREG_PR },
4739 { "lsb", dot_byteorder, 0 },
4740 { "msb", dot_byteorder, 1 },
4741 { "psr", dot_psr, 0 },
4742 { "alias", dot_alias, 0 },
4743 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4745 { "xdata1", dot_xdata, 1 },
4746 { "xdata2", dot_xdata, 2 },
4747 { "xdata4", dot_xdata, 4 },
4748 { "xdata8", dot_xdata, 8 },
4749 { "xreal4", dot_xfloat_cons, 'f' },
4750 { "xreal8", dot_xfloat_cons, 'd' },
4751 { "xreal10", dot_xfloat_cons, 'x' },
4752 { "xstring", dot_xstringer, 0 },
4753 { "xstringz", dot_xstringer, 1 },
4755 /* unaligned versions: */
4756 { "xdata2.ua", dot_xdata_ua, 2 },
4757 { "xdata4.ua", dot_xdata_ua, 4 },
4758 { "xdata8.ua", dot_xdata_ua, 8 },
4759 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4760 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4761 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4763 /* annotations/DV checking support */
4764 { "entry", dot_entry, 0 },
4765 { "mem.offset", dot_mem_offset, 0 },
4766 { "pred.rel", dot_pred_rel, 0 },
4767 { "pred.rel.clear", dot_pred_rel, 'c' },
4768 { "pred.rel.imply", dot_pred_rel, 'i' },
4769 { "pred.rel.mutex", dot_pred_rel, 'm' },
4770 { "pred.safe_across_calls", dot_pred_rel, 's' },
4771 { "reg.val", dot_reg_val, 0 },
4772 { "auto", dot_dv_mode, 'a' },
4773 { "explicit", dot_dv_mode, 'e' },
4774 { "default", dot_dv_mode, 'd' },
4776 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
4777 IA-64 aligns data allocation pseudo-ops by default, so we have to
4778 tell it that these ones are supposed to be unaligned. Long term,
4779 should rewrite so that only IA-64 specific data allocation pseudo-ops
4780 are aligned by default. */
4781 {"2byte", stmt_cons_ua, 2},
4782 {"4byte", stmt_cons_ua, 4},
4783 {"8byte", stmt_cons_ua, 8},
4788 static const struct pseudo_opcode
4791 void (*handler) (int);
4796 /* these are more like pseudo-ops, but don't start with a dot */
4797 { "data1", cons, 1 },
4798 { "data2", cons, 2 },
4799 { "data4", cons, 4 },
4800 { "data8", cons, 8 },
4801 { "data16", cons, 16 },
4802 { "real4", stmt_float_cons, 'f' },
4803 { "real8", stmt_float_cons, 'd' },
4804 { "real10", stmt_float_cons, 'x' },
4805 { "string", stringer, 0 },
4806 { "stringz", stringer, 1 },
4808 /* unaligned versions: */
4809 { "data2.ua", stmt_cons_ua, 2 },
4810 { "data4.ua", stmt_cons_ua, 4 },
4811 { "data8.ua", stmt_cons_ua, 8 },
4812 { "data16.ua", stmt_cons_ua, 16 },
4813 { "real4.ua", float_cons, 'f' },
4814 { "real8.ua", float_cons, 'd' },
4815 { "real10.ua", float_cons, 'x' },
4818 /* Declare a register by creating a symbol for it and entering it in
4819 the symbol table. */
4822 declare_register (name, regnum)
4829 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
4831 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
4833 as_fatal ("Inserting \"%s\" into register table failed: %s",
4840 declare_register_set (prefix, num_regs, base_regnum)
4848 for (i = 0; i < num_regs; ++i)
4850 sprintf (name, "%s%u", prefix, i);
4851 declare_register (name, base_regnum + i);
4856 operand_width (opnd)
4857 enum ia64_opnd opnd;
4859 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
4860 unsigned int bits = 0;
4864 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
4865 bits += odesc->field[i].bits;
4870 static enum operand_match_result
4871 operand_match (idesc, index, e)
4872 const struct ia64_opcode *idesc;
4876 enum ia64_opnd opnd = idesc->operands[index];
4877 int bits, relocatable = 0;
4878 struct insn_fix *fix;
4885 case IA64_OPND_AR_CCV:
4886 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
4887 return OPERAND_MATCH;
4890 case IA64_OPND_AR_PFS:
4891 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
4892 return OPERAND_MATCH;
4896 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
4897 return OPERAND_MATCH;
4901 if (e->X_op == O_register && e->X_add_number == REG_IP)
4902 return OPERAND_MATCH;
4906 if (e->X_op == O_register && e->X_add_number == REG_PR)
4907 return OPERAND_MATCH;
4910 case IA64_OPND_PR_ROT:
4911 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
4912 return OPERAND_MATCH;
4916 if (e->X_op == O_register && e->X_add_number == REG_PSR)
4917 return OPERAND_MATCH;
4920 case IA64_OPND_PSR_L:
4921 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
4922 return OPERAND_MATCH;
4925 case IA64_OPND_PSR_UM:
4926 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
4927 return OPERAND_MATCH;
4931 if (e->X_op == O_constant)
4933 if (e->X_add_number == 1)
4934 return OPERAND_MATCH;
4936 return OPERAND_OUT_OF_RANGE;
4941 if (e->X_op == O_constant)
4943 if (e->X_add_number == 8)
4944 return OPERAND_MATCH;
4946 return OPERAND_OUT_OF_RANGE;
4951 if (e->X_op == O_constant)
4953 if (e->X_add_number == 16)
4954 return OPERAND_MATCH;
4956 return OPERAND_OUT_OF_RANGE;
4960 /* register operands: */
4963 if (e->X_op == O_register && e->X_add_number >= REG_AR
4964 && e->X_add_number < REG_AR + 128)
4965 return OPERAND_MATCH;
4970 if (e->X_op == O_register && e->X_add_number >= REG_BR
4971 && e->X_add_number < REG_BR + 8)
4972 return OPERAND_MATCH;
4976 if (e->X_op == O_register && e->X_add_number >= REG_CR
4977 && e->X_add_number < REG_CR + 128)
4978 return OPERAND_MATCH;
4985 if (e->X_op == O_register && e->X_add_number >= REG_FR
4986 && e->X_add_number < REG_FR + 128)
4987 return OPERAND_MATCH;
4992 if (e->X_op == O_register && e->X_add_number >= REG_P
4993 && e->X_add_number < REG_P + 64)
4994 return OPERAND_MATCH;
5000 if (e->X_op == O_register && e->X_add_number >= REG_GR
5001 && e->X_add_number < REG_GR + 128)
5002 return OPERAND_MATCH;
5005 case IA64_OPND_R3_2:
5006 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5008 if (e->X_add_number < REG_GR + 4)
5009 return OPERAND_MATCH;
5010 else if (e->X_add_number < REG_GR + 128)
5011 return OPERAND_OUT_OF_RANGE;
5015 /* indirect operands: */
5016 case IA64_OPND_CPUID_R3:
5017 case IA64_OPND_DBR_R3:
5018 case IA64_OPND_DTR_R3:
5019 case IA64_OPND_ITR_R3:
5020 case IA64_OPND_IBR_R3:
5021 case IA64_OPND_MSR_R3:
5022 case IA64_OPND_PKR_R3:
5023 case IA64_OPND_PMC_R3:
5024 case IA64_OPND_PMD_R3:
5025 case IA64_OPND_RR_R3:
5026 if (e->X_op == O_index && e->X_op_symbol
5027 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5028 == opnd - IA64_OPND_CPUID_R3))
5029 return OPERAND_MATCH;
5033 if (e->X_op == O_index && !e->X_op_symbol)
5034 return OPERAND_MATCH;
5037 /* immediate operands: */
5038 case IA64_OPND_CNT2a:
5039 case IA64_OPND_LEN4:
5040 case IA64_OPND_LEN6:
5041 bits = operand_width (idesc->operands[index]);
5042 if (e->X_op == O_constant)
5044 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5045 return OPERAND_MATCH;
5047 return OPERAND_OUT_OF_RANGE;
5051 case IA64_OPND_CNT2b:
5052 if (e->X_op == O_constant)
5054 if ((bfd_vma) (e->X_add_number - 1) < 3)
5055 return OPERAND_MATCH;
5057 return OPERAND_OUT_OF_RANGE;
5061 case IA64_OPND_CNT2c:
5062 val = e->X_add_number;
5063 if (e->X_op == O_constant)
5065 if ((val == 0 || val == 7 || val == 15 || val == 16))
5066 return OPERAND_MATCH;
5068 return OPERAND_OUT_OF_RANGE;
5073 /* SOR must be an integer multiple of 8 */
5074 if (e->X_op == O_constant && e->X_add_number & 0x7)
5075 return OPERAND_OUT_OF_RANGE;
5078 if (e->X_op == O_constant)
5080 if ((bfd_vma) e->X_add_number <= 96)
5081 return OPERAND_MATCH;
5083 return OPERAND_OUT_OF_RANGE;
5087 case IA64_OPND_IMMU62:
5088 if (e->X_op == O_constant)
5090 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5091 return OPERAND_MATCH;
5093 return OPERAND_OUT_OF_RANGE;
5097 /* FIXME -- need 62-bit relocation type */
5098 as_bad (_("62-bit relocation not yet implemented"));
5102 case IA64_OPND_IMMU64:
5103 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5104 || e->X_op == O_subtract)
5106 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5107 fix->code = BFD_RELOC_IA64_IMM64;
5108 if (e->X_op != O_subtract)
5110 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5111 if (e->X_op == O_pseudo_fixup)
5115 fix->opnd = idesc->operands[index];
5118 ++CURR_SLOT.num_fixups;
5119 return OPERAND_MATCH;
5121 else if (e->X_op == O_constant)
5122 return OPERAND_MATCH;
5125 case IA64_OPND_CCNT5:
5126 case IA64_OPND_CNT5:
5127 case IA64_OPND_CNT6:
5128 case IA64_OPND_CPOS6a:
5129 case IA64_OPND_CPOS6b:
5130 case IA64_OPND_CPOS6c:
5131 case IA64_OPND_IMMU2:
5132 case IA64_OPND_IMMU7a:
5133 case IA64_OPND_IMMU7b:
5134 case IA64_OPND_IMMU21:
5135 case IA64_OPND_IMMU24:
5136 case IA64_OPND_MBTYPE4:
5137 case IA64_OPND_MHTYPE8:
5138 case IA64_OPND_POS6:
5139 bits = operand_width (idesc->operands[index]);
5140 if (e->X_op == O_constant)
5142 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5143 return OPERAND_MATCH;
5145 return OPERAND_OUT_OF_RANGE;
5149 case IA64_OPND_IMMU9:
5150 bits = operand_width (idesc->operands[index]);
5151 if (e->X_op == O_constant)
5153 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5155 int lobits = e->X_add_number & 0x3;
5156 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5157 e->X_add_number |= (bfd_vma) 0x3;
5158 return OPERAND_MATCH;
5161 return OPERAND_OUT_OF_RANGE;
5165 case IA64_OPND_IMM44:
5166 /* least 16 bits must be zero */
5167 if ((e->X_add_number & 0xffff) != 0)
5168 /* XXX technically, this is wrong: we should not be issuing warning
5169 messages until we're sure this instruction pattern is going to
5171 as_warn (_("lower 16 bits of mask ignored"));
5173 if (e->X_op == O_constant)
5175 if (((e->X_add_number >= 0
5176 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5177 || (e->X_add_number < 0
5178 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5181 if (e->X_add_number >= 0
5182 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5184 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5186 return OPERAND_MATCH;
5189 return OPERAND_OUT_OF_RANGE;
5193 case IA64_OPND_IMM17:
5194 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5195 if (e->X_op == O_constant)
5197 if (((e->X_add_number >= 0
5198 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5199 || (e->X_add_number < 0
5200 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5203 if (e->X_add_number >= 0
5204 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5206 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5208 return OPERAND_MATCH;
5211 return OPERAND_OUT_OF_RANGE;
5215 case IA64_OPND_IMM14:
5216 case IA64_OPND_IMM22:
5218 case IA64_OPND_IMM1:
5219 case IA64_OPND_IMM8:
5220 case IA64_OPND_IMM8U4:
5221 case IA64_OPND_IMM8M1:
5222 case IA64_OPND_IMM8M1U4:
5223 case IA64_OPND_IMM8M1U8:
5224 case IA64_OPND_IMM9a:
5225 case IA64_OPND_IMM9b:
5226 bits = operand_width (idesc->operands[index]);
5227 if (relocatable && (e->X_op == O_symbol
5228 || e->X_op == O_subtract
5229 || e->X_op == O_pseudo_fixup))
5231 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5233 if (idesc->operands[index] == IA64_OPND_IMM14)
5234 fix->code = BFD_RELOC_IA64_IMM14;
5236 fix->code = BFD_RELOC_IA64_IMM22;
5238 if (e->X_op != O_subtract)
5240 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5241 if (e->X_op == O_pseudo_fixup)
5245 fix->opnd = idesc->operands[index];
5248 ++CURR_SLOT.num_fixups;
5249 return OPERAND_MATCH;
5251 else if (e->X_op != O_constant
5252 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5253 return OPERAND_MISMATCH;
5255 if (opnd == IA64_OPND_IMM8M1U4)
5257 /* Zero is not valid for unsigned compares that take an adjusted
5258 constant immediate range. */
5259 if (e->X_add_number == 0)
5260 return OPERAND_OUT_OF_RANGE;
5262 /* Sign-extend 32-bit unsigned numbers, so that the following range
5263 checks will work. */
5264 val = e->X_add_number;
5265 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5266 && ((val & ((bfd_vma) 1 << 31)) != 0))
5267 val = ((val << 32) >> 32);
5269 /* Check for 0x100000000. This is valid because
5270 0x100000000-1 is the same as ((uint32_t) -1). */
5271 if (val == ((bfd_signed_vma) 1 << 32))
5272 return OPERAND_MATCH;
5276 else if (opnd == IA64_OPND_IMM8M1U8)
5278 /* Zero is not valid for unsigned compares that take an adjusted
5279 constant immediate range. */
5280 if (e->X_add_number == 0)
5281 return OPERAND_OUT_OF_RANGE;
5283 /* Check for 0x10000000000000000. */
5284 if (e->X_op == O_big)
5286 if (generic_bignum[0] == 0
5287 && generic_bignum[1] == 0
5288 && generic_bignum[2] == 0
5289 && generic_bignum[3] == 0
5290 && generic_bignum[4] == 1)
5291 return OPERAND_MATCH;
5293 return OPERAND_OUT_OF_RANGE;
5296 val = e->X_add_number - 1;
5298 else if (opnd == IA64_OPND_IMM8M1)
5299 val = e->X_add_number - 1;
5300 else if (opnd == IA64_OPND_IMM8U4)
5302 /* Sign-extend 32-bit unsigned numbers, so that the following range
5303 checks will work. */
5304 val = e->X_add_number;
5305 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5306 && ((val & ((bfd_vma) 1 << 31)) != 0))
5307 val = ((val << 32) >> 32);
5310 val = e->X_add_number;
5312 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5313 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5314 return OPERAND_MATCH;
5316 return OPERAND_OUT_OF_RANGE;
5318 case IA64_OPND_INC3:
5319 /* +/- 1, 4, 8, 16 */
5320 val = e->X_add_number;
5323 if (e->X_op == O_constant)
5325 if ((val == 1 || val == 4 || val == 8 || val == 16))
5326 return OPERAND_MATCH;
5328 return OPERAND_OUT_OF_RANGE;
5332 case IA64_OPND_TGT25:
5333 case IA64_OPND_TGT25b:
5334 case IA64_OPND_TGT25c:
5335 case IA64_OPND_TGT64:
5336 if (e->X_op == O_symbol)
5338 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5339 if (opnd == IA64_OPND_TGT25)
5340 fix->code = BFD_RELOC_IA64_PCREL21F;
5341 else if (opnd == IA64_OPND_TGT25b)
5342 fix->code = BFD_RELOC_IA64_PCREL21M;
5343 else if (opnd == IA64_OPND_TGT25c)
5344 fix->code = BFD_RELOC_IA64_PCREL21B;
5345 else if (opnd == IA64_OPND_TGT64)
5346 fix->code = BFD_RELOC_IA64_PCREL60B;
5350 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5351 fix->opnd = idesc->operands[index];
5354 ++CURR_SLOT.num_fixups;
5355 return OPERAND_MATCH;
5357 case IA64_OPND_TAG13:
5358 case IA64_OPND_TAG13b:
5362 return OPERAND_MATCH;
5365 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5366 /* There are no external relocs for TAG13/TAG13b fields, so we
5367 create a dummy reloc. This will not live past md_apply_fix3. */
5368 fix->code = BFD_RELOC_UNUSED;
5369 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5370 fix->opnd = idesc->operands[index];
5373 ++CURR_SLOT.num_fixups;
5374 return OPERAND_MATCH;
5384 return OPERAND_MISMATCH;
5393 memset (e, 0, sizeof (*e));
5396 if (*input_line_pointer != '}')
5398 sep = *input_line_pointer++;
5402 if (!md.manual_bundling)
5403 as_warn ("Found '}' when manual bundling is off");
5405 CURR_SLOT.manual_bundling_off = 1;
5406 md.manual_bundling = 0;
5412 /* Returns the next entry in the opcode table that matches the one in
5413 IDESC, and frees the entry in IDESC. If no matching entry is
5414 found, NULL is returned instead. */
5416 static struct ia64_opcode *
5417 get_next_opcode (struct ia64_opcode *idesc)
5419 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5420 ia64_free_opcode (idesc);
5424 /* Parse the operands for the opcode and find the opcode variant that
5425 matches the specified operands, or NULL if no match is possible. */
5427 static struct ia64_opcode *
5428 parse_operands (idesc)
5429 struct ia64_opcode *idesc;
5431 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5432 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5433 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5434 enum operand_match_result result;
5436 char *first_arg = 0, *end, *saved_input_pointer;
5439 assert (strlen (idesc->name) <= 128);
5441 strcpy (mnemonic, idesc->name);
5442 if (idesc->operands[2] == IA64_OPND_SOF)
5444 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5445 can't parse the first operand until we have parsed the
5446 remaining operands of the "alloc" instruction. */
5448 first_arg = input_line_pointer;
5449 end = strchr (input_line_pointer, '=');
5452 as_bad ("Expected separator `='");
5455 input_line_pointer = end + 1;
5460 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5462 sep = parse_operand (CURR_SLOT.opnd + i);
5463 if (CURR_SLOT.opnd[i].X_op == O_absent)
5468 if (sep != '=' && sep != ',')
5473 if (num_outputs > 0)
5474 as_bad ("Duplicate equal sign (=) in instruction");
5476 num_outputs = i + 1;
5481 as_bad ("Illegal operand separator `%c'", sep);
5485 if (idesc->operands[2] == IA64_OPND_SOF)
5487 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5488 know (strcmp (idesc->name, "alloc") == 0);
5489 if (num_operands == 5 /* first_arg not included in this count! */
5490 && CURR_SLOT.opnd[2].X_op == O_constant
5491 && CURR_SLOT.opnd[3].X_op == O_constant
5492 && CURR_SLOT.opnd[4].X_op == O_constant
5493 && CURR_SLOT.opnd[5].X_op == O_constant)
5495 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5496 CURR_SLOT.opnd[3].X_add_number,
5497 CURR_SLOT.opnd[4].X_add_number,
5498 CURR_SLOT.opnd[5].X_add_number);
5500 /* now we can parse the first arg: */
5501 saved_input_pointer = input_line_pointer;
5502 input_line_pointer = first_arg;
5503 sep = parse_operand (CURR_SLOT.opnd + 0);
5505 --num_outputs; /* force error */
5506 input_line_pointer = saved_input_pointer;
5508 CURR_SLOT.opnd[2].X_add_number = sof;
5509 CURR_SLOT.opnd[3].X_add_number
5510 = sof - CURR_SLOT.opnd[4].X_add_number;
5511 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5515 highest_unmatched_operand = 0;
5516 curr_out_of_range_pos = -1;
5518 expected_operand = idesc->operands[0];
5519 for (; idesc; idesc = get_next_opcode (idesc))
5521 if (num_outputs != idesc->num_outputs)
5522 continue; /* mismatch in # of outputs */
5524 CURR_SLOT.num_fixups = 0;
5526 /* Try to match all operands. If we see an out-of-range operand,
5527 then continue trying to match the rest of the operands, since if
5528 the rest match, then this idesc will give the best error message. */
5530 out_of_range_pos = -1;
5531 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5533 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5534 if (result != OPERAND_MATCH)
5536 if (result != OPERAND_OUT_OF_RANGE)
5538 if (out_of_range_pos < 0)
5539 /* remember position of the first out-of-range operand: */
5540 out_of_range_pos = i;
5544 /* If we did not match all operands, or if at least one operand was
5545 out-of-range, then this idesc does not match. Keep track of which
5546 idesc matched the most operands before failing. If we have two
5547 idescs that failed at the same position, and one had an out-of-range
5548 operand, then prefer the out-of-range operand. Thus if we have
5549 "add r0=0x1000000,r1" we get an error saying the constant is out
5550 of range instead of an error saying that the constant should have been
5553 if (i != num_operands || out_of_range_pos >= 0)
5555 if (i > highest_unmatched_operand
5556 || (i == highest_unmatched_operand
5557 && out_of_range_pos > curr_out_of_range_pos))
5559 highest_unmatched_operand = i;
5560 if (out_of_range_pos >= 0)
5562 expected_operand = idesc->operands[out_of_range_pos];
5563 error_pos = out_of_range_pos;
5567 expected_operand = idesc->operands[i];
5570 curr_out_of_range_pos = out_of_range_pos;
5575 if (num_operands < NELEMS (idesc->operands)
5576 && idesc->operands[num_operands])
5577 continue; /* mismatch in number of arguments */
5583 if (expected_operand)
5584 as_bad ("Operand %u of `%s' should be %s",
5585 error_pos + 1, mnemonic,
5586 elf64_ia64_operands[expected_operand].desc);
5588 as_bad ("Operand mismatch");
5594 /* Keep track of state necessary to determine whether a NOP is necessary
5595 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5596 detect a case where additional NOPs may be necessary. */
5598 errata_nop_necessary_p (slot, insn_unit)
5600 enum ia64_unit insn_unit;
5603 struct group *this_group = md.last_groups + md.group_idx;
5604 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5605 struct ia64_opcode *idesc = slot->idesc;
5607 /* Test whether this could be the first insn in a problematic sequence. */
5608 if (insn_unit == IA64_UNIT_F)
5610 for (i = 0; i < idesc->num_outputs; i++)
5611 if (idesc->operands[i] == IA64_OPND_P1
5612 || idesc->operands[i] == IA64_OPND_P2)
5614 int regno = slot->opnd[i].X_add_number - REG_P;
5615 /* Ignore invalid operands; they generate errors elsewhere. */
5618 this_group->p_reg_set[regno] = 1;
5622 /* Test whether this could be the second insn in a problematic sequence. */
5623 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5624 && prev_group->p_reg_set[slot->qp_regno])
5626 for (i = 0; i < idesc->num_outputs; i++)
5627 if (idesc->operands[i] == IA64_OPND_R1
5628 || idesc->operands[i] == IA64_OPND_R2
5629 || idesc->operands[i] == IA64_OPND_R3)
5631 int regno = slot->opnd[i].X_add_number - REG_GR;
5632 /* Ignore invalid operands; they generate errors elsewhere. */
5635 if (strncmp (idesc->name, "add", 3) != 0
5636 && strncmp (idesc->name, "sub", 3) != 0
5637 && strncmp (idesc->name, "shladd", 6) != 0
5638 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5639 this_group->g_reg_set_conditionally[regno] = 1;
5643 /* Test whether this could be the third insn in a problematic sequence. */
5644 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5646 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5647 idesc->operands[i] == IA64_OPND_R3
5648 /* For mov indirect. */
5649 || idesc->operands[i] == IA64_OPND_RR_R3
5650 || idesc->operands[i] == IA64_OPND_DBR_R3
5651 || idesc->operands[i] == IA64_OPND_IBR_R3
5652 || idesc->operands[i] == IA64_OPND_PKR_R3
5653 || idesc->operands[i] == IA64_OPND_PMC_R3
5654 || idesc->operands[i] == IA64_OPND_PMD_R3
5655 || idesc->operands[i] == IA64_OPND_MSR_R3
5656 || idesc->operands[i] == IA64_OPND_CPUID_R3
5658 || idesc->operands[i] == IA64_OPND_ITR_R3
5659 || idesc->operands[i] == IA64_OPND_DTR_R3
5660 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5661 || idesc->operands[i] == IA64_OPND_MR3)
5663 int regno = slot->opnd[i].X_add_number - REG_GR;
5664 /* Ignore invalid operands; they generate errors elsewhere. */
5667 if (idesc->operands[i] == IA64_OPND_R3)
5669 if (strcmp (idesc->name, "fc") != 0
5670 && strcmp (idesc->name, "tak") != 0
5671 && strcmp (idesc->name, "thash") != 0
5672 && strcmp (idesc->name, "tpa") != 0
5673 && strcmp (idesc->name, "ttag") != 0
5674 && strncmp (idesc->name, "ptr", 3) != 0
5675 && strncmp (idesc->name, "ptc", 3) != 0
5676 && strncmp (idesc->name, "probe", 5) != 0)
5679 if (prev_group->g_reg_set_conditionally[regno])
5687 build_insn (slot, insnp)
5691 const struct ia64_operand *odesc, *o2desc;
5692 struct ia64_opcode *idesc = slot->idesc;
5693 bfd_signed_vma insn, val;
5697 insn = idesc->opcode | slot->qp_regno;
5699 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5701 if (slot->opnd[i].X_op == O_register
5702 || slot->opnd[i].X_op == O_constant
5703 || slot->opnd[i].X_op == O_index)
5704 val = slot->opnd[i].X_add_number;
5705 else if (slot->opnd[i].X_op == O_big)
5707 /* This must be the value 0x10000000000000000. */
5708 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5714 switch (idesc->operands[i])
5716 case IA64_OPND_IMMU64:
5717 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5718 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5719 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5720 | (((val >> 63) & 0x1) << 36));
5723 case IA64_OPND_IMMU62:
5724 val &= 0x3fffffffffffffffULL;
5725 if (val != slot->opnd[i].X_add_number)
5726 as_warn (_("Value truncated to 62 bits"));
5727 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5728 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5731 case IA64_OPND_TGT64:
5733 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5734 insn |= ((((val >> 59) & 0x1) << 36)
5735 | (((val >> 0) & 0xfffff) << 13));
5766 case IA64_OPND_R3_2:
5767 case IA64_OPND_CPUID_R3:
5768 case IA64_OPND_DBR_R3:
5769 case IA64_OPND_DTR_R3:
5770 case IA64_OPND_ITR_R3:
5771 case IA64_OPND_IBR_R3:
5773 case IA64_OPND_MSR_R3:
5774 case IA64_OPND_PKR_R3:
5775 case IA64_OPND_PMC_R3:
5776 case IA64_OPND_PMD_R3:
5777 case IA64_OPND_RR_R3:
5785 odesc = elf64_ia64_operands + idesc->operands[i];
5786 err = (*odesc->insert) (odesc, val, &insn);
5788 as_bad_where (slot->src_file, slot->src_line,
5789 "Bad operand value: %s", err);
5790 if (idesc->flags & IA64_OPCODE_PSEUDO)
5792 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
5793 && odesc == elf64_ia64_operands + IA64_OPND_F3)
5795 o2desc = elf64_ia64_operands + IA64_OPND_F2;
5796 (*o2desc->insert) (o2desc, val, &insn);
5798 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
5799 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
5800 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
5802 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
5803 (*o2desc->insert) (o2desc, 64 - val, &insn);
5813 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
5814 unsigned int manual_bundling = 0;
5815 enum ia64_unit required_unit, insn_unit = 0;
5816 enum ia64_insn_type type[3], insn_type;
5817 unsigned int template, orig_template;
5818 bfd_vma insn[3] = { -1, -1, -1 };
5819 struct ia64_opcode *idesc;
5820 int end_of_insn_group = 0, user_template = -1;
5821 int n, i, j, first, curr;
5823 bfd_vma t0 = 0, t1 = 0;
5824 struct label_fix *lfix;
5825 struct insn_fix *ifix;
5830 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
5831 know (first >= 0 & first < NUM_SLOTS);
5832 n = MIN (3, md.num_slots_in_use);
5834 /* Determine template: user user_template if specified, best match
5837 if (md.slot[first].user_template >= 0)
5838 user_template = template = md.slot[first].user_template;
5841 /* Auto select appropriate template. */
5842 memset (type, 0, sizeof (type));
5844 for (i = 0; i < n; ++i)
5846 if (md.slot[curr].label_fixups && i != 0)
5848 type[i] = md.slot[curr].idesc->type;
5849 curr = (curr + 1) % NUM_SLOTS;
5851 template = best_template[type[0]][type[1]][type[2]];
5854 /* initialize instructions with appropriate nops: */
5855 for (i = 0; i < 3; ++i)
5856 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
5860 /* now fill in slots with as many insns as possible: */
5862 idesc = md.slot[curr].idesc;
5863 end_of_insn_group = 0;
5864 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
5866 /* Set the slot number for prologue/body records now as those
5867 refer to the current point, not the point after the
5868 instruction has been issued: */
5869 /* Don't try to delete prologue/body records here, as that will cause
5870 them to also be deleted from the master list of unwind records. */
5871 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
5872 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
5873 || ptr->r.type == body)
5875 ptr->slot_number = (unsigned long) f + i;
5876 ptr->slot_frag = frag_now;
5879 if (idesc->flags & IA64_OPCODE_SLOT2)
5881 if (manual_bundling && i != 2)
5882 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5883 "`%s' must be last in bundle", idesc->name);
5887 if (idesc->flags & IA64_OPCODE_LAST)
5890 unsigned int required_template;
5892 /* If we need a stop bit after an M slot, our only choice is
5893 template 5 (M;;MI). If we need a stop bit after a B
5894 slot, our only choice is to place it at the end of the
5895 bundle, because the only available templates are MIB,
5896 MBB, BBB, MMB, and MFB. We don't handle anything other
5897 than M and B slots because these are the only kind of
5898 instructions that can have the IA64_OPCODE_LAST bit set. */
5899 required_template = template;
5900 switch (idesc->type)
5904 required_template = 5;
5912 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5913 "Internal error: don't know how to force %s to end"
5914 "of instruction group", idesc->name);
5918 if (manual_bundling && i != required_slot)
5919 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5920 "`%s' must be last in instruction group",
5922 if (required_slot < i)
5923 /* Can't fit this instruction. */
5927 if (required_template != template)
5929 /* If we switch the template, we need to reset the NOPs
5930 after slot i. The slot-types of the instructions ahead
5931 of i never change, so we don't need to worry about
5932 changing NOPs in front of this slot. */
5933 for (j = i; j < 3; ++j)
5934 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
5936 template = required_template;
5938 if (curr != first && md.slot[curr].label_fixups)
5940 if (manual_bundling_on)
5941 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5942 "Label must be first in a bundle");
5943 /* This insn must go into the first slot of a bundle. */
5947 manual_bundling_on = md.slot[curr].manual_bundling_on;
5948 manual_bundling_off = md.slot[curr].manual_bundling_off;
5950 if (manual_bundling_on)
5953 manual_bundling = 1;
5955 break; /* need to start a new bundle */
5958 if (end_of_insn_group && md.num_slots_in_use >= 1)
5960 /* We need an instruction group boundary in the middle of a
5961 bundle. See if we can switch to an other template with
5962 an appropriate boundary. */
5964 orig_template = template;
5965 if (i == 1 && (user_template == 4
5966 || (user_template < 0
5967 && (ia64_templ_desc[template].exec_unit[0]
5971 end_of_insn_group = 0;
5973 else if (i == 2 && (user_template == 0
5974 || (user_template < 0
5975 && (ia64_templ_desc[template].exec_unit[1]
5977 /* This test makes sure we don't switch the template if
5978 the next instruction is one that needs to be first in
5979 an instruction group. Since all those instructions are
5980 in the M group, there is no way such an instruction can
5981 fit in this bundle even if we switch the template. The
5982 reason we have to check for this is that otherwise we
5983 may end up generating "MI;;I M.." which has the deadly
5984 effect that the second M instruction is no longer the
5985 first in the bundle! --davidm 99/12/16 */
5986 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
5989 end_of_insn_group = 0;
5991 else if (curr != first)
5992 /* can't fit this insn */
5995 if (template != orig_template)
5996 /* if we switch the template, we need to reset the NOPs
5997 after slot i. The slot-types of the instructions ahead
5998 of i never change, so we don't need to worry about
5999 changing NOPs in front of this slot. */
6000 for (j = i; j < 3; ++j)
6001 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6003 required_unit = ia64_templ_desc[template].exec_unit[i];
6005 /* resolve dynamic opcodes such as "break" and "nop": */
6006 if (idesc->type == IA64_TYPE_DYN)
6008 if ((strcmp (idesc->name, "nop") == 0)
6009 || (strcmp (idesc->name, "break") == 0))
6010 insn_unit = required_unit;
6011 else if (strcmp (idesc->name, "chk.s") == 0)
6013 insn_unit = IA64_UNIT_M;
6014 if (required_unit == IA64_UNIT_I)
6015 insn_unit = IA64_UNIT_I;
6018 as_fatal ("emit_one_bundle: unexpected dynamic op");
6020 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6021 ia64_free_opcode (idesc);
6022 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6024 know (!idesc->next); /* no resolved dynamic ops have collisions */
6029 insn_type = idesc->type;
6030 insn_unit = IA64_UNIT_NIL;
6034 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6035 insn_unit = required_unit;
6037 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6038 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6039 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6040 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6041 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6046 if (insn_unit != required_unit)
6048 if (required_unit == IA64_UNIT_L
6049 && insn_unit == IA64_UNIT_I
6050 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6052 /* we got ourselves an MLX template but the current
6053 instruction isn't an X-unit, or an I-unit instruction
6054 that can go into the X slot of an MLX template. Duh. */
6055 if (md.num_slots_in_use >= NUM_SLOTS)
6057 as_bad_where (md.slot[curr].src_file,
6058 md.slot[curr].src_line,
6059 "`%s' can't go in X slot of "
6060 "MLX template", idesc->name);
6061 /* drop this insn so we don't livelock: */
6062 --md.num_slots_in_use;
6066 continue; /* try next slot */
6072 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6073 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6076 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6077 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6079 build_insn (md.slot + curr, insn + i);
6081 /* Set slot counts for non prologue/body unwind records. */
6082 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
6083 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
6084 && ptr->r.type != body)
6086 ptr->slot_number = (unsigned long) f + i;
6087 ptr->slot_frag = frag_now;
6089 md.slot[curr].unwind_record = NULL;
6091 if (required_unit == IA64_UNIT_L)
6094 /* skip one slot for long/X-unit instructions */
6097 --md.num_slots_in_use;
6099 /* now is a good time to fix up the labels for this insn: */
6100 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6102 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6103 symbol_set_frag (lfix->sym, frag_now);
6105 /* and fix up the tags also. */
6106 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6108 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6109 symbol_set_frag (lfix->sym, frag_now);
6112 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6114 ifix = md.slot[curr].fixup + j;
6115 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6116 &ifix->expr, ifix->is_pcrel, ifix->code);
6117 fix->tc_fix_data.opnd = ifix->opnd;
6118 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6119 fix->fx_file = md.slot[curr].src_file;
6120 fix->fx_line = md.slot[curr].src_line;
6123 end_of_insn_group = md.slot[curr].end_of_insn_group;
6125 if (end_of_insn_group)
6127 md.group_idx = (md.group_idx + 1) % 3;
6128 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6132 ia64_free_opcode (md.slot[curr].idesc);
6133 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6134 md.slot[curr].user_template = -1;
6136 if (manual_bundling_off)
6138 manual_bundling = 0;
6141 curr = (curr + 1) % NUM_SLOTS;
6142 idesc = md.slot[curr].idesc;
6144 if (manual_bundling)
6146 if (md.num_slots_in_use > 0)
6147 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6148 "`%s' does not fit into %s template",
6149 idesc->name, ia64_templ_desc[template].name);
6151 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6152 "Missing '}' at end of file");
6154 know (md.num_slots_in_use < NUM_SLOTS);
6156 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6157 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6159 number_to_chars_littleendian (f + 0, t0, 8);
6160 number_to_chars_littleendian (f + 8, t1, 8);
6162 unwind.next_slot_number = (unsigned long) f + 16;
6163 unwind.next_slot_frag = frag_now;
6167 md_parse_option (c, arg)
6174 /* Switches from the Intel assembler. */
6176 if (strcmp (arg, "ilp64") == 0
6177 || strcmp (arg, "lp64") == 0
6178 || strcmp (arg, "p64") == 0)
6180 md.flags |= EF_IA_64_ABI64;
6182 else if (strcmp (arg, "ilp32") == 0)
6184 md.flags &= ~EF_IA_64_ABI64;
6186 else if (strcmp (arg, "le") == 0)
6188 md.flags &= ~EF_IA_64_BE;
6190 else if (strcmp (arg, "be") == 0)
6192 md.flags |= EF_IA_64_BE;
6199 if (strcmp (arg, "so") == 0)
6201 /* Suppress signon message. */
6203 else if (strcmp (arg, "pi") == 0)
6205 /* Reject privileged instructions. FIXME */
6207 else if (strcmp (arg, "us") == 0)
6209 /* Allow union of signed and unsigned range. FIXME */
6211 else if (strcmp (arg, "close_fcalls") == 0)
6213 /* Do not resolve global function calls. */
6220 /* temp[="prefix"] Insert temporary labels into the object file
6221 symbol table prefixed by "prefix".
6222 Default prefix is ":temp:".
6227 /* indirect=<tgt> Assume unannotated indirect branches behavior
6228 according to <tgt> --
6229 exit: branch out from the current context (default)
6230 labels: all labels in context may be branch targets
6232 if (strncmp (arg, "indirect=", 9) != 0)
6237 /* -X conflicts with an ignored option, use -x instead */
6239 if (!arg || strcmp (arg, "explicit") == 0)
6241 /* set default mode to explicit */
6242 md.default_explicit_mode = 1;
6245 else if (strcmp (arg, "auto") == 0)
6247 md.default_explicit_mode = 0;
6249 else if (strcmp (arg, "debug") == 0)
6253 else if (strcmp (arg, "debugx") == 0)
6255 md.default_explicit_mode = 1;
6260 as_bad (_("Unrecognized option '-x%s'"), arg);
6265 /* nops Print nops statistics. */
6268 /* GNU specific switches for gcc. */
6269 case OPTION_MCONSTANT_GP:
6270 md.flags |= EF_IA_64_CONS_GP;
6273 case OPTION_MAUTO_PIC:
6274 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6285 md_show_usage (stream)
6290 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6291 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6292 -x | -xexplicit turn on dependency violation checking (default)\n\
6293 -xauto automagically remove dependency violations\n\
6294 -xdebug debug dependency violation checker\n"),
6298 /* Return true if TYPE fits in TEMPL at SLOT. */
6301 match (int templ, int type, int slot)
6303 enum ia64_unit unit;
6306 unit = ia64_templ_desc[templ].exec_unit[slot];
6309 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6311 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6313 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6314 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6315 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6316 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6317 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6318 default: result = 0; break;
6323 /* Add a bit of extra goodness if a nop of type F or B would fit
6324 in TEMPL at SLOT. */
6327 extra_goodness (int templ, int slot)
6329 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6331 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6336 /* This function is called once, at assembler startup time. It sets
6337 up all the tables, etc. that the MD part of the assembler will need
6338 that can be determined before arguments are parsed. */
6342 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6347 md.explicit_mode = md.default_explicit_mode;
6349 bfd_set_section_alignment (stdoutput, text_section, 4);
6351 target_big_endian = TARGET_BYTES_BIG_ENDIAN;
6352 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6353 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6354 &zero_address_frag);
6356 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6357 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6358 &zero_address_frag);
6360 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6361 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6362 &zero_address_frag);
6364 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6365 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6366 &zero_address_frag);
6368 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6369 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6370 &zero_address_frag);
6372 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6373 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6374 &zero_address_frag);
6376 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6377 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6378 &zero_address_frag);
6380 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6381 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6382 &zero_address_frag);
6384 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6385 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6386 &zero_address_frag);
6388 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6389 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6390 &zero_address_frag);
6392 /* Compute the table of best templates. We compute goodness as a
6393 base 4 value, in which each match counts for 3, each F counts
6394 for 2, each B counts for 1. This should maximize the number of
6395 F and B nops in the chosen bundles, which is good because these
6396 pipelines are least likely to be overcommitted. */
6397 for (i = 0; i < IA64_NUM_TYPES; ++i)
6398 for (j = 0; j < IA64_NUM_TYPES; ++j)
6399 for (k = 0; k < IA64_NUM_TYPES; ++k)
6402 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6405 if (match (t, i, 0))
6407 if (match (t, j, 1))
6409 if (match (t, k, 2))
6410 goodness = 3 + 3 + 3;
6412 goodness = 3 + 3 + extra_goodness (t, 2);
6414 else if (match (t, j, 2))
6415 goodness = 3 + 3 + extra_goodness (t, 1);
6419 goodness += extra_goodness (t, 1);
6420 goodness += extra_goodness (t, 2);
6423 else if (match (t, i, 1))
6425 if (match (t, j, 2))
6428 goodness = 3 + extra_goodness (t, 2);
6430 else if (match (t, i, 2))
6431 goodness = 3 + extra_goodness (t, 1);
6433 if (goodness > best)
6436 best_template[i][j][k] = t;
6441 for (i = 0; i < NUM_SLOTS; ++i)
6442 md.slot[i].user_template = -1;
6444 md.pseudo_hash = hash_new ();
6445 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6447 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6448 (void *) (pseudo_opcode + i));
6450 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6451 pseudo_opcode[i].name, err);
6454 md.reg_hash = hash_new ();
6455 md.dynreg_hash = hash_new ();
6456 md.const_hash = hash_new ();
6457 md.entry_hash = hash_new ();
6459 /* general registers: */
6462 for (i = 0; i < total; ++i)
6464 sprintf (name, "r%d", i - REG_GR);
6465 md.regsym[i] = declare_register (name, i);
6468 /* floating point registers: */
6470 for (; i < total; ++i)
6472 sprintf (name, "f%d", i - REG_FR);
6473 md.regsym[i] = declare_register (name, i);
6476 /* application registers: */
6479 for (; i < total; ++i)
6481 sprintf (name, "ar%d", i - REG_AR);
6482 md.regsym[i] = declare_register (name, i);
6485 /* control registers: */
6488 for (; i < total; ++i)
6490 sprintf (name, "cr%d", i - REG_CR);
6491 md.regsym[i] = declare_register (name, i);
6494 /* predicate registers: */
6496 for (; i < total; ++i)
6498 sprintf (name, "p%d", i - REG_P);
6499 md.regsym[i] = declare_register (name, i);
6502 /* branch registers: */
6504 for (; i < total; ++i)
6506 sprintf (name, "b%d", i - REG_BR);
6507 md.regsym[i] = declare_register (name, i);
6510 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6511 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6512 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6513 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6514 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6515 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6516 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6518 for (i = 0; i < NELEMS (indirect_reg); ++i)
6520 regnum = indirect_reg[i].regnum;
6521 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6524 /* define synonyms for application registers: */
6525 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6526 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6527 REG_AR + ar[i - REG_AR].regnum);
6529 /* define synonyms for control registers: */
6530 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6531 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6532 REG_CR + cr[i - REG_CR].regnum);
6534 declare_register ("gp", REG_GR + 1);
6535 declare_register ("sp", REG_GR + 12);
6536 declare_register ("rp", REG_BR + 0);
6538 /* pseudo-registers used to specify unwind info: */
6539 declare_register ("psp", REG_PSP);
6541 declare_register_set ("ret", 4, REG_GR + 8);
6542 declare_register_set ("farg", 8, REG_FR + 8);
6543 declare_register_set ("fret", 8, REG_FR + 8);
6545 for (i = 0; i < NELEMS (const_bits); ++i)
6547 err = hash_insert (md.const_hash, const_bits[i].name,
6548 (PTR) (const_bits + i));
6550 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6554 /* Set the architecture and machine depending on defaults and command line
6556 if (md.flags & EF_IA_64_ABI64)
6557 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6559 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6562 as_warn (_("Could not set architecture and machine"));
6564 /* Set the pointer size and pointer shift size depending on md.flags */
6566 if (md.flags & EF_IA_64_ABI64)
6568 md.pointer_size = 8; /* pointers are 8 bytes */
6569 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6573 md.pointer_size = 4; /* pointers are 4 bytes */
6574 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6577 md.mem_offset.hint = 0;
6580 md.entry_labels = NULL;
6583 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6584 because that is called after md_parse_option which is where we do the
6585 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6586 default endianness. */
6589 ia64_init (argc, argv)
6590 int argc ATTRIBUTE_UNUSED;
6591 char **argv ATTRIBUTE_UNUSED;
6593 md.flags = EF_IA_64_ABI64;
6594 if (TARGET_BYTES_BIG_ENDIAN)
6595 md.flags |= EF_IA_64_BE;
6598 /* Return a string for the target object file format. */
6601 ia64_target_format ()
6603 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6605 if (md.flags & EF_IA_64_BE)
6607 if (md.flags & EF_IA_64_ABI64)
6609 return "elf64-ia64-aix-big";
6611 return "elf64-ia64-big";
6615 return "elf32-ia64-aix-big";
6617 return "elf32-ia64-big";
6622 if (md.flags & EF_IA_64_ABI64)
6624 return "elf64-ia64-aix-little";
6626 return "elf64-ia64-little";
6630 return "elf32-ia64-aix-little";
6632 return "elf32-ia64-little";
6637 return "unknown-format";
6641 ia64_end_of_source ()
6643 /* terminate insn group upon reaching end of file: */
6644 insn_group_break (1, 0, 0);
6646 /* emits slots we haven't written yet: */
6647 ia64_flush_insns ();
6649 bfd_set_private_flags (stdoutput, md.flags);
6651 md.mem_offset.hint = 0;
6657 if (md.qp.X_op == O_register)
6658 as_bad ("qualifying predicate not followed by instruction");
6659 md.qp.X_op = O_absent;
6661 if (ignore_input ())
6664 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6666 if (md.detect_dv && !md.explicit_mode)
6667 as_warn (_("Explicit stops are ignored in auto mode"));
6669 insn_group_break (1, 0, 0);
6673 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
6675 static int defining_tag = 0;
6678 ia64_unrecognized_line (ch)
6684 expression (&md.qp);
6685 if (*input_line_pointer++ != ')')
6687 as_bad ("Expected ')'");
6690 if (md.qp.X_op != O_register)
6692 as_bad ("Qualifying predicate expected");
6695 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
6697 as_bad ("Predicate register expected");
6703 if (md.manual_bundling)
6704 as_warn ("Found '{' when manual bundling is already turned on");
6706 CURR_SLOT.manual_bundling_on = 1;
6707 md.manual_bundling = 1;
6709 /* Bundling is only acceptable in explicit mode
6710 or when in default automatic mode. */
6711 if (md.detect_dv && !md.explicit_mode)
6713 if (!md.mode_explicitly_set
6714 && !md.default_explicit_mode)
6717 as_warn (_("Found '{' after explicit switch to automatic mode"));
6722 if (!md.manual_bundling)
6723 as_warn ("Found '}' when manual bundling is off");
6725 PREV_SLOT.manual_bundling_off = 1;
6726 md.manual_bundling = 0;
6728 /* switch back to automatic mode, if applicable */
6731 && !md.mode_explicitly_set
6732 && !md.default_explicit_mode)
6735 /* Allow '{' to follow on the same line. We also allow ";;", but that
6736 happens automatically because ';' is an end of line marker. */
6738 if (input_line_pointer[0] == '{')
6740 input_line_pointer++;
6741 return ia64_unrecognized_line ('{');
6744 demand_empty_rest_of_line ();
6754 if (md.qp.X_op == O_register)
6756 as_bad ("Tag must come before qualifying predicate.");
6760 /* This implements just enough of read_a_source_file in read.c to
6761 recognize labels. */
6762 if (is_name_beginner (*input_line_pointer))
6764 s = input_line_pointer;
6765 c = get_symbol_end ();
6767 else if (LOCAL_LABELS_FB
6768 && isdigit ((unsigned char) *input_line_pointer))
6771 while (isdigit ((unsigned char) *input_line_pointer))
6772 temp = (temp * 10) + *input_line_pointer++ - '0';
6773 fb_label_instance_inc (temp);
6774 s = fb_label_name (temp, 0);
6775 c = *input_line_pointer;
6784 /* Put ':' back for error messages' sake. */
6785 *input_line_pointer++ = ':';
6786 as_bad ("Expected ':'");
6793 /* Put ':' back for error messages' sake. */
6794 *input_line_pointer++ = ':';
6795 if (*input_line_pointer++ != ']')
6797 as_bad ("Expected ']'");
6802 as_bad ("Tag name expected");
6812 /* Not a valid line. */
6817 ia64_frob_label (sym)
6820 struct label_fix *fix;
6822 /* Tags need special handling since they are not bundle breaks like
6826 fix = obstack_alloc (¬es, sizeof (*fix));
6828 fix->next = CURR_SLOT.tag_fixups;
6829 CURR_SLOT.tag_fixups = fix;
6834 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
6836 md.last_text_seg = now_seg;
6837 fix = obstack_alloc (¬es, sizeof (*fix));
6839 fix->next = CURR_SLOT.label_fixups;
6840 CURR_SLOT.label_fixups = fix;
6842 /* Keep track of how many code entry points we've seen. */
6843 if (md.path == md.maxpaths)
6846 md.entry_labels = (const char **)
6847 xrealloc ((void *) md.entry_labels,
6848 md.maxpaths * sizeof (char *));
6850 md.entry_labels[md.path++] = S_GET_NAME (sym);
6855 ia64_flush_pending_output ()
6857 if (!md.keep_pending_output
6858 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
6860 /* ??? This causes many unnecessary stop bits to be emitted.
6861 Unfortunately, it isn't clear if it is safe to remove this. */
6862 insn_group_break (1, 0, 0);
6863 ia64_flush_insns ();
6867 /* Do ia64-specific expression optimization. All that's done here is
6868 to transform index expressions that are either due to the indexing
6869 of rotating registers or due to the indexing of indirect register
6872 ia64_optimize_expr (l, op, r)
6881 if (l->X_op == O_register && r->X_op == O_constant)
6883 num_regs = (l->X_add_number >> 16);
6884 if ((unsigned) r->X_add_number >= num_regs)
6887 as_bad ("No current frame");
6889 as_bad ("Index out of range 0..%u", num_regs - 1);
6890 r->X_add_number = 0;
6892 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
6895 else if (l->X_op == O_register && r->X_op == O_register)
6897 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
6898 || l->X_add_number == IND_MEM)
6900 as_bad ("Indirect register set name expected");
6901 l->X_add_number = IND_CPUID;
6904 l->X_op_symbol = md.regsym[l->X_add_number];
6905 l->X_add_number = r->X_add_number;
6913 ia64_parse_name (name, e)
6917 struct const_desc *cdesc;
6918 struct dynreg *dr = 0;
6919 unsigned int regnum;
6923 /* first see if NAME is a known register name: */
6924 sym = hash_find (md.reg_hash, name);
6927 e->X_op = O_register;
6928 e->X_add_number = S_GET_VALUE (sym);
6932 cdesc = hash_find (md.const_hash, name);
6935 e->X_op = O_constant;
6936 e->X_add_number = cdesc->value;
6940 /* check for inN, locN, or outN: */
6944 if (name[1] == 'n' && isdigit (name[2]))
6952 if (name[1] == 'o' && name[2] == 'c' && isdigit (name[3]))
6960 if (name[1] == 'u' && name[2] == 't' && isdigit (name[3]))
6973 /* The name is inN, locN, or outN; parse the register number. */
6974 regnum = strtoul (name, &end, 10);
6975 if (end > name && *end == '\0')
6977 if ((unsigned) regnum >= dr->num_regs)
6980 as_bad ("No current frame");
6982 as_bad ("Register number out of range 0..%u",
6986 e->X_op = O_register;
6987 e->X_add_number = dr->base + regnum;
6992 if ((dr = hash_find (md.dynreg_hash, name)))
6994 /* We've got ourselves the name of a rotating register set.
6995 Store the base register number in the low 16 bits of
6996 X_add_number and the size of the register set in the top 16
6998 e->X_op = O_register;
6999 e->X_add_number = dr->base | (dr->num_regs << 16);
7005 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7008 ia64_canonicalize_symbol_name (name)
7011 size_t len = strlen (name);
7012 if (len > 1 && name[len - 1] == '#')
7013 name[len - 1] = '\0';
7017 /* Return true if idesc is a conditional branch instruction. This excludes
7018 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7019 because they always read/write resources regardless of the value of the
7020 qualifying predicate. br.ia must always use p0, and hence is always
7021 taken. Thus this function returns true for branches which can fall
7022 through, and which use no resources if they do fall through. */
7025 is_conditional_branch (idesc)
7026 struct ia64_opcode *idesc;
7028 /* br is a conditional branch. Everything that starts with br. except
7029 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7030 Everything that starts with brl is a conditional branch. */
7031 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7032 && (idesc->name[2] == '\0'
7033 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7034 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7035 || idesc->name[2] == 'l'
7036 /* br.cond, br.call, br.clr */
7037 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7038 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7039 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7042 /* Return whether the given opcode is a taken branch. If there's any doubt,
7046 is_taken_branch (idesc)
7047 struct ia64_opcode *idesc;
7049 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7050 || strncmp (idesc->name, "br.ia", 5) == 0);
7053 /* Return whether the given opcode is an interruption or rfi. If there's any
7054 doubt, returns zero. */
7057 is_interruption_or_rfi (idesc)
7058 struct ia64_opcode *idesc;
7060 if (strcmp (idesc->name, "rfi") == 0)
7065 /* Returns the index of the given dependency in the opcode's list of chks, or
7066 -1 if there is no dependency. */
7069 depends_on (depind, idesc)
7071 struct ia64_opcode *idesc;
7074 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7075 for (i = 0; i < dep->nchks; i++)
7077 if (depind == DEP (dep->chks[i]))
7083 /* Determine a set of specific resources used for a particular resource
7084 class. Returns the number of specific resources identified For those
7085 cases which are not determinable statically, the resource returned is
7088 Meanings of value in 'NOTE':
7089 1) only read/write when the register number is explicitly encoded in the
7091 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7092 accesses CFM when qualifying predicate is in the rotating region.
7093 3) general register value is used to specify an indirect register; not
7094 determinable statically.
7095 4) only read the given resource when bits 7:0 of the indirect index
7096 register value does not match the register number of the resource; not
7097 determinable statically.
7098 5) all rules are implementation specific.
7099 6) only when both the index specified by the reader and the index specified
7100 by the writer have the same value in bits 63:61; not determinable
7102 7) only access the specified resource when the corresponding mask bit is
7104 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7105 only read when these insns reference FR2-31
7106 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7107 written when these insns write FR32-127
7108 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7110 11) The target predicates are written independently of PR[qp], but source
7111 registers are only read if PR[qp] is true. Since the state of PR[qp]
7112 cannot statically be determined, all source registers are marked used.
7113 12) This insn only reads the specified predicate register when that
7114 register is the PR[qp].
7115 13) This reference to ld-c only applies to teh GR whose value is loaded
7116 with data returned from memory, not the post-incremented address register.
7117 14) The RSE resource includes the implementation-specific RSE internal
7118 state resources. At least one (and possibly more) of these resources are
7119 read by each instruction listed in IC:rse-readers. At least one (and
7120 possibly more) of these resources are written by each insn listed in
7122 15+16) Represents reserved instructions, which the assembler does not
7125 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7126 this code; there are no dependency violations based on memory access.
7129 #define MAX_SPECS 256
7134 specify_resource (dep, idesc, type, specs, note, path)
7135 const struct ia64_dependency *dep;
7136 struct ia64_opcode *idesc;
7137 int type; /* is this a DV chk or a DV reg? */
7138 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7139 int note; /* resource note for this insn's usage */
7140 int path; /* which execution path to examine */
7147 if (dep->mode == IA64_DV_WAW
7148 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7149 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7152 /* template for any resources we identify */
7153 tmpl.dependency = dep;
7155 tmpl.insn_srlz = tmpl.data_srlz = 0;
7156 tmpl.qp_regno = CURR_SLOT.qp_regno;
7157 tmpl.link_to_qp_branch = 1;
7158 tmpl.mem_offset.hint = 0;
7161 tmpl.cmp_type = CMP_NONE;
7164 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7165 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7166 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7168 /* we don't need to track these */
7169 if (dep->semantics == IA64_DVS_NONE)
7172 switch (dep->specifier)
7177 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7179 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7180 if (regno >= 0 && regno <= 7)
7182 specs[count] = tmpl;
7183 specs[count++].index = regno;
7189 for (i = 0; i < 8; i++)
7191 specs[count] = tmpl;
7192 specs[count++].index = i;
7201 case IA64_RS_AR_UNAT:
7202 /* This is a mov =AR or mov AR= instruction. */
7203 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7205 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7206 if (regno == AR_UNAT)
7208 specs[count++] = tmpl;
7213 /* This is a spill/fill, or other instruction that modifies the
7216 /* Unless we can determine the specific bits used, mark the whole
7217 thing; bits 8:3 of the memory address indicate the bit used in
7218 UNAT. The .mem.offset hint may be used to eliminate a small
7219 subset of conflicts. */
7220 specs[count] = tmpl;
7221 if (md.mem_offset.hint)
7224 fprintf (stderr, " Using hint for spill/fill\n");
7225 /* The index isn't actually used, just set it to something
7226 approximating the bit index. */
7227 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7228 specs[count].mem_offset.hint = 1;
7229 specs[count].mem_offset.offset = md.mem_offset.offset;
7230 specs[count++].mem_offset.base = md.mem_offset.base;
7234 specs[count++].specific = 0;
7242 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7244 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7245 if ((regno >= 8 && regno <= 15)
7246 || (regno >= 20 && regno <= 23)
7247 || (regno >= 31 && regno <= 39)
7248 || (regno >= 41 && regno <= 47)
7249 || (regno >= 67 && regno <= 111))
7251 specs[count] = tmpl;
7252 specs[count++].index = regno;
7265 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7267 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7268 if ((regno >= 48 && regno <= 63)
7269 || (regno >= 112 && regno <= 127))
7271 specs[count] = tmpl;
7272 specs[count++].index = regno;
7278 for (i = 48; i < 64; i++)
7280 specs[count] = tmpl;
7281 specs[count++].index = i;
7283 for (i = 112; i < 128; i++)
7285 specs[count] = tmpl;
7286 specs[count++].index = i;
7304 for (i = 0; i < idesc->num_outputs; i++)
7305 if (idesc->operands[i] == IA64_OPND_B1
7306 || idesc->operands[i] == IA64_OPND_B2)
7308 specs[count] = tmpl;
7309 specs[count++].index =
7310 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7315 for (i = idesc->num_outputs;i < NELEMS (idesc->operands); i++)
7316 if (idesc->operands[i] == IA64_OPND_B1
7317 || idesc->operands[i] == IA64_OPND_B2)
7319 specs[count] = tmpl;
7320 specs[count++].index =
7321 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7327 case IA64_RS_CPUID: /* four or more registers */
7330 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7332 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7333 if (regno >= 0 && regno < NELEMS (gr_values)
7336 specs[count] = tmpl;
7337 specs[count++].index = gr_values[regno].value & 0xFF;
7341 specs[count] = tmpl;
7342 specs[count++].specific = 0;
7352 case IA64_RS_DBR: /* four or more registers */
7355 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7357 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7358 if (regno >= 0 && regno < NELEMS (gr_values)
7361 specs[count] = tmpl;
7362 specs[count++].index = gr_values[regno].value & 0xFF;
7366 specs[count] = tmpl;
7367 specs[count++].specific = 0;
7371 else if (note == 0 && !rsrc_write)
7373 specs[count] = tmpl;
7374 specs[count++].specific = 0;
7382 case IA64_RS_IBR: /* four or more registers */
7385 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7387 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7388 if (regno >= 0 && regno < NELEMS (gr_values)
7391 specs[count] = tmpl;
7392 specs[count++].index = gr_values[regno].value & 0xFF;
7396 specs[count] = tmpl;
7397 specs[count++].specific = 0;
7410 /* These are implementation specific. Force all references to
7411 conflict with all other references. */
7412 specs[count] = tmpl;
7413 specs[count++].specific = 0;
7421 case IA64_RS_PKR: /* 16 or more registers */
7422 if (note == 3 || note == 4)
7424 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7426 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7427 if (regno >= 0 && regno < NELEMS (gr_values)
7432 specs[count] = tmpl;
7433 specs[count++].index = gr_values[regno].value & 0xFF;
7436 for (i = 0; i < NELEMS (gr_values); i++)
7438 /* Uses all registers *except* the one in R3. */
7439 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7441 specs[count] = tmpl;
7442 specs[count++].index = i;
7448 specs[count] = tmpl;
7449 specs[count++].specific = 0;
7456 specs[count] = tmpl;
7457 specs[count++].specific = 0;
7461 case IA64_RS_PMC: /* four or more registers */
7464 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7465 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7468 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7470 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7471 if (regno >= 0 && regno < NELEMS (gr_values)
7474 specs[count] = tmpl;
7475 specs[count++].index = gr_values[regno].value & 0xFF;
7479 specs[count] = tmpl;
7480 specs[count++].specific = 0;
7490 case IA64_RS_PMD: /* four or more registers */
7493 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7495 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7496 if (regno >= 0 && regno < NELEMS (gr_values)
7499 specs[count] = tmpl;
7500 specs[count++].index = gr_values[regno].value & 0xFF;
7504 specs[count] = tmpl;
7505 specs[count++].specific = 0;
7515 case IA64_RS_RR: /* eight registers */
7518 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7520 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7521 if (regno >= 0 && regno < NELEMS (gr_values)
7524 specs[count] = tmpl;
7525 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7529 specs[count] = tmpl;
7530 specs[count++].specific = 0;
7534 else if (note == 0 && !rsrc_write)
7536 specs[count] = tmpl;
7537 specs[count++].specific = 0;
7545 case IA64_RS_CR_IRR:
7548 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7549 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7551 && idesc->operands[1] == IA64_OPND_CR3
7554 for (i = 0; i < 4; i++)
7556 specs[count] = tmpl;
7557 specs[count++].index = CR_IRR0 + i;
7563 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7564 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7566 && regno <= CR_IRR3)
7568 specs[count] = tmpl;
7569 specs[count++].index = regno;
7578 case IA64_RS_CR_LRR:
7585 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7586 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7587 && (regno == CR_LRR0 || regno == CR_LRR1))
7589 specs[count] = tmpl;
7590 specs[count++].index = regno;
7598 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7600 specs[count] = tmpl;
7601 specs[count++].index =
7602 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7617 else if (rsrc_write)
7619 if (dep->specifier == IA64_RS_FRb
7620 && idesc->operands[0] == IA64_OPND_F1)
7622 specs[count] = tmpl;
7623 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7628 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7630 if (idesc->operands[i] == IA64_OPND_F2
7631 || idesc->operands[i] == IA64_OPND_F3
7632 || idesc->operands[i] == IA64_OPND_F4)
7634 specs[count] = tmpl;
7635 specs[count++].index =
7636 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7645 /* This reference applies only to the GR whose value is loaded with
7646 data returned from memory. */
7647 specs[count] = tmpl;
7648 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7654 for (i = 0; i < idesc->num_outputs; i++)
7655 if (idesc->operands[i] == IA64_OPND_R1
7656 || idesc->operands[i] == IA64_OPND_R2
7657 || idesc->operands[i] == IA64_OPND_R3)
7659 specs[count] = tmpl;
7660 specs[count++].index =
7661 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7663 if (idesc->flags & IA64_OPCODE_POSTINC)
7664 for (i = 0; i < NELEMS (idesc->operands); i++)
7665 if (idesc->operands[i] == IA64_OPND_MR3)
7667 specs[count] = tmpl;
7668 specs[count++].index =
7669 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7674 /* Look for anything that reads a GR. */
7675 for (i = 0; i < NELEMS (idesc->operands); i++)
7677 if (idesc->operands[i] == IA64_OPND_MR3
7678 || idesc->operands[i] == IA64_OPND_CPUID_R3
7679 || idesc->operands[i] == IA64_OPND_DBR_R3
7680 || idesc->operands[i] == IA64_OPND_IBR_R3
7681 || idesc->operands[i] == IA64_OPND_MSR_R3
7682 || idesc->operands[i] == IA64_OPND_PKR_R3
7683 || idesc->operands[i] == IA64_OPND_PMC_R3
7684 || idesc->operands[i] == IA64_OPND_PMD_R3
7685 || idesc->operands[i] == IA64_OPND_RR_R3
7686 || ((i >= idesc->num_outputs)
7687 && (idesc->operands[i] == IA64_OPND_R1
7688 || idesc->operands[i] == IA64_OPND_R2
7689 || idesc->operands[i] == IA64_OPND_R3
7690 /* addl source register. */
7691 || idesc->operands[i] == IA64_OPND_R3_2)))
7693 specs[count] = tmpl;
7694 specs[count++].index =
7695 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7706 /* This is the same as IA64_RS_PRr, except that the register range is
7707 from 1 - 15, and there are no rotating register reads/writes here. */
7711 for (i = 1; i < 16; i++)
7713 specs[count] = tmpl;
7714 specs[count++].index = i;
7720 /* Mark only those registers indicated by the mask. */
7723 mask = CURR_SLOT.opnd[2].X_add_number;
7724 for (i = 1; i < 16; i++)
7725 if (mask & ((valueT) 1 << i))
7727 specs[count] = tmpl;
7728 specs[count++].index = i;
7736 else if (note == 11) /* note 11 implies note 1 as well */
7740 for (i = 0; i < idesc->num_outputs; i++)
7742 if (idesc->operands[i] == IA64_OPND_P1
7743 || idesc->operands[i] == IA64_OPND_P2)
7745 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
7746 if (regno >= 1 && regno < 16)
7748 specs[count] = tmpl;
7749 specs[count++].index = regno;
7759 else if (note == 12)
7761 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
7763 specs[count] = tmpl;
7764 specs[count++].index = CURR_SLOT.qp_regno;
7771 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7772 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7773 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
7774 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
7776 if ((idesc->operands[0] == IA64_OPND_P1
7777 || idesc->operands[0] == IA64_OPND_P2)
7778 && p1 >= 1 && p1 < 16)
7780 specs[count] = tmpl;
7781 specs[count].cmp_type =
7782 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
7783 specs[count++].index = p1;
7785 if ((idesc->operands[1] == IA64_OPND_P1
7786 || idesc->operands[1] == IA64_OPND_P2)
7787 && p2 >= 1 && p2 < 16)
7789 specs[count] = tmpl;
7790 specs[count].cmp_type =
7791 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
7792 specs[count++].index = p2;
7797 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
7799 specs[count] = tmpl;
7800 specs[count++].index = CURR_SLOT.qp_regno;
7802 if (idesc->operands[1] == IA64_OPND_PR)
7804 for (i = 1; i < 16; i++)
7806 specs[count] = tmpl;
7807 specs[count++].index = i;
7818 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
7819 simplified cases of this. */
7823 for (i = 16; i < 63; i++)
7825 specs[count] = tmpl;
7826 specs[count++].index = i;
7832 /* Mark only those registers indicated by the mask. */
7834 && idesc->operands[0] == IA64_OPND_PR)
7836 mask = CURR_SLOT.opnd[2].X_add_number;
7837 if (mask & ((valueT) 1<<16))
7838 for (i = 16; i < 63; i++)
7840 specs[count] = tmpl;
7841 specs[count++].index = i;
7845 && idesc->operands[0] == IA64_OPND_PR_ROT)
7847 for (i = 16; i < 63; i++)
7849 specs[count] = tmpl;
7850 specs[count++].index = i;
7858 else if (note == 11) /* note 11 implies note 1 as well */
7862 for (i = 0; i < idesc->num_outputs; i++)
7864 if (idesc->operands[i] == IA64_OPND_P1
7865 || idesc->operands[i] == IA64_OPND_P2)
7867 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
7868 if (regno >= 16 && regno < 63)
7870 specs[count] = tmpl;
7871 specs[count++].index = regno;
7881 else if (note == 12)
7883 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
7885 specs[count] = tmpl;
7886 specs[count++].index = CURR_SLOT.qp_regno;
7893 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7894 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7895 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
7896 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
7898 if ((idesc->operands[0] == IA64_OPND_P1
7899 || idesc->operands[0] == IA64_OPND_P2)
7900 && p1 >= 16 && p1 < 63)
7902 specs[count] = tmpl;
7903 specs[count].cmp_type =
7904 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
7905 specs[count++].index = p1;
7907 if ((idesc->operands[1] == IA64_OPND_P1
7908 || idesc->operands[1] == IA64_OPND_P2)
7909 && p2 >= 16 && p2 < 63)
7911 specs[count] = tmpl;
7912 specs[count].cmp_type =
7913 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
7914 specs[count++].index = p2;
7919 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
7921 specs[count] = tmpl;
7922 specs[count++].index = CURR_SLOT.qp_regno;
7924 if (idesc->operands[1] == IA64_OPND_PR)
7926 for (i = 16; i < 63; i++)
7928 specs[count] = tmpl;
7929 specs[count++].index = i;
7941 /* Verify that the instruction is using the PSR bit indicated in
7945 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
7947 if (dep->regindex < 6)
7949 specs[count++] = tmpl;
7952 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
7954 if (dep->regindex < 32
7955 || dep->regindex == 35
7956 || dep->regindex == 36
7957 || (!rsrc_write && dep->regindex == PSR_CPL))
7959 specs[count++] = tmpl;
7962 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
7964 if (dep->regindex < 32
7965 || dep->regindex == 35
7966 || dep->regindex == 36
7967 || (rsrc_write && dep->regindex == PSR_CPL))
7969 specs[count++] = tmpl;
7974 /* Several PSR bits have very specific dependencies. */
7975 switch (dep->regindex)
7978 specs[count++] = tmpl;
7983 specs[count++] = tmpl;
7987 /* Only certain CR accesses use PSR.ic */
7988 if (idesc->operands[0] == IA64_OPND_CR3
7989 || idesc->operands[1] == IA64_OPND_CR3)
7992 ((idesc->operands[0] == IA64_OPND_CR3)
7995 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8010 specs[count++] = tmpl;
8019 specs[count++] = tmpl;
8023 /* Only some AR accesses use cpl */
8024 if (idesc->operands[0] == IA64_OPND_AR3
8025 || idesc->operands[1] == IA64_OPND_AR3)
8028 ((idesc->operands[0] == IA64_OPND_AR3)
8031 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8038 && regno <= AR_K7))))
8040 specs[count++] = tmpl;
8045 specs[count++] = tmpl;
8055 if (idesc->operands[0] == IA64_OPND_IMMU24)
8057 mask = CURR_SLOT.opnd[0].X_add_number;
8063 if (mask & ((valueT) 1 << dep->regindex))
8065 specs[count++] = tmpl;
8070 int min = dep->regindex == PSR_DFL ? 2 : 32;
8071 int max = dep->regindex == PSR_DFL ? 31 : 127;
8072 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8073 for (i = 0; i < NELEMS (idesc->operands); i++)
8075 if (idesc->operands[i] == IA64_OPND_F1
8076 || idesc->operands[i] == IA64_OPND_F2
8077 || idesc->operands[i] == IA64_OPND_F3
8078 || idesc->operands[i] == IA64_OPND_F4)
8080 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8081 if (reg >= min && reg <= max)
8083 specs[count++] = tmpl;
8090 int min = dep->regindex == PSR_MFL ? 2 : 32;
8091 int max = dep->regindex == PSR_MFL ? 31 : 127;
8092 /* mfh is read on writes to FR32-127; mfl is read on writes to
8094 for (i = 0; i < idesc->num_outputs; i++)
8096 if (idesc->operands[i] == IA64_OPND_F1)
8098 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8099 if (reg >= min && reg <= max)
8101 specs[count++] = tmpl;
8106 else if (note == 10)
8108 for (i = 0; i < NELEMS (idesc->operands); i++)
8110 if (idesc->operands[i] == IA64_OPND_R1
8111 || idesc->operands[i] == IA64_OPND_R2
8112 || idesc->operands[i] == IA64_OPND_R3)
8114 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8115 if (regno >= 16 && regno <= 31)
8117 specs[count++] = tmpl;
8128 case IA64_RS_AR_FPSR:
8129 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8131 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8132 if (regno == AR_FPSR)
8134 specs[count++] = tmpl;
8139 specs[count++] = tmpl;
8144 /* Handle all AR[REG] resources */
8145 if (note == 0 || note == 1)
8147 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8148 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8149 && regno == dep->regindex)
8151 specs[count++] = tmpl;
8153 /* other AR[REG] resources may be affected by AR accesses */
8154 else if (idesc->operands[0] == IA64_OPND_AR3)
8157 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8158 switch (dep->regindex)
8164 if (regno == AR_BSPSTORE)
8166 specs[count++] = tmpl;
8170 (regno == AR_BSPSTORE
8171 || regno == AR_RNAT))
8173 specs[count++] = tmpl;
8178 else if (idesc->operands[1] == IA64_OPND_AR3)
8181 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8182 switch (dep->regindex)
8187 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8189 specs[count++] = tmpl;
8196 specs[count++] = tmpl;
8206 /* Handle all CR[REG] resources */
8207 if (note == 0 || note == 1)
8209 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8211 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8212 if (regno == dep->regindex)
8214 specs[count++] = tmpl;
8216 else if (!rsrc_write)
8218 /* Reads from CR[IVR] affect other resources. */
8219 if (regno == CR_IVR)
8221 if ((dep->regindex >= CR_IRR0
8222 && dep->regindex <= CR_IRR3)
8223 || dep->regindex == CR_TPR)
8225 specs[count++] = tmpl;
8232 specs[count++] = tmpl;
8241 case IA64_RS_INSERVICE:
8242 /* look for write of EOI (67) or read of IVR (65) */
8243 if ((idesc->operands[0] == IA64_OPND_CR3
8244 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8245 || (idesc->operands[1] == IA64_OPND_CR3
8246 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8248 specs[count++] = tmpl;
8255 specs[count++] = tmpl;
8266 specs[count++] = tmpl;
8270 /* Check if any of the registers accessed are in the rotating region.
8271 mov to/from pr accesses CFM only when qp_regno is in the rotating
8273 for (i = 0; i < NELEMS (idesc->operands); i++)
8275 if (idesc->operands[i] == IA64_OPND_R1
8276 || idesc->operands[i] == IA64_OPND_R2
8277 || idesc->operands[i] == IA64_OPND_R3)
8279 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8280 /* Assumes that md.rot.num_regs is always valid */
8281 if (md.rot.num_regs > 0
8283 && num < 31 + md.rot.num_regs)
8285 specs[count] = tmpl;
8286 specs[count++].specific = 0;
8289 else if (idesc->operands[i] == IA64_OPND_F1
8290 || idesc->operands[i] == IA64_OPND_F2
8291 || idesc->operands[i] == IA64_OPND_F3
8292 || idesc->operands[i] == IA64_OPND_F4)
8294 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8297 specs[count] = tmpl;
8298 specs[count++].specific = 0;
8301 else if (idesc->operands[i] == IA64_OPND_P1
8302 || idesc->operands[i] == IA64_OPND_P2)
8304 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8307 specs[count] = tmpl;
8308 specs[count++].specific = 0;
8312 if (CURR_SLOT.qp_regno > 15)
8314 specs[count] = tmpl;
8315 specs[count++].specific = 0;
8320 /* This is the same as IA64_RS_PRr, except simplified to account for
8321 the fact that there is only one register. */
8325 specs[count++] = tmpl;
8330 if (idesc->operands[2] == IA64_OPND_IMM17)
8331 mask = CURR_SLOT.opnd[2].X_add_number;
8332 if (mask & ((valueT) 1 << 63))
8333 specs[count++] = tmpl;
8335 else if (note == 11)
8337 if ((idesc->operands[0] == IA64_OPND_P1
8338 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8339 || (idesc->operands[1] == IA64_OPND_P2
8340 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8342 specs[count++] = tmpl;
8345 else if (note == 12)
8347 if (CURR_SLOT.qp_regno == 63)
8349 specs[count++] = tmpl;
8356 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8357 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8358 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8359 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8362 && (idesc->operands[0] == IA64_OPND_P1
8363 || idesc->operands[0] == IA64_OPND_P2))
8365 specs[count] = tmpl;
8366 specs[count++].cmp_type =
8367 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8370 && (idesc->operands[1] == IA64_OPND_P1
8371 || idesc->operands[1] == IA64_OPND_P2))
8373 specs[count] = tmpl;
8374 specs[count++].cmp_type =
8375 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8380 if (CURR_SLOT.qp_regno == 63)
8382 specs[count++] = tmpl;
8393 /* FIXME we can identify some individual RSE written resources, but RSE
8394 read resources have not yet been completely identified, so for now
8395 treat RSE as a single resource */
8396 if (strncmp (idesc->name, "mov", 3) == 0)
8400 if (idesc->operands[0] == IA64_OPND_AR3
8401 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8403 specs[count] = tmpl;
8404 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8409 if (idesc->operands[0] == IA64_OPND_AR3)
8411 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8412 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8414 specs[count++] = tmpl;
8417 else if (idesc->operands[1] == IA64_OPND_AR3)
8419 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8420 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8421 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8423 specs[count++] = tmpl;
8430 specs[count++] = tmpl;
8435 /* FIXME -- do any of these need to be non-specific? */
8436 specs[count++] = tmpl;
8440 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8447 /* Clear branch flags on marked resources. This breaks the link between the
8448 QP of the marking instruction and a subsequent branch on the same QP. */
8451 clear_qp_branch_flag (mask)
8455 for (i = 0; i < regdepslen; i++)
8457 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8458 if ((bit & mask) != 0)
8460 regdeps[i].link_to_qp_branch = 0;
8465 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8467 Any changes to a PR clears the mutex relations which include that PR. */
8470 clear_qp_mutex (mask)
8476 while (i < qp_mutexeslen)
8478 if ((qp_mutexes[i].prmask & mask) != 0)
8482 fprintf (stderr, " Clearing mutex relation");
8483 print_prmask (qp_mutexes[i].prmask);
8484 fprintf (stderr, "\n");
8486 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8493 /* Clear implies relations which contain PRs in the given masks.
8494 P1_MASK indicates the source of the implies relation, while P2_MASK
8495 indicates the implied PR. */
8498 clear_qp_implies (p1_mask, p2_mask)
8505 while (i < qp_implieslen)
8507 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8508 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8511 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8512 qp_implies[i].p1, qp_implies[i].p2);
8513 qp_implies[i] = qp_implies[--qp_implieslen];
8520 /* Add the PRs specified to the list of implied relations. */
8523 add_qp_imply (p1, p2)
8530 /* p0 is not meaningful here. */
8531 if (p1 == 0 || p2 == 0)
8537 /* If it exists already, ignore it. */
8538 for (i = 0; i < qp_implieslen; i++)
8540 if (qp_implies[i].p1 == p1
8541 && qp_implies[i].p2 == p2
8542 && qp_implies[i].path == md.path
8543 && !qp_implies[i].p2_branched)
8547 if (qp_implieslen == qp_impliestotlen)
8549 qp_impliestotlen += 20;
8550 qp_implies = (struct qp_imply *)
8551 xrealloc ((void *) qp_implies,
8552 qp_impliestotlen * sizeof (struct qp_imply));
8555 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8556 qp_implies[qp_implieslen].p1 = p1;
8557 qp_implies[qp_implieslen].p2 = p2;
8558 qp_implies[qp_implieslen].path = md.path;
8559 qp_implies[qp_implieslen++].p2_branched = 0;
8561 /* Add in the implied transitive relations; for everything that p2 implies,
8562 make p1 imply that, too; for everything that implies p1, make it imply p2
8564 for (i = 0; i < qp_implieslen; i++)
8566 if (qp_implies[i].p1 == p2)
8567 add_qp_imply (p1, qp_implies[i].p2);
8568 if (qp_implies[i].p2 == p1)
8569 add_qp_imply (qp_implies[i].p1, p2);
8571 /* Add in mutex relations implied by this implies relation; for each mutex
8572 relation containing p2, duplicate it and replace p2 with p1. */
8573 bit = (valueT) 1 << p1;
8574 mask = (valueT) 1 << p2;
8575 for (i = 0; i < qp_mutexeslen; i++)
8577 if (qp_mutexes[i].prmask & mask)
8578 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8582 /* Add the PRs specified in the mask to the mutex list; this means that only
8583 one of the PRs can be true at any time. PR0 should never be included in
8593 if (qp_mutexeslen == qp_mutexestotlen)
8595 qp_mutexestotlen += 20;
8596 qp_mutexes = (struct qpmutex *)
8597 xrealloc ((void *) qp_mutexes,
8598 qp_mutexestotlen * sizeof (struct qpmutex));
8602 fprintf (stderr, " Registering mutex on");
8603 print_prmask (mask);
8604 fprintf (stderr, "\n");
8606 qp_mutexes[qp_mutexeslen].path = md.path;
8607 qp_mutexes[qp_mutexeslen++].prmask = mask;
8611 clear_register_values ()
8615 fprintf (stderr, " Clearing register values\n");
8616 for (i = 1; i < NELEMS (gr_values); i++)
8617 gr_values[i].known = 0;
8620 /* Keep track of register values/changes which affect DV tracking.
8622 optimization note: should add a flag to classes of insns where otherwise we
8623 have to examine a group of strings to identify them. */
8626 note_register_values (idesc)
8627 struct ia64_opcode *idesc;
8629 valueT qp_changemask = 0;
8632 /* Invalidate values for registers being written to. */
8633 for (i = 0; i < idesc->num_outputs; i++)
8635 if (idesc->operands[i] == IA64_OPND_R1
8636 || idesc->operands[i] == IA64_OPND_R2
8637 || idesc->operands[i] == IA64_OPND_R3)
8639 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8640 if (regno > 0 && regno < NELEMS (gr_values))
8641 gr_values[regno].known = 0;
8643 else if (idesc->operands[i] == IA64_OPND_R3_2)
8645 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8646 if (regno > 0 && regno < 4)
8647 gr_values[regno].known = 0;
8649 else if (idesc->operands[i] == IA64_OPND_P1
8650 || idesc->operands[i] == IA64_OPND_P2)
8652 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8653 qp_changemask |= (valueT) 1 << regno;
8655 else if (idesc->operands[i] == IA64_OPND_PR)
8657 if (idesc->operands[2] & (valueT) 0x10000)
8658 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
8660 qp_changemask = idesc->operands[2];
8663 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
8665 if (idesc->operands[1] & ((valueT) 1 << 43))
8666 qp_changemask = ~(valueT) 0xFFFFFFFFFFF | idesc->operands[1];
8668 qp_changemask = idesc->operands[1];
8669 qp_changemask &= ~(valueT) 0xFFFF;
8674 /* Always clear qp branch flags on any PR change. */
8675 /* FIXME there may be exceptions for certain compares. */
8676 clear_qp_branch_flag (qp_changemask);
8678 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
8679 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
8681 qp_changemask |= ~(valueT) 0xFFFF;
8682 if (strcmp (idesc->name, "clrrrb.pr") != 0)
8684 for (i = 32; i < 32 + md.rot.num_regs; i++)
8685 gr_values[i].known = 0;
8687 clear_qp_mutex (qp_changemask);
8688 clear_qp_implies (qp_changemask, qp_changemask);
8690 /* After a call, all register values are undefined, except those marked
8692 else if (strncmp (idesc->name, "br.call", 6) == 0
8693 || strncmp (idesc->name, "brl.call", 7) == 0)
8695 /* FIXME keep GR values which are marked as "safe_across_calls" */
8696 clear_register_values ();
8697 clear_qp_mutex (~qp_safe_across_calls);
8698 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
8699 clear_qp_branch_flag (~qp_safe_across_calls);
8701 else if (is_interruption_or_rfi (idesc)
8702 || is_taken_branch (idesc))
8704 clear_register_values ();
8705 clear_qp_mutex (~(valueT) 0);
8706 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
8708 /* Look for mutex and implies relations. */
8709 else if ((idesc->operands[0] == IA64_OPND_P1
8710 || idesc->operands[0] == IA64_OPND_P2)
8711 && (idesc->operands[1] == IA64_OPND_P1
8712 || idesc->operands[1] == IA64_OPND_P2))
8714 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8715 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8716 valueT p1mask = (valueT) 1 << p1;
8717 valueT p2mask = (valueT) 1 << p2;
8719 /* If one of the PRs is PR0, we can't really do anything. */
8720 if (p1 == 0 || p2 == 0)
8723 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
8725 /* In general, clear mutexes and implies which include P1 or P2,
8726 with the following exceptions. */
8727 else if (strstr (idesc->name, ".or.andcm") != NULL)
8729 add_qp_mutex (p1mask | p2mask);
8730 clear_qp_implies (p2mask, p1mask);
8732 else if (strstr (idesc->name, ".and.orcm") != NULL)
8734 add_qp_mutex (p1mask | p2mask);
8735 clear_qp_implies (p1mask, p2mask);
8737 else if (strstr (idesc->name, ".and") != NULL)
8739 clear_qp_implies (0, p1mask | p2mask);
8741 else if (strstr (idesc->name, ".or") != NULL)
8743 clear_qp_mutex (p1mask | p2mask);
8744 clear_qp_implies (p1mask | p2mask, 0);
8748 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
8749 if (strstr (idesc->name, ".unc") != NULL)
8751 add_qp_mutex (p1mask | p2mask);
8752 if (CURR_SLOT.qp_regno != 0)
8754 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
8755 CURR_SLOT.qp_regno);
8756 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
8757 CURR_SLOT.qp_regno);
8760 else if (CURR_SLOT.qp_regno == 0)
8762 add_qp_mutex (p1mask | p2mask);
8766 clear_qp_mutex (p1mask | p2mask);
8770 /* Look for mov imm insns into GRs. */
8771 else if (idesc->operands[0] == IA64_OPND_R1
8772 && (idesc->operands[1] == IA64_OPND_IMM22
8773 || idesc->operands[1] == IA64_OPND_IMMU64)
8774 && (strcmp (idesc->name, "mov") == 0
8775 || strcmp (idesc->name, "movl") == 0))
8777 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8778 if (regno > 0 && regno < NELEMS (gr_values))
8780 gr_values[regno].known = 1;
8781 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
8782 gr_values[regno].path = md.path;
8785 fprintf (stderr, " Know gr%d = ", regno);
8786 fprintf_vma (stderr, gr_values[regno].value);
8787 fputs ("\n", stderr);
8793 clear_qp_mutex (qp_changemask);
8794 clear_qp_implies (qp_changemask, qp_changemask);
8798 /* Return whether the given predicate registers are currently mutex. */
8801 qp_mutex (p1, p2, path)
8811 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
8812 for (i = 0; i < qp_mutexeslen; i++)
8814 if (qp_mutexes[i].path >= path
8815 && (qp_mutexes[i].prmask & mask) == mask)
8822 /* Return whether the given resource is in the given insn's list of chks
8823 Return 1 if the conflict is absolutely determined, 2 if it's a potential
8827 resources_match (rs, idesc, note, qp_regno, path)
8829 struct ia64_opcode *idesc;
8834 struct rsrc specs[MAX_SPECS];
8837 /* If the marked resource's qp_regno and the given qp_regno are mutex,
8838 we don't need to check. One exception is note 11, which indicates that
8839 target predicates are written regardless of PR[qp]. */
8840 if (qp_mutex (rs->qp_regno, qp_regno, path)
8844 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
8847 /* UNAT checking is a bit more specific than other resources */
8848 if (rs->dependency->specifier == IA64_RS_AR_UNAT
8849 && specs[count].mem_offset.hint
8850 && rs->mem_offset.hint)
8852 if (rs->mem_offset.base == specs[count].mem_offset.base)
8854 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
8855 ((specs[count].mem_offset.offset >> 3) & 0x3F))
8862 /* Skip apparent PR write conflicts where both writes are an AND or both
8863 writes are an OR. */
8864 if (rs->dependency->specifier == IA64_RS_PR
8865 || rs->dependency->specifier == IA64_RS_PRr
8866 || rs->dependency->specifier == IA64_RS_PR63)
8868 if (specs[count].cmp_type != CMP_NONE
8869 && specs[count].cmp_type == rs->cmp_type)
8872 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
8873 dv_mode[rs->dependency->mode],
8874 rs->dependency->specifier != IA64_RS_PR63 ?
8875 specs[count].index : 63);
8880 " %s on parallel compare conflict %s vs %s on PR%d\n",
8881 dv_mode[rs->dependency->mode],
8882 dv_cmp_type[rs->cmp_type],
8883 dv_cmp_type[specs[count].cmp_type],
8884 rs->dependency->specifier != IA64_RS_PR63 ?
8885 specs[count].index : 63);
8889 /* If either resource is not specific, conservatively assume a conflict
8891 if (!specs[count].specific || !rs->specific)
8893 else if (specs[count].index == rs->index)
8898 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
8904 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
8905 insert a stop to create the break. Update all resource dependencies
8906 appropriately. If QP_REGNO is non-zero, only apply the break to resources
8907 which use the same QP_REGNO and have the link_to_qp_branch flag set.
8908 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
8912 insn_group_break (insert_stop, qp_regno, save_current)
8919 if (insert_stop && md.num_slots_in_use > 0)
8920 PREV_SLOT.end_of_insn_group = 1;
8924 fprintf (stderr, " Insn group break%s",
8925 (insert_stop ? " (w/stop)" : ""));
8927 fprintf (stderr, " effective for QP=%d", qp_regno);
8928 fprintf (stderr, "\n");
8932 while (i < regdepslen)
8934 const struct ia64_dependency *dep = regdeps[i].dependency;
8937 && regdeps[i].qp_regno != qp_regno)
8944 && CURR_SLOT.src_file == regdeps[i].file
8945 && CURR_SLOT.src_line == regdeps[i].line)
8951 /* clear dependencies which are automatically cleared by a stop, or
8952 those that have reached the appropriate state of insn serialization */
8953 if (dep->semantics == IA64_DVS_IMPLIED
8954 || dep->semantics == IA64_DVS_IMPLIEDF
8955 || regdeps[i].insn_srlz == STATE_SRLZ)
8957 print_dependency ("Removing", i);
8958 regdeps[i] = regdeps[--regdepslen];
8962 if (dep->semantics == IA64_DVS_DATA
8963 || dep->semantics == IA64_DVS_INSTR
8964 || dep->semantics == IA64_DVS_SPECIFIC)
8966 if (regdeps[i].insn_srlz == STATE_NONE)
8967 regdeps[i].insn_srlz = STATE_STOP;
8968 if (regdeps[i].data_srlz == STATE_NONE)
8969 regdeps[i].data_srlz = STATE_STOP;
8976 /* Add the given resource usage spec to the list of active dependencies. */
8979 mark_resource (idesc, dep, spec, depind, path)
8980 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
8981 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
8986 if (regdepslen == regdepstotlen)
8988 regdepstotlen += 20;
8989 regdeps = (struct rsrc *)
8990 xrealloc ((void *) regdeps,
8991 regdepstotlen * sizeof (struct rsrc));
8994 regdeps[regdepslen] = *spec;
8995 regdeps[regdepslen].depind = depind;
8996 regdeps[regdepslen].path = path;
8997 regdeps[regdepslen].file = CURR_SLOT.src_file;
8998 regdeps[regdepslen].line = CURR_SLOT.src_line;
9000 print_dependency ("Adding", regdepslen);
9006 print_dependency (action, depind)
9012 fprintf (stderr, " %s %s '%s'",
9013 action, dv_mode[(regdeps[depind].dependency)->mode],
9014 (regdeps[depind].dependency)->name);
9015 if (regdeps[depind].specific && regdeps[depind].index != 0)
9016 fprintf (stderr, " (%d)", regdeps[depind].index);
9017 if (regdeps[depind].mem_offset.hint)
9019 fputs (" ", stderr);
9020 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9021 fputs ("+", stderr);
9022 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9024 fprintf (stderr, "\n");
9029 instruction_serialization ()
9033 fprintf (stderr, " Instruction serialization\n");
9034 for (i = 0; i < regdepslen; i++)
9035 if (regdeps[i].insn_srlz == STATE_STOP)
9036 regdeps[i].insn_srlz = STATE_SRLZ;
9040 data_serialization ()
9044 fprintf (stderr, " Data serialization\n");
9045 while (i < regdepslen)
9047 if (regdeps[i].data_srlz == STATE_STOP
9048 /* Note: as of 991210, all "other" dependencies are cleared by a
9049 data serialization. This might change with new tables */
9050 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9052 print_dependency ("Removing", i);
9053 regdeps[i] = regdeps[--regdepslen];
9060 /* Insert stops and serializations as needed to avoid DVs. */
9063 remove_marked_resource (rs)
9066 switch (rs->dependency->semantics)
9068 case IA64_DVS_SPECIFIC:
9070 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9071 /* ...fall through... */
9072 case IA64_DVS_INSTR:
9074 fprintf (stderr, "Inserting instr serialization\n");
9075 if (rs->insn_srlz < STATE_STOP)
9076 insn_group_break (1, 0, 0);
9077 if (rs->insn_srlz < STATE_SRLZ)
9079 int oldqp = CURR_SLOT.qp_regno;
9080 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9081 /* Manually jam a srlz.i insn into the stream */
9082 CURR_SLOT.qp_regno = 0;
9083 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9084 instruction_serialization ();
9085 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9086 if (++md.num_slots_in_use >= NUM_SLOTS)
9088 CURR_SLOT.qp_regno = oldqp;
9089 CURR_SLOT.idesc = oldidesc;
9091 insn_group_break (1, 0, 0);
9093 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9094 "other" types of DV are eliminated
9095 by a data serialization */
9098 fprintf (stderr, "Inserting data serialization\n");
9099 if (rs->data_srlz < STATE_STOP)
9100 insn_group_break (1, 0, 0);
9102 int oldqp = CURR_SLOT.qp_regno;
9103 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9104 /* Manually jam a srlz.d insn into the stream */
9105 CURR_SLOT.qp_regno = 0;
9106 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9107 data_serialization ();
9108 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9109 if (++md.num_slots_in_use >= NUM_SLOTS)
9111 CURR_SLOT.qp_regno = oldqp;
9112 CURR_SLOT.idesc = oldidesc;
9115 case IA64_DVS_IMPLIED:
9116 case IA64_DVS_IMPLIEDF:
9118 fprintf (stderr, "Inserting stop\n");
9119 insn_group_break (1, 0, 0);
9126 /* Check the resources used by the given opcode against the current dependency
9129 The check is run once for each execution path encountered. In this case,
9130 a unique execution path is the sequence of instructions following a code
9131 entry point, e.g. the following has three execution paths, one starting
9132 at L0, one at L1, and one at L2.
9141 check_dependencies (idesc)
9142 struct ia64_opcode *idesc;
9144 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9148 /* Note that the number of marked resources may change within the
9149 loop if in auto mode. */
9151 while (i < regdepslen)
9153 struct rsrc *rs = ®deps[i];
9154 const struct ia64_dependency *dep = rs->dependency;
9159 if (dep->semantics == IA64_DVS_NONE
9160 || (chkind = depends_on (rs->depind, idesc)) == -1)
9166 note = NOTE (opdeps->chks[chkind]);
9168 /* Check this resource against each execution path seen thus far. */
9169 for (path = 0; path <= md.path; path++)
9173 /* If the dependency wasn't on the path being checked, ignore it. */
9174 if (rs->path < path)
9177 /* If the QP for this insn implies a QP which has branched, don't
9178 bother checking. Ed. NOTE: I don't think this check is terribly
9179 useful; what's the point of generating code which will only be
9180 reached if its QP is zero?
9181 This code was specifically inserted to handle the following code,
9182 based on notes from Intel's DV checking code, where p1 implies p2.
9188 if (CURR_SLOT.qp_regno != 0)
9192 for (implies = 0; implies < qp_implieslen; implies++)
9194 if (qp_implies[implies].path >= path
9195 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9196 && qp_implies[implies].p2_branched)
9206 if ((matchtype = resources_match (rs, idesc, note,
9207 CURR_SLOT.qp_regno, path)) != 0)
9210 char pathmsg[256] = "";
9211 char indexmsg[256] = "";
9212 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9215 sprintf (pathmsg, " when entry is at label '%s'",
9216 md.entry_labels[path - 1]);
9217 if (rs->specific && rs->index != 0)
9218 sprintf (indexmsg, ", specific resource number is %d",
9220 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9222 (certain ? "violates" : "may violate"),
9223 dv_mode[dep->mode], dep->name,
9224 dv_sem[dep->semantics],
9227 if (md.explicit_mode)
9229 as_warn ("%s", msg);
9231 as_warn (_("Only the first path encountering the conflict "
9233 as_warn_where (rs->file, rs->line,
9234 _("This is the location of the "
9235 "conflicting usage"));
9236 /* Don't bother checking other paths, to avoid duplicating
9243 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9245 remove_marked_resource (rs);
9247 /* since the set of dependencies has changed, start over */
9248 /* FIXME -- since we're removing dvs as we go, we
9249 probably don't really need to start over... */
9262 /* Register new dependencies based on the given opcode. */
9265 mark_resources (idesc)
9266 struct ia64_opcode *idesc;
9269 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9270 int add_only_qp_reads = 0;
9272 /* A conditional branch only uses its resources if it is taken; if it is
9273 taken, we stop following that path. The other branch types effectively
9274 *always* write their resources. If it's not taken, register only QP
9276 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9278 add_only_qp_reads = 1;
9282 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9284 for (i = 0; i < opdeps->nregs; i++)
9286 const struct ia64_dependency *dep;
9287 struct rsrc specs[MAX_SPECS];
9292 dep = ia64_find_dependency (opdeps->regs[i]);
9293 note = NOTE (opdeps->regs[i]);
9295 if (add_only_qp_reads
9296 && !(dep->mode == IA64_DV_WAR
9297 && (dep->specifier == IA64_RS_PR
9298 || dep->specifier == IA64_RS_PRr
9299 || dep->specifier == IA64_RS_PR63)))
9302 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9305 if (md.debug_dv && !count)
9306 fprintf (stderr, " No %s %s usage found (path %d)\n",
9307 dv_mode[dep->mode], dep->name, md.path);
9312 mark_resource (idesc, dep, &specs[count],
9313 DEP (opdeps->regs[i]), md.path);
9316 /* The execution path may affect register values, which may in turn
9317 affect which indirect-access resources are accessed. */
9318 switch (dep->specifier)
9330 for (path = 0; path < md.path; path++)
9332 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9334 mark_resource (idesc, dep, &specs[count],
9335 DEP (opdeps->regs[i]), path);
9342 /* Remove dependencies when they no longer apply. */
9345 update_dependencies (idesc)
9346 struct ia64_opcode *idesc;
9350 if (strcmp (idesc->name, "srlz.i") == 0)
9352 instruction_serialization ();
9354 else if (strcmp (idesc->name, "srlz.d") == 0)
9356 data_serialization ();
9358 else if (is_interruption_or_rfi (idesc)
9359 || is_taken_branch (idesc))
9361 /* Although technically the taken branch doesn't clear dependencies
9362 which require a srlz.[id], we don't follow the branch; the next
9363 instruction is assumed to start with a clean slate. */
9367 else if (is_conditional_branch (idesc)
9368 && CURR_SLOT.qp_regno != 0)
9370 int is_call = strstr (idesc->name, ".call") != NULL;
9372 for (i = 0; i < qp_implieslen; i++)
9374 /* If the conditional branch's predicate is implied by the predicate
9375 in an existing dependency, remove that dependency. */
9376 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9379 /* Note that this implied predicate takes a branch so that if
9380 a later insn generates a DV but its predicate implies this
9381 one, we can avoid the false DV warning. */
9382 qp_implies[i].p2_branched = 1;
9383 while (depind < regdepslen)
9385 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9387 print_dependency ("Removing", depind);
9388 regdeps[depind] = regdeps[--regdepslen];
9395 /* Any marked resources which have this same predicate should be
9396 cleared, provided that the QP hasn't been modified between the
9397 marking instruction and the branch. */
9400 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9405 while (i < regdepslen)
9407 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9408 && regdeps[i].link_to_qp_branch
9409 && (regdeps[i].file != CURR_SLOT.src_file
9410 || regdeps[i].line != CURR_SLOT.src_line))
9412 /* Treat like a taken branch */
9413 print_dependency ("Removing", i);
9414 regdeps[i] = regdeps[--regdepslen];
9423 /* Examine the current instruction for dependency violations. */
9427 struct ia64_opcode *idesc;
9431 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9432 idesc->name, CURR_SLOT.src_line,
9433 idesc->dependencies->nchks,
9434 idesc->dependencies->nregs);
9437 /* Look through the list of currently marked resources; if the current
9438 instruction has the dependency in its chks list which uses that resource,
9439 check against the specific resources used. */
9440 check_dependencies (idesc);
9442 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9443 then add them to the list of marked resources. */
9444 mark_resources (idesc);
9446 /* There are several types of dependency semantics, and each has its own
9447 requirements for being cleared
9449 Instruction serialization (insns separated by interruption, rfi, or
9450 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9452 Data serialization (instruction serialization, or writer + srlz.d +
9453 reader, where writer and srlz.d are in separate groups) clears
9454 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9455 always be the case).
9457 Instruction group break (groups separated by stop, taken branch,
9458 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9460 update_dependencies (idesc);
9462 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9463 warning. Keep track of as many as possible that are useful. */
9464 note_register_values (idesc);
9466 /* We don't need or want this anymore. */
9467 md.mem_offset.hint = 0;
9472 /* Translate one line of assembly. Pseudo ops and labels do not show
9478 char *saved_input_line_pointer, *mnemonic;
9479 const struct pseudo_opcode *pdesc;
9480 struct ia64_opcode *idesc;
9481 unsigned char qp_regno;
9485 saved_input_line_pointer = input_line_pointer;
9486 input_line_pointer = str;
9488 /* extract the opcode (mnemonic): */
9490 mnemonic = input_line_pointer;
9491 ch = get_symbol_end ();
9492 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9495 *input_line_pointer = ch;
9496 (*pdesc->handler) (pdesc->arg);
9500 /* Find the instruction descriptor matching the arguments. */
9502 idesc = ia64_find_opcode (mnemonic);
9503 *input_line_pointer = ch;
9506 as_bad ("Unknown opcode `%s'", mnemonic);
9510 idesc = parse_operands (idesc);
9514 /* Handle the dynamic ops we can handle now: */
9515 if (idesc->type == IA64_TYPE_DYN)
9517 if (strcmp (idesc->name, "add") == 0)
9519 if (CURR_SLOT.opnd[2].X_op == O_register
9520 && CURR_SLOT.opnd[2].X_add_number < 4)
9524 ia64_free_opcode (idesc);
9525 idesc = ia64_find_opcode (mnemonic);
9527 know (!idesc->next);
9530 else if (strcmp (idesc->name, "mov") == 0)
9532 enum ia64_opnd opnd1, opnd2;
9535 opnd1 = idesc->operands[0];
9536 opnd2 = idesc->operands[1];
9537 if (opnd1 == IA64_OPND_AR3)
9539 else if (opnd2 == IA64_OPND_AR3)
9543 if (CURR_SLOT.opnd[rop].X_op == O_register
9544 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9548 ia64_free_opcode (idesc);
9549 idesc = ia64_find_opcode (mnemonic);
9550 while (idesc != NULL
9551 && (idesc->operands[0] != opnd1
9552 || idesc->operands[1] != opnd2))
9553 idesc = get_next_opcode (idesc);
9558 if (md.qp.X_op == O_register)
9560 qp_regno = md.qp.X_add_number - REG_P;
9561 md.qp.X_op = O_absent;
9564 flags = idesc->flags;
9566 if ((flags & IA64_OPCODE_FIRST) != 0)
9567 insn_group_break (1, 0, 0);
9569 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
9571 as_bad ("`%s' cannot be predicated", idesc->name);
9575 /* Build the instruction. */
9576 CURR_SLOT.qp_regno = qp_regno;
9577 CURR_SLOT.idesc = idesc;
9578 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
9579 dwarf2_where (&CURR_SLOT.debug_line);
9581 /* Add unwind entry, if there is one. */
9582 if (unwind.current_entry)
9584 CURR_SLOT.unwind_record = unwind.current_entry;
9585 unwind.current_entry = NULL;
9588 /* Check for dependency violations. */
9592 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9593 if (++md.num_slots_in_use >= NUM_SLOTS)
9596 if ((flags & IA64_OPCODE_LAST) != 0)
9597 insn_group_break (1, 0, 0);
9599 md.last_text_seg = now_seg;
9602 input_line_pointer = saved_input_line_pointer;
9605 /* Called when symbol NAME cannot be found in the symbol table.
9606 Should be used for dynamic valued symbols only. */
9609 md_undefined_symbol (name)
9610 char *name ATTRIBUTE_UNUSED;
9615 /* Called for any expression that can not be recognized. When the
9616 function is called, `input_line_pointer' will point to the start of
9623 enum pseudo_type pseudo_type;
9628 switch (*input_line_pointer)
9631 /* Find what relocation pseudo-function we're dealing with. */
9633 ch = *++input_line_pointer;
9634 for (i = 0; i < NELEMS (pseudo_func); ++i)
9635 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
9637 len = strlen (pseudo_func[i].name);
9638 if (strncmp (pseudo_func[i].name + 1,
9639 input_line_pointer + 1, len - 1) == 0
9640 && !is_part_of_name (input_line_pointer[len]))
9642 input_line_pointer += len;
9643 pseudo_type = pseudo_func[i].type;
9647 switch (pseudo_type)
9649 case PSEUDO_FUNC_RELOC:
9651 if (*input_line_pointer != '(')
9653 as_bad ("Expected '('");
9657 ++input_line_pointer;
9659 if (*input_line_pointer++ != ')')
9661 as_bad ("Missing ')'");
9664 if (e->X_op != O_symbol)
9666 if (e->X_op != O_pseudo_fixup)
9668 as_bad ("Not a symbolic expression");
9671 if (S_GET_VALUE (e->X_op_symbol) == FUNC_FPTR_RELATIVE
9672 && i == FUNC_LT_RELATIVE)
9673 i = FUNC_LT_FPTR_RELATIVE;
9676 as_bad ("Illegal combination of relocation functions");
9680 /* Make sure gas doesn't get rid of local symbols that are used
9682 e->X_op = O_pseudo_fixup;
9683 e->X_op_symbol = pseudo_func[i].u.sym;
9686 case PSEUDO_FUNC_CONST:
9687 e->X_op = O_constant;
9688 e->X_add_number = pseudo_func[i].u.ival;
9691 case PSEUDO_FUNC_REG:
9692 e->X_op = O_register;
9693 e->X_add_number = pseudo_func[i].u.ival;
9697 name = input_line_pointer - 1;
9699 as_bad ("Unknown pseudo function `%s'", name);
9705 ++input_line_pointer;
9707 if (*input_line_pointer != ']')
9709 as_bad ("Closing bracket misssing");
9714 if (e->X_op != O_register)
9715 as_bad ("Register expected as index");
9717 ++input_line_pointer;
9728 ignore_rest_of_line ();
9731 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
9732 a section symbol plus some offset. For relocs involving @fptr(),
9733 directives we don't want such adjustments since we need to have the
9734 original symbol's name in the reloc. */
9736 ia64_fix_adjustable (fix)
9739 /* Prevent all adjustments to global symbols */
9740 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
9743 switch (fix->fx_r_type)
9745 case BFD_RELOC_IA64_FPTR64I:
9746 case BFD_RELOC_IA64_FPTR32MSB:
9747 case BFD_RELOC_IA64_FPTR32LSB:
9748 case BFD_RELOC_IA64_FPTR64MSB:
9749 case BFD_RELOC_IA64_FPTR64LSB:
9750 case BFD_RELOC_IA64_LTOFF_FPTR22:
9751 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9761 ia64_force_relocation (fix)
9764 switch (fix->fx_r_type)
9766 case BFD_RELOC_IA64_FPTR64I:
9767 case BFD_RELOC_IA64_FPTR32MSB:
9768 case BFD_RELOC_IA64_FPTR32LSB:
9769 case BFD_RELOC_IA64_FPTR64MSB:
9770 case BFD_RELOC_IA64_FPTR64LSB:
9772 case BFD_RELOC_IA64_LTOFF22:
9773 case BFD_RELOC_IA64_LTOFF64I:
9774 case BFD_RELOC_IA64_LTOFF_FPTR22:
9775 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9776 case BFD_RELOC_IA64_PLTOFF22:
9777 case BFD_RELOC_IA64_PLTOFF64I:
9778 case BFD_RELOC_IA64_PLTOFF64MSB:
9779 case BFD_RELOC_IA64_PLTOFF64LSB:
9788 /* Decide from what point a pc-relative relocation is relative to,
9789 relative to the pc-relative fixup. Er, relatively speaking. */
9791 ia64_pcrel_from_section (fix, sec)
9795 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
9797 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
9803 /* This is called whenever some data item (not an instruction) needs a
9804 fixup. We pick the right reloc code depending on the byteorder
9805 currently in effect. */
9807 ia64_cons_fix_new (f, where, nbytes, exp)
9813 bfd_reloc_code_real_type code;
9818 /* There are no reloc for 8 and 16 bit quantities, but we allow
9819 them here since they will work fine as long as the expression
9820 is fully defined at the end of the pass over the source file. */
9821 case 1: code = BFD_RELOC_8; break;
9822 case 2: code = BFD_RELOC_16; break;
9824 if (target_big_endian)
9825 code = BFD_RELOC_IA64_DIR32MSB;
9827 code = BFD_RELOC_IA64_DIR32LSB;
9831 if (target_big_endian)
9832 code = BFD_RELOC_IA64_DIR64MSB;
9834 code = BFD_RELOC_IA64_DIR64LSB;
9838 if (exp->X_op == O_pseudo_fixup
9840 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
9842 if (target_big_endian)
9843 code = BFD_RELOC_IA64_IPLTMSB;
9845 code = BFD_RELOC_IA64_IPLTLSB;
9847 exp->X_op = O_symbol;
9853 as_bad ("Unsupported fixup size %d", nbytes);
9854 ignore_rest_of_line ();
9857 if (exp->X_op == O_pseudo_fixup)
9860 exp->X_op = O_symbol;
9861 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
9864 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
9865 /* We need to store the byte order in effect in case we're going
9866 to fix an 8 or 16 bit relocation (for which there no real
9867 relocs available). See md_apply_fix(). */
9868 fix->tc_fix_data.bigendian = target_big_endian;
9871 /* Return the actual relocation we wish to associate with the pseudo
9872 reloc described by SYM and R_TYPE. SYM should be one of the
9873 symbols in the pseudo_func array, or NULL. */
9875 static bfd_reloc_code_real_type
9876 ia64_gen_real_reloc_type (sym, r_type)
9878 bfd_reloc_code_real_type r_type;
9880 bfd_reloc_code_real_type new = 0;
9887 switch (S_GET_VALUE (sym))
9889 case FUNC_FPTR_RELATIVE:
9892 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
9893 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
9894 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
9895 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
9896 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
9901 case FUNC_GP_RELATIVE:
9904 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
9905 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
9906 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
9907 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
9908 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
9909 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
9914 case FUNC_LT_RELATIVE:
9917 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
9918 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
9923 case FUNC_PC_RELATIVE:
9926 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
9927 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
9928 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
9929 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
9930 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
9931 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
9936 case FUNC_PLT_RELATIVE:
9939 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
9940 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
9941 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
9942 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
9947 case FUNC_SEC_RELATIVE:
9950 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
9951 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
9952 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
9953 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
9958 case FUNC_SEG_RELATIVE:
9961 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
9962 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
9963 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
9964 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
9969 case FUNC_LTV_RELATIVE:
9972 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
9973 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
9974 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
9975 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
9980 case FUNC_LT_FPTR_RELATIVE:
9983 case BFD_RELOC_IA64_IMM22:
9984 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
9985 case BFD_RELOC_IA64_IMM64:
9986 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
9995 /* Hmmmm. Should this ever occur? */
10002 /* Here is where generate the appropriate reloc for pseudo relocation
10005 ia64_validate_fix (fix)
10008 switch (fix->fx_r_type)
10010 case BFD_RELOC_IA64_FPTR64I:
10011 case BFD_RELOC_IA64_FPTR32MSB:
10012 case BFD_RELOC_IA64_FPTR64LSB:
10013 case BFD_RELOC_IA64_LTOFF_FPTR22:
10014 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10015 if (fix->fx_offset != 0)
10016 as_bad_where (fix->fx_file, fix->fx_line,
10017 "No addend allowed in @fptr() relocation");
10027 fix_insn (fix, odesc, value)
10029 const struct ia64_operand *odesc;
10032 bfd_vma insn[3], t0, t1, control_bits;
10037 slot = fix->fx_where & 0x3;
10038 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10040 /* Bundles are always in little-endian byte order */
10041 t0 = bfd_getl64 (fixpos);
10042 t1 = bfd_getl64 (fixpos + 8);
10043 control_bits = t0 & 0x1f;
10044 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10045 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10046 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10049 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10051 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10052 insn[2] |= (((value & 0x7f) << 13)
10053 | (((value >> 7) & 0x1ff) << 27)
10054 | (((value >> 16) & 0x1f) << 22)
10055 | (((value >> 21) & 0x1) << 21)
10056 | (((value >> 63) & 0x1) << 36));
10058 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10060 if (value & ~0x3fffffffffffffffULL)
10061 err = "integer operand out of range";
10062 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10063 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10065 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10068 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10069 insn[2] |= ((((value >> 59) & 0x1) << 36)
10070 | (((value >> 0) & 0xfffff) << 13));
10073 err = (*odesc->insert) (odesc, value, insn + slot);
10076 as_bad_where (fix->fx_file, fix->fx_line, err);
10078 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10079 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10080 number_to_chars_littleendian (fixpos + 0, t0, 8);
10081 number_to_chars_littleendian (fixpos + 8, t1, 8);
10084 /* Attempt to simplify or even eliminate a fixup. The return value is
10085 ignored; perhaps it was once meaningful, but now it is historical.
10086 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10088 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10091 md_apply_fix3 (fix, valuep, seg)
10094 segT seg ATTRIBUTE_UNUSED;
10097 valueT value = *valuep;
10100 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10104 switch (fix->fx_r_type)
10106 case BFD_RELOC_IA64_DIR32MSB:
10107 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10111 case BFD_RELOC_IA64_DIR32LSB:
10112 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10116 case BFD_RELOC_IA64_DIR64MSB:
10117 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10121 case BFD_RELOC_IA64_DIR64LSB:
10122 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10132 if (fix->fx_r_type == (int) BFD_RELOC_UNUSED)
10134 /* This must be a TAG13 or TAG13b operand. There are no external
10135 relocs defined for them, so we must give an error. */
10136 as_bad_where (fix->fx_file, fix->fx_line,
10137 "%s must have a constant value",
10138 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10143 /* ??? This is a hack copied from tc-i386.c to make PCREL relocs
10144 work. There should be a better way to handle this. */
10146 fix->fx_offset += fix->fx_where + fix->fx_frag->fr_address;
10148 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10150 if (fix->tc_fix_data.bigendian)
10151 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10153 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10159 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10166 /* Generate the BFD reloc to be stuck in the object file from the
10167 fixup used internally in the assembler. */
10170 tc_gen_reloc (sec, fixp)
10171 asection *sec ATTRIBUTE_UNUSED;
10176 reloc = xmalloc (sizeof (*reloc));
10177 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10178 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10179 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10180 reloc->addend = fixp->fx_offset;
10181 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10185 as_bad_where (fixp->fx_file, fixp->fx_line,
10186 "Cannot represent %s relocation in object file",
10187 bfd_get_reloc_code_name (fixp->fx_r_type));
10192 /* Turn a string in input_line_pointer into a floating point constant
10193 of type TYPE, and store the appropriate bytes in *LIT. The number
10194 of LITTLENUMS emitted is stored in *SIZE. An error message is
10195 returned, or NULL on OK. */
10197 #define MAX_LITTLENUMS 5
10200 md_atof (type, lit, size)
10205 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10206 LITTLENUM_TYPE *word;
10236 return "Bad call to MD_ATOF()";
10238 t = atof_ieee (input_line_pointer, type, words);
10240 input_line_pointer = t;
10241 *size = prec * sizeof (LITTLENUM_TYPE);
10243 for (word = words + prec - 1; prec--;)
10245 md_number_to_chars (lit, (long) (*word--), sizeof (LITTLENUM_TYPE));
10246 lit += sizeof (LITTLENUM_TYPE);
10251 /* Round up a section's size to the appropriate boundary. */
10253 md_section_align (seg, size)
10257 int align = bfd_get_section_alignment (stdoutput, seg);
10258 valueT mask = ((valueT) 1 << align) - 1;
10260 return (size + mask) & ~mask;
10263 /* Handle ia64 specific semantics of the align directive. */
10266 ia64_md_do_align (n, fill, len, max)
10267 int n ATTRIBUTE_UNUSED;
10268 const char *fill ATTRIBUTE_UNUSED;
10269 int len ATTRIBUTE_UNUSED;
10270 int max ATTRIBUTE_UNUSED;
10272 if (subseg_text_p (now_seg))
10273 ia64_flush_insns ();
10276 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10277 of an rs_align_code fragment. */
10280 ia64_handle_align (fragp)
10283 /* Use mfi bundle of nops with no stop bits. */
10284 static const unsigned char be_nop[]
10285 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
10286 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
10287 static const unsigned char le_nop[]
10288 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10289 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10294 if (fragp->fr_type != rs_align_code)
10297 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10298 p = fragp->fr_literal + fragp->fr_fix;
10300 /* Make sure we are on a 16-byte boundary, in case someone has been
10301 putting data into a text section. */
10304 int fix = bytes & 15;
10305 memset (p, 0, fix);
10308 fragp->fr_fix += fix;
10311 memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
10312 fragp->fr_var = 16;