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.
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 /* Each bundle consists of up to three instructions. We keep
235 track of four most recent instructions so we can correctly set
236 the end_of_insn_group for the last instruction in a bundle. */
238 int num_slots_in_use;
242 end_of_insn_group : 1,
243 manual_bundling_on : 1,
244 manual_bundling_off : 1,
245 loc_directive_seen : 1;
246 signed char user_template; /* user-selected template, if any */
247 unsigned char qp_regno; /* qualifying predicate */
248 /* This duplicates a good fraction of "struct fix" but we
249 can't use a "struct fix" instead since we can't call
250 fix_new_exp() until we know the address of the instruction. */
254 bfd_reloc_code_real_type code;
255 enum ia64_opnd opnd; /* type of operand in need of fix */
256 unsigned int is_pcrel : 1; /* is operand pc-relative? */
257 expressionS expr; /* the value to be inserted */
259 fixup[2]; /* at most two fixups per insn */
260 struct ia64_opcode *idesc;
261 struct label_fix *label_fixups;
262 struct label_fix *tag_fixups;
263 struct unw_rec_list *unwind_record; /* Unwind directive. */
266 unsigned int src_line;
267 struct dwarf2_line_info debug_line;
275 struct dynreg *next; /* next dynamic register */
277 unsigned short base; /* the base register number */
278 unsigned short num_regs; /* # of registers in this set */
280 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
282 flagword flags; /* ELF-header flags */
285 unsigned hint:1; /* is this hint currently valid? */
286 bfd_vma offset; /* mem.offset offset */
287 bfd_vma base; /* mem.offset base */
290 int path; /* number of alt. entry points seen */
291 const char **entry_labels; /* labels of all alternate paths in
292 the current DV-checking block. */
293 int maxpaths; /* size currently allocated for
295 /* Support for hardware errata workarounds. */
297 /* Record data about the last three insn groups. */
300 /* B-step workaround.
301 For each predicate register, this is set if the corresponding insn
302 group conditionally sets this register with one of the affected
305 /* B-step workaround.
306 For each general register, this is set if the corresponding insn
307 a) is conditional one one of the predicate registers for which
308 P_REG_SET is 1 in the corresponding entry of the previous group,
309 b) sets this general register with one of the affected
311 int g_reg_set_conditionally[128];
315 int pointer_size; /* size in bytes of a pointer */
316 int pointer_size_shift; /* shift size of a pointer for alignment */
320 /* application registers: */
326 #define AR_BSPSTORE 18
341 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
342 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
343 {"ar.rsc", 16}, {"ar.bsp", 17},
344 {"ar.bspstore", 18}, {"ar.rnat", 19},
345 {"ar.fcr", 21}, {"ar.eflag", 24},
346 {"ar.csd", 25}, {"ar.ssd", 26},
347 {"ar.cflg", 27}, {"ar.fsr", 28},
348 {"ar.fir", 29}, {"ar.fdr", 30},
349 {"ar.ccv", 32}, {"ar.unat", 36},
350 {"ar.fpsr", 40}, {"ar.itc", 44},
351 {"ar.pfs", 64}, {"ar.lc", 65},
372 /* control registers: */
414 static const struct const_desc
421 /* PSR constant masks: */
424 {"psr.be", ((valueT) 1) << 1},
425 {"psr.up", ((valueT) 1) << 2},
426 {"psr.ac", ((valueT) 1) << 3},
427 {"psr.mfl", ((valueT) 1) << 4},
428 {"psr.mfh", ((valueT) 1) << 5},
430 {"psr.ic", ((valueT) 1) << 13},
431 {"psr.i", ((valueT) 1) << 14},
432 {"psr.pk", ((valueT) 1) << 15},
434 {"psr.dt", ((valueT) 1) << 17},
435 {"psr.dfl", ((valueT) 1) << 18},
436 {"psr.dfh", ((valueT) 1) << 19},
437 {"psr.sp", ((valueT) 1) << 20},
438 {"psr.pp", ((valueT) 1) << 21},
439 {"psr.di", ((valueT) 1) << 22},
440 {"psr.si", ((valueT) 1) << 23},
441 {"psr.db", ((valueT) 1) << 24},
442 {"psr.lp", ((valueT) 1) << 25},
443 {"psr.tb", ((valueT) 1) << 26},
444 {"psr.rt", ((valueT) 1) << 27},
445 /* 28-31: reserved */
446 /* 32-33: cpl (current privilege level) */
447 {"psr.is", ((valueT) 1) << 34},
448 {"psr.mc", ((valueT) 1) << 35},
449 {"psr.it", ((valueT) 1) << 36},
450 {"psr.id", ((valueT) 1) << 37},
451 {"psr.da", ((valueT) 1) << 38},
452 {"psr.dd", ((valueT) 1) << 39},
453 {"psr.ss", ((valueT) 1) << 40},
454 /* 41-42: ri (restart instruction) */
455 {"psr.ed", ((valueT) 1) << 43},
456 {"psr.bn", ((valueT) 1) << 44},
459 /* indirect register-sets/memory: */
468 { "CPUID", IND_CPUID },
469 { "cpuid", IND_CPUID },
481 /* Pseudo functions used to indicate relocation types (these functions
482 start with an at sign (@). */
504 /* reloc pseudo functions (these must come first!): */
505 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
506 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
507 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
508 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
509 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
510 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
511 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
512 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
513 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
514 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
515 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
516 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
517 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
518 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
519 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
520 { "", 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
521 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
523 /* mbtype4 constants: */
524 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
525 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
526 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
527 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
528 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
530 /* fclass constants: */
531 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
532 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
533 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
534 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
535 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
536 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
537 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
538 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
539 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
541 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
543 /* hint constants: */
544 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
546 /* unwind-related constants: */
547 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
548 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
549 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
550 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
551 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
552 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
553 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
555 /* unwind-related registers: */
556 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
559 /* 41-bit nop opcodes (one per unit): */
560 static const bfd_vma nop[IA64_NUM_UNITS] =
562 0x0000000000LL, /* NIL => break 0 */
563 0x0008000000LL, /* I-unit nop */
564 0x0008000000LL, /* M-unit nop */
565 0x4000000000LL, /* B-unit nop */
566 0x0008000000LL, /* F-unit nop */
567 0x0008000000LL, /* L-"unit" nop */
568 0x0008000000LL, /* X-unit nop */
571 /* Can't be `const' as it's passed to input routines (which have the
572 habit of setting temporary sentinels. */
573 static char special_section_name[][20] =
575 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
576 {".IA_64.unwind"}, {".IA_64.unwind_info"},
577 {".init_array"}, {".fini_array"}
580 /* The best template for a particular sequence of up to three
582 #define N IA64_NUM_TYPES
583 static unsigned char best_template[N][N][N];
586 /* Resource dependencies currently in effect */
588 int depind; /* dependency index */
589 const struct ia64_dependency *dependency; /* actual dependency */
590 unsigned specific:1, /* is this a specific bit/regno? */
591 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
592 int index; /* specific regno/bit within dependency */
593 int note; /* optional qualifying note (0 if none) */
597 int insn_srlz; /* current insn serialization state */
598 int data_srlz; /* current data serialization state */
599 int qp_regno; /* qualifying predicate for this usage */
600 char *file; /* what file marked this dependency */
601 unsigned int line; /* what line marked this dependency */
602 struct mem_offset mem_offset; /* optional memory offset hint */
603 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
604 int path; /* corresponding code entry index */
606 static int regdepslen = 0;
607 static int regdepstotlen = 0;
608 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
609 static const char *dv_sem[] = { "none", "implied", "impliedf",
610 "data", "instr", "specific", "stop", "other" };
611 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
613 /* Current state of PR mutexation */
614 static struct qpmutex {
617 } *qp_mutexes = NULL; /* QP mutex bitmasks */
618 static int qp_mutexeslen = 0;
619 static int qp_mutexestotlen = 0;
620 static valueT qp_safe_across_calls = 0;
622 /* Current state of PR implications */
623 static struct qp_imply {
626 unsigned p2_branched:1;
628 } *qp_implies = NULL;
629 static int qp_implieslen = 0;
630 static int qp_impliestotlen = 0;
632 /* Keep track of static GR values so that indirect register usage can
633 sometimes be tracked. */
638 } gr_values[128] = {{ 1, 0, 0 }};
640 /* Remember the alignment frag. */
641 static fragS *align_frag;
643 /* These are the routines required to output the various types of
646 /* A slot_number is a frag address plus the slot index (0-2). We use the
647 frag address here so that if there is a section switch in the middle of
648 a function, then instructions emitted to a different section are not
649 counted. Since there may be more than one frag for a function, this
650 means we also need to keep track of which frag this address belongs to
651 so we can compute inter-frag distances. This also nicely solves the
652 problem with nops emitted for align directives, which can't easily be
653 counted, but can easily be derived from frag sizes. */
655 typedef struct unw_rec_list {
657 unsigned long slot_number;
659 unsigned long next_slot_number;
660 fragS *next_slot_frag;
661 struct unw_rec_list *next;
664 #define SLOT_NUM_NOT_SET (unsigned)-1
666 /* Linked list of saved prologue counts. A very poor
667 implementation of a map from label numbers to prologue counts. */
668 typedef struct label_prologue_count
670 struct label_prologue_count *next;
671 unsigned long label_number;
672 unsigned int prologue_count;
673 } label_prologue_count;
677 /* Maintain a list of unwind entries for the current function. */
681 /* Any unwind entires that should be attached to the current slot
682 that an insn is being constructed for. */
683 unw_rec_list *current_entry;
685 /* These are used to create the unwind table entry for this function. */
687 symbolS *info; /* pointer to unwind info */
688 symbolS *personality_routine;
690 subsegT saved_text_subseg;
691 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
693 /* TRUE if processing unwind directives in a prologue region. */
694 unsigned int prologue : 1;
695 unsigned int prologue_mask : 4;
696 unsigned int body : 1;
697 unsigned int insn : 1;
698 unsigned int prologue_count; /* number of .prologues seen so far */
699 /* Prologue counts at previous .label_state directives. */
700 struct label_prologue_count * saved_prologue_counts;
703 /* The input value is a negated offset from psp, and specifies an address
704 psp - offset. The encoded value is psp + 16 - (4 * offset). Thus we
705 must add 16 and divide by 4 to get the encoded value. */
707 #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4)
709 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
711 /* Forward declarations: */
712 static void set_section PARAMS ((char *name));
713 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
714 unsigned int, unsigned int));
715 static void dot_align (int);
716 static void dot_radix PARAMS ((int));
717 static void dot_special_section PARAMS ((int));
718 static void dot_proc PARAMS ((int));
719 static void dot_fframe PARAMS ((int));
720 static void dot_vframe PARAMS ((int));
721 static void dot_vframesp PARAMS ((int));
722 static void dot_vframepsp PARAMS ((int));
723 static void dot_save PARAMS ((int));
724 static void dot_restore PARAMS ((int));
725 static void dot_restorereg PARAMS ((int));
726 static void dot_restorereg_p PARAMS ((int));
727 static void dot_handlerdata PARAMS ((int));
728 static void dot_unwentry PARAMS ((int));
729 static void dot_altrp PARAMS ((int));
730 static void dot_savemem PARAMS ((int));
731 static void dot_saveg PARAMS ((int));
732 static void dot_savef PARAMS ((int));
733 static void dot_saveb PARAMS ((int));
734 static void dot_savegf PARAMS ((int));
735 static void dot_spill PARAMS ((int));
736 static void dot_spillreg PARAMS ((int));
737 static void dot_spillmem PARAMS ((int));
738 static void dot_spillreg_p PARAMS ((int));
739 static void dot_spillmem_p PARAMS ((int));
740 static void dot_label_state PARAMS ((int));
741 static void dot_copy_state PARAMS ((int));
742 static void dot_unwabi PARAMS ((int));
743 static void dot_personality PARAMS ((int));
744 static void dot_body PARAMS ((int));
745 static void dot_prologue PARAMS ((int));
746 static void dot_endp PARAMS ((int));
747 static void dot_template PARAMS ((int));
748 static void dot_regstk PARAMS ((int));
749 static void dot_rot PARAMS ((int));
750 static void dot_byteorder PARAMS ((int));
751 static void dot_psr PARAMS ((int));
752 static void dot_alias PARAMS ((int));
753 static void dot_ln PARAMS ((int));
754 static char *parse_section_name PARAMS ((void));
755 static void dot_xdata PARAMS ((int));
756 static void stmt_float_cons PARAMS ((int));
757 static void stmt_cons_ua PARAMS ((int));
758 static void dot_xfloat_cons PARAMS ((int));
759 static void dot_xstringer PARAMS ((int));
760 static void dot_xdata_ua PARAMS ((int));
761 static void dot_xfloat_cons_ua PARAMS ((int));
762 static void print_prmask PARAMS ((valueT mask));
763 static void dot_pred_rel PARAMS ((int));
764 static void dot_reg_val PARAMS ((int));
765 static void dot_serialize PARAMS ((int));
766 static void dot_dv_mode PARAMS ((int));
767 static void dot_entry PARAMS ((int));
768 static void dot_mem_offset PARAMS ((int));
769 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
770 static symbolS *declare_register PARAMS ((const char *name, int regnum));
771 static void declare_register_set PARAMS ((const char *, int, int));
772 static unsigned int operand_width PARAMS ((enum ia64_opnd));
773 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
776 static int parse_operand PARAMS ((expressionS *e));
777 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
778 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
779 static void build_insn PARAMS ((struct slot *, bfd_vma *));
780 static void emit_one_bundle PARAMS ((void));
781 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
782 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
783 bfd_reloc_code_real_type r_type));
784 static void insn_group_break PARAMS ((int, int, int));
785 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
786 struct rsrc *, int depind, int path));
787 static void add_qp_mutex PARAMS((valueT mask));
788 static void add_qp_imply PARAMS((int p1, int p2));
789 static void clear_qp_branch_flag PARAMS((valueT mask));
790 static void clear_qp_mutex PARAMS((valueT mask));
791 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
792 static int has_suffix_p PARAMS((const char *, const char *));
793 static void clear_register_values PARAMS ((void));
794 static void print_dependency PARAMS ((const char *action, int depind));
795 static void instruction_serialization PARAMS ((void));
796 static void data_serialization PARAMS ((void));
797 static void remove_marked_resource PARAMS ((struct rsrc *));
798 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
799 static int is_taken_branch PARAMS ((struct ia64_opcode *));
800 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
801 static int depends_on PARAMS ((int, struct ia64_opcode *));
802 static int specify_resource PARAMS ((const struct ia64_dependency *,
803 struct ia64_opcode *, int, struct rsrc [], int, int));
804 static int check_dv PARAMS((struct ia64_opcode *idesc));
805 static void check_dependencies PARAMS((struct ia64_opcode *));
806 static void mark_resources PARAMS((struct ia64_opcode *));
807 static void update_dependencies PARAMS((struct ia64_opcode *));
808 static void note_register_values PARAMS((struct ia64_opcode *));
809 static int qp_mutex PARAMS ((int, int, int));
810 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
811 static void output_vbyte_mem PARAMS ((int, char *, char *));
812 static void count_output PARAMS ((int, char *, char *));
813 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
814 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
815 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
816 static void output_P1_format PARAMS ((vbyte_func, int));
817 static void output_P2_format PARAMS ((vbyte_func, int, int));
818 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
819 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
820 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
821 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
822 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
823 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
824 static void output_P9_format PARAMS ((vbyte_func, int, int));
825 static void output_P10_format PARAMS ((vbyte_func, int, int));
826 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
827 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
828 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
829 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
830 static char format_ab_reg PARAMS ((int, int));
831 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
833 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
834 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
836 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
837 static unw_rec_list *output_endp PARAMS ((void));
838 static unw_rec_list *output_prologue PARAMS ((void));
839 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
840 static unw_rec_list *output_body PARAMS ((void));
841 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
842 static unw_rec_list *output_mem_stack_v PARAMS ((void));
843 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
844 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
845 static unw_rec_list *output_rp_when PARAMS ((void));
846 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
847 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
848 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
849 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
850 static unw_rec_list *output_pfs_when PARAMS ((void));
851 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
852 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
853 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
854 static unw_rec_list *output_preds_when PARAMS ((void));
855 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
856 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
857 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
858 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
859 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
860 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
861 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
862 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
863 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
864 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
865 static unw_rec_list *output_unat_when PARAMS ((void));
866 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
867 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
868 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
869 static unw_rec_list *output_lc_when PARAMS ((void));
870 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
871 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
872 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
873 static unw_rec_list *output_fpsr_when PARAMS ((void));
874 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
875 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
876 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
877 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
878 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
879 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
880 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
881 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
882 static unw_rec_list *output_bsp_when PARAMS ((void));
883 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
884 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
885 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
886 static unw_rec_list *output_bspstore_when PARAMS ((void));
887 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
888 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
889 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
890 static unw_rec_list *output_rnat_when PARAMS ((void));
891 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
892 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
893 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
894 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
895 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
896 static unw_rec_list *output_label_state PARAMS ((unsigned long));
897 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
898 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
899 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
900 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
902 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
904 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
906 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
907 unsigned int, unsigned int));
908 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
909 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
910 static int calc_record_size PARAMS ((unw_rec_list *));
911 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
912 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
913 unsigned long, fragS *,
915 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
916 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
917 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
918 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
919 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
920 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
921 static void free_saved_prologue_counts PARAMS ((void));
923 /* Determine if application register REGNUM resides only in the integer
924 unit (as opposed to the memory unit). */
926 ar_is_only_in_integer_unit (int reg)
929 return reg >= 64 && reg <= 111;
932 /* Determine if application register REGNUM resides only in the memory
933 unit (as opposed to the integer unit). */
935 ar_is_only_in_memory_unit (int reg)
938 return reg >= 0 && reg <= 47;
941 /* Switch to section NAME and create section if necessary. It's
942 rather ugly that we have to manipulate input_line_pointer but I
943 don't see any other way to accomplish the same thing without
944 changing obj-elf.c (which may be the Right Thing, in the end). */
949 char *saved_input_line_pointer;
951 saved_input_line_pointer = input_line_pointer;
952 input_line_pointer = name;
954 input_line_pointer = saved_input_line_pointer;
957 /* Map 's' to SHF_IA_64_SHORT. */
960 ia64_elf_section_letter (letter, ptr_msg)
965 return SHF_IA_64_SHORT;
966 else if (letter == 'o')
967 return SHF_LINK_ORDER;
969 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
973 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
976 ia64_elf_section_flags (flags, attr, type)
978 int attr, type ATTRIBUTE_UNUSED;
980 if (attr & SHF_IA_64_SHORT)
981 flags |= SEC_SMALL_DATA;
986 ia64_elf_section_type (str, len)
990 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
992 if (STREQ (ELF_STRING_ia64_unwind_info))
995 if (STREQ (ELF_STRING_ia64_unwind_info_once))
998 if (STREQ (ELF_STRING_ia64_unwind))
999 return SHT_IA_64_UNWIND;
1001 if (STREQ (ELF_STRING_ia64_unwind_once))
1002 return SHT_IA_64_UNWIND;
1004 if (STREQ ("unwind"))
1005 return SHT_IA_64_UNWIND;
1012 set_regstack (ins, locs, outs, rots)
1013 unsigned int ins, locs, outs, rots;
1015 /* Size of frame. */
1018 sof = ins + locs + outs;
1021 as_bad ("Size of frame exceeds maximum of 96 registers");
1026 as_warn ("Size of rotating registers exceeds frame size");
1029 md.in.base = REG_GR + 32;
1030 md.loc.base = md.in.base + ins;
1031 md.out.base = md.loc.base + locs;
1033 md.in.num_regs = ins;
1034 md.loc.num_regs = locs;
1035 md.out.num_regs = outs;
1036 md.rot.num_regs = rots;
1043 struct label_fix *lfix;
1045 subsegT saved_subseg;
1048 if (!md.last_text_seg)
1051 saved_seg = now_seg;
1052 saved_subseg = now_subseg;
1054 subseg_set (md.last_text_seg, 0);
1056 while (md.num_slots_in_use > 0)
1057 emit_one_bundle (); /* force out queued instructions */
1059 /* In case there are labels following the last instruction, resolve
1061 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1063 S_SET_VALUE (lfix->sym, frag_now_fix ());
1064 symbol_set_frag (lfix->sym, frag_now);
1066 CURR_SLOT.label_fixups = 0;
1067 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1069 S_SET_VALUE (lfix->sym, frag_now_fix ());
1070 symbol_set_frag (lfix->sym, frag_now);
1072 CURR_SLOT.tag_fixups = 0;
1074 /* In case there are unwind directives following the last instruction,
1075 resolve those now. We only handle prologue, body, and endp directives
1076 here. Give an error for others. */
1077 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1079 switch (ptr->r.type)
1085 ptr->slot_number = (unsigned long) frag_more (0);
1086 ptr->slot_frag = frag_now;
1089 /* Allow any record which doesn't have a "t" field (i.e.,
1090 doesn't relate to a particular instruction). */
1106 as_bad (_("Unwind directive not followed by an instruction."));
1110 unwind.current_entry = NULL;
1112 subseg_set (saved_seg, saved_subseg);
1114 if (md.qp.X_op == O_register)
1115 as_bad ("qualifying predicate not followed by instruction");
1119 ia64_do_align (int nbytes)
1121 char *saved_input_line_pointer = input_line_pointer;
1123 input_line_pointer = "";
1124 s_align_bytes (nbytes);
1125 input_line_pointer = saved_input_line_pointer;
1129 ia64_cons_align (nbytes)
1134 char *saved_input_line_pointer = input_line_pointer;
1135 input_line_pointer = "";
1136 s_align_bytes (nbytes);
1137 input_line_pointer = saved_input_line_pointer;
1141 /* Output COUNT bytes to a memory location. */
1142 static unsigned char *vbyte_mem_ptr = NULL;
1145 output_vbyte_mem (count, ptr, comment)
1148 char *comment ATTRIBUTE_UNUSED;
1151 if (vbyte_mem_ptr == NULL)
1156 for (x = 0; x < count; x++)
1157 *(vbyte_mem_ptr++) = ptr[x];
1160 /* Count the number of bytes required for records. */
1161 static int vbyte_count = 0;
1163 count_output (count, ptr, comment)
1165 char *ptr ATTRIBUTE_UNUSED;
1166 char *comment ATTRIBUTE_UNUSED;
1168 vbyte_count += count;
1172 output_R1_format (f, rtype, rlen)
1174 unw_record_type rtype;
1181 output_R3_format (f, rtype, rlen);
1187 else if (rtype != prologue)
1188 as_bad ("record type is not valid");
1190 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1191 (*f) (1, &byte, NULL);
1195 output_R2_format (f, mask, grsave, rlen)
1202 mask = (mask & 0x0f);
1203 grsave = (grsave & 0x7f);
1205 bytes[0] = (UNW_R2 | (mask >> 1));
1206 bytes[1] = (((mask & 0x01) << 7) | grsave);
1207 count += output_leb128 (bytes + 2, rlen, 0);
1208 (*f) (count, bytes, NULL);
1212 output_R3_format (f, rtype, rlen)
1214 unw_record_type rtype;
1221 output_R1_format (f, rtype, rlen);
1227 else if (rtype != prologue)
1228 as_bad ("record type is not valid");
1229 bytes[0] = (UNW_R3 | r);
1230 count = output_leb128 (bytes + 1, rlen, 0);
1231 (*f) (count + 1, bytes, NULL);
1235 output_P1_format (f, brmask)
1240 byte = UNW_P1 | (brmask & 0x1f);
1241 (*f) (1, &byte, NULL);
1245 output_P2_format (f, brmask, gr)
1251 brmask = (brmask & 0x1f);
1252 bytes[0] = UNW_P2 | (brmask >> 1);
1253 bytes[1] = (((brmask & 1) << 7) | gr);
1254 (*f) (2, bytes, NULL);
1258 output_P3_format (f, rtype, reg)
1260 unw_record_type rtype;
1305 as_bad ("Invalid record type for P3 format.");
1307 bytes[0] = (UNW_P3 | (r >> 1));
1308 bytes[1] = (((r & 1) << 7) | reg);
1309 (*f) (2, bytes, NULL);
1313 output_P4_format (f, imask, imask_size)
1315 unsigned char *imask;
1316 unsigned long imask_size;
1319 (*f) (imask_size, imask, NULL);
1323 output_P5_format (f, grmask, frmask)
1326 unsigned long frmask;
1329 grmask = (grmask & 0x0f);
1332 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1333 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1334 bytes[3] = (frmask & 0x000000ff);
1335 (*f) (4, bytes, NULL);
1339 output_P6_format (f, rtype, rmask)
1341 unw_record_type rtype;
1347 if (rtype == gr_mem)
1349 else if (rtype != fr_mem)
1350 as_bad ("Invalid record type for format P6");
1351 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1352 (*f) (1, &byte, NULL);
1356 output_P7_format (f, rtype, w1, w2)
1358 unw_record_type rtype;
1365 count += output_leb128 (bytes + 1, w1, 0);
1370 count += output_leb128 (bytes + count, w2 >> 4, 0);
1420 bytes[0] = (UNW_P7 | r);
1421 (*f) (count, bytes, NULL);
1425 output_P8_format (f, rtype, t)
1427 unw_record_type rtype;
1466 case bspstore_psprel:
1469 case bspstore_sprel:
1481 case priunat_when_gr:
1484 case priunat_psprel:
1490 case priunat_when_mem:
1497 count += output_leb128 (bytes + 2, t, 0);
1498 (*f) (count, bytes, NULL);
1502 output_P9_format (f, grmask, gr)
1509 bytes[1] = (grmask & 0x0f);
1510 bytes[2] = (gr & 0x7f);
1511 (*f) (3, bytes, NULL);
1515 output_P10_format (f, abi, context)
1522 bytes[1] = (abi & 0xff);
1523 bytes[2] = (context & 0xff);
1524 (*f) (3, bytes, NULL);
1528 output_B1_format (f, rtype, label)
1530 unw_record_type rtype;
1531 unsigned long label;
1537 output_B4_format (f, rtype, label);
1540 if (rtype == copy_state)
1542 else if (rtype != label_state)
1543 as_bad ("Invalid record type for format B1");
1545 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1546 (*f) (1, &byte, NULL);
1550 output_B2_format (f, ecount, t)
1552 unsigned long ecount;
1559 output_B3_format (f, ecount, t);
1562 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1563 count += output_leb128 (bytes + 1, t, 0);
1564 (*f) (count, bytes, NULL);
1568 output_B3_format (f, ecount, t)
1570 unsigned long ecount;
1577 output_B2_format (f, ecount, t);
1581 count += output_leb128 (bytes + 1, t, 0);
1582 count += output_leb128 (bytes + count, ecount, 0);
1583 (*f) (count, bytes, NULL);
1587 output_B4_format (f, rtype, label)
1589 unw_record_type rtype;
1590 unsigned long label;
1597 output_B1_format (f, rtype, label);
1601 if (rtype == copy_state)
1603 else if (rtype != label_state)
1604 as_bad ("Invalid record type for format B1");
1606 bytes[0] = (UNW_B4 | (r << 3));
1607 count += output_leb128 (bytes + 1, label, 0);
1608 (*f) (count, bytes, NULL);
1612 format_ab_reg (ab, reg)
1619 ret = (ab << 5) | reg;
1624 output_X1_format (f, rtype, ab, reg, t, w1)
1626 unw_record_type rtype;
1636 if (rtype == spill_sprel)
1638 else if (rtype != spill_psprel)
1639 as_bad ("Invalid record type for format X1");
1640 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1641 count += output_leb128 (bytes + 2, t, 0);
1642 count += output_leb128 (bytes + count, w1, 0);
1643 (*f) (count, bytes, NULL);
1647 output_X2_format (f, ab, reg, x, y, treg, t)
1656 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1657 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1658 count += output_leb128 (bytes + 3, t, 0);
1659 (*f) (count, bytes, NULL);
1663 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1665 unw_record_type rtype;
1676 if (rtype == spill_sprel_p)
1678 else if (rtype != spill_psprel_p)
1679 as_bad ("Invalid record type for format X3");
1680 bytes[1] = ((r << 7) | (qp & 0x3f));
1681 bytes[2] = format_ab_reg (ab, reg);
1682 count += output_leb128 (bytes + 3, t, 0);
1683 count += output_leb128 (bytes + count, w1, 0);
1684 (*f) (count, bytes, NULL);
1688 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1698 bytes[1] = (qp & 0x3f);
1699 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1700 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1701 count += output_leb128 (bytes + 4, t, 0);
1702 (*f) (count, bytes, NULL);
1705 /* This function allocates a record list structure, and initializes fields. */
1707 static unw_rec_list *
1708 alloc_record (unw_record_type t)
1711 ptr = xmalloc (sizeof (*ptr));
1713 ptr->slot_number = SLOT_NUM_NOT_SET;
1715 ptr->next_slot_number = 0;
1716 ptr->next_slot_frag = 0;
1720 /* Dummy unwind record used for calculating the length of the last prologue or
1723 static unw_rec_list *
1726 unw_rec_list *ptr = alloc_record (endp);
1730 static unw_rec_list *
1733 unw_rec_list *ptr = alloc_record (prologue);
1734 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1738 static unw_rec_list *
1739 output_prologue_gr (saved_mask, reg)
1740 unsigned int saved_mask;
1743 unw_rec_list *ptr = alloc_record (prologue_gr);
1744 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1745 ptr->r.record.r.grmask = saved_mask;
1746 ptr->r.record.r.grsave = reg;
1750 static unw_rec_list *
1753 unw_rec_list *ptr = alloc_record (body);
1757 static unw_rec_list *
1758 output_mem_stack_f (size)
1761 unw_rec_list *ptr = alloc_record (mem_stack_f);
1762 ptr->r.record.p.size = size;
1766 static unw_rec_list *
1767 output_mem_stack_v ()
1769 unw_rec_list *ptr = alloc_record (mem_stack_v);
1773 static unw_rec_list *
1777 unw_rec_list *ptr = alloc_record (psp_gr);
1778 ptr->r.record.p.gr = gr;
1782 static unw_rec_list *
1783 output_psp_sprel (offset)
1784 unsigned int offset;
1786 unw_rec_list *ptr = alloc_record (psp_sprel);
1787 ptr->r.record.p.spoff = offset / 4;
1791 static unw_rec_list *
1794 unw_rec_list *ptr = alloc_record (rp_when);
1798 static unw_rec_list *
1802 unw_rec_list *ptr = alloc_record (rp_gr);
1803 ptr->r.record.p.gr = gr;
1807 static unw_rec_list *
1811 unw_rec_list *ptr = alloc_record (rp_br);
1812 ptr->r.record.p.br = br;
1816 static unw_rec_list *
1817 output_rp_psprel (offset)
1818 unsigned int offset;
1820 unw_rec_list *ptr = alloc_record (rp_psprel);
1821 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1825 static unw_rec_list *
1826 output_rp_sprel (offset)
1827 unsigned int offset;
1829 unw_rec_list *ptr = alloc_record (rp_sprel);
1830 ptr->r.record.p.spoff = offset / 4;
1834 static unw_rec_list *
1837 unw_rec_list *ptr = alloc_record (pfs_when);
1841 static unw_rec_list *
1845 unw_rec_list *ptr = alloc_record (pfs_gr);
1846 ptr->r.record.p.gr = gr;
1850 static unw_rec_list *
1851 output_pfs_psprel (offset)
1852 unsigned int offset;
1854 unw_rec_list *ptr = alloc_record (pfs_psprel);
1855 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1859 static unw_rec_list *
1860 output_pfs_sprel (offset)
1861 unsigned int offset;
1863 unw_rec_list *ptr = alloc_record (pfs_sprel);
1864 ptr->r.record.p.spoff = offset / 4;
1868 static unw_rec_list *
1869 output_preds_when ()
1871 unw_rec_list *ptr = alloc_record (preds_when);
1875 static unw_rec_list *
1876 output_preds_gr (gr)
1879 unw_rec_list *ptr = alloc_record (preds_gr);
1880 ptr->r.record.p.gr = gr;
1884 static unw_rec_list *
1885 output_preds_psprel (offset)
1886 unsigned int offset;
1888 unw_rec_list *ptr = alloc_record (preds_psprel);
1889 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1893 static unw_rec_list *
1894 output_preds_sprel (offset)
1895 unsigned int offset;
1897 unw_rec_list *ptr = alloc_record (preds_sprel);
1898 ptr->r.record.p.spoff = offset / 4;
1902 static unw_rec_list *
1903 output_fr_mem (mask)
1906 unw_rec_list *ptr = alloc_record (fr_mem);
1907 ptr->r.record.p.rmask = mask;
1911 static unw_rec_list *
1912 output_frgr_mem (gr_mask, fr_mask)
1913 unsigned int gr_mask;
1914 unsigned int fr_mask;
1916 unw_rec_list *ptr = alloc_record (frgr_mem);
1917 ptr->r.record.p.grmask = gr_mask;
1918 ptr->r.record.p.frmask = fr_mask;
1922 static unw_rec_list *
1923 output_gr_gr (mask, reg)
1927 unw_rec_list *ptr = alloc_record (gr_gr);
1928 ptr->r.record.p.grmask = mask;
1929 ptr->r.record.p.gr = reg;
1933 static unw_rec_list *
1934 output_gr_mem (mask)
1937 unw_rec_list *ptr = alloc_record (gr_mem);
1938 ptr->r.record.p.rmask = mask;
1942 static unw_rec_list *
1943 output_br_mem (unsigned int mask)
1945 unw_rec_list *ptr = alloc_record (br_mem);
1946 ptr->r.record.p.brmask = mask;
1950 static unw_rec_list *
1951 output_br_gr (save_mask, reg)
1952 unsigned int save_mask;
1955 unw_rec_list *ptr = alloc_record (br_gr);
1956 ptr->r.record.p.brmask = save_mask;
1957 ptr->r.record.p.gr = reg;
1961 static unw_rec_list *
1962 output_spill_base (offset)
1963 unsigned int offset;
1965 unw_rec_list *ptr = alloc_record (spill_base);
1966 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1970 static unw_rec_list *
1973 unw_rec_list *ptr = alloc_record (unat_when);
1977 static unw_rec_list *
1981 unw_rec_list *ptr = alloc_record (unat_gr);
1982 ptr->r.record.p.gr = gr;
1986 static unw_rec_list *
1987 output_unat_psprel (offset)
1988 unsigned int offset;
1990 unw_rec_list *ptr = alloc_record (unat_psprel);
1991 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1995 static unw_rec_list *
1996 output_unat_sprel (offset)
1997 unsigned int offset;
1999 unw_rec_list *ptr = alloc_record (unat_sprel);
2000 ptr->r.record.p.spoff = offset / 4;
2004 static unw_rec_list *
2007 unw_rec_list *ptr = alloc_record (lc_when);
2011 static unw_rec_list *
2015 unw_rec_list *ptr = alloc_record (lc_gr);
2016 ptr->r.record.p.gr = gr;
2020 static unw_rec_list *
2021 output_lc_psprel (offset)
2022 unsigned int offset;
2024 unw_rec_list *ptr = alloc_record (lc_psprel);
2025 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2029 static unw_rec_list *
2030 output_lc_sprel (offset)
2031 unsigned int offset;
2033 unw_rec_list *ptr = alloc_record (lc_sprel);
2034 ptr->r.record.p.spoff = offset / 4;
2038 static unw_rec_list *
2041 unw_rec_list *ptr = alloc_record (fpsr_when);
2045 static unw_rec_list *
2049 unw_rec_list *ptr = alloc_record (fpsr_gr);
2050 ptr->r.record.p.gr = gr;
2054 static unw_rec_list *
2055 output_fpsr_psprel (offset)
2056 unsigned int offset;
2058 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2059 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2063 static unw_rec_list *
2064 output_fpsr_sprel (offset)
2065 unsigned int offset;
2067 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2068 ptr->r.record.p.spoff = offset / 4;
2072 static unw_rec_list *
2073 output_priunat_when_gr ()
2075 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2079 static unw_rec_list *
2080 output_priunat_when_mem ()
2082 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2086 static unw_rec_list *
2087 output_priunat_gr (gr)
2090 unw_rec_list *ptr = alloc_record (priunat_gr);
2091 ptr->r.record.p.gr = gr;
2095 static unw_rec_list *
2096 output_priunat_psprel (offset)
2097 unsigned int offset;
2099 unw_rec_list *ptr = alloc_record (priunat_psprel);
2100 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2104 static unw_rec_list *
2105 output_priunat_sprel (offset)
2106 unsigned int offset;
2108 unw_rec_list *ptr = alloc_record (priunat_sprel);
2109 ptr->r.record.p.spoff = offset / 4;
2113 static unw_rec_list *
2116 unw_rec_list *ptr = alloc_record (bsp_when);
2120 static unw_rec_list *
2124 unw_rec_list *ptr = alloc_record (bsp_gr);
2125 ptr->r.record.p.gr = gr;
2129 static unw_rec_list *
2130 output_bsp_psprel (offset)
2131 unsigned int offset;
2133 unw_rec_list *ptr = alloc_record (bsp_psprel);
2134 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2138 static unw_rec_list *
2139 output_bsp_sprel (offset)
2140 unsigned int offset;
2142 unw_rec_list *ptr = alloc_record (bsp_sprel);
2143 ptr->r.record.p.spoff = offset / 4;
2147 static unw_rec_list *
2148 output_bspstore_when ()
2150 unw_rec_list *ptr = alloc_record (bspstore_when);
2154 static unw_rec_list *
2155 output_bspstore_gr (gr)
2158 unw_rec_list *ptr = alloc_record (bspstore_gr);
2159 ptr->r.record.p.gr = gr;
2163 static unw_rec_list *
2164 output_bspstore_psprel (offset)
2165 unsigned int offset;
2167 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2168 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2172 static unw_rec_list *
2173 output_bspstore_sprel (offset)
2174 unsigned int offset;
2176 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2177 ptr->r.record.p.spoff = offset / 4;
2181 static unw_rec_list *
2184 unw_rec_list *ptr = alloc_record (rnat_when);
2188 static unw_rec_list *
2192 unw_rec_list *ptr = alloc_record (rnat_gr);
2193 ptr->r.record.p.gr = gr;
2197 static unw_rec_list *
2198 output_rnat_psprel (offset)
2199 unsigned int offset;
2201 unw_rec_list *ptr = alloc_record (rnat_psprel);
2202 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2206 static unw_rec_list *
2207 output_rnat_sprel (offset)
2208 unsigned int offset;
2210 unw_rec_list *ptr = alloc_record (rnat_sprel);
2211 ptr->r.record.p.spoff = offset / 4;
2215 static unw_rec_list *
2216 output_unwabi (abi, context)
2218 unsigned long context;
2220 unw_rec_list *ptr = alloc_record (unwabi);
2221 ptr->r.record.p.abi = abi;
2222 ptr->r.record.p.context = context;
2226 static unw_rec_list *
2227 output_epilogue (unsigned long ecount)
2229 unw_rec_list *ptr = alloc_record (epilogue);
2230 ptr->r.record.b.ecount = ecount;
2234 static unw_rec_list *
2235 output_label_state (unsigned long label)
2237 unw_rec_list *ptr = alloc_record (label_state);
2238 ptr->r.record.b.label = label;
2242 static unw_rec_list *
2243 output_copy_state (unsigned long label)
2245 unw_rec_list *ptr = alloc_record (copy_state);
2246 ptr->r.record.b.label = label;
2250 static unw_rec_list *
2251 output_spill_psprel (ab, reg, offset)
2254 unsigned int offset;
2256 unw_rec_list *ptr = alloc_record (spill_psprel);
2257 ptr->r.record.x.ab = ab;
2258 ptr->r.record.x.reg = reg;
2259 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2263 static unw_rec_list *
2264 output_spill_sprel (ab, reg, offset)
2267 unsigned int offset;
2269 unw_rec_list *ptr = alloc_record (spill_sprel);
2270 ptr->r.record.x.ab = ab;
2271 ptr->r.record.x.reg = reg;
2272 ptr->r.record.x.spoff = offset / 4;
2276 static unw_rec_list *
2277 output_spill_psprel_p (ab, reg, offset, predicate)
2280 unsigned int offset;
2281 unsigned int predicate;
2283 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2284 ptr->r.record.x.ab = ab;
2285 ptr->r.record.x.reg = reg;
2286 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2287 ptr->r.record.x.qp = predicate;
2291 static unw_rec_list *
2292 output_spill_sprel_p (ab, reg, offset, predicate)
2295 unsigned int offset;
2296 unsigned int predicate;
2298 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2299 ptr->r.record.x.ab = ab;
2300 ptr->r.record.x.reg = reg;
2301 ptr->r.record.x.spoff = offset / 4;
2302 ptr->r.record.x.qp = predicate;
2306 static unw_rec_list *
2307 output_spill_reg (ab, reg, targ_reg, xy)
2310 unsigned int targ_reg;
2313 unw_rec_list *ptr = alloc_record (spill_reg);
2314 ptr->r.record.x.ab = ab;
2315 ptr->r.record.x.reg = reg;
2316 ptr->r.record.x.treg = targ_reg;
2317 ptr->r.record.x.xy = xy;
2321 static unw_rec_list *
2322 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2325 unsigned int targ_reg;
2327 unsigned int predicate;
2329 unw_rec_list *ptr = alloc_record (spill_reg_p);
2330 ptr->r.record.x.ab = ab;
2331 ptr->r.record.x.reg = reg;
2332 ptr->r.record.x.treg = targ_reg;
2333 ptr->r.record.x.xy = xy;
2334 ptr->r.record.x.qp = predicate;
2338 /* Given a unw_rec_list process the correct format with the
2339 specified function. */
2342 process_one_record (ptr, f)
2346 unsigned long fr_mask, gr_mask;
2348 switch (ptr->r.type)
2350 /* This is a dummy record that takes up no space in the output. */
2358 /* These are taken care of by prologue/prologue_gr. */
2363 if (ptr->r.type == prologue_gr)
2364 output_R2_format (f, ptr->r.record.r.grmask,
2365 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2367 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2369 /* Output descriptor(s) for union of register spills (if any). */
2370 gr_mask = ptr->r.record.r.mask.gr_mem;
2371 fr_mask = ptr->r.record.r.mask.fr_mem;
2374 if ((fr_mask & ~0xfUL) == 0)
2375 output_P6_format (f, fr_mem, fr_mask);
2378 output_P5_format (f, gr_mask, fr_mask);
2383 output_P6_format (f, gr_mem, gr_mask);
2384 if (ptr->r.record.r.mask.br_mem)
2385 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2387 /* output imask descriptor if necessary: */
2388 if (ptr->r.record.r.mask.i)
2389 output_P4_format (f, ptr->r.record.r.mask.i,
2390 ptr->r.record.r.imask_size);
2394 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2398 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2399 ptr->r.record.p.size);
2412 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2415 output_P3_format (f, rp_br, ptr->r.record.p.br);
2418 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2426 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2435 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2445 case bspstore_sprel:
2447 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2450 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2453 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2456 as_bad ("spill_mask record unimplemented.");
2458 case priunat_when_gr:
2459 case priunat_when_mem:
2463 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2465 case priunat_psprel:
2467 case bspstore_psprel:
2469 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2472 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2475 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2479 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2482 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2483 ptr->r.record.x.reg, ptr->r.record.x.t,
2484 ptr->r.record.x.pspoff);
2487 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2488 ptr->r.record.x.reg, ptr->r.record.x.t,
2489 ptr->r.record.x.spoff);
2492 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2493 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2494 ptr->r.record.x.treg, ptr->r.record.x.t);
2496 case spill_psprel_p:
2497 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2498 ptr->r.record.x.ab, ptr->r.record.x.reg,
2499 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2502 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2503 ptr->r.record.x.ab, ptr->r.record.x.reg,
2504 ptr->r.record.x.t, ptr->r.record.x.spoff);
2507 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2508 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2509 ptr->r.record.x.xy, ptr->r.record.x.treg,
2513 as_bad ("record_type_not_valid");
2518 /* Given a unw_rec_list list, process all the records with
2519 the specified function. */
2521 process_unw_records (list, f)
2526 for (ptr = list; ptr; ptr = ptr->next)
2527 process_one_record (ptr, f);
2530 /* Determine the size of a record list in bytes. */
2532 calc_record_size (list)
2536 process_unw_records (list, count_output);
2540 /* Update IMASK bitmask to reflect the fact that one or more registers
2541 of type TYPE are saved starting at instruction with index T. If N
2542 bits are set in REGMASK, it is assumed that instructions T through
2543 T+N-1 save these registers.
2547 1: instruction saves next fp reg
2548 2: instruction saves next general reg
2549 3: instruction saves next branch reg */
2551 set_imask (region, regmask, t, type)
2552 unw_rec_list *region;
2553 unsigned long regmask;
2557 unsigned char *imask;
2558 unsigned long imask_size;
2562 imask = region->r.record.r.mask.i;
2563 imask_size = region->r.record.r.imask_size;
2566 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2567 imask = xmalloc (imask_size);
2568 memset (imask, 0, imask_size);
2570 region->r.record.r.imask_size = imask_size;
2571 region->r.record.r.mask.i = imask;
2575 pos = 2 * (3 - t % 4);
2578 if (i >= imask_size)
2580 as_bad ("Ignoring attempt to spill beyond end of region");
2584 imask[i] |= (type & 0x3) << pos;
2586 regmask &= (regmask - 1);
2596 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2597 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2598 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2602 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2603 unsigned long slot_addr;
2605 unsigned long first_addr;
2609 unsigned long index = 0;
2611 /* First time we are called, the initial address and frag are invalid. */
2612 if (first_addr == 0)
2615 /* If the two addresses are in different frags, then we need to add in
2616 the remaining size of this frag, and then the entire size of intermediate
2618 while (slot_frag != first_frag)
2620 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2624 /* We can get the final addresses only during and after
2626 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2627 index += 3 * ((first_frag->fr_next->fr_address
2628 - first_frag->fr_address
2629 - first_frag->fr_fix) >> 4);
2632 /* We don't know what the final addresses will be. We try our
2633 best to estimate. */
2634 switch (first_frag->fr_type)
2640 as_fatal ("only constant space allocation is supported");
2646 /* Take alignment into account. Assume the worst case
2647 before relaxation. */
2648 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2652 if (first_frag->fr_symbol)
2654 as_fatal ("only constant offsets are supported");
2658 index += 3 * (first_frag->fr_offset >> 4);
2662 /* Add in the full size of the frag converted to instruction slots. */
2663 index += 3 * (first_frag->fr_fix >> 4);
2664 /* Subtract away the initial part before first_addr. */
2665 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2666 + ((first_addr & 0x3) - (start_addr & 0x3)));
2668 /* Move to the beginning of the next frag. */
2669 first_frag = first_frag->fr_next;
2670 first_addr = (unsigned long) &first_frag->fr_literal;
2673 /* Add in the used part of the last frag. */
2674 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2675 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2679 /* Optimize unwind record directives. */
2681 static unw_rec_list *
2682 optimize_unw_records (list)
2688 /* If the only unwind record is ".prologue" or ".prologue" followed
2689 by ".body", then we can optimize the unwind directives away. */
2690 if (list->r.type == prologue
2691 && (list->next->r.type == endp
2692 || (list->next->r.type == body && list->next->next->r.type == endp)))
2698 /* Given a complete record list, process any records which have
2699 unresolved fields, (ie length counts for a prologue). After
2700 this has been run, all necessary information should be available
2701 within each record to generate an image. */
2704 fixup_unw_records (list, before_relax)
2708 unw_rec_list *ptr, *region = 0;
2709 unsigned long first_addr = 0, rlen = 0, t;
2710 fragS *first_frag = 0;
2712 for (ptr = list; ptr; ptr = ptr->next)
2714 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2715 as_bad (" Insn slot not set in unwind record.");
2716 t = slot_index (ptr->slot_number, ptr->slot_frag,
2717 first_addr, first_frag, before_relax);
2718 switch (ptr->r.type)
2726 unsigned long last_addr = 0;
2727 fragS *last_frag = NULL;
2729 first_addr = ptr->slot_number;
2730 first_frag = ptr->slot_frag;
2731 /* Find either the next body/prologue start, or the end of
2732 the function, and determine the size of the region. */
2733 for (last = ptr->next; last != NULL; last = last->next)
2734 if (last->r.type == prologue || last->r.type == prologue_gr
2735 || last->r.type == body || last->r.type == endp)
2737 last_addr = last->slot_number;
2738 last_frag = last->slot_frag;
2741 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2743 rlen = ptr->r.record.r.rlen = size;
2744 if (ptr->r.type == body)
2745 /* End of region. */
2753 ptr->r.record.b.t = rlen - 1 - t;
2755 /* This happens when a memory-stack-less procedure uses a
2756 ".restore sp" directive at the end of a region to pop
2758 ptr->r.record.b.t = 0;
2769 case priunat_when_gr:
2770 case priunat_when_mem:
2774 ptr->r.record.p.t = t;
2782 case spill_psprel_p:
2783 ptr->r.record.x.t = t;
2789 as_bad ("frgr_mem record before region record!");
2792 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2793 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2794 set_imask (region, ptr->r.record.p.frmask, t, 1);
2795 set_imask (region, ptr->r.record.p.grmask, t, 2);
2800 as_bad ("fr_mem record before region record!");
2803 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2804 set_imask (region, ptr->r.record.p.rmask, t, 1);
2809 as_bad ("gr_mem record before region record!");
2812 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2813 set_imask (region, ptr->r.record.p.rmask, t, 2);
2818 as_bad ("br_mem record before region record!");
2821 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2822 set_imask (region, ptr->r.record.p.brmask, t, 3);
2828 as_bad ("gr_gr record before region record!");
2831 set_imask (region, ptr->r.record.p.grmask, t, 2);
2836 as_bad ("br_gr record before region record!");
2839 set_imask (region, ptr->r.record.p.brmask, t, 3);
2848 /* Estimate the size of a frag before relaxing. We only have one type of frag
2849 to handle here, which is the unwind info frag. */
2852 ia64_estimate_size_before_relax (fragS *frag,
2853 asection *segtype ATTRIBUTE_UNUSED)
2858 /* ??? This code is identical to the first part of ia64_convert_frag. */
2859 list = (unw_rec_list *) frag->fr_opcode;
2860 fixup_unw_records (list, 0);
2862 len = calc_record_size (list);
2863 /* pad to pointer-size boundary. */
2864 pad = len % md.pointer_size;
2866 len += md.pointer_size - pad;
2867 /* Add 8 for the header. */
2869 /* Add a pointer for the personality offset. */
2870 if (frag->fr_offset)
2871 size += md.pointer_size;
2873 /* fr_var carries the max_chars that we created the fragment with.
2874 We must, of course, have allocated enough memory earlier. */
2875 assert (frag->fr_var >= size);
2877 return frag->fr_fix + size;
2880 /* This function converts a rs_machine_dependent variant frag into a
2881 normal fill frag with the unwind image from the the record list. */
2883 ia64_convert_frag (fragS *frag)
2889 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2890 list = (unw_rec_list *) frag->fr_opcode;
2891 fixup_unw_records (list, 0);
2893 len = calc_record_size (list);
2894 /* pad to pointer-size boundary. */
2895 pad = len % md.pointer_size;
2897 len += md.pointer_size - pad;
2898 /* Add 8 for the header. */
2900 /* Add a pointer for the personality offset. */
2901 if (frag->fr_offset)
2902 size += md.pointer_size;
2904 /* fr_var carries the max_chars that we created the fragment with.
2905 We must, of course, have allocated enough memory earlier. */
2906 assert (frag->fr_var >= size);
2908 /* Initialize the header area. fr_offset is initialized with
2909 unwind.personality_routine. */
2910 if (frag->fr_offset)
2912 if (md.flags & EF_IA_64_ABI64)
2913 flag_value = (bfd_vma) 3 << 32;
2915 /* 32-bit unwind info block. */
2916 flag_value = (bfd_vma) 0x1003 << 32;
2921 md_number_to_chars (frag->fr_literal,
2922 (((bfd_vma) 1 << 48) /* Version. */
2923 | flag_value /* U & E handler flags. */
2924 | (len / md.pointer_size)), /* Length. */
2927 /* Skip the header. */
2928 vbyte_mem_ptr = frag->fr_literal + 8;
2929 process_unw_records (list, output_vbyte_mem);
2931 /* Fill the padding bytes with zeros. */
2933 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2934 md.pointer_size - pad);
2936 frag->fr_fix += size;
2937 frag->fr_type = rs_fill;
2939 frag->fr_offset = 0;
2943 convert_expr_to_ab_reg (e, ab, regp)
2950 if (e->X_op != O_register)
2953 reg = e->X_add_number;
2954 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2957 *regp = reg - REG_GR;
2959 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2960 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2963 *regp = reg - REG_FR;
2965 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2968 *regp = reg - REG_BR;
2975 case REG_PR: *regp = 0; break;
2976 case REG_PSP: *regp = 1; break;
2977 case REG_PRIUNAT: *regp = 2; break;
2978 case REG_BR + 0: *regp = 3; break;
2979 case REG_AR + AR_BSP: *regp = 4; break;
2980 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2981 case REG_AR + AR_RNAT: *regp = 6; break;
2982 case REG_AR + AR_UNAT: *regp = 7; break;
2983 case REG_AR + AR_FPSR: *regp = 8; break;
2984 case REG_AR + AR_PFS: *regp = 9; break;
2985 case REG_AR + AR_LC: *regp = 10; break;
2995 convert_expr_to_xy_reg (e, xy, regp)
3002 if (e->X_op != O_register)
3005 reg = e->X_add_number;
3007 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
3010 *regp = reg - REG_GR;
3012 else if (reg >= REG_FR && reg <= (REG_FR + 127))
3015 *regp = reg - REG_FR;
3017 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3020 *regp = reg - REG_BR;
3030 /* The current frag is an alignment frag. */
3031 align_frag = frag_now;
3032 s_align_bytes (arg);
3037 int dummy ATTRIBUTE_UNUSED;
3042 radix = *input_line_pointer++;
3044 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3046 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3047 ignore_rest_of_line ();
3052 /* Helper function for .loc directives. If the assembler is not generating
3053 line number info, then we need to remember which instructions have a .loc
3054 directive, and only call dwarf2_gen_line_info for those instructions. */
3059 CURR_SLOT.loc_directive_seen = 1;
3060 dwarf2_directive_loc (x);
3063 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3065 dot_special_section (which)
3068 set_section ((char *) special_section_name[which]);
3072 in_procedure (const char *directive)
3074 if (unwind.proc_start
3075 && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0))
3077 as_bad (".%s outside of procedure", directive);
3078 ignore_rest_of_line ();
3083 in_prologue (const char *directive)
3085 if (in_procedure (directive))
3087 if (unwind.prologue)
3089 as_bad (".%s outside of prologue", directive);
3090 ignore_rest_of_line ();
3096 in_body (const char *directive)
3098 if (in_procedure (directive))
3102 as_bad (".%s outside of body region", directive);
3103 ignore_rest_of_line ();
3109 add_unwind_entry (ptr)
3113 unwind.tail->next = ptr;
3118 /* The current entry can in fact be a chain of unwind entries. */
3119 if (unwind.current_entry == NULL)
3120 unwind.current_entry = ptr;
3125 int dummy ATTRIBUTE_UNUSED;
3129 if (!in_prologue ("fframe"))
3134 if (e.X_op != O_constant)
3135 as_bad ("Operand to .fframe must be a constant");
3137 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3142 int dummy ATTRIBUTE_UNUSED;
3147 if (!in_prologue ("vframe"))
3151 reg = e.X_add_number - REG_GR;
3152 if (e.X_op == O_register && reg < 128)
3154 add_unwind_entry (output_mem_stack_v ());
3155 if (! (unwind.prologue_mask & 2))
3156 add_unwind_entry (output_psp_gr (reg));
3159 as_bad ("First operand to .vframe must be a general register");
3163 dot_vframesp (dummy)
3164 int dummy ATTRIBUTE_UNUSED;
3168 if (!in_prologue ("vframesp"))
3172 if (e.X_op == O_constant)
3174 add_unwind_entry (output_mem_stack_v ());
3175 add_unwind_entry (output_psp_sprel (e.X_add_number));
3178 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3182 dot_vframepsp (dummy)
3183 int dummy ATTRIBUTE_UNUSED;
3187 if (!in_prologue ("vframepsp"))
3191 if (e.X_op == O_constant)
3193 add_unwind_entry (output_mem_stack_v ());
3194 add_unwind_entry (output_psp_sprel (e.X_add_number));
3197 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3202 int dummy ATTRIBUTE_UNUSED;
3208 if (!in_prologue ("save"))
3211 sep = parse_operand (&e1);
3213 as_bad ("No second operand to .save");
3214 sep = parse_operand (&e2);
3216 reg1 = e1.X_add_number;
3217 reg2 = e2.X_add_number - REG_GR;
3219 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3220 if (e1.X_op == O_register)
3222 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3226 case REG_AR + AR_BSP:
3227 add_unwind_entry (output_bsp_when ());
3228 add_unwind_entry (output_bsp_gr (reg2));
3230 case REG_AR + AR_BSPSTORE:
3231 add_unwind_entry (output_bspstore_when ());
3232 add_unwind_entry (output_bspstore_gr (reg2));
3234 case REG_AR + AR_RNAT:
3235 add_unwind_entry (output_rnat_when ());
3236 add_unwind_entry (output_rnat_gr (reg2));
3238 case REG_AR + AR_UNAT:
3239 add_unwind_entry (output_unat_when ());
3240 add_unwind_entry (output_unat_gr (reg2));
3242 case REG_AR + AR_FPSR:
3243 add_unwind_entry (output_fpsr_when ());
3244 add_unwind_entry (output_fpsr_gr (reg2));
3246 case REG_AR + AR_PFS:
3247 add_unwind_entry (output_pfs_when ());
3248 if (! (unwind.prologue_mask & 4))
3249 add_unwind_entry (output_pfs_gr (reg2));
3251 case REG_AR + AR_LC:
3252 add_unwind_entry (output_lc_when ());
3253 add_unwind_entry (output_lc_gr (reg2));
3256 add_unwind_entry (output_rp_when ());
3257 if (! (unwind.prologue_mask & 8))
3258 add_unwind_entry (output_rp_gr (reg2));
3261 add_unwind_entry (output_preds_when ());
3262 if (! (unwind.prologue_mask & 1))
3263 add_unwind_entry (output_preds_gr (reg2));
3266 add_unwind_entry (output_priunat_when_gr ());
3267 add_unwind_entry (output_priunat_gr (reg2));
3270 as_bad ("First operand not a valid register");
3274 as_bad (" Second operand not a valid register");
3277 as_bad ("First operand not a register");
3282 int dummy ATTRIBUTE_UNUSED;
3285 unsigned long ecount; /* # of _additional_ regions to pop */
3288 if (!in_body ("restore"))
3291 sep = parse_operand (&e1);
3292 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3294 as_bad ("First operand to .restore must be stack pointer (sp)");
3300 parse_operand (&e2);
3301 if (e2.X_op != O_constant || e2.X_add_number < 0)
3303 as_bad ("Second operand to .restore must be a constant >= 0");
3306 ecount = e2.X_add_number;
3309 ecount = unwind.prologue_count - 1;
3311 if (ecount >= unwind.prologue_count)
3313 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3314 ecount + 1, unwind.prologue_count);
3318 add_unwind_entry (output_epilogue (ecount));
3320 if (ecount < unwind.prologue_count)
3321 unwind.prologue_count -= ecount + 1;
3323 unwind.prologue_count = 0;
3327 dot_restorereg (dummy)
3328 int dummy ATTRIBUTE_UNUSED;
3330 unsigned int ab, reg;
3333 if (!in_procedure ("restorereg"))
3338 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3340 as_bad ("First operand to .restorereg must be a preserved register");
3343 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3347 dot_restorereg_p (dummy)
3348 int dummy ATTRIBUTE_UNUSED;
3350 unsigned int qp, ab, reg;
3354 if (!in_procedure ("restorereg.p"))
3357 sep = parse_operand (&e1);
3360 as_bad ("No second operand to .restorereg.p");
3364 parse_operand (&e2);
3366 qp = e1.X_add_number - REG_P;
3367 if (e1.X_op != O_register || qp > 63)
3369 as_bad ("First operand to .restorereg.p must be a predicate");
3373 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3375 as_bad ("Second operand to .restorereg.p must be a preserved register");
3378 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3381 static char *special_linkonce_name[] =
3383 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3387 start_unwind_section (const segT text_seg, int sec_index, int linkonce_empty)
3390 Use a slightly ugly scheme to derive the unwind section names from
3391 the text section name:
3393 text sect. unwind table sect.
3394 name: name: comments:
3395 ---------- ----------------- --------------------------------
3397 .text.foo .IA_64.unwind.text.foo
3398 .foo .IA_64.unwind.foo
3400 .gnu.linkonce.ia64unw.foo
3401 _info .IA_64.unwind_info gas issues error message (ditto)
3402 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3404 This mapping is done so that:
3406 (a) An object file with unwind info only in .text will use
3407 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3408 This follows the letter of the ABI and also ensures backwards
3409 compatibility with older toolchains.
3411 (b) An object file with unwind info in multiple text sections
3412 will use separate unwind sections for each text section.
3413 This allows us to properly set the "sh_info" and "sh_link"
3414 fields in SHT_IA_64_UNWIND as required by the ABI and also
3415 lets GNU ld support programs with multiple segments
3416 containing unwind info (as might be the case for certain
3417 embedded applications).
3419 (c) An error is issued if there would be a name clash.
3422 const char *text_name, *sec_text_name;
3424 const char *prefix = special_section_name [sec_index];
3426 size_t prefix_len, suffix_len, sec_name_len;
3428 sec_text_name = segment_name (text_seg);
3429 text_name = sec_text_name;
3430 if (strncmp (text_name, "_info", 5) == 0)
3432 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3434 ignore_rest_of_line ();
3437 if (strcmp (text_name, ".text") == 0)
3440 /* Build the unwind section name by appending the (possibly stripped)
3441 text section name to the unwind prefix. */
3443 if (strncmp (text_name, ".gnu.linkonce.t.",
3444 sizeof (".gnu.linkonce.t.") - 1) == 0)
3446 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3447 suffix += sizeof (".gnu.linkonce.t.") - 1;
3449 else if (linkonce_empty)
3452 prefix_len = strlen (prefix);
3453 suffix_len = strlen (suffix);
3454 sec_name_len = prefix_len + suffix_len;
3455 sec_name = alloca (sec_name_len + 1);
3456 memcpy (sec_name, prefix, prefix_len);
3457 memcpy (sec_name + prefix_len, suffix, suffix_len);
3458 sec_name [sec_name_len] = '\0';
3460 /* Handle COMDAT group. */
3461 if (suffix == text_name && (text_seg->flags & SEC_LINK_ONCE) != 0)
3464 size_t len, group_name_len;
3465 const char *group_name = elf_group_name (text_seg);
3467 if (group_name == NULL)
3469 as_bad ("Group section `%s' has no group signature",
3471 ignore_rest_of_line ();
3474 /* We have to construct a fake section directive. */
3475 group_name_len = strlen (group_name);
3477 + 16 /* ,"aG",@progbits, */
3478 + group_name_len /* ,group_name */
3481 section = alloca (len + 1);
3482 memcpy (section, sec_name, sec_name_len);
3483 memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3484 memcpy (section + sec_name_len + 16, group_name, group_name_len);
3485 memcpy (section + len - 7, ",comdat", 7);
3486 section [len] = '\0';
3487 set_section (section);
3491 set_section (sec_name);
3492 bfd_set_section_flags (stdoutput, now_seg,
3493 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3496 elf_linked_to_section (now_seg) = text_seg;
3500 generate_unwind_image (const segT text_seg)
3505 /* Mark the end of the unwind info, so that we can compute the size of the
3506 last unwind region. */
3507 add_unwind_entry (output_endp ());
3509 /* Force out pending instructions, to make sure all unwind records have
3510 a valid slot_number field. */
3511 ia64_flush_insns ();
3513 /* Generate the unwind record. */
3514 list = optimize_unw_records (unwind.list);
3515 fixup_unw_records (list, 1);
3516 size = calc_record_size (list);
3518 if (size > 0 || unwind.force_unwind_entry)
3520 unwind.force_unwind_entry = 0;
3521 /* pad to pointer-size boundary. */
3522 pad = size % md.pointer_size;
3524 size += md.pointer_size - pad;
3525 /* Add 8 for the header. */
3527 /* Add a pointer for the personality offset. */
3528 if (unwind.personality_routine)
3529 size += md.pointer_size;
3532 /* If there are unwind records, switch sections, and output the info. */
3536 bfd_reloc_code_real_type reloc;
3538 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 0);
3540 /* Make sure the section has 4 byte alignment for ILP32 and
3541 8 byte alignment for LP64. */
3542 frag_align (md.pointer_size_shift, 0, 0);
3543 record_alignment (now_seg, md.pointer_size_shift);
3545 /* Set expression which points to start of unwind descriptor area. */
3546 unwind.info = expr_build_dot ();
3548 frag_var (rs_machine_dependent, size, size, 0, 0,
3549 (offsetT) (long) unwind.personality_routine,
3552 /* Add the personality address to the image. */
3553 if (unwind.personality_routine != 0)
3555 exp.X_op = O_symbol;
3556 exp.X_add_symbol = unwind.personality_routine;
3557 exp.X_add_number = 0;
3559 if (md.flags & EF_IA_64_BE)
3561 if (md.flags & EF_IA_64_ABI64)
3562 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3564 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3568 if (md.flags & EF_IA_64_ABI64)
3569 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3571 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3574 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3575 md.pointer_size, &exp, 0, reloc);
3576 unwind.personality_routine = 0;
3580 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 1);
3582 free_saved_prologue_counts ();
3583 unwind.list = unwind.tail = unwind.current_entry = NULL;
3587 dot_handlerdata (dummy)
3588 int dummy ATTRIBUTE_UNUSED;
3590 if (!in_procedure ("handlerdata"))
3592 unwind.force_unwind_entry = 1;
3594 /* Remember which segment we're in so we can switch back after .endp */
3595 unwind.saved_text_seg = now_seg;
3596 unwind.saved_text_subseg = now_subseg;
3598 /* Generate unwind info into unwind-info section and then leave that
3599 section as the currently active one so dataXX directives go into
3600 the language specific data area of the unwind info block. */
3601 generate_unwind_image (now_seg);
3602 demand_empty_rest_of_line ();
3606 dot_unwentry (dummy)
3607 int dummy ATTRIBUTE_UNUSED;
3609 if (!in_procedure ("unwentry"))
3611 unwind.force_unwind_entry = 1;
3612 demand_empty_rest_of_line ();
3617 int dummy ATTRIBUTE_UNUSED;
3622 if (!in_prologue ("altrp"))
3626 reg = e.X_add_number - REG_BR;
3627 if (e.X_op == O_register && reg < 8)
3628 add_unwind_entry (output_rp_br (reg));
3630 as_bad ("First operand not a valid branch register");
3634 dot_savemem (psprel)
3641 if (!in_prologue (psprel ? "savepsp" : "savesp"))
3644 sep = parse_operand (&e1);
3646 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3647 sep = parse_operand (&e2);
3649 reg1 = e1.X_add_number;
3650 val = e2.X_add_number;
3652 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3653 if (e1.X_op == O_register)
3655 if (e2.X_op == O_constant)
3659 case REG_AR + AR_BSP:
3660 add_unwind_entry (output_bsp_when ());
3661 add_unwind_entry ((psprel
3663 : output_bsp_sprel) (val));
3665 case REG_AR + AR_BSPSTORE:
3666 add_unwind_entry (output_bspstore_when ());
3667 add_unwind_entry ((psprel
3668 ? output_bspstore_psprel
3669 : output_bspstore_sprel) (val));
3671 case REG_AR + AR_RNAT:
3672 add_unwind_entry (output_rnat_when ());
3673 add_unwind_entry ((psprel
3674 ? output_rnat_psprel
3675 : output_rnat_sprel) (val));
3677 case REG_AR + AR_UNAT:
3678 add_unwind_entry (output_unat_when ());
3679 add_unwind_entry ((psprel
3680 ? output_unat_psprel
3681 : output_unat_sprel) (val));
3683 case REG_AR + AR_FPSR:
3684 add_unwind_entry (output_fpsr_when ());
3685 add_unwind_entry ((psprel
3686 ? output_fpsr_psprel
3687 : output_fpsr_sprel) (val));
3689 case REG_AR + AR_PFS:
3690 add_unwind_entry (output_pfs_when ());
3691 add_unwind_entry ((psprel
3693 : output_pfs_sprel) (val));
3695 case REG_AR + AR_LC:
3696 add_unwind_entry (output_lc_when ());
3697 add_unwind_entry ((psprel
3699 : output_lc_sprel) (val));
3702 add_unwind_entry (output_rp_when ());
3703 add_unwind_entry ((psprel
3705 : output_rp_sprel) (val));
3708 add_unwind_entry (output_preds_when ());
3709 add_unwind_entry ((psprel
3710 ? output_preds_psprel
3711 : output_preds_sprel) (val));
3714 add_unwind_entry (output_priunat_when_mem ());
3715 add_unwind_entry ((psprel
3716 ? output_priunat_psprel
3717 : output_priunat_sprel) (val));
3720 as_bad ("First operand not a valid register");
3724 as_bad (" Second operand not a valid constant");
3727 as_bad ("First operand not a register");
3732 int dummy ATTRIBUTE_UNUSED;
3737 if (!in_prologue ("save.g"))
3740 sep = parse_operand (&e1);
3742 parse_operand (&e2);
3744 if (e1.X_op != O_constant)
3745 as_bad ("First operand to .save.g must be a constant.");
3748 int grmask = e1.X_add_number;
3750 add_unwind_entry (output_gr_mem (grmask));
3753 int reg = e2.X_add_number - REG_GR;
3754 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3755 add_unwind_entry (output_gr_gr (grmask, reg));
3757 as_bad ("Second operand is an invalid register.");
3764 int dummy ATTRIBUTE_UNUSED;
3769 if (!in_prologue ("save.f"))
3772 sep = parse_operand (&e1);
3774 if (e1.X_op != O_constant)
3775 as_bad ("Operand to .save.f must be a constant.");
3777 add_unwind_entry (output_fr_mem (e1.X_add_number));
3782 int dummy ATTRIBUTE_UNUSED;
3789 if (!in_prologue ("save.b"))
3792 sep = parse_operand (&e1);
3793 if (e1.X_op != O_constant)
3795 as_bad ("First operand to .save.b must be a constant.");
3798 brmask = e1.X_add_number;
3802 sep = parse_operand (&e2);
3803 reg = e2.X_add_number - REG_GR;
3804 if (e2.X_op != O_register || reg > 127)
3806 as_bad ("Second operand to .save.b must be a general register.");
3809 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3812 add_unwind_entry (output_br_mem (brmask));
3814 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3815 demand_empty_rest_of_line ();
3820 int dummy ATTRIBUTE_UNUSED;
3825 if (!in_prologue ("save.gf"))
3828 sep = parse_operand (&e1);
3830 parse_operand (&e2);
3832 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3833 as_bad ("Both operands of .save.gf must be constants.");
3836 int grmask = e1.X_add_number;
3837 int frmask = e2.X_add_number;
3838 add_unwind_entry (output_frgr_mem (grmask, frmask));
3844 int dummy ATTRIBUTE_UNUSED;
3849 if (!in_prologue ("spill"))
3852 sep = parse_operand (&e);
3853 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3854 demand_empty_rest_of_line ();
3856 if (e.X_op != O_constant)
3857 as_bad ("Operand to .spill must be a constant");
3859 add_unwind_entry (output_spill_base (e.X_add_number));
3863 dot_spillreg (dummy)
3864 int dummy ATTRIBUTE_UNUSED;
3866 int sep, ab, xy, reg, treg;
3869 if (!in_procedure ("spillreg"))
3872 sep = parse_operand (&e1);
3875 as_bad ("No second operand to .spillreg");
3879 parse_operand (&e2);
3881 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3883 as_bad ("First operand to .spillreg must be a preserved register");
3887 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3889 as_bad ("Second operand to .spillreg must be a register");
3893 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3897 dot_spillmem (psprel)
3903 if (!in_procedure ("spillmem"))
3906 sep = parse_operand (&e1);
3909 as_bad ("Second operand missing");
3913 parse_operand (&e2);
3915 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3917 as_bad ("First operand to .spill%s must be a preserved register",
3918 psprel ? "psp" : "sp");
3922 if (e2.X_op != O_constant)
3924 as_bad ("Second operand to .spill%s must be a constant",
3925 psprel ? "psp" : "sp");
3930 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3932 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3936 dot_spillreg_p (dummy)
3937 int dummy ATTRIBUTE_UNUSED;
3939 int sep, ab, xy, reg, treg;
3940 expressionS e1, e2, e3;
3943 if (!in_procedure ("spillreg.p"))
3946 sep = parse_operand (&e1);
3949 as_bad ("No second and third operand to .spillreg.p");
3953 sep = parse_operand (&e2);
3956 as_bad ("No third operand to .spillreg.p");
3960 parse_operand (&e3);
3962 qp = e1.X_add_number - REG_P;
3964 if (e1.X_op != O_register || qp > 63)
3966 as_bad ("First operand to .spillreg.p must be a predicate");
3970 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3972 as_bad ("Second operand to .spillreg.p must be a preserved register");
3976 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3978 as_bad ("Third operand to .spillreg.p must be a register");
3982 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3986 dot_spillmem_p (psprel)
3989 expressionS e1, e2, e3;
3993 if (!in_procedure ("spillmem.p"))
3996 sep = parse_operand (&e1);
3999 as_bad ("Second operand missing");
4003 parse_operand (&e2);
4006 as_bad ("Second operand missing");
4010 parse_operand (&e3);
4012 qp = e1.X_add_number - REG_P;
4013 if (e1.X_op != O_register || qp > 63)
4015 as_bad ("First operand to .spill%s_p must be a predicate",
4016 psprel ? "psp" : "sp");
4020 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
4022 as_bad ("Second operand to .spill%s_p must be a preserved register",
4023 psprel ? "psp" : "sp");
4027 if (e3.X_op != O_constant)
4029 as_bad ("Third operand to .spill%s_p must be a constant",
4030 psprel ? "psp" : "sp");
4035 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
4037 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
4041 get_saved_prologue_count (lbl)
4044 label_prologue_count *lpc = unwind.saved_prologue_counts;
4046 while (lpc != NULL && lpc->label_number != lbl)
4050 return lpc->prologue_count;
4052 as_bad ("Missing .label_state %ld", lbl);
4057 save_prologue_count (lbl, count)
4061 label_prologue_count *lpc = unwind.saved_prologue_counts;
4063 while (lpc != NULL && lpc->label_number != lbl)
4067 lpc->prologue_count = count;
4070 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
4072 new_lpc->next = unwind.saved_prologue_counts;
4073 new_lpc->label_number = lbl;
4074 new_lpc->prologue_count = count;
4075 unwind.saved_prologue_counts = new_lpc;
4080 free_saved_prologue_counts ()
4082 label_prologue_count *lpc = unwind.saved_prologue_counts;
4083 label_prologue_count *next;
4092 unwind.saved_prologue_counts = NULL;
4096 dot_label_state (dummy)
4097 int dummy ATTRIBUTE_UNUSED;
4101 if (!in_body ("label_state"))
4105 if (e.X_op != O_constant)
4107 as_bad ("Operand to .label_state must be a constant");
4110 add_unwind_entry (output_label_state (e.X_add_number));
4111 save_prologue_count (e.X_add_number, unwind.prologue_count);
4115 dot_copy_state (dummy)
4116 int dummy ATTRIBUTE_UNUSED;
4120 if (!in_body ("copy_state"))
4124 if (e.X_op != O_constant)
4126 as_bad ("Operand to .copy_state must be a constant");
4129 add_unwind_entry (output_copy_state (e.X_add_number));
4130 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
4135 int dummy ATTRIBUTE_UNUSED;
4140 if (!in_procedure ("unwabi"))
4143 sep = parse_operand (&e1);
4146 as_bad ("Second operand to .unwabi missing");
4149 sep = parse_operand (&e2);
4150 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4151 demand_empty_rest_of_line ();
4153 if (e1.X_op != O_constant)
4155 as_bad ("First operand to .unwabi must be a constant");
4159 if (e2.X_op != O_constant)
4161 as_bad ("Second operand to .unwabi must be a constant");
4165 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4169 dot_personality (dummy)
4170 int dummy ATTRIBUTE_UNUSED;
4173 if (!in_procedure ("personality"))
4176 name = input_line_pointer;
4177 c = get_symbol_end ();
4178 p = input_line_pointer;
4179 unwind.personality_routine = symbol_find_or_make (name);
4180 unwind.force_unwind_entry = 1;
4183 demand_empty_rest_of_line ();
4188 int dummy ATTRIBUTE_UNUSED;
4193 unwind.proc_start = 0;
4194 /* Parse names of main and alternate entry points and mark them as
4195 function symbols: */
4199 name = input_line_pointer;
4200 c = get_symbol_end ();
4201 p = input_line_pointer;
4203 as_bad ("Empty argument of .proc");
4206 sym = symbol_find_or_make (name);
4207 if (S_IS_DEFINED (sym))
4208 as_bad ("`%s' was already defined", name);
4209 else if (unwind.proc_start == 0)
4211 unwind.proc_start = sym;
4213 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4217 if (*input_line_pointer != ',')
4219 ++input_line_pointer;
4221 if (unwind.proc_start == 0)
4222 unwind.proc_start = expr_build_dot ();
4223 demand_empty_rest_of_line ();
4226 unwind.prologue = 0;
4227 unwind.prologue_count = 0;
4230 unwind.list = unwind.tail = unwind.current_entry = NULL;
4231 unwind.personality_routine = 0;
4236 int dummy ATTRIBUTE_UNUSED;
4238 if (!in_procedure ("body"))
4240 if (!unwind.prologue && !unwind.body && unwind.insn)
4241 as_warn ("Initial .body should precede any instructions");
4243 unwind.prologue = 0;
4244 unwind.prologue_mask = 0;
4247 add_unwind_entry (output_body ());
4248 demand_empty_rest_of_line ();
4252 dot_prologue (dummy)
4253 int dummy ATTRIBUTE_UNUSED;
4256 int mask = 0, grsave = 0;
4258 if (!in_procedure ("prologue"))
4260 if (unwind.prologue)
4262 as_bad (".prologue within prologue");
4263 ignore_rest_of_line ();
4266 if (!unwind.body && unwind.insn)
4267 as_warn ("Initial .prologue should precede any instructions");
4269 if (!is_it_end_of_statement ())
4272 sep = parse_operand (&e1);
4274 as_bad ("No second operand to .prologue");
4275 sep = parse_operand (&e2);
4276 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4277 demand_empty_rest_of_line ();
4279 if (e1.X_op == O_constant)
4281 mask = e1.X_add_number;
4283 if (e2.X_op == O_constant)
4284 grsave = e2.X_add_number;
4285 else if (e2.X_op == O_register
4286 && (grsave = e2.X_add_number - REG_GR) < 128)
4289 as_bad ("Second operand not a constant or general register");
4291 add_unwind_entry (output_prologue_gr (mask, grsave));
4294 as_bad ("First operand not a constant");
4297 add_unwind_entry (output_prologue ());
4299 unwind.prologue = 1;
4300 unwind.prologue_mask = mask;
4302 ++unwind.prologue_count;
4307 int dummy ATTRIBUTE_UNUSED;
4311 int bytes_per_address;
4314 subsegT saved_subseg;
4318 if (!in_procedure ("endp"))
4321 if (unwind.saved_text_seg)
4323 saved_seg = unwind.saved_text_seg;
4324 saved_subseg = unwind.saved_text_subseg;
4325 unwind.saved_text_seg = NULL;
4329 saved_seg = now_seg;
4330 saved_subseg = now_subseg;
4333 insn_group_break (1, 0, 0);
4335 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4337 generate_unwind_image (saved_seg);
4339 if (unwind.info || unwind.force_unwind_entry)
4343 subseg_set (md.last_text_seg, 0);
4344 proc_end = expr_build_dot ();
4346 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 0);
4348 /* Make sure that section has 4 byte alignment for ILP32 and
4349 8 byte alignment for LP64. */
4350 record_alignment (now_seg, md.pointer_size_shift);
4352 /* Need space for 3 pointers for procedure start, procedure end,
4354 ptr = frag_more (3 * md.pointer_size);
4355 where = frag_now_fix () - (3 * md.pointer_size);
4356 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4358 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4359 e.X_op = O_pseudo_fixup;
4360 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4362 e.X_add_symbol = unwind.proc_start;
4363 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4365 e.X_op = O_pseudo_fixup;
4366 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4368 e.X_add_symbol = proc_end;
4369 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4370 bytes_per_address, &e);
4374 e.X_op = O_pseudo_fixup;
4375 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4377 e.X_add_symbol = unwind.info;
4378 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4379 bytes_per_address, &e);
4382 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4387 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 1);
4389 subseg_set (saved_seg, saved_subseg);
4391 /* Parse names of main and alternate entry points and set symbol sizes. */
4395 name = input_line_pointer;
4396 c = get_symbol_end ();
4397 p = input_line_pointer;
4399 as_bad ("Empty argument of .endp");
4402 sym = symbol_find (name);
4403 if (!sym || !S_IS_DEFINED (sym))
4404 as_bad ("`%s' was not defined within procedure", name);
4405 else if (unwind.proc_start
4406 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4407 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4409 fragS *fr = symbol_get_frag (unwind.proc_start);
4410 fragS *frag = symbol_get_frag (sym);
4412 /* Check whether the function label is at or beyond last
4414 while (fr && fr != frag)
4418 if (frag == frag_now && SEG_NORMAL (now_seg))
4419 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4422 symbol_get_obj (sym)->size =
4423 (expressionS *) xmalloc (sizeof (expressionS));
4424 symbol_get_obj (sym)->size->X_op = O_subtract;
4425 symbol_get_obj (sym)->size->X_add_symbol
4426 = symbol_new (FAKE_LABEL_NAME, now_seg,
4427 frag_now_fix (), frag_now);
4428 symbol_get_obj (sym)->size->X_op_symbol = sym;
4429 symbol_get_obj (sym)->size->X_add_number = 0;
4436 if (*input_line_pointer != ',')
4438 ++input_line_pointer;
4440 demand_empty_rest_of_line ();
4441 unwind.proc_start = unwind.info = 0;
4445 dot_template (template)
4448 CURR_SLOT.user_template = template;
4453 int dummy ATTRIBUTE_UNUSED;
4455 int ins, locs, outs, rots;
4457 if (is_it_end_of_statement ())
4458 ins = locs = outs = rots = 0;
4461 ins = get_absolute_expression ();
4462 if (*input_line_pointer++ != ',')
4464 locs = get_absolute_expression ();
4465 if (*input_line_pointer++ != ',')
4467 outs = get_absolute_expression ();
4468 if (*input_line_pointer++ != ',')
4470 rots = get_absolute_expression ();
4472 set_regstack (ins, locs, outs, rots);
4476 as_bad ("Comma expected");
4477 ignore_rest_of_line ();
4484 unsigned num_regs, num_alloced = 0;
4485 struct dynreg **drpp, *dr;
4486 int ch, base_reg = 0;
4492 case DYNREG_GR: base_reg = REG_GR + 32; break;
4493 case DYNREG_FR: base_reg = REG_FR + 32; break;
4494 case DYNREG_PR: base_reg = REG_P + 16; break;
4498 /* First, remove existing names from hash table. */
4499 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4501 hash_delete (md.dynreg_hash, dr->name);
4505 drpp = &md.dynreg[type];
4508 start = input_line_pointer;
4509 ch = get_symbol_end ();
4510 *input_line_pointer = ch;
4511 len = (input_line_pointer - start);
4514 if (*input_line_pointer != '[')
4516 as_bad ("Expected '['");
4519 ++input_line_pointer; /* skip '[' */
4521 num_regs = get_absolute_expression ();
4523 if (*input_line_pointer++ != ']')
4525 as_bad ("Expected ']'");
4530 num_alloced += num_regs;
4534 if (num_alloced > md.rot.num_regs)
4536 as_bad ("Used more than the declared %d rotating registers",
4542 if (num_alloced > 96)
4544 as_bad ("Used more than the available 96 rotating registers");
4549 if (num_alloced > 48)
4551 as_bad ("Used more than the available 48 rotating registers");
4560 name = obstack_alloc (¬es, len + 1);
4561 memcpy (name, start, len);
4566 *drpp = obstack_alloc (¬es, sizeof (*dr));
4567 memset (*drpp, 0, sizeof (*dr));
4572 dr->num_regs = num_regs;
4573 dr->base = base_reg;
4575 base_reg += num_regs;
4577 if (hash_insert (md.dynreg_hash, name, dr))
4579 as_bad ("Attempt to redefine register set `%s'", name);
4583 if (*input_line_pointer != ',')
4585 ++input_line_pointer; /* skip comma */
4588 demand_empty_rest_of_line ();
4592 ignore_rest_of_line ();
4596 dot_byteorder (byteorder)
4599 segment_info_type *seginfo = seg_info (now_seg);
4601 if (byteorder == -1)
4603 if (seginfo->tc_segment_info_data.endian == 0)
4604 seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2;
4605 byteorder = seginfo->tc_segment_info_data.endian == 1;
4608 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4610 if (target_big_endian != byteorder)
4612 target_big_endian = byteorder;
4613 if (target_big_endian)
4615 ia64_number_to_chars = number_to_chars_bigendian;
4616 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4620 ia64_number_to_chars = number_to_chars_littleendian;
4621 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4628 int dummy ATTRIBUTE_UNUSED;
4635 option = input_line_pointer;
4636 ch = get_symbol_end ();
4637 if (strcmp (option, "lsb") == 0)
4638 md.flags &= ~EF_IA_64_BE;
4639 else if (strcmp (option, "msb") == 0)
4640 md.flags |= EF_IA_64_BE;
4641 else if (strcmp (option, "abi32") == 0)
4642 md.flags &= ~EF_IA_64_ABI64;
4643 else if (strcmp (option, "abi64") == 0)
4644 md.flags |= EF_IA_64_ABI64;
4646 as_bad ("Unknown psr option `%s'", option);
4647 *input_line_pointer = ch;
4650 if (*input_line_pointer != ',')
4653 ++input_line_pointer;
4656 demand_empty_rest_of_line ();
4661 int dummy ATTRIBUTE_UNUSED;
4663 new_logical_line (0, get_absolute_expression ());
4664 demand_empty_rest_of_line ();
4668 parse_section_name ()
4674 if (*input_line_pointer == '"')
4675 name = demand_copy_C_string (&len);
4678 char *start = input_line_pointer;
4679 char c = get_symbol_end ();
4681 if (input_line_pointer == start)
4683 as_bad ("Missing section name");
4684 ignore_rest_of_line ();
4687 name = obstack_copy (¬es, start, input_line_pointer - start + 1);
4688 *input_line_pointer = c;
4692 ignore_rest_of_line ();
4696 if (*input_line_pointer != ',')
4698 as_bad ("Comma expected after section name");
4699 ignore_rest_of_line ();
4702 ++input_line_pointer; /* skip comma */
4710 char *name = parse_section_name ();
4714 md.keep_pending_output = 1;
4716 obstack_free (¬es, name);
4718 obj_elf_previous (0);
4719 md.keep_pending_output = 0;
4722 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4725 stmt_float_cons (kind)
4746 ia64_do_align (alignment);
4754 int saved_auto_align = md.auto_align;
4758 md.auto_align = saved_auto_align;
4762 dot_xfloat_cons (kind)
4765 char *name = parse_section_name ();
4769 md.keep_pending_output = 1;
4771 obstack_free (¬es, name);
4772 stmt_float_cons (kind);
4773 obj_elf_previous (0);
4774 md.keep_pending_output = 0;
4778 dot_xstringer (zero)
4781 char *name = parse_section_name ();
4785 md.keep_pending_output = 1;
4787 obstack_free (¬es, name);
4789 obj_elf_previous (0);
4790 md.keep_pending_output = 0;
4797 int saved_auto_align = md.auto_align;
4798 char *name = parse_section_name ();
4802 md.keep_pending_output = 1;
4804 obstack_free (¬es, name);
4807 md.auto_align = saved_auto_align;
4808 obj_elf_previous (0);
4809 md.keep_pending_output = 0;
4813 dot_xfloat_cons_ua (kind)
4816 int saved_auto_align = md.auto_align;
4817 char *name = parse_section_name ();
4821 md.keep_pending_output = 1;
4823 obstack_free (¬es, name);
4825 stmt_float_cons (kind);
4826 md.auto_align = saved_auto_align;
4827 obj_elf_previous (0);
4828 md.keep_pending_output = 0;
4831 /* .reg.val <regname>,value */
4835 int dummy ATTRIBUTE_UNUSED;
4840 if (reg.X_op != O_register)
4842 as_bad (_("Register name expected"));
4843 ignore_rest_of_line ();
4845 else if (*input_line_pointer++ != ',')
4847 as_bad (_("Comma expected"));
4848 ignore_rest_of_line ();
4852 valueT value = get_absolute_expression ();
4853 int regno = reg.X_add_number;
4854 if (regno < REG_GR || regno > REG_GR + 128)
4855 as_warn (_("Register value annotation ignored"));
4858 gr_values[regno - REG_GR].known = 1;
4859 gr_values[regno - REG_GR].value = value;
4860 gr_values[regno - REG_GR].path = md.path;
4863 demand_empty_rest_of_line ();
4868 .serialize.instruction
4871 dot_serialize (type)
4874 insn_group_break (0, 0, 0);
4876 instruction_serialization ();
4878 data_serialization ();
4879 insn_group_break (0, 0, 0);
4880 demand_empty_rest_of_line ();
4883 /* select dv checking mode
4888 A stop is inserted when changing modes
4895 if (md.manual_bundling)
4896 as_warn (_("Directive invalid within a bundle"));
4898 if (type == 'E' || type == 'A')
4899 md.mode_explicitly_set = 0;
4901 md.mode_explicitly_set = 1;
4908 if (md.explicit_mode)
4909 insn_group_break (1, 0, 0);
4910 md.explicit_mode = 0;
4914 if (!md.explicit_mode)
4915 insn_group_break (1, 0, 0);
4916 md.explicit_mode = 1;
4920 if (md.explicit_mode != md.default_explicit_mode)
4921 insn_group_break (1, 0, 0);
4922 md.explicit_mode = md.default_explicit_mode;
4923 md.mode_explicitly_set = 0;
4934 for (regno = 0; regno < 64; regno++)
4936 if (mask & ((valueT) 1 << regno))
4938 fprintf (stderr, "%s p%d", comma, regno);
4945 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear)
4946 .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply)
4947 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex)
4948 .pred.safe_across_calls p1 [, p2 [,...]]
4957 int p1 = -1, p2 = -1;
4961 if (*input_line_pointer == '"')
4964 char *form = demand_copy_C_string (&len);
4966 if (strcmp (form, "mutex") == 0)
4968 else if (strcmp (form, "clear") == 0)
4970 else if (strcmp (form, "imply") == 0)
4972 obstack_free (¬es, form);
4974 else if (*input_line_pointer == '@')
4976 char *form = ++input_line_pointer;
4977 char c = get_symbol_end();
4979 if (strcmp (form, "mutex") == 0)
4981 else if (strcmp (form, "clear") == 0)
4983 else if (strcmp (form, "imply") == 0)
4985 *input_line_pointer = c;
4989 as_bad (_("Missing predicate relation type"));
4990 ignore_rest_of_line ();
4995 as_bad (_("Unrecognized predicate relation type"));
4996 ignore_rest_of_line ();
4999 if (*input_line_pointer == ',')
5000 ++input_line_pointer;
5010 if (TOUPPER (*input_line_pointer) != 'P'
5011 || (regno = atoi (++input_line_pointer)) < 0
5014 as_bad (_("Predicate register expected"));
5015 ignore_rest_of_line ();
5018 while (ISDIGIT (*input_line_pointer))
5019 ++input_line_pointer;
5026 as_warn (_("Duplicate predicate register ignored"));
5029 /* See if it's a range. */
5030 if (*input_line_pointer == '-')
5033 ++input_line_pointer;
5035 if (TOUPPER (*input_line_pointer) != 'P'
5036 || (regno = atoi (++input_line_pointer)) < 0
5039 as_bad (_("Predicate register expected"));
5040 ignore_rest_of_line ();
5043 while (ISDIGIT (*input_line_pointer))
5044 ++input_line_pointer;
5048 as_bad (_("Bad register range"));
5049 ignore_rest_of_line ();
5060 if (*input_line_pointer != ',')
5062 ++input_line_pointer;
5071 clear_qp_mutex (mask);
5072 clear_qp_implies (mask, (valueT) 0);
5075 if (count != 2 || p1 == -1 || p2 == -1)
5076 as_bad (_("Predicate source and target required"));
5077 else if (p1 == 0 || p2 == 0)
5078 as_bad (_("Use of p0 is not valid in this context"));
5080 add_qp_imply (p1, p2);
5085 as_bad (_("At least two PR arguments expected"));
5090 as_bad (_("Use of p0 is not valid in this context"));
5093 add_qp_mutex (mask);
5096 /* note that we don't override any existing relations */
5099 as_bad (_("At least one PR argument expected"));
5104 fprintf (stderr, "Safe across calls: ");
5105 print_prmask (mask);
5106 fprintf (stderr, "\n");
5108 qp_safe_across_calls = mask;
5111 demand_empty_rest_of_line ();
5114 /* .entry label [, label [, ...]]
5115 Hint to DV code that the given labels are to be considered entry points.
5116 Otherwise, only global labels are considered entry points. */
5120 int dummy ATTRIBUTE_UNUSED;
5129 name = input_line_pointer;
5130 c = get_symbol_end ();
5131 symbolP = symbol_find_or_make (name);
5133 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
5135 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
5138 *input_line_pointer = c;
5140 c = *input_line_pointer;
5143 input_line_pointer++;
5145 if (*input_line_pointer == '\n')
5151 demand_empty_rest_of_line ();
5154 /* .mem.offset offset, base
5155 "base" is used to distinguish between offsets from a different base. */
5158 dot_mem_offset (dummy)
5159 int dummy ATTRIBUTE_UNUSED;
5161 md.mem_offset.hint = 1;
5162 md.mem_offset.offset = get_absolute_expression ();
5163 if (*input_line_pointer != ',')
5165 as_bad (_("Comma expected"));
5166 ignore_rest_of_line ();
5169 ++input_line_pointer;
5170 md.mem_offset.base = get_absolute_expression ();
5171 demand_empty_rest_of_line ();
5174 /* ia64-specific pseudo-ops: */
5175 const pseudo_typeS md_pseudo_table[] =
5177 { "radix", dot_radix, 0 },
5178 { "lcomm", s_lcomm_bytes, 1 },
5179 { "loc", dot_loc, 0 },
5180 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
5181 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
5182 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
5183 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
5184 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
5185 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
5186 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
5187 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
5188 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
5189 { "proc", dot_proc, 0 },
5190 { "body", dot_body, 0 },
5191 { "prologue", dot_prologue, 0 },
5192 { "endp", dot_endp, 0 },
5194 { "fframe", dot_fframe, 0 },
5195 { "vframe", dot_vframe, 0 },
5196 { "vframesp", dot_vframesp, 0 },
5197 { "vframepsp", dot_vframepsp, 0 },
5198 { "save", dot_save, 0 },
5199 { "restore", dot_restore, 0 },
5200 { "restorereg", dot_restorereg, 0 },
5201 { "restorereg.p", dot_restorereg_p, 0 },
5202 { "handlerdata", dot_handlerdata, 0 },
5203 { "unwentry", dot_unwentry, 0 },
5204 { "altrp", dot_altrp, 0 },
5205 { "savesp", dot_savemem, 0 },
5206 { "savepsp", dot_savemem, 1 },
5207 { "save.g", dot_saveg, 0 },
5208 { "save.f", dot_savef, 0 },
5209 { "save.b", dot_saveb, 0 },
5210 { "save.gf", dot_savegf, 0 },
5211 { "spill", dot_spill, 0 },
5212 { "spillreg", dot_spillreg, 0 },
5213 { "spillsp", dot_spillmem, 0 },
5214 { "spillpsp", dot_spillmem, 1 },
5215 { "spillreg.p", dot_spillreg_p, 0 },
5216 { "spillsp.p", dot_spillmem_p, 0 },
5217 { "spillpsp.p", dot_spillmem_p, 1 },
5218 { "label_state", dot_label_state, 0 },
5219 { "copy_state", dot_copy_state, 0 },
5220 { "unwabi", dot_unwabi, 0 },
5221 { "personality", dot_personality, 0 },
5222 { "mii", dot_template, 0x0 },
5223 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5224 { "mlx", dot_template, 0x2 },
5225 { "mmi", dot_template, 0x4 },
5226 { "mfi", dot_template, 0x6 },
5227 { "mmf", dot_template, 0x7 },
5228 { "mib", dot_template, 0x8 },
5229 { "mbb", dot_template, 0x9 },
5230 { "bbb", dot_template, 0xb },
5231 { "mmb", dot_template, 0xc },
5232 { "mfb", dot_template, 0xe },
5233 { "align", dot_align, 0 },
5234 { "regstk", dot_regstk, 0 },
5235 { "rotr", dot_rot, DYNREG_GR },
5236 { "rotf", dot_rot, DYNREG_FR },
5237 { "rotp", dot_rot, DYNREG_PR },
5238 { "lsb", dot_byteorder, 0 },
5239 { "msb", dot_byteorder, 1 },
5240 { "psr", dot_psr, 0 },
5241 { "alias", dot_alias, 0 },
5242 { "secalias", dot_alias, 1 },
5243 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5245 { "xdata1", dot_xdata, 1 },
5246 { "xdata2", dot_xdata, 2 },
5247 { "xdata4", dot_xdata, 4 },
5248 { "xdata8", dot_xdata, 8 },
5249 { "xdata16", dot_xdata, 16 },
5250 { "xreal4", dot_xfloat_cons, 'f' },
5251 { "xreal8", dot_xfloat_cons, 'd' },
5252 { "xreal10", dot_xfloat_cons, 'x' },
5253 { "xreal16", dot_xfloat_cons, 'X' },
5254 { "xstring", dot_xstringer, 0 },
5255 { "xstringz", dot_xstringer, 1 },
5257 /* unaligned versions: */
5258 { "xdata2.ua", dot_xdata_ua, 2 },
5259 { "xdata4.ua", dot_xdata_ua, 4 },
5260 { "xdata8.ua", dot_xdata_ua, 8 },
5261 { "xdata16.ua", dot_xdata_ua, 16 },
5262 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5263 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5264 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5265 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5267 /* annotations/DV checking support */
5268 { "entry", dot_entry, 0 },
5269 { "mem.offset", dot_mem_offset, 0 },
5270 { "pred.rel", dot_pred_rel, 0 },
5271 { "pred.rel.clear", dot_pred_rel, 'c' },
5272 { "pred.rel.imply", dot_pred_rel, 'i' },
5273 { "pred.rel.mutex", dot_pred_rel, 'm' },
5274 { "pred.safe_across_calls", dot_pred_rel, 's' },
5275 { "reg.val", dot_reg_val, 0 },
5276 { "serialize.data", dot_serialize, 0 },
5277 { "serialize.instruction", dot_serialize, 1 },
5278 { "auto", dot_dv_mode, 'a' },
5279 { "explicit", dot_dv_mode, 'e' },
5280 { "default", dot_dv_mode, 'd' },
5282 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5283 IA-64 aligns data allocation pseudo-ops by default, so we have to
5284 tell it that these ones are supposed to be unaligned. Long term,
5285 should rewrite so that only IA-64 specific data allocation pseudo-ops
5286 are aligned by default. */
5287 {"2byte", stmt_cons_ua, 2},
5288 {"4byte", stmt_cons_ua, 4},
5289 {"8byte", stmt_cons_ua, 8},
5294 static const struct pseudo_opcode
5297 void (*handler) (int);
5302 /* these are more like pseudo-ops, but don't start with a dot */
5303 { "data1", cons, 1 },
5304 { "data2", cons, 2 },
5305 { "data4", cons, 4 },
5306 { "data8", cons, 8 },
5307 { "data16", cons, 16 },
5308 { "real4", stmt_float_cons, 'f' },
5309 { "real8", stmt_float_cons, 'd' },
5310 { "real10", stmt_float_cons, 'x' },
5311 { "real16", stmt_float_cons, 'X' },
5312 { "string", stringer, 0 },
5313 { "stringz", stringer, 1 },
5315 /* unaligned versions: */
5316 { "data2.ua", stmt_cons_ua, 2 },
5317 { "data4.ua", stmt_cons_ua, 4 },
5318 { "data8.ua", stmt_cons_ua, 8 },
5319 { "data16.ua", stmt_cons_ua, 16 },
5320 { "real4.ua", float_cons, 'f' },
5321 { "real8.ua", float_cons, 'd' },
5322 { "real10.ua", float_cons, 'x' },
5323 { "real16.ua", float_cons, 'X' },
5326 /* Declare a register by creating a symbol for it and entering it in
5327 the symbol table. */
5330 declare_register (name, regnum)
5337 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5339 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5341 as_fatal ("Inserting \"%s\" into register table failed: %s",
5348 declare_register_set (prefix, num_regs, base_regnum)
5356 for (i = 0; i < num_regs; ++i)
5358 sprintf (name, "%s%u", prefix, i);
5359 declare_register (name, base_regnum + i);
5364 operand_width (opnd)
5365 enum ia64_opnd opnd;
5367 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5368 unsigned int bits = 0;
5372 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5373 bits += odesc->field[i].bits;
5378 static enum operand_match_result
5379 operand_match (idesc, index, e)
5380 const struct ia64_opcode *idesc;
5384 enum ia64_opnd opnd = idesc->operands[index];
5385 int bits, relocatable = 0;
5386 struct insn_fix *fix;
5393 case IA64_OPND_AR_CCV:
5394 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5395 return OPERAND_MATCH;
5398 case IA64_OPND_AR_CSD:
5399 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5400 return OPERAND_MATCH;
5403 case IA64_OPND_AR_PFS:
5404 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5405 return OPERAND_MATCH;
5409 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5410 return OPERAND_MATCH;
5414 if (e->X_op == O_register && e->X_add_number == REG_IP)
5415 return OPERAND_MATCH;
5419 if (e->X_op == O_register && e->X_add_number == REG_PR)
5420 return OPERAND_MATCH;
5423 case IA64_OPND_PR_ROT:
5424 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5425 return OPERAND_MATCH;
5429 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5430 return OPERAND_MATCH;
5433 case IA64_OPND_PSR_L:
5434 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5435 return OPERAND_MATCH;
5438 case IA64_OPND_PSR_UM:
5439 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5440 return OPERAND_MATCH;
5444 if (e->X_op == O_constant)
5446 if (e->X_add_number == 1)
5447 return OPERAND_MATCH;
5449 return OPERAND_OUT_OF_RANGE;
5454 if (e->X_op == O_constant)
5456 if (e->X_add_number == 8)
5457 return OPERAND_MATCH;
5459 return OPERAND_OUT_OF_RANGE;
5464 if (e->X_op == O_constant)
5466 if (e->X_add_number == 16)
5467 return OPERAND_MATCH;
5469 return OPERAND_OUT_OF_RANGE;
5473 /* register operands: */
5476 if (e->X_op == O_register && e->X_add_number >= REG_AR
5477 && e->X_add_number < REG_AR + 128)
5478 return OPERAND_MATCH;
5483 if (e->X_op == O_register && e->X_add_number >= REG_BR
5484 && e->X_add_number < REG_BR + 8)
5485 return OPERAND_MATCH;
5489 if (e->X_op == O_register && e->X_add_number >= REG_CR
5490 && e->X_add_number < REG_CR + 128)
5491 return OPERAND_MATCH;
5498 if (e->X_op == O_register && e->X_add_number >= REG_FR
5499 && e->X_add_number < REG_FR + 128)
5500 return OPERAND_MATCH;
5505 if (e->X_op == O_register && e->X_add_number >= REG_P
5506 && e->X_add_number < REG_P + 64)
5507 return OPERAND_MATCH;
5513 if (e->X_op == O_register && e->X_add_number >= REG_GR
5514 && e->X_add_number < REG_GR + 128)
5515 return OPERAND_MATCH;
5518 case IA64_OPND_R3_2:
5519 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5521 if (e->X_add_number < REG_GR + 4)
5522 return OPERAND_MATCH;
5523 else if (e->X_add_number < REG_GR + 128)
5524 return OPERAND_OUT_OF_RANGE;
5528 /* indirect operands: */
5529 case IA64_OPND_CPUID_R3:
5530 case IA64_OPND_DBR_R3:
5531 case IA64_OPND_DTR_R3:
5532 case IA64_OPND_ITR_R3:
5533 case IA64_OPND_IBR_R3:
5534 case IA64_OPND_MSR_R3:
5535 case IA64_OPND_PKR_R3:
5536 case IA64_OPND_PMC_R3:
5537 case IA64_OPND_PMD_R3:
5538 case IA64_OPND_RR_R3:
5539 if (e->X_op == O_index && e->X_op_symbol
5540 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5541 == opnd - IA64_OPND_CPUID_R3))
5542 return OPERAND_MATCH;
5546 if (e->X_op == O_index && !e->X_op_symbol)
5547 return OPERAND_MATCH;
5550 /* immediate operands: */
5551 case IA64_OPND_CNT2a:
5552 case IA64_OPND_LEN4:
5553 case IA64_OPND_LEN6:
5554 bits = operand_width (idesc->operands[index]);
5555 if (e->X_op == O_constant)
5557 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5558 return OPERAND_MATCH;
5560 return OPERAND_OUT_OF_RANGE;
5564 case IA64_OPND_CNT2b:
5565 if (e->X_op == O_constant)
5567 if ((bfd_vma) (e->X_add_number - 1) < 3)
5568 return OPERAND_MATCH;
5570 return OPERAND_OUT_OF_RANGE;
5574 case IA64_OPND_CNT2c:
5575 val = e->X_add_number;
5576 if (e->X_op == O_constant)
5578 if ((val == 0 || val == 7 || val == 15 || val == 16))
5579 return OPERAND_MATCH;
5581 return OPERAND_OUT_OF_RANGE;
5586 /* SOR must be an integer multiple of 8 */
5587 if (e->X_op == O_constant && e->X_add_number & 0x7)
5588 return OPERAND_OUT_OF_RANGE;
5591 if (e->X_op == O_constant)
5593 if ((bfd_vma) e->X_add_number <= 96)
5594 return OPERAND_MATCH;
5596 return OPERAND_OUT_OF_RANGE;
5600 case IA64_OPND_IMMU62:
5601 if (e->X_op == O_constant)
5603 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5604 return OPERAND_MATCH;
5606 return OPERAND_OUT_OF_RANGE;
5610 /* FIXME -- need 62-bit relocation type */
5611 as_bad (_("62-bit relocation not yet implemented"));
5615 case IA64_OPND_IMMU64:
5616 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5617 || e->X_op == O_subtract)
5619 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5620 fix->code = BFD_RELOC_IA64_IMM64;
5621 if (e->X_op != O_subtract)
5623 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5624 if (e->X_op == O_pseudo_fixup)
5628 fix->opnd = idesc->operands[index];
5631 ++CURR_SLOT.num_fixups;
5632 return OPERAND_MATCH;
5634 else if (e->X_op == O_constant)
5635 return OPERAND_MATCH;
5638 case IA64_OPND_CCNT5:
5639 case IA64_OPND_CNT5:
5640 case IA64_OPND_CNT6:
5641 case IA64_OPND_CPOS6a:
5642 case IA64_OPND_CPOS6b:
5643 case IA64_OPND_CPOS6c:
5644 case IA64_OPND_IMMU2:
5645 case IA64_OPND_IMMU7a:
5646 case IA64_OPND_IMMU7b:
5647 case IA64_OPND_IMMU21:
5648 case IA64_OPND_IMMU24:
5649 case IA64_OPND_MBTYPE4:
5650 case IA64_OPND_MHTYPE8:
5651 case IA64_OPND_POS6:
5652 bits = operand_width (idesc->operands[index]);
5653 if (e->X_op == O_constant)
5655 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5656 return OPERAND_MATCH;
5658 return OPERAND_OUT_OF_RANGE;
5662 case IA64_OPND_IMMU9:
5663 bits = operand_width (idesc->operands[index]);
5664 if (e->X_op == O_constant)
5666 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5668 int lobits = e->X_add_number & 0x3;
5669 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5670 e->X_add_number |= (bfd_vma) 0x3;
5671 return OPERAND_MATCH;
5674 return OPERAND_OUT_OF_RANGE;
5678 case IA64_OPND_IMM44:
5679 /* least 16 bits must be zero */
5680 if ((e->X_add_number & 0xffff) != 0)
5681 /* XXX technically, this is wrong: we should not be issuing warning
5682 messages until we're sure this instruction pattern is going to
5684 as_warn (_("lower 16 bits of mask ignored"));
5686 if (e->X_op == O_constant)
5688 if (((e->X_add_number >= 0
5689 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5690 || (e->X_add_number < 0
5691 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5694 if (e->X_add_number >= 0
5695 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5697 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5699 return OPERAND_MATCH;
5702 return OPERAND_OUT_OF_RANGE;
5706 case IA64_OPND_IMM17:
5707 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5708 if (e->X_op == O_constant)
5710 if (((e->X_add_number >= 0
5711 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5712 || (e->X_add_number < 0
5713 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5716 if (e->X_add_number >= 0
5717 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5719 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5721 return OPERAND_MATCH;
5724 return OPERAND_OUT_OF_RANGE;
5728 case IA64_OPND_IMM14:
5729 case IA64_OPND_IMM22:
5731 case IA64_OPND_IMM1:
5732 case IA64_OPND_IMM8:
5733 case IA64_OPND_IMM8U4:
5734 case IA64_OPND_IMM8M1:
5735 case IA64_OPND_IMM8M1U4:
5736 case IA64_OPND_IMM8M1U8:
5737 case IA64_OPND_IMM9a:
5738 case IA64_OPND_IMM9b:
5739 bits = operand_width (idesc->operands[index]);
5740 if (relocatable && (e->X_op == O_symbol
5741 || e->X_op == O_subtract
5742 || e->X_op == O_pseudo_fixup))
5744 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5746 if (idesc->operands[index] == IA64_OPND_IMM14)
5747 fix->code = BFD_RELOC_IA64_IMM14;
5749 fix->code = BFD_RELOC_IA64_IMM22;
5751 if (e->X_op != O_subtract)
5753 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5754 if (e->X_op == O_pseudo_fixup)
5758 fix->opnd = idesc->operands[index];
5761 ++CURR_SLOT.num_fixups;
5762 return OPERAND_MATCH;
5764 else if (e->X_op != O_constant
5765 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5766 return OPERAND_MISMATCH;
5768 if (opnd == IA64_OPND_IMM8M1U4)
5770 /* Zero is not valid for unsigned compares that take an adjusted
5771 constant immediate range. */
5772 if (e->X_add_number == 0)
5773 return OPERAND_OUT_OF_RANGE;
5775 /* Sign-extend 32-bit unsigned numbers, so that the following range
5776 checks will work. */
5777 val = e->X_add_number;
5778 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5779 && ((val & ((bfd_vma) 1 << 31)) != 0))
5780 val = ((val << 32) >> 32);
5782 /* Check for 0x100000000. This is valid because
5783 0x100000000-1 is the same as ((uint32_t) -1). */
5784 if (val == ((bfd_signed_vma) 1 << 32))
5785 return OPERAND_MATCH;
5789 else if (opnd == IA64_OPND_IMM8M1U8)
5791 /* Zero is not valid for unsigned compares that take an adjusted
5792 constant immediate range. */
5793 if (e->X_add_number == 0)
5794 return OPERAND_OUT_OF_RANGE;
5796 /* Check for 0x10000000000000000. */
5797 if (e->X_op == O_big)
5799 if (generic_bignum[0] == 0
5800 && generic_bignum[1] == 0
5801 && generic_bignum[2] == 0
5802 && generic_bignum[3] == 0
5803 && generic_bignum[4] == 1)
5804 return OPERAND_MATCH;
5806 return OPERAND_OUT_OF_RANGE;
5809 val = e->X_add_number - 1;
5811 else if (opnd == IA64_OPND_IMM8M1)
5812 val = e->X_add_number - 1;
5813 else if (opnd == IA64_OPND_IMM8U4)
5815 /* Sign-extend 32-bit unsigned numbers, so that the following range
5816 checks will work. */
5817 val = e->X_add_number;
5818 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5819 && ((val & ((bfd_vma) 1 << 31)) != 0))
5820 val = ((val << 32) >> 32);
5823 val = e->X_add_number;
5825 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5826 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5827 return OPERAND_MATCH;
5829 return OPERAND_OUT_OF_RANGE;
5831 case IA64_OPND_INC3:
5832 /* +/- 1, 4, 8, 16 */
5833 val = e->X_add_number;
5836 if (e->X_op == O_constant)
5838 if ((val == 1 || val == 4 || val == 8 || val == 16))
5839 return OPERAND_MATCH;
5841 return OPERAND_OUT_OF_RANGE;
5845 case IA64_OPND_TGT25:
5846 case IA64_OPND_TGT25b:
5847 case IA64_OPND_TGT25c:
5848 case IA64_OPND_TGT64:
5849 if (e->X_op == O_symbol)
5851 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5852 if (opnd == IA64_OPND_TGT25)
5853 fix->code = BFD_RELOC_IA64_PCREL21F;
5854 else if (opnd == IA64_OPND_TGT25b)
5855 fix->code = BFD_RELOC_IA64_PCREL21M;
5856 else if (opnd == IA64_OPND_TGT25c)
5857 fix->code = BFD_RELOC_IA64_PCREL21B;
5858 else if (opnd == IA64_OPND_TGT64)
5859 fix->code = BFD_RELOC_IA64_PCREL60B;
5863 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5864 fix->opnd = idesc->operands[index];
5867 ++CURR_SLOT.num_fixups;
5868 return OPERAND_MATCH;
5870 case IA64_OPND_TAG13:
5871 case IA64_OPND_TAG13b:
5875 return OPERAND_MATCH;
5878 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5879 /* There are no external relocs for TAG13/TAG13b fields, so we
5880 create a dummy reloc. This will not live past md_apply_fix3. */
5881 fix->code = BFD_RELOC_UNUSED;
5882 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5883 fix->opnd = idesc->operands[index];
5886 ++CURR_SLOT.num_fixups;
5887 return OPERAND_MATCH;
5894 case IA64_OPND_LDXMOV:
5895 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5896 fix->code = BFD_RELOC_IA64_LDXMOV;
5897 fix->opnd = idesc->operands[index];
5900 ++CURR_SLOT.num_fixups;
5901 return OPERAND_MATCH;
5906 return OPERAND_MISMATCH;
5915 memset (e, 0, sizeof (*e));
5918 if (*input_line_pointer != '}')
5920 sep = *input_line_pointer++;
5924 if (!md.manual_bundling)
5925 as_warn ("Found '}' when manual bundling is off");
5927 CURR_SLOT.manual_bundling_off = 1;
5928 md.manual_bundling = 0;
5934 /* Returns the next entry in the opcode table that matches the one in
5935 IDESC, and frees the entry in IDESC. If no matching entry is
5936 found, NULL is returned instead. */
5938 static struct ia64_opcode *
5939 get_next_opcode (struct ia64_opcode *idesc)
5941 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5942 ia64_free_opcode (idesc);
5946 /* Parse the operands for the opcode and find the opcode variant that
5947 matches the specified operands, or NULL if no match is possible. */
5949 static struct ia64_opcode *
5950 parse_operands (idesc)
5951 struct ia64_opcode *idesc;
5953 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5954 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5955 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5956 enum operand_match_result result;
5958 char *first_arg = 0, *end, *saved_input_pointer;
5961 assert (strlen (idesc->name) <= 128);
5963 strcpy (mnemonic, idesc->name);
5964 if (idesc->operands[2] == IA64_OPND_SOF
5965 || idesc->operands[1] == IA64_OPND_SOF)
5967 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5968 can't parse the first operand until we have parsed the
5969 remaining operands of the "alloc" instruction. */
5971 first_arg = input_line_pointer;
5972 end = strchr (input_line_pointer, '=');
5975 as_bad ("Expected separator `='");
5978 input_line_pointer = end + 1;
5985 if (i < NELEMS (CURR_SLOT.opnd))
5987 sep = parse_operand (CURR_SLOT.opnd + i);
5988 if (CURR_SLOT.opnd[i].X_op == O_absent)
5995 sep = parse_operand (&dummy);
5996 if (dummy.X_op == O_absent)
6002 if (sep != '=' && sep != ',')
6007 if (num_outputs > 0)
6008 as_bad ("Duplicate equal sign (=) in instruction");
6010 num_outputs = i + 1;
6015 as_bad ("Illegal operand separator `%c'", sep);
6019 if (idesc->operands[2] == IA64_OPND_SOF
6020 || idesc->operands[1] == IA64_OPND_SOF)
6022 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
6023 know (strcmp (idesc->name, "alloc") == 0);
6024 i = (CURR_SLOT.opnd[1].X_op == O_register
6025 && CURR_SLOT.opnd[1].X_add_number == REG_AR + AR_PFS) ? 2 : 1;
6026 if (num_operands == i + 3 /* first_arg not included in this count! */
6027 && CURR_SLOT.opnd[i].X_op == O_constant
6028 && CURR_SLOT.opnd[i + 1].X_op == O_constant
6029 && CURR_SLOT.opnd[i + 2].X_op == O_constant
6030 && CURR_SLOT.opnd[i + 3].X_op == O_constant)
6032 sof = set_regstack (CURR_SLOT.opnd[i].X_add_number,
6033 CURR_SLOT.opnd[i + 1].X_add_number,
6034 CURR_SLOT.opnd[i + 2].X_add_number,
6035 CURR_SLOT.opnd[i + 3].X_add_number);
6037 /* now we can parse the first arg: */
6038 saved_input_pointer = input_line_pointer;
6039 input_line_pointer = first_arg;
6040 sep = parse_operand (CURR_SLOT.opnd + 0);
6042 --num_outputs; /* force error */
6043 input_line_pointer = saved_input_pointer;
6045 CURR_SLOT.opnd[i].X_add_number = sof;
6046 CURR_SLOT.opnd[i + 1].X_add_number
6047 = sof - CURR_SLOT.opnd[i + 2].X_add_number;
6048 CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3];
6052 highest_unmatched_operand = -4;
6053 curr_out_of_range_pos = -1;
6055 for (; idesc; idesc = get_next_opcode (idesc))
6057 if (num_outputs != idesc->num_outputs)
6058 continue; /* mismatch in # of outputs */
6059 if (highest_unmatched_operand < 0)
6060 highest_unmatched_operand |= 1;
6061 if (num_operands > NELEMS (idesc->operands)
6062 || (num_operands < NELEMS (idesc->operands)
6063 && idesc->operands[num_operands])
6064 || (num_operands > 0 && !idesc->operands[num_operands - 1]))
6065 continue; /* mismatch in number of arguments */
6066 if (highest_unmatched_operand < 0)
6067 highest_unmatched_operand |= 2;
6069 CURR_SLOT.num_fixups = 0;
6071 /* Try to match all operands. If we see an out-of-range operand,
6072 then continue trying to match the rest of the operands, since if
6073 the rest match, then this idesc will give the best error message. */
6075 out_of_range_pos = -1;
6076 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
6078 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
6079 if (result != OPERAND_MATCH)
6081 if (result != OPERAND_OUT_OF_RANGE)
6083 if (out_of_range_pos < 0)
6084 /* remember position of the first out-of-range operand: */
6085 out_of_range_pos = i;
6089 /* If we did not match all operands, or if at least one operand was
6090 out-of-range, then this idesc does not match. Keep track of which
6091 idesc matched the most operands before failing. If we have two
6092 idescs that failed at the same position, and one had an out-of-range
6093 operand, then prefer the out-of-range operand. Thus if we have
6094 "add r0=0x1000000,r1" we get an error saying the constant is out
6095 of range instead of an error saying that the constant should have been
6098 if (i != num_operands || out_of_range_pos >= 0)
6100 if (i > highest_unmatched_operand
6101 || (i == highest_unmatched_operand
6102 && out_of_range_pos > curr_out_of_range_pos))
6104 highest_unmatched_operand = i;
6105 if (out_of_range_pos >= 0)
6107 expected_operand = idesc->operands[out_of_range_pos];
6108 error_pos = out_of_range_pos;
6112 expected_operand = idesc->operands[i];
6115 curr_out_of_range_pos = out_of_range_pos;
6124 if (expected_operand)
6125 as_bad ("Operand %u of `%s' should be %s",
6126 error_pos + 1, mnemonic,
6127 elf64_ia64_operands[expected_operand].desc);
6128 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1))
6129 as_bad ("Wrong number of output operands");
6130 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2))
6131 as_bad ("Wrong number of input operands");
6133 as_bad ("Operand mismatch");
6139 /* Keep track of state necessary to determine whether a NOP is necessary
6140 to avoid an erratum in A and B step Itanium chips, and return 1 if we
6141 detect a case where additional NOPs may be necessary. */
6143 errata_nop_necessary_p (slot, insn_unit)
6145 enum ia64_unit insn_unit;
6148 struct group *this_group = md.last_groups + md.group_idx;
6149 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
6150 struct ia64_opcode *idesc = slot->idesc;
6152 /* Test whether this could be the first insn in a problematic sequence. */
6153 if (insn_unit == IA64_UNIT_F)
6155 for (i = 0; i < idesc->num_outputs; i++)
6156 if (idesc->operands[i] == IA64_OPND_P1
6157 || idesc->operands[i] == IA64_OPND_P2)
6159 int regno = slot->opnd[i].X_add_number - REG_P;
6160 /* Ignore invalid operands; they generate errors elsewhere. */
6163 this_group->p_reg_set[regno] = 1;
6167 /* Test whether this could be the second insn in a problematic sequence. */
6168 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
6169 && prev_group->p_reg_set[slot->qp_regno])
6171 for (i = 0; i < idesc->num_outputs; i++)
6172 if (idesc->operands[i] == IA64_OPND_R1
6173 || idesc->operands[i] == IA64_OPND_R2
6174 || idesc->operands[i] == IA64_OPND_R3)
6176 int regno = slot->opnd[i].X_add_number - REG_GR;
6177 /* Ignore invalid operands; they generate errors elsewhere. */
6180 if (strncmp (idesc->name, "add", 3) != 0
6181 && strncmp (idesc->name, "sub", 3) != 0
6182 && strncmp (idesc->name, "shladd", 6) != 0
6183 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
6184 this_group->g_reg_set_conditionally[regno] = 1;
6188 /* Test whether this could be the third insn in a problematic sequence. */
6189 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
6191 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
6192 idesc->operands[i] == IA64_OPND_R3
6193 /* For mov indirect. */
6194 || idesc->operands[i] == IA64_OPND_RR_R3
6195 || idesc->operands[i] == IA64_OPND_DBR_R3
6196 || idesc->operands[i] == IA64_OPND_IBR_R3
6197 || idesc->operands[i] == IA64_OPND_PKR_R3
6198 || idesc->operands[i] == IA64_OPND_PMC_R3
6199 || idesc->operands[i] == IA64_OPND_PMD_R3
6200 || idesc->operands[i] == IA64_OPND_MSR_R3
6201 || idesc->operands[i] == IA64_OPND_CPUID_R3
6203 || idesc->operands[i] == IA64_OPND_ITR_R3
6204 || idesc->operands[i] == IA64_OPND_DTR_R3
6205 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
6206 || idesc->operands[i] == IA64_OPND_MR3)
6208 int regno = slot->opnd[i].X_add_number - REG_GR;
6209 /* Ignore invalid operands; they generate errors elsewhere. */
6212 if (idesc->operands[i] == IA64_OPND_R3)
6214 if (strcmp (idesc->name, "fc") != 0
6215 && strcmp (idesc->name, "tak") != 0
6216 && strcmp (idesc->name, "thash") != 0
6217 && strcmp (idesc->name, "tpa") != 0
6218 && strcmp (idesc->name, "ttag") != 0
6219 && strncmp (idesc->name, "ptr", 3) != 0
6220 && strncmp (idesc->name, "ptc", 3) != 0
6221 && strncmp (idesc->name, "probe", 5) != 0)
6224 if (prev_group->g_reg_set_conditionally[regno])
6232 build_insn (slot, insnp)
6236 const struct ia64_operand *odesc, *o2desc;
6237 struct ia64_opcode *idesc = slot->idesc;
6238 bfd_signed_vma insn, val;
6242 insn = idesc->opcode | slot->qp_regno;
6244 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6246 if (slot->opnd[i].X_op == O_register
6247 || slot->opnd[i].X_op == O_constant
6248 || slot->opnd[i].X_op == O_index)
6249 val = slot->opnd[i].X_add_number;
6250 else if (slot->opnd[i].X_op == O_big)
6252 /* This must be the value 0x10000000000000000. */
6253 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6259 switch (idesc->operands[i])
6261 case IA64_OPND_IMMU64:
6262 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6263 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6264 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6265 | (((val >> 63) & 0x1) << 36));
6268 case IA64_OPND_IMMU62:
6269 val &= 0x3fffffffffffffffULL;
6270 if (val != slot->opnd[i].X_add_number)
6271 as_warn (_("Value truncated to 62 bits"));
6272 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6273 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6276 case IA64_OPND_TGT64:
6278 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6279 insn |= ((((val >> 59) & 0x1) << 36)
6280 | (((val >> 0) & 0xfffff) << 13));
6311 case IA64_OPND_R3_2:
6312 case IA64_OPND_CPUID_R3:
6313 case IA64_OPND_DBR_R3:
6314 case IA64_OPND_DTR_R3:
6315 case IA64_OPND_ITR_R3:
6316 case IA64_OPND_IBR_R3:
6318 case IA64_OPND_MSR_R3:
6319 case IA64_OPND_PKR_R3:
6320 case IA64_OPND_PMC_R3:
6321 case IA64_OPND_PMD_R3:
6322 case IA64_OPND_RR_R3:
6330 odesc = elf64_ia64_operands + idesc->operands[i];
6331 err = (*odesc->insert) (odesc, val, &insn);
6333 as_bad_where (slot->src_file, slot->src_line,
6334 "Bad operand value: %s", err);
6335 if (idesc->flags & IA64_OPCODE_PSEUDO)
6337 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6338 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6340 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6341 (*o2desc->insert) (o2desc, val, &insn);
6343 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6344 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6345 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6347 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6348 (*o2desc->insert) (o2desc, 64 - val, &insn);
6358 int manual_bundling_off = 0, manual_bundling = 0;
6359 enum ia64_unit required_unit, insn_unit = 0;
6360 enum ia64_insn_type type[3], insn_type;
6361 unsigned int template, orig_template;
6362 bfd_vma insn[3] = { -1, -1, -1 };
6363 struct ia64_opcode *idesc;
6364 int end_of_insn_group = 0, user_template = -1;
6365 int n, i, j, first, curr;
6366 unw_rec_list *ptr, *last_ptr, *end_ptr;
6367 bfd_vma t0 = 0, t1 = 0;
6368 struct label_fix *lfix;
6369 struct insn_fix *ifix;
6375 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6376 know (first >= 0 & first < NUM_SLOTS);
6377 n = MIN (3, md.num_slots_in_use);
6379 /* Determine template: user user_template if specified, best match
6382 if (md.slot[first].user_template >= 0)
6383 user_template = template = md.slot[first].user_template;
6386 /* Auto select appropriate template. */
6387 memset (type, 0, sizeof (type));
6389 for (i = 0; i < n; ++i)
6391 if (md.slot[curr].label_fixups && i != 0)
6393 type[i] = md.slot[curr].idesc->type;
6394 curr = (curr + 1) % NUM_SLOTS;
6396 template = best_template[type[0]][type[1]][type[2]];
6399 /* initialize instructions with appropriate nops: */
6400 for (i = 0; i < 3; ++i)
6401 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6405 /* Check to see if this bundle is at an offset that is a multiple of 16-bytes
6406 from the start of the frag. */
6407 addr_mod = frag_now_fix () & 15;
6408 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
6409 as_bad (_("instruction address is not a multiple of 16"));
6410 frag_now->insn_addr = addr_mod;
6411 frag_now->has_code = 1;
6413 /* now fill in slots with as many insns as possible: */
6415 idesc = md.slot[curr].idesc;
6416 end_of_insn_group = 0;
6417 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6419 /* If we have unwind records, we may need to update some now. */
6420 ptr = md.slot[curr].unwind_record;
6423 /* Find the last prologue/body record in the list for the current
6424 insn, and set the slot number for all records up to that point.
6425 This needs to be done now, because prologue/body records refer to
6426 the current point, not the point after the instruction has been
6427 issued. This matters because there may have been nops emitted
6428 meanwhile. Any non-prologue non-body record followed by a
6429 prologue/body record must also refer to the current point. */
6431 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6432 for (; ptr != end_ptr; ptr = ptr->next)
6433 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6434 || ptr->r.type == body)
6438 /* Make last_ptr point one after the last prologue/body
6440 last_ptr = last_ptr->next;
6441 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6444 ptr->slot_number = (unsigned long) f + i;
6445 ptr->slot_frag = frag_now;
6447 /* Remove the initialized records, so that we won't accidentally
6448 update them again if we insert a nop and continue. */
6449 md.slot[curr].unwind_record = last_ptr;
6453 manual_bundling_off = md.slot[curr].manual_bundling_off;
6454 if (md.slot[curr].manual_bundling_on)
6457 manual_bundling = 1;
6459 break; /* Need to start a new bundle. */
6462 if (idesc->flags & IA64_OPCODE_SLOT2)
6464 if (manual_bundling && !manual_bundling_off)
6466 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6467 "`%s' must be last in bundle", idesc->name);
6469 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6473 if (idesc->flags & IA64_OPCODE_LAST)
6476 unsigned int required_template;
6478 /* If we need a stop bit after an M slot, our only choice is
6479 template 5 (M;;MI). If we need a stop bit after a B
6480 slot, our only choice is to place it at the end of the
6481 bundle, because the only available templates are MIB,
6482 MBB, BBB, MMB, and MFB. We don't handle anything other
6483 than M and B slots because these are the only kind of
6484 instructions that can have the IA64_OPCODE_LAST bit set. */
6485 required_template = template;
6486 switch (idesc->type)
6490 required_template = 5;
6498 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6499 "Internal error: don't know how to force %s to end"
6500 "of instruction group", idesc->name);
6505 && (i > required_slot
6506 || (required_slot == 2 && !manual_bundling_off)
6507 || (user_template >= 0
6508 /* Changing from MMI to M;MI is OK. */
6509 && (template ^ required_template) > 1)))
6511 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6512 "`%s' must be last in instruction group",
6514 if (i < 2 && required_slot == 2 && !manual_bundling_off)
6515 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6517 if (required_slot < i)
6518 /* Can't fit this instruction. */
6522 if (required_template != template)
6524 /* If we switch the template, we need to reset the NOPs
6525 after slot i. The slot-types of the instructions ahead
6526 of i never change, so we don't need to worry about
6527 changing NOPs in front of this slot. */
6528 for (j = i; j < 3; ++j)
6529 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6531 template = required_template;
6533 if (curr != first && md.slot[curr].label_fixups)
6535 if (manual_bundling)
6537 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6538 "Label must be first in a bundle");
6539 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6541 /* This insn must go into the first slot of a bundle. */
6545 if (end_of_insn_group && md.num_slots_in_use >= 1)
6547 /* We need an instruction group boundary in the middle of a
6548 bundle. See if we can switch to an other template with
6549 an appropriate boundary. */
6551 orig_template = template;
6552 if (i == 1 && (user_template == 4
6553 || (user_template < 0
6554 && (ia64_templ_desc[template].exec_unit[0]
6558 end_of_insn_group = 0;
6560 else if (i == 2 && (user_template == 0
6561 || (user_template < 0
6562 && (ia64_templ_desc[template].exec_unit[1]
6564 /* This test makes sure we don't switch the template if
6565 the next instruction is one that needs to be first in
6566 an instruction group. Since all those instructions are
6567 in the M group, there is no way such an instruction can
6568 fit in this bundle even if we switch the template. The
6569 reason we have to check for this is that otherwise we
6570 may end up generating "MI;;I M.." which has the deadly
6571 effect that the second M instruction is no longer the
6572 first in the group! --davidm 99/12/16 */
6573 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6576 end_of_insn_group = 0;
6579 && user_template == 0
6580 && !(idesc->flags & IA64_OPCODE_FIRST))
6581 /* Use the next slot. */
6583 else if (curr != first)
6584 /* can't fit this insn */
6587 if (template != orig_template)
6588 /* if we switch the template, we need to reset the NOPs
6589 after slot i. The slot-types of the instructions ahead
6590 of i never change, so we don't need to worry about
6591 changing NOPs in front of this slot. */
6592 for (j = i; j < 3; ++j)
6593 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6595 required_unit = ia64_templ_desc[template].exec_unit[i];
6597 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6598 if (idesc->type == IA64_TYPE_DYN)
6600 enum ia64_opnd opnd1, opnd2;
6602 if ((strcmp (idesc->name, "nop") == 0)
6603 || (strcmp (idesc->name, "hint") == 0)
6604 || (strcmp (idesc->name, "break") == 0))
6605 insn_unit = required_unit;
6606 else if (strcmp (idesc->name, "chk.s") == 0
6607 || strcmp (idesc->name, "mov") == 0)
6609 insn_unit = IA64_UNIT_M;
6610 if (required_unit == IA64_UNIT_I
6611 || (required_unit == IA64_UNIT_F && template == 6))
6612 insn_unit = IA64_UNIT_I;
6615 as_fatal ("emit_one_bundle: unexpected dynamic op");
6617 sprintf (mnemonic, "%s.%c", idesc->name, "?imbfxx"[insn_unit]);
6618 opnd1 = idesc->operands[0];
6619 opnd2 = idesc->operands[1];
6620 ia64_free_opcode (idesc);
6621 idesc = ia64_find_opcode (mnemonic);
6622 /* moves to/from ARs have collisions */
6623 if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3)
6625 while (idesc != NULL
6626 && (idesc->operands[0] != opnd1
6627 || idesc->operands[1] != opnd2))
6628 idesc = get_next_opcode (idesc);
6630 md.slot[curr].idesc = idesc;
6634 insn_type = idesc->type;
6635 insn_unit = IA64_UNIT_NIL;
6639 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6640 insn_unit = required_unit;
6642 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6643 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6644 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6645 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6646 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6651 if (insn_unit != required_unit)
6653 if (required_unit == IA64_UNIT_L
6654 && insn_unit == IA64_UNIT_I
6655 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6657 /* we got ourselves an MLX template but the current
6658 instruction isn't an X-unit, or an I-unit instruction
6659 that can go into the X slot of an MLX template. Duh. */
6660 if (md.num_slots_in_use >= NUM_SLOTS)
6662 as_bad_where (md.slot[curr].src_file,
6663 md.slot[curr].src_line,
6664 "`%s' can't go in X slot of "
6665 "MLX template", idesc->name);
6666 /* drop this insn so we don't livelock: */
6667 --md.num_slots_in_use;
6671 continue; /* try next slot */
6674 if (debug_type == DEBUG_DWARF2 || md.slot[curr].loc_directive_seen)
6676 bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6678 md.slot[curr].loc_directive_seen = 0;
6679 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6682 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6683 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6685 build_insn (md.slot + curr, insn + i);
6687 ptr = md.slot[curr].unwind_record;
6690 /* Set slot numbers for all remaining unwind records belonging to the
6691 current insn. There can not be any prologue/body unwind records
6693 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6694 for (; ptr != end_ptr; ptr = ptr->next)
6696 ptr->slot_number = (unsigned long) f + i;
6697 ptr->slot_frag = frag_now;
6699 md.slot[curr].unwind_record = NULL;
6702 if (required_unit == IA64_UNIT_L)
6705 /* skip one slot for long/X-unit instructions */
6708 --md.num_slots_in_use;
6710 /* now is a good time to fix up the labels for this insn: */
6711 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6713 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6714 symbol_set_frag (lfix->sym, frag_now);
6716 /* and fix up the tags also. */
6717 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6719 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6720 symbol_set_frag (lfix->sym, frag_now);
6723 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6725 ifix = md.slot[curr].fixup + j;
6726 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6727 &ifix->expr, ifix->is_pcrel, ifix->code);
6728 fix->tc_fix_data.opnd = ifix->opnd;
6729 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6730 fix->fx_file = md.slot[curr].src_file;
6731 fix->fx_line = md.slot[curr].src_line;
6734 end_of_insn_group = md.slot[curr].end_of_insn_group;
6736 if (end_of_insn_group)
6738 md.group_idx = (md.group_idx + 1) % 3;
6739 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6743 ia64_free_opcode (md.slot[curr].idesc);
6744 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6745 md.slot[curr].user_template = -1;
6747 if (manual_bundling_off)
6749 manual_bundling = 0;
6752 curr = (curr + 1) % NUM_SLOTS;
6753 idesc = md.slot[curr].idesc;
6755 if (manual_bundling > 0)
6757 if (md.num_slots_in_use > 0)
6759 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6760 "`%s' does not fit into %s template",
6761 idesc->name, ia64_templ_desc[template].name);
6762 --md.num_slots_in_use;
6765 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6766 "Missing '}' at end of file");
6768 know (md.num_slots_in_use < NUM_SLOTS);
6770 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6771 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6773 number_to_chars_littleendian (f + 0, t0, 8);
6774 number_to_chars_littleendian (f + 8, t1, 8);
6778 unwind.list->next_slot_number = (unsigned long) f + 16;
6779 unwind.list->next_slot_frag = frag_now;
6784 md_parse_option (c, arg)
6791 /* Switches from the Intel assembler. */
6793 if (strcmp (arg, "ilp64") == 0
6794 || strcmp (arg, "lp64") == 0
6795 || strcmp (arg, "p64") == 0)
6797 md.flags |= EF_IA_64_ABI64;
6799 else if (strcmp (arg, "ilp32") == 0)
6801 md.flags &= ~EF_IA_64_ABI64;
6803 else if (strcmp (arg, "le") == 0)
6805 md.flags &= ~EF_IA_64_BE;
6806 default_big_endian = 0;
6808 else if (strcmp (arg, "be") == 0)
6810 md.flags |= EF_IA_64_BE;
6811 default_big_endian = 1;
6818 if (strcmp (arg, "so") == 0)
6820 /* Suppress signon message. */
6822 else if (strcmp (arg, "pi") == 0)
6824 /* Reject privileged instructions. FIXME */
6826 else if (strcmp (arg, "us") == 0)
6828 /* Allow union of signed and unsigned range. FIXME */
6830 else if (strcmp (arg, "close_fcalls") == 0)
6832 /* Do not resolve global function calls. */
6839 /* temp[="prefix"] Insert temporary labels into the object file
6840 symbol table prefixed by "prefix".
6841 Default prefix is ":temp:".
6846 /* indirect=<tgt> Assume unannotated indirect branches behavior
6847 according to <tgt> --
6848 exit: branch out from the current context (default)
6849 labels: all labels in context may be branch targets
6851 if (strncmp (arg, "indirect=", 9) != 0)
6856 /* -X conflicts with an ignored option, use -x instead */
6858 if (!arg || strcmp (arg, "explicit") == 0)
6860 /* set default mode to explicit */
6861 md.default_explicit_mode = 1;
6864 else if (strcmp (arg, "auto") == 0)
6866 md.default_explicit_mode = 0;
6868 else if (strcmp (arg, "debug") == 0)
6872 else if (strcmp (arg, "debugx") == 0)
6874 md.default_explicit_mode = 1;
6879 as_bad (_("Unrecognized option '-x%s'"), arg);
6884 /* nops Print nops statistics. */
6887 /* GNU specific switches for gcc. */
6888 case OPTION_MCONSTANT_GP:
6889 md.flags |= EF_IA_64_CONS_GP;
6892 case OPTION_MAUTO_PIC:
6893 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6904 md_show_usage (stream)
6909 --mconstant-gp mark output file as using the constant-GP model\n\
6910 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6911 --mauto-pic mark output file as using the constant-GP model\n\
6912 without function descriptors (sets ELF header flag\n\
6913 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6914 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6915 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6916 -x | -xexplicit turn on dependency violation checking (default)\n\
6917 -xauto automagically remove dependency violations\n\
6918 -xdebug debug dependency violation checker\n"),
6923 ia64_after_parse_args ()
6925 if (debug_type == DEBUG_STABS)
6926 as_fatal (_("--gstabs is not supported for ia64"));
6929 /* Return true if TYPE fits in TEMPL at SLOT. */
6932 match (int templ, int type, int slot)
6934 enum ia64_unit unit;
6937 unit = ia64_templ_desc[templ].exec_unit[slot];
6940 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6942 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6944 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6945 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6946 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6947 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6948 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6949 default: result = 0; break;
6954 /* Add a bit of extra goodness if a nop of type F or B would fit
6955 in TEMPL at SLOT. */
6958 extra_goodness (int templ, int slot)
6960 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6962 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6967 /* This function is called once, at assembler startup time. It sets
6968 up all the tables, etc. that the MD part of the assembler will need
6969 that can be determined before arguments are parsed. */
6973 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6978 md.explicit_mode = md.default_explicit_mode;
6980 bfd_set_section_alignment (stdoutput, text_section, 4);
6982 /* Make sure function pointers get initialized. */
6983 target_big_endian = -1;
6984 dot_byteorder (default_big_endian);
6986 alias_hash = hash_new ();
6987 alias_name_hash = hash_new ();
6988 secalias_hash = hash_new ();
6989 secalias_name_hash = hash_new ();
6991 pseudo_func[FUNC_DTP_MODULE].u.sym =
6992 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6993 &zero_address_frag);
6995 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6996 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6997 &zero_address_frag);
6999 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
7000 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
7001 &zero_address_frag);
7003 pseudo_func[FUNC_GP_RELATIVE].u.sym =
7004 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
7005 &zero_address_frag);
7007 pseudo_func[FUNC_LT_RELATIVE].u.sym =
7008 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
7009 &zero_address_frag);
7011 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
7012 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
7013 &zero_address_frag);
7015 pseudo_func[FUNC_PC_RELATIVE].u.sym =
7016 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
7017 &zero_address_frag);
7019 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
7020 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
7021 &zero_address_frag);
7023 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
7024 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
7025 &zero_address_frag);
7027 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
7028 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
7029 &zero_address_frag);
7031 pseudo_func[FUNC_TP_RELATIVE].u.sym =
7032 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
7033 &zero_address_frag);
7035 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
7036 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
7037 &zero_address_frag);
7039 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
7040 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
7041 &zero_address_frag);
7043 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
7044 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
7045 &zero_address_frag);
7047 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
7048 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
7049 &zero_address_frag);
7051 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
7052 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
7053 &zero_address_frag);
7055 pseudo_func[FUNC_IPLT_RELOC].u.sym =
7056 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
7057 &zero_address_frag);
7059 /* Compute the table of best templates. We compute goodness as a
7060 base 4 value, in which each match counts for 3, each F counts
7061 for 2, each B counts for 1. This should maximize the number of
7062 F and B nops in the chosen bundles, which is good because these
7063 pipelines are least likely to be overcommitted. */
7064 for (i = 0; i < IA64_NUM_TYPES; ++i)
7065 for (j = 0; j < IA64_NUM_TYPES; ++j)
7066 for (k = 0; k < IA64_NUM_TYPES; ++k)
7069 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
7072 if (match (t, i, 0))
7074 if (match (t, j, 1))
7076 if (match (t, k, 2))
7077 goodness = 3 + 3 + 3;
7079 goodness = 3 + 3 + extra_goodness (t, 2);
7081 else if (match (t, j, 2))
7082 goodness = 3 + 3 + extra_goodness (t, 1);
7086 goodness += extra_goodness (t, 1);
7087 goodness += extra_goodness (t, 2);
7090 else if (match (t, i, 1))
7092 if (match (t, j, 2))
7095 goodness = 3 + extra_goodness (t, 2);
7097 else if (match (t, i, 2))
7098 goodness = 3 + extra_goodness (t, 1);
7100 if (goodness > best)
7103 best_template[i][j][k] = t;
7108 for (i = 0; i < NUM_SLOTS; ++i)
7109 md.slot[i].user_template = -1;
7111 md.pseudo_hash = hash_new ();
7112 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
7114 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
7115 (void *) (pseudo_opcode + i));
7117 as_fatal ("ia64.md_begin: can't hash `%s': %s",
7118 pseudo_opcode[i].name, err);
7121 md.reg_hash = hash_new ();
7122 md.dynreg_hash = hash_new ();
7123 md.const_hash = hash_new ();
7124 md.entry_hash = hash_new ();
7126 /* general registers: */
7129 for (i = 0; i < total; ++i)
7131 sprintf (name, "r%d", i - REG_GR);
7132 md.regsym[i] = declare_register (name, i);
7135 /* floating point registers: */
7137 for (; i < total; ++i)
7139 sprintf (name, "f%d", i - REG_FR);
7140 md.regsym[i] = declare_register (name, i);
7143 /* application registers: */
7146 for (; i < total; ++i)
7148 sprintf (name, "ar%d", i - REG_AR);
7149 md.regsym[i] = declare_register (name, i);
7152 /* control registers: */
7155 for (; i < total; ++i)
7157 sprintf (name, "cr%d", i - REG_CR);
7158 md.regsym[i] = declare_register (name, i);
7161 /* predicate registers: */
7163 for (; i < total; ++i)
7165 sprintf (name, "p%d", i - REG_P);
7166 md.regsym[i] = declare_register (name, i);
7169 /* branch registers: */
7171 for (; i < total; ++i)
7173 sprintf (name, "b%d", i - REG_BR);
7174 md.regsym[i] = declare_register (name, i);
7177 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
7178 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
7179 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
7180 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
7181 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
7182 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
7183 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
7185 for (i = 0; i < NELEMS (indirect_reg); ++i)
7187 regnum = indirect_reg[i].regnum;
7188 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
7191 /* define synonyms for application registers: */
7192 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
7193 md.regsym[i] = declare_register (ar[i - REG_AR].name,
7194 REG_AR + ar[i - REG_AR].regnum);
7196 /* define synonyms for control registers: */
7197 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
7198 md.regsym[i] = declare_register (cr[i - REG_CR].name,
7199 REG_CR + cr[i - REG_CR].regnum);
7201 declare_register ("gp", REG_GR + 1);
7202 declare_register ("sp", REG_GR + 12);
7203 declare_register ("rp", REG_BR + 0);
7205 /* pseudo-registers used to specify unwind info: */
7206 declare_register ("psp", REG_PSP);
7208 declare_register_set ("ret", 4, REG_GR + 8);
7209 declare_register_set ("farg", 8, REG_FR + 8);
7210 declare_register_set ("fret", 8, REG_FR + 8);
7212 for (i = 0; i < NELEMS (const_bits); ++i)
7214 err = hash_insert (md.const_hash, const_bits[i].name,
7215 (PTR) (const_bits + i));
7217 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
7221 /* Set the architecture and machine depending on defaults and command line
7223 if (md.flags & EF_IA_64_ABI64)
7224 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
7226 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
7229 as_warn (_("Could not set architecture and machine"));
7231 /* Set the pointer size and pointer shift size depending on md.flags */
7233 if (md.flags & EF_IA_64_ABI64)
7235 md.pointer_size = 8; /* pointers are 8 bytes */
7236 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
7240 md.pointer_size = 4; /* pointers are 4 bytes */
7241 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
7244 md.mem_offset.hint = 0;
7247 md.entry_labels = NULL;
7250 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
7251 because that is called after md_parse_option which is where we do the
7252 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
7253 default endianness. */
7256 ia64_init (argc, argv)
7257 int argc ATTRIBUTE_UNUSED;
7258 char **argv ATTRIBUTE_UNUSED;
7260 md.flags = MD_FLAGS_DEFAULT;
7263 /* Return a string for the target object file format. */
7266 ia64_target_format ()
7268 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7270 if (md.flags & EF_IA_64_BE)
7272 if (md.flags & EF_IA_64_ABI64)
7273 #if defined(TE_AIX50)
7274 return "elf64-ia64-aix-big";
7275 #elif defined(TE_HPUX)
7276 return "elf64-ia64-hpux-big";
7278 return "elf64-ia64-big";
7281 #if defined(TE_AIX50)
7282 return "elf32-ia64-aix-big";
7283 #elif defined(TE_HPUX)
7284 return "elf32-ia64-hpux-big";
7286 return "elf32-ia64-big";
7291 if (md.flags & EF_IA_64_ABI64)
7293 return "elf64-ia64-aix-little";
7295 return "elf64-ia64-little";
7299 return "elf32-ia64-aix-little";
7301 return "elf32-ia64-little";
7306 return "unknown-format";
7310 ia64_end_of_source ()
7312 /* terminate insn group upon reaching end of file: */
7313 insn_group_break (1, 0, 0);
7315 /* emits slots we haven't written yet: */
7316 ia64_flush_insns ();
7318 bfd_set_private_flags (stdoutput, md.flags);
7320 md.mem_offset.hint = 0;
7326 if (md.qp.X_op == O_register)
7327 as_bad ("qualifying predicate not followed by instruction");
7328 md.qp.X_op = O_absent;
7330 if (ignore_input ())
7333 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7335 if (md.detect_dv && !md.explicit_mode)
7336 as_warn (_("Explicit stops are ignored in auto mode"));
7338 insn_group_break (1, 0, 0);
7342 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7344 static int defining_tag = 0;
7347 ia64_unrecognized_line (ch)
7353 expression (&md.qp);
7354 if (*input_line_pointer++ != ')')
7356 as_bad ("Expected ')'");
7359 if (md.qp.X_op != O_register)
7361 as_bad ("Qualifying predicate expected");
7364 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7366 as_bad ("Predicate register expected");
7372 if (md.manual_bundling)
7373 as_warn ("Found '{' when manual bundling is already turned on");
7375 CURR_SLOT.manual_bundling_on = 1;
7376 md.manual_bundling = 1;
7378 /* Bundling is only acceptable in explicit mode
7379 or when in default automatic mode. */
7380 if (md.detect_dv && !md.explicit_mode)
7382 if (!md.mode_explicitly_set
7383 && !md.default_explicit_mode)
7386 as_warn (_("Found '{' after explicit switch to automatic mode"));
7391 if (!md.manual_bundling)
7392 as_warn ("Found '}' when manual bundling is off");
7394 PREV_SLOT.manual_bundling_off = 1;
7395 md.manual_bundling = 0;
7397 /* switch back to automatic mode, if applicable */
7400 && !md.mode_explicitly_set
7401 && !md.default_explicit_mode)
7404 /* Allow '{' to follow on the same line. We also allow ";;", but that
7405 happens automatically because ';' is an end of line marker. */
7407 if (input_line_pointer[0] == '{')
7409 input_line_pointer++;
7410 return ia64_unrecognized_line ('{');
7413 demand_empty_rest_of_line ();
7423 if (md.qp.X_op == O_register)
7425 as_bad ("Tag must come before qualifying predicate.");
7429 /* This implements just enough of read_a_source_file in read.c to
7430 recognize labels. */
7431 if (is_name_beginner (*input_line_pointer))
7433 s = input_line_pointer;
7434 c = get_symbol_end ();
7436 else if (LOCAL_LABELS_FB
7437 && ISDIGIT (*input_line_pointer))
7440 while (ISDIGIT (*input_line_pointer))
7441 temp = (temp * 10) + *input_line_pointer++ - '0';
7442 fb_label_instance_inc (temp);
7443 s = fb_label_name (temp, 0);
7444 c = *input_line_pointer;
7453 /* Put ':' back for error messages' sake. */
7454 *input_line_pointer++ = ':';
7455 as_bad ("Expected ':'");
7462 /* Put ':' back for error messages' sake. */
7463 *input_line_pointer++ = ':';
7464 if (*input_line_pointer++ != ']')
7466 as_bad ("Expected ']'");
7471 as_bad ("Tag name expected");
7481 /* Not a valid line. */
7486 ia64_frob_label (sym)
7489 struct label_fix *fix;
7491 /* Tags need special handling since they are not bundle breaks like
7495 fix = obstack_alloc (¬es, sizeof (*fix));
7497 fix->next = CURR_SLOT.tag_fixups;
7498 CURR_SLOT.tag_fixups = fix;
7503 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7505 md.last_text_seg = now_seg;
7506 fix = obstack_alloc (¬es, sizeof (*fix));
7508 fix->next = CURR_SLOT.label_fixups;
7509 CURR_SLOT.label_fixups = fix;
7511 /* Keep track of how many code entry points we've seen. */
7512 if (md.path == md.maxpaths)
7515 md.entry_labels = (const char **)
7516 xrealloc ((void *) md.entry_labels,
7517 md.maxpaths * sizeof (char *));
7519 md.entry_labels[md.path++] = S_GET_NAME (sym);
7524 /* The HP-UX linker will give unresolved symbol errors for symbols
7525 that are declared but unused. This routine removes declared,
7526 unused symbols from an object. */
7528 ia64_frob_symbol (sym)
7531 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7532 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7533 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7534 && ! S_IS_EXTERNAL (sym)))
7541 ia64_flush_pending_output ()
7543 if (!md.keep_pending_output
7544 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7546 /* ??? This causes many unnecessary stop bits to be emitted.
7547 Unfortunately, it isn't clear if it is safe to remove this. */
7548 insn_group_break (1, 0, 0);
7549 ia64_flush_insns ();
7553 /* Do ia64-specific expression optimization. All that's done here is
7554 to transform index expressions that are either due to the indexing
7555 of rotating registers or due to the indexing of indirect register
7558 ia64_optimize_expr (l, op, r)
7567 if (l->X_op == O_register && r->X_op == O_constant)
7569 num_regs = (l->X_add_number >> 16);
7570 if ((unsigned) r->X_add_number >= num_regs)
7573 as_bad ("No current frame");
7575 as_bad ("Index out of range 0..%u", num_regs - 1);
7576 r->X_add_number = 0;
7578 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7581 else if (l->X_op == O_register && r->X_op == O_register)
7583 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7584 || l->X_add_number == IND_MEM)
7586 as_bad ("Indirect register set name expected");
7587 l->X_add_number = IND_CPUID;
7590 l->X_op_symbol = md.regsym[l->X_add_number];
7591 l->X_add_number = r->X_add_number;
7599 ia64_parse_name (name, e)
7603 struct const_desc *cdesc;
7604 struct dynreg *dr = 0;
7605 unsigned int regnum;
7609 /* first see if NAME is a known register name: */
7610 sym = hash_find (md.reg_hash, name);
7613 e->X_op = O_register;
7614 e->X_add_number = S_GET_VALUE (sym);
7618 cdesc = hash_find (md.const_hash, name);
7621 e->X_op = O_constant;
7622 e->X_add_number = cdesc->value;
7626 /* check for inN, locN, or outN: */
7630 if (name[1] == 'n' && ISDIGIT (name[2]))
7638 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7646 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7659 /* The name is inN, locN, or outN; parse the register number. */
7660 regnum = strtoul (name, &end, 10);
7661 if (end > name && *end == '\0')
7663 if ((unsigned) regnum >= dr->num_regs)
7666 as_bad ("No current frame");
7668 as_bad ("Register number out of range 0..%u",
7672 e->X_op = O_register;
7673 e->X_add_number = dr->base + regnum;
7678 if ((dr = hash_find (md.dynreg_hash, name)))
7680 /* We've got ourselves the name of a rotating register set.
7681 Store the base register number in the low 16 bits of
7682 X_add_number and the size of the register set in the top 16
7684 e->X_op = O_register;
7685 e->X_add_number = dr->base | (dr->num_regs << 16);
7691 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7694 ia64_canonicalize_symbol_name (name)
7697 size_t len = strlen (name);
7698 if (len > 1 && name[len - 1] == '#')
7699 name[len - 1] = '\0';
7703 /* Return true if idesc is a conditional branch instruction. This excludes
7704 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7705 because they always read/write resources regardless of the value of the
7706 qualifying predicate. br.ia must always use p0, and hence is always
7707 taken. Thus this function returns true for branches which can fall
7708 through, and which use no resources if they do fall through. */
7711 is_conditional_branch (idesc)
7712 struct ia64_opcode *idesc;
7714 /* br is a conditional branch. Everything that starts with br. except
7715 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7716 Everything that starts with brl is a conditional branch. */
7717 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7718 && (idesc->name[2] == '\0'
7719 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7720 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7721 || idesc->name[2] == 'l'
7722 /* br.cond, br.call, br.clr */
7723 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7724 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7725 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7728 /* Return whether the given opcode is a taken branch. If there's any doubt,
7732 is_taken_branch (idesc)
7733 struct ia64_opcode *idesc;
7735 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7736 || strncmp (idesc->name, "br.ia", 5) == 0);
7739 /* Return whether the given opcode is an interruption or rfi. If there's any
7740 doubt, returns zero. */
7743 is_interruption_or_rfi (idesc)
7744 struct ia64_opcode *idesc;
7746 if (strcmp (idesc->name, "rfi") == 0)
7751 /* Returns the index of the given dependency in the opcode's list of chks, or
7752 -1 if there is no dependency. */
7755 depends_on (depind, idesc)
7757 struct ia64_opcode *idesc;
7760 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7761 for (i = 0; i < dep->nchks; i++)
7763 if (depind == DEP (dep->chks[i]))
7769 /* Determine a set of specific resources used for a particular resource
7770 class. Returns the number of specific resources identified For those
7771 cases which are not determinable statically, the resource returned is
7774 Meanings of value in 'NOTE':
7775 1) only read/write when the register number is explicitly encoded in the
7777 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7778 accesses CFM when qualifying predicate is in the rotating region.
7779 3) general register value is used to specify an indirect register; not
7780 determinable statically.
7781 4) only read the given resource when bits 7:0 of the indirect index
7782 register value does not match the register number of the resource; not
7783 determinable statically.
7784 5) all rules are implementation specific.
7785 6) only when both the index specified by the reader and the index specified
7786 by the writer have the same value in bits 63:61; not determinable
7788 7) only access the specified resource when the corresponding mask bit is
7790 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7791 only read when these insns reference FR2-31
7792 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7793 written when these insns write FR32-127
7794 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7796 11) The target predicates are written independently of PR[qp], but source
7797 registers are only read if PR[qp] is true. Since the state of PR[qp]
7798 cannot statically be determined, all source registers are marked used.
7799 12) This insn only reads the specified predicate register when that
7800 register is the PR[qp].
7801 13) This reference to ld-c only applies to teh GR whose value is loaded
7802 with data returned from memory, not the post-incremented address register.
7803 14) The RSE resource includes the implementation-specific RSE internal
7804 state resources. At least one (and possibly more) of these resources are
7805 read by each instruction listed in IC:rse-readers. At least one (and
7806 possibly more) of these resources are written by each insn listed in
7808 15+16) Represents reserved instructions, which the assembler does not
7811 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7812 this code; there are no dependency violations based on memory access.
7815 #define MAX_SPECS 256
7820 specify_resource (dep, idesc, type, specs, note, path)
7821 const struct ia64_dependency *dep;
7822 struct ia64_opcode *idesc;
7823 int type; /* is this a DV chk or a DV reg? */
7824 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7825 int note; /* resource note for this insn's usage */
7826 int path; /* which execution path to examine */
7833 if (dep->mode == IA64_DV_WAW
7834 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7835 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7838 /* template for any resources we identify */
7839 tmpl.dependency = dep;
7841 tmpl.insn_srlz = tmpl.data_srlz = 0;
7842 tmpl.qp_regno = CURR_SLOT.qp_regno;
7843 tmpl.link_to_qp_branch = 1;
7844 tmpl.mem_offset.hint = 0;
7847 tmpl.cmp_type = CMP_NONE;
7850 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7851 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7852 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7854 /* we don't need to track these */
7855 if (dep->semantics == IA64_DVS_NONE)
7858 switch (dep->specifier)
7863 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7865 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7866 if (regno >= 0 && regno <= 7)
7868 specs[count] = tmpl;
7869 specs[count++].index = regno;
7875 for (i = 0; i < 8; i++)
7877 specs[count] = tmpl;
7878 specs[count++].index = i;
7887 case IA64_RS_AR_UNAT:
7888 /* This is a mov =AR or mov AR= instruction. */
7889 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7891 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7892 if (regno == AR_UNAT)
7894 specs[count++] = tmpl;
7899 /* This is a spill/fill, or other instruction that modifies the
7902 /* Unless we can determine the specific bits used, mark the whole
7903 thing; bits 8:3 of the memory address indicate the bit used in
7904 UNAT. The .mem.offset hint may be used to eliminate a small
7905 subset of conflicts. */
7906 specs[count] = tmpl;
7907 if (md.mem_offset.hint)
7910 fprintf (stderr, " Using hint for spill/fill\n");
7911 /* The index isn't actually used, just set it to something
7912 approximating the bit index. */
7913 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7914 specs[count].mem_offset.hint = 1;
7915 specs[count].mem_offset.offset = md.mem_offset.offset;
7916 specs[count++].mem_offset.base = md.mem_offset.base;
7920 specs[count++].specific = 0;
7928 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7930 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7931 if ((regno >= 8 && regno <= 15)
7932 || (regno >= 20 && regno <= 23)
7933 || (regno >= 31 && regno <= 39)
7934 || (regno >= 41 && regno <= 47)
7935 || (regno >= 67 && regno <= 111))
7937 specs[count] = tmpl;
7938 specs[count++].index = regno;
7951 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7953 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7954 if ((regno >= 48 && regno <= 63)
7955 || (regno >= 112 && regno <= 127))
7957 specs[count] = tmpl;
7958 specs[count++].index = regno;
7964 for (i = 48; i < 64; i++)
7966 specs[count] = tmpl;
7967 specs[count++].index = i;
7969 for (i = 112; i < 128; i++)
7971 specs[count] = tmpl;
7972 specs[count++].index = i;
7990 for (i = 0; i < idesc->num_outputs; i++)
7991 if (idesc->operands[i] == IA64_OPND_B1
7992 || idesc->operands[i] == IA64_OPND_B2)
7994 specs[count] = tmpl;
7995 specs[count++].index =
7996 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8001 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8002 if (idesc->operands[i] == IA64_OPND_B1
8003 || idesc->operands[i] == IA64_OPND_B2)
8005 specs[count] = tmpl;
8006 specs[count++].index =
8007 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8013 case IA64_RS_CPUID: /* four or more registers */
8016 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
8018 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8019 if (regno >= 0 && regno < NELEMS (gr_values)
8022 specs[count] = tmpl;
8023 specs[count++].index = gr_values[regno].value & 0xFF;
8027 specs[count] = tmpl;
8028 specs[count++].specific = 0;
8038 case IA64_RS_DBR: /* four or more registers */
8041 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
8043 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8044 if (regno >= 0 && regno < NELEMS (gr_values)
8047 specs[count] = tmpl;
8048 specs[count++].index = gr_values[regno].value & 0xFF;
8052 specs[count] = tmpl;
8053 specs[count++].specific = 0;
8057 else if (note == 0 && !rsrc_write)
8059 specs[count] = tmpl;
8060 specs[count++].specific = 0;
8068 case IA64_RS_IBR: /* four or more registers */
8071 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
8073 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8074 if (regno >= 0 && regno < NELEMS (gr_values)
8077 specs[count] = tmpl;
8078 specs[count++].index = gr_values[regno].value & 0xFF;
8082 specs[count] = tmpl;
8083 specs[count++].specific = 0;
8096 /* These are implementation specific. Force all references to
8097 conflict with all other references. */
8098 specs[count] = tmpl;
8099 specs[count++].specific = 0;
8107 case IA64_RS_PKR: /* 16 or more registers */
8108 if (note == 3 || note == 4)
8110 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
8112 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8113 if (regno >= 0 && regno < NELEMS (gr_values)
8118 specs[count] = tmpl;
8119 specs[count++].index = gr_values[regno].value & 0xFF;
8122 for (i = 0; i < NELEMS (gr_values); i++)
8124 /* Uses all registers *except* the one in R3. */
8125 if ((unsigned)i != (gr_values[regno].value & 0xFF))
8127 specs[count] = tmpl;
8128 specs[count++].index = i;
8134 specs[count] = tmpl;
8135 specs[count++].specific = 0;
8142 specs[count] = tmpl;
8143 specs[count++].specific = 0;
8147 case IA64_RS_PMC: /* four or more registers */
8150 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
8151 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
8154 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
8156 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
8157 if (regno >= 0 && regno < NELEMS (gr_values)
8160 specs[count] = tmpl;
8161 specs[count++].index = gr_values[regno].value & 0xFF;
8165 specs[count] = tmpl;
8166 specs[count++].specific = 0;
8176 case IA64_RS_PMD: /* four or more registers */
8179 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
8181 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8182 if (regno >= 0 && regno < NELEMS (gr_values)
8185 specs[count] = tmpl;
8186 specs[count++].index = gr_values[regno].value & 0xFF;
8190 specs[count] = tmpl;
8191 specs[count++].specific = 0;
8201 case IA64_RS_RR: /* eight registers */
8204 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
8206 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8207 if (regno >= 0 && regno < NELEMS (gr_values)
8210 specs[count] = tmpl;
8211 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
8215 specs[count] = tmpl;
8216 specs[count++].specific = 0;
8220 else if (note == 0 && !rsrc_write)
8222 specs[count] = tmpl;
8223 specs[count++].specific = 0;
8231 case IA64_RS_CR_IRR:
8234 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
8235 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
8237 && idesc->operands[1] == IA64_OPND_CR3
8240 for (i = 0; i < 4; i++)
8242 specs[count] = tmpl;
8243 specs[count++].index = CR_IRR0 + i;
8249 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8250 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8252 && regno <= CR_IRR3)
8254 specs[count] = tmpl;
8255 specs[count++].index = regno;
8264 case IA64_RS_CR_LRR:
8271 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8272 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8273 && (regno == CR_LRR0 || regno == CR_LRR1))
8275 specs[count] = tmpl;
8276 specs[count++].index = regno;
8284 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8286 specs[count] = tmpl;
8287 specs[count++].index =
8288 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8303 else if (rsrc_write)
8305 if (dep->specifier == IA64_RS_FRb
8306 && idesc->operands[0] == IA64_OPND_F1)
8308 specs[count] = tmpl;
8309 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8314 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8316 if (idesc->operands[i] == IA64_OPND_F2
8317 || idesc->operands[i] == IA64_OPND_F3
8318 || idesc->operands[i] == IA64_OPND_F4)
8320 specs[count] = tmpl;
8321 specs[count++].index =
8322 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8331 /* This reference applies only to the GR whose value is loaded with
8332 data returned from memory. */
8333 specs[count] = tmpl;
8334 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8340 for (i = 0; i < idesc->num_outputs; i++)
8341 if (idesc->operands[i] == IA64_OPND_R1
8342 || idesc->operands[i] == IA64_OPND_R2
8343 || idesc->operands[i] == IA64_OPND_R3)
8345 specs[count] = tmpl;
8346 specs[count++].index =
8347 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8349 if (idesc->flags & IA64_OPCODE_POSTINC)
8350 for (i = 0; i < NELEMS (idesc->operands); i++)
8351 if (idesc->operands[i] == IA64_OPND_MR3)
8353 specs[count] = tmpl;
8354 specs[count++].index =
8355 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8360 /* Look for anything that reads a GR. */
8361 for (i = 0; i < NELEMS (idesc->operands); i++)
8363 if (idesc->operands[i] == IA64_OPND_MR3
8364 || idesc->operands[i] == IA64_OPND_CPUID_R3
8365 || idesc->operands[i] == IA64_OPND_DBR_R3
8366 || idesc->operands[i] == IA64_OPND_IBR_R3
8367 || idesc->operands[i] == IA64_OPND_MSR_R3
8368 || idesc->operands[i] == IA64_OPND_PKR_R3
8369 || idesc->operands[i] == IA64_OPND_PMC_R3
8370 || idesc->operands[i] == IA64_OPND_PMD_R3
8371 || idesc->operands[i] == IA64_OPND_RR_R3
8372 || ((i >= idesc->num_outputs)
8373 && (idesc->operands[i] == IA64_OPND_R1
8374 || idesc->operands[i] == IA64_OPND_R2
8375 || idesc->operands[i] == IA64_OPND_R3
8376 /* addl source register. */
8377 || idesc->operands[i] == IA64_OPND_R3_2)))
8379 specs[count] = tmpl;
8380 specs[count++].index =
8381 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8392 /* This is the same as IA64_RS_PRr, except that the register range is
8393 from 1 - 15, and there are no rotating register reads/writes here. */
8397 for (i = 1; i < 16; i++)
8399 specs[count] = tmpl;
8400 specs[count++].index = i;
8406 /* Mark only those registers indicated by the mask. */
8409 mask = CURR_SLOT.opnd[2].X_add_number;
8410 for (i = 1; i < 16; i++)
8411 if (mask & ((valueT) 1 << i))
8413 specs[count] = tmpl;
8414 specs[count++].index = i;
8422 else if (note == 11) /* note 11 implies note 1 as well */
8426 for (i = 0; i < idesc->num_outputs; i++)
8428 if (idesc->operands[i] == IA64_OPND_P1
8429 || idesc->operands[i] == IA64_OPND_P2)
8431 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8432 if (regno >= 1 && regno < 16)
8434 specs[count] = tmpl;
8435 specs[count++].index = regno;
8445 else if (note == 12)
8447 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8449 specs[count] = tmpl;
8450 specs[count++].index = CURR_SLOT.qp_regno;
8457 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8458 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8459 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8460 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8462 if ((idesc->operands[0] == IA64_OPND_P1
8463 || idesc->operands[0] == IA64_OPND_P2)
8464 && p1 >= 1 && p1 < 16)
8466 specs[count] = tmpl;
8467 specs[count].cmp_type =
8468 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8469 specs[count++].index = p1;
8471 if ((idesc->operands[1] == IA64_OPND_P1
8472 || idesc->operands[1] == IA64_OPND_P2)
8473 && p2 >= 1 && p2 < 16)
8475 specs[count] = tmpl;
8476 specs[count].cmp_type =
8477 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8478 specs[count++].index = p2;
8483 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8485 specs[count] = tmpl;
8486 specs[count++].index = CURR_SLOT.qp_regno;
8488 if (idesc->operands[1] == IA64_OPND_PR)
8490 for (i = 1; i < 16; i++)
8492 specs[count] = tmpl;
8493 specs[count++].index = i;
8504 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8505 simplified cases of this. */
8509 for (i = 16; i < 63; i++)
8511 specs[count] = tmpl;
8512 specs[count++].index = i;
8518 /* Mark only those registers indicated by the mask. */
8520 && idesc->operands[0] == IA64_OPND_PR)
8522 mask = CURR_SLOT.opnd[2].X_add_number;
8523 if (mask & ((valueT) 1 << 16))
8524 for (i = 16; i < 63; i++)
8526 specs[count] = tmpl;
8527 specs[count++].index = i;
8531 && idesc->operands[0] == IA64_OPND_PR_ROT)
8533 for (i = 16; i < 63; i++)
8535 specs[count] = tmpl;
8536 specs[count++].index = i;
8544 else if (note == 11) /* note 11 implies note 1 as well */
8548 for (i = 0; i < idesc->num_outputs; i++)
8550 if (idesc->operands[i] == IA64_OPND_P1
8551 || idesc->operands[i] == IA64_OPND_P2)
8553 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8554 if (regno >= 16 && regno < 63)
8556 specs[count] = tmpl;
8557 specs[count++].index = regno;
8567 else if (note == 12)
8569 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8571 specs[count] = tmpl;
8572 specs[count++].index = CURR_SLOT.qp_regno;
8579 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8580 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8581 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8582 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8584 if ((idesc->operands[0] == IA64_OPND_P1
8585 || idesc->operands[0] == IA64_OPND_P2)
8586 && p1 >= 16 && p1 < 63)
8588 specs[count] = tmpl;
8589 specs[count].cmp_type =
8590 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8591 specs[count++].index = p1;
8593 if ((idesc->operands[1] == IA64_OPND_P1
8594 || idesc->operands[1] == IA64_OPND_P2)
8595 && p2 >= 16 && p2 < 63)
8597 specs[count] = tmpl;
8598 specs[count].cmp_type =
8599 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8600 specs[count++].index = p2;
8605 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8607 specs[count] = tmpl;
8608 specs[count++].index = CURR_SLOT.qp_regno;
8610 if (idesc->operands[1] == IA64_OPND_PR)
8612 for (i = 16; i < 63; i++)
8614 specs[count] = tmpl;
8615 specs[count++].index = i;
8627 /* Verify that the instruction is using the PSR bit indicated in
8631 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8633 if (dep->regindex < 6)
8635 specs[count++] = tmpl;
8638 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8640 if (dep->regindex < 32
8641 || dep->regindex == 35
8642 || dep->regindex == 36
8643 || (!rsrc_write && dep->regindex == PSR_CPL))
8645 specs[count++] = tmpl;
8648 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8650 if (dep->regindex < 32
8651 || dep->regindex == 35
8652 || dep->regindex == 36
8653 || (rsrc_write && dep->regindex == PSR_CPL))
8655 specs[count++] = tmpl;
8660 /* Several PSR bits have very specific dependencies. */
8661 switch (dep->regindex)
8664 specs[count++] = tmpl;
8669 specs[count++] = tmpl;
8673 /* Only certain CR accesses use PSR.ic */
8674 if (idesc->operands[0] == IA64_OPND_CR3
8675 || idesc->operands[1] == IA64_OPND_CR3)
8678 ((idesc->operands[0] == IA64_OPND_CR3)
8681 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8696 specs[count++] = tmpl;
8705 specs[count++] = tmpl;
8709 /* Only some AR accesses use cpl */
8710 if (idesc->operands[0] == IA64_OPND_AR3
8711 || idesc->operands[1] == IA64_OPND_AR3)
8714 ((idesc->operands[0] == IA64_OPND_AR3)
8717 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8724 && regno <= AR_K7))))
8726 specs[count++] = tmpl;
8731 specs[count++] = tmpl;
8741 if (idesc->operands[0] == IA64_OPND_IMMU24)
8743 mask = CURR_SLOT.opnd[0].X_add_number;
8749 if (mask & ((valueT) 1 << dep->regindex))
8751 specs[count++] = tmpl;
8756 int min = dep->regindex == PSR_DFL ? 2 : 32;
8757 int max = dep->regindex == PSR_DFL ? 31 : 127;
8758 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8759 for (i = 0; i < NELEMS (idesc->operands); i++)
8761 if (idesc->operands[i] == IA64_OPND_F1
8762 || idesc->operands[i] == IA64_OPND_F2
8763 || idesc->operands[i] == IA64_OPND_F3
8764 || idesc->operands[i] == IA64_OPND_F4)
8766 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8767 if (reg >= min && reg <= max)
8769 specs[count++] = tmpl;
8776 int min = dep->regindex == PSR_MFL ? 2 : 32;
8777 int max = dep->regindex == PSR_MFL ? 31 : 127;
8778 /* mfh is read on writes to FR32-127; mfl is read on writes to
8780 for (i = 0; i < idesc->num_outputs; i++)
8782 if (idesc->operands[i] == IA64_OPND_F1)
8784 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8785 if (reg >= min && reg <= max)
8787 specs[count++] = tmpl;
8792 else if (note == 10)
8794 for (i = 0; i < NELEMS (idesc->operands); i++)
8796 if (idesc->operands[i] == IA64_OPND_R1
8797 || idesc->operands[i] == IA64_OPND_R2
8798 || idesc->operands[i] == IA64_OPND_R3)
8800 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8801 if (regno >= 16 && regno <= 31)
8803 specs[count++] = tmpl;
8814 case IA64_RS_AR_FPSR:
8815 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8817 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8818 if (regno == AR_FPSR)
8820 specs[count++] = tmpl;
8825 specs[count++] = tmpl;
8830 /* Handle all AR[REG] resources */
8831 if (note == 0 || note == 1)
8833 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8834 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8835 && regno == dep->regindex)
8837 specs[count++] = tmpl;
8839 /* other AR[REG] resources may be affected by AR accesses */
8840 else if (idesc->operands[0] == IA64_OPND_AR3)
8843 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8844 switch (dep->regindex)
8850 if (regno == AR_BSPSTORE)
8852 specs[count++] = tmpl;
8856 (regno == AR_BSPSTORE
8857 || regno == AR_RNAT))
8859 specs[count++] = tmpl;
8864 else if (idesc->operands[1] == IA64_OPND_AR3)
8867 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8868 switch (dep->regindex)
8873 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8875 specs[count++] = tmpl;
8882 specs[count++] = tmpl;
8892 /* Handle all CR[REG] resources */
8893 if (note == 0 || note == 1)
8895 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8897 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8898 if (regno == dep->regindex)
8900 specs[count++] = tmpl;
8902 else if (!rsrc_write)
8904 /* Reads from CR[IVR] affect other resources. */
8905 if (regno == CR_IVR)
8907 if ((dep->regindex >= CR_IRR0
8908 && dep->regindex <= CR_IRR3)
8909 || dep->regindex == CR_TPR)
8911 specs[count++] = tmpl;
8918 specs[count++] = tmpl;
8927 case IA64_RS_INSERVICE:
8928 /* look for write of EOI (67) or read of IVR (65) */
8929 if ((idesc->operands[0] == IA64_OPND_CR3
8930 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8931 || (idesc->operands[1] == IA64_OPND_CR3
8932 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8934 specs[count++] = tmpl;
8941 specs[count++] = tmpl;
8952 specs[count++] = tmpl;
8956 /* Check if any of the registers accessed are in the rotating region.
8957 mov to/from pr accesses CFM only when qp_regno is in the rotating
8959 for (i = 0; i < NELEMS (idesc->operands); i++)
8961 if (idesc->operands[i] == IA64_OPND_R1
8962 || idesc->operands[i] == IA64_OPND_R2
8963 || idesc->operands[i] == IA64_OPND_R3)
8965 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8966 /* Assumes that md.rot.num_regs is always valid */
8967 if (md.rot.num_regs > 0
8969 && num < 31 + md.rot.num_regs)
8971 specs[count] = tmpl;
8972 specs[count++].specific = 0;
8975 else if (idesc->operands[i] == IA64_OPND_F1
8976 || idesc->operands[i] == IA64_OPND_F2
8977 || idesc->operands[i] == IA64_OPND_F3
8978 || idesc->operands[i] == IA64_OPND_F4)
8980 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8983 specs[count] = tmpl;
8984 specs[count++].specific = 0;
8987 else if (idesc->operands[i] == IA64_OPND_P1
8988 || idesc->operands[i] == IA64_OPND_P2)
8990 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8993 specs[count] = tmpl;
8994 specs[count++].specific = 0;
8998 if (CURR_SLOT.qp_regno > 15)
9000 specs[count] = tmpl;
9001 specs[count++].specific = 0;
9006 /* This is the same as IA64_RS_PRr, except simplified to account for
9007 the fact that there is only one register. */
9011 specs[count++] = tmpl;
9016 if (idesc->operands[2] == IA64_OPND_IMM17)
9017 mask = CURR_SLOT.opnd[2].X_add_number;
9018 if (mask & ((valueT) 1 << 63))
9019 specs[count++] = tmpl;
9021 else if (note == 11)
9023 if ((idesc->operands[0] == IA64_OPND_P1
9024 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
9025 || (idesc->operands[1] == IA64_OPND_P2
9026 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
9028 specs[count++] = tmpl;
9031 else if (note == 12)
9033 if (CURR_SLOT.qp_regno == 63)
9035 specs[count++] = tmpl;
9042 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9043 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9044 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
9045 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
9048 && (idesc->operands[0] == IA64_OPND_P1
9049 || idesc->operands[0] == IA64_OPND_P2))
9051 specs[count] = tmpl;
9052 specs[count++].cmp_type =
9053 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
9056 && (idesc->operands[1] == IA64_OPND_P1
9057 || idesc->operands[1] == IA64_OPND_P2))
9059 specs[count] = tmpl;
9060 specs[count++].cmp_type =
9061 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9066 if (CURR_SLOT.qp_regno == 63)
9068 specs[count++] = tmpl;
9079 /* FIXME we can identify some individual RSE written resources, but RSE
9080 read resources have not yet been completely identified, so for now
9081 treat RSE as a single resource */
9082 if (strncmp (idesc->name, "mov", 3) == 0)
9086 if (idesc->operands[0] == IA64_OPND_AR3
9087 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
9089 specs[count] = tmpl;
9090 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
9095 if (idesc->operands[0] == IA64_OPND_AR3)
9097 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
9098 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
9100 specs[count++] = tmpl;
9103 else if (idesc->operands[1] == IA64_OPND_AR3)
9105 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
9106 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
9107 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
9109 specs[count++] = tmpl;
9116 specs[count++] = tmpl;
9121 /* FIXME -- do any of these need to be non-specific? */
9122 specs[count++] = tmpl;
9126 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
9133 /* Clear branch flags on marked resources. This breaks the link between the
9134 QP of the marking instruction and a subsequent branch on the same QP. */
9137 clear_qp_branch_flag (mask)
9141 for (i = 0; i < regdepslen; i++)
9143 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
9144 if ((bit & mask) != 0)
9146 regdeps[i].link_to_qp_branch = 0;
9151 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
9152 any mutexes which contain one of the PRs and create new ones when
9156 update_qp_mutex (valueT mask)
9162 while (i < qp_mutexeslen)
9164 if ((qp_mutexes[i].prmask & mask) != 0)
9166 /* If it destroys and creates the same mutex, do nothing. */
9167 if (qp_mutexes[i].prmask == mask
9168 && qp_mutexes[i].path == md.path)
9179 fprintf (stderr, " Clearing mutex relation");
9180 print_prmask (qp_mutexes[i].prmask);
9181 fprintf (stderr, "\n");
9184 /* Deal with the old mutex with more than 3+ PRs only if
9185 the new mutex on the same execution path with it.
9187 FIXME: The 3+ mutex support is incomplete.
9188 dot_pred_rel () may be a better place to fix it. */
9189 if (qp_mutexes[i].path == md.path)
9191 /* If it is a proper subset of the mutex, create a
9194 && (qp_mutexes[i].prmask & mask) == mask)
9197 qp_mutexes[i].prmask &= ~mask;
9198 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
9200 /* Modify the mutex if there are more than one
9208 /* Remove the mutex. */
9209 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9217 add_qp_mutex (mask);
9222 /* Remove any mutexes which contain any of the PRs indicated in the mask.
9224 Any changes to a PR clears the mutex relations which include that PR. */
9227 clear_qp_mutex (mask)
9233 while (i < qp_mutexeslen)
9235 if ((qp_mutexes[i].prmask & mask) != 0)
9239 fprintf (stderr, " Clearing mutex relation");
9240 print_prmask (qp_mutexes[i].prmask);
9241 fprintf (stderr, "\n");
9243 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9250 /* Clear implies relations which contain PRs in the given masks.
9251 P1_MASK indicates the source of the implies relation, while P2_MASK
9252 indicates the implied PR. */
9255 clear_qp_implies (p1_mask, p2_mask)
9262 while (i < qp_implieslen)
9264 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
9265 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
9268 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
9269 qp_implies[i].p1, qp_implies[i].p2);
9270 qp_implies[i] = qp_implies[--qp_implieslen];
9277 /* Add the PRs specified to the list of implied relations. */
9280 add_qp_imply (p1, p2)
9287 /* p0 is not meaningful here. */
9288 if (p1 == 0 || p2 == 0)
9294 /* If it exists already, ignore it. */
9295 for (i = 0; i < qp_implieslen; i++)
9297 if (qp_implies[i].p1 == p1
9298 && qp_implies[i].p2 == p2
9299 && qp_implies[i].path == md.path
9300 && !qp_implies[i].p2_branched)
9304 if (qp_implieslen == qp_impliestotlen)
9306 qp_impliestotlen += 20;
9307 qp_implies = (struct qp_imply *)
9308 xrealloc ((void *) qp_implies,
9309 qp_impliestotlen * sizeof (struct qp_imply));
9312 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9313 qp_implies[qp_implieslen].p1 = p1;
9314 qp_implies[qp_implieslen].p2 = p2;
9315 qp_implies[qp_implieslen].path = md.path;
9316 qp_implies[qp_implieslen++].p2_branched = 0;
9318 /* Add in the implied transitive relations; for everything that p2 implies,
9319 make p1 imply that, too; for everything that implies p1, make it imply p2
9321 for (i = 0; i < qp_implieslen; i++)
9323 if (qp_implies[i].p1 == p2)
9324 add_qp_imply (p1, qp_implies[i].p2);
9325 if (qp_implies[i].p2 == p1)
9326 add_qp_imply (qp_implies[i].p1, p2);
9328 /* Add in mutex relations implied by this implies relation; for each mutex
9329 relation containing p2, duplicate it and replace p2 with p1. */
9330 bit = (valueT) 1 << p1;
9331 mask = (valueT) 1 << p2;
9332 for (i = 0; i < qp_mutexeslen; i++)
9334 if (qp_mutexes[i].prmask & mask)
9335 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9339 /* Add the PRs specified in the mask to the mutex list; this means that only
9340 one of the PRs can be true at any time. PR0 should never be included in
9350 if (qp_mutexeslen == qp_mutexestotlen)
9352 qp_mutexestotlen += 20;
9353 qp_mutexes = (struct qpmutex *)
9354 xrealloc ((void *) qp_mutexes,
9355 qp_mutexestotlen * sizeof (struct qpmutex));
9359 fprintf (stderr, " Registering mutex on");
9360 print_prmask (mask);
9361 fprintf (stderr, "\n");
9363 qp_mutexes[qp_mutexeslen].path = md.path;
9364 qp_mutexes[qp_mutexeslen++].prmask = mask;
9368 has_suffix_p (name, suffix)
9372 size_t namelen = strlen (name);
9373 size_t sufflen = strlen (suffix);
9375 if (namelen <= sufflen)
9377 return strcmp (name + namelen - sufflen, suffix) == 0;
9381 clear_register_values ()
9385 fprintf (stderr, " Clearing register values\n");
9386 for (i = 1; i < NELEMS (gr_values); i++)
9387 gr_values[i].known = 0;
9390 /* Keep track of register values/changes which affect DV tracking.
9392 optimization note: should add a flag to classes of insns where otherwise we
9393 have to examine a group of strings to identify them. */
9396 note_register_values (idesc)
9397 struct ia64_opcode *idesc;
9399 valueT qp_changemask = 0;
9402 /* Invalidate values for registers being written to. */
9403 for (i = 0; i < idesc->num_outputs; i++)
9405 if (idesc->operands[i] == IA64_OPND_R1
9406 || idesc->operands[i] == IA64_OPND_R2
9407 || idesc->operands[i] == IA64_OPND_R3)
9409 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9410 if (regno > 0 && regno < NELEMS (gr_values))
9411 gr_values[regno].known = 0;
9413 else if (idesc->operands[i] == IA64_OPND_R3_2)
9415 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9416 if (regno > 0 && regno < 4)
9417 gr_values[regno].known = 0;
9419 else if (idesc->operands[i] == IA64_OPND_P1
9420 || idesc->operands[i] == IA64_OPND_P2)
9422 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9423 qp_changemask |= (valueT) 1 << regno;
9425 else if (idesc->operands[i] == IA64_OPND_PR)
9427 if (idesc->operands[2] & (valueT) 0x10000)
9428 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9430 qp_changemask = idesc->operands[2];
9433 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9435 if (idesc->operands[1] & ((valueT) 1 << 43))
9436 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9438 qp_changemask = idesc->operands[1];
9439 qp_changemask &= ~(valueT) 0xFFFF;
9444 /* Always clear qp branch flags on any PR change. */
9445 /* FIXME there may be exceptions for certain compares. */
9446 clear_qp_branch_flag (qp_changemask);
9448 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9449 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9451 qp_changemask |= ~(valueT) 0xFFFF;
9452 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9454 for (i = 32; i < 32 + md.rot.num_regs; i++)
9455 gr_values[i].known = 0;
9457 clear_qp_mutex (qp_changemask);
9458 clear_qp_implies (qp_changemask, qp_changemask);
9460 /* After a call, all register values are undefined, except those marked
9462 else if (strncmp (idesc->name, "br.call", 6) == 0
9463 || strncmp (idesc->name, "brl.call", 7) == 0)
9465 /* FIXME keep GR values which are marked as "safe_across_calls" */
9466 clear_register_values ();
9467 clear_qp_mutex (~qp_safe_across_calls);
9468 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9469 clear_qp_branch_flag (~qp_safe_across_calls);
9471 else if (is_interruption_or_rfi (idesc)
9472 || is_taken_branch (idesc))
9474 clear_register_values ();
9475 clear_qp_mutex (~(valueT) 0);
9476 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9478 /* Look for mutex and implies relations. */
9479 else if ((idesc->operands[0] == IA64_OPND_P1
9480 || idesc->operands[0] == IA64_OPND_P2)
9481 && (idesc->operands[1] == IA64_OPND_P1
9482 || idesc->operands[1] == IA64_OPND_P2))
9484 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9485 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9486 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9487 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9489 /* If both PRs are PR0, we can't really do anything. */
9490 if (p1 == 0 && p2 == 0)
9493 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9495 /* In general, clear mutexes and implies which include P1 or P2,
9496 with the following exceptions. */
9497 else if (has_suffix_p (idesc->name, ".or.andcm")
9498 || has_suffix_p (idesc->name, ".and.orcm"))
9500 clear_qp_implies (p2mask, p1mask);
9502 else if (has_suffix_p (idesc->name, ".andcm")
9503 || has_suffix_p (idesc->name, ".and"))
9505 clear_qp_implies (0, p1mask | p2mask);
9507 else if (has_suffix_p (idesc->name, ".orcm")
9508 || has_suffix_p (idesc->name, ".or"))
9510 clear_qp_mutex (p1mask | p2mask);
9511 clear_qp_implies (p1mask | p2mask, 0);
9517 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9519 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9520 if (p1 == 0 || p2 == 0)
9521 clear_qp_mutex (p1mask | p2mask);
9523 added = update_qp_mutex (p1mask | p2mask);
9525 if (CURR_SLOT.qp_regno == 0
9526 || has_suffix_p (idesc->name, ".unc"))
9528 if (added == 0 && p1 && p2)
9529 add_qp_mutex (p1mask | p2mask);
9530 if (CURR_SLOT.qp_regno != 0)
9533 add_qp_imply (p1, CURR_SLOT.qp_regno);
9535 add_qp_imply (p2, CURR_SLOT.qp_regno);
9540 /* Look for mov imm insns into GRs. */
9541 else if (idesc->operands[0] == IA64_OPND_R1
9542 && (idesc->operands[1] == IA64_OPND_IMM22
9543 || idesc->operands[1] == IA64_OPND_IMMU64)
9544 && (strcmp (idesc->name, "mov") == 0
9545 || strcmp (idesc->name, "movl") == 0))
9547 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9548 if (regno > 0 && regno < NELEMS (gr_values))
9550 gr_values[regno].known = 1;
9551 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9552 gr_values[regno].path = md.path;
9555 fprintf (stderr, " Know gr%d = ", regno);
9556 fprintf_vma (stderr, gr_values[regno].value);
9557 fputs ("\n", stderr);
9563 clear_qp_mutex (qp_changemask);
9564 clear_qp_implies (qp_changemask, qp_changemask);
9568 /* Return whether the given predicate registers are currently mutex. */
9571 qp_mutex (p1, p2, path)
9581 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9582 for (i = 0; i < qp_mutexeslen; i++)
9584 if (qp_mutexes[i].path >= path
9585 && (qp_mutexes[i].prmask & mask) == mask)
9592 /* Return whether the given resource is in the given insn's list of chks
9593 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9597 resources_match (rs, idesc, note, qp_regno, path)
9599 struct ia64_opcode *idesc;
9604 struct rsrc specs[MAX_SPECS];
9607 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9608 we don't need to check. One exception is note 11, which indicates that
9609 target predicates are written regardless of PR[qp]. */
9610 if (qp_mutex (rs->qp_regno, qp_regno, path)
9614 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9617 /* UNAT checking is a bit more specific than other resources */
9618 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9619 && specs[count].mem_offset.hint
9620 && rs->mem_offset.hint)
9622 if (rs->mem_offset.base == specs[count].mem_offset.base)
9624 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9625 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9632 /* Skip apparent PR write conflicts where both writes are an AND or both
9633 writes are an OR. */
9634 if (rs->dependency->specifier == IA64_RS_PR
9635 || rs->dependency->specifier == IA64_RS_PRr
9636 || rs->dependency->specifier == IA64_RS_PR63)
9638 if (specs[count].cmp_type != CMP_NONE
9639 && specs[count].cmp_type == rs->cmp_type)
9642 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9643 dv_mode[rs->dependency->mode],
9644 rs->dependency->specifier != IA64_RS_PR63 ?
9645 specs[count].index : 63);
9650 " %s on parallel compare conflict %s vs %s on PR%d\n",
9651 dv_mode[rs->dependency->mode],
9652 dv_cmp_type[rs->cmp_type],
9653 dv_cmp_type[specs[count].cmp_type],
9654 rs->dependency->specifier != IA64_RS_PR63 ?
9655 specs[count].index : 63);
9659 /* If either resource is not specific, conservatively assume a conflict
9661 if (!specs[count].specific || !rs->specific)
9663 else if (specs[count].index == rs->index)
9670 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9671 insert a stop to create the break. Update all resource dependencies
9672 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9673 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9674 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9678 insn_group_break (insert_stop, qp_regno, save_current)
9685 if (insert_stop && md.num_slots_in_use > 0)
9686 PREV_SLOT.end_of_insn_group = 1;
9690 fprintf (stderr, " Insn group break%s",
9691 (insert_stop ? " (w/stop)" : ""));
9693 fprintf (stderr, " effective for QP=%d", qp_regno);
9694 fprintf (stderr, "\n");
9698 while (i < regdepslen)
9700 const struct ia64_dependency *dep = regdeps[i].dependency;
9703 && regdeps[i].qp_regno != qp_regno)
9710 && CURR_SLOT.src_file == regdeps[i].file
9711 && CURR_SLOT.src_line == regdeps[i].line)
9717 /* clear dependencies which are automatically cleared by a stop, or
9718 those that have reached the appropriate state of insn serialization */
9719 if (dep->semantics == IA64_DVS_IMPLIED
9720 || dep->semantics == IA64_DVS_IMPLIEDF
9721 || regdeps[i].insn_srlz == STATE_SRLZ)
9723 print_dependency ("Removing", i);
9724 regdeps[i] = regdeps[--regdepslen];
9728 if (dep->semantics == IA64_DVS_DATA
9729 || dep->semantics == IA64_DVS_INSTR
9730 || dep->semantics == IA64_DVS_SPECIFIC)
9732 if (regdeps[i].insn_srlz == STATE_NONE)
9733 regdeps[i].insn_srlz = STATE_STOP;
9734 if (regdeps[i].data_srlz == STATE_NONE)
9735 regdeps[i].data_srlz = STATE_STOP;
9742 /* Add the given resource usage spec to the list of active dependencies. */
9745 mark_resource (idesc, dep, spec, depind, path)
9746 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9747 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9752 if (regdepslen == regdepstotlen)
9754 regdepstotlen += 20;
9755 regdeps = (struct rsrc *)
9756 xrealloc ((void *) regdeps,
9757 regdepstotlen * sizeof (struct rsrc));
9760 regdeps[regdepslen] = *spec;
9761 regdeps[regdepslen].depind = depind;
9762 regdeps[regdepslen].path = path;
9763 regdeps[regdepslen].file = CURR_SLOT.src_file;
9764 regdeps[regdepslen].line = CURR_SLOT.src_line;
9766 print_dependency ("Adding", regdepslen);
9772 print_dependency (action, depind)
9778 fprintf (stderr, " %s %s '%s'",
9779 action, dv_mode[(regdeps[depind].dependency)->mode],
9780 (regdeps[depind].dependency)->name);
9781 if (regdeps[depind].specific && regdeps[depind].index != 0)
9782 fprintf (stderr, " (%d)", regdeps[depind].index);
9783 if (regdeps[depind].mem_offset.hint)
9785 fputs (" ", stderr);
9786 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9787 fputs ("+", stderr);
9788 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9790 fprintf (stderr, "\n");
9795 instruction_serialization ()
9799 fprintf (stderr, " Instruction serialization\n");
9800 for (i = 0; i < regdepslen; i++)
9801 if (regdeps[i].insn_srlz == STATE_STOP)
9802 regdeps[i].insn_srlz = STATE_SRLZ;
9806 data_serialization ()
9810 fprintf (stderr, " Data serialization\n");
9811 while (i < regdepslen)
9813 if (regdeps[i].data_srlz == STATE_STOP
9814 /* Note: as of 991210, all "other" dependencies are cleared by a
9815 data serialization. This might change with new tables */
9816 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9818 print_dependency ("Removing", i);
9819 regdeps[i] = regdeps[--regdepslen];
9826 /* Insert stops and serializations as needed to avoid DVs. */
9829 remove_marked_resource (rs)
9832 switch (rs->dependency->semantics)
9834 case IA64_DVS_SPECIFIC:
9836 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9837 /* ...fall through... */
9838 case IA64_DVS_INSTR:
9840 fprintf (stderr, "Inserting instr serialization\n");
9841 if (rs->insn_srlz < STATE_STOP)
9842 insn_group_break (1, 0, 0);
9843 if (rs->insn_srlz < STATE_SRLZ)
9845 struct slot oldslot = CURR_SLOT;
9846 /* Manually jam a srlz.i insn into the stream */
9847 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
9848 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9849 instruction_serialization ();
9850 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9851 if (++md.num_slots_in_use >= NUM_SLOTS)
9853 CURR_SLOT = oldslot;
9855 insn_group_break (1, 0, 0);
9857 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9858 "other" types of DV are eliminated
9859 by a data serialization */
9862 fprintf (stderr, "Inserting data serialization\n");
9863 if (rs->data_srlz < STATE_STOP)
9864 insn_group_break (1, 0, 0);
9866 struct slot oldslot = CURR_SLOT;
9867 /* Manually jam a srlz.d insn into the stream */
9868 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
9869 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9870 data_serialization ();
9871 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9872 if (++md.num_slots_in_use >= NUM_SLOTS)
9874 CURR_SLOT = oldslot;
9877 case IA64_DVS_IMPLIED:
9878 case IA64_DVS_IMPLIEDF:
9880 fprintf (stderr, "Inserting stop\n");
9881 insn_group_break (1, 0, 0);
9888 /* Check the resources used by the given opcode against the current dependency
9891 The check is run once for each execution path encountered. In this case,
9892 a unique execution path is the sequence of instructions following a code
9893 entry point, e.g. the following has three execution paths, one starting
9894 at L0, one at L1, and one at L2.
9903 check_dependencies (idesc)
9904 struct ia64_opcode *idesc;
9906 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9910 /* Note that the number of marked resources may change within the
9911 loop if in auto mode. */
9913 while (i < regdepslen)
9915 struct rsrc *rs = ®deps[i];
9916 const struct ia64_dependency *dep = rs->dependency;
9921 if (dep->semantics == IA64_DVS_NONE
9922 || (chkind = depends_on (rs->depind, idesc)) == -1)
9928 note = NOTE (opdeps->chks[chkind]);
9930 /* Check this resource against each execution path seen thus far. */
9931 for (path = 0; path <= md.path; path++)
9935 /* If the dependency wasn't on the path being checked, ignore it. */
9936 if (rs->path < path)
9939 /* If the QP for this insn implies a QP which has branched, don't
9940 bother checking. Ed. NOTE: I don't think this check is terribly
9941 useful; what's the point of generating code which will only be
9942 reached if its QP is zero?
9943 This code was specifically inserted to handle the following code,
9944 based on notes from Intel's DV checking code, where p1 implies p2.
9950 if (CURR_SLOT.qp_regno != 0)
9954 for (implies = 0; implies < qp_implieslen; implies++)
9956 if (qp_implies[implies].path >= path
9957 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9958 && qp_implies[implies].p2_branched)
9968 if ((matchtype = resources_match (rs, idesc, note,
9969 CURR_SLOT.qp_regno, path)) != 0)
9972 char pathmsg[256] = "";
9973 char indexmsg[256] = "";
9974 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9977 sprintf (pathmsg, " when entry is at label '%s'",
9978 md.entry_labels[path - 1]);
9979 if (rs->specific && rs->index != 0)
9980 sprintf (indexmsg, ", specific resource number is %d",
9982 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9984 (certain ? "violates" : "may violate"),
9985 dv_mode[dep->mode], dep->name,
9986 dv_sem[dep->semantics],
9989 if (md.explicit_mode)
9991 as_warn ("%s", msg);
9993 as_warn (_("Only the first path encountering the conflict "
9995 as_warn_where (rs->file, rs->line,
9996 _("This is the location of the "
9997 "conflicting usage"));
9998 /* Don't bother checking other paths, to avoid duplicating
10005 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
10007 remove_marked_resource (rs);
10009 /* since the set of dependencies has changed, start over */
10010 /* FIXME -- since we're removing dvs as we go, we
10011 probably don't really need to start over... */
10024 /* Register new dependencies based on the given opcode. */
10027 mark_resources (idesc)
10028 struct ia64_opcode *idesc;
10031 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10032 int add_only_qp_reads = 0;
10034 /* A conditional branch only uses its resources if it is taken; if it is
10035 taken, we stop following that path. The other branch types effectively
10036 *always* write their resources. If it's not taken, register only QP
10038 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
10040 add_only_qp_reads = 1;
10044 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
10046 for (i = 0; i < opdeps->nregs; i++)
10048 const struct ia64_dependency *dep;
10049 struct rsrc specs[MAX_SPECS];
10054 dep = ia64_find_dependency (opdeps->regs[i]);
10055 note = NOTE (opdeps->regs[i]);
10057 if (add_only_qp_reads
10058 && !(dep->mode == IA64_DV_WAR
10059 && (dep->specifier == IA64_RS_PR
10060 || dep->specifier == IA64_RS_PRr
10061 || dep->specifier == IA64_RS_PR63)))
10064 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
10066 while (count-- > 0)
10068 mark_resource (idesc, dep, &specs[count],
10069 DEP (opdeps->regs[i]), md.path);
10072 /* The execution path may affect register values, which may in turn
10073 affect which indirect-access resources are accessed. */
10074 switch (dep->specifier)
10078 case IA64_RS_CPUID:
10086 for (path = 0; path < md.path; path++)
10088 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
10089 while (count-- > 0)
10090 mark_resource (idesc, dep, &specs[count],
10091 DEP (opdeps->regs[i]), path);
10098 /* Remove dependencies when they no longer apply. */
10101 update_dependencies (idesc)
10102 struct ia64_opcode *idesc;
10106 if (strcmp (idesc->name, "srlz.i") == 0)
10108 instruction_serialization ();
10110 else if (strcmp (idesc->name, "srlz.d") == 0)
10112 data_serialization ();
10114 else if (is_interruption_or_rfi (idesc)
10115 || is_taken_branch (idesc))
10117 /* Although technically the taken branch doesn't clear dependencies
10118 which require a srlz.[id], we don't follow the branch; the next
10119 instruction is assumed to start with a clean slate. */
10123 else if (is_conditional_branch (idesc)
10124 && CURR_SLOT.qp_regno != 0)
10126 int is_call = strstr (idesc->name, ".call") != NULL;
10128 for (i = 0; i < qp_implieslen; i++)
10130 /* If the conditional branch's predicate is implied by the predicate
10131 in an existing dependency, remove that dependency. */
10132 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
10135 /* Note that this implied predicate takes a branch so that if
10136 a later insn generates a DV but its predicate implies this
10137 one, we can avoid the false DV warning. */
10138 qp_implies[i].p2_branched = 1;
10139 while (depind < regdepslen)
10141 if (regdeps[depind].qp_regno == qp_implies[i].p1)
10143 print_dependency ("Removing", depind);
10144 regdeps[depind] = regdeps[--regdepslen];
10151 /* Any marked resources which have this same predicate should be
10152 cleared, provided that the QP hasn't been modified between the
10153 marking instruction and the branch. */
10156 insn_group_break (0, CURR_SLOT.qp_regno, 1);
10161 while (i < regdepslen)
10163 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
10164 && regdeps[i].link_to_qp_branch
10165 && (regdeps[i].file != CURR_SLOT.src_file
10166 || regdeps[i].line != CURR_SLOT.src_line))
10168 /* Treat like a taken branch */
10169 print_dependency ("Removing", i);
10170 regdeps[i] = regdeps[--regdepslen];
10179 /* Examine the current instruction for dependency violations. */
10183 struct ia64_opcode *idesc;
10187 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
10188 idesc->name, CURR_SLOT.src_line,
10189 idesc->dependencies->nchks,
10190 idesc->dependencies->nregs);
10193 /* Look through the list of currently marked resources; if the current
10194 instruction has the dependency in its chks list which uses that resource,
10195 check against the specific resources used. */
10196 check_dependencies (idesc);
10198 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
10199 then add them to the list of marked resources. */
10200 mark_resources (idesc);
10202 /* There are several types of dependency semantics, and each has its own
10203 requirements for being cleared
10205 Instruction serialization (insns separated by interruption, rfi, or
10206 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
10208 Data serialization (instruction serialization, or writer + srlz.d +
10209 reader, where writer and srlz.d are in separate groups) clears
10210 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
10211 always be the case).
10213 Instruction group break (groups separated by stop, taken branch,
10214 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
10216 update_dependencies (idesc);
10218 /* Sometimes, knowing a register value allows us to avoid giving a false DV
10219 warning. Keep track of as many as possible that are useful. */
10220 note_register_values (idesc);
10222 /* We don't need or want this anymore. */
10223 md.mem_offset.hint = 0;
10228 /* Translate one line of assembly. Pseudo ops and labels do not show
10234 char *saved_input_line_pointer, *mnemonic;
10235 const struct pseudo_opcode *pdesc;
10236 struct ia64_opcode *idesc;
10237 unsigned char qp_regno;
10238 unsigned int flags;
10241 saved_input_line_pointer = input_line_pointer;
10242 input_line_pointer = str;
10244 /* extract the opcode (mnemonic): */
10246 mnemonic = input_line_pointer;
10247 ch = get_symbol_end ();
10248 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
10251 *input_line_pointer = ch;
10252 (*pdesc->handler) (pdesc->arg);
10256 /* Find the instruction descriptor matching the arguments. */
10258 idesc = ia64_find_opcode (mnemonic);
10259 *input_line_pointer = ch;
10262 as_bad ("Unknown opcode `%s'", mnemonic);
10266 idesc = parse_operands (idesc);
10270 /* Handle the dynamic ops we can handle now: */
10271 if (idesc->type == IA64_TYPE_DYN)
10273 if (strcmp (idesc->name, "add") == 0)
10275 if (CURR_SLOT.opnd[2].X_op == O_register
10276 && CURR_SLOT.opnd[2].X_add_number < 4)
10280 ia64_free_opcode (idesc);
10281 idesc = ia64_find_opcode (mnemonic);
10283 else if (strcmp (idesc->name, "mov") == 0)
10285 enum ia64_opnd opnd1, opnd2;
10288 opnd1 = idesc->operands[0];
10289 opnd2 = idesc->operands[1];
10290 if (opnd1 == IA64_OPND_AR3)
10292 else if (opnd2 == IA64_OPND_AR3)
10296 if (CURR_SLOT.opnd[rop].X_op == O_register)
10298 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10299 mnemonic = "mov.i";
10300 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10301 mnemonic = "mov.m";
10309 ia64_free_opcode (idesc);
10310 idesc = ia64_find_opcode (mnemonic);
10311 while (idesc != NULL
10312 && (idesc->operands[0] != opnd1
10313 || idesc->operands[1] != opnd2))
10314 idesc = get_next_opcode (idesc);
10318 else if (strcmp (idesc->name, "mov.i") == 0
10319 || strcmp (idesc->name, "mov.m") == 0)
10321 enum ia64_opnd opnd1, opnd2;
10324 opnd1 = idesc->operands[0];
10325 opnd2 = idesc->operands[1];
10326 if (opnd1 == IA64_OPND_AR3)
10328 else if (opnd2 == IA64_OPND_AR3)
10332 if (CURR_SLOT.opnd[rop].X_op == O_register)
10335 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10337 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10339 if (unit != 'a' && unit != idesc->name [4])
10340 as_bad ("AR %d cannot be accessed by %c-unit",
10341 (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR),
10347 if (md.qp.X_op == O_register)
10349 qp_regno = md.qp.X_add_number - REG_P;
10350 md.qp.X_op = O_absent;
10353 flags = idesc->flags;
10355 if ((flags & IA64_OPCODE_FIRST) != 0)
10357 /* The alignment frag has to end with a stop bit only if the
10358 next instruction after the alignment directive has to be
10359 the first instruction in an instruction group. */
10362 while (align_frag->fr_type != rs_align_code)
10364 align_frag = align_frag->fr_next;
10368 /* align_frag can be NULL if there are directives in
10370 if (align_frag && align_frag->fr_next == frag_now)
10371 align_frag->tc_frag_data = 1;
10374 insn_group_break (1, 0, 0);
10378 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10380 as_bad ("`%s' cannot be predicated", idesc->name);
10384 /* Build the instruction. */
10385 CURR_SLOT.qp_regno = qp_regno;
10386 CURR_SLOT.idesc = idesc;
10387 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10388 dwarf2_where (&CURR_SLOT.debug_line);
10390 /* Add unwind entry, if there is one. */
10391 if (unwind.current_entry)
10393 CURR_SLOT.unwind_record = unwind.current_entry;
10394 unwind.current_entry = NULL;
10396 if (unwind.proc_start && S_IS_DEFINED (unwind.proc_start))
10399 /* Check for dependency violations. */
10403 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10404 if (++md.num_slots_in_use >= NUM_SLOTS)
10405 emit_one_bundle ();
10407 if ((flags & IA64_OPCODE_LAST) != 0)
10408 insn_group_break (1, 0, 0);
10410 md.last_text_seg = now_seg;
10413 input_line_pointer = saved_input_line_pointer;
10416 /* Called when symbol NAME cannot be found in the symbol table.
10417 Should be used for dynamic valued symbols only. */
10420 md_undefined_symbol (name)
10421 char *name ATTRIBUTE_UNUSED;
10426 /* Called for any expression that can not be recognized. When the
10427 function is called, `input_line_pointer' will point to the start of
10434 enum pseudo_type pseudo_type;
10439 switch (*input_line_pointer)
10442 /* Find what relocation pseudo-function we're dealing with. */
10444 ch = *++input_line_pointer;
10445 for (i = 0; i < NELEMS (pseudo_func); ++i)
10446 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
10448 len = strlen (pseudo_func[i].name);
10449 if (strncmp (pseudo_func[i].name + 1,
10450 input_line_pointer + 1, len - 1) == 0
10451 && !is_part_of_name (input_line_pointer[len]))
10453 input_line_pointer += len;
10454 pseudo_type = pseudo_func[i].type;
10458 switch (pseudo_type)
10460 case PSEUDO_FUNC_RELOC:
10461 SKIP_WHITESPACE ();
10462 if (*input_line_pointer != '(')
10464 as_bad ("Expected '('");
10468 ++input_line_pointer;
10470 if (*input_line_pointer++ != ')')
10472 as_bad ("Missing ')'");
10475 if (e->X_op != O_symbol)
10477 if (e->X_op != O_pseudo_fixup)
10479 as_bad ("Not a symbolic expression");
10482 if (i != FUNC_LT_RELATIVE)
10484 as_bad ("Illegal combination of relocation functions");
10487 switch (S_GET_VALUE (e->X_op_symbol))
10489 case FUNC_FPTR_RELATIVE:
10490 i = FUNC_LT_FPTR_RELATIVE; break;
10491 case FUNC_DTP_MODULE:
10492 i = FUNC_LT_DTP_MODULE; break;
10493 case FUNC_DTP_RELATIVE:
10494 i = FUNC_LT_DTP_RELATIVE; break;
10495 case FUNC_TP_RELATIVE:
10496 i = FUNC_LT_TP_RELATIVE; break;
10498 as_bad ("Illegal combination of relocation functions");
10502 /* Make sure gas doesn't get rid of local symbols that are used
10504 e->X_op = O_pseudo_fixup;
10505 e->X_op_symbol = pseudo_func[i].u.sym;
10508 case PSEUDO_FUNC_CONST:
10509 e->X_op = O_constant;
10510 e->X_add_number = pseudo_func[i].u.ival;
10513 case PSEUDO_FUNC_REG:
10514 e->X_op = O_register;
10515 e->X_add_number = pseudo_func[i].u.ival;
10519 name = input_line_pointer - 1;
10521 as_bad ("Unknown pseudo function `%s'", name);
10527 ++input_line_pointer;
10529 if (*input_line_pointer != ']')
10531 as_bad ("Closing bracket misssing");
10536 if (e->X_op != O_register)
10537 as_bad ("Register expected as index");
10539 ++input_line_pointer;
10550 ignore_rest_of_line ();
10553 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10554 a section symbol plus some offset. For relocs involving @fptr(),
10555 directives we don't want such adjustments since we need to have the
10556 original symbol's name in the reloc. */
10558 ia64_fix_adjustable (fix)
10561 /* Prevent all adjustments to global symbols */
10562 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10565 switch (fix->fx_r_type)
10567 case BFD_RELOC_IA64_FPTR64I:
10568 case BFD_RELOC_IA64_FPTR32MSB:
10569 case BFD_RELOC_IA64_FPTR32LSB:
10570 case BFD_RELOC_IA64_FPTR64MSB:
10571 case BFD_RELOC_IA64_FPTR64LSB:
10572 case BFD_RELOC_IA64_LTOFF_FPTR22:
10573 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10583 ia64_force_relocation (fix)
10586 switch (fix->fx_r_type)
10588 case BFD_RELOC_IA64_FPTR64I:
10589 case BFD_RELOC_IA64_FPTR32MSB:
10590 case BFD_RELOC_IA64_FPTR32LSB:
10591 case BFD_RELOC_IA64_FPTR64MSB:
10592 case BFD_RELOC_IA64_FPTR64LSB:
10594 case BFD_RELOC_IA64_LTOFF22:
10595 case BFD_RELOC_IA64_LTOFF64I:
10596 case BFD_RELOC_IA64_LTOFF_FPTR22:
10597 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10598 case BFD_RELOC_IA64_PLTOFF22:
10599 case BFD_RELOC_IA64_PLTOFF64I:
10600 case BFD_RELOC_IA64_PLTOFF64MSB:
10601 case BFD_RELOC_IA64_PLTOFF64LSB:
10603 case BFD_RELOC_IA64_LTOFF22X:
10604 case BFD_RELOC_IA64_LDXMOV:
10611 return generic_force_reloc (fix);
10614 /* Decide from what point a pc-relative relocation is relative to,
10615 relative to the pc-relative fixup. Er, relatively speaking. */
10617 ia64_pcrel_from_section (fix, sec)
10621 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10623 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10630 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10632 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10636 expr.X_op = O_pseudo_fixup;
10637 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10638 expr.X_add_number = 0;
10639 expr.X_add_symbol = symbol;
10640 emit_expr (&expr, size);
10643 /* This is called whenever some data item (not an instruction) needs a
10644 fixup. We pick the right reloc code depending on the byteorder
10645 currently in effect. */
10647 ia64_cons_fix_new (f, where, nbytes, exp)
10653 bfd_reloc_code_real_type code;
10658 /* There are no reloc for 8 and 16 bit quantities, but we allow
10659 them here since they will work fine as long as the expression
10660 is fully defined at the end of the pass over the source file. */
10661 case 1: code = BFD_RELOC_8; break;
10662 case 2: code = BFD_RELOC_16; break;
10664 if (target_big_endian)
10665 code = BFD_RELOC_IA64_DIR32MSB;
10667 code = BFD_RELOC_IA64_DIR32LSB;
10671 /* In 32-bit mode, data8 could mean function descriptors too. */
10672 if (exp->X_op == O_pseudo_fixup
10673 && exp->X_op_symbol
10674 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10675 && !(md.flags & EF_IA_64_ABI64))
10677 if (target_big_endian)
10678 code = BFD_RELOC_IA64_IPLTMSB;
10680 code = BFD_RELOC_IA64_IPLTLSB;
10681 exp->X_op = O_symbol;
10686 if (target_big_endian)
10687 code = BFD_RELOC_IA64_DIR64MSB;
10689 code = BFD_RELOC_IA64_DIR64LSB;
10694 if (exp->X_op == O_pseudo_fixup
10695 && exp->X_op_symbol
10696 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10698 if (target_big_endian)
10699 code = BFD_RELOC_IA64_IPLTMSB;
10701 code = BFD_RELOC_IA64_IPLTLSB;
10702 exp->X_op = O_symbol;
10708 as_bad ("Unsupported fixup size %d", nbytes);
10709 ignore_rest_of_line ();
10713 if (exp->X_op == O_pseudo_fixup)
10715 exp->X_op = O_symbol;
10716 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10717 /* ??? If code unchanged, unsupported. */
10720 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10721 /* We need to store the byte order in effect in case we're going
10722 to fix an 8 or 16 bit relocation (for which there no real
10723 relocs available). See md_apply_fix3(). */
10724 fix->tc_fix_data.bigendian = target_big_endian;
10727 /* Return the actual relocation we wish to associate with the pseudo
10728 reloc described by SYM and R_TYPE. SYM should be one of the
10729 symbols in the pseudo_func array, or NULL. */
10731 static bfd_reloc_code_real_type
10732 ia64_gen_real_reloc_type (sym, r_type)
10733 struct symbol *sym;
10734 bfd_reloc_code_real_type r_type;
10736 bfd_reloc_code_real_type new = 0;
10743 switch (S_GET_VALUE (sym))
10745 case FUNC_FPTR_RELATIVE:
10748 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10749 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10750 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10751 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10752 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10757 case FUNC_GP_RELATIVE:
10760 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10761 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10762 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10763 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10764 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10765 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10770 case FUNC_LT_RELATIVE:
10773 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10774 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10779 case FUNC_LT_RELATIVE_X:
10782 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10787 case FUNC_PC_RELATIVE:
10790 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10791 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10792 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10793 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10794 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10795 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10800 case FUNC_PLT_RELATIVE:
10803 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10804 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10805 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10806 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10811 case FUNC_SEC_RELATIVE:
10814 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10815 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10816 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10817 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10822 case FUNC_SEG_RELATIVE:
10825 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10826 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10827 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10828 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10833 case FUNC_LTV_RELATIVE:
10836 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10837 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10838 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10839 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10844 case FUNC_LT_FPTR_RELATIVE:
10847 case BFD_RELOC_IA64_IMM22:
10848 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10849 case BFD_RELOC_IA64_IMM64:
10850 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10856 case FUNC_TP_RELATIVE:
10859 case BFD_RELOC_IA64_IMM14:
10860 new = BFD_RELOC_IA64_TPREL14; break;
10861 case BFD_RELOC_IA64_IMM22:
10862 new = BFD_RELOC_IA64_TPREL22; break;
10863 case BFD_RELOC_IA64_IMM64:
10864 new = BFD_RELOC_IA64_TPREL64I; break;
10870 case FUNC_LT_TP_RELATIVE:
10873 case BFD_RELOC_IA64_IMM22:
10874 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10880 case FUNC_LT_DTP_MODULE:
10883 case BFD_RELOC_IA64_IMM22:
10884 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10890 case FUNC_DTP_RELATIVE:
10893 case BFD_RELOC_IA64_DIR64MSB:
10894 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10895 case BFD_RELOC_IA64_DIR64LSB:
10896 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10897 case BFD_RELOC_IA64_IMM14:
10898 new = BFD_RELOC_IA64_DTPREL14; break;
10899 case BFD_RELOC_IA64_IMM22:
10900 new = BFD_RELOC_IA64_DTPREL22; break;
10901 case BFD_RELOC_IA64_IMM64:
10902 new = BFD_RELOC_IA64_DTPREL64I; break;
10908 case FUNC_LT_DTP_RELATIVE:
10911 case BFD_RELOC_IA64_IMM22:
10912 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10918 case FUNC_IPLT_RELOC:
10925 /* Hmmmm. Should this ever occur? */
10932 /* Here is where generate the appropriate reloc for pseudo relocation
10935 ia64_validate_fix (fix)
10938 switch (fix->fx_r_type)
10940 case BFD_RELOC_IA64_FPTR64I:
10941 case BFD_RELOC_IA64_FPTR32MSB:
10942 case BFD_RELOC_IA64_FPTR64LSB:
10943 case BFD_RELOC_IA64_LTOFF_FPTR22:
10944 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10945 if (fix->fx_offset != 0)
10946 as_bad_where (fix->fx_file, fix->fx_line,
10947 "No addend allowed in @fptr() relocation");
10955 fix_insn (fix, odesc, value)
10957 const struct ia64_operand *odesc;
10960 bfd_vma insn[3], t0, t1, control_bits;
10965 slot = fix->fx_where & 0x3;
10966 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10968 /* Bundles are always in little-endian byte order */
10969 t0 = bfd_getl64 (fixpos);
10970 t1 = bfd_getl64 (fixpos + 8);
10971 control_bits = t0 & 0x1f;
10972 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10973 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10974 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10977 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10979 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10980 insn[2] |= (((value & 0x7f) << 13)
10981 | (((value >> 7) & 0x1ff) << 27)
10982 | (((value >> 16) & 0x1f) << 22)
10983 | (((value >> 21) & 0x1) << 21)
10984 | (((value >> 63) & 0x1) << 36));
10986 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10988 if (value & ~0x3fffffffffffffffULL)
10989 err = "integer operand out of range";
10990 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10991 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10993 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10996 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10997 insn[2] |= ((((value >> 59) & 0x1) << 36)
10998 | (((value >> 0) & 0xfffff) << 13));
11001 err = (*odesc->insert) (odesc, value, insn + slot);
11004 as_bad_where (fix->fx_file, fix->fx_line, err);
11006 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
11007 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
11008 number_to_chars_littleendian (fixpos + 0, t0, 8);
11009 number_to_chars_littleendian (fixpos + 8, t1, 8);
11012 /* Attempt to simplify or even eliminate a fixup. The return value is
11013 ignored; perhaps it was once meaningful, but now it is historical.
11014 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
11016 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
11020 md_apply_fix3 (fix, valP, seg)
11023 segT seg ATTRIBUTE_UNUSED;
11026 valueT value = *valP;
11028 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
11032 switch (fix->fx_r_type)
11034 case BFD_RELOC_IA64_DIR32MSB:
11035 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
11038 case BFD_RELOC_IA64_DIR32LSB:
11039 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
11042 case BFD_RELOC_IA64_DIR64MSB:
11043 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
11046 case BFD_RELOC_IA64_DIR64LSB:
11047 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
11056 switch (fix->fx_r_type)
11058 case BFD_RELOC_UNUSED:
11059 /* This must be a TAG13 or TAG13b operand. There are no external
11060 relocs defined for them, so we must give an error. */
11061 as_bad_where (fix->fx_file, fix->fx_line,
11062 "%s must have a constant value",
11063 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
11067 case BFD_RELOC_IA64_TPREL14:
11068 case BFD_RELOC_IA64_TPREL22:
11069 case BFD_RELOC_IA64_TPREL64I:
11070 case BFD_RELOC_IA64_LTOFF_TPREL22:
11071 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
11072 case BFD_RELOC_IA64_DTPREL14:
11073 case BFD_RELOC_IA64_DTPREL22:
11074 case BFD_RELOC_IA64_DTPREL64I:
11075 case BFD_RELOC_IA64_LTOFF_DTPREL22:
11076 S_SET_THREAD_LOCAL (fix->fx_addsy);
11083 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
11085 if (fix->tc_fix_data.bigendian)
11086 number_to_chars_bigendian (fixpos, value, fix->fx_size);
11088 number_to_chars_littleendian (fixpos, value, fix->fx_size);
11093 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
11098 /* Generate the BFD reloc to be stuck in the object file from the
11099 fixup used internally in the assembler. */
11102 tc_gen_reloc (sec, fixp)
11103 asection *sec ATTRIBUTE_UNUSED;
11108 reloc = xmalloc (sizeof (*reloc));
11109 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11110 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11111 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11112 reloc->addend = fixp->fx_offset;
11113 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
11117 as_bad_where (fixp->fx_file, fixp->fx_line,
11118 "Cannot represent %s relocation in object file",
11119 bfd_get_reloc_code_name (fixp->fx_r_type));
11124 /* Turn a string in input_line_pointer into a floating point constant
11125 of type TYPE, and store the appropriate bytes in *LIT. The number
11126 of LITTLENUMS emitted is stored in *SIZE. An error message is
11127 returned, or NULL on OK. */
11129 #define MAX_LITTLENUMS 5
11132 md_atof (type, lit, size)
11137 LITTLENUM_TYPE words[MAX_LITTLENUMS];
11167 return "Bad call to MD_ATOF()";
11169 t = atof_ieee (input_line_pointer, type, words);
11171 input_line_pointer = t;
11173 (*ia64_float_to_chars) (lit, words, prec);
11177 /* It is 10 byte floating point with 6 byte padding. */
11178 memset (&lit [10], 0, 6);
11179 *size = 8 * sizeof (LITTLENUM_TYPE);
11182 *size = prec * sizeof (LITTLENUM_TYPE);
11187 /* Handle ia64 specific semantics of the align directive. */
11190 ia64_md_do_align (n, fill, len, max)
11191 int n ATTRIBUTE_UNUSED;
11192 const char *fill ATTRIBUTE_UNUSED;
11193 int len ATTRIBUTE_UNUSED;
11194 int max ATTRIBUTE_UNUSED;
11196 if (subseg_text_p (now_seg))
11197 ia64_flush_insns ();
11200 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
11201 of an rs_align_code fragment. */
11204 ia64_handle_align (fragp)
11207 /* Use mfi bundle of nops with no stop bits. */
11208 static const unsigned char le_nop[]
11209 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
11210 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
11211 static const unsigned char le_nop_stop[]
11212 = { 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
11213 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
11217 const unsigned char *nop;
11219 if (fragp->fr_type != rs_align_code)
11222 /* Check if this frag has to end with a stop bit. */
11223 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
11225 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11226 p = fragp->fr_literal + fragp->fr_fix;
11228 /* If no paddings are needed, we check if we need a stop bit. */
11229 if (!bytes && fragp->tc_frag_data)
11231 if (fragp->fr_fix < 16)
11233 /* FIXME: It won't work with
11235 alloc r32=ar.pfs,1,2,4,0
11239 as_bad_where (fragp->fr_file, fragp->fr_line,
11240 _("Can't add stop bit to mark end of instruction group"));
11243 /* Bundles are always in little-endian byte order. Make sure
11244 the previous bundle has the stop bit. */
11248 /* Make sure we are on a 16-byte boundary, in case someone has been
11249 putting data into a text section. */
11252 int fix = bytes & 15;
11253 memset (p, 0, fix);
11256 fragp->fr_fix += fix;
11259 /* Instruction bundles are always little-endian. */
11260 memcpy (p, nop, 16);
11261 fragp->fr_var = 16;
11265 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
11270 number_to_chars_bigendian (lit, (long) (*words++),
11271 sizeof (LITTLENUM_TYPE));
11272 lit += sizeof (LITTLENUM_TYPE);
11277 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
11282 number_to_chars_littleendian (lit, (long) (words[prec]),
11283 sizeof (LITTLENUM_TYPE));
11284 lit += sizeof (LITTLENUM_TYPE);
11289 ia64_elf_section_change_hook (void)
11291 if (elf_section_type (now_seg) == SHT_IA_64_UNWIND
11292 && elf_linked_to_section (now_seg) == NULL)
11293 elf_linked_to_section (now_seg) = text_section;
11294 dot_byteorder (-1);
11297 /* Check if a label should be made global. */
11299 ia64_check_label (symbolS *label)
11301 if (*input_line_pointer == ':')
11303 S_SET_EXTERNAL (label);
11304 input_line_pointer++;
11308 /* Used to remember where .alias and .secalias directives are seen. We
11309 will rename symbol and section names when we are about to output
11310 the relocatable file. */
11313 char *file; /* The file where the directive is seen. */
11314 unsigned int line; /* The line number the directive is at. */
11315 const char *name; /* The orignale name of the symbol. */
11318 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11319 .secalias. Otherwise, it is .alias. */
11321 dot_alias (int section)
11323 char *name, *alias;
11327 const char *error_string;
11330 struct hash_control *ahash, *nhash;
11333 name = input_line_pointer;
11334 delim = get_symbol_end ();
11335 end_name = input_line_pointer;
11338 if (name == end_name)
11340 as_bad (_("expected symbol name"));
11341 discard_rest_of_line ();
11345 SKIP_WHITESPACE ();
11347 if (*input_line_pointer != ',')
11350 as_bad (_("expected comma after \"%s\""), name);
11352 ignore_rest_of_line ();
11356 input_line_pointer++;
11359 /* We call demand_copy_C_string to check if alias string is valid.
11360 There should be a closing `"' and no `\0' in the string. */
11361 alias = demand_copy_C_string (&len);
11364 ignore_rest_of_line ();
11368 /* Make a copy of name string. */
11369 len = strlen (name) + 1;
11370 obstack_grow (¬es, name, len);
11371 name = obstack_finish (¬es);
11376 ahash = secalias_hash;
11377 nhash = secalias_name_hash;
11382 ahash = alias_hash;
11383 nhash = alias_name_hash;
11386 /* Check if alias has been used before. */
11387 h = (struct alias *) hash_find (ahash, alias);
11390 if (strcmp (h->name, name))
11391 as_bad (_("`%s' is already the alias of %s `%s'"),
11392 alias, kind, h->name);
11396 /* Check if name already has an alias. */
11397 a = (const char *) hash_find (nhash, name);
11400 if (strcmp (a, alias))
11401 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11405 h = (struct alias *) xmalloc (sizeof (struct alias));
11406 as_where (&h->file, &h->line);
11409 error_string = hash_jam (ahash, alias, (PTR) h);
11412 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11413 alias, kind, error_string);
11417 error_string = hash_jam (nhash, name, (PTR) alias);
11420 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11421 alias, kind, error_string);
11423 obstack_free (¬es, name);
11424 obstack_free (¬es, alias);
11427 demand_empty_rest_of_line ();
11430 /* It renames the original symbol name to its alias. */
11432 do_alias (const char *alias, PTR value)
11434 struct alias *h = (struct alias *) value;
11435 symbolS *sym = symbol_find (h->name);
11438 as_warn_where (h->file, h->line,
11439 _("symbol `%s' aliased to `%s' is not used"),
11442 S_SET_NAME (sym, (char *) alias);
11445 /* Called from write_object_file. */
11447 ia64_adjust_symtab (void)
11449 hash_traverse (alias_hash, do_alias);
11452 /* It renames the original section name to its alias. */
11454 do_secalias (const char *alias, PTR value)
11456 struct alias *h = (struct alias *) value;
11457 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11460 as_warn_where (h->file, h->line,
11461 _("section `%s' aliased to `%s' is not used"),
11467 /* Called from write_object_file. */
11469 ia64_frob_file (void)
11471 hash_traverse (secalias_hash, do_secalias);