1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
35 - labels are wrong if automatic alignment is introduced
36 (e.g., checkout the second real10 definition in test-data.s)
38 <reg>.safe_across_calls and any other DV-related directives I don't
39 have documentation for.
40 verify mod-sched-brs reads/writes are checked/marked (and other
46 #include "safe-ctype.h"
47 #include "dwarf2dbg.h"
50 #include "opcode/ia64.h"
54 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
55 #define MIN(a,b) ((a) < (b) ? (a) : (b))
58 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
59 #define CURR_SLOT md.slot[md.curr_slot]
61 #define O_pseudo_fixup (O_max + 1)
65 /* IA-64 ABI section pseudo-ops. */
66 SPECIAL_SECTION_BSS = 0,
68 SPECIAL_SECTION_SDATA,
69 SPECIAL_SECTION_RODATA,
70 SPECIAL_SECTION_COMMENT,
71 SPECIAL_SECTION_UNWIND,
72 SPECIAL_SECTION_UNWIND_INFO,
73 /* HPUX specific section pseudo-ops. */
74 SPECIAL_SECTION_INIT_ARRAY,
75 SPECIAL_SECTION_FINI_ARRAY,
92 FUNC_LT_FPTR_RELATIVE,
102 REG_FR = (REG_GR + 128),
103 REG_AR = (REG_FR + 128),
104 REG_CR = (REG_AR + 128),
105 REG_P = (REG_CR + 128),
106 REG_BR = (REG_P + 64),
107 REG_IP = (REG_BR + 8),
114 /* The following are pseudo-registers for use by gas only. */
126 /* The following pseudo-registers are used for unwind directives only: */
134 DYNREG_GR = 0, /* dynamic general purpose register */
135 DYNREG_FR, /* dynamic floating point register */
136 DYNREG_PR, /* dynamic predicate register */
140 enum operand_match_result
143 OPERAND_OUT_OF_RANGE,
147 /* On the ia64, we can't know the address of a text label until the
148 instructions are packed into a bundle. To handle this, we keep
149 track of the list of labels that appear in front of each
153 struct label_fix *next;
157 /* This is the endianness of the current section. */
158 extern int target_big_endian;
160 /* This is the default endianness. */
161 static int default_big_endian = TARGET_BYTES_BIG_ENDIAN;
163 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
165 static void ia64_float_to_chars_bigendian
166 PARAMS ((char *, LITTLENUM_TYPE *, int));
167 static void ia64_float_to_chars_littleendian
168 PARAMS ((char *, LITTLENUM_TYPE *, int));
169 static void (*ia64_float_to_chars)
170 PARAMS ((char *, LITTLENUM_TYPE *, int));
172 static struct hash_control *alias_hash;
173 static struct hash_control *alias_name_hash;
174 static struct hash_control *secalias_hash;
175 static struct hash_control *secalias_name_hash;
177 /* Characters which always start a comment. */
178 const char comment_chars[] = "";
180 /* Characters which start a comment at the beginning of a line. */
181 const char line_comment_chars[] = "#";
183 /* Characters which may be used to separate multiple commands on a
185 const char line_separator_chars[] = ";";
187 /* Characters which are used to indicate an exponent in a floating
189 const char EXP_CHARS[] = "eE";
191 /* Characters which mean that a number is a floating point constant,
193 const char FLT_CHARS[] = "rRsSfFdDxXpP";
195 /* ia64-specific option processing: */
197 const char *md_shortopts = "m:N:x::";
199 struct option md_longopts[] =
201 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
202 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
203 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
204 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
207 size_t md_longopts_size = sizeof (md_longopts);
211 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
212 struct hash_control *reg_hash; /* register name hash table */
213 struct hash_control *dynreg_hash; /* dynamic register hash table */
214 struct hash_control *const_hash; /* constant hash table */
215 struct hash_control *entry_hash; /* code entry hint hash table */
217 symbolS *regsym[REG_NUM];
219 /* If X_op is != O_absent, the registername for the instruction's
220 qualifying predicate. If NULL, p0 is assumed for instructions
221 that are predicatable. */
228 explicit_mode : 1, /* which mode we're in */
229 default_explicit_mode : 1, /* which mode is the default */
230 mode_explicitly_set : 1, /* was the current mode explicitly set? */
232 keep_pending_output : 1;
234 /* What to do when something is wrong with unwind directives. */
237 unwind_check_warning,
241 /* Each bundle consists of up to three instructions. We keep
242 track of four most recent instructions so we can correctly set
243 the end_of_insn_group for the last instruction in a bundle. */
245 int num_slots_in_use;
249 end_of_insn_group : 1,
250 manual_bundling_on : 1,
251 manual_bundling_off : 1,
252 loc_directive_seen : 1;
253 signed char user_template; /* user-selected template, if any */
254 unsigned char qp_regno; /* qualifying predicate */
255 /* This duplicates a good fraction of "struct fix" but we
256 can't use a "struct fix" instead since we can't call
257 fix_new_exp() until we know the address of the instruction. */
261 bfd_reloc_code_real_type code;
262 enum ia64_opnd opnd; /* type of operand in need of fix */
263 unsigned int is_pcrel : 1; /* is operand pc-relative? */
264 expressionS expr; /* the value to be inserted */
266 fixup[2]; /* at most two fixups per insn */
267 struct ia64_opcode *idesc;
268 struct label_fix *label_fixups;
269 struct label_fix *tag_fixups;
270 struct unw_rec_list *unwind_record; /* Unwind directive. */
273 unsigned int src_line;
274 struct dwarf2_line_info debug_line;
282 struct dynreg *next; /* next dynamic register */
284 unsigned short base; /* the base register number */
285 unsigned short num_regs; /* # of registers in this set */
287 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
289 flagword flags; /* ELF-header flags */
292 unsigned hint:1; /* is this hint currently valid? */
293 bfd_vma offset; /* mem.offset offset */
294 bfd_vma base; /* mem.offset base */
297 int path; /* number of alt. entry points seen */
298 const char **entry_labels; /* labels of all alternate paths in
299 the current DV-checking block. */
300 int maxpaths; /* size currently allocated for
303 int pointer_size; /* size in bytes of a pointer */
304 int pointer_size_shift; /* shift size of a pointer for alignment */
308 /* application registers: */
314 #define AR_BSPSTORE 18
329 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
330 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
331 {"ar.rsc", 16}, {"ar.bsp", 17},
332 {"ar.bspstore", 18}, {"ar.rnat", 19},
333 {"ar.fcr", 21}, {"ar.eflag", 24},
334 {"ar.csd", 25}, {"ar.ssd", 26},
335 {"ar.cflg", 27}, {"ar.fsr", 28},
336 {"ar.fir", 29}, {"ar.fdr", 30},
337 {"ar.ccv", 32}, {"ar.unat", 36},
338 {"ar.fpsr", 40}, {"ar.itc", 44},
339 {"ar.pfs", 64}, {"ar.lc", 65},
360 /* control registers: */
402 static const struct const_desc
409 /* PSR constant masks: */
412 {"psr.be", ((valueT) 1) << 1},
413 {"psr.up", ((valueT) 1) << 2},
414 {"psr.ac", ((valueT) 1) << 3},
415 {"psr.mfl", ((valueT) 1) << 4},
416 {"psr.mfh", ((valueT) 1) << 5},
418 {"psr.ic", ((valueT) 1) << 13},
419 {"psr.i", ((valueT) 1) << 14},
420 {"psr.pk", ((valueT) 1) << 15},
422 {"psr.dt", ((valueT) 1) << 17},
423 {"psr.dfl", ((valueT) 1) << 18},
424 {"psr.dfh", ((valueT) 1) << 19},
425 {"psr.sp", ((valueT) 1) << 20},
426 {"psr.pp", ((valueT) 1) << 21},
427 {"psr.di", ((valueT) 1) << 22},
428 {"psr.si", ((valueT) 1) << 23},
429 {"psr.db", ((valueT) 1) << 24},
430 {"psr.lp", ((valueT) 1) << 25},
431 {"psr.tb", ((valueT) 1) << 26},
432 {"psr.rt", ((valueT) 1) << 27},
433 /* 28-31: reserved */
434 /* 32-33: cpl (current privilege level) */
435 {"psr.is", ((valueT) 1) << 34},
436 {"psr.mc", ((valueT) 1) << 35},
437 {"psr.it", ((valueT) 1) << 36},
438 {"psr.id", ((valueT) 1) << 37},
439 {"psr.da", ((valueT) 1) << 38},
440 {"psr.dd", ((valueT) 1) << 39},
441 {"psr.ss", ((valueT) 1) << 40},
442 /* 41-42: ri (restart instruction) */
443 {"psr.ed", ((valueT) 1) << 43},
444 {"psr.bn", ((valueT) 1) << 44},
447 /* indirect register-sets/memory: */
456 { "CPUID", IND_CPUID },
457 { "cpuid", IND_CPUID },
469 /* Pseudo functions used to indicate relocation types (these functions
470 start with an at sign (@). */
492 /* reloc pseudo functions (these must come first!): */
493 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
494 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
495 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
496 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
497 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
498 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
499 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
500 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
501 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
502 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
503 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
504 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
505 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
506 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
507 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
508 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
509 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
511 /* mbtype4 constants: */
512 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
513 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
514 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
515 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
516 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
518 /* fclass constants: */
519 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
520 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
521 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
522 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
523 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
524 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
525 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
526 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
527 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
529 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
531 /* hint constants: */
532 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
534 /* unwind-related constants: */
535 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
536 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
537 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
538 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
539 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
540 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
541 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
543 /* unwind-related registers: */
544 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
547 /* 41-bit nop opcodes (one per unit): */
548 static const bfd_vma nop[IA64_NUM_UNITS] =
550 0x0000000000LL, /* NIL => break 0 */
551 0x0008000000LL, /* I-unit nop */
552 0x0008000000LL, /* M-unit nop */
553 0x4000000000LL, /* B-unit nop */
554 0x0008000000LL, /* F-unit nop */
555 0x0008000000LL, /* L-"unit" nop */
556 0x0008000000LL, /* X-unit nop */
559 /* Can't be `const' as it's passed to input routines (which have the
560 habit of setting temporary sentinels. */
561 static char special_section_name[][20] =
563 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
564 {".IA_64.unwind"}, {".IA_64.unwind_info"},
565 {".init_array"}, {".fini_array"}
568 /* The best template for a particular sequence of up to three
570 #define N IA64_NUM_TYPES
571 static unsigned char best_template[N][N][N];
574 /* Resource dependencies currently in effect */
576 int depind; /* dependency index */
577 const struct ia64_dependency *dependency; /* actual dependency */
578 unsigned specific:1, /* is this a specific bit/regno? */
579 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
580 int index; /* specific regno/bit within dependency */
581 int note; /* optional qualifying note (0 if none) */
585 int insn_srlz; /* current insn serialization state */
586 int data_srlz; /* current data serialization state */
587 int qp_regno; /* qualifying predicate for this usage */
588 char *file; /* what file marked this dependency */
589 unsigned int line; /* what line marked this dependency */
590 struct mem_offset mem_offset; /* optional memory offset hint */
591 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
592 int path; /* corresponding code entry index */
594 static int regdepslen = 0;
595 static int regdepstotlen = 0;
596 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
597 static const char *dv_sem[] = { "none", "implied", "impliedf",
598 "data", "instr", "specific", "stop", "other" };
599 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
601 /* Current state of PR mutexation */
602 static struct qpmutex {
605 } *qp_mutexes = NULL; /* QP mutex bitmasks */
606 static int qp_mutexeslen = 0;
607 static int qp_mutexestotlen = 0;
608 static valueT qp_safe_across_calls = 0;
610 /* Current state of PR implications */
611 static struct qp_imply {
614 unsigned p2_branched:1;
616 } *qp_implies = NULL;
617 static int qp_implieslen = 0;
618 static int qp_impliestotlen = 0;
620 /* Keep track of static GR values so that indirect register usage can
621 sometimes be tracked. */
626 } gr_values[128] = {{ 1, 0, 0 }};
628 /* Remember the alignment frag. */
629 static fragS *align_frag;
631 /* These are the routines required to output the various types of
634 /* A slot_number is a frag address plus the slot index (0-2). We use the
635 frag address here so that if there is a section switch in the middle of
636 a function, then instructions emitted to a different section are not
637 counted. Since there may be more than one frag for a function, this
638 means we also need to keep track of which frag this address belongs to
639 so we can compute inter-frag distances. This also nicely solves the
640 problem with nops emitted for align directives, which can't easily be
641 counted, but can easily be derived from frag sizes. */
643 typedef struct unw_rec_list {
645 unsigned long slot_number;
647 unsigned long next_slot_number;
648 fragS *next_slot_frag;
649 struct unw_rec_list *next;
652 #define SLOT_NUM_NOT_SET (unsigned)-1
654 /* Linked list of saved prologue counts. A very poor
655 implementation of a map from label numbers to prologue counts. */
656 typedef struct label_prologue_count
658 struct label_prologue_count *next;
659 unsigned long label_number;
660 unsigned int prologue_count;
661 } label_prologue_count;
665 /* Maintain a list of unwind entries for the current function. */
669 /* Any unwind entires that should be attached to the current slot
670 that an insn is being constructed for. */
671 unw_rec_list *current_entry;
673 /* These are used to create the unwind table entry for this function. */
675 symbolS *info; /* pointer to unwind info */
676 symbolS *personality_routine;
678 subsegT saved_text_subseg;
679 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
681 /* TRUE if processing unwind directives in a prologue region. */
682 unsigned int prologue : 1;
683 unsigned int prologue_mask : 4;
684 unsigned int body : 1;
685 unsigned int insn : 1;
686 unsigned int prologue_count; /* number of .prologues seen so far */
687 /* Prologue counts at previous .label_state directives. */
688 struct label_prologue_count * saved_prologue_counts;
691 /* The input value is a negated offset from psp, and specifies an address
692 psp - offset. The encoded value is psp + 16 - (4 * offset). Thus we
693 must add 16 and divide by 4 to get the encoded value. */
695 #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4)
697 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
699 /* Forward declarations: */
700 static void set_section PARAMS ((char *name));
701 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
702 unsigned int, unsigned int));
703 static void dot_align (int);
704 static void dot_radix PARAMS ((int));
705 static void dot_special_section PARAMS ((int));
706 static void dot_proc PARAMS ((int));
707 static void dot_fframe PARAMS ((int));
708 static void dot_vframe PARAMS ((int));
709 static void dot_vframesp PARAMS ((int));
710 static void dot_vframepsp PARAMS ((int));
711 static void dot_save PARAMS ((int));
712 static void dot_restore PARAMS ((int));
713 static void dot_restorereg PARAMS ((int));
714 static void dot_restorereg_p PARAMS ((int));
715 static void dot_handlerdata PARAMS ((int));
716 static void dot_unwentry PARAMS ((int));
717 static void dot_altrp PARAMS ((int));
718 static void dot_savemem PARAMS ((int));
719 static void dot_saveg PARAMS ((int));
720 static void dot_savef PARAMS ((int));
721 static void dot_saveb PARAMS ((int));
722 static void dot_savegf PARAMS ((int));
723 static void dot_spill PARAMS ((int));
724 static void dot_spillreg PARAMS ((int));
725 static void dot_spillmem PARAMS ((int));
726 static void dot_spillreg_p PARAMS ((int));
727 static void dot_spillmem_p PARAMS ((int));
728 static void dot_label_state PARAMS ((int));
729 static void dot_copy_state PARAMS ((int));
730 static void dot_unwabi PARAMS ((int));
731 static void dot_personality PARAMS ((int));
732 static void dot_body PARAMS ((int));
733 static void dot_prologue PARAMS ((int));
734 static void dot_endp PARAMS ((int));
735 static void dot_template PARAMS ((int));
736 static void dot_regstk PARAMS ((int));
737 static void dot_rot PARAMS ((int));
738 static void dot_byteorder PARAMS ((int));
739 static void dot_psr PARAMS ((int));
740 static void dot_alias PARAMS ((int));
741 static void dot_ln PARAMS ((int));
742 static char *parse_section_name PARAMS ((void));
743 static void dot_xdata PARAMS ((int));
744 static void stmt_float_cons PARAMS ((int));
745 static void stmt_cons_ua PARAMS ((int));
746 static void dot_xfloat_cons PARAMS ((int));
747 static void dot_xstringer PARAMS ((int));
748 static void dot_xdata_ua PARAMS ((int));
749 static void dot_xfloat_cons_ua PARAMS ((int));
750 static void print_prmask PARAMS ((valueT mask));
751 static void dot_pred_rel PARAMS ((int));
752 static void dot_reg_val PARAMS ((int));
753 static void dot_serialize PARAMS ((int));
754 static void dot_dv_mode PARAMS ((int));
755 static void dot_entry PARAMS ((int));
756 static void dot_mem_offset PARAMS ((int));
757 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
758 static symbolS *declare_register PARAMS ((const char *name, int regnum));
759 static void declare_register_set PARAMS ((const char *, int, int));
760 static unsigned int operand_width PARAMS ((enum ia64_opnd));
761 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
764 static int parse_operand PARAMS ((expressionS *e));
765 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
766 static void build_insn PARAMS ((struct slot *, bfd_vma *));
767 static void emit_one_bundle PARAMS ((void));
768 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
769 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
770 bfd_reloc_code_real_type r_type));
771 static void insn_group_break PARAMS ((int, int, int));
772 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
773 struct rsrc *, int depind, int path));
774 static void add_qp_mutex PARAMS((valueT mask));
775 static void add_qp_imply PARAMS((int p1, int p2));
776 static void clear_qp_branch_flag PARAMS((valueT mask));
777 static void clear_qp_mutex PARAMS((valueT mask));
778 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
779 static int has_suffix_p PARAMS((const char *, const char *));
780 static void clear_register_values PARAMS ((void));
781 static void print_dependency PARAMS ((const char *action, int depind));
782 static void instruction_serialization PARAMS ((void));
783 static void data_serialization PARAMS ((void));
784 static void remove_marked_resource PARAMS ((struct rsrc *));
785 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
786 static int is_taken_branch PARAMS ((struct ia64_opcode *));
787 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
788 static int depends_on PARAMS ((int, struct ia64_opcode *));
789 static int specify_resource PARAMS ((const struct ia64_dependency *,
790 struct ia64_opcode *, int, struct rsrc [], int, int));
791 static int check_dv PARAMS((struct ia64_opcode *idesc));
792 static void check_dependencies PARAMS((struct ia64_opcode *));
793 static void mark_resources PARAMS((struct ia64_opcode *));
794 static void update_dependencies PARAMS((struct ia64_opcode *));
795 static void note_register_values PARAMS((struct ia64_opcode *));
796 static int qp_mutex PARAMS ((int, int, int));
797 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
798 static void output_vbyte_mem PARAMS ((int, char *, char *));
799 static void count_output PARAMS ((int, char *, char *));
800 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
801 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
802 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
803 static void output_P1_format PARAMS ((vbyte_func, int));
804 static void output_P2_format PARAMS ((vbyte_func, int, int));
805 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
806 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
807 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
808 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
809 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
810 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
811 static void output_P9_format PARAMS ((vbyte_func, int, int));
812 static void output_P10_format PARAMS ((vbyte_func, int, int));
813 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
814 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
815 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
816 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
817 static char format_ab_reg PARAMS ((int, int));
818 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
820 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
821 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
823 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
824 static unw_rec_list *output_endp PARAMS ((void));
825 static unw_rec_list *output_prologue PARAMS ((void));
826 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
827 static unw_rec_list *output_body PARAMS ((void));
828 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
829 static unw_rec_list *output_mem_stack_v PARAMS ((void));
830 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
831 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
832 static unw_rec_list *output_rp_when PARAMS ((void));
833 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
834 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
835 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
836 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
837 static unw_rec_list *output_pfs_when PARAMS ((void));
838 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
839 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
840 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
841 static unw_rec_list *output_preds_when PARAMS ((void));
842 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
843 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
844 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
845 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
846 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
847 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
848 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
849 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
850 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
851 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
852 static unw_rec_list *output_unat_when PARAMS ((void));
853 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
854 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
855 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
856 static unw_rec_list *output_lc_when PARAMS ((void));
857 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
858 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
859 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
860 static unw_rec_list *output_fpsr_when PARAMS ((void));
861 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
862 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
863 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
864 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
865 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
866 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
867 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
868 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
869 static unw_rec_list *output_bsp_when PARAMS ((void));
870 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
871 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
872 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
873 static unw_rec_list *output_bspstore_when PARAMS ((void));
874 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
875 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
876 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
877 static unw_rec_list *output_rnat_when PARAMS ((void));
878 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
879 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
880 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
881 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
882 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
883 static unw_rec_list *output_label_state PARAMS ((unsigned long));
884 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
885 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
886 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
887 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
889 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
891 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
893 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
894 unsigned int, unsigned int));
895 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
896 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
897 static int calc_record_size PARAMS ((unw_rec_list *));
898 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
899 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
900 unsigned long, fragS *,
902 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
903 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
904 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
905 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
906 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
907 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
908 static void free_saved_prologue_counts PARAMS ((void));
910 /* Determine if application register REGNUM resides only in the integer
911 unit (as opposed to the memory unit). */
913 ar_is_only_in_integer_unit (int reg)
916 return reg >= 64 && reg <= 111;
919 /* Determine if application register REGNUM resides only in the memory
920 unit (as opposed to the integer unit). */
922 ar_is_only_in_memory_unit (int reg)
925 return reg >= 0 && reg <= 47;
928 /* Switch to section NAME and create section if necessary. It's
929 rather ugly that we have to manipulate input_line_pointer but I
930 don't see any other way to accomplish the same thing without
931 changing obj-elf.c (which may be the Right Thing, in the end). */
936 char *saved_input_line_pointer;
938 saved_input_line_pointer = input_line_pointer;
939 input_line_pointer = name;
941 input_line_pointer = saved_input_line_pointer;
944 /* Map 's' to SHF_IA_64_SHORT. */
947 ia64_elf_section_letter (letter, ptr_msg)
952 return SHF_IA_64_SHORT;
953 else if (letter == 'o')
954 return SHF_LINK_ORDER;
956 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
960 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
963 ia64_elf_section_flags (flags, attr, type)
965 int attr, type ATTRIBUTE_UNUSED;
967 if (attr & SHF_IA_64_SHORT)
968 flags |= SEC_SMALL_DATA;
973 ia64_elf_section_type (str, len)
977 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
979 if (STREQ (ELF_STRING_ia64_unwind_info))
982 if (STREQ (ELF_STRING_ia64_unwind_info_once))
985 if (STREQ (ELF_STRING_ia64_unwind))
986 return SHT_IA_64_UNWIND;
988 if (STREQ (ELF_STRING_ia64_unwind_once))
989 return SHT_IA_64_UNWIND;
991 if (STREQ ("unwind"))
992 return SHT_IA_64_UNWIND;
999 set_regstack (ins, locs, outs, rots)
1000 unsigned int ins, locs, outs, rots;
1002 /* Size of frame. */
1005 sof = ins + locs + outs;
1008 as_bad ("Size of frame exceeds maximum of 96 registers");
1013 as_warn ("Size of rotating registers exceeds frame size");
1016 md.in.base = REG_GR + 32;
1017 md.loc.base = md.in.base + ins;
1018 md.out.base = md.loc.base + locs;
1020 md.in.num_regs = ins;
1021 md.loc.num_regs = locs;
1022 md.out.num_regs = outs;
1023 md.rot.num_regs = rots;
1030 struct label_fix *lfix;
1032 subsegT saved_subseg;
1035 if (!md.last_text_seg)
1038 saved_seg = now_seg;
1039 saved_subseg = now_subseg;
1041 subseg_set (md.last_text_seg, 0);
1043 while (md.num_slots_in_use > 0)
1044 emit_one_bundle (); /* force out queued instructions */
1046 /* In case there are labels following the last instruction, resolve
1048 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1050 S_SET_VALUE (lfix->sym, frag_now_fix ());
1051 symbol_set_frag (lfix->sym, frag_now);
1053 CURR_SLOT.label_fixups = 0;
1054 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1056 S_SET_VALUE (lfix->sym, frag_now_fix ());
1057 symbol_set_frag (lfix->sym, frag_now);
1059 CURR_SLOT.tag_fixups = 0;
1061 /* In case there are unwind directives following the last instruction,
1062 resolve those now. We only handle prologue, body, and endp directives
1063 here. Give an error for others. */
1064 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1066 switch (ptr->r.type)
1072 ptr->slot_number = (unsigned long) frag_more (0);
1073 ptr->slot_frag = frag_now;
1076 /* Allow any record which doesn't have a "t" field (i.e.,
1077 doesn't relate to a particular instruction). */
1093 as_bad (_("Unwind directive not followed by an instruction."));
1097 unwind.current_entry = NULL;
1099 subseg_set (saved_seg, saved_subseg);
1101 if (md.qp.X_op == O_register)
1102 as_bad ("qualifying predicate not followed by instruction");
1106 ia64_do_align (int nbytes)
1108 char *saved_input_line_pointer = input_line_pointer;
1110 input_line_pointer = "";
1111 s_align_bytes (nbytes);
1112 input_line_pointer = saved_input_line_pointer;
1116 ia64_cons_align (nbytes)
1121 char *saved_input_line_pointer = input_line_pointer;
1122 input_line_pointer = "";
1123 s_align_bytes (nbytes);
1124 input_line_pointer = saved_input_line_pointer;
1128 /* Output COUNT bytes to a memory location. */
1129 static unsigned char *vbyte_mem_ptr = NULL;
1132 output_vbyte_mem (count, ptr, comment)
1135 char *comment ATTRIBUTE_UNUSED;
1138 if (vbyte_mem_ptr == NULL)
1143 for (x = 0; x < count; x++)
1144 *(vbyte_mem_ptr++) = ptr[x];
1147 /* Count the number of bytes required for records. */
1148 static int vbyte_count = 0;
1150 count_output (count, ptr, comment)
1152 char *ptr ATTRIBUTE_UNUSED;
1153 char *comment ATTRIBUTE_UNUSED;
1155 vbyte_count += count;
1159 output_R1_format (f, rtype, rlen)
1161 unw_record_type rtype;
1168 output_R3_format (f, rtype, rlen);
1174 else if (rtype != prologue)
1175 as_bad ("record type is not valid");
1177 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1178 (*f) (1, &byte, NULL);
1182 output_R2_format (f, mask, grsave, rlen)
1189 mask = (mask & 0x0f);
1190 grsave = (grsave & 0x7f);
1192 bytes[0] = (UNW_R2 | (mask >> 1));
1193 bytes[1] = (((mask & 0x01) << 7) | grsave);
1194 count += output_leb128 (bytes + 2, rlen, 0);
1195 (*f) (count, bytes, NULL);
1199 output_R3_format (f, rtype, rlen)
1201 unw_record_type rtype;
1208 output_R1_format (f, rtype, rlen);
1214 else if (rtype != prologue)
1215 as_bad ("record type is not valid");
1216 bytes[0] = (UNW_R3 | r);
1217 count = output_leb128 (bytes + 1, rlen, 0);
1218 (*f) (count + 1, bytes, NULL);
1222 output_P1_format (f, brmask)
1227 byte = UNW_P1 | (brmask & 0x1f);
1228 (*f) (1, &byte, NULL);
1232 output_P2_format (f, brmask, gr)
1238 brmask = (brmask & 0x1f);
1239 bytes[0] = UNW_P2 | (brmask >> 1);
1240 bytes[1] = (((brmask & 1) << 7) | gr);
1241 (*f) (2, bytes, NULL);
1245 output_P3_format (f, rtype, reg)
1247 unw_record_type rtype;
1292 as_bad ("Invalid record type for P3 format.");
1294 bytes[0] = (UNW_P3 | (r >> 1));
1295 bytes[1] = (((r & 1) << 7) | reg);
1296 (*f) (2, bytes, NULL);
1300 output_P4_format (f, imask, imask_size)
1302 unsigned char *imask;
1303 unsigned long imask_size;
1306 (*f) (imask_size, imask, NULL);
1310 output_P5_format (f, grmask, frmask)
1313 unsigned long frmask;
1316 grmask = (grmask & 0x0f);
1319 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1320 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1321 bytes[3] = (frmask & 0x000000ff);
1322 (*f) (4, bytes, NULL);
1326 output_P6_format (f, rtype, rmask)
1328 unw_record_type rtype;
1334 if (rtype == gr_mem)
1336 else if (rtype != fr_mem)
1337 as_bad ("Invalid record type for format P6");
1338 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1339 (*f) (1, &byte, NULL);
1343 output_P7_format (f, rtype, w1, w2)
1345 unw_record_type rtype;
1352 count += output_leb128 (bytes + 1, w1, 0);
1357 count += output_leb128 (bytes + count, w2 >> 4, 0);
1407 bytes[0] = (UNW_P7 | r);
1408 (*f) (count, bytes, NULL);
1412 output_P8_format (f, rtype, t)
1414 unw_record_type rtype;
1453 case bspstore_psprel:
1456 case bspstore_sprel:
1468 case priunat_when_gr:
1471 case priunat_psprel:
1477 case priunat_when_mem:
1484 count += output_leb128 (bytes + 2, t, 0);
1485 (*f) (count, bytes, NULL);
1489 output_P9_format (f, grmask, gr)
1496 bytes[1] = (grmask & 0x0f);
1497 bytes[2] = (gr & 0x7f);
1498 (*f) (3, bytes, NULL);
1502 output_P10_format (f, abi, context)
1509 bytes[1] = (abi & 0xff);
1510 bytes[2] = (context & 0xff);
1511 (*f) (3, bytes, NULL);
1515 output_B1_format (f, rtype, label)
1517 unw_record_type rtype;
1518 unsigned long label;
1524 output_B4_format (f, rtype, label);
1527 if (rtype == copy_state)
1529 else if (rtype != label_state)
1530 as_bad ("Invalid record type for format B1");
1532 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1533 (*f) (1, &byte, NULL);
1537 output_B2_format (f, ecount, t)
1539 unsigned long ecount;
1546 output_B3_format (f, ecount, t);
1549 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1550 count += output_leb128 (bytes + 1, t, 0);
1551 (*f) (count, bytes, NULL);
1555 output_B3_format (f, ecount, t)
1557 unsigned long ecount;
1564 output_B2_format (f, ecount, t);
1568 count += output_leb128 (bytes + 1, t, 0);
1569 count += output_leb128 (bytes + count, ecount, 0);
1570 (*f) (count, bytes, NULL);
1574 output_B4_format (f, rtype, label)
1576 unw_record_type rtype;
1577 unsigned long label;
1584 output_B1_format (f, rtype, label);
1588 if (rtype == copy_state)
1590 else if (rtype != label_state)
1591 as_bad ("Invalid record type for format B1");
1593 bytes[0] = (UNW_B4 | (r << 3));
1594 count += output_leb128 (bytes + 1, label, 0);
1595 (*f) (count, bytes, NULL);
1599 format_ab_reg (ab, reg)
1606 ret = (ab << 5) | reg;
1611 output_X1_format (f, rtype, ab, reg, t, w1)
1613 unw_record_type rtype;
1623 if (rtype == spill_sprel)
1625 else if (rtype != spill_psprel)
1626 as_bad ("Invalid record type for format X1");
1627 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1628 count += output_leb128 (bytes + 2, t, 0);
1629 count += output_leb128 (bytes + count, w1, 0);
1630 (*f) (count, bytes, NULL);
1634 output_X2_format (f, ab, reg, x, y, treg, t)
1643 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1644 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1645 count += output_leb128 (bytes + 3, t, 0);
1646 (*f) (count, bytes, NULL);
1650 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1652 unw_record_type rtype;
1663 if (rtype == spill_sprel_p)
1665 else if (rtype != spill_psprel_p)
1666 as_bad ("Invalid record type for format X3");
1667 bytes[1] = ((r << 7) | (qp & 0x3f));
1668 bytes[2] = format_ab_reg (ab, reg);
1669 count += output_leb128 (bytes + 3, t, 0);
1670 count += output_leb128 (bytes + count, w1, 0);
1671 (*f) (count, bytes, NULL);
1675 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1685 bytes[1] = (qp & 0x3f);
1686 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1687 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1688 count += output_leb128 (bytes + 4, t, 0);
1689 (*f) (count, bytes, NULL);
1692 /* This function allocates a record list structure, and initializes fields. */
1694 static unw_rec_list *
1695 alloc_record (unw_record_type t)
1698 ptr = xmalloc (sizeof (*ptr));
1700 ptr->slot_number = SLOT_NUM_NOT_SET;
1702 ptr->next_slot_number = 0;
1703 ptr->next_slot_frag = 0;
1707 /* Dummy unwind record used for calculating the length of the last prologue or
1710 static unw_rec_list *
1713 unw_rec_list *ptr = alloc_record (endp);
1717 static unw_rec_list *
1720 unw_rec_list *ptr = alloc_record (prologue);
1721 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1725 static unw_rec_list *
1726 output_prologue_gr (saved_mask, reg)
1727 unsigned int saved_mask;
1730 unw_rec_list *ptr = alloc_record (prologue_gr);
1731 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1732 ptr->r.record.r.grmask = saved_mask;
1733 ptr->r.record.r.grsave = reg;
1737 static unw_rec_list *
1740 unw_rec_list *ptr = alloc_record (body);
1744 static unw_rec_list *
1745 output_mem_stack_f (size)
1748 unw_rec_list *ptr = alloc_record (mem_stack_f);
1749 ptr->r.record.p.size = size;
1753 static unw_rec_list *
1754 output_mem_stack_v ()
1756 unw_rec_list *ptr = alloc_record (mem_stack_v);
1760 static unw_rec_list *
1764 unw_rec_list *ptr = alloc_record (psp_gr);
1765 ptr->r.record.p.gr = gr;
1769 static unw_rec_list *
1770 output_psp_sprel (offset)
1771 unsigned int offset;
1773 unw_rec_list *ptr = alloc_record (psp_sprel);
1774 ptr->r.record.p.spoff = offset / 4;
1778 static unw_rec_list *
1781 unw_rec_list *ptr = alloc_record (rp_when);
1785 static unw_rec_list *
1789 unw_rec_list *ptr = alloc_record (rp_gr);
1790 ptr->r.record.p.gr = gr;
1794 static unw_rec_list *
1798 unw_rec_list *ptr = alloc_record (rp_br);
1799 ptr->r.record.p.br = br;
1803 static unw_rec_list *
1804 output_rp_psprel (offset)
1805 unsigned int offset;
1807 unw_rec_list *ptr = alloc_record (rp_psprel);
1808 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1812 static unw_rec_list *
1813 output_rp_sprel (offset)
1814 unsigned int offset;
1816 unw_rec_list *ptr = alloc_record (rp_sprel);
1817 ptr->r.record.p.spoff = offset / 4;
1821 static unw_rec_list *
1824 unw_rec_list *ptr = alloc_record (pfs_when);
1828 static unw_rec_list *
1832 unw_rec_list *ptr = alloc_record (pfs_gr);
1833 ptr->r.record.p.gr = gr;
1837 static unw_rec_list *
1838 output_pfs_psprel (offset)
1839 unsigned int offset;
1841 unw_rec_list *ptr = alloc_record (pfs_psprel);
1842 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1846 static unw_rec_list *
1847 output_pfs_sprel (offset)
1848 unsigned int offset;
1850 unw_rec_list *ptr = alloc_record (pfs_sprel);
1851 ptr->r.record.p.spoff = offset / 4;
1855 static unw_rec_list *
1856 output_preds_when ()
1858 unw_rec_list *ptr = alloc_record (preds_when);
1862 static unw_rec_list *
1863 output_preds_gr (gr)
1866 unw_rec_list *ptr = alloc_record (preds_gr);
1867 ptr->r.record.p.gr = gr;
1871 static unw_rec_list *
1872 output_preds_psprel (offset)
1873 unsigned int offset;
1875 unw_rec_list *ptr = alloc_record (preds_psprel);
1876 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1880 static unw_rec_list *
1881 output_preds_sprel (offset)
1882 unsigned int offset;
1884 unw_rec_list *ptr = alloc_record (preds_sprel);
1885 ptr->r.record.p.spoff = offset / 4;
1889 static unw_rec_list *
1890 output_fr_mem (mask)
1893 unw_rec_list *ptr = alloc_record (fr_mem);
1894 ptr->r.record.p.rmask = mask;
1898 static unw_rec_list *
1899 output_frgr_mem (gr_mask, fr_mask)
1900 unsigned int gr_mask;
1901 unsigned int fr_mask;
1903 unw_rec_list *ptr = alloc_record (frgr_mem);
1904 ptr->r.record.p.grmask = gr_mask;
1905 ptr->r.record.p.frmask = fr_mask;
1909 static unw_rec_list *
1910 output_gr_gr (mask, reg)
1914 unw_rec_list *ptr = alloc_record (gr_gr);
1915 ptr->r.record.p.grmask = mask;
1916 ptr->r.record.p.gr = reg;
1920 static unw_rec_list *
1921 output_gr_mem (mask)
1924 unw_rec_list *ptr = alloc_record (gr_mem);
1925 ptr->r.record.p.rmask = mask;
1929 static unw_rec_list *
1930 output_br_mem (unsigned int mask)
1932 unw_rec_list *ptr = alloc_record (br_mem);
1933 ptr->r.record.p.brmask = mask;
1937 static unw_rec_list *
1938 output_br_gr (save_mask, reg)
1939 unsigned int save_mask;
1942 unw_rec_list *ptr = alloc_record (br_gr);
1943 ptr->r.record.p.brmask = save_mask;
1944 ptr->r.record.p.gr = reg;
1948 static unw_rec_list *
1949 output_spill_base (offset)
1950 unsigned int offset;
1952 unw_rec_list *ptr = alloc_record (spill_base);
1953 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1957 static unw_rec_list *
1960 unw_rec_list *ptr = alloc_record (unat_when);
1964 static unw_rec_list *
1968 unw_rec_list *ptr = alloc_record (unat_gr);
1969 ptr->r.record.p.gr = gr;
1973 static unw_rec_list *
1974 output_unat_psprel (offset)
1975 unsigned int offset;
1977 unw_rec_list *ptr = alloc_record (unat_psprel);
1978 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1982 static unw_rec_list *
1983 output_unat_sprel (offset)
1984 unsigned int offset;
1986 unw_rec_list *ptr = alloc_record (unat_sprel);
1987 ptr->r.record.p.spoff = offset / 4;
1991 static unw_rec_list *
1994 unw_rec_list *ptr = alloc_record (lc_when);
1998 static unw_rec_list *
2002 unw_rec_list *ptr = alloc_record (lc_gr);
2003 ptr->r.record.p.gr = gr;
2007 static unw_rec_list *
2008 output_lc_psprel (offset)
2009 unsigned int offset;
2011 unw_rec_list *ptr = alloc_record (lc_psprel);
2012 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2016 static unw_rec_list *
2017 output_lc_sprel (offset)
2018 unsigned int offset;
2020 unw_rec_list *ptr = alloc_record (lc_sprel);
2021 ptr->r.record.p.spoff = offset / 4;
2025 static unw_rec_list *
2028 unw_rec_list *ptr = alloc_record (fpsr_when);
2032 static unw_rec_list *
2036 unw_rec_list *ptr = alloc_record (fpsr_gr);
2037 ptr->r.record.p.gr = gr;
2041 static unw_rec_list *
2042 output_fpsr_psprel (offset)
2043 unsigned int offset;
2045 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2046 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2050 static unw_rec_list *
2051 output_fpsr_sprel (offset)
2052 unsigned int offset;
2054 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2055 ptr->r.record.p.spoff = offset / 4;
2059 static unw_rec_list *
2060 output_priunat_when_gr ()
2062 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2066 static unw_rec_list *
2067 output_priunat_when_mem ()
2069 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2073 static unw_rec_list *
2074 output_priunat_gr (gr)
2077 unw_rec_list *ptr = alloc_record (priunat_gr);
2078 ptr->r.record.p.gr = gr;
2082 static unw_rec_list *
2083 output_priunat_psprel (offset)
2084 unsigned int offset;
2086 unw_rec_list *ptr = alloc_record (priunat_psprel);
2087 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2091 static unw_rec_list *
2092 output_priunat_sprel (offset)
2093 unsigned int offset;
2095 unw_rec_list *ptr = alloc_record (priunat_sprel);
2096 ptr->r.record.p.spoff = offset / 4;
2100 static unw_rec_list *
2103 unw_rec_list *ptr = alloc_record (bsp_when);
2107 static unw_rec_list *
2111 unw_rec_list *ptr = alloc_record (bsp_gr);
2112 ptr->r.record.p.gr = gr;
2116 static unw_rec_list *
2117 output_bsp_psprel (offset)
2118 unsigned int offset;
2120 unw_rec_list *ptr = alloc_record (bsp_psprel);
2121 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2125 static unw_rec_list *
2126 output_bsp_sprel (offset)
2127 unsigned int offset;
2129 unw_rec_list *ptr = alloc_record (bsp_sprel);
2130 ptr->r.record.p.spoff = offset / 4;
2134 static unw_rec_list *
2135 output_bspstore_when ()
2137 unw_rec_list *ptr = alloc_record (bspstore_when);
2141 static unw_rec_list *
2142 output_bspstore_gr (gr)
2145 unw_rec_list *ptr = alloc_record (bspstore_gr);
2146 ptr->r.record.p.gr = gr;
2150 static unw_rec_list *
2151 output_bspstore_psprel (offset)
2152 unsigned int offset;
2154 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2155 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2159 static unw_rec_list *
2160 output_bspstore_sprel (offset)
2161 unsigned int offset;
2163 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2164 ptr->r.record.p.spoff = offset / 4;
2168 static unw_rec_list *
2171 unw_rec_list *ptr = alloc_record (rnat_when);
2175 static unw_rec_list *
2179 unw_rec_list *ptr = alloc_record (rnat_gr);
2180 ptr->r.record.p.gr = gr;
2184 static unw_rec_list *
2185 output_rnat_psprel (offset)
2186 unsigned int offset;
2188 unw_rec_list *ptr = alloc_record (rnat_psprel);
2189 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2193 static unw_rec_list *
2194 output_rnat_sprel (offset)
2195 unsigned int offset;
2197 unw_rec_list *ptr = alloc_record (rnat_sprel);
2198 ptr->r.record.p.spoff = offset / 4;
2202 static unw_rec_list *
2203 output_unwabi (abi, context)
2205 unsigned long context;
2207 unw_rec_list *ptr = alloc_record (unwabi);
2208 ptr->r.record.p.abi = abi;
2209 ptr->r.record.p.context = context;
2213 static unw_rec_list *
2214 output_epilogue (unsigned long ecount)
2216 unw_rec_list *ptr = alloc_record (epilogue);
2217 ptr->r.record.b.ecount = ecount;
2221 static unw_rec_list *
2222 output_label_state (unsigned long label)
2224 unw_rec_list *ptr = alloc_record (label_state);
2225 ptr->r.record.b.label = label;
2229 static unw_rec_list *
2230 output_copy_state (unsigned long label)
2232 unw_rec_list *ptr = alloc_record (copy_state);
2233 ptr->r.record.b.label = label;
2237 static unw_rec_list *
2238 output_spill_psprel (ab, reg, offset)
2241 unsigned int offset;
2243 unw_rec_list *ptr = alloc_record (spill_psprel);
2244 ptr->r.record.x.ab = ab;
2245 ptr->r.record.x.reg = reg;
2246 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2250 static unw_rec_list *
2251 output_spill_sprel (ab, reg, offset)
2254 unsigned int offset;
2256 unw_rec_list *ptr = alloc_record (spill_sprel);
2257 ptr->r.record.x.ab = ab;
2258 ptr->r.record.x.reg = reg;
2259 ptr->r.record.x.spoff = offset / 4;
2263 static unw_rec_list *
2264 output_spill_psprel_p (ab, reg, offset, predicate)
2267 unsigned int offset;
2268 unsigned int predicate;
2270 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2271 ptr->r.record.x.ab = ab;
2272 ptr->r.record.x.reg = reg;
2273 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2274 ptr->r.record.x.qp = predicate;
2278 static unw_rec_list *
2279 output_spill_sprel_p (ab, reg, offset, predicate)
2282 unsigned int offset;
2283 unsigned int predicate;
2285 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2286 ptr->r.record.x.ab = ab;
2287 ptr->r.record.x.reg = reg;
2288 ptr->r.record.x.spoff = offset / 4;
2289 ptr->r.record.x.qp = predicate;
2293 static unw_rec_list *
2294 output_spill_reg (ab, reg, targ_reg, xy)
2297 unsigned int targ_reg;
2300 unw_rec_list *ptr = alloc_record (spill_reg);
2301 ptr->r.record.x.ab = ab;
2302 ptr->r.record.x.reg = reg;
2303 ptr->r.record.x.treg = targ_reg;
2304 ptr->r.record.x.xy = xy;
2308 static unw_rec_list *
2309 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2312 unsigned int targ_reg;
2314 unsigned int predicate;
2316 unw_rec_list *ptr = alloc_record (spill_reg_p);
2317 ptr->r.record.x.ab = ab;
2318 ptr->r.record.x.reg = reg;
2319 ptr->r.record.x.treg = targ_reg;
2320 ptr->r.record.x.xy = xy;
2321 ptr->r.record.x.qp = predicate;
2325 /* Given a unw_rec_list process the correct format with the
2326 specified function. */
2329 process_one_record (ptr, f)
2333 unsigned long fr_mask, gr_mask;
2335 switch (ptr->r.type)
2337 /* This is a dummy record that takes up no space in the output. */
2345 /* These are taken care of by prologue/prologue_gr. */
2350 if (ptr->r.type == prologue_gr)
2351 output_R2_format (f, ptr->r.record.r.grmask,
2352 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2354 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2356 /* Output descriptor(s) for union of register spills (if any). */
2357 gr_mask = ptr->r.record.r.mask.gr_mem;
2358 fr_mask = ptr->r.record.r.mask.fr_mem;
2361 if ((fr_mask & ~0xfUL) == 0)
2362 output_P6_format (f, fr_mem, fr_mask);
2365 output_P5_format (f, gr_mask, fr_mask);
2370 output_P6_format (f, gr_mem, gr_mask);
2371 if (ptr->r.record.r.mask.br_mem)
2372 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2374 /* output imask descriptor if necessary: */
2375 if (ptr->r.record.r.mask.i)
2376 output_P4_format (f, ptr->r.record.r.mask.i,
2377 ptr->r.record.r.imask_size);
2381 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2385 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2386 ptr->r.record.p.size);
2399 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2402 output_P3_format (f, rp_br, ptr->r.record.p.br);
2405 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2413 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2422 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2432 case bspstore_sprel:
2434 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2437 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2440 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2443 as_bad ("spill_mask record unimplemented.");
2445 case priunat_when_gr:
2446 case priunat_when_mem:
2450 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2452 case priunat_psprel:
2454 case bspstore_psprel:
2456 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2459 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2462 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2466 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2469 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2470 ptr->r.record.x.reg, ptr->r.record.x.t,
2471 ptr->r.record.x.pspoff);
2474 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2475 ptr->r.record.x.reg, ptr->r.record.x.t,
2476 ptr->r.record.x.spoff);
2479 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2480 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2481 ptr->r.record.x.treg, ptr->r.record.x.t);
2483 case spill_psprel_p:
2484 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2485 ptr->r.record.x.ab, ptr->r.record.x.reg,
2486 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2489 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2490 ptr->r.record.x.ab, ptr->r.record.x.reg,
2491 ptr->r.record.x.t, ptr->r.record.x.spoff);
2494 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2495 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2496 ptr->r.record.x.xy, ptr->r.record.x.treg,
2500 as_bad ("record_type_not_valid");
2505 /* Given a unw_rec_list list, process all the records with
2506 the specified function. */
2508 process_unw_records (list, f)
2513 for (ptr = list; ptr; ptr = ptr->next)
2514 process_one_record (ptr, f);
2517 /* Determine the size of a record list in bytes. */
2519 calc_record_size (list)
2523 process_unw_records (list, count_output);
2527 /* Update IMASK bitmask to reflect the fact that one or more registers
2528 of type TYPE are saved starting at instruction with index T. If N
2529 bits are set in REGMASK, it is assumed that instructions T through
2530 T+N-1 save these registers.
2534 1: instruction saves next fp reg
2535 2: instruction saves next general reg
2536 3: instruction saves next branch reg */
2538 set_imask (region, regmask, t, type)
2539 unw_rec_list *region;
2540 unsigned long regmask;
2544 unsigned char *imask;
2545 unsigned long imask_size;
2549 imask = region->r.record.r.mask.i;
2550 imask_size = region->r.record.r.imask_size;
2553 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2554 imask = xmalloc (imask_size);
2555 memset (imask, 0, imask_size);
2557 region->r.record.r.imask_size = imask_size;
2558 region->r.record.r.mask.i = imask;
2562 pos = 2 * (3 - t % 4);
2565 if (i >= imask_size)
2567 as_bad ("Ignoring attempt to spill beyond end of region");
2571 imask[i] |= (type & 0x3) << pos;
2573 regmask &= (regmask - 1);
2583 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2584 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2585 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2589 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2590 unsigned long slot_addr;
2592 unsigned long first_addr;
2596 unsigned long index = 0;
2598 /* First time we are called, the initial address and frag are invalid. */
2599 if (first_addr == 0)
2602 /* If the two addresses are in different frags, then we need to add in
2603 the remaining size of this frag, and then the entire size of intermediate
2605 while (slot_frag != first_frag)
2607 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2611 /* We can get the final addresses only during and after
2613 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2614 index += 3 * ((first_frag->fr_next->fr_address
2615 - first_frag->fr_address
2616 - first_frag->fr_fix) >> 4);
2619 /* We don't know what the final addresses will be. We try our
2620 best to estimate. */
2621 switch (first_frag->fr_type)
2627 as_fatal ("only constant space allocation is supported");
2633 /* Take alignment into account. Assume the worst case
2634 before relaxation. */
2635 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2639 if (first_frag->fr_symbol)
2641 as_fatal ("only constant offsets are supported");
2645 index += 3 * (first_frag->fr_offset >> 4);
2649 /* Add in the full size of the frag converted to instruction slots. */
2650 index += 3 * (first_frag->fr_fix >> 4);
2651 /* Subtract away the initial part before first_addr. */
2652 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2653 + ((first_addr & 0x3) - (start_addr & 0x3)));
2655 /* Move to the beginning of the next frag. */
2656 first_frag = first_frag->fr_next;
2657 first_addr = (unsigned long) &first_frag->fr_literal;
2660 /* Add in the used part of the last frag. */
2661 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2662 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2666 /* Optimize unwind record directives. */
2668 static unw_rec_list *
2669 optimize_unw_records (list)
2675 /* If the only unwind record is ".prologue" or ".prologue" followed
2676 by ".body", then we can optimize the unwind directives away. */
2677 if (list->r.type == prologue
2678 && (list->next->r.type == endp
2679 || (list->next->r.type == body && list->next->next->r.type == endp)))
2685 /* Given a complete record list, process any records which have
2686 unresolved fields, (ie length counts for a prologue). After
2687 this has been run, all necessary information should be available
2688 within each record to generate an image. */
2691 fixup_unw_records (list, before_relax)
2695 unw_rec_list *ptr, *region = 0;
2696 unsigned long first_addr = 0, rlen = 0, t;
2697 fragS *first_frag = 0;
2699 for (ptr = list; ptr; ptr = ptr->next)
2701 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2702 as_bad (" Insn slot not set in unwind record.");
2703 t = slot_index (ptr->slot_number, ptr->slot_frag,
2704 first_addr, first_frag, before_relax);
2705 switch (ptr->r.type)
2713 unsigned long last_addr = 0;
2714 fragS *last_frag = NULL;
2716 first_addr = ptr->slot_number;
2717 first_frag = ptr->slot_frag;
2718 /* Find either the next body/prologue start, or the end of
2719 the function, and determine the size of the region. */
2720 for (last = ptr->next; last != NULL; last = last->next)
2721 if (last->r.type == prologue || last->r.type == prologue_gr
2722 || last->r.type == body || last->r.type == endp)
2724 last_addr = last->slot_number;
2725 last_frag = last->slot_frag;
2728 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2730 rlen = ptr->r.record.r.rlen = size;
2731 if (ptr->r.type == body)
2732 /* End of region. */
2740 ptr->r.record.b.t = rlen - 1 - t;
2742 /* This happens when a memory-stack-less procedure uses a
2743 ".restore sp" directive at the end of a region to pop
2745 ptr->r.record.b.t = 0;
2756 case priunat_when_gr:
2757 case priunat_when_mem:
2761 ptr->r.record.p.t = t;
2769 case spill_psprel_p:
2770 ptr->r.record.x.t = t;
2776 as_bad ("frgr_mem record before region record!");
2779 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2780 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2781 set_imask (region, ptr->r.record.p.frmask, t, 1);
2782 set_imask (region, ptr->r.record.p.grmask, t, 2);
2787 as_bad ("fr_mem record before region record!");
2790 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2791 set_imask (region, ptr->r.record.p.rmask, t, 1);
2796 as_bad ("gr_mem record before region record!");
2799 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2800 set_imask (region, ptr->r.record.p.rmask, t, 2);
2805 as_bad ("br_mem record before region record!");
2808 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2809 set_imask (region, ptr->r.record.p.brmask, t, 3);
2815 as_bad ("gr_gr record before region record!");
2818 set_imask (region, ptr->r.record.p.grmask, t, 2);
2823 as_bad ("br_gr record before region record!");
2826 set_imask (region, ptr->r.record.p.brmask, t, 3);
2835 /* Estimate the size of a frag before relaxing. We only have one type of frag
2836 to handle here, which is the unwind info frag. */
2839 ia64_estimate_size_before_relax (fragS *frag,
2840 asection *segtype ATTRIBUTE_UNUSED)
2845 /* ??? This code is identical to the first part of ia64_convert_frag. */
2846 list = (unw_rec_list *) frag->fr_opcode;
2847 fixup_unw_records (list, 0);
2849 len = calc_record_size (list);
2850 /* pad to pointer-size boundary. */
2851 pad = len % md.pointer_size;
2853 len += md.pointer_size - pad;
2854 /* Add 8 for the header. */
2856 /* Add a pointer for the personality offset. */
2857 if (frag->fr_offset)
2858 size += md.pointer_size;
2860 /* fr_var carries the max_chars that we created the fragment with.
2861 We must, of course, have allocated enough memory earlier. */
2862 assert (frag->fr_var >= size);
2864 return frag->fr_fix + size;
2867 /* This function converts a rs_machine_dependent variant frag into a
2868 normal fill frag with the unwind image from the the record list. */
2870 ia64_convert_frag (fragS *frag)
2876 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2877 list = (unw_rec_list *) frag->fr_opcode;
2878 fixup_unw_records (list, 0);
2880 len = calc_record_size (list);
2881 /* pad to pointer-size boundary. */
2882 pad = len % md.pointer_size;
2884 len += md.pointer_size - pad;
2885 /* Add 8 for the header. */
2887 /* Add a pointer for the personality offset. */
2888 if (frag->fr_offset)
2889 size += md.pointer_size;
2891 /* fr_var carries the max_chars that we created the fragment with.
2892 We must, of course, have allocated enough memory earlier. */
2893 assert (frag->fr_var >= size);
2895 /* Initialize the header area. fr_offset is initialized with
2896 unwind.personality_routine. */
2897 if (frag->fr_offset)
2899 if (md.flags & EF_IA_64_ABI64)
2900 flag_value = (bfd_vma) 3 << 32;
2902 /* 32-bit unwind info block. */
2903 flag_value = (bfd_vma) 0x1003 << 32;
2908 md_number_to_chars (frag->fr_literal,
2909 (((bfd_vma) 1 << 48) /* Version. */
2910 | flag_value /* U & E handler flags. */
2911 | (len / md.pointer_size)), /* Length. */
2914 /* Skip the header. */
2915 vbyte_mem_ptr = frag->fr_literal + 8;
2916 process_unw_records (list, output_vbyte_mem);
2918 /* Fill the padding bytes with zeros. */
2920 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2921 md.pointer_size - pad);
2923 frag->fr_fix += size;
2924 frag->fr_type = rs_fill;
2926 frag->fr_offset = 0;
2930 convert_expr_to_ab_reg (e, ab, regp)
2937 if (e->X_op != O_register)
2940 reg = e->X_add_number;
2941 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2944 *regp = reg - REG_GR;
2946 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2947 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2950 *regp = reg - REG_FR;
2952 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2955 *regp = reg - REG_BR;
2962 case REG_PR: *regp = 0; break;
2963 case REG_PSP: *regp = 1; break;
2964 case REG_PRIUNAT: *regp = 2; break;
2965 case REG_BR + 0: *regp = 3; break;
2966 case REG_AR + AR_BSP: *regp = 4; break;
2967 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2968 case REG_AR + AR_RNAT: *regp = 6; break;
2969 case REG_AR + AR_UNAT: *regp = 7; break;
2970 case REG_AR + AR_FPSR: *regp = 8; break;
2971 case REG_AR + AR_PFS: *regp = 9; break;
2972 case REG_AR + AR_LC: *regp = 10; break;
2982 convert_expr_to_xy_reg (e, xy, regp)
2989 if (e->X_op != O_register)
2992 reg = e->X_add_number;
2994 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2997 *regp = reg - REG_GR;
2999 else if (reg >= REG_FR && reg <= (REG_FR + 127))
3002 *regp = reg - REG_FR;
3004 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3007 *regp = reg - REG_BR;
3017 /* The current frag is an alignment frag. */
3018 align_frag = frag_now;
3019 s_align_bytes (arg);
3024 int dummy ATTRIBUTE_UNUSED;
3029 radix = *input_line_pointer++;
3031 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3033 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3034 ignore_rest_of_line ();
3039 /* Helper function for .loc directives. If the assembler is not generating
3040 line number info, then we need to remember which instructions have a .loc
3041 directive, and only call dwarf2_gen_line_info for those instructions. */
3046 CURR_SLOT.loc_directive_seen = 1;
3047 dwarf2_directive_loc (x);
3050 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3052 dot_special_section (which)
3055 set_section ((char *) special_section_name[which]);
3059 unwind_diagnostic (const char * region, const char *directive)
3061 if (md.unwind_check == unwind_check_warning)
3062 as_warn (".%s outside of %s", directive, region);
3065 as_bad (".%s outside of %s", directive, region);
3066 ignore_rest_of_line ();
3071 in_procedure (const char *directive)
3073 if (unwind.proc_start
3074 && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0))
3076 unwind_diagnostic ("procedure", directive);
3081 in_prologue (const char *directive)
3083 if (in_procedure (directive))
3085 /* We are in a procedure. Check if we are in a prologue. */
3086 if (unwind.prologue)
3088 unwind_diagnostic ("prologue", directive);
3094 in_body (const char *directive)
3096 if (in_procedure (directive))
3098 /* We are in a procedure. Check if we are in a body. */
3101 unwind_diagnostic ("body region", directive);
3107 add_unwind_entry (ptr)
3111 unwind.tail->next = ptr;
3116 /* The current entry can in fact be a chain of unwind entries. */
3117 if (unwind.current_entry == NULL)
3118 unwind.current_entry = ptr;
3123 int dummy ATTRIBUTE_UNUSED;
3127 if (!in_prologue ("fframe"))
3132 if (e.X_op != O_constant)
3133 as_bad ("Operand to .fframe must be a constant");
3135 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3140 int dummy ATTRIBUTE_UNUSED;
3145 if (!in_prologue ("vframe"))
3149 reg = e.X_add_number - REG_GR;
3150 if (e.X_op == O_register && reg < 128)
3152 add_unwind_entry (output_mem_stack_v ());
3153 if (! (unwind.prologue_mask & 2))
3154 add_unwind_entry (output_psp_gr (reg));
3157 as_bad ("First operand to .vframe must be a general register");
3161 dot_vframesp (dummy)
3162 int dummy ATTRIBUTE_UNUSED;
3166 if (!in_prologue ("vframesp"))
3170 if (e.X_op == O_constant)
3172 add_unwind_entry (output_mem_stack_v ());
3173 add_unwind_entry (output_psp_sprel (e.X_add_number));
3176 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3180 dot_vframepsp (dummy)
3181 int dummy ATTRIBUTE_UNUSED;
3185 if (!in_prologue ("vframepsp"))
3189 if (e.X_op == O_constant)
3191 add_unwind_entry (output_mem_stack_v ());
3192 add_unwind_entry (output_psp_sprel (e.X_add_number));
3195 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3200 int dummy ATTRIBUTE_UNUSED;
3206 if (!in_prologue ("save"))
3209 sep = parse_operand (&e1);
3211 as_bad ("No second operand to .save");
3212 sep = parse_operand (&e2);
3214 reg1 = e1.X_add_number;
3215 reg2 = e2.X_add_number - REG_GR;
3217 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3218 if (e1.X_op == O_register)
3220 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3224 case REG_AR + AR_BSP:
3225 add_unwind_entry (output_bsp_when ());
3226 add_unwind_entry (output_bsp_gr (reg2));
3228 case REG_AR + AR_BSPSTORE:
3229 add_unwind_entry (output_bspstore_when ());
3230 add_unwind_entry (output_bspstore_gr (reg2));
3232 case REG_AR + AR_RNAT:
3233 add_unwind_entry (output_rnat_when ());
3234 add_unwind_entry (output_rnat_gr (reg2));
3236 case REG_AR + AR_UNAT:
3237 add_unwind_entry (output_unat_when ());
3238 add_unwind_entry (output_unat_gr (reg2));
3240 case REG_AR + AR_FPSR:
3241 add_unwind_entry (output_fpsr_when ());
3242 add_unwind_entry (output_fpsr_gr (reg2));
3244 case REG_AR + AR_PFS:
3245 add_unwind_entry (output_pfs_when ());
3246 if (! (unwind.prologue_mask & 4))
3247 add_unwind_entry (output_pfs_gr (reg2));
3249 case REG_AR + AR_LC:
3250 add_unwind_entry (output_lc_when ());
3251 add_unwind_entry (output_lc_gr (reg2));
3254 add_unwind_entry (output_rp_when ());
3255 if (! (unwind.prologue_mask & 8))
3256 add_unwind_entry (output_rp_gr (reg2));
3259 add_unwind_entry (output_preds_when ());
3260 if (! (unwind.prologue_mask & 1))
3261 add_unwind_entry (output_preds_gr (reg2));
3264 add_unwind_entry (output_priunat_when_gr ());
3265 add_unwind_entry (output_priunat_gr (reg2));
3268 as_bad ("First operand not a valid register");
3272 as_bad (" Second operand not a valid register");
3275 as_bad ("First operand not a register");
3280 int dummy ATTRIBUTE_UNUSED;
3283 unsigned long ecount; /* # of _additional_ regions to pop */
3286 if (!in_body ("restore"))
3289 sep = parse_operand (&e1);
3290 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3292 as_bad ("First operand to .restore must be stack pointer (sp)");
3298 parse_operand (&e2);
3299 if (e2.X_op != O_constant || e2.X_add_number < 0)
3301 as_bad ("Second operand to .restore must be a constant >= 0");
3304 ecount = e2.X_add_number;
3307 ecount = unwind.prologue_count - 1;
3309 if (ecount >= unwind.prologue_count)
3311 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3312 ecount + 1, unwind.prologue_count);
3316 add_unwind_entry (output_epilogue (ecount));
3318 if (ecount < unwind.prologue_count)
3319 unwind.prologue_count -= ecount + 1;
3321 unwind.prologue_count = 0;
3325 dot_restorereg (dummy)
3326 int dummy ATTRIBUTE_UNUSED;
3328 unsigned int ab, reg;
3331 if (!in_procedure ("restorereg"))
3336 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3338 as_bad ("First operand to .restorereg must be a preserved register");
3341 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3345 dot_restorereg_p (dummy)
3346 int dummy ATTRIBUTE_UNUSED;
3348 unsigned int qp, ab, reg;
3352 if (!in_procedure ("restorereg.p"))
3355 sep = parse_operand (&e1);
3358 as_bad ("No second operand to .restorereg.p");
3362 parse_operand (&e2);
3364 qp = e1.X_add_number - REG_P;
3365 if (e1.X_op != O_register || qp > 63)
3367 as_bad ("First operand to .restorereg.p must be a predicate");
3371 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3373 as_bad ("Second operand to .restorereg.p must be a preserved register");
3376 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3379 static char *special_linkonce_name[] =
3381 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3385 start_unwind_section (const segT text_seg, int sec_index, int linkonce_empty)
3388 Use a slightly ugly scheme to derive the unwind section names from
3389 the text section name:
3391 text sect. unwind table sect.
3392 name: name: comments:
3393 ---------- ----------------- --------------------------------
3395 .text.foo .IA_64.unwind.text.foo
3396 .foo .IA_64.unwind.foo
3398 .gnu.linkonce.ia64unw.foo
3399 _info .IA_64.unwind_info gas issues error message (ditto)
3400 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3402 This mapping is done so that:
3404 (a) An object file with unwind info only in .text will use
3405 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3406 This follows the letter of the ABI and also ensures backwards
3407 compatibility with older toolchains.
3409 (b) An object file with unwind info in multiple text sections
3410 will use separate unwind sections for each text section.
3411 This allows us to properly set the "sh_info" and "sh_link"
3412 fields in SHT_IA_64_UNWIND as required by the ABI and also
3413 lets GNU ld support programs with multiple segments
3414 containing unwind info (as might be the case for certain
3415 embedded applications).
3417 (c) An error is issued if there would be a name clash.
3420 const char *text_name, *sec_text_name;
3422 const char *prefix = special_section_name [sec_index];
3424 size_t prefix_len, suffix_len, sec_name_len;
3426 sec_text_name = segment_name (text_seg);
3427 text_name = sec_text_name;
3428 if (strncmp (text_name, "_info", 5) == 0)
3430 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3432 ignore_rest_of_line ();
3435 if (strcmp (text_name, ".text") == 0)
3438 /* Build the unwind section name by appending the (possibly stripped)
3439 text section name to the unwind prefix. */
3441 if (strncmp (text_name, ".gnu.linkonce.t.",
3442 sizeof (".gnu.linkonce.t.") - 1) == 0)
3444 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3445 suffix += sizeof (".gnu.linkonce.t.") - 1;
3447 else if (linkonce_empty)
3450 prefix_len = strlen (prefix);
3451 suffix_len = strlen (suffix);
3452 sec_name_len = prefix_len + suffix_len;
3453 sec_name = alloca (sec_name_len + 1);
3454 memcpy (sec_name, prefix, prefix_len);
3455 memcpy (sec_name + prefix_len, suffix, suffix_len);
3456 sec_name [sec_name_len] = '\0';
3458 /* Handle COMDAT group. */
3459 if (suffix == text_name && (text_seg->flags & SEC_LINK_ONCE) != 0)
3462 size_t len, group_name_len;
3463 const char *group_name = elf_group_name (text_seg);
3465 if (group_name == NULL)
3467 as_bad ("Group section `%s' has no group signature",
3469 ignore_rest_of_line ();
3472 /* We have to construct a fake section directive. */
3473 group_name_len = strlen (group_name);
3475 + 16 /* ,"aG",@progbits, */
3476 + group_name_len /* ,group_name */
3479 section = alloca (len + 1);
3480 memcpy (section, sec_name, sec_name_len);
3481 memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3482 memcpy (section + sec_name_len + 16, group_name, group_name_len);
3483 memcpy (section + len - 7, ",comdat", 7);
3484 section [len] = '\0';
3485 set_section (section);
3489 set_section (sec_name);
3490 bfd_set_section_flags (stdoutput, now_seg,
3491 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3494 elf_linked_to_section (now_seg) = text_seg;
3498 generate_unwind_image (const segT text_seg)
3503 /* Mark the end of the unwind info, so that we can compute the size of the
3504 last unwind region. */
3505 add_unwind_entry (output_endp ());
3507 /* Force out pending instructions, to make sure all unwind records have
3508 a valid slot_number field. */
3509 ia64_flush_insns ();
3511 /* Generate the unwind record. */
3512 list = optimize_unw_records (unwind.list);
3513 fixup_unw_records (list, 1);
3514 size = calc_record_size (list);
3516 if (size > 0 || unwind.force_unwind_entry)
3518 unwind.force_unwind_entry = 0;
3519 /* pad to pointer-size boundary. */
3520 pad = size % md.pointer_size;
3522 size += md.pointer_size - pad;
3523 /* Add 8 for the header. */
3525 /* Add a pointer for the personality offset. */
3526 if (unwind.personality_routine)
3527 size += md.pointer_size;
3530 /* If there are unwind records, switch sections, and output the info. */
3534 bfd_reloc_code_real_type reloc;
3536 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 0);
3538 /* Make sure the section has 4 byte alignment for ILP32 and
3539 8 byte alignment for LP64. */
3540 frag_align (md.pointer_size_shift, 0, 0);
3541 record_alignment (now_seg, md.pointer_size_shift);
3543 /* Set expression which points to start of unwind descriptor area. */
3544 unwind.info = expr_build_dot ();
3546 frag_var (rs_machine_dependent, size, size, 0, 0,
3547 (offsetT) (long) unwind.personality_routine,
3550 /* Add the personality address to the image. */
3551 if (unwind.personality_routine != 0)
3553 exp.X_op = O_symbol;
3554 exp.X_add_symbol = unwind.personality_routine;
3555 exp.X_add_number = 0;
3557 if (md.flags & EF_IA_64_BE)
3559 if (md.flags & EF_IA_64_ABI64)
3560 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3562 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3566 if (md.flags & EF_IA_64_ABI64)
3567 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3569 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3572 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3573 md.pointer_size, &exp, 0, reloc);
3574 unwind.personality_routine = 0;
3578 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 1);
3580 free_saved_prologue_counts ();
3581 unwind.list = unwind.tail = unwind.current_entry = NULL;
3585 dot_handlerdata (dummy)
3586 int dummy ATTRIBUTE_UNUSED;
3588 if (!in_procedure ("handlerdata"))
3590 unwind.force_unwind_entry = 1;
3592 /* Remember which segment we're in so we can switch back after .endp */
3593 unwind.saved_text_seg = now_seg;
3594 unwind.saved_text_subseg = now_subseg;
3596 /* Generate unwind info into unwind-info section and then leave that
3597 section as the currently active one so dataXX directives go into
3598 the language specific data area of the unwind info block. */
3599 generate_unwind_image (now_seg);
3600 demand_empty_rest_of_line ();
3604 dot_unwentry (dummy)
3605 int dummy ATTRIBUTE_UNUSED;
3607 if (!in_procedure ("unwentry"))
3609 unwind.force_unwind_entry = 1;
3610 demand_empty_rest_of_line ();
3615 int dummy ATTRIBUTE_UNUSED;
3620 if (!in_prologue ("altrp"))
3624 reg = e.X_add_number - REG_BR;
3625 if (e.X_op == O_register && reg < 8)
3626 add_unwind_entry (output_rp_br (reg));
3628 as_bad ("First operand not a valid branch register");
3632 dot_savemem (psprel)
3639 if (!in_prologue (psprel ? "savepsp" : "savesp"))
3642 sep = parse_operand (&e1);
3644 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3645 sep = parse_operand (&e2);
3647 reg1 = e1.X_add_number;
3648 val = e2.X_add_number;
3650 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3651 if (e1.X_op == O_register)
3653 if (e2.X_op == O_constant)
3657 case REG_AR + AR_BSP:
3658 add_unwind_entry (output_bsp_when ());
3659 add_unwind_entry ((psprel
3661 : output_bsp_sprel) (val));
3663 case REG_AR + AR_BSPSTORE:
3664 add_unwind_entry (output_bspstore_when ());
3665 add_unwind_entry ((psprel
3666 ? output_bspstore_psprel
3667 : output_bspstore_sprel) (val));
3669 case REG_AR + AR_RNAT:
3670 add_unwind_entry (output_rnat_when ());
3671 add_unwind_entry ((psprel
3672 ? output_rnat_psprel
3673 : output_rnat_sprel) (val));
3675 case REG_AR + AR_UNAT:
3676 add_unwind_entry (output_unat_when ());
3677 add_unwind_entry ((psprel
3678 ? output_unat_psprel
3679 : output_unat_sprel) (val));
3681 case REG_AR + AR_FPSR:
3682 add_unwind_entry (output_fpsr_when ());
3683 add_unwind_entry ((psprel
3684 ? output_fpsr_psprel
3685 : output_fpsr_sprel) (val));
3687 case REG_AR + AR_PFS:
3688 add_unwind_entry (output_pfs_when ());
3689 add_unwind_entry ((psprel
3691 : output_pfs_sprel) (val));
3693 case REG_AR + AR_LC:
3694 add_unwind_entry (output_lc_when ());
3695 add_unwind_entry ((psprel
3697 : output_lc_sprel) (val));
3700 add_unwind_entry (output_rp_when ());
3701 add_unwind_entry ((psprel
3703 : output_rp_sprel) (val));
3706 add_unwind_entry (output_preds_when ());
3707 add_unwind_entry ((psprel
3708 ? output_preds_psprel
3709 : output_preds_sprel) (val));
3712 add_unwind_entry (output_priunat_when_mem ());
3713 add_unwind_entry ((psprel
3714 ? output_priunat_psprel
3715 : output_priunat_sprel) (val));
3718 as_bad ("First operand not a valid register");
3722 as_bad (" Second operand not a valid constant");
3725 as_bad ("First operand not a register");
3730 int dummy ATTRIBUTE_UNUSED;
3735 if (!in_prologue ("save.g"))
3738 sep = parse_operand (&e1);
3740 parse_operand (&e2);
3742 if (e1.X_op != O_constant)
3743 as_bad ("First operand to .save.g must be a constant.");
3746 int grmask = e1.X_add_number;
3748 add_unwind_entry (output_gr_mem (grmask));
3751 int reg = e2.X_add_number - REG_GR;
3752 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3753 add_unwind_entry (output_gr_gr (grmask, reg));
3755 as_bad ("Second operand is an invalid register.");
3762 int dummy ATTRIBUTE_UNUSED;
3767 if (!in_prologue ("save.f"))
3770 sep = parse_operand (&e1);
3772 if (e1.X_op != O_constant)
3773 as_bad ("Operand to .save.f must be a constant.");
3775 add_unwind_entry (output_fr_mem (e1.X_add_number));
3780 int dummy ATTRIBUTE_UNUSED;
3787 if (!in_prologue ("save.b"))
3790 sep = parse_operand (&e1);
3791 if (e1.X_op != O_constant)
3793 as_bad ("First operand to .save.b must be a constant.");
3796 brmask = e1.X_add_number;
3800 sep = parse_operand (&e2);
3801 reg = e2.X_add_number - REG_GR;
3802 if (e2.X_op != O_register || reg > 127)
3804 as_bad ("Second operand to .save.b must be a general register.");
3807 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3810 add_unwind_entry (output_br_mem (brmask));
3812 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3813 demand_empty_rest_of_line ();
3818 int dummy ATTRIBUTE_UNUSED;
3823 if (!in_prologue ("save.gf"))
3826 sep = parse_operand (&e1);
3828 parse_operand (&e2);
3830 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3831 as_bad ("Both operands of .save.gf must be constants.");
3834 int grmask = e1.X_add_number;
3835 int frmask = e2.X_add_number;
3836 add_unwind_entry (output_frgr_mem (grmask, frmask));
3842 int dummy ATTRIBUTE_UNUSED;
3847 if (!in_prologue ("spill"))
3850 sep = parse_operand (&e);
3851 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3852 demand_empty_rest_of_line ();
3854 if (e.X_op != O_constant)
3855 as_bad ("Operand to .spill must be a constant");
3857 add_unwind_entry (output_spill_base (e.X_add_number));
3861 dot_spillreg (dummy)
3862 int dummy ATTRIBUTE_UNUSED;
3864 int sep, ab, xy, reg, treg;
3867 if (!in_procedure ("spillreg"))
3870 sep = parse_operand (&e1);
3873 as_bad ("No second operand to .spillreg");
3877 parse_operand (&e2);
3879 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3881 as_bad ("First operand to .spillreg must be a preserved register");
3885 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3887 as_bad ("Second operand to .spillreg must be a register");
3891 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3895 dot_spillmem (psprel)
3901 if (!in_procedure ("spillmem"))
3904 sep = parse_operand (&e1);
3907 as_bad ("Second operand missing");
3911 parse_operand (&e2);
3913 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3915 as_bad ("First operand to .spill%s must be a preserved register",
3916 psprel ? "psp" : "sp");
3920 if (e2.X_op != O_constant)
3922 as_bad ("Second operand to .spill%s must be a constant",
3923 psprel ? "psp" : "sp");
3928 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3930 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3934 dot_spillreg_p (dummy)
3935 int dummy ATTRIBUTE_UNUSED;
3937 int sep, ab, xy, reg, treg;
3938 expressionS e1, e2, e3;
3941 if (!in_procedure ("spillreg.p"))
3944 sep = parse_operand (&e1);
3947 as_bad ("No second and third operand to .spillreg.p");
3951 sep = parse_operand (&e2);
3954 as_bad ("No third operand to .spillreg.p");
3958 parse_operand (&e3);
3960 qp = e1.X_add_number - REG_P;
3962 if (e1.X_op != O_register || qp > 63)
3964 as_bad ("First operand to .spillreg.p must be a predicate");
3968 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3970 as_bad ("Second operand to .spillreg.p must be a preserved register");
3974 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3976 as_bad ("Third operand to .spillreg.p must be a register");
3980 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3984 dot_spillmem_p (psprel)
3987 expressionS e1, e2, e3;
3991 if (!in_procedure ("spillmem.p"))
3994 sep = parse_operand (&e1);
3997 as_bad ("Second operand missing");
4001 parse_operand (&e2);
4004 as_bad ("Second operand missing");
4008 parse_operand (&e3);
4010 qp = e1.X_add_number - REG_P;
4011 if (e1.X_op != O_register || qp > 63)
4013 as_bad ("First operand to .spill%s_p must be a predicate",
4014 psprel ? "psp" : "sp");
4018 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
4020 as_bad ("Second operand to .spill%s_p must be a preserved register",
4021 psprel ? "psp" : "sp");
4025 if (e3.X_op != O_constant)
4027 as_bad ("Third operand to .spill%s_p must be a constant",
4028 psprel ? "psp" : "sp");
4033 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
4035 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
4039 get_saved_prologue_count (lbl)
4042 label_prologue_count *lpc = unwind.saved_prologue_counts;
4044 while (lpc != NULL && lpc->label_number != lbl)
4048 return lpc->prologue_count;
4050 as_bad ("Missing .label_state %ld", lbl);
4055 save_prologue_count (lbl, count)
4059 label_prologue_count *lpc = unwind.saved_prologue_counts;
4061 while (lpc != NULL && lpc->label_number != lbl)
4065 lpc->prologue_count = count;
4068 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
4070 new_lpc->next = unwind.saved_prologue_counts;
4071 new_lpc->label_number = lbl;
4072 new_lpc->prologue_count = count;
4073 unwind.saved_prologue_counts = new_lpc;
4078 free_saved_prologue_counts ()
4080 label_prologue_count *lpc = unwind.saved_prologue_counts;
4081 label_prologue_count *next;
4090 unwind.saved_prologue_counts = NULL;
4094 dot_label_state (dummy)
4095 int dummy ATTRIBUTE_UNUSED;
4099 if (!in_body ("label_state"))
4103 if (e.X_op != O_constant)
4105 as_bad ("Operand to .label_state must be a constant");
4108 add_unwind_entry (output_label_state (e.X_add_number));
4109 save_prologue_count (e.X_add_number, unwind.prologue_count);
4113 dot_copy_state (dummy)
4114 int dummy ATTRIBUTE_UNUSED;
4118 if (!in_body ("copy_state"))
4122 if (e.X_op != O_constant)
4124 as_bad ("Operand to .copy_state must be a constant");
4127 add_unwind_entry (output_copy_state (e.X_add_number));
4128 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
4133 int dummy ATTRIBUTE_UNUSED;
4138 if (!in_procedure ("unwabi"))
4141 sep = parse_operand (&e1);
4144 as_bad ("Second operand to .unwabi missing");
4147 sep = parse_operand (&e2);
4148 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4149 demand_empty_rest_of_line ();
4151 if (e1.X_op != O_constant)
4153 as_bad ("First operand to .unwabi must be a constant");
4157 if (e2.X_op != O_constant)
4159 as_bad ("Second operand to .unwabi must be a constant");
4163 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4167 dot_personality (dummy)
4168 int dummy ATTRIBUTE_UNUSED;
4171 if (!in_procedure ("personality"))
4174 name = input_line_pointer;
4175 c = get_symbol_end ();
4176 p = input_line_pointer;
4177 unwind.personality_routine = symbol_find_or_make (name);
4178 unwind.force_unwind_entry = 1;
4181 demand_empty_rest_of_line ();
4186 int dummy ATTRIBUTE_UNUSED;
4191 unwind.proc_start = 0;
4192 /* Parse names of main and alternate entry points and mark them as
4193 function symbols: */
4197 name = input_line_pointer;
4198 c = get_symbol_end ();
4199 p = input_line_pointer;
4201 as_bad ("Empty argument of .proc");
4204 sym = symbol_find_or_make (name);
4205 if (S_IS_DEFINED (sym))
4206 as_bad ("`%s' was already defined", name);
4207 else if (unwind.proc_start == 0)
4209 unwind.proc_start = sym;
4211 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4215 if (*input_line_pointer != ',')
4217 ++input_line_pointer;
4219 if (unwind.proc_start == 0)
4220 unwind.proc_start = expr_build_dot ();
4221 demand_empty_rest_of_line ();
4224 unwind.prologue = 0;
4225 unwind.prologue_count = 0;
4228 unwind.list = unwind.tail = unwind.current_entry = NULL;
4229 unwind.personality_routine = 0;
4234 int dummy ATTRIBUTE_UNUSED;
4236 if (!in_procedure ("body"))
4238 if (!unwind.prologue && !unwind.body && unwind.insn)
4239 as_warn ("Initial .body should precede any instructions");
4241 unwind.prologue = 0;
4242 unwind.prologue_mask = 0;
4245 add_unwind_entry (output_body ());
4246 demand_empty_rest_of_line ();
4250 dot_prologue (dummy)
4251 int dummy ATTRIBUTE_UNUSED;
4254 int mask = 0, grsave = 0;
4256 if (!in_procedure ("prologue"))
4258 if (unwind.prologue)
4260 as_bad (".prologue within prologue");
4261 ignore_rest_of_line ();
4264 if (!unwind.body && unwind.insn)
4265 as_warn ("Initial .prologue should precede any instructions");
4267 if (!is_it_end_of_statement ())
4270 sep = parse_operand (&e1);
4272 as_bad ("No second operand to .prologue");
4273 sep = parse_operand (&e2);
4274 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4275 demand_empty_rest_of_line ();
4277 if (e1.X_op == O_constant)
4279 mask = e1.X_add_number;
4281 if (e2.X_op == O_constant)
4282 grsave = e2.X_add_number;
4283 else if (e2.X_op == O_register
4284 && (grsave = e2.X_add_number - REG_GR) < 128)
4287 as_bad ("Second operand not a constant or general register");
4289 add_unwind_entry (output_prologue_gr (mask, grsave));
4292 as_bad ("First operand not a constant");
4295 add_unwind_entry (output_prologue ());
4297 unwind.prologue = 1;
4298 unwind.prologue_mask = mask;
4300 ++unwind.prologue_count;
4305 int dummy ATTRIBUTE_UNUSED;
4309 int bytes_per_address;
4312 subsegT saved_subseg;
4313 char *name, *default_name, *p, c;
4315 int unwind_check = md.unwind_check;
4317 md.unwind_check = unwind_check_error;
4318 if (!in_procedure ("endp"))
4320 md.unwind_check = unwind_check;
4322 if (unwind.saved_text_seg)
4324 saved_seg = unwind.saved_text_seg;
4325 saved_subseg = unwind.saved_text_subseg;
4326 unwind.saved_text_seg = NULL;
4330 saved_seg = now_seg;
4331 saved_subseg = now_subseg;
4334 insn_group_break (1, 0, 0);
4336 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4338 generate_unwind_image (saved_seg);
4340 if (unwind.info || unwind.force_unwind_entry)
4344 subseg_set (md.last_text_seg, 0);
4345 proc_end = expr_build_dot ();
4347 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 0);
4349 /* Make sure that section has 4 byte alignment for ILP32 and
4350 8 byte alignment for LP64. */
4351 record_alignment (now_seg, md.pointer_size_shift);
4353 /* Need space for 3 pointers for procedure start, procedure end,
4355 ptr = frag_more (3 * md.pointer_size);
4356 where = frag_now_fix () - (3 * md.pointer_size);
4357 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4359 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4360 e.X_op = O_pseudo_fixup;
4361 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4363 e.X_add_symbol = unwind.proc_start;
4364 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4366 e.X_op = O_pseudo_fixup;
4367 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4369 e.X_add_symbol = proc_end;
4370 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4371 bytes_per_address, &e);
4375 e.X_op = O_pseudo_fixup;
4376 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4378 e.X_add_symbol = unwind.info;
4379 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4380 bytes_per_address, &e);
4383 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4388 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 1);
4390 subseg_set (saved_seg, saved_subseg);
4392 if (unwind.proc_start)
4393 default_name = (char *) S_GET_NAME (unwind.proc_start);
4395 default_name = NULL;
4397 /* Parse names of main and alternate entry points and set symbol sizes. */
4401 name = input_line_pointer;
4402 c = get_symbol_end ();
4403 p = input_line_pointer;
4406 if (md.unwind_check == unwind_check_warning)
4410 as_warn ("Empty argument of .endp. Use the default name `%s'",
4412 name = default_name;
4415 as_warn ("Empty argument of .endp");
4418 as_bad ("Empty argument of .endp");
4422 sym = symbol_find (name);
4424 && md.unwind_check == unwind_check_warning
4426 && default_name != name)
4428 /* We have a bad name. Try the default one if needed. */
4429 as_warn ("`%s' was not defined within procedure. Use the default name `%s'",
4430 name, default_name);
4431 name = default_name;
4432 sym = symbol_find (name);
4434 if (!sym || !S_IS_DEFINED (sym))
4435 as_bad ("`%s' was not defined within procedure", name);
4436 else if (unwind.proc_start
4437 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4438 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4440 fragS *fr = symbol_get_frag (unwind.proc_start);
4441 fragS *frag = symbol_get_frag (sym);
4443 /* Check whether the function label is at or beyond last
4445 while (fr && fr != frag)
4449 if (frag == frag_now && SEG_NORMAL (now_seg))
4450 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4453 symbol_get_obj (sym)->size =
4454 (expressionS *) xmalloc (sizeof (expressionS));
4455 symbol_get_obj (sym)->size->X_op = O_subtract;
4456 symbol_get_obj (sym)->size->X_add_symbol
4457 = symbol_new (FAKE_LABEL_NAME, now_seg,
4458 frag_now_fix (), frag_now);
4459 symbol_get_obj (sym)->size->X_op_symbol = sym;
4460 symbol_get_obj (sym)->size->X_add_number = 0;
4467 if (*input_line_pointer != ',')
4469 ++input_line_pointer;
4471 demand_empty_rest_of_line ();
4472 unwind.proc_start = unwind.info = 0;
4476 dot_template (template)
4479 CURR_SLOT.user_template = template;
4484 int dummy ATTRIBUTE_UNUSED;
4486 int ins, locs, outs, rots;
4488 if (is_it_end_of_statement ())
4489 ins = locs = outs = rots = 0;
4492 ins = get_absolute_expression ();
4493 if (*input_line_pointer++ != ',')
4495 locs = get_absolute_expression ();
4496 if (*input_line_pointer++ != ',')
4498 outs = get_absolute_expression ();
4499 if (*input_line_pointer++ != ',')
4501 rots = get_absolute_expression ();
4503 set_regstack (ins, locs, outs, rots);
4507 as_bad ("Comma expected");
4508 ignore_rest_of_line ();
4515 unsigned num_regs, num_alloced = 0;
4516 struct dynreg **drpp, *dr;
4517 int ch, base_reg = 0;
4523 case DYNREG_GR: base_reg = REG_GR + 32; break;
4524 case DYNREG_FR: base_reg = REG_FR + 32; break;
4525 case DYNREG_PR: base_reg = REG_P + 16; break;
4529 /* First, remove existing names from hash table. */
4530 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4532 hash_delete (md.dynreg_hash, dr->name);
4536 drpp = &md.dynreg[type];
4539 start = input_line_pointer;
4540 ch = get_symbol_end ();
4541 *input_line_pointer = ch;
4542 len = (input_line_pointer - start);
4545 if (*input_line_pointer != '[')
4547 as_bad ("Expected '['");
4550 ++input_line_pointer; /* skip '[' */
4552 num_regs = get_absolute_expression ();
4554 if (*input_line_pointer++ != ']')
4556 as_bad ("Expected ']'");
4561 num_alloced += num_regs;
4565 if (num_alloced > md.rot.num_regs)
4567 as_bad ("Used more than the declared %d rotating registers",
4573 if (num_alloced > 96)
4575 as_bad ("Used more than the available 96 rotating registers");
4580 if (num_alloced > 48)
4582 as_bad ("Used more than the available 48 rotating registers");
4591 name = obstack_alloc (¬es, len + 1);
4592 memcpy (name, start, len);
4597 *drpp = obstack_alloc (¬es, sizeof (*dr));
4598 memset (*drpp, 0, sizeof (*dr));
4603 dr->num_regs = num_regs;
4604 dr->base = base_reg;
4606 base_reg += num_regs;
4608 if (hash_insert (md.dynreg_hash, name, dr))
4610 as_bad ("Attempt to redefine register set `%s'", name);
4614 if (*input_line_pointer != ',')
4616 ++input_line_pointer; /* skip comma */
4619 demand_empty_rest_of_line ();
4623 ignore_rest_of_line ();
4627 dot_byteorder (byteorder)
4630 segment_info_type *seginfo = seg_info (now_seg);
4632 if (byteorder == -1)
4634 if (seginfo->tc_segment_info_data.endian == 0)
4635 seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2;
4636 byteorder = seginfo->tc_segment_info_data.endian == 1;
4639 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4641 if (target_big_endian != byteorder)
4643 target_big_endian = byteorder;
4644 if (target_big_endian)
4646 ia64_number_to_chars = number_to_chars_bigendian;
4647 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4651 ia64_number_to_chars = number_to_chars_littleendian;
4652 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4659 int dummy ATTRIBUTE_UNUSED;
4666 option = input_line_pointer;
4667 ch = get_symbol_end ();
4668 if (strcmp (option, "lsb") == 0)
4669 md.flags &= ~EF_IA_64_BE;
4670 else if (strcmp (option, "msb") == 0)
4671 md.flags |= EF_IA_64_BE;
4672 else if (strcmp (option, "abi32") == 0)
4673 md.flags &= ~EF_IA_64_ABI64;
4674 else if (strcmp (option, "abi64") == 0)
4675 md.flags |= EF_IA_64_ABI64;
4677 as_bad ("Unknown psr option `%s'", option);
4678 *input_line_pointer = ch;
4681 if (*input_line_pointer != ',')
4684 ++input_line_pointer;
4687 demand_empty_rest_of_line ();
4692 int dummy ATTRIBUTE_UNUSED;
4694 new_logical_line (0, get_absolute_expression ());
4695 demand_empty_rest_of_line ();
4699 parse_section_name ()
4705 if (*input_line_pointer == '"')
4706 name = demand_copy_C_string (&len);
4709 char *start = input_line_pointer;
4710 char c = get_symbol_end ();
4712 if (input_line_pointer == start)
4714 as_bad ("Missing section name");
4715 ignore_rest_of_line ();
4718 name = obstack_copy (¬es, start, input_line_pointer - start + 1);
4719 *input_line_pointer = c;
4723 ignore_rest_of_line ();
4727 if (*input_line_pointer != ',')
4729 as_bad ("Comma expected after section name");
4730 ignore_rest_of_line ();
4733 ++input_line_pointer; /* skip comma */
4741 char *name = parse_section_name ();
4745 md.keep_pending_output = 1;
4747 obstack_free (¬es, name);
4749 obj_elf_previous (0);
4750 md.keep_pending_output = 0;
4753 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4756 stmt_float_cons (kind)
4777 ia64_do_align (alignment);
4785 int saved_auto_align = md.auto_align;
4789 md.auto_align = saved_auto_align;
4793 dot_xfloat_cons (kind)
4796 char *name = parse_section_name ();
4800 md.keep_pending_output = 1;
4802 obstack_free (¬es, name);
4803 stmt_float_cons (kind);
4804 obj_elf_previous (0);
4805 md.keep_pending_output = 0;
4809 dot_xstringer (zero)
4812 char *name = parse_section_name ();
4816 md.keep_pending_output = 1;
4818 obstack_free (¬es, name);
4820 obj_elf_previous (0);
4821 md.keep_pending_output = 0;
4828 int saved_auto_align = md.auto_align;
4829 char *name = parse_section_name ();
4833 md.keep_pending_output = 1;
4835 obstack_free (¬es, name);
4838 md.auto_align = saved_auto_align;
4839 obj_elf_previous (0);
4840 md.keep_pending_output = 0;
4844 dot_xfloat_cons_ua (kind)
4847 int saved_auto_align = md.auto_align;
4848 char *name = parse_section_name ();
4852 md.keep_pending_output = 1;
4854 obstack_free (¬es, name);
4856 stmt_float_cons (kind);
4857 md.auto_align = saved_auto_align;
4858 obj_elf_previous (0);
4859 md.keep_pending_output = 0;
4862 /* .reg.val <regname>,value */
4866 int dummy ATTRIBUTE_UNUSED;
4871 if (reg.X_op != O_register)
4873 as_bad (_("Register name expected"));
4874 ignore_rest_of_line ();
4876 else if (*input_line_pointer++ != ',')
4878 as_bad (_("Comma expected"));
4879 ignore_rest_of_line ();
4883 valueT value = get_absolute_expression ();
4884 int regno = reg.X_add_number;
4885 if (regno < REG_GR || regno > REG_GR + 128)
4886 as_warn (_("Register value annotation ignored"));
4889 gr_values[regno - REG_GR].known = 1;
4890 gr_values[regno - REG_GR].value = value;
4891 gr_values[regno - REG_GR].path = md.path;
4894 demand_empty_rest_of_line ();
4899 .serialize.instruction
4902 dot_serialize (type)
4905 insn_group_break (0, 0, 0);
4907 instruction_serialization ();
4909 data_serialization ();
4910 insn_group_break (0, 0, 0);
4911 demand_empty_rest_of_line ();
4914 /* select dv checking mode
4919 A stop is inserted when changing modes
4926 if (md.manual_bundling)
4927 as_warn (_("Directive invalid within a bundle"));
4929 if (type == 'E' || type == 'A')
4930 md.mode_explicitly_set = 0;
4932 md.mode_explicitly_set = 1;
4939 if (md.explicit_mode)
4940 insn_group_break (1, 0, 0);
4941 md.explicit_mode = 0;
4945 if (!md.explicit_mode)
4946 insn_group_break (1, 0, 0);
4947 md.explicit_mode = 1;
4951 if (md.explicit_mode != md.default_explicit_mode)
4952 insn_group_break (1, 0, 0);
4953 md.explicit_mode = md.default_explicit_mode;
4954 md.mode_explicitly_set = 0;
4965 for (regno = 0; regno < 64; regno++)
4967 if (mask & ((valueT) 1 << regno))
4969 fprintf (stderr, "%s p%d", comma, regno);
4976 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear)
4977 .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply)
4978 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex)
4979 .pred.safe_across_calls p1 [, p2 [,...]]
4988 int p1 = -1, p2 = -1;
4992 if (*input_line_pointer == '"')
4995 char *form = demand_copy_C_string (&len);
4997 if (strcmp (form, "mutex") == 0)
4999 else if (strcmp (form, "clear") == 0)
5001 else if (strcmp (form, "imply") == 0)
5003 obstack_free (¬es, form);
5005 else if (*input_line_pointer == '@')
5007 char *form = ++input_line_pointer;
5008 char c = get_symbol_end();
5010 if (strcmp (form, "mutex") == 0)
5012 else if (strcmp (form, "clear") == 0)
5014 else if (strcmp (form, "imply") == 0)
5016 *input_line_pointer = c;
5020 as_bad (_("Missing predicate relation type"));
5021 ignore_rest_of_line ();
5026 as_bad (_("Unrecognized predicate relation type"));
5027 ignore_rest_of_line ();
5030 if (*input_line_pointer == ',')
5031 ++input_line_pointer;
5041 if (TOUPPER (*input_line_pointer) != 'P'
5042 || (regno = atoi (++input_line_pointer)) < 0
5045 as_bad (_("Predicate register expected"));
5046 ignore_rest_of_line ();
5049 while (ISDIGIT (*input_line_pointer))
5050 ++input_line_pointer;
5057 as_warn (_("Duplicate predicate register ignored"));
5060 /* See if it's a range. */
5061 if (*input_line_pointer == '-')
5064 ++input_line_pointer;
5066 if (TOUPPER (*input_line_pointer) != 'P'
5067 || (regno = atoi (++input_line_pointer)) < 0
5070 as_bad (_("Predicate register expected"));
5071 ignore_rest_of_line ();
5074 while (ISDIGIT (*input_line_pointer))
5075 ++input_line_pointer;
5079 as_bad (_("Bad register range"));
5080 ignore_rest_of_line ();
5091 if (*input_line_pointer != ',')
5093 ++input_line_pointer;
5102 clear_qp_mutex (mask);
5103 clear_qp_implies (mask, (valueT) 0);
5106 if (count != 2 || p1 == -1 || p2 == -1)
5107 as_bad (_("Predicate source and target required"));
5108 else if (p1 == 0 || p2 == 0)
5109 as_bad (_("Use of p0 is not valid in this context"));
5111 add_qp_imply (p1, p2);
5116 as_bad (_("At least two PR arguments expected"));
5121 as_bad (_("Use of p0 is not valid in this context"));
5124 add_qp_mutex (mask);
5127 /* note that we don't override any existing relations */
5130 as_bad (_("At least one PR argument expected"));
5135 fprintf (stderr, "Safe across calls: ");
5136 print_prmask (mask);
5137 fprintf (stderr, "\n");
5139 qp_safe_across_calls = mask;
5142 demand_empty_rest_of_line ();
5145 /* .entry label [, label [, ...]]
5146 Hint to DV code that the given labels are to be considered entry points.
5147 Otherwise, only global labels are considered entry points. */
5151 int dummy ATTRIBUTE_UNUSED;
5160 name = input_line_pointer;
5161 c = get_symbol_end ();
5162 symbolP = symbol_find_or_make (name);
5164 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
5166 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
5169 *input_line_pointer = c;
5171 c = *input_line_pointer;
5174 input_line_pointer++;
5176 if (*input_line_pointer == '\n')
5182 demand_empty_rest_of_line ();
5185 /* .mem.offset offset, base
5186 "base" is used to distinguish between offsets from a different base. */
5189 dot_mem_offset (dummy)
5190 int dummy ATTRIBUTE_UNUSED;
5192 md.mem_offset.hint = 1;
5193 md.mem_offset.offset = get_absolute_expression ();
5194 if (*input_line_pointer != ',')
5196 as_bad (_("Comma expected"));
5197 ignore_rest_of_line ();
5200 ++input_line_pointer;
5201 md.mem_offset.base = get_absolute_expression ();
5202 demand_empty_rest_of_line ();
5205 /* ia64-specific pseudo-ops: */
5206 const pseudo_typeS md_pseudo_table[] =
5208 { "radix", dot_radix, 0 },
5209 { "lcomm", s_lcomm_bytes, 1 },
5210 { "loc", dot_loc, 0 },
5211 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
5212 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
5213 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
5214 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
5215 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
5216 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
5217 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
5218 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
5219 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
5220 { "proc", dot_proc, 0 },
5221 { "body", dot_body, 0 },
5222 { "prologue", dot_prologue, 0 },
5223 { "endp", dot_endp, 0 },
5225 { "fframe", dot_fframe, 0 },
5226 { "vframe", dot_vframe, 0 },
5227 { "vframesp", dot_vframesp, 0 },
5228 { "vframepsp", dot_vframepsp, 0 },
5229 { "save", dot_save, 0 },
5230 { "restore", dot_restore, 0 },
5231 { "restorereg", dot_restorereg, 0 },
5232 { "restorereg.p", dot_restorereg_p, 0 },
5233 { "handlerdata", dot_handlerdata, 0 },
5234 { "unwentry", dot_unwentry, 0 },
5235 { "altrp", dot_altrp, 0 },
5236 { "savesp", dot_savemem, 0 },
5237 { "savepsp", dot_savemem, 1 },
5238 { "save.g", dot_saveg, 0 },
5239 { "save.f", dot_savef, 0 },
5240 { "save.b", dot_saveb, 0 },
5241 { "save.gf", dot_savegf, 0 },
5242 { "spill", dot_spill, 0 },
5243 { "spillreg", dot_spillreg, 0 },
5244 { "spillsp", dot_spillmem, 0 },
5245 { "spillpsp", dot_spillmem, 1 },
5246 { "spillreg.p", dot_spillreg_p, 0 },
5247 { "spillsp.p", dot_spillmem_p, 0 },
5248 { "spillpsp.p", dot_spillmem_p, 1 },
5249 { "label_state", dot_label_state, 0 },
5250 { "copy_state", dot_copy_state, 0 },
5251 { "unwabi", dot_unwabi, 0 },
5252 { "personality", dot_personality, 0 },
5253 { "mii", dot_template, 0x0 },
5254 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5255 { "mlx", dot_template, 0x2 },
5256 { "mmi", dot_template, 0x4 },
5257 { "mfi", dot_template, 0x6 },
5258 { "mmf", dot_template, 0x7 },
5259 { "mib", dot_template, 0x8 },
5260 { "mbb", dot_template, 0x9 },
5261 { "bbb", dot_template, 0xb },
5262 { "mmb", dot_template, 0xc },
5263 { "mfb", dot_template, 0xe },
5264 { "align", dot_align, 0 },
5265 { "regstk", dot_regstk, 0 },
5266 { "rotr", dot_rot, DYNREG_GR },
5267 { "rotf", dot_rot, DYNREG_FR },
5268 { "rotp", dot_rot, DYNREG_PR },
5269 { "lsb", dot_byteorder, 0 },
5270 { "msb", dot_byteorder, 1 },
5271 { "psr", dot_psr, 0 },
5272 { "alias", dot_alias, 0 },
5273 { "secalias", dot_alias, 1 },
5274 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5276 { "xdata1", dot_xdata, 1 },
5277 { "xdata2", dot_xdata, 2 },
5278 { "xdata4", dot_xdata, 4 },
5279 { "xdata8", dot_xdata, 8 },
5280 { "xdata16", dot_xdata, 16 },
5281 { "xreal4", dot_xfloat_cons, 'f' },
5282 { "xreal8", dot_xfloat_cons, 'd' },
5283 { "xreal10", dot_xfloat_cons, 'x' },
5284 { "xreal16", dot_xfloat_cons, 'X' },
5285 { "xstring", dot_xstringer, 0 },
5286 { "xstringz", dot_xstringer, 1 },
5288 /* unaligned versions: */
5289 { "xdata2.ua", dot_xdata_ua, 2 },
5290 { "xdata4.ua", dot_xdata_ua, 4 },
5291 { "xdata8.ua", dot_xdata_ua, 8 },
5292 { "xdata16.ua", dot_xdata_ua, 16 },
5293 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5294 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5295 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5296 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5298 /* annotations/DV checking support */
5299 { "entry", dot_entry, 0 },
5300 { "mem.offset", dot_mem_offset, 0 },
5301 { "pred.rel", dot_pred_rel, 0 },
5302 { "pred.rel.clear", dot_pred_rel, 'c' },
5303 { "pred.rel.imply", dot_pred_rel, 'i' },
5304 { "pred.rel.mutex", dot_pred_rel, 'm' },
5305 { "pred.safe_across_calls", dot_pred_rel, 's' },
5306 { "reg.val", dot_reg_val, 0 },
5307 { "serialize.data", dot_serialize, 0 },
5308 { "serialize.instruction", dot_serialize, 1 },
5309 { "auto", dot_dv_mode, 'a' },
5310 { "explicit", dot_dv_mode, 'e' },
5311 { "default", dot_dv_mode, 'd' },
5313 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5314 IA-64 aligns data allocation pseudo-ops by default, so we have to
5315 tell it that these ones are supposed to be unaligned. Long term,
5316 should rewrite so that only IA-64 specific data allocation pseudo-ops
5317 are aligned by default. */
5318 {"2byte", stmt_cons_ua, 2},
5319 {"4byte", stmt_cons_ua, 4},
5320 {"8byte", stmt_cons_ua, 8},
5325 static const struct pseudo_opcode
5328 void (*handler) (int);
5333 /* these are more like pseudo-ops, but don't start with a dot */
5334 { "data1", cons, 1 },
5335 { "data2", cons, 2 },
5336 { "data4", cons, 4 },
5337 { "data8", cons, 8 },
5338 { "data16", cons, 16 },
5339 { "real4", stmt_float_cons, 'f' },
5340 { "real8", stmt_float_cons, 'd' },
5341 { "real10", stmt_float_cons, 'x' },
5342 { "real16", stmt_float_cons, 'X' },
5343 { "string", stringer, 0 },
5344 { "stringz", stringer, 1 },
5346 /* unaligned versions: */
5347 { "data2.ua", stmt_cons_ua, 2 },
5348 { "data4.ua", stmt_cons_ua, 4 },
5349 { "data8.ua", stmt_cons_ua, 8 },
5350 { "data16.ua", stmt_cons_ua, 16 },
5351 { "real4.ua", float_cons, 'f' },
5352 { "real8.ua", float_cons, 'd' },
5353 { "real10.ua", float_cons, 'x' },
5354 { "real16.ua", float_cons, 'X' },
5357 /* Declare a register by creating a symbol for it and entering it in
5358 the symbol table. */
5361 declare_register (name, regnum)
5368 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5370 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5372 as_fatal ("Inserting \"%s\" into register table failed: %s",
5379 declare_register_set (prefix, num_regs, base_regnum)
5387 for (i = 0; i < num_regs; ++i)
5389 sprintf (name, "%s%u", prefix, i);
5390 declare_register (name, base_regnum + i);
5395 operand_width (opnd)
5396 enum ia64_opnd opnd;
5398 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5399 unsigned int bits = 0;
5403 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5404 bits += odesc->field[i].bits;
5409 static enum operand_match_result
5410 operand_match (idesc, index, e)
5411 const struct ia64_opcode *idesc;
5415 enum ia64_opnd opnd = idesc->operands[index];
5416 int bits, relocatable = 0;
5417 struct insn_fix *fix;
5424 case IA64_OPND_AR_CCV:
5425 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5426 return OPERAND_MATCH;
5429 case IA64_OPND_AR_CSD:
5430 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5431 return OPERAND_MATCH;
5434 case IA64_OPND_AR_PFS:
5435 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5436 return OPERAND_MATCH;
5440 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5441 return OPERAND_MATCH;
5445 if (e->X_op == O_register && e->X_add_number == REG_IP)
5446 return OPERAND_MATCH;
5450 if (e->X_op == O_register && e->X_add_number == REG_PR)
5451 return OPERAND_MATCH;
5454 case IA64_OPND_PR_ROT:
5455 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5456 return OPERAND_MATCH;
5460 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5461 return OPERAND_MATCH;
5464 case IA64_OPND_PSR_L:
5465 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5466 return OPERAND_MATCH;
5469 case IA64_OPND_PSR_UM:
5470 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5471 return OPERAND_MATCH;
5475 if (e->X_op == O_constant)
5477 if (e->X_add_number == 1)
5478 return OPERAND_MATCH;
5480 return OPERAND_OUT_OF_RANGE;
5485 if (e->X_op == O_constant)
5487 if (e->X_add_number == 8)
5488 return OPERAND_MATCH;
5490 return OPERAND_OUT_OF_RANGE;
5495 if (e->X_op == O_constant)
5497 if (e->X_add_number == 16)
5498 return OPERAND_MATCH;
5500 return OPERAND_OUT_OF_RANGE;
5504 /* register operands: */
5507 if (e->X_op == O_register && e->X_add_number >= REG_AR
5508 && e->X_add_number < REG_AR + 128)
5509 return OPERAND_MATCH;
5514 if (e->X_op == O_register && e->X_add_number >= REG_BR
5515 && e->X_add_number < REG_BR + 8)
5516 return OPERAND_MATCH;
5520 if (e->X_op == O_register && e->X_add_number >= REG_CR
5521 && e->X_add_number < REG_CR + 128)
5522 return OPERAND_MATCH;
5529 if (e->X_op == O_register && e->X_add_number >= REG_FR
5530 && e->X_add_number < REG_FR + 128)
5531 return OPERAND_MATCH;
5536 if (e->X_op == O_register && e->X_add_number >= REG_P
5537 && e->X_add_number < REG_P + 64)
5538 return OPERAND_MATCH;
5544 if (e->X_op == O_register && e->X_add_number >= REG_GR
5545 && e->X_add_number < REG_GR + 128)
5546 return OPERAND_MATCH;
5549 case IA64_OPND_R3_2:
5550 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5552 if (e->X_add_number < REG_GR + 4)
5553 return OPERAND_MATCH;
5554 else if (e->X_add_number < REG_GR + 128)
5555 return OPERAND_OUT_OF_RANGE;
5559 /* indirect operands: */
5560 case IA64_OPND_CPUID_R3:
5561 case IA64_OPND_DBR_R3:
5562 case IA64_OPND_DTR_R3:
5563 case IA64_OPND_ITR_R3:
5564 case IA64_OPND_IBR_R3:
5565 case IA64_OPND_MSR_R3:
5566 case IA64_OPND_PKR_R3:
5567 case IA64_OPND_PMC_R3:
5568 case IA64_OPND_PMD_R3:
5569 case IA64_OPND_RR_R3:
5570 if (e->X_op == O_index && e->X_op_symbol
5571 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5572 == opnd - IA64_OPND_CPUID_R3))
5573 return OPERAND_MATCH;
5577 if (e->X_op == O_index && !e->X_op_symbol)
5578 return OPERAND_MATCH;
5581 /* immediate operands: */
5582 case IA64_OPND_CNT2a:
5583 case IA64_OPND_LEN4:
5584 case IA64_OPND_LEN6:
5585 bits = operand_width (idesc->operands[index]);
5586 if (e->X_op == O_constant)
5588 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5589 return OPERAND_MATCH;
5591 return OPERAND_OUT_OF_RANGE;
5595 case IA64_OPND_CNT2b:
5596 if (e->X_op == O_constant)
5598 if ((bfd_vma) (e->X_add_number - 1) < 3)
5599 return OPERAND_MATCH;
5601 return OPERAND_OUT_OF_RANGE;
5605 case IA64_OPND_CNT2c:
5606 val = e->X_add_number;
5607 if (e->X_op == O_constant)
5609 if ((val == 0 || val == 7 || val == 15 || val == 16))
5610 return OPERAND_MATCH;
5612 return OPERAND_OUT_OF_RANGE;
5617 /* SOR must be an integer multiple of 8 */
5618 if (e->X_op == O_constant && e->X_add_number & 0x7)
5619 return OPERAND_OUT_OF_RANGE;
5622 if (e->X_op == O_constant)
5624 if ((bfd_vma) e->X_add_number <= 96)
5625 return OPERAND_MATCH;
5627 return OPERAND_OUT_OF_RANGE;
5631 case IA64_OPND_IMMU62:
5632 if (e->X_op == O_constant)
5634 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5635 return OPERAND_MATCH;
5637 return OPERAND_OUT_OF_RANGE;
5641 /* FIXME -- need 62-bit relocation type */
5642 as_bad (_("62-bit relocation not yet implemented"));
5646 case IA64_OPND_IMMU64:
5647 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5648 || e->X_op == O_subtract)
5650 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5651 fix->code = BFD_RELOC_IA64_IMM64;
5652 if (e->X_op != O_subtract)
5654 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5655 if (e->X_op == O_pseudo_fixup)
5659 fix->opnd = idesc->operands[index];
5662 ++CURR_SLOT.num_fixups;
5663 return OPERAND_MATCH;
5665 else if (e->X_op == O_constant)
5666 return OPERAND_MATCH;
5669 case IA64_OPND_CCNT5:
5670 case IA64_OPND_CNT5:
5671 case IA64_OPND_CNT6:
5672 case IA64_OPND_CPOS6a:
5673 case IA64_OPND_CPOS6b:
5674 case IA64_OPND_CPOS6c:
5675 case IA64_OPND_IMMU2:
5676 case IA64_OPND_IMMU7a:
5677 case IA64_OPND_IMMU7b:
5678 case IA64_OPND_IMMU21:
5679 case IA64_OPND_IMMU24:
5680 case IA64_OPND_MBTYPE4:
5681 case IA64_OPND_MHTYPE8:
5682 case IA64_OPND_POS6:
5683 bits = operand_width (idesc->operands[index]);
5684 if (e->X_op == O_constant)
5686 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5687 return OPERAND_MATCH;
5689 return OPERAND_OUT_OF_RANGE;
5693 case IA64_OPND_IMMU9:
5694 bits = operand_width (idesc->operands[index]);
5695 if (e->X_op == O_constant)
5697 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5699 int lobits = e->X_add_number & 0x3;
5700 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5701 e->X_add_number |= (bfd_vma) 0x3;
5702 return OPERAND_MATCH;
5705 return OPERAND_OUT_OF_RANGE;
5709 case IA64_OPND_IMM44:
5710 /* least 16 bits must be zero */
5711 if ((e->X_add_number & 0xffff) != 0)
5712 /* XXX technically, this is wrong: we should not be issuing warning
5713 messages until we're sure this instruction pattern is going to
5715 as_warn (_("lower 16 bits of mask ignored"));
5717 if (e->X_op == O_constant)
5719 if (((e->X_add_number >= 0
5720 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5721 || (e->X_add_number < 0
5722 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5725 if (e->X_add_number >= 0
5726 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5728 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5730 return OPERAND_MATCH;
5733 return OPERAND_OUT_OF_RANGE;
5737 case IA64_OPND_IMM17:
5738 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5739 if (e->X_op == O_constant)
5741 if (((e->X_add_number >= 0
5742 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5743 || (e->X_add_number < 0
5744 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5747 if (e->X_add_number >= 0
5748 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5750 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5752 return OPERAND_MATCH;
5755 return OPERAND_OUT_OF_RANGE;
5759 case IA64_OPND_IMM14:
5760 case IA64_OPND_IMM22:
5762 case IA64_OPND_IMM1:
5763 case IA64_OPND_IMM8:
5764 case IA64_OPND_IMM8U4:
5765 case IA64_OPND_IMM8M1:
5766 case IA64_OPND_IMM8M1U4:
5767 case IA64_OPND_IMM8M1U8:
5768 case IA64_OPND_IMM9a:
5769 case IA64_OPND_IMM9b:
5770 bits = operand_width (idesc->operands[index]);
5771 if (relocatable && (e->X_op == O_symbol
5772 || e->X_op == O_subtract
5773 || e->X_op == O_pseudo_fixup))
5775 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5777 if (idesc->operands[index] == IA64_OPND_IMM14)
5778 fix->code = BFD_RELOC_IA64_IMM14;
5780 fix->code = BFD_RELOC_IA64_IMM22;
5782 if (e->X_op != O_subtract)
5784 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5785 if (e->X_op == O_pseudo_fixup)
5789 fix->opnd = idesc->operands[index];
5792 ++CURR_SLOT.num_fixups;
5793 return OPERAND_MATCH;
5795 else if (e->X_op != O_constant
5796 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5797 return OPERAND_MISMATCH;
5799 if (opnd == IA64_OPND_IMM8M1U4)
5801 /* Zero is not valid for unsigned compares that take an adjusted
5802 constant immediate range. */
5803 if (e->X_add_number == 0)
5804 return OPERAND_OUT_OF_RANGE;
5806 /* Sign-extend 32-bit unsigned numbers, so that the following range
5807 checks will work. */
5808 val = e->X_add_number;
5809 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5810 && ((val & ((bfd_vma) 1 << 31)) != 0))
5811 val = ((val << 32) >> 32);
5813 /* Check for 0x100000000. This is valid because
5814 0x100000000-1 is the same as ((uint32_t) -1). */
5815 if (val == ((bfd_signed_vma) 1 << 32))
5816 return OPERAND_MATCH;
5820 else if (opnd == IA64_OPND_IMM8M1U8)
5822 /* Zero is not valid for unsigned compares that take an adjusted
5823 constant immediate range. */
5824 if (e->X_add_number == 0)
5825 return OPERAND_OUT_OF_RANGE;
5827 /* Check for 0x10000000000000000. */
5828 if (e->X_op == O_big)
5830 if (generic_bignum[0] == 0
5831 && generic_bignum[1] == 0
5832 && generic_bignum[2] == 0
5833 && generic_bignum[3] == 0
5834 && generic_bignum[4] == 1)
5835 return OPERAND_MATCH;
5837 return OPERAND_OUT_OF_RANGE;
5840 val = e->X_add_number - 1;
5842 else if (opnd == IA64_OPND_IMM8M1)
5843 val = e->X_add_number - 1;
5844 else if (opnd == IA64_OPND_IMM8U4)
5846 /* Sign-extend 32-bit unsigned numbers, so that the following range
5847 checks will work. */
5848 val = e->X_add_number;
5849 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5850 && ((val & ((bfd_vma) 1 << 31)) != 0))
5851 val = ((val << 32) >> 32);
5854 val = e->X_add_number;
5856 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5857 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5858 return OPERAND_MATCH;
5860 return OPERAND_OUT_OF_RANGE;
5862 case IA64_OPND_INC3:
5863 /* +/- 1, 4, 8, 16 */
5864 val = e->X_add_number;
5867 if (e->X_op == O_constant)
5869 if ((val == 1 || val == 4 || val == 8 || val == 16))
5870 return OPERAND_MATCH;
5872 return OPERAND_OUT_OF_RANGE;
5876 case IA64_OPND_TGT25:
5877 case IA64_OPND_TGT25b:
5878 case IA64_OPND_TGT25c:
5879 case IA64_OPND_TGT64:
5880 if (e->X_op == O_symbol)
5882 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5883 if (opnd == IA64_OPND_TGT25)
5884 fix->code = BFD_RELOC_IA64_PCREL21F;
5885 else if (opnd == IA64_OPND_TGT25b)
5886 fix->code = BFD_RELOC_IA64_PCREL21M;
5887 else if (opnd == IA64_OPND_TGT25c)
5888 fix->code = BFD_RELOC_IA64_PCREL21B;
5889 else if (opnd == IA64_OPND_TGT64)
5890 fix->code = BFD_RELOC_IA64_PCREL60B;
5894 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5895 fix->opnd = idesc->operands[index];
5898 ++CURR_SLOT.num_fixups;
5899 return OPERAND_MATCH;
5901 case IA64_OPND_TAG13:
5902 case IA64_OPND_TAG13b:
5906 return OPERAND_MATCH;
5909 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5910 /* There are no external relocs for TAG13/TAG13b fields, so we
5911 create a dummy reloc. This will not live past md_apply_fix3. */
5912 fix->code = BFD_RELOC_UNUSED;
5913 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5914 fix->opnd = idesc->operands[index];
5917 ++CURR_SLOT.num_fixups;
5918 return OPERAND_MATCH;
5925 case IA64_OPND_LDXMOV:
5926 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5927 fix->code = BFD_RELOC_IA64_LDXMOV;
5928 fix->opnd = idesc->operands[index];
5931 ++CURR_SLOT.num_fixups;
5932 return OPERAND_MATCH;
5937 return OPERAND_MISMATCH;
5946 memset (e, 0, sizeof (*e));
5949 if (*input_line_pointer != '}')
5951 sep = *input_line_pointer++;
5955 if (!md.manual_bundling)
5956 as_warn ("Found '}' when manual bundling is off");
5958 CURR_SLOT.manual_bundling_off = 1;
5959 md.manual_bundling = 0;
5965 /* Returns the next entry in the opcode table that matches the one in
5966 IDESC, and frees the entry in IDESC. If no matching entry is
5967 found, NULL is returned instead. */
5969 static struct ia64_opcode *
5970 get_next_opcode (struct ia64_opcode *idesc)
5972 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5973 ia64_free_opcode (idesc);
5977 /* Parse the operands for the opcode and find the opcode variant that
5978 matches the specified operands, or NULL if no match is possible. */
5980 static struct ia64_opcode *
5981 parse_operands (idesc)
5982 struct ia64_opcode *idesc;
5984 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5985 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5986 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5987 enum operand_match_result result;
5989 char *first_arg = 0, *end, *saved_input_pointer;
5992 assert (strlen (idesc->name) <= 128);
5994 strcpy (mnemonic, idesc->name);
5995 if (idesc->operands[2] == IA64_OPND_SOF
5996 || idesc->operands[1] == IA64_OPND_SOF)
5998 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5999 can't parse the first operand until we have parsed the
6000 remaining operands of the "alloc" instruction. */
6002 first_arg = input_line_pointer;
6003 end = strchr (input_line_pointer, '=');
6006 as_bad ("Expected separator `='");
6009 input_line_pointer = end + 1;
6016 if (i < NELEMS (CURR_SLOT.opnd))
6018 sep = parse_operand (CURR_SLOT.opnd + i);
6019 if (CURR_SLOT.opnd[i].X_op == O_absent)
6026 sep = parse_operand (&dummy);
6027 if (dummy.X_op == O_absent)
6033 if (sep != '=' && sep != ',')
6038 if (num_outputs > 0)
6039 as_bad ("Duplicate equal sign (=) in instruction");
6041 num_outputs = i + 1;
6046 as_bad ("Illegal operand separator `%c'", sep);
6050 if (idesc->operands[2] == IA64_OPND_SOF
6051 || idesc->operands[1] == IA64_OPND_SOF)
6053 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
6054 know (strcmp (idesc->name, "alloc") == 0);
6055 i = (CURR_SLOT.opnd[1].X_op == O_register
6056 && CURR_SLOT.opnd[1].X_add_number == REG_AR + AR_PFS) ? 2 : 1;
6057 if (num_operands == i + 3 /* first_arg not included in this count! */
6058 && CURR_SLOT.opnd[i].X_op == O_constant
6059 && CURR_SLOT.opnd[i + 1].X_op == O_constant
6060 && CURR_SLOT.opnd[i + 2].X_op == O_constant
6061 && CURR_SLOT.opnd[i + 3].X_op == O_constant)
6063 sof = set_regstack (CURR_SLOT.opnd[i].X_add_number,
6064 CURR_SLOT.opnd[i + 1].X_add_number,
6065 CURR_SLOT.opnd[i + 2].X_add_number,
6066 CURR_SLOT.opnd[i + 3].X_add_number);
6068 /* now we can parse the first arg: */
6069 saved_input_pointer = input_line_pointer;
6070 input_line_pointer = first_arg;
6071 sep = parse_operand (CURR_SLOT.opnd + 0);
6073 --num_outputs; /* force error */
6074 input_line_pointer = saved_input_pointer;
6076 CURR_SLOT.opnd[i].X_add_number = sof;
6077 CURR_SLOT.opnd[i + 1].X_add_number
6078 = sof - CURR_SLOT.opnd[i + 2].X_add_number;
6079 CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3];
6083 highest_unmatched_operand = -4;
6084 curr_out_of_range_pos = -1;
6086 for (; idesc; idesc = get_next_opcode (idesc))
6088 if (num_outputs != idesc->num_outputs)
6089 continue; /* mismatch in # of outputs */
6090 if (highest_unmatched_operand < 0)
6091 highest_unmatched_operand |= 1;
6092 if (num_operands > NELEMS (idesc->operands)
6093 || (num_operands < NELEMS (idesc->operands)
6094 && idesc->operands[num_operands])
6095 || (num_operands > 0 && !idesc->operands[num_operands - 1]))
6096 continue; /* mismatch in number of arguments */
6097 if (highest_unmatched_operand < 0)
6098 highest_unmatched_operand |= 2;
6100 CURR_SLOT.num_fixups = 0;
6102 /* Try to match all operands. If we see an out-of-range operand,
6103 then continue trying to match the rest of the operands, since if
6104 the rest match, then this idesc will give the best error message. */
6106 out_of_range_pos = -1;
6107 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
6109 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
6110 if (result != OPERAND_MATCH)
6112 if (result != OPERAND_OUT_OF_RANGE)
6114 if (out_of_range_pos < 0)
6115 /* remember position of the first out-of-range operand: */
6116 out_of_range_pos = i;
6120 /* If we did not match all operands, or if at least one operand was
6121 out-of-range, then this idesc does not match. Keep track of which
6122 idesc matched the most operands before failing. If we have two
6123 idescs that failed at the same position, and one had an out-of-range
6124 operand, then prefer the out-of-range operand. Thus if we have
6125 "add r0=0x1000000,r1" we get an error saying the constant is out
6126 of range instead of an error saying that the constant should have been
6129 if (i != num_operands || out_of_range_pos >= 0)
6131 if (i > highest_unmatched_operand
6132 || (i == highest_unmatched_operand
6133 && out_of_range_pos > curr_out_of_range_pos))
6135 highest_unmatched_operand = i;
6136 if (out_of_range_pos >= 0)
6138 expected_operand = idesc->operands[out_of_range_pos];
6139 error_pos = out_of_range_pos;
6143 expected_operand = idesc->operands[i];
6146 curr_out_of_range_pos = out_of_range_pos;
6155 if (expected_operand)
6156 as_bad ("Operand %u of `%s' should be %s",
6157 error_pos + 1, mnemonic,
6158 elf64_ia64_operands[expected_operand].desc);
6159 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1))
6160 as_bad ("Wrong number of output operands");
6161 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2))
6162 as_bad ("Wrong number of input operands");
6164 as_bad ("Operand mismatch");
6171 build_insn (slot, insnp)
6175 const struct ia64_operand *odesc, *o2desc;
6176 struct ia64_opcode *idesc = slot->idesc;
6177 bfd_signed_vma insn, val;
6181 insn = idesc->opcode | slot->qp_regno;
6183 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6185 if (slot->opnd[i].X_op == O_register
6186 || slot->opnd[i].X_op == O_constant
6187 || slot->opnd[i].X_op == O_index)
6188 val = slot->opnd[i].X_add_number;
6189 else if (slot->opnd[i].X_op == O_big)
6191 /* This must be the value 0x10000000000000000. */
6192 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6198 switch (idesc->operands[i])
6200 case IA64_OPND_IMMU64:
6201 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6202 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6203 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6204 | (((val >> 63) & 0x1) << 36));
6207 case IA64_OPND_IMMU62:
6208 val &= 0x3fffffffffffffffULL;
6209 if (val != slot->opnd[i].X_add_number)
6210 as_warn (_("Value truncated to 62 bits"));
6211 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6212 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6215 case IA64_OPND_TGT64:
6217 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6218 insn |= ((((val >> 59) & 0x1) << 36)
6219 | (((val >> 0) & 0xfffff) << 13));
6250 case IA64_OPND_R3_2:
6251 case IA64_OPND_CPUID_R3:
6252 case IA64_OPND_DBR_R3:
6253 case IA64_OPND_DTR_R3:
6254 case IA64_OPND_ITR_R3:
6255 case IA64_OPND_IBR_R3:
6257 case IA64_OPND_MSR_R3:
6258 case IA64_OPND_PKR_R3:
6259 case IA64_OPND_PMC_R3:
6260 case IA64_OPND_PMD_R3:
6261 case IA64_OPND_RR_R3:
6269 odesc = elf64_ia64_operands + idesc->operands[i];
6270 err = (*odesc->insert) (odesc, val, &insn);
6272 as_bad_where (slot->src_file, slot->src_line,
6273 "Bad operand value: %s", err);
6274 if (idesc->flags & IA64_OPCODE_PSEUDO)
6276 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6277 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6279 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6280 (*o2desc->insert) (o2desc, val, &insn);
6282 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6283 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6284 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6286 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6287 (*o2desc->insert) (o2desc, 64 - val, &insn);
6297 int manual_bundling_off = 0, manual_bundling = 0;
6298 enum ia64_unit required_unit, insn_unit = 0;
6299 enum ia64_insn_type type[3], insn_type;
6300 unsigned int template, orig_template;
6301 bfd_vma insn[3] = { -1, -1, -1 };
6302 struct ia64_opcode *idesc;
6303 int end_of_insn_group = 0, user_template = -1;
6304 int n, i, j, first, curr;
6305 unw_rec_list *ptr, *last_ptr, *end_ptr;
6306 bfd_vma t0 = 0, t1 = 0;
6307 struct label_fix *lfix;
6308 struct insn_fix *ifix;
6314 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6315 know (first >= 0 & first < NUM_SLOTS);
6316 n = MIN (3, md.num_slots_in_use);
6318 /* Determine template: user user_template if specified, best match
6321 if (md.slot[first].user_template >= 0)
6322 user_template = template = md.slot[first].user_template;
6325 /* Auto select appropriate template. */
6326 memset (type, 0, sizeof (type));
6328 for (i = 0; i < n; ++i)
6330 if (md.slot[curr].label_fixups && i != 0)
6332 type[i] = md.slot[curr].idesc->type;
6333 curr = (curr + 1) % NUM_SLOTS;
6335 template = best_template[type[0]][type[1]][type[2]];
6338 /* initialize instructions with appropriate nops: */
6339 for (i = 0; i < 3; ++i)
6340 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6344 /* Check to see if this bundle is at an offset that is a multiple of 16-bytes
6345 from the start of the frag. */
6346 addr_mod = frag_now_fix () & 15;
6347 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
6348 as_bad (_("instruction address is not a multiple of 16"));
6349 frag_now->insn_addr = addr_mod;
6350 frag_now->has_code = 1;
6352 /* now fill in slots with as many insns as possible: */
6354 idesc = md.slot[curr].idesc;
6355 end_of_insn_group = 0;
6356 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6358 /* If we have unwind records, we may need to update some now. */
6359 ptr = md.slot[curr].unwind_record;
6362 /* Find the last prologue/body record in the list for the current
6363 insn, and set the slot number for all records up to that point.
6364 This needs to be done now, because prologue/body records refer to
6365 the current point, not the point after the instruction has been
6366 issued. This matters because there may have been nops emitted
6367 meanwhile. Any non-prologue non-body record followed by a
6368 prologue/body record must also refer to the current point. */
6370 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6371 for (; ptr != end_ptr; ptr = ptr->next)
6372 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6373 || ptr->r.type == body)
6377 /* Make last_ptr point one after the last prologue/body
6379 last_ptr = last_ptr->next;
6380 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6383 ptr->slot_number = (unsigned long) f + i;
6384 ptr->slot_frag = frag_now;
6386 /* Remove the initialized records, so that we won't accidentally
6387 update them again if we insert a nop and continue. */
6388 md.slot[curr].unwind_record = last_ptr;
6392 manual_bundling_off = md.slot[curr].manual_bundling_off;
6393 if (md.slot[curr].manual_bundling_on)
6396 manual_bundling = 1;
6398 break; /* Need to start a new bundle. */
6401 if (idesc->flags & IA64_OPCODE_SLOT2)
6403 if (manual_bundling && !manual_bundling_off)
6405 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6406 "`%s' must be last in bundle", idesc->name);
6408 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6412 if (idesc->flags & IA64_OPCODE_LAST)
6415 unsigned int required_template;
6417 /* If we need a stop bit after an M slot, our only choice is
6418 template 5 (M;;MI). If we need a stop bit after a B
6419 slot, our only choice is to place it at the end of the
6420 bundle, because the only available templates are MIB,
6421 MBB, BBB, MMB, and MFB. We don't handle anything other
6422 than M and B slots because these are the only kind of
6423 instructions that can have the IA64_OPCODE_LAST bit set. */
6424 required_template = template;
6425 switch (idesc->type)
6429 required_template = 5;
6437 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6438 "Internal error: don't know how to force %s to end"
6439 "of instruction group", idesc->name);
6444 && (i > required_slot
6445 || (required_slot == 2 && !manual_bundling_off)
6446 || (user_template >= 0
6447 /* Changing from MMI to M;MI is OK. */
6448 && (template ^ required_template) > 1)))
6450 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6451 "`%s' must be last in instruction group",
6453 if (i < 2 && required_slot == 2 && !manual_bundling_off)
6454 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6456 if (required_slot < i)
6457 /* Can't fit this instruction. */
6461 if (required_template != template)
6463 /* If we switch the template, we need to reset the NOPs
6464 after slot i. The slot-types of the instructions ahead
6465 of i never change, so we don't need to worry about
6466 changing NOPs in front of this slot. */
6467 for (j = i; j < 3; ++j)
6468 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6470 template = required_template;
6472 if (curr != first && md.slot[curr].label_fixups)
6474 if (manual_bundling)
6476 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6477 "Label must be first in a bundle");
6478 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6480 /* This insn must go into the first slot of a bundle. */
6484 if (end_of_insn_group && md.num_slots_in_use >= 1)
6486 /* We need an instruction group boundary in the middle of a
6487 bundle. See if we can switch to an other template with
6488 an appropriate boundary. */
6490 orig_template = template;
6491 if (i == 1 && (user_template == 4
6492 || (user_template < 0
6493 && (ia64_templ_desc[template].exec_unit[0]
6497 end_of_insn_group = 0;
6499 else if (i == 2 && (user_template == 0
6500 || (user_template < 0
6501 && (ia64_templ_desc[template].exec_unit[1]
6503 /* This test makes sure we don't switch the template if
6504 the next instruction is one that needs to be first in
6505 an instruction group. Since all those instructions are
6506 in the M group, there is no way such an instruction can
6507 fit in this bundle even if we switch the template. The
6508 reason we have to check for this is that otherwise we
6509 may end up generating "MI;;I M.." which has the deadly
6510 effect that the second M instruction is no longer the
6511 first in the group! --davidm 99/12/16 */
6512 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6515 end_of_insn_group = 0;
6518 && user_template == 0
6519 && !(idesc->flags & IA64_OPCODE_FIRST))
6520 /* Use the next slot. */
6522 else if (curr != first)
6523 /* can't fit this insn */
6526 if (template != orig_template)
6527 /* if we switch the template, we need to reset the NOPs
6528 after slot i. The slot-types of the instructions ahead
6529 of i never change, so we don't need to worry about
6530 changing NOPs in front of this slot. */
6531 for (j = i; j < 3; ++j)
6532 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6534 required_unit = ia64_templ_desc[template].exec_unit[i];
6536 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6537 if (idesc->type == IA64_TYPE_DYN)
6539 enum ia64_opnd opnd1, opnd2;
6541 if ((strcmp (idesc->name, "nop") == 0)
6542 || (strcmp (idesc->name, "hint") == 0)
6543 || (strcmp (idesc->name, "break") == 0))
6544 insn_unit = required_unit;
6545 else if (strcmp (idesc->name, "chk.s") == 0
6546 || strcmp (idesc->name, "mov") == 0)
6548 insn_unit = IA64_UNIT_M;
6549 if (required_unit == IA64_UNIT_I
6550 || (required_unit == IA64_UNIT_F && template == 6))
6551 insn_unit = IA64_UNIT_I;
6554 as_fatal ("emit_one_bundle: unexpected dynamic op");
6556 sprintf (mnemonic, "%s.%c", idesc->name, "?imbfxx"[insn_unit]);
6557 opnd1 = idesc->operands[0];
6558 opnd2 = idesc->operands[1];
6559 ia64_free_opcode (idesc);
6560 idesc = ia64_find_opcode (mnemonic);
6561 /* moves to/from ARs have collisions */
6562 if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3)
6564 while (idesc != NULL
6565 && (idesc->operands[0] != opnd1
6566 || idesc->operands[1] != opnd2))
6567 idesc = get_next_opcode (idesc);
6569 md.slot[curr].idesc = idesc;
6573 insn_type = idesc->type;
6574 insn_unit = IA64_UNIT_NIL;
6578 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6579 insn_unit = required_unit;
6581 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6582 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6583 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6584 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6585 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6590 if (insn_unit != required_unit)
6592 if (required_unit == IA64_UNIT_L
6593 && insn_unit == IA64_UNIT_I
6594 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6596 /* we got ourselves an MLX template but the current
6597 instruction isn't an X-unit, or an I-unit instruction
6598 that can go into the X slot of an MLX template. Duh. */
6599 if (md.num_slots_in_use >= NUM_SLOTS)
6601 as_bad_where (md.slot[curr].src_file,
6602 md.slot[curr].src_line,
6603 "`%s' can't go in X slot of "
6604 "MLX template", idesc->name);
6605 /* drop this insn so we don't livelock: */
6606 --md.num_slots_in_use;
6610 continue; /* try next slot */
6613 if (debug_type == DEBUG_DWARF2 || md.slot[curr].loc_directive_seen)
6615 bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6617 md.slot[curr].loc_directive_seen = 0;
6618 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6621 build_insn (md.slot + curr, insn + i);
6623 ptr = md.slot[curr].unwind_record;
6626 /* Set slot numbers for all remaining unwind records belonging to the
6627 current insn. There can not be any prologue/body unwind records
6629 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6630 for (; ptr != end_ptr; ptr = ptr->next)
6632 ptr->slot_number = (unsigned long) f + i;
6633 ptr->slot_frag = frag_now;
6635 md.slot[curr].unwind_record = NULL;
6638 if (required_unit == IA64_UNIT_L)
6641 /* skip one slot for long/X-unit instructions */
6644 --md.num_slots_in_use;
6646 /* now is a good time to fix up the labels for this insn: */
6647 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6649 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6650 symbol_set_frag (lfix->sym, frag_now);
6652 /* and fix up the tags also. */
6653 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6655 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6656 symbol_set_frag (lfix->sym, frag_now);
6659 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6661 ifix = md.slot[curr].fixup + j;
6662 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6663 &ifix->expr, ifix->is_pcrel, ifix->code);
6664 fix->tc_fix_data.opnd = ifix->opnd;
6665 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6666 fix->fx_file = md.slot[curr].src_file;
6667 fix->fx_line = md.slot[curr].src_line;
6670 end_of_insn_group = md.slot[curr].end_of_insn_group;
6673 ia64_free_opcode (md.slot[curr].idesc);
6674 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6675 md.slot[curr].user_template = -1;
6677 if (manual_bundling_off)
6679 manual_bundling = 0;
6682 curr = (curr + 1) % NUM_SLOTS;
6683 idesc = md.slot[curr].idesc;
6685 if (manual_bundling > 0)
6687 if (md.num_slots_in_use > 0)
6689 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6690 "`%s' does not fit into %s template",
6691 idesc->name, ia64_templ_desc[template].name);
6692 --md.num_slots_in_use;
6695 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6696 "Missing '}' at end of file");
6698 know (md.num_slots_in_use < NUM_SLOTS);
6700 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6701 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6703 number_to_chars_littleendian (f + 0, t0, 8);
6704 number_to_chars_littleendian (f + 8, t1, 8);
6708 unwind.list->next_slot_number = (unsigned long) f + 16;
6709 unwind.list->next_slot_frag = frag_now;
6714 md_parse_option (c, arg)
6721 /* Switches from the Intel assembler. */
6723 if (strcmp (arg, "ilp64") == 0
6724 || strcmp (arg, "lp64") == 0
6725 || strcmp (arg, "p64") == 0)
6727 md.flags |= EF_IA_64_ABI64;
6729 else if (strcmp (arg, "ilp32") == 0)
6731 md.flags &= ~EF_IA_64_ABI64;
6733 else if (strcmp (arg, "le") == 0)
6735 md.flags &= ~EF_IA_64_BE;
6736 default_big_endian = 0;
6738 else if (strcmp (arg, "be") == 0)
6740 md.flags |= EF_IA_64_BE;
6741 default_big_endian = 1;
6743 else if (strncmp (arg, "unwind-check=", 13) == 0)
6746 if (strcmp (arg, "warning") == 0)
6747 md.unwind_check = unwind_check_warning;
6748 else if (strcmp (arg, "error") == 0)
6749 md.unwind_check = unwind_check_error;
6758 if (strcmp (arg, "so") == 0)
6760 /* Suppress signon message. */
6762 else if (strcmp (arg, "pi") == 0)
6764 /* Reject privileged instructions. FIXME */
6766 else if (strcmp (arg, "us") == 0)
6768 /* Allow union of signed and unsigned range. FIXME */
6770 else if (strcmp (arg, "close_fcalls") == 0)
6772 /* Do not resolve global function calls. */
6779 /* temp[="prefix"] Insert temporary labels into the object file
6780 symbol table prefixed by "prefix".
6781 Default prefix is ":temp:".
6786 /* indirect=<tgt> Assume unannotated indirect branches behavior
6787 according to <tgt> --
6788 exit: branch out from the current context (default)
6789 labels: all labels in context may be branch targets
6791 if (strncmp (arg, "indirect=", 9) != 0)
6796 /* -X conflicts with an ignored option, use -x instead */
6798 if (!arg || strcmp (arg, "explicit") == 0)
6800 /* set default mode to explicit */
6801 md.default_explicit_mode = 1;
6804 else if (strcmp (arg, "auto") == 0)
6806 md.default_explicit_mode = 0;
6808 else if (strcmp (arg, "debug") == 0)
6812 else if (strcmp (arg, "debugx") == 0)
6814 md.default_explicit_mode = 1;
6819 as_bad (_("Unrecognized option '-x%s'"), arg);
6824 /* nops Print nops statistics. */
6827 /* GNU specific switches for gcc. */
6828 case OPTION_MCONSTANT_GP:
6829 md.flags |= EF_IA_64_CONS_GP;
6832 case OPTION_MAUTO_PIC:
6833 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6844 md_show_usage (stream)
6849 --mconstant-gp mark output file as using the constant-GP model\n\
6850 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6851 --mauto-pic mark output file as using the constant-GP model\n\
6852 without function descriptors (sets ELF header flag\n\
6853 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6854 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6855 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6856 -munwind-check=[warning|error]\n\
6857 unwind directive check (default -munwind-check=warning)\n\
6858 -x | -xexplicit turn on dependency violation checking (default)\n\
6859 -xauto automagically remove dependency violations\n\
6860 -xdebug debug dependency violation checker\n"),
6865 ia64_after_parse_args ()
6867 if (debug_type == DEBUG_STABS)
6868 as_fatal (_("--gstabs is not supported for ia64"));
6871 /* Return true if TYPE fits in TEMPL at SLOT. */
6874 match (int templ, int type, int slot)
6876 enum ia64_unit unit;
6879 unit = ia64_templ_desc[templ].exec_unit[slot];
6882 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6884 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6886 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6887 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6888 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6889 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6890 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6891 default: result = 0; break;
6896 /* Add a bit of extra goodness if a nop of type F or B would fit
6897 in TEMPL at SLOT. */
6900 extra_goodness (int templ, int slot)
6902 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6904 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6909 /* This function is called once, at assembler startup time. It sets
6910 up all the tables, etc. that the MD part of the assembler will need
6911 that can be determined before arguments are parsed. */
6915 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6920 md.explicit_mode = md.default_explicit_mode;
6922 bfd_set_section_alignment (stdoutput, text_section, 4);
6924 /* Make sure function pointers get initialized. */
6925 target_big_endian = -1;
6926 dot_byteorder (default_big_endian);
6928 alias_hash = hash_new ();
6929 alias_name_hash = hash_new ();
6930 secalias_hash = hash_new ();
6931 secalias_name_hash = hash_new ();
6933 pseudo_func[FUNC_DTP_MODULE].u.sym =
6934 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6935 &zero_address_frag);
6937 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6938 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6939 &zero_address_frag);
6941 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6942 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6943 &zero_address_frag);
6945 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6946 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6947 &zero_address_frag);
6949 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6950 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6951 &zero_address_frag);
6953 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6954 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6955 &zero_address_frag);
6957 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6958 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6959 &zero_address_frag);
6961 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6962 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6963 &zero_address_frag);
6965 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6966 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6967 &zero_address_frag);
6969 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6970 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6971 &zero_address_frag);
6973 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6974 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6975 &zero_address_frag);
6977 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6978 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6979 &zero_address_frag);
6981 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6982 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6983 &zero_address_frag);
6985 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6986 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6987 &zero_address_frag);
6989 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6990 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6991 &zero_address_frag);
6993 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6994 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6995 &zero_address_frag);
6997 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6998 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6999 &zero_address_frag);
7001 /* Compute the table of best templates. We compute goodness as a
7002 base 4 value, in which each match counts for 3, each F counts
7003 for 2, each B counts for 1. This should maximize the number of
7004 F and B nops in the chosen bundles, which is good because these
7005 pipelines are least likely to be overcommitted. */
7006 for (i = 0; i < IA64_NUM_TYPES; ++i)
7007 for (j = 0; j < IA64_NUM_TYPES; ++j)
7008 for (k = 0; k < IA64_NUM_TYPES; ++k)
7011 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
7014 if (match (t, i, 0))
7016 if (match (t, j, 1))
7018 if (match (t, k, 2))
7019 goodness = 3 + 3 + 3;
7021 goodness = 3 + 3 + extra_goodness (t, 2);
7023 else if (match (t, j, 2))
7024 goodness = 3 + 3 + extra_goodness (t, 1);
7028 goodness += extra_goodness (t, 1);
7029 goodness += extra_goodness (t, 2);
7032 else if (match (t, i, 1))
7034 if (match (t, j, 2))
7037 goodness = 3 + extra_goodness (t, 2);
7039 else if (match (t, i, 2))
7040 goodness = 3 + extra_goodness (t, 1);
7042 if (goodness > best)
7045 best_template[i][j][k] = t;
7050 for (i = 0; i < NUM_SLOTS; ++i)
7051 md.slot[i].user_template = -1;
7053 md.pseudo_hash = hash_new ();
7054 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
7056 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
7057 (void *) (pseudo_opcode + i));
7059 as_fatal ("ia64.md_begin: can't hash `%s': %s",
7060 pseudo_opcode[i].name, err);
7063 md.reg_hash = hash_new ();
7064 md.dynreg_hash = hash_new ();
7065 md.const_hash = hash_new ();
7066 md.entry_hash = hash_new ();
7068 /* general registers: */
7071 for (i = 0; i < total; ++i)
7073 sprintf (name, "r%d", i - REG_GR);
7074 md.regsym[i] = declare_register (name, i);
7077 /* floating point registers: */
7079 for (; i < total; ++i)
7081 sprintf (name, "f%d", i - REG_FR);
7082 md.regsym[i] = declare_register (name, i);
7085 /* application registers: */
7088 for (; i < total; ++i)
7090 sprintf (name, "ar%d", i - REG_AR);
7091 md.regsym[i] = declare_register (name, i);
7094 /* control registers: */
7097 for (; i < total; ++i)
7099 sprintf (name, "cr%d", i - REG_CR);
7100 md.regsym[i] = declare_register (name, i);
7103 /* predicate registers: */
7105 for (; i < total; ++i)
7107 sprintf (name, "p%d", i - REG_P);
7108 md.regsym[i] = declare_register (name, i);
7111 /* branch registers: */
7113 for (; i < total; ++i)
7115 sprintf (name, "b%d", i - REG_BR);
7116 md.regsym[i] = declare_register (name, i);
7119 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
7120 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
7121 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
7122 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
7123 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
7124 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
7125 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
7127 for (i = 0; i < NELEMS (indirect_reg); ++i)
7129 regnum = indirect_reg[i].regnum;
7130 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
7133 /* define synonyms for application registers: */
7134 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
7135 md.regsym[i] = declare_register (ar[i - REG_AR].name,
7136 REG_AR + ar[i - REG_AR].regnum);
7138 /* define synonyms for control registers: */
7139 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
7140 md.regsym[i] = declare_register (cr[i - REG_CR].name,
7141 REG_CR + cr[i - REG_CR].regnum);
7143 declare_register ("gp", REG_GR + 1);
7144 declare_register ("sp", REG_GR + 12);
7145 declare_register ("rp", REG_BR + 0);
7147 /* pseudo-registers used to specify unwind info: */
7148 declare_register ("psp", REG_PSP);
7150 declare_register_set ("ret", 4, REG_GR + 8);
7151 declare_register_set ("farg", 8, REG_FR + 8);
7152 declare_register_set ("fret", 8, REG_FR + 8);
7154 for (i = 0; i < NELEMS (const_bits); ++i)
7156 err = hash_insert (md.const_hash, const_bits[i].name,
7157 (PTR) (const_bits + i));
7159 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
7163 /* Set the architecture and machine depending on defaults and command line
7165 if (md.flags & EF_IA_64_ABI64)
7166 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
7168 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
7171 as_warn (_("Could not set architecture and machine"));
7173 /* Set the pointer size and pointer shift size depending on md.flags */
7175 if (md.flags & EF_IA_64_ABI64)
7177 md.pointer_size = 8; /* pointers are 8 bytes */
7178 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
7182 md.pointer_size = 4; /* pointers are 4 bytes */
7183 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
7186 md.mem_offset.hint = 0;
7189 md.entry_labels = NULL;
7192 /* Set the default options in md. Cannot do this in md_begin because
7193 that is called after md_parse_option which is where we set the
7194 options in md based on command line options. */
7197 ia64_init (argc, argv)
7198 int argc ATTRIBUTE_UNUSED;
7199 char **argv ATTRIBUTE_UNUSED;
7201 md.flags = MD_FLAGS_DEFAULT;
7202 /* FIXME: We should change it to unwind_check_error someday. */
7203 md.unwind_check = unwind_check_warning;
7206 /* Return a string for the target object file format. */
7209 ia64_target_format ()
7211 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7213 if (md.flags & EF_IA_64_BE)
7215 if (md.flags & EF_IA_64_ABI64)
7216 #if defined(TE_AIX50)
7217 return "elf64-ia64-aix-big";
7218 #elif defined(TE_HPUX)
7219 return "elf64-ia64-hpux-big";
7221 return "elf64-ia64-big";
7224 #if defined(TE_AIX50)
7225 return "elf32-ia64-aix-big";
7226 #elif defined(TE_HPUX)
7227 return "elf32-ia64-hpux-big";
7229 return "elf32-ia64-big";
7234 if (md.flags & EF_IA_64_ABI64)
7236 return "elf64-ia64-aix-little";
7238 return "elf64-ia64-little";
7242 return "elf32-ia64-aix-little";
7244 return "elf32-ia64-little";
7249 return "unknown-format";
7253 ia64_end_of_source ()
7255 /* terminate insn group upon reaching end of file: */
7256 insn_group_break (1, 0, 0);
7258 /* emits slots we haven't written yet: */
7259 ia64_flush_insns ();
7261 bfd_set_private_flags (stdoutput, md.flags);
7263 md.mem_offset.hint = 0;
7269 if (md.qp.X_op == O_register)
7270 as_bad ("qualifying predicate not followed by instruction");
7271 md.qp.X_op = O_absent;
7273 if (ignore_input ())
7276 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7278 if (md.detect_dv && !md.explicit_mode)
7279 as_warn (_("Explicit stops are ignored in auto mode"));
7281 insn_group_break (1, 0, 0);
7285 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7287 static int defining_tag = 0;
7290 ia64_unrecognized_line (ch)
7296 expression (&md.qp);
7297 if (*input_line_pointer++ != ')')
7299 as_bad ("Expected ')'");
7302 if (md.qp.X_op != O_register)
7304 as_bad ("Qualifying predicate expected");
7307 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7309 as_bad ("Predicate register expected");
7315 if (md.manual_bundling)
7316 as_warn ("Found '{' when manual bundling is already turned on");
7318 CURR_SLOT.manual_bundling_on = 1;
7319 md.manual_bundling = 1;
7321 /* Bundling is only acceptable in explicit mode
7322 or when in default automatic mode. */
7323 if (md.detect_dv && !md.explicit_mode)
7325 if (!md.mode_explicitly_set
7326 && !md.default_explicit_mode)
7329 as_warn (_("Found '{' after explicit switch to automatic mode"));
7334 if (!md.manual_bundling)
7335 as_warn ("Found '}' when manual bundling is off");
7337 PREV_SLOT.manual_bundling_off = 1;
7338 md.manual_bundling = 0;
7340 /* switch back to automatic mode, if applicable */
7343 && !md.mode_explicitly_set
7344 && !md.default_explicit_mode)
7347 /* Allow '{' to follow on the same line. We also allow ";;", but that
7348 happens automatically because ';' is an end of line marker. */
7350 if (input_line_pointer[0] == '{')
7352 input_line_pointer++;
7353 return ia64_unrecognized_line ('{');
7356 demand_empty_rest_of_line ();
7366 if (md.qp.X_op == O_register)
7368 as_bad ("Tag must come before qualifying predicate.");
7372 /* This implements just enough of read_a_source_file in read.c to
7373 recognize labels. */
7374 if (is_name_beginner (*input_line_pointer))
7376 s = input_line_pointer;
7377 c = get_symbol_end ();
7379 else if (LOCAL_LABELS_FB
7380 && ISDIGIT (*input_line_pointer))
7383 while (ISDIGIT (*input_line_pointer))
7384 temp = (temp * 10) + *input_line_pointer++ - '0';
7385 fb_label_instance_inc (temp);
7386 s = fb_label_name (temp, 0);
7387 c = *input_line_pointer;
7396 /* Put ':' back for error messages' sake. */
7397 *input_line_pointer++ = ':';
7398 as_bad ("Expected ':'");
7405 /* Put ':' back for error messages' sake. */
7406 *input_line_pointer++ = ':';
7407 if (*input_line_pointer++ != ']')
7409 as_bad ("Expected ']'");
7414 as_bad ("Tag name expected");
7424 /* Not a valid line. */
7429 ia64_frob_label (sym)
7432 struct label_fix *fix;
7434 /* Tags need special handling since they are not bundle breaks like
7438 fix = obstack_alloc (¬es, sizeof (*fix));
7440 fix->next = CURR_SLOT.tag_fixups;
7441 CURR_SLOT.tag_fixups = fix;
7446 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7448 md.last_text_seg = now_seg;
7449 fix = obstack_alloc (¬es, sizeof (*fix));
7451 fix->next = CURR_SLOT.label_fixups;
7452 CURR_SLOT.label_fixups = fix;
7454 /* Keep track of how many code entry points we've seen. */
7455 if (md.path == md.maxpaths)
7458 md.entry_labels = (const char **)
7459 xrealloc ((void *) md.entry_labels,
7460 md.maxpaths * sizeof (char *));
7462 md.entry_labels[md.path++] = S_GET_NAME (sym);
7467 /* The HP-UX linker will give unresolved symbol errors for symbols
7468 that are declared but unused. This routine removes declared,
7469 unused symbols from an object. */
7471 ia64_frob_symbol (sym)
7474 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7475 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7476 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7477 && ! S_IS_EXTERNAL (sym)))
7484 ia64_flush_pending_output ()
7486 if (!md.keep_pending_output
7487 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7489 /* ??? This causes many unnecessary stop bits to be emitted.
7490 Unfortunately, it isn't clear if it is safe to remove this. */
7491 insn_group_break (1, 0, 0);
7492 ia64_flush_insns ();
7496 /* Do ia64-specific expression optimization. All that's done here is
7497 to transform index expressions that are either due to the indexing
7498 of rotating registers or due to the indexing of indirect register
7501 ia64_optimize_expr (l, op, r)
7510 if (l->X_op == O_register && r->X_op == O_constant)
7512 num_regs = (l->X_add_number >> 16);
7513 if ((unsigned) r->X_add_number >= num_regs)
7516 as_bad ("No current frame");
7518 as_bad ("Index out of range 0..%u", num_regs - 1);
7519 r->X_add_number = 0;
7521 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7524 else if (l->X_op == O_register && r->X_op == O_register)
7526 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7527 || l->X_add_number == IND_MEM)
7529 as_bad ("Indirect register set name expected");
7530 l->X_add_number = IND_CPUID;
7533 l->X_op_symbol = md.regsym[l->X_add_number];
7534 l->X_add_number = r->X_add_number;
7542 ia64_parse_name (name, e, nextcharP)
7547 struct const_desc *cdesc;
7548 struct dynreg *dr = 0;
7549 unsigned int regnum;
7556 enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE;
7558 /* Find what relocation pseudo-function we're dealing with. */
7559 for (idx = 0; idx < NELEMS (pseudo_func); ++idx)
7560 if (pseudo_func[idx].name
7561 && pseudo_func[idx].name[0] == name[1]
7562 && strcmp (pseudo_func[idx].name + 1, name + 2) == 0)
7564 pseudo_type = pseudo_func[idx].type;
7567 switch (pseudo_type)
7569 case PSEUDO_FUNC_RELOC:
7570 end = input_line_pointer;
7571 if (*nextcharP != '(')
7573 as_bad ("Expected '('");
7577 ++input_line_pointer;
7579 if (*input_line_pointer != ')')
7581 as_bad ("Missing ')'");
7585 ++input_line_pointer;
7586 if (e->X_op != O_symbol)
7588 if (e->X_op != O_pseudo_fixup)
7590 as_bad ("Not a symbolic expression");
7593 if (idx != FUNC_LT_RELATIVE)
7595 as_bad ("Illegal combination of relocation functions");
7598 switch (S_GET_VALUE (e->X_op_symbol))
7600 case FUNC_FPTR_RELATIVE:
7601 idx = FUNC_LT_FPTR_RELATIVE; break;
7602 case FUNC_DTP_MODULE:
7603 idx = FUNC_LT_DTP_MODULE; break;
7604 case FUNC_DTP_RELATIVE:
7605 idx = FUNC_LT_DTP_RELATIVE; break;
7606 case FUNC_TP_RELATIVE:
7607 idx = FUNC_LT_TP_RELATIVE; break;
7609 as_bad ("Illegal combination of relocation functions");
7613 /* Make sure gas doesn't get rid of local symbols that are used
7615 e->X_op = O_pseudo_fixup;
7616 e->X_op_symbol = pseudo_func[idx].u.sym;
7619 case PSEUDO_FUNC_CONST:
7620 e->X_op = O_constant;
7621 e->X_add_number = pseudo_func[idx].u.ival;
7624 case PSEUDO_FUNC_REG:
7625 e->X_op = O_register;
7626 e->X_add_number = pseudo_func[idx].u.ival;
7633 *nextcharP = *input_line_pointer;
7637 /* first see if NAME is a known register name: */
7638 sym = hash_find (md.reg_hash, name);
7641 e->X_op = O_register;
7642 e->X_add_number = S_GET_VALUE (sym);
7646 cdesc = hash_find (md.const_hash, name);
7649 e->X_op = O_constant;
7650 e->X_add_number = cdesc->value;
7654 /* check for inN, locN, or outN: */
7658 if (name[1] == 'n' && ISDIGIT (name[2]))
7666 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7674 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7687 /* The name is inN, locN, or outN; parse the register number. */
7688 regnum = strtoul (name, &end, 10);
7689 if (end > name && *end == '\0')
7691 if ((unsigned) regnum >= dr->num_regs)
7694 as_bad ("No current frame");
7696 as_bad ("Register number out of range 0..%u",
7700 e->X_op = O_register;
7701 e->X_add_number = dr->base + regnum;
7706 if ((dr = hash_find (md.dynreg_hash, name)))
7708 /* We've got ourselves the name of a rotating register set.
7709 Store the base register number in the low 16 bits of
7710 X_add_number and the size of the register set in the top 16
7712 e->X_op = O_register;
7713 e->X_add_number = dr->base | (dr->num_regs << 16);
7719 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7722 ia64_canonicalize_symbol_name (name)
7725 size_t len = strlen (name);
7726 if (len > 1 && name[len - 1] == '#')
7727 name[len - 1] = '\0';
7731 /* Return true if idesc is a conditional branch instruction. This excludes
7732 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7733 because they always read/write resources regardless of the value of the
7734 qualifying predicate. br.ia must always use p0, and hence is always
7735 taken. Thus this function returns true for branches which can fall
7736 through, and which use no resources if they do fall through. */
7739 is_conditional_branch (idesc)
7740 struct ia64_opcode *idesc;
7742 /* br is a conditional branch. Everything that starts with br. except
7743 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7744 Everything that starts with brl is a conditional branch. */
7745 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7746 && (idesc->name[2] == '\0'
7747 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7748 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7749 || idesc->name[2] == 'l'
7750 /* br.cond, br.call, br.clr */
7751 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7752 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7753 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7756 /* Return whether the given opcode is a taken branch. If there's any doubt,
7760 is_taken_branch (idesc)
7761 struct ia64_opcode *idesc;
7763 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7764 || strncmp (idesc->name, "br.ia", 5) == 0);
7767 /* Return whether the given opcode is an interruption or rfi. If there's any
7768 doubt, returns zero. */
7771 is_interruption_or_rfi (idesc)
7772 struct ia64_opcode *idesc;
7774 if (strcmp (idesc->name, "rfi") == 0)
7779 /* Returns the index of the given dependency in the opcode's list of chks, or
7780 -1 if there is no dependency. */
7783 depends_on (depind, idesc)
7785 struct ia64_opcode *idesc;
7788 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7789 for (i = 0; i < dep->nchks; i++)
7791 if (depind == DEP (dep->chks[i]))
7797 /* Determine a set of specific resources used for a particular resource
7798 class. Returns the number of specific resources identified For those
7799 cases which are not determinable statically, the resource returned is
7802 Meanings of value in 'NOTE':
7803 1) only read/write when the register number is explicitly encoded in the
7805 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7806 accesses CFM when qualifying predicate is in the rotating region.
7807 3) general register value is used to specify an indirect register; not
7808 determinable statically.
7809 4) only read the given resource when bits 7:0 of the indirect index
7810 register value does not match the register number of the resource; not
7811 determinable statically.
7812 5) all rules are implementation specific.
7813 6) only when both the index specified by the reader and the index specified
7814 by the writer have the same value in bits 63:61; not determinable
7816 7) only access the specified resource when the corresponding mask bit is
7818 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7819 only read when these insns reference FR2-31
7820 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7821 written when these insns write FR32-127
7822 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7824 11) The target predicates are written independently of PR[qp], but source
7825 registers are only read if PR[qp] is true. Since the state of PR[qp]
7826 cannot statically be determined, all source registers are marked used.
7827 12) This insn only reads the specified predicate register when that
7828 register is the PR[qp].
7829 13) This reference to ld-c only applies to teh GR whose value is loaded
7830 with data returned from memory, not the post-incremented address register.
7831 14) The RSE resource includes the implementation-specific RSE internal
7832 state resources. At least one (and possibly more) of these resources are
7833 read by each instruction listed in IC:rse-readers. At least one (and
7834 possibly more) of these resources are written by each insn listed in
7836 15+16) Represents reserved instructions, which the assembler does not
7839 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7840 this code; there are no dependency violations based on memory access.
7843 #define MAX_SPECS 256
7848 specify_resource (dep, idesc, type, specs, note, path)
7849 const struct ia64_dependency *dep;
7850 struct ia64_opcode *idesc;
7851 int type; /* is this a DV chk or a DV reg? */
7852 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7853 int note; /* resource note for this insn's usage */
7854 int path; /* which execution path to examine */
7861 if (dep->mode == IA64_DV_WAW
7862 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7863 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7866 /* template for any resources we identify */
7867 tmpl.dependency = dep;
7869 tmpl.insn_srlz = tmpl.data_srlz = 0;
7870 tmpl.qp_regno = CURR_SLOT.qp_regno;
7871 tmpl.link_to_qp_branch = 1;
7872 tmpl.mem_offset.hint = 0;
7875 tmpl.cmp_type = CMP_NONE;
7878 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7879 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7880 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7882 /* we don't need to track these */
7883 if (dep->semantics == IA64_DVS_NONE)
7886 switch (dep->specifier)
7891 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7893 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7894 if (regno >= 0 && regno <= 7)
7896 specs[count] = tmpl;
7897 specs[count++].index = regno;
7903 for (i = 0; i < 8; i++)
7905 specs[count] = tmpl;
7906 specs[count++].index = i;
7915 case IA64_RS_AR_UNAT:
7916 /* This is a mov =AR or mov AR= instruction. */
7917 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7919 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7920 if (regno == AR_UNAT)
7922 specs[count++] = tmpl;
7927 /* This is a spill/fill, or other instruction that modifies the
7930 /* Unless we can determine the specific bits used, mark the whole
7931 thing; bits 8:3 of the memory address indicate the bit used in
7932 UNAT. The .mem.offset hint may be used to eliminate a small
7933 subset of conflicts. */
7934 specs[count] = tmpl;
7935 if (md.mem_offset.hint)
7938 fprintf (stderr, " Using hint for spill/fill\n");
7939 /* The index isn't actually used, just set it to something
7940 approximating the bit index. */
7941 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7942 specs[count].mem_offset.hint = 1;
7943 specs[count].mem_offset.offset = md.mem_offset.offset;
7944 specs[count++].mem_offset.base = md.mem_offset.base;
7948 specs[count++].specific = 0;
7956 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7958 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7959 if ((regno >= 8 && regno <= 15)
7960 || (regno >= 20 && regno <= 23)
7961 || (regno >= 31 && regno <= 39)
7962 || (regno >= 41 && regno <= 47)
7963 || (regno >= 67 && regno <= 111))
7965 specs[count] = tmpl;
7966 specs[count++].index = regno;
7979 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7981 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7982 if ((regno >= 48 && regno <= 63)
7983 || (regno >= 112 && regno <= 127))
7985 specs[count] = tmpl;
7986 specs[count++].index = regno;
7992 for (i = 48; i < 64; i++)
7994 specs[count] = tmpl;
7995 specs[count++].index = i;
7997 for (i = 112; i < 128; i++)
7999 specs[count] = tmpl;
8000 specs[count++].index = i;
8018 for (i = 0; i < idesc->num_outputs; i++)
8019 if (idesc->operands[i] == IA64_OPND_B1
8020 || idesc->operands[i] == IA64_OPND_B2)
8022 specs[count] = tmpl;
8023 specs[count++].index =
8024 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8029 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8030 if (idesc->operands[i] == IA64_OPND_B1
8031 || idesc->operands[i] == IA64_OPND_B2)
8033 specs[count] = tmpl;
8034 specs[count++].index =
8035 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8041 case IA64_RS_CPUID: /* four or more registers */
8044 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
8046 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8047 if (regno >= 0 && regno < NELEMS (gr_values)
8050 specs[count] = tmpl;
8051 specs[count++].index = gr_values[regno].value & 0xFF;
8055 specs[count] = tmpl;
8056 specs[count++].specific = 0;
8066 case IA64_RS_DBR: /* four or more registers */
8069 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
8071 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8072 if (regno >= 0 && regno < NELEMS (gr_values)
8075 specs[count] = tmpl;
8076 specs[count++].index = gr_values[regno].value & 0xFF;
8080 specs[count] = tmpl;
8081 specs[count++].specific = 0;
8085 else if (note == 0 && !rsrc_write)
8087 specs[count] = tmpl;
8088 specs[count++].specific = 0;
8096 case IA64_RS_IBR: /* four or more registers */
8099 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
8101 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8102 if (regno >= 0 && regno < NELEMS (gr_values)
8105 specs[count] = tmpl;
8106 specs[count++].index = gr_values[regno].value & 0xFF;
8110 specs[count] = tmpl;
8111 specs[count++].specific = 0;
8124 /* These are implementation specific. Force all references to
8125 conflict with all other references. */
8126 specs[count] = tmpl;
8127 specs[count++].specific = 0;
8135 case IA64_RS_PKR: /* 16 or more registers */
8136 if (note == 3 || note == 4)
8138 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
8140 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8141 if (regno >= 0 && regno < NELEMS (gr_values)
8146 specs[count] = tmpl;
8147 specs[count++].index = gr_values[regno].value & 0xFF;
8150 for (i = 0; i < NELEMS (gr_values); i++)
8152 /* Uses all registers *except* the one in R3. */
8153 if ((unsigned)i != (gr_values[regno].value & 0xFF))
8155 specs[count] = tmpl;
8156 specs[count++].index = i;
8162 specs[count] = tmpl;
8163 specs[count++].specific = 0;
8170 specs[count] = tmpl;
8171 specs[count++].specific = 0;
8175 case IA64_RS_PMC: /* four or more registers */
8178 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
8179 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
8182 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
8184 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
8185 if (regno >= 0 && regno < NELEMS (gr_values)
8188 specs[count] = tmpl;
8189 specs[count++].index = gr_values[regno].value & 0xFF;
8193 specs[count] = tmpl;
8194 specs[count++].specific = 0;
8204 case IA64_RS_PMD: /* four or more registers */
8207 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
8209 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8210 if (regno >= 0 && regno < NELEMS (gr_values)
8213 specs[count] = tmpl;
8214 specs[count++].index = gr_values[regno].value & 0xFF;
8218 specs[count] = tmpl;
8219 specs[count++].specific = 0;
8229 case IA64_RS_RR: /* eight registers */
8232 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
8234 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8235 if (regno >= 0 && regno < NELEMS (gr_values)
8238 specs[count] = tmpl;
8239 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
8243 specs[count] = tmpl;
8244 specs[count++].specific = 0;
8248 else if (note == 0 && !rsrc_write)
8250 specs[count] = tmpl;
8251 specs[count++].specific = 0;
8259 case IA64_RS_CR_IRR:
8262 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
8263 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
8265 && idesc->operands[1] == IA64_OPND_CR3
8268 for (i = 0; i < 4; i++)
8270 specs[count] = tmpl;
8271 specs[count++].index = CR_IRR0 + i;
8277 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8278 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8280 && regno <= CR_IRR3)
8282 specs[count] = tmpl;
8283 specs[count++].index = regno;
8292 case IA64_RS_CR_LRR:
8299 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8300 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8301 && (regno == CR_LRR0 || regno == CR_LRR1))
8303 specs[count] = tmpl;
8304 specs[count++].index = regno;
8312 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8314 specs[count] = tmpl;
8315 specs[count++].index =
8316 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8331 else if (rsrc_write)
8333 if (dep->specifier == IA64_RS_FRb
8334 && idesc->operands[0] == IA64_OPND_F1)
8336 specs[count] = tmpl;
8337 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8342 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8344 if (idesc->operands[i] == IA64_OPND_F2
8345 || idesc->operands[i] == IA64_OPND_F3
8346 || idesc->operands[i] == IA64_OPND_F4)
8348 specs[count] = tmpl;
8349 specs[count++].index =
8350 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8359 /* This reference applies only to the GR whose value is loaded with
8360 data returned from memory. */
8361 specs[count] = tmpl;
8362 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8368 for (i = 0; i < idesc->num_outputs; i++)
8369 if (idesc->operands[i] == IA64_OPND_R1
8370 || idesc->operands[i] == IA64_OPND_R2
8371 || idesc->operands[i] == IA64_OPND_R3)
8373 specs[count] = tmpl;
8374 specs[count++].index =
8375 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8377 if (idesc->flags & IA64_OPCODE_POSTINC)
8378 for (i = 0; i < NELEMS (idesc->operands); i++)
8379 if (idesc->operands[i] == IA64_OPND_MR3)
8381 specs[count] = tmpl;
8382 specs[count++].index =
8383 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8388 /* Look for anything that reads a GR. */
8389 for (i = 0; i < NELEMS (idesc->operands); i++)
8391 if (idesc->operands[i] == IA64_OPND_MR3
8392 || idesc->operands[i] == IA64_OPND_CPUID_R3
8393 || idesc->operands[i] == IA64_OPND_DBR_R3
8394 || idesc->operands[i] == IA64_OPND_IBR_R3
8395 || idesc->operands[i] == IA64_OPND_MSR_R3
8396 || idesc->operands[i] == IA64_OPND_PKR_R3
8397 || idesc->operands[i] == IA64_OPND_PMC_R3
8398 || idesc->operands[i] == IA64_OPND_PMD_R3
8399 || idesc->operands[i] == IA64_OPND_RR_R3
8400 || ((i >= idesc->num_outputs)
8401 && (idesc->operands[i] == IA64_OPND_R1
8402 || idesc->operands[i] == IA64_OPND_R2
8403 || idesc->operands[i] == IA64_OPND_R3
8404 /* addl source register. */
8405 || idesc->operands[i] == IA64_OPND_R3_2)))
8407 specs[count] = tmpl;
8408 specs[count++].index =
8409 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8420 /* This is the same as IA64_RS_PRr, except that the register range is
8421 from 1 - 15, and there are no rotating register reads/writes here. */
8425 for (i = 1; i < 16; i++)
8427 specs[count] = tmpl;
8428 specs[count++].index = i;
8434 /* Mark only those registers indicated by the mask. */
8437 mask = CURR_SLOT.opnd[2].X_add_number;
8438 for (i = 1; i < 16; i++)
8439 if (mask & ((valueT) 1 << i))
8441 specs[count] = tmpl;
8442 specs[count++].index = i;
8450 else if (note == 11) /* note 11 implies note 1 as well */
8454 for (i = 0; i < idesc->num_outputs; i++)
8456 if (idesc->operands[i] == IA64_OPND_P1
8457 || idesc->operands[i] == IA64_OPND_P2)
8459 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8460 if (regno >= 1 && regno < 16)
8462 specs[count] = tmpl;
8463 specs[count++].index = regno;
8473 else if (note == 12)
8475 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8477 specs[count] = tmpl;
8478 specs[count++].index = CURR_SLOT.qp_regno;
8485 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8486 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8487 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8488 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8490 if ((idesc->operands[0] == IA64_OPND_P1
8491 || idesc->operands[0] == IA64_OPND_P2)
8492 && p1 >= 1 && p1 < 16)
8494 specs[count] = tmpl;
8495 specs[count].cmp_type =
8496 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8497 specs[count++].index = p1;
8499 if ((idesc->operands[1] == IA64_OPND_P1
8500 || idesc->operands[1] == IA64_OPND_P2)
8501 && p2 >= 1 && p2 < 16)
8503 specs[count] = tmpl;
8504 specs[count].cmp_type =
8505 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8506 specs[count++].index = p2;
8511 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8513 specs[count] = tmpl;
8514 specs[count++].index = CURR_SLOT.qp_regno;
8516 if (idesc->operands[1] == IA64_OPND_PR)
8518 for (i = 1; i < 16; i++)
8520 specs[count] = tmpl;
8521 specs[count++].index = i;
8532 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8533 simplified cases of this. */
8537 for (i = 16; i < 63; i++)
8539 specs[count] = tmpl;
8540 specs[count++].index = i;
8546 /* Mark only those registers indicated by the mask. */
8548 && idesc->operands[0] == IA64_OPND_PR)
8550 mask = CURR_SLOT.opnd[2].X_add_number;
8551 if (mask & ((valueT) 1 << 16))
8552 for (i = 16; i < 63; i++)
8554 specs[count] = tmpl;
8555 specs[count++].index = i;
8559 && idesc->operands[0] == IA64_OPND_PR_ROT)
8561 for (i = 16; i < 63; i++)
8563 specs[count] = tmpl;
8564 specs[count++].index = i;
8572 else if (note == 11) /* note 11 implies note 1 as well */
8576 for (i = 0; i < idesc->num_outputs; i++)
8578 if (idesc->operands[i] == IA64_OPND_P1
8579 || idesc->operands[i] == IA64_OPND_P2)
8581 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8582 if (regno >= 16 && regno < 63)
8584 specs[count] = tmpl;
8585 specs[count++].index = regno;
8595 else if (note == 12)
8597 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8599 specs[count] = tmpl;
8600 specs[count++].index = CURR_SLOT.qp_regno;
8607 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8608 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8609 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8610 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8612 if ((idesc->operands[0] == IA64_OPND_P1
8613 || idesc->operands[0] == IA64_OPND_P2)
8614 && p1 >= 16 && p1 < 63)
8616 specs[count] = tmpl;
8617 specs[count].cmp_type =
8618 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8619 specs[count++].index = p1;
8621 if ((idesc->operands[1] == IA64_OPND_P1
8622 || idesc->operands[1] == IA64_OPND_P2)
8623 && p2 >= 16 && p2 < 63)
8625 specs[count] = tmpl;
8626 specs[count].cmp_type =
8627 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8628 specs[count++].index = p2;
8633 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8635 specs[count] = tmpl;
8636 specs[count++].index = CURR_SLOT.qp_regno;
8638 if (idesc->operands[1] == IA64_OPND_PR)
8640 for (i = 16; i < 63; i++)
8642 specs[count] = tmpl;
8643 specs[count++].index = i;
8655 /* Verify that the instruction is using the PSR bit indicated in
8659 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8661 if (dep->regindex < 6)
8663 specs[count++] = tmpl;
8666 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8668 if (dep->regindex < 32
8669 || dep->regindex == 35
8670 || dep->regindex == 36
8671 || (!rsrc_write && dep->regindex == PSR_CPL))
8673 specs[count++] = tmpl;
8676 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8678 if (dep->regindex < 32
8679 || dep->regindex == 35
8680 || dep->regindex == 36
8681 || (rsrc_write && dep->regindex == PSR_CPL))
8683 specs[count++] = tmpl;
8688 /* Several PSR bits have very specific dependencies. */
8689 switch (dep->regindex)
8692 specs[count++] = tmpl;
8697 specs[count++] = tmpl;
8701 /* Only certain CR accesses use PSR.ic */
8702 if (idesc->operands[0] == IA64_OPND_CR3
8703 || idesc->operands[1] == IA64_OPND_CR3)
8706 ((idesc->operands[0] == IA64_OPND_CR3)
8709 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8724 specs[count++] = tmpl;
8733 specs[count++] = tmpl;
8737 /* Only some AR accesses use cpl */
8738 if (idesc->operands[0] == IA64_OPND_AR3
8739 || idesc->operands[1] == IA64_OPND_AR3)
8742 ((idesc->operands[0] == IA64_OPND_AR3)
8745 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8752 && regno <= AR_K7))))
8754 specs[count++] = tmpl;
8759 specs[count++] = tmpl;
8769 if (idesc->operands[0] == IA64_OPND_IMMU24)
8771 mask = CURR_SLOT.opnd[0].X_add_number;
8777 if (mask & ((valueT) 1 << dep->regindex))
8779 specs[count++] = tmpl;
8784 int min = dep->regindex == PSR_DFL ? 2 : 32;
8785 int max = dep->regindex == PSR_DFL ? 31 : 127;
8786 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8787 for (i = 0; i < NELEMS (idesc->operands); i++)
8789 if (idesc->operands[i] == IA64_OPND_F1
8790 || idesc->operands[i] == IA64_OPND_F2
8791 || idesc->operands[i] == IA64_OPND_F3
8792 || idesc->operands[i] == IA64_OPND_F4)
8794 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8795 if (reg >= min && reg <= max)
8797 specs[count++] = tmpl;
8804 int min = dep->regindex == PSR_MFL ? 2 : 32;
8805 int max = dep->regindex == PSR_MFL ? 31 : 127;
8806 /* mfh is read on writes to FR32-127; mfl is read on writes to
8808 for (i = 0; i < idesc->num_outputs; i++)
8810 if (idesc->operands[i] == IA64_OPND_F1)
8812 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8813 if (reg >= min && reg <= max)
8815 specs[count++] = tmpl;
8820 else if (note == 10)
8822 for (i = 0; i < NELEMS (idesc->operands); i++)
8824 if (idesc->operands[i] == IA64_OPND_R1
8825 || idesc->operands[i] == IA64_OPND_R2
8826 || idesc->operands[i] == IA64_OPND_R3)
8828 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8829 if (regno >= 16 && regno <= 31)
8831 specs[count++] = tmpl;
8842 case IA64_RS_AR_FPSR:
8843 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8845 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8846 if (regno == AR_FPSR)
8848 specs[count++] = tmpl;
8853 specs[count++] = tmpl;
8858 /* Handle all AR[REG] resources */
8859 if (note == 0 || note == 1)
8861 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8862 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8863 && regno == dep->regindex)
8865 specs[count++] = tmpl;
8867 /* other AR[REG] resources may be affected by AR accesses */
8868 else if (idesc->operands[0] == IA64_OPND_AR3)
8871 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8872 switch (dep->regindex)
8878 if (regno == AR_BSPSTORE)
8880 specs[count++] = tmpl;
8884 (regno == AR_BSPSTORE
8885 || regno == AR_RNAT))
8887 specs[count++] = tmpl;
8892 else if (idesc->operands[1] == IA64_OPND_AR3)
8895 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8896 switch (dep->regindex)
8901 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8903 specs[count++] = tmpl;
8910 specs[count++] = tmpl;
8920 /* Handle all CR[REG] resources */
8921 if (note == 0 || note == 1)
8923 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8925 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8926 if (regno == dep->regindex)
8928 specs[count++] = tmpl;
8930 else if (!rsrc_write)
8932 /* Reads from CR[IVR] affect other resources. */
8933 if (regno == CR_IVR)
8935 if ((dep->regindex >= CR_IRR0
8936 && dep->regindex <= CR_IRR3)
8937 || dep->regindex == CR_TPR)
8939 specs[count++] = tmpl;
8946 specs[count++] = tmpl;
8955 case IA64_RS_INSERVICE:
8956 /* look for write of EOI (67) or read of IVR (65) */
8957 if ((idesc->operands[0] == IA64_OPND_CR3
8958 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8959 || (idesc->operands[1] == IA64_OPND_CR3
8960 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8962 specs[count++] = tmpl;
8969 specs[count++] = tmpl;
8980 specs[count++] = tmpl;
8984 /* Check if any of the registers accessed are in the rotating region.
8985 mov to/from pr accesses CFM only when qp_regno is in the rotating
8987 for (i = 0; i < NELEMS (idesc->operands); i++)
8989 if (idesc->operands[i] == IA64_OPND_R1
8990 || idesc->operands[i] == IA64_OPND_R2
8991 || idesc->operands[i] == IA64_OPND_R3)
8993 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8994 /* Assumes that md.rot.num_regs is always valid */
8995 if (md.rot.num_regs > 0
8997 && num < 31 + md.rot.num_regs)
8999 specs[count] = tmpl;
9000 specs[count++].specific = 0;
9003 else if (idesc->operands[i] == IA64_OPND_F1
9004 || idesc->operands[i] == IA64_OPND_F2
9005 || idesc->operands[i] == IA64_OPND_F3
9006 || idesc->operands[i] == IA64_OPND_F4)
9008 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9011 specs[count] = tmpl;
9012 specs[count++].specific = 0;
9015 else if (idesc->operands[i] == IA64_OPND_P1
9016 || idesc->operands[i] == IA64_OPND_P2)
9018 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
9021 specs[count] = tmpl;
9022 specs[count++].specific = 0;
9026 if (CURR_SLOT.qp_regno > 15)
9028 specs[count] = tmpl;
9029 specs[count++].specific = 0;
9034 /* This is the same as IA64_RS_PRr, except simplified to account for
9035 the fact that there is only one register. */
9039 specs[count++] = tmpl;
9044 if (idesc->operands[2] == IA64_OPND_IMM17)
9045 mask = CURR_SLOT.opnd[2].X_add_number;
9046 if (mask & ((valueT) 1 << 63))
9047 specs[count++] = tmpl;
9049 else if (note == 11)
9051 if ((idesc->operands[0] == IA64_OPND_P1
9052 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
9053 || (idesc->operands[1] == IA64_OPND_P2
9054 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
9056 specs[count++] = tmpl;
9059 else if (note == 12)
9061 if (CURR_SLOT.qp_regno == 63)
9063 specs[count++] = tmpl;
9070 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9071 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9072 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
9073 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
9076 && (idesc->operands[0] == IA64_OPND_P1
9077 || idesc->operands[0] == IA64_OPND_P2))
9079 specs[count] = tmpl;
9080 specs[count++].cmp_type =
9081 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
9084 && (idesc->operands[1] == IA64_OPND_P1
9085 || idesc->operands[1] == IA64_OPND_P2))
9087 specs[count] = tmpl;
9088 specs[count++].cmp_type =
9089 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9094 if (CURR_SLOT.qp_regno == 63)
9096 specs[count++] = tmpl;
9107 /* FIXME we can identify some individual RSE written resources, but RSE
9108 read resources have not yet been completely identified, so for now
9109 treat RSE as a single resource */
9110 if (strncmp (idesc->name, "mov", 3) == 0)
9114 if (idesc->operands[0] == IA64_OPND_AR3
9115 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
9117 specs[count] = tmpl;
9118 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
9123 if (idesc->operands[0] == IA64_OPND_AR3)
9125 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
9126 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
9128 specs[count++] = tmpl;
9131 else if (idesc->operands[1] == IA64_OPND_AR3)
9133 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
9134 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
9135 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
9137 specs[count++] = tmpl;
9144 specs[count++] = tmpl;
9149 /* FIXME -- do any of these need to be non-specific? */
9150 specs[count++] = tmpl;
9154 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
9161 /* Clear branch flags on marked resources. This breaks the link between the
9162 QP of the marking instruction and a subsequent branch on the same QP. */
9165 clear_qp_branch_flag (mask)
9169 for (i = 0; i < regdepslen; i++)
9171 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
9172 if ((bit & mask) != 0)
9174 regdeps[i].link_to_qp_branch = 0;
9179 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
9180 any mutexes which contain one of the PRs and create new ones when
9184 update_qp_mutex (valueT mask)
9190 while (i < qp_mutexeslen)
9192 if ((qp_mutexes[i].prmask & mask) != 0)
9194 /* If it destroys and creates the same mutex, do nothing. */
9195 if (qp_mutexes[i].prmask == mask
9196 && qp_mutexes[i].path == md.path)
9207 fprintf (stderr, " Clearing mutex relation");
9208 print_prmask (qp_mutexes[i].prmask);
9209 fprintf (stderr, "\n");
9212 /* Deal with the old mutex with more than 3+ PRs only if
9213 the new mutex on the same execution path with it.
9215 FIXME: The 3+ mutex support is incomplete.
9216 dot_pred_rel () may be a better place to fix it. */
9217 if (qp_mutexes[i].path == md.path)
9219 /* If it is a proper subset of the mutex, create a
9222 && (qp_mutexes[i].prmask & mask) == mask)
9225 qp_mutexes[i].prmask &= ~mask;
9226 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
9228 /* Modify the mutex if there are more than one
9236 /* Remove the mutex. */
9237 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9245 add_qp_mutex (mask);
9250 /* Remove any mutexes which contain any of the PRs indicated in the mask.
9252 Any changes to a PR clears the mutex relations which include that PR. */
9255 clear_qp_mutex (mask)
9261 while (i < qp_mutexeslen)
9263 if ((qp_mutexes[i].prmask & mask) != 0)
9267 fprintf (stderr, " Clearing mutex relation");
9268 print_prmask (qp_mutexes[i].prmask);
9269 fprintf (stderr, "\n");
9271 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9278 /* Clear implies relations which contain PRs in the given masks.
9279 P1_MASK indicates the source of the implies relation, while P2_MASK
9280 indicates the implied PR. */
9283 clear_qp_implies (p1_mask, p2_mask)
9290 while (i < qp_implieslen)
9292 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
9293 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
9296 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
9297 qp_implies[i].p1, qp_implies[i].p2);
9298 qp_implies[i] = qp_implies[--qp_implieslen];
9305 /* Add the PRs specified to the list of implied relations. */
9308 add_qp_imply (p1, p2)
9315 /* p0 is not meaningful here. */
9316 if (p1 == 0 || p2 == 0)
9322 /* If it exists already, ignore it. */
9323 for (i = 0; i < qp_implieslen; i++)
9325 if (qp_implies[i].p1 == p1
9326 && qp_implies[i].p2 == p2
9327 && qp_implies[i].path == md.path
9328 && !qp_implies[i].p2_branched)
9332 if (qp_implieslen == qp_impliestotlen)
9334 qp_impliestotlen += 20;
9335 qp_implies = (struct qp_imply *)
9336 xrealloc ((void *) qp_implies,
9337 qp_impliestotlen * sizeof (struct qp_imply));
9340 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9341 qp_implies[qp_implieslen].p1 = p1;
9342 qp_implies[qp_implieslen].p2 = p2;
9343 qp_implies[qp_implieslen].path = md.path;
9344 qp_implies[qp_implieslen++].p2_branched = 0;
9346 /* Add in the implied transitive relations; for everything that p2 implies,
9347 make p1 imply that, too; for everything that implies p1, make it imply p2
9349 for (i = 0; i < qp_implieslen; i++)
9351 if (qp_implies[i].p1 == p2)
9352 add_qp_imply (p1, qp_implies[i].p2);
9353 if (qp_implies[i].p2 == p1)
9354 add_qp_imply (qp_implies[i].p1, p2);
9356 /* Add in mutex relations implied by this implies relation; for each mutex
9357 relation containing p2, duplicate it and replace p2 with p1. */
9358 bit = (valueT) 1 << p1;
9359 mask = (valueT) 1 << p2;
9360 for (i = 0; i < qp_mutexeslen; i++)
9362 if (qp_mutexes[i].prmask & mask)
9363 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9367 /* Add the PRs specified in the mask to the mutex list; this means that only
9368 one of the PRs can be true at any time. PR0 should never be included in
9378 if (qp_mutexeslen == qp_mutexestotlen)
9380 qp_mutexestotlen += 20;
9381 qp_mutexes = (struct qpmutex *)
9382 xrealloc ((void *) qp_mutexes,
9383 qp_mutexestotlen * sizeof (struct qpmutex));
9387 fprintf (stderr, " Registering mutex on");
9388 print_prmask (mask);
9389 fprintf (stderr, "\n");
9391 qp_mutexes[qp_mutexeslen].path = md.path;
9392 qp_mutexes[qp_mutexeslen++].prmask = mask;
9396 has_suffix_p (name, suffix)
9400 size_t namelen = strlen (name);
9401 size_t sufflen = strlen (suffix);
9403 if (namelen <= sufflen)
9405 return strcmp (name + namelen - sufflen, suffix) == 0;
9409 clear_register_values ()
9413 fprintf (stderr, " Clearing register values\n");
9414 for (i = 1; i < NELEMS (gr_values); i++)
9415 gr_values[i].known = 0;
9418 /* Keep track of register values/changes which affect DV tracking.
9420 optimization note: should add a flag to classes of insns where otherwise we
9421 have to examine a group of strings to identify them. */
9424 note_register_values (idesc)
9425 struct ia64_opcode *idesc;
9427 valueT qp_changemask = 0;
9430 /* Invalidate values for registers being written to. */
9431 for (i = 0; i < idesc->num_outputs; i++)
9433 if (idesc->operands[i] == IA64_OPND_R1
9434 || idesc->operands[i] == IA64_OPND_R2
9435 || idesc->operands[i] == IA64_OPND_R3)
9437 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9438 if (regno > 0 && regno < NELEMS (gr_values))
9439 gr_values[regno].known = 0;
9441 else if (idesc->operands[i] == IA64_OPND_R3_2)
9443 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9444 if (regno > 0 && regno < 4)
9445 gr_values[regno].known = 0;
9447 else if (idesc->operands[i] == IA64_OPND_P1
9448 || idesc->operands[i] == IA64_OPND_P2)
9450 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9451 qp_changemask |= (valueT) 1 << regno;
9453 else if (idesc->operands[i] == IA64_OPND_PR)
9455 if (idesc->operands[2] & (valueT) 0x10000)
9456 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9458 qp_changemask = idesc->operands[2];
9461 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9463 if (idesc->operands[1] & ((valueT) 1 << 43))
9464 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9466 qp_changemask = idesc->operands[1];
9467 qp_changemask &= ~(valueT) 0xFFFF;
9472 /* Always clear qp branch flags on any PR change. */
9473 /* FIXME there may be exceptions for certain compares. */
9474 clear_qp_branch_flag (qp_changemask);
9476 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9477 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9479 qp_changemask |= ~(valueT) 0xFFFF;
9480 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9482 for (i = 32; i < 32 + md.rot.num_regs; i++)
9483 gr_values[i].known = 0;
9485 clear_qp_mutex (qp_changemask);
9486 clear_qp_implies (qp_changemask, qp_changemask);
9488 /* After a call, all register values are undefined, except those marked
9490 else if (strncmp (idesc->name, "br.call", 6) == 0
9491 || strncmp (idesc->name, "brl.call", 7) == 0)
9493 /* FIXME keep GR values which are marked as "safe_across_calls" */
9494 clear_register_values ();
9495 clear_qp_mutex (~qp_safe_across_calls);
9496 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9497 clear_qp_branch_flag (~qp_safe_across_calls);
9499 else if (is_interruption_or_rfi (idesc)
9500 || is_taken_branch (idesc))
9502 clear_register_values ();
9503 clear_qp_mutex (~(valueT) 0);
9504 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9506 /* Look for mutex and implies relations. */
9507 else if ((idesc->operands[0] == IA64_OPND_P1
9508 || idesc->operands[0] == IA64_OPND_P2)
9509 && (idesc->operands[1] == IA64_OPND_P1
9510 || idesc->operands[1] == IA64_OPND_P2))
9512 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9513 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9514 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9515 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9517 /* If both PRs are PR0, we can't really do anything. */
9518 if (p1 == 0 && p2 == 0)
9521 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9523 /* In general, clear mutexes and implies which include P1 or P2,
9524 with the following exceptions. */
9525 else if (has_suffix_p (idesc->name, ".or.andcm")
9526 || has_suffix_p (idesc->name, ".and.orcm"))
9528 clear_qp_implies (p2mask, p1mask);
9530 else if (has_suffix_p (idesc->name, ".andcm")
9531 || has_suffix_p (idesc->name, ".and"))
9533 clear_qp_implies (0, p1mask | p2mask);
9535 else if (has_suffix_p (idesc->name, ".orcm")
9536 || has_suffix_p (idesc->name, ".or"))
9538 clear_qp_mutex (p1mask | p2mask);
9539 clear_qp_implies (p1mask | p2mask, 0);
9545 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9547 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9548 if (p1 == 0 || p2 == 0)
9549 clear_qp_mutex (p1mask | p2mask);
9551 added = update_qp_mutex (p1mask | p2mask);
9553 if (CURR_SLOT.qp_regno == 0
9554 || has_suffix_p (idesc->name, ".unc"))
9556 if (added == 0 && p1 && p2)
9557 add_qp_mutex (p1mask | p2mask);
9558 if (CURR_SLOT.qp_regno != 0)
9561 add_qp_imply (p1, CURR_SLOT.qp_regno);
9563 add_qp_imply (p2, CURR_SLOT.qp_regno);
9568 /* Look for mov imm insns into GRs. */
9569 else if (idesc->operands[0] == IA64_OPND_R1
9570 && (idesc->operands[1] == IA64_OPND_IMM22
9571 || idesc->operands[1] == IA64_OPND_IMMU64)
9572 && (strcmp (idesc->name, "mov") == 0
9573 || strcmp (idesc->name, "movl") == 0))
9575 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9576 if (regno > 0 && regno < NELEMS (gr_values))
9578 gr_values[regno].known = 1;
9579 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9580 gr_values[regno].path = md.path;
9583 fprintf (stderr, " Know gr%d = ", regno);
9584 fprintf_vma (stderr, gr_values[regno].value);
9585 fputs ("\n", stderr);
9591 clear_qp_mutex (qp_changemask);
9592 clear_qp_implies (qp_changemask, qp_changemask);
9596 /* Return whether the given predicate registers are currently mutex. */
9599 qp_mutex (p1, p2, path)
9609 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9610 for (i = 0; i < qp_mutexeslen; i++)
9612 if (qp_mutexes[i].path >= path
9613 && (qp_mutexes[i].prmask & mask) == mask)
9620 /* Return whether the given resource is in the given insn's list of chks
9621 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9625 resources_match (rs, idesc, note, qp_regno, path)
9627 struct ia64_opcode *idesc;
9632 struct rsrc specs[MAX_SPECS];
9635 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9636 we don't need to check. One exception is note 11, which indicates that
9637 target predicates are written regardless of PR[qp]. */
9638 if (qp_mutex (rs->qp_regno, qp_regno, path)
9642 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9645 /* UNAT checking is a bit more specific than other resources */
9646 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9647 && specs[count].mem_offset.hint
9648 && rs->mem_offset.hint)
9650 if (rs->mem_offset.base == specs[count].mem_offset.base)
9652 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9653 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9660 /* Skip apparent PR write conflicts where both writes are an AND or both
9661 writes are an OR. */
9662 if (rs->dependency->specifier == IA64_RS_PR
9663 || rs->dependency->specifier == IA64_RS_PRr
9664 || rs->dependency->specifier == IA64_RS_PR63)
9666 if (specs[count].cmp_type != CMP_NONE
9667 && specs[count].cmp_type == rs->cmp_type)
9670 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9671 dv_mode[rs->dependency->mode],
9672 rs->dependency->specifier != IA64_RS_PR63 ?
9673 specs[count].index : 63);
9678 " %s on parallel compare conflict %s vs %s on PR%d\n",
9679 dv_mode[rs->dependency->mode],
9680 dv_cmp_type[rs->cmp_type],
9681 dv_cmp_type[specs[count].cmp_type],
9682 rs->dependency->specifier != IA64_RS_PR63 ?
9683 specs[count].index : 63);
9687 /* If either resource is not specific, conservatively assume a conflict
9689 if (!specs[count].specific || !rs->specific)
9691 else if (specs[count].index == rs->index)
9698 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9699 insert a stop to create the break. Update all resource dependencies
9700 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9701 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9702 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9706 insn_group_break (insert_stop, qp_regno, save_current)
9713 if (insert_stop && md.num_slots_in_use > 0)
9714 PREV_SLOT.end_of_insn_group = 1;
9718 fprintf (stderr, " Insn group break%s",
9719 (insert_stop ? " (w/stop)" : ""));
9721 fprintf (stderr, " effective for QP=%d", qp_regno);
9722 fprintf (stderr, "\n");
9726 while (i < regdepslen)
9728 const struct ia64_dependency *dep = regdeps[i].dependency;
9731 && regdeps[i].qp_regno != qp_regno)
9738 && CURR_SLOT.src_file == regdeps[i].file
9739 && CURR_SLOT.src_line == regdeps[i].line)
9745 /* clear dependencies which are automatically cleared by a stop, or
9746 those that have reached the appropriate state of insn serialization */
9747 if (dep->semantics == IA64_DVS_IMPLIED
9748 || dep->semantics == IA64_DVS_IMPLIEDF
9749 || regdeps[i].insn_srlz == STATE_SRLZ)
9751 print_dependency ("Removing", i);
9752 regdeps[i] = regdeps[--regdepslen];
9756 if (dep->semantics == IA64_DVS_DATA
9757 || dep->semantics == IA64_DVS_INSTR
9758 || dep->semantics == IA64_DVS_SPECIFIC)
9760 if (regdeps[i].insn_srlz == STATE_NONE)
9761 regdeps[i].insn_srlz = STATE_STOP;
9762 if (regdeps[i].data_srlz == STATE_NONE)
9763 regdeps[i].data_srlz = STATE_STOP;
9770 /* Add the given resource usage spec to the list of active dependencies. */
9773 mark_resource (idesc, dep, spec, depind, path)
9774 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9775 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9780 if (regdepslen == regdepstotlen)
9782 regdepstotlen += 20;
9783 regdeps = (struct rsrc *)
9784 xrealloc ((void *) regdeps,
9785 regdepstotlen * sizeof (struct rsrc));
9788 regdeps[regdepslen] = *spec;
9789 regdeps[regdepslen].depind = depind;
9790 regdeps[regdepslen].path = path;
9791 regdeps[regdepslen].file = CURR_SLOT.src_file;
9792 regdeps[regdepslen].line = CURR_SLOT.src_line;
9794 print_dependency ("Adding", regdepslen);
9800 print_dependency (action, depind)
9806 fprintf (stderr, " %s %s '%s'",
9807 action, dv_mode[(regdeps[depind].dependency)->mode],
9808 (regdeps[depind].dependency)->name);
9809 if (regdeps[depind].specific && regdeps[depind].index != 0)
9810 fprintf (stderr, " (%d)", regdeps[depind].index);
9811 if (regdeps[depind].mem_offset.hint)
9813 fputs (" ", stderr);
9814 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9815 fputs ("+", stderr);
9816 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9818 fprintf (stderr, "\n");
9823 instruction_serialization ()
9827 fprintf (stderr, " Instruction serialization\n");
9828 for (i = 0; i < regdepslen; i++)
9829 if (regdeps[i].insn_srlz == STATE_STOP)
9830 regdeps[i].insn_srlz = STATE_SRLZ;
9834 data_serialization ()
9838 fprintf (stderr, " Data serialization\n");
9839 while (i < regdepslen)
9841 if (regdeps[i].data_srlz == STATE_STOP
9842 /* Note: as of 991210, all "other" dependencies are cleared by a
9843 data serialization. This might change with new tables */
9844 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9846 print_dependency ("Removing", i);
9847 regdeps[i] = regdeps[--regdepslen];
9854 /* Insert stops and serializations as needed to avoid DVs. */
9857 remove_marked_resource (rs)
9860 switch (rs->dependency->semantics)
9862 case IA64_DVS_SPECIFIC:
9864 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9865 /* ...fall through... */
9866 case IA64_DVS_INSTR:
9868 fprintf (stderr, "Inserting instr serialization\n");
9869 if (rs->insn_srlz < STATE_STOP)
9870 insn_group_break (1, 0, 0);
9871 if (rs->insn_srlz < STATE_SRLZ)
9873 struct slot oldslot = CURR_SLOT;
9874 /* Manually jam a srlz.i insn into the stream */
9875 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
9876 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9877 instruction_serialization ();
9878 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9879 if (++md.num_slots_in_use >= NUM_SLOTS)
9881 CURR_SLOT = oldslot;
9883 insn_group_break (1, 0, 0);
9885 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9886 "other" types of DV are eliminated
9887 by a data serialization */
9890 fprintf (stderr, "Inserting data serialization\n");
9891 if (rs->data_srlz < STATE_STOP)
9892 insn_group_break (1, 0, 0);
9894 struct slot oldslot = CURR_SLOT;
9895 /* Manually jam a srlz.d insn into the stream */
9896 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
9897 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9898 data_serialization ();
9899 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9900 if (++md.num_slots_in_use >= NUM_SLOTS)
9902 CURR_SLOT = oldslot;
9905 case IA64_DVS_IMPLIED:
9906 case IA64_DVS_IMPLIEDF:
9908 fprintf (stderr, "Inserting stop\n");
9909 insn_group_break (1, 0, 0);
9916 /* Check the resources used by the given opcode against the current dependency
9919 The check is run once for each execution path encountered. In this case,
9920 a unique execution path is the sequence of instructions following a code
9921 entry point, e.g. the following has three execution paths, one starting
9922 at L0, one at L1, and one at L2.
9931 check_dependencies (idesc)
9932 struct ia64_opcode *idesc;
9934 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9938 /* Note that the number of marked resources may change within the
9939 loop if in auto mode. */
9941 while (i < regdepslen)
9943 struct rsrc *rs = ®deps[i];
9944 const struct ia64_dependency *dep = rs->dependency;
9949 if (dep->semantics == IA64_DVS_NONE
9950 || (chkind = depends_on (rs->depind, idesc)) == -1)
9956 note = NOTE (opdeps->chks[chkind]);
9958 /* Check this resource against each execution path seen thus far. */
9959 for (path = 0; path <= md.path; path++)
9963 /* If the dependency wasn't on the path being checked, ignore it. */
9964 if (rs->path < path)
9967 /* If the QP for this insn implies a QP which has branched, don't
9968 bother checking. Ed. NOTE: I don't think this check is terribly
9969 useful; what's the point of generating code which will only be
9970 reached if its QP is zero?
9971 This code was specifically inserted to handle the following code,
9972 based on notes from Intel's DV checking code, where p1 implies p2.
9978 if (CURR_SLOT.qp_regno != 0)
9982 for (implies = 0; implies < qp_implieslen; implies++)
9984 if (qp_implies[implies].path >= path
9985 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9986 && qp_implies[implies].p2_branched)
9996 if ((matchtype = resources_match (rs, idesc, note,
9997 CURR_SLOT.qp_regno, path)) != 0)
10000 char pathmsg[256] = "";
10001 char indexmsg[256] = "";
10002 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
10005 sprintf (pathmsg, " when entry is at label '%s'",
10006 md.entry_labels[path - 1]);
10007 if (rs->specific && rs->index != 0)
10008 sprintf (indexmsg, ", specific resource number is %d",
10010 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
10012 (certain ? "violates" : "may violate"),
10013 dv_mode[dep->mode], dep->name,
10014 dv_sem[dep->semantics],
10015 pathmsg, indexmsg);
10017 if (md.explicit_mode)
10019 as_warn ("%s", msg);
10020 if (path < md.path)
10021 as_warn (_("Only the first path encountering the conflict "
10023 as_warn_where (rs->file, rs->line,
10024 _("This is the location of the "
10025 "conflicting usage"));
10026 /* Don't bother checking other paths, to avoid duplicating
10027 the same warning */
10033 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
10035 remove_marked_resource (rs);
10037 /* since the set of dependencies has changed, start over */
10038 /* FIXME -- since we're removing dvs as we go, we
10039 probably don't really need to start over... */
10052 /* Register new dependencies based on the given opcode. */
10055 mark_resources (idesc)
10056 struct ia64_opcode *idesc;
10059 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10060 int add_only_qp_reads = 0;
10062 /* A conditional branch only uses its resources if it is taken; if it is
10063 taken, we stop following that path. The other branch types effectively
10064 *always* write their resources. If it's not taken, register only QP
10066 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
10068 add_only_qp_reads = 1;
10072 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
10074 for (i = 0; i < opdeps->nregs; i++)
10076 const struct ia64_dependency *dep;
10077 struct rsrc specs[MAX_SPECS];
10082 dep = ia64_find_dependency (opdeps->regs[i]);
10083 note = NOTE (opdeps->regs[i]);
10085 if (add_only_qp_reads
10086 && !(dep->mode == IA64_DV_WAR
10087 && (dep->specifier == IA64_RS_PR
10088 || dep->specifier == IA64_RS_PRr
10089 || dep->specifier == IA64_RS_PR63)))
10092 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
10094 while (count-- > 0)
10096 mark_resource (idesc, dep, &specs[count],
10097 DEP (opdeps->regs[i]), md.path);
10100 /* The execution path may affect register values, which may in turn
10101 affect which indirect-access resources are accessed. */
10102 switch (dep->specifier)
10106 case IA64_RS_CPUID:
10114 for (path = 0; path < md.path; path++)
10116 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
10117 while (count-- > 0)
10118 mark_resource (idesc, dep, &specs[count],
10119 DEP (opdeps->regs[i]), path);
10126 /* Remove dependencies when they no longer apply. */
10129 update_dependencies (idesc)
10130 struct ia64_opcode *idesc;
10134 if (strcmp (idesc->name, "srlz.i") == 0)
10136 instruction_serialization ();
10138 else if (strcmp (idesc->name, "srlz.d") == 0)
10140 data_serialization ();
10142 else if (is_interruption_or_rfi (idesc)
10143 || is_taken_branch (idesc))
10145 /* Although technically the taken branch doesn't clear dependencies
10146 which require a srlz.[id], we don't follow the branch; the next
10147 instruction is assumed to start with a clean slate. */
10151 else if (is_conditional_branch (idesc)
10152 && CURR_SLOT.qp_regno != 0)
10154 int is_call = strstr (idesc->name, ".call") != NULL;
10156 for (i = 0; i < qp_implieslen; i++)
10158 /* If the conditional branch's predicate is implied by the predicate
10159 in an existing dependency, remove that dependency. */
10160 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
10163 /* Note that this implied predicate takes a branch so that if
10164 a later insn generates a DV but its predicate implies this
10165 one, we can avoid the false DV warning. */
10166 qp_implies[i].p2_branched = 1;
10167 while (depind < regdepslen)
10169 if (regdeps[depind].qp_regno == qp_implies[i].p1)
10171 print_dependency ("Removing", depind);
10172 regdeps[depind] = regdeps[--regdepslen];
10179 /* Any marked resources which have this same predicate should be
10180 cleared, provided that the QP hasn't been modified between the
10181 marking instruction and the branch. */
10184 insn_group_break (0, CURR_SLOT.qp_regno, 1);
10189 while (i < regdepslen)
10191 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
10192 && regdeps[i].link_to_qp_branch
10193 && (regdeps[i].file != CURR_SLOT.src_file
10194 || regdeps[i].line != CURR_SLOT.src_line))
10196 /* Treat like a taken branch */
10197 print_dependency ("Removing", i);
10198 regdeps[i] = regdeps[--regdepslen];
10207 /* Examine the current instruction for dependency violations. */
10211 struct ia64_opcode *idesc;
10215 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
10216 idesc->name, CURR_SLOT.src_line,
10217 idesc->dependencies->nchks,
10218 idesc->dependencies->nregs);
10221 /* Look through the list of currently marked resources; if the current
10222 instruction has the dependency in its chks list which uses that resource,
10223 check against the specific resources used. */
10224 check_dependencies (idesc);
10226 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
10227 then add them to the list of marked resources. */
10228 mark_resources (idesc);
10230 /* There are several types of dependency semantics, and each has its own
10231 requirements for being cleared
10233 Instruction serialization (insns separated by interruption, rfi, or
10234 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
10236 Data serialization (instruction serialization, or writer + srlz.d +
10237 reader, where writer and srlz.d are in separate groups) clears
10238 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
10239 always be the case).
10241 Instruction group break (groups separated by stop, taken branch,
10242 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
10244 update_dependencies (idesc);
10246 /* Sometimes, knowing a register value allows us to avoid giving a false DV
10247 warning. Keep track of as many as possible that are useful. */
10248 note_register_values (idesc);
10250 /* We don't need or want this anymore. */
10251 md.mem_offset.hint = 0;
10256 /* Translate one line of assembly. Pseudo ops and labels do not show
10262 char *saved_input_line_pointer, *mnemonic;
10263 const struct pseudo_opcode *pdesc;
10264 struct ia64_opcode *idesc;
10265 unsigned char qp_regno;
10266 unsigned int flags;
10269 saved_input_line_pointer = input_line_pointer;
10270 input_line_pointer = str;
10272 /* extract the opcode (mnemonic): */
10274 mnemonic = input_line_pointer;
10275 ch = get_symbol_end ();
10276 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
10279 *input_line_pointer = ch;
10280 (*pdesc->handler) (pdesc->arg);
10284 /* Find the instruction descriptor matching the arguments. */
10286 idesc = ia64_find_opcode (mnemonic);
10287 *input_line_pointer = ch;
10290 as_bad ("Unknown opcode `%s'", mnemonic);
10294 idesc = parse_operands (idesc);
10298 /* Handle the dynamic ops we can handle now: */
10299 if (idesc->type == IA64_TYPE_DYN)
10301 if (strcmp (idesc->name, "add") == 0)
10303 if (CURR_SLOT.opnd[2].X_op == O_register
10304 && CURR_SLOT.opnd[2].X_add_number < 4)
10308 ia64_free_opcode (idesc);
10309 idesc = ia64_find_opcode (mnemonic);
10311 else if (strcmp (idesc->name, "mov") == 0)
10313 enum ia64_opnd opnd1, opnd2;
10316 opnd1 = idesc->operands[0];
10317 opnd2 = idesc->operands[1];
10318 if (opnd1 == IA64_OPND_AR3)
10320 else if (opnd2 == IA64_OPND_AR3)
10324 if (CURR_SLOT.opnd[rop].X_op == O_register)
10326 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10327 mnemonic = "mov.i";
10328 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10329 mnemonic = "mov.m";
10337 ia64_free_opcode (idesc);
10338 idesc = ia64_find_opcode (mnemonic);
10339 while (idesc != NULL
10340 && (idesc->operands[0] != opnd1
10341 || idesc->operands[1] != opnd2))
10342 idesc = get_next_opcode (idesc);
10346 else if (strcmp (idesc->name, "mov.i") == 0
10347 || strcmp (idesc->name, "mov.m") == 0)
10349 enum ia64_opnd opnd1, opnd2;
10352 opnd1 = idesc->operands[0];
10353 opnd2 = idesc->operands[1];
10354 if (opnd1 == IA64_OPND_AR3)
10356 else if (opnd2 == IA64_OPND_AR3)
10360 if (CURR_SLOT.opnd[rop].X_op == O_register)
10363 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10365 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10367 if (unit != 'a' && unit != idesc->name [4])
10368 as_bad ("AR %d cannot be accessed by %c-unit",
10369 (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR),
10375 if (md.qp.X_op == O_register)
10377 qp_regno = md.qp.X_add_number - REG_P;
10378 md.qp.X_op = O_absent;
10381 flags = idesc->flags;
10383 if ((flags & IA64_OPCODE_FIRST) != 0)
10385 /* The alignment frag has to end with a stop bit only if the
10386 next instruction after the alignment directive has to be
10387 the first instruction in an instruction group. */
10390 while (align_frag->fr_type != rs_align_code)
10392 align_frag = align_frag->fr_next;
10396 /* align_frag can be NULL if there are directives in
10398 if (align_frag && align_frag->fr_next == frag_now)
10399 align_frag->tc_frag_data = 1;
10402 insn_group_break (1, 0, 0);
10406 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10408 as_bad ("`%s' cannot be predicated", idesc->name);
10412 /* Build the instruction. */
10413 CURR_SLOT.qp_regno = qp_regno;
10414 CURR_SLOT.idesc = idesc;
10415 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10416 dwarf2_where (&CURR_SLOT.debug_line);
10418 /* Add unwind entry, if there is one. */
10419 if (unwind.current_entry)
10421 CURR_SLOT.unwind_record = unwind.current_entry;
10422 unwind.current_entry = NULL;
10424 if (unwind.proc_start && S_IS_DEFINED (unwind.proc_start))
10427 /* Check for dependency violations. */
10431 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10432 if (++md.num_slots_in_use >= NUM_SLOTS)
10433 emit_one_bundle ();
10435 if ((flags & IA64_OPCODE_LAST) != 0)
10436 insn_group_break (1, 0, 0);
10438 md.last_text_seg = now_seg;
10441 input_line_pointer = saved_input_line_pointer;
10444 /* Called when symbol NAME cannot be found in the symbol table.
10445 Should be used for dynamic valued symbols only. */
10448 md_undefined_symbol (name)
10449 char *name ATTRIBUTE_UNUSED;
10454 /* Called for any expression that can not be recognized. When the
10455 function is called, `input_line_pointer' will point to the start of
10462 switch (*input_line_pointer)
10465 ++input_line_pointer;
10467 if (*input_line_pointer != ']')
10469 as_bad ("Closing bracket missing");
10474 if (e->X_op != O_register)
10475 as_bad ("Register expected as index");
10477 ++input_line_pointer;
10488 ignore_rest_of_line ();
10491 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10492 a section symbol plus some offset. For relocs involving @fptr(),
10493 directives we don't want such adjustments since we need to have the
10494 original symbol's name in the reloc. */
10496 ia64_fix_adjustable (fix)
10499 /* Prevent all adjustments to global symbols */
10500 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10503 switch (fix->fx_r_type)
10505 case BFD_RELOC_IA64_FPTR64I:
10506 case BFD_RELOC_IA64_FPTR32MSB:
10507 case BFD_RELOC_IA64_FPTR32LSB:
10508 case BFD_RELOC_IA64_FPTR64MSB:
10509 case BFD_RELOC_IA64_FPTR64LSB:
10510 case BFD_RELOC_IA64_LTOFF_FPTR22:
10511 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10521 ia64_force_relocation (fix)
10524 switch (fix->fx_r_type)
10526 case BFD_RELOC_IA64_FPTR64I:
10527 case BFD_RELOC_IA64_FPTR32MSB:
10528 case BFD_RELOC_IA64_FPTR32LSB:
10529 case BFD_RELOC_IA64_FPTR64MSB:
10530 case BFD_RELOC_IA64_FPTR64LSB:
10532 case BFD_RELOC_IA64_LTOFF22:
10533 case BFD_RELOC_IA64_LTOFF64I:
10534 case BFD_RELOC_IA64_LTOFF_FPTR22:
10535 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10536 case BFD_RELOC_IA64_PLTOFF22:
10537 case BFD_RELOC_IA64_PLTOFF64I:
10538 case BFD_RELOC_IA64_PLTOFF64MSB:
10539 case BFD_RELOC_IA64_PLTOFF64LSB:
10541 case BFD_RELOC_IA64_LTOFF22X:
10542 case BFD_RELOC_IA64_LDXMOV:
10549 return generic_force_reloc (fix);
10552 /* Decide from what point a pc-relative relocation is relative to,
10553 relative to the pc-relative fixup. Er, relatively speaking. */
10555 ia64_pcrel_from_section (fix, sec)
10559 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10561 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10568 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10570 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10574 expr.X_op = O_pseudo_fixup;
10575 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10576 expr.X_add_number = 0;
10577 expr.X_add_symbol = symbol;
10578 emit_expr (&expr, size);
10581 /* This is called whenever some data item (not an instruction) needs a
10582 fixup. We pick the right reloc code depending on the byteorder
10583 currently in effect. */
10585 ia64_cons_fix_new (f, where, nbytes, exp)
10591 bfd_reloc_code_real_type code;
10596 /* There are no reloc for 8 and 16 bit quantities, but we allow
10597 them here since they will work fine as long as the expression
10598 is fully defined at the end of the pass over the source file. */
10599 case 1: code = BFD_RELOC_8; break;
10600 case 2: code = BFD_RELOC_16; break;
10602 if (target_big_endian)
10603 code = BFD_RELOC_IA64_DIR32MSB;
10605 code = BFD_RELOC_IA64_DIR32LSB;
10609 /* In 32-bit mode, data8 could mean function descriptors too. */
10610 if (exp->X_op == O_pseudo_fixup
10611 && exp->X_op_symbol
10612 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10613 && !(md.flags & EF_IA_64_ABI64))
10615 if (target_big_endian)
10616 code = BFD_RELOC_IA64_IPLTMSB;
10618 code = BFD_RELOC_IA64_IPLTLSB;
10619 exp->X_op = O_symbol;
10624 if (target_big_endian)
10625 code = BFD_RELOC_IA64_DIR64MSB;
10627 code = BFD_RELOC_IA64_DIR64LSB;
10632 if (exp->X_op == O_pseudo_fixup
10633 && exp->X_op_symbol
10634 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10636 if (target_big_endian)
10637 code = BFD_RELOC_IA64_IPLTMSB;
10639 code = BFD_RELOC_IA64_IPLTLSB;
10640 exp->X_op = O_symbol;
10646 as_bad ("Unsupported fixup size %d", nbytes);
10647 ignore_rest_of_line ();
10651 if (exp->X_op == O_pseudo_fixup)
10653 exp->X_op = O_symbol;
10654 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10655 /* ??? If code unchanged, unsupported. */
10658 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10659 /* We need to store the byte order in effect in case we're going
10660 to fix an 8 or 16 bit relocation (for which there no real
10661 relocs available). See md_apply_fix3(). */
10662 fix->tc_fix_data.bigendian = target_big_endian;
10665 /* Return the actual relocation we wish to associate with the pseudo
10666 reloc described by SYM and R_TYPE. SYM should be one of the
10667 symbols in the pseudo_func array, or NULL. */
10669 static bfd_reloc_code_real_type
10670 ia64_gen_real_reloc_type (sym, r_type)
10671 struct symbol *sym;
10672 bfd_reloc_code_real_type r_type;
10674 bfd_reloc_code_real_type new = 0;
10681 switch (S_GET_VALUE (sym))
10683 case FUNC_FPTR_RELATIVE:
10686 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10687 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10688 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10689 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10690 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10695 case FUNC_GP_RELATIVE:
10698 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10699 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10700 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10701 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10702 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10703 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10708 case FUNC_LT_RELATIVE:
10711 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10712 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10717 case FUNC_LT_RELATIVE_X:
10720 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10725 case FUNC_PC_RELATIVE:
10728 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10729 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10730 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10731 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10732 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10733 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10738 case FUNC_PLT_RELATIVE:
10741 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10742 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10743 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10744 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10749 case FUNC_SEC_RELATIVE:
10752 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10753 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10754 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10755 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10760 case FUNC_SEG_RELATIVE:
10763 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10764 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10765 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10766 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10771 case FUNC_LTV_RELATIVE:
10774 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10775 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10776 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10777 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10782 case FUNC_LT_FPTR_RELATIVE:
10785 case BFD_RELOC_IA64_IMM22:
10786 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10787 case BFD_RELOC_IA64_IMM64:
10788 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10794 case FUNC_TP_RELATIVE:
10797 case BFD_RELOC_IA64_IMM14:
10798 new = BFD_RELOC_IA64_TPREL14; break;
10799 case BFD_RELOC_IA64_IMM22:
10800 new = BFD_RELOC_IA64_TPREL22; break;
10801 case BFD_RELOC_IA64_IMM64:
10802 new = BFD_RELOC_IA64_TPREL64I; break;
10808 case FUNC_LT_TP_RELATIVE:
10811 case BFD_RELOC_IA64_IMM22:
10812 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10818 case FUNC_LT_DTP_MODULE:
10821 case BFD_RELOC_IA64_IMM22:
10822 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10828 case FUNC_DTP_RELATIVE:
10831 case BFD_RELOC_IA64_DIR64MSB:
10832 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10833 case BFD_RELOC_IA64_DIR64LSB:
10834 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10835 case BFD_RELOC_IA64_IMM14:
10836 new = BFD_RELOC_IA64_DTPREL14; break;
10837 case BFD_RELOC_IA64_IMM22:
10838 new = BFD_RELOC_IA64_DTPREL22; break;
10839 case BFD_RELOC_IA64_IMM64:
10840 new = BFD_RELOC_IA64_DTPREL64I; break;
10846 case FUNC_LT_DTP_RELATIVE:
10849 case BFD_RELOC_IA64_IMM22:
10850 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10856 case FUNC_IPLT_RELOC:
10863 /* Hmmmm. Should this ever occur? */
10870 /* Here is where generate the appropriate reloc for pseudo relocation
10873 ia64_validate_fix (fix)
10876 switch (fix->fx_r_type)
10878 case BFD_RELOC_IA64_FPTR64I:
10879 case BFD_RELOC_IA64_FPTR32MSB:
10880 case BFD_RELOC_IA64_FPTR64LSB:
10881 case BFD_RELOC_IA64_LTOFF_FPTR22:
10882 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10883 if (fix->fx_offset != 0)
10884 as_bad_where (fix->fx_file, fix->fx_line,
10885 "No addend allowed in @fptr() relocation");
10893 fix_insn (fix, odesc, value)
10895 const struct ia64_operand *odesc;
10898 bfd_vma insn[3], t0, t1, control_bits;
10903 slot = fix->fx_where & 0x3;
10904 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10906 /* Bundles are always in little-endian byte order */
10907 t0 = bfd_getl64 (fixpos);
10908 t1 = bfd_getl64 (fixpos + 8);
10909 control_bits = t0 & 0x1f;
10910 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10911 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10912 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10915 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10917 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10918 insn[2] |= (((value & 0x7f) << 13)
10919 | (((value >> 7) & 0x1ff) << 27)
10920 | (((value >> 16) & 0x1f) << 22)
10921 | (((value >> 21) & 0x1) << 21)
10922 | (((value >> 63) & 0x1) << 36));
10924 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10926 if (value & ~0x3fffffffffffffffULL)
10927 err = "integer operand out of range";
10928 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10929 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10931 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10934 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10935 insn[2] |= ((((value >> 59) & 0x1) << 36)
10936 | (((value >> 0) & 0xfffff) << 13));
10939 err = (*odesc->insert) (odesc, value, insn + slot);
10942 as_bad_where (fix->fx_file, fix->fx_line, err);
10944 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10945 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10946 number_to_chars_littleendian (fixpos + 0, t0, 8);
10947 number_to_chars_littleendian (fixpos + 8, t1, 8);
10950 /* Attempt to simplify or even eliminate a fixup. The return value is
10951 ignored; perhaps it was once meaningful, but now it is historical.
10952 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10954 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10958 md_apply_fix3 (fix, valP, seg)
10961 segT seg ATTRIBUTE_UNUSED;
10964 valueT value = *valP;
10966 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10970 switch (fix->fx_r_type)
10972 case BFD_RELOC_IA64_DIR32MSB:
10973 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10976 case BFD_RELOC_IA64_DIR32LSB:
10977 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10980 case BFD_RELOC_IA64_DIR64MSB:
10981 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10984 case BFD_RELOC_IA64_DIR64LSB:
10985 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10994 switch (fix->fx_r_type)
10996 case BFD_RELOC_UNUSED:
10997 /* This must be a TAG13 or TAG13b operand. There are no external
10998 relocs defined for them, so we must give an error. */
10999 as_bad_where (fix->fx_file, fix->fx_line,
11000 "%s must have a constant value",
11001 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
11005 case BFD_RELOC_IA64_TPREL14:
11006 case BFD_RELOC_IA64_TPREL22:
11007 case BFD_RELOC_IA64_TPREL64I:
11008 case BFD_RELOC_IA64_LTOFF_TPREL22:
11009 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
11010 case BFD_RELOC_IA64_DTPREL14:
11011 case BFD_RELOC_IA64_DTPREL22:
11012 case BFD_RELOC_IA64_DTPREL64I:
11013 case BFD_RELOC_IA64_LTOFF_DTPREL22:
11014 S_SET_THREAD_LOCAL (fix->fx_addsy);
11021 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
11023 if (fix->tc_fix_data.bigendian)
11024 number_to_chars_bigendian (fixpos, value, fix->fx_size);
11026 number_to_chars_littleendian (fixpos, value, fix->fx_size);
11031 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
11036 /* Generate the BFD reloc to be stuck in the object file from the
11037 fixup used internally in the assembler. */
11040 tc_gen_reloc (sec, fixp)
11041 asection *sec ATTRIBUTE_UNUSED;
11046 reloc = xmalloc (sizeof (*reloc));
11047 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11048 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11049 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11050 reloc->addend = fixp->fx_offset;
11051 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
11055 as_bad_where (fixp->fx_file, fixp->fx_line,
11056 "Cannot represent %s relocation in object file",
11057 bfd_get_reloc_code_name (fixp->fx_r_type));
11062 /* Turn a string in input_line_pointer into a floating point constant
11063 of type TYPE, and store the appropriate bytes in *LIT. The number
11064 of LITTLENUMS emitted is stored in *SIZE. An error message is
11065 returned, or NULL on OK. */
11067 #define MAX_LITTLENUMS 5
11070 md_atof (type, lit, size)
11075 LITTLENUM_TYPE words[MAX_LITTLENUMS];
11105 return "Bad call to MD_ATOF()";
11107 t = atof_ieee (input_line_pointer, type, words);
11109 input_line_pointer = t;
11111 (*ia64_float_to_chars) (lit, words, prec);
11115 /* It is 10 byte floating point with 6 byte padding. */
11116 memset (&lit [10], 0, 6);
11117 *size = 8 * sizeof (LITTLENUM_TYPE);
11120 *size = prec * sizeof (LITTLENUM_TYPE);
11125 /* Handle ia64 specific semantics of the align directive. */
11128 ia64_md_do_align (n, fill, len, max)
11129 int n ATTRIBUTE_UNUSED;
11130 const char *fill ATTRIBUTE_UNUSED;
11131 int len ATTRIBUTE_UNUSED;
11132 int max ATTRIBUTE_UNUSED;
11134 if (subseg_text_p (now_seg))
11135 ia64_flush_insns ();
11138 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
11139 of an rs_align_code fragment. */
11142 ia64_handle_align (fragp)
11145 /* Use mfi bundle of nops with no stop bits. */
11146 static const unsigned char le_nop[]
11147 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
11148 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
11149 static const unsigned char le_nop_stop[]
11150 = { 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
11151 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
11155 const unsigned char *nop;
11157 if (fragp->fr_type != rs_align_code)
11160 /* Check if this frag has to end with a stop bit. */
11161 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
11163 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11164 p = fragp->fr_literal + fragp->fr_fix;
11166 /* If no paddings are needed, we check if we need a stop bit. */
11167 if (!bytes && fragp->tc_frag_data)
11169 if (fragp->fr_fix < 16)
11171 /* FIXME: It won't work with
11173 alloc r32=ar.pfs,1,2,4,0
11177 as_bad_where (fragp->fr_file, fragp->fr_line,
11178 _("Can't add stop bit to mark end of instruction group"));
11181 /* Bundles are always in little-endian byte order. Make sure
11182 the previous bundle has the stop bit. */
11186 /* Make sure we are on a 16-byte boundary, in case someone has been
11187 putting data into a text section. */
11190 int fix = bytes & 15;
11191 memset (p, 0, fix);
11194 fragp->fr_fix += fix;
11197 /* Instruction bundles are always little-endian. */
11198 memcpy (p, nop, 16);
11199 fragp->fr_var = 16;
11203 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
11208 number_to_chars_bigendian (lit, (long) (*words++),
11209 sizeof (LITTLENUM_TYPE));
11210 lit += sizeof (LITTLENUM_TYPE);
11215 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
11220 number_to_chars_littleendian (lit, (long) (words[prec]),
11221 sizeof (LITTLENUM_TYPE));
11222 lit += sizeof (LITTLENUM_TYPE);
11227 ia64_elf_section_change_hook (void)
11229 if (elf_section_type (now_seg) == SHT_IA_64_UNWIND
11230 && elf_linked_to_section (now_seg) == NULL)
11231 elf_linked_to_section (now_seg) = text_section;
11232 dot_byteorder (-1);
11235 /* Check if a label should be made global. */
11237 ia64_check_label (symbolS *label)
11239 if (*input_line_pointer == ':')
11241 S_SET_EXTERNAL (label);
11242 input_line_pointer++;
11246 /* Used to remember where .alias and .secalias directives are seen. We
11247 will rename symbol and section names when we are about to output
11248 the relocatable file. */
11251 char *file; /* The file where the directive is seen. */
11252 unsigned int line; /* The line number the directive is at. */
11253 const char *name; /* The orignale name of the symbol. */
11256 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11257 .secalias. Otherwise, it is .alias. */
11259 dot_alias (int section)
11261 char *name, *alias;
11265 const char *error_string;
11268 struct hash_control *ahash, *nhash;
11271 name = input_line_pointer;
11272 delim = get_symbol_end ();
11273 end_name = input_line_pointer;
11276 if (name == end_name)
11278 as_bad (_("expected symbol name"));
11279 discard_rest_of_line ();
11283 SKIP_WHITESPACE ();
11285 if (*input_line_pointer != ',')
11288 as_bad (_("expected comma after \"%s\""), name);
11290 ignore_rest_of_line ();
11294 input_line_pointer++;
11297 /* We call demand_copy_C_string to check if alias string is valid.
11298 There should be a closing `"' and no `\0' in the string. */
11299 alias = demand_copy_C_string (&len);
11302 ignore_rest_of_line ();
11306 /* Make a copy of name string. */
11307 len = strlen (name) + 1;
11308 obstack_grow (¬es, name, len);
11309 name = obstack_finish (¬es);
11314 ahash = secalias_hash;
11315 nhash = secalias_name_hash;
11320 ahash = alias_hash;
11321 nhash = alias_name_hash;
11324 /* Check if alias has been used before. */
11325 h = (struct alias *) hash_find (ahash, alias);
11328 if (strcmp (h->name, name))
11329 as_bad (_("`%s' is already the alias of %s `%s'"),
11330 alias, kind, h->name);
11334 /* Check if name already has an alias. */
11335 a = (const char *) hash_find (nhash, name);
11338 if (strcmp (a, alias))
11339 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11343 h = (struct alias *) xmalloc (sizeof (struct alias));
11344 as_where (&h->file, &h->line);
11347 error_string = hash_jam (ahash, alias, (PTR) h);
11350 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11351 alias, kind, error_string);
11355 error_string = hash_jam (nhash, name, (PTR) alias);
11358 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11359 alias, kind, error_string);
11361 obstack_free (¬es, name);
11362 obstack_free (¬es, alias);
11365 demand_empty_rest_of_line ();
11368 /* It renames the original symbol name to its alias. */
11370 do_alias (const char *alias, PTR value)
11372 struct alias *h = (struct alias *) value;
11373 symbolS *sym = symbol_find (h->name);
11376 as_warn_where (h->file, h->line,
11377 _("symbol `%s' aliased to `%s' is not used"),
11380 S_SET_NAME (sym, (char *) alias);
11383 /* Called from write_object_file. */
11385 ia64_adjust_symtab (void)
11387 hash_traverse (alias_hash, do_alias);
11390 /* It renames the original section name to its alias. */
11392 do_secalias (const char *alias, PTR value)
11394 struct alias *h = (struct alias *) value;
11395 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11398 as_warn_where (h->file, h->line,
11399 _("section `%s' aliased to `%s' is not used"),
11405 /* Called from write_object_file. */
11407 ia64_frob_file (void)
11409 hash_traverse (secalias_hash, do_secalias);