1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
35 - labels are wrong if automatic alignment is introduced
36 (e.g., checkout the second real10 definition in test-data.s)
38 <reg>.safe_across_calls and any other DV-related directives I don't
39 have documentation for.
40 verify mod-sched-brs reads/writes are checked/marked (and other
46 #include "dwarf2dbg.h"
49 #include "opcode/ia64.h"
53 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
54 #define MIN(a,b) ((a) < (b) ? (a) : (b))
57 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
58 #define CURR_SLOT md.slot[md.curr_slot]
60 #define O_pseudo_fixup (O_max + 1)
64 SPECIAL_SECTION_BSS = 0,
66 SPECIAL_SECTION_SDATA,
67 SPECIAL_SECTION_RODATA,
68 SPECIAL_SECTION_COMMENT,
69 SPECIAL_SECTION_UNWIND,
70 SPECIAL_SECTION_UNWIND_INFO
83 FUNC_LT_FPTR_RELATIVE,
89 REG_FR = (REG_GR + 128),
90 REG_AR = (REG_FR + 128),
91 REG_CR = (REG_AR + 128),
92 REG_P = (REG_CR + 128),
93 REG_BR = (REG_P + 64),
94 REG_IP = (REG_BR + 8),
101 /* The following are pseudo-registers for use by gas only. */
113 /* The following pseudo-registers are used for unwind directives only: */
121 DYNREG_GR = 0, /* dynamic general purpose register */
122 DYNREG_FR, /* dynamic floating point register */
123 DYNREG_PR, /* dynamic predicate register */
127 enum operand_match_result
130 OPERAND_OUT_OF_RANGE,
134 /* On the ia64, we can't know the address of a text label until the
135 instructions are packed into a bundle. To handle this, we keep
136 track of the list of labels that appear in front of each
140 struct label_fix *next;
144 extern int target_big_endian;
146 /* Characters which always start a comment. */
147 const char comment_chars[] = "";
149 /* Characters which start a comment at the beginning of a line. */
150 const char line_comment_chars[] = "#";
152 /* Characters which may be used to separate multiple commands on a
154 const char line_separator_chars[] = ";";
156 /* Characters which are used to indicate an exponent in a floating
158 const char EXP_CHARS[] = "eE";
160 /* Characters which mean that a number is a floating point constant,
162 const char FLT_CHARS[] = "rRsSfFdDxXpP";
164 /* ia64-specific option processing: */
166 const char *md_shortopts = "m:N:x::";
168 struct option md_longopts[] =
170 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
171 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
172 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
173 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
176 size_t md_longopts_size = sizeof (md_longopts);
180 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
181 struct hash_control *reg_hash; /* register name hash table */
182 struct hash_control *dynreg_hash; /* dynamic register hash table */
183 struct hash_control *const_hash; /* constant hash table */
184 struct hash_control *entry_hash; /* code entry hint hash table */
186 symbolS *regsym[REG_NUM];
188 /* If X_op is != O_absent, the registername for the instruction's
189 qualifying predicate. If NULL, p0 is assumed for instructions
190 that are predicatable. */
197 explicit_mode : 1, /* which mode we're in */
198 default_explicit_mode : 1, /* which mode is the default */
199 mode_explicitly_set : 1, /* was the current mode explicitly set? */
201 keep_pending_output : 1;
203 /* Each bundle consists of up to three instructions. We keep
204 track of four most recent instructions so we can correctly set
205 the end_of_insn_group for the last instruction in a bundle. */
207 int num_slots_in_use;
211 end_of_insn_group : 1,
212 manual_bundling_on : 1,
213 manual_bundling_off : 1;
214 signed char user_template; /* user-selected template, if any */
215 unsigned char qp_regno; /* qualifying predicate */
216 /* This duplicates a good fraction of "struct fix" but we
217 can't use a "struct fix" instead since we can't call
218 fix_new_exp() until we know the address of the instruction. */
222 bfd_reloc_code_real_type code;
223 enum ia64_opnd opnd; /* type of operand in need of fix */
224 unsigned int is_pcrel : 1; /* is operand pc-relative? */
225 expressionS expr; /* the value to be inserted */
227 fixup[2]; /* at most two fixups per insn */
228 struct ia64_opcode *idesc;
229 struct label_fix *label_fixups;
230 struct label_fix *tag_fixups;
231 struct unw_rec_list *unwind_record; /* Unwind directive. */
234 unsigned int src_line;
235 struct dwarf2_line_info debug_line;
243 struct dynreg *next; /* next dynamic register */
245 unsigned short base; /* the base register number */
246 unsigned short num_regs; /* # of registers in this set */
248 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
250 flagword flags; /* ELF-header flags */
253 unsigned hint:1; /* is this hint currently valid? */
254 bfd_vma offset; /* mem.offset offset */
255 bfd_vma base; /* mem.offset base */
258 int path; /* number of alt. entry points seen */
259 const char **entry_labels; /* labels of all alternate paths in
260 the current DV-checking block. */
261 int maxpaths; /* size currently allocated for
263 /* Support for hardware errata workarounds. */
265 /* Record data about the last three insn groups. */
268 /* B-step workaround.
269 For each predicate register, this is set if the corresponding insn
270 group conditionally sets this register with one of the affected
273 /* B-step workaround.
274 For each general register, this is set if the corresponding insn
275 a) is conditional one one of the predicate registers for which
276 P_REG_SET is 1 in the corresponding entry of the previous group,
277 b) sets this general register with one of the affected
279 int g_reg_set_conditionally[128];
285 /* application registers: */
291 #define AR_BSPSTORE 18
306 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
307 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
308 {"ar.rsc", 16}, {"ar.bsp", 17},
309 {"ar.bspstore", 18}, {"ar.rnat", 19},
310 {"ar.fcr", 21}, {"ar.eflag", 24},
311 {"ar.csd", 25}, {"ar.ssd", 26},
312 {"ar.cflg", 27}, {"ar.fsr", 28},
313 {"ar.fir", 29}, {"ar.fdr", 30},
314 {"ar.ccv", 32}, {"ar.unat", 36},
315 {"ar.fpsr", 40}, {"ar.itc", 44},
316 {"ar.pfs", 64}, {"ar.lc", 65},
337 /* control registers: */
379 static const struct const_desc
386 /* PSR constant masks: */
389 {"psr.be", ((valueT) 1) << 1},
390 {"psr.up", ((valueT) 1) << 2},
391 {"psr.ac", ((valueT) 1) << 3},
392 {"psr.mfl", ((valueT) 1) << 4},
393 {"psr.mfh", ((valueT) 1) << 5},
395 {"psr.ic", ((valueT) 1) << 13},
396 {"psr.i", ((valueT) 1) << 14},
397 {"psr.pk", ((valueT) 1) << 15},
399 {"psr.dt", ((valueT) 1) << 17},
400 {"psr.dfl", ((valueT) 1) << 18},
401 {"psr.dfh", ((valueT) 1) << 19},
402 {"psr.sp", ((valueT) 1) << 20},
403 {"psr.pp", ((valueT) 1) << 21},
404 {"psr.di", ((valueT) 1) << 22},
405 {"psr.si", ((valueT) 1) << 23},
406 {"psr.db", ((valueT) 1) << 24},
407 {"psr.lp", ((valueT) 1) << 25},
408 {"psr.tb", ((valueT) 1) << 26},
409 {"psr.rt", ((valueT) 1) << 27},
410 /* 28-31: reserved */
411 /* 32-33: cpl (current privilege level) */
412 {"psr.is", ((valueT) 1) << 34},
413 {"psr.mc", ((valueT) 1) << 35},
414 {"psr.it", ((valueT) 1) << 36},
415 {"psr.id", ((valueT) 1) << 37},
416 {"psr.da", ((valueT) 1) << 38},
417 {"psr.dd", ((valueT) 1) << 39},
418 {"psr.ss", ((valueT) 1) << 40},
419 /* 41-42: ri (restart instruction) */
420 {"psr.ed", ((valueT) 1) << 43},
421 {"psr.bn", ((valueT) 1) << 44},
424 /* indirect register-sets/memory: */
433 { "CPUID", IND_CPUID },
434 { "cpuid", IND_CPUID },
446 /* Pseudo functions used to indicate relocation types (these functions
447 start with an at sign (@). */
469 /* reloc pseudo functions (these must come first!): */
470 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
471 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
472 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
473 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
474 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
475 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
476 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
477 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
478 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
480 /* mbtype4 constants: */
481 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
482 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
483 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
484 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
485 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
487 /* fclass constants: */
488 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
489 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
490 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
491 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
492 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
493 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
494 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
495 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
496 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
498 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
500 /* unwind-related constants: */
501 { "svr4", PSEUDO_FUNC_CONST, { 0 } },
502 { "hpux", PSEUDO_FUNC_CONST, { 1 } },
503 { "nt", PSEUDO_FUNC_CONST, { 2 } },
505 /* unwind-related registers: */
506 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
509 /* 41-bit nop opcodes (one per unit): */
510 static const bfd_vma nop[IA64_NUM_UNITS] =
512 0x0000000000LL, /* NIL => break 0 */
513 0x0008000000LL, /* I-unit nop */
514 0x0008000000LL, /* M-unit nop */
515 0x4000000000LL, /* B-unit nop */
516 0x0008000000LL, /* F-unit nop */
517 0x0008000000LL, /* L-"unit" nop */
518 0x0008000000LL, /* X-unit nop */
521 /* Can't be `const' as it's passed to input routines (which have the
522 habit of setting temporary sentinels. */
523 static char special_section_name[][20] =
525 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
526 {".IA_64.unwind"}, {".IA_64.unwind_info"}
529 /* The best template for a particular sequence of up to three
531 #define N IA64_NUM_TYPES
532 static unsigned char best_template[N][N][N];
535 /* Resource dependencies currently in effect */
537 int depind; /* dependency index */
538 const struct ia64_dependency *dependency; /* actual dependency */
539 unsigned specific:1, /* is this a specific bit/regno? */
540 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
541 int index; /* specific regno/bit within dependency */
542 int note; /* optional qualifying note (0 if none) */
546 int insn_srlz; /* current insn serialization state */
547 int data_srlz; /* current data serialization state */
548 int qp_regno; /* qualifying predicate for this usage */
549 char *file; /* what file marked this dependency */
550 unsigned int line; /* what line marked this dependency */
551 struct mem_offset mem_offset; /* optional memory offset hint */
552 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
553 int path; /* corresponding code entry index */
555 static int regdepslen = 0;
556 static int regdepstotlen = 0;
557 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
558 static const char *dv_sem[] = { "none", "implied", "impliedf",
559 "data", "instr", "specific", "stop", "other" };
560 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
562 /* Current state of PR mutexation */
563 static struct qpmutex {
566 } *qp_mutexes = NULL; /* QP mutex bitmasks */
567 static int qp_mutexeslen = 0;
568 static int qp_mutexestotlen = 0;
569 static valueT qp_safe_across_calls = 0;
571 /* Current state of PR implications */
572 static struct qp_imply {
575 unsigned p2_branched:1;
577 } *qp_implies = NULL;
578 static int qp_implieslen = 0;
579 static int qp_impliestotlen = 0;
581 /* Keep track of static GR values so that indirect register usage can
582 sometimes be tracked. */
587 } gr_values[128] = {{ 1, 0, 0 }};
589 /* These are the routines required to output the various types of
592 /* A slot_number is a frag address plus the slot index (0-2). We use the
593 frag address here so that if there is a section switch in the middle of
594 a function, then instructions emitted to a different section are not
595 counted. Since there may be more than one frag for a function, this
596 means we also need to keep track of which frag this address belongs to
597 so we can compute inter-frag distances. This also nicely solves the
598 problem with nops emitted for align directives, which can't easily be
599 counted, but can easily be derived from frag sizes. */
601 typedef struct unw_rec_list {
603 unsigned long slot_number;
605 struct unw_rec_list *next;
608 #define SLOT_NUM_NOT_SET (unsigned)-1
612 unsigned long next_slot_number;
613 fragS *next_slot_frag;
615 /* Maintain a list of unwind entries for the current function. */
619 /* Any unwind entires that should be attached to the current slot
620 that an insn is being constructed for. */
621 unw_rec_list *current_entry;
623 /* These are used to create the unwind table entry for this function. */
626 symbolS *info; /* pointer to unwind info */
627 symbolS *personality_routine;
629 subsegT saved_text_subseg;
630 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
632 /* TRUE if processing unwind directives in a prologue region. */
635 unsigned int prologue_count; /* number of .prologues seen so far */
638 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
640 /* Forward delarations: */
641 static int ar_is_in_integer_unit PARAMS ((int regnum));
642 static void set_section PARAMS ((char *name));
643 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
644 unsigned int, unsigned int));
645 static void dot_radix PARAMS ((int));
646 static void dot_special_section PARAMS ((int));
647 static void dot_proc PARAMS ((int));
648 static void dot_fframe PARAMS ((int));
649 static void dot_vframe PARAMS ((int));
650 static void dot_vframesp PARAMS ((int));
651 static void dot_vframepsp PARAMS ((int));
652 static void dot_save PARAMS ((int));
653 static void dot_restore PARAMS ((int));
654 static void dot_restorereg PARAMS ((int));
655 static void dot_restorereg_p PARAMS ((int));
656 static void dot_handlerdata PARAMS ((int));
657 static void dot_unwentry PARAMS ((int));
658 static void dot_altrp PARAMS ((int));
659 static void dot_savemem PARAMS ((int));
660 static void dot_saveg PARAMS ((int));
661 static void dot_savef PARAMS ((int));
662 static void dot_saveb PARAMS ((int));
663 static void dot_savegf PARAMS ((int));
664 static void dot_spill PARAMS ((int));
665 static void dot_spillreg PARAMS ((int));
666 static void dot_spillmem PARAMS ((int));
667 static void dot_spillreg_p PARAMS ((int));
668 static void dot_spillmem_p PARAMS ((int));
669 static void dot_label_state PARAMS ((int));
670 static void dot_copy_state PARAMS ((int));
671 static void dot_unwabi PARAMS ((int));
672 static void dot_personality PARAMS ((int));
673 static void dot_body PARAMS ((int));
674 static void dot_prologue PARAMS ((int));
675 static void dot_endp PARAMS ((int));
676 static void dot_template PARAMS ((int));
677 static void dot_regstk PARAMS ((int));
678 static void dot_rot PARAMS ((int));
679 static void dot_byteorder PARAMS ((int));
680 static void dot_psr PARAMS ((int));
681 static void dot_alias PARAMS ((int));
682 static void dot_ln PARAMS ((int));
683 static char *parse_section_name PARAMS ((void));
684 static void dot_xdata PARAMS ((int));
685 static void stmt_float_cons PARAMS ((int));
686 static void stmt_cons_ua PARAMS ((int));
687 static void dot_xfloat_cons PARAMS ((int));
688 static void dot_xstringer PARAMS ((int));
689 static void dot_xdata_ua PARAMS ((int));
690 static void dot_xfloat_cons_ua PARAMS ((int));
691 static void print_prmask PARAMS ((valueT mask));
692 static void dot_pred_rel PARAMS ((int));
693 static void dot_reg_val PARAMS ((int));
694 static void dot_dv_mode PARAMS ((int));
695 static void dot_entry PARAMS ((int));
696 static void dot_mem_offset PARAMS ((int));
697 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
698 static symbolS *declare_register PARAMS ((const char *name, int regnum));
699 static void declare_register_set PARAMS ((const char *, int, int));
700 static unsigned int operand_width PARAMS ((enum ia64_opnd));
701 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
704 static int parse_operand PARAMS ((expressionS *e));
705 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
706 static void build_insn PARAMS ((struct slot *, bfd_vma *));
707 static void emit_one_bundle PARAMS ((void));
708 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
709 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
710 bfd_reloc_code_real_type r_type));
711 static void insn_group_break PARAMS ((int, int, int));
712 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
713 struct rsrc *, int depind, int path));
714 static void add_qp_mutex PARAMS((valueT mask));
715 static void add_qp_imply PARAMS((int p1, int p2));
716 static void clear_qp_branch_flag PARAMS((valueT mask));
717 static void clear_qp_mutex PARAMS((valueT mask));
718 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
719 static void clear_register_values PARAMS ((void));
720 static void print_dependency PARAMS ((const char *action, int depind));
721 static void instruction_serialization PARAMS ((void));
722 static void data_serialization PARAMS ((void));
723 static void remove_marked_resource PARAMS ((struct rsrc *));
724 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
725 static int is_taken_branch PARAMS ((struct ia64_opcode *));
726 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
727 static int depends_on PARAMS ((int, struct ia64_opcode *));
728 static int specify_resource PARAMS ((const struct ia64_dependency *,
729 struct ia64_opcode *, int, struct rsrc [], int, int));
730 static int check_dv PARAMS((struct ia64_opcode *idesc));
731 static void check_dependencies PARAMS((struct ia64_opcode *));
732 static void mark_resources PARAMS((struct ia64_opcode *));
733 static void update_dependencies PARAMS((struct ia64_opcode *));
734 static void note_register_values PARAMS((struct ia64_opcode *));
735 static int qp_mutex PARAMS ((int, int, int));
736 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
737 static void output_vbyte_mem PARAMS ((int, char *, char *));
738 static void count_output PARAMS ((int, char *, char *));
739 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
740 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
741 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
742 static void output_P1_format PARAMS ((vbyte_func, int));
743 static void output_P2_format PARAMS ((vbyte_func, int, int));
744 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
745 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
746 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
747 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
748 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
749 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
750 static void output_P9_format PARAMS ((vbyte_func, int, int));
751 static void output_P10_format PARAMS ((vbyte_func, int, int));
752 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
753 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
754 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
755 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
756 static char format_ab_reg PARAMS ((int, int));
757 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
759 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
760 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
762 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
763 static void free_list_records PARAMS ((unw_rec_list *));
764 static unw_rec_list *output_prologue PARAMS ((void));
765 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
766 static unw_rec_list *output_body PARAMS ((void));
767 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
768 static unw_rec_list *output_mem_stack_v PARAMS ((void));
769 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
770 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
771 static unw_rec_list *output_rp_when PARAMS ((void));
772 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
773 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
774 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
775 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
776 static unw_rec_list *output_pfs_when PARAMS ((void));
777 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
778 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
779 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
780 static unw_rec_list *output_preds_when PARAMS ((void));
781 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
782 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
783 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
784 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
785 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
786 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
787 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
788 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
789 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
790 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
791 static unw_rec_list *output_unat_when PARAMS ((void));
792 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
793 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
794 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
795 static unw_rec_list *output_lc_when PARAMS ((void));
796 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
797 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
798 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
799 static unw_rec_list *output_fpsr_when PARAMS ((void));
800 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
801 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
802 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
803 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
804 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
805 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
806 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
807 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
808 static unw_rec_list *output_bsp_when PARAMS ((void));
809 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
810 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
811 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
812 static unw_rec_list *output_bspstore_when PARAMS ((void));
813 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
814 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
815 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
816 static unw_rec_list *output_rnat_when PARAMS ((void));
817 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
818 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
819 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
820 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
821 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
822 static unw_rec_list *output_label_state PARAMS ((unsigned long));
823 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
824 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
825 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
826 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
828 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
830 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
832 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
833 unsigned int, unsigned int));
834 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
835 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
836 static int calc_record_size PARAMS ((unw_rec_list *));
837 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
838 static int count_bits PARAMS ((unsigned long));
839 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
840 unsigned long, fragS *));
841 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
842 static void fixup_unw_records PARAMS ((unw_rec_list *));
843 static int output_unw_records PARAMS ((unw_rec_list *, void **));
844 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
845 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
846 static int generate_unwind_image PARAMS ((const char *));
848 /* Build the unwind section name by appending the (possibly stripped)
849 text section NAME to the unwind PREFIX. The resulting string
850 pointer is assigned to RESULT. The string is allocated on the
851 stack, so this must be a macro... */
852 #define make_unw_section_name(special, text_name, result) \
854 char *_prefix = special_section_name[special]; \
855 size_t _prefix_len = strlen (_prefix), _text_len = strlen (text_name); \
856 char *_result = alloca (_prefix_len + _text_len + 1); \
857 memcpy(_result, _prefix, _prefix_len); \
858 memcpy(_result + _prefix_len, text_name, _text_len); \
859 _result[_prefix_len + _text_len] = '\0'; \
864 /* Determine if application register REGNUM resides in the integer
865 unit (as opposed to the memory unit). */
867 ar_is_in_integer_unit (reg)
872 return (reg == 64 /* pfs */
873 || reg == 65 /* lc */
874 || reg == 66 /* ec */
875 /* ??? ias accepts and puts these in the integer unit. */
876 || (reg >= 112 && reg <= 127));
879 /* Switch to section NAME and create section if necessary. It's
880 rather ugly that we have to manipulate input_line_pointer but I
881 don't see any other way to accomplish the same thing without
882 changing obj-elf.c (which may be the Right Thing, in the end). */
887 char *saved_input_line_pointer;
889 saved_input_line_pointer = input_line_pointer;
890 input_line_pointer = name;
892 input_line_pointer = saved_input_line_pointer;
895 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
898 ia64_elf_section_flags (flags, attr, type)
900 int attr, type ATTRIBUTE_UNUSED;
902 if (attr & SHF_IA_64_SHORT)
903 flags |= SEC_SMALL_DATA;
908 ia64_elf_section_type (str, len)
912 len = sizeof (ELF_STRING_ia64_unwind_info) - 1;
913 if (strncmp (str, ELF_STRING_ia64_unwind_info, len) == 0)
916 len = sizeof (ELF_STRING_ia64_unwind) - 1;
917 if (strncmp (str, ELF_STRING_ia64_unwind, len) == 0)
918 return SHT_IA_64_UNWIND;
924 set_regstack (ins, locs, outs, rots)
925 unsigned int ins, locs, outs, rots;
930 sof = ins + locs + outs;
933 as_bad ("Size of frame exceeds maximum of 96 registers");
938 as_warn ("Size of rotating registers exceeds frame size");
941 md.in.base = REG_GR + 32;
942 md.loc.base = md.in.base + ins;
943 md.out.base = md.loc.base + locs;
945 md.in.num_regs = ins;
946 md.loc.num_regs = locs;
947 md.out.num_regs = outs;
948 md.rot.num_regs = rots;
955 struct label_fix *lfix;
957 subsegT saved_subseg;
960 if (!md.last_text_seg)
964 saved_subseg = now_subseg;
966 subseg_set (md.last_text_seg, 0);
968 while (md.num_slots_in_use > 0)
969 emit_one_bundle (); /* force out queued instructions */
971 /* In case there are labels following the last instruction, resolve
973 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
975 S_SET_VALUE (lfix->sym, frag_now_fix ());
976 symbol_set_frag (lfix->sym, frag_now);
978 CURR_SLOT.label_fixups = 0;
979 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
981 S_SET_VALUE (lfix->sym, frag_now_fix ());
982 symbol_set_frag (lfix->sym, frag_now);
984 CURR_SLOT.tag_fixups = 0;
986 /* In case there are unwind directives following the last instruction,
987 resolve those now. We only handle body and prologue directives here.
988 Give an error for others. */
989 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
991 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
992 || ptr->r.type == body)
994 ptr->slot_number = (unsigned long) frag_more (0);
995 ptr->slot_frag = frag_now;
998 as_bad (_("Unwind directive not followed by an instruction."));
1000 unwind.current_entry = NULL;
1002 subseg_set (saved_seg, saved_subseg);
1004 if (md.qp.X_op == O_register)
1005 as_bad ("qualifying predicate not followed by instruction");
1009 ia64_do_align (nbytes)
1012 char *saved_input_line_pointer = input_line_pointer;
1014 input_line_pointer = "";
1015 s_align_bytes (nbytes);
1016 input_line_pointer = saved_input_line_pointer;
1020 ia64_cons_align (nbytes)
1025 char *saved_input_line_pointer = input_line_pointer;
1026 input_line_pointer = "";
1027 s_align_bytes (nbytes);
1028 input_line_pointer = saved_input_line_pointer;
1032 /* Output COUNT bytes to a memory location. */
1033 static unsigned char *vbyte_mem_ptr = NULL;
1036 output_vbyte_mem (count, ptr, comment)
1039 char *comment ATTRIBUTE_UNUSED;
1042 if (vbyte_mem_ptr == NULL)
1047 for (x = 0; x < count; x++)
1048 *(vbyte_mem_ptr++) = ptr[x];
1051 /* Count the number of bytes required for records. */
1052 static int vbyte_count = 0;
1054 count_output (count, ptr, comment)
1056 char *ptr ATTRIBUTE_UNUSED;
1057 char *comment ATTRIBUTE_UNUSED;
1059 vbyte_count += count;
1063 output_R1_format (f, rtype, rlen)
1065 unw_record_type rtype;
1072 output_R3_format (f, rtype, rlen);
1078 else if (rtype != prologue)
1079 as_bad ("record type is not valid");
1081 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1082 (*f) (1, &byte, NULL);
1086 output_R2_format (f, mask, grsave, rlen)
1093 mask = (mask & 0x0f);
1094 grsave = (grsave & 0x7f);
1096 bytes[0] = (UNW_R2 | (mask >> 1));
1097 bytes[1] = (((mask & 0x01) << 7) | grsave);
1098 count += output_leb128 (bytes + 2, rlen, 0);
1099 (*f) (count, bytes, NULL);
1103 output_R3_format (f, rtype, rlen)
1105 unw_record_type rtype;
1112 output_R1_format (f, rtype, rlen);
1118 else if (rtype != prologue)
1119 as_bad ("record type is not valid");
1120 bytes[0] = (UNW_R3 | r);
1121 count = output_leb128 (bytes + 1, rlen, 0);
1122 (*f) (count + 1, bytes, NULL);
1126 output_P1_format (f, brmask)
1131 byte = UNW_P1 | (brmask & 0x1f);
1132 (*f) (1, &byte, NULL);
1136 output_P2_format (f, brmask, gr)
1142 brmask = (brmask & 0x1f);
1143 bytes[0] = UNW_P2 | (brmask >> 1);
1144 bytes[1] = (((brmask & 1) << 7) | gr);
1145 (*f) (2, bytes, NULL);
1149 output_P3_format (f, rtype, reg)
1151 unw_record_type rtype;
1196 as_bad ("Invalid record type for P3 format.");
1198 bytes[0] = (UNW_P3 | (r >> 1));
1199 bytes[1] = (((r & 1) << 7) | reg);
1200 (*f) (2, bytes, NULL);
1204 output_P4_format (f, imask, imask_size)
1206 unsigned char *imask;
1207 unsigned long imask_size;
1210 (*f) (imask_size, imask, NULL);
1214 output_P5_format (f, grmask, frmask)
1217 unsigned long frmask;
1220 grmask = (grmask & 0x0f);
1223 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1224 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1225 bytes[3] = (frmask & 0x000000ff);
1226 (*f) (4, bytes, NULL);
1230 output_P6_format (f, rtype, rmask)
1232 unw_record_type rtype;
1238 if (rtype == gr_mem)
1240 else if (rtype != fr_mem)
1241 as_bad ("Invalid record type for format P6");
1242 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1243 (*f) (1, &byte, NULL);
1247 output_P7_format (f, rtype, w1, w2)
1249 unw_record_type rtype;
1256 count += output_leb128 (bytes + 1, w1, 0);
1261 count += output_leb128 (bytes + count, w2 >> 4, 0);
1311 bytes[0] = (UNW_P7 | r);
1312 (*f) (count, bytes, NULL);
1316 output_P8_format (f, rtype, t)
1318 unw_record_type rtype;
1357 case bspstore_psprel:
1360 case bspstore_sprel:
1372 case priunat_when_gr:
1375 case priunat_psprel:
1381 case priunat_when_mem:
1388 count += output_leb128 (bytes + 2, t, 0);
1389 (*f) (count, bytes, NULL);
1393 output_P9_format (f, grmask, gr)
1400 bytes[1] = (grmask & 0x0f);
1401 bytes[2] = (gr & 0x7f);
1402 (*f) (3, bytes, NULL);
1406 output_P10_format (f, abi, context)
1413 bytes[1] = (abi & 0xff);
1414 bytes[2] = (context & 0xff);
1415 (*f) (3, bytes, NULL);
1419 output_B1_format (f, rtype, label)
1421 unw_record_type rtype;
1422 unsigned long label;
1428 output_B4_format (f, rtype, label);
1431 if (rtype == copy_state)
1433 else if (rtype != label_state)
1434 as_bad ("Invalid record type for format B1");
1436 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1437 (*f) (1, &byte, NULL);
1441 output_B2_format (f, ecount, t)
1443 unsigned long ecount;
1450 output_B3_format (f, ecount, t);
1453 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1454 count += output_leb128 (bytes + 1, t, 0);
1455 (*f) (count, bytes, NULL);
1459 output_B3_format (f, ecount, t)
1461 unsigned long ecount;
1468 output_B2_format (f, ecount, t);
1472 count += output_leb128 (bytes + 1, t, 0);
1473 count += output_leb128 (bytes + count, ecount, 0);
1474 (*f) (count, bytes, NULL);
1478 output_B4_format (f, rtype, label)
1480 unw_record_type rtype;
1481 unsigned long label;
1488 output_B1_format (f, rtype, label);
1492 if (rtype == copy_state)
1494 else if (rtype != label_state)
1495 as_bad ("Invalid record type for format B1");
1497 bytes[0] = (UNW_B4 | (r << 3));
1498 count += output_leb128 (bytes + 1, label, 0);
1499 (*f) (count, bytes, NULL);
1503 format_ab_reg (ab, reg)
1510 ret = (ab << 5) | reg;
1515 output_X1_format (f, rtype, ab, reg, t, w1)
1517 unw_record_type rtype;
1527 if (rtype == spill_sprel)
1529 else if (rtype != spill_psprel)
1530 as_bad ("Invalid record type for format X1");
1531 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1532 count += output_leb128 (bytes + 2, t, 0);
1533 count += output_leb128 (bytes + count, w1, 0);
1534 (*f) (count, bytes, NULL);
1538 output_X2_format (f, ab, reg, x, y, treg, t)
1547 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1548 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1549 count += output_leb128 (bytes + 3, t, 0);
1550 (*f) (count, bytes, NULL);
1554 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1556 unw_record_type rtype;
1567 if (rtype == spill_sprel_p)
1569 else if (rtype != spill_psprel_p)
1570 as_bad ("Invalid record type for format X3");
1571 bytes[1] = ((r << 7) | (qp & 0x3f));
1572 bytes[2] = format_ab_reg (ab, reg);
1573 count += output_leb128 (bytes + 3, t, 0);
1574 count += output_leb128 (bytes + count, w1, 0);
1575 (*f) (count, bytes, NULL);
1579 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1589 bytes[1] = (qp & 0x3f);
1590 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1591 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1592 count += output_leb128 (bytes + 4, t, 0);
1593 (*f) (count, bytes, NULL);
1596 /* This function allocates a record list structure, and initializes fields. */
1598 static unw_rec_list *
1599 alloc_record (unw_record_type t)
1602 ptr = xmalloc (sizeof (*ptr));
1604 ptr->slot_number = SLOT_NUM_NOT_SET;
1609 /* This function frees an entire list of record structures. */
1612 free_list_records (unw_rec_list *first)
1615 for (ptr = first; ptr != NULL;)
1617 unw_rec_list *tmp = ptr;
1619 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1620 && tmp->r.record.r.mask.i)
1621 free (tmp->r.record.r.mask.i);
1628 static unw_rec_list *
1631 unw_rec_list *ptr = alloc_record (prologue);
1632 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1636 static unw_rec_list *
1637 output_prologue_gr (saved_mask, reg)
1638 unsigned int saved_mask;
1641 unw_rec_list *ptr = alloc_record (prologue_gr);
1642 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1643 ptr->r.record.r.grmask = saved_mask;
1644 ptr->r.record.r.grsave = reg;
1648 static unw_rec_list *
1651 unw_rec_list *ptr = alloc_record (body);
1655 static unw_rec_list *
1656 output_mem_stack_f (size)
1659 unw_rec_list *ptr = alloc_record (mem_stack_f);
1660 ptr->r.record.p.size = size;
1664 static unw_rec_list *
1665 output_mem_stack_v ()
1667 unw_rec_list *ptr = alloc_record (mem_stack_v);
1671 static unw_rec_list *
1675 unw_rec_list *ptr = alloc_record (psp_gr);
1676 ptr->r.record.p.gr = gr;
1680 static unw_rec_list *
1681 output_psp_sprel (offset)
1682 unsigned int offset;
1684 unw_rec_list *ptr = alloc_record (psp_sprel);
1685 ptr->r.record.p.spoff = offset / 4;
1689 static unw_rec_list *
1692 unw_rec_list *ptr = alloc_record (rp_when);
1696 static unw_rec_list *
1700 unw_rec_list *ptr = alloc_record (rp_gr);
1701 ptr->r.record.p.gr = gr;
1705 static unw_rec_list *
1709 unw_rec_list *ptr = alloc_record (rp_br);
1710 ptr->r.record.p.br = br;
1714 static unw_rec_list *
1715 output_rp_psprel (offset)
1716 unsigned int offset;
1718 unw_rec_list *ptr = alloc_record (rp_psprel);
1719 ptr->r.record.p.pspoff = offset / 4;
1723 static unw_rec_list *
1724 output_rp_sprel (offset)
1725 unsigned int offset;
1727 unw_rec_list *ptr = alloc_record (rp_sprel);
1728 ptr->r.record.p.spoff = offset / 4;
1732 static unw_rec_list *
1735 unw_rec_list *ptr = alloc_record (pfs_when);
1739 static unw_rec_list *
1743 unw_rec_list *ptr = alloc_record (pfs_gr);
1744 ptr->r.record.p.gr = gr;
1748 static unw_rec_list *
1749 output_pfs_psprel (offset)
1750 unsigned int offset;
1752 unw_rec_list *ptr = alloc_record (pfs_psprel);
1753 ptr->r.record.p.pspoff = offset / 4;
1757 static unw_rec_list *
1758 output_pfs_sprel (offset)
1759 unsigned int offset;
1761 unw_rec_list *ptr = alloc_record (pfs_sprel);
1762 ptr->r.record.p.spoff = offset / 4;
1766 static unw_rec_list *
1767 output_preds_when ()
1769 unw_rec_list *ptr = alloc_record (preds_when);
1773 static unw_rec_list *
1774 output_preds_gr (gr)
1777 unw_rec_list *ptr = alloc_record (preds_gr);
1778 ptr->r.record.p.gr = gr;
1782 static unw_rec_list *
1783 output_preds_psprel (offset)
1784 unsigned int offset;
1786 unw_rec_list *ptr = alloc_record (preds_psprel);
1787 ptr->r.record.p.pspoff = offset / 4;
1791 static unw_rec_list *
1792 output_preds_sprel (offset)
1793 unsigned int offset;
1795 unw_rec_list *ptr = alloc_record (preds_sprel);
1796 ptr->r.record.p.spoff = offset / 4;
1800 static unw_rec_list *
1801 output_fr_mem (mask)
1804 unw_rec_list *ptr = alloc_record (fr_mem);
1805 ptr->r.record.p.rmask = mask;
1809 static unw_rec_list *
1810 output_frgr_mem (gr_mask, fr_mask)
1811 unsigned int gr_mask;
1812 unsigned int fr_mask;
1814 unw_rec_list *ptr = alloc_record (frgr_mem);
1815 ptr->r.record.p.grmask = gr_mask;
1816 ptr->r.record.p.frmask = fr_mask;
1820 static unw_rec_list *
1821 output_gr_gr (mask, reg)
1825 unw_rec_list *ptr = alloc_record (gr_gr);
1826 ptr->r.record.p.grmask = mask;
1827 ptr->r.record.p.gr = reg;
1831 static unw_rec_list *
1832 output_gr_mem (mask)
1835 unw_rec_list *ptr = alloc_record (gr_mem);
1836 ptr->r.record.p.rmask = mask;
1840 static unw_rec_list *
1841 output_br_mem (unsigned int mask)
1843 unw_rec_list *ptr = alloc_record (br_mem);
1844 ptr->r.record.p.brmask = mask;
1848 static unw_rec_list *
1849 output_br_gr (save_mask, reg)
1850 unsigned int save_mask;
1853 unw_rec_list *ptr = alloc_record (br_gr);
1854 ptr->r.record.p.brmask = save_mask;
1855 ptr->r.record.p.gr = reg;
1859 static unw_rec_list *
1860 output_spill_base (offset)
1861 unsigned int offset;
1863 unw_rec_list *ptr = alloc_record (spill_base);
1864 ptr->r.record.p.pspoff = offset / 4;
1868 static unw_rec_list *
1871 unw_rec_list *ptr = alloc_record (unat_when);
1875 static unw_rec_list *
1879 unw_rec_list *ptr = alloc_record (unat_gr);
1880 ptr->r.record.p.gr = gr;
1884 static unw_rec_list *
1885 output_unat_psprel (offset)
1886 unsigned int offset;
1888 unw_rec_list *ptr = alloc_record (unat_psprel);
1889 ptr->r.record.p.pspoff = offset / 4;
1893 static unw_rec_list *
1894 output_unat_sprel (offset)
1895 unsigned int offset;
1897 unw_rec_list *ptr = alloc_record (unat_sprel);
1898 ptr->r.record.p.spoff = offset / 4;
1902 static unw_rec_list *
1905 unw_rec_list *ptr = alloc_record (lc_when);
1909 static unw_rec_list *
1913 unw_rec_list *ptr = alloc_record (lc_gr);
1914 ptr->r.record.p.gr = gr;
1918 static unw_rec_list *
1919 output_lc_psprel (offset)
1920 unsigned int offset;
1922 unw_rec_list *ptr = alloc_record (lc_psprel);
1923 ptr->r.record.p.pspoff = offset / 4;
1927 static unw_rec_list *
1928 output_lc_sprel (offset)
1929 unsigned int offset;
1931 unw_rec_list *ptr = alloc_record (lc_sprel);
1932 ptr->r.record.p.spoff = offset / 4;
1936 static unw_rec_list *
1939 unw_rec_list *ptr = alloc_record (fpsr_when);
1943 static unw_rec_list *
1947 unw_rec_list *ptr = alloc_record (fpsr_gr);
1948 ptr->r.record.p.gr = gr;
1952 static unw_rec_list *
1953 output_fpsr_psprel (offset)
1954 unsigned int offset;
1956 unw_rec_list *ptr = alloc_record (fpsr_psprel);
1957 ptr->r.record.p.pspoff = offset / 4;
1961 static unw_rec_list *
1962 output_fpsr_sprel (offset)
1963 unsigned int offset;
1965 unw_rec_list *ptr = alloc_record (fpsr_sprel);
1966 ptr->r.record.p.spoff = offset / 4;
1970 static unw_rec_list *
1971 output_priunat_when_gr ()
1973 unw_rec_list *ptr = alloc_record (priunat_when_gr);
1977 static unw_rec_list *
1978 output_priunat_when_mem ()
1980 unw_rec_list *ptr = alloc_record (priunat_when_mem);
1984 static unw_rec_list *
1985 output_priunat_gr (gr)
1988 unw_rec_list *ptr = alloc_record (priunat_gr);
1989 ptr->r.record.p.gr = gr;
1993 static unw_rec_list *
1994 output_priunat_psprel (offset)
1995 unsigned int offset;
1997 unw_rec_list *ptr = alloc_record (priunat_psprel);
1998 ptr->r.record.p.pspoff = offset / 4;
2002 static unw_rec_list *
2003 output_priunat_sprel (offset)
2004 unsigned int offset;
2006 unw_rec_list *ptr = alloc_record (priunat_sprel);
2007 ptr->r.record.p.spoff = offset / 4;
2011 static unw_rec_list *
2014 unw_rec_list *ptr = alloc_record (bsp_when);
2018 static unw_rec_list *
2022 unw_rec_list *ptr = alloc_record (bsp_gr);
2023 ptr->r.record.p.gr = gr;
2027 static unw_rec_list *
2028 output_bsp_psprel (offset)
2029 unsigned int offset;
2031 unw_rec_list *ptr = alloc_record (bsp_psprel);
2032 ptr->r.record.p.pspoff = offset / 4;
2036 static unw_rec_list *
2037 output_bsp_sprel (offset)
2038 unsigned int offset;
2040 unw_rec_list *ptr = alloc_record (bsp_sprel);
2041 ptr->r.record.p.spoff = offset / 4;
2045 static unw_rec_list *
2046 output_bspstore_when ()
2048 unw_rec_list *ptr = alloc_record (bspstore_when);
2052 static unw_rec_list *
2053 output_bspstore_gr (gr)
2056 unw_rec_list *ptr = alloc_record (bspstore_gr);
2057 ptr->r.record.p.gr = gr;
2061 static unw_rec_list *
2062 output_bspstore_psprel (offset)
2063 unsigned int offset;
2065 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2066 ptr->r.record.p.pspoff = offset / 4;
2070 static unw_rec_list *
2071 output_bspstore_sprel (offset)
2072 unsigned int offset;
2074 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2075 ptr->r.record.p.spoff = offset / 4;
2079 static unw_rec_list *
2082 unw_rec_list *ptr = alloc_record (rnat_when);
2086 static unw_rec_list *
2090 unw_rec_list *ptr = alloc_record (rnat_gr);
2091 ptr->r.record.p.gr = gr;
2095 static unw_rec_list *
2096 output_rnat_psprel (offset)
2097 unsigned int offset;
2099 unw_rec_list *ptr = alloc_record (rnat_psprel);
2100 ptr->r.record.p.pspoff = offset / 4;
2104 static unw_rec_list *
2105 output_rnat_sprel (offset)
2106 unsigned int offset;
2108 unw_rec_list *ptr = alloc_record (rnat_sprel);
2109 ptr->r.record.p.spoff = offset / 4;
2113 static unw_rec_list *
2114 output_unwabi (abi, context)
2116 unsigned long context;
2118 unw_rec_list *ptr = alloc_record (unwabi);
2119 ptr->r.record.p.abi = abi;
2120 ptr->r.record.p.context = context;
2124 static unw_rec_list *
2125 output_epilogue (unsigned long ecount)
2127 unw_rec_list *ptr = alloc_record (epilogue);
2128 ptr->r.record.b.ecount = ecount;
2132 static unw_rec_list *
2133 output_label_state (unsigned long label)
2135 unw_rec_list *ptr = alloc_record (label_state);
2136 ptr->r.record.b.label = label;
2140 static unw_rec_list *
2141 output_copy_state (unsigned long label)
2143 unw_rec_list *ptr = alloc_record (copy_state);
2144 ptr->r.record.b.label = label;
2148 static unw_rec_list *
2149 output_spill_psprel (ab, reg, offset)
2152 unsigned int offset;
2154 unw_rec_list *ptr = alloc_record (spill_psprel);
2155 ptr->r.record.x.ab = ab;
2156 ptr->r.record.x.reg = reg;
2157 ptr->r.record.x.pspoff = offset / 4;
2161 static unw_rec_list *
2162 output_spill_sprel (ab, reg, offset)
2165 unsigned int offset;
2167 unw_rec_list *ptr = alloc_record (spill_sprel);
2168 ptr->r.record.x.ab = ab;
2169 ptr->r.record.x.reg = reg;
2170 ptr->r.record.x.spoff = offset / 4;
2174 static unw_rec_list *
2175 output_spill_psprel_p (ab, reg, offset, predicate)
2178 unsigned int offset;
2179 unsigned int predicate;
2181 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2182 ptr->r.record.x.ab = ab;
2183 ptr->r.record.x.reg = reg;
2184 ptr->r.record.x.pspoff = offset / 4;
2185 ptr->r.record.x.qp = predicate;
2189 static unw_rec_list *
2190 output_spill_sprel_p (ab, reg, offset, predicate)
2193 unsigned int offset;
2194 unsigned int predicate;
2196 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2197 ptr->r.record.x.ab = ab;
2198 ptr->r.record.x.reg = reg;
2199 ptr->r.record.x.spoff = offset / 4;
2200 ptr->r.record.x.qp = predicate;
2204 static unw_rec_list *
2205 output_spill_reg (ab, reg, targ_reg, xy)
2208 unsigned int targ_reg;
2211 unw_rec_list *ptr = alloc_record (spill_reg);
2212 ptr->r.record.x.ab = ab;
2213 ptr->r.record.x.reg = reg;
2214 ptr->r.record.x.treg = targ_reg;
2215 ptr->r.record.x.xy = xy;
2219 static unw_rec_list *
2220 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2223 unsigned int targ_reg;
2225 unsigned int predicate;
2227 unw_rec_list *ptr = alloc_record (spill_reg_p);
2228 ptr->r.record.x.ab = ab;
2229 ptr->r.record.x.reg = reg;
2230 ptr->r.record.x.treg = targ_reg;
2231 ptr->r.record.x.xy = xy;
2232 ptr->r.record.x.qp = predicate;
2236 /* Given a unw_rec_list process the correct format with the
2237 specified function. */
2240 process_one_record (ptr, f)
2244 unsigned long fr_mask, gr_mask;
2246 switch (ptr->r.type)
2252 /* These are taken care of by prologue/prologue_gr. */
2257 if (ptr->r.type == prologue_gr)
2258 output_R2_format (f, ptr->r.record.r.grmask,
2259 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2261 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2263 /* Output descriptor(s) for union of register spills (if any). */
2264 gr_mask = ptr->r.record.r.mask.gr_mem;
2265 fr_mask = ptr->r.record.r.mask.fr_mem;
2268 if ((fr_mask & ~0xfUL) == 0)
2269 output_P6_format (f, fr_mem, fr_mask);
2272 output_P5_format (f, gr_mask, fr_mask);
2277 output_P6_format (f, gr_mem, gr_mask);
2278 if (ptr->r.record.r.mask.br_mem)
2279 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2281 /* output imask descriptor if necessary: */
2282 if (ptr->r.record.r.mask.i)
2283 output_P4_format (f, ptr->r.record.r.mask.i,
2284 ptr->r.record.r.imask_size);
2288 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2292 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2293 ptr->r.record.p.size);
2306 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2309 output_P3_format (f, rp_br, ptr->r.record.p.br);
2312 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2320 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2329 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2339 case bspstore_sprel:
2341 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2344 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2347 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2350 as_bad ("spill_mask record unimplemented.");
2352 case priunat_when_gr:
2353 case priunat_when_mem:
2357 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2359 case priunat_psprel:
2361 case bspstore_psprel:
2363 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2366 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2369 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2373 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2376 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2377 ptr->r.record.x.reg, ptr->r.record.x.t,
2378 ptr->r.record.x.pspoff);
2381 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2382 ptr->r.record.x.reg, ptr->r.record.x.t,
2383 ptr->r.record.x.spoff);
2386 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2387 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2388 ptr->r.record.x.treg, ptr->r.record.x.t);
2390 case spill_psprel_p:
2391 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2392 ptr->r.record.x.ab, ptr->r.record.x.reg,
2393 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2396 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2397 ptr->r.record.x.ab, ptr->r.record.x.reg,
2398 ptr->r.record.x.t, ptr->r.record.x.spoff);
2401 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2402 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2403 ptr->r.record.x.xy, ptr->r.record.x.treg,
2407 as_bad ("record_type_not_valid");
2412 /* Given a unw_rec_list list, process all the records with
2413 the specified function. */
2415 process_unw_records (list, f)
2420 for (ptr = list; ptr; ptr = ptr->next)
2421 process_one_record (ptr, f);
2424 /* Determine the size of a record list in bytes. */
2426 calc_record_size (list)
2430 process_unw_records (list, count_output);
2434 /* Update IMASK bitmask to reflect the fact that one or more registers
2435 of type TYPE are saved starting at instruction with index T. If N
2436 bits are set in REGMASK, it is assumed that instructions T through
2437 T+N-1 save these registers.
2441 1: instruction saves next fp reg
2442 2: instruction saves next general reg
2443 3: instruction saves next branch reg */
2445 set_imask (region, regmask, t, type)
2446 unw_rec_list *region;
2447 unsigned long regmask;
2451 unsigned char *imask;
2452 unsigned long imask_size;
2456 imask = region->r.record.r.mask.i;
2457 imask_size = region->r.record.r.imask_size;
2460 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2461 imask = xmalloc (imask_size);
2462 memset (imask, 0, imask_size);
2464 region->r.record.r.imask_size = imask_size;
2465 region->r.record.r.mask.i = imask;
2469 pos = 2 * (3 - t % 4);
2472 if (i >= imask_size)
2474 as_bad ("Ignoring attempt to spill beyond end of region");
2478 imask[i] |= (type & 0x3) << pos;
2480 regmask &= (regmask - 1);
2491 count_bits (unsigned long mask)
2503 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2504 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2505 containing FIRST_ADDR. */
2508 slot_index (slot_addr, slot_frag, first_addr, first_frag)
2509 unsigned long slot_addr;
2511 unsigned long first_addr;
2514 unsigned long index = 0;
2516 /* First time we are called, the initial address and frag are invalid. */
2517 if (first_addr == 0)
2520 /* If the two addresses are in different frags, then we need to add in
2521 the remaining size of this frag, and then the entire size of intermediate
2523 while (slot_frag != first_frag)
2525 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2527 /* Add in the full size of the frag converted to instruction slots. */
2528 index += 3 * (first_frag->fr_fix >> 4);
2529 /* Subtract away the initial part before first_addr. */
2530 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2531 + ((first_addr & 0x3) - (start_addr & 0x3)));
2533 /* Move to the beginning of the next frag. */
2534 first_frag = first_frag->fr_next;
2535 first_addr = (unsigned long) &first_frag->fr_literal;
2538 /* Add in the used part of the last frag. */
2539 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2540 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2544 /* Optimize unwind record directives. */
2546 static unw_rec_list *
2547 optimize_unw_records (list)
2553 /* If the only unwind record is ".prologue" or ".prologue" followed
2554 by ".body", then we can optimize the unwind directives away. */
2555 if (list->r.type == prologue
2556 && (list->next == NULL
2557 || (list->next->r.type == body && list->next->next == NULL)))
2563 /* Given a complete record list, process any records which have
2564 unresolved fields, (ie length counts for a prologue). After
2565 this has been run, all neccessary information should be available
2566 within each record to generate an image. */
2569 fixup_unw_records (list)
2572 unw_rec_list *ptr, *region = 0;
2573 unsigned long first_addr = 0, rlen = 0, t;
2574 fragS *first_frag = 0;
2576 for (ptr = list; ptr; ptr = ptr->next)
2578 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2579 as_bad (" Insn slot not set in unwind record.");
2580 t = slot_index (ptr->slot_number, ptr->slot_frag,
2581 first_addr, first_frag);
2582 switch (ptr->r.type)
2589 int size, dir_len = 0;
2590 unsigned long last_addr;
2593 first_addr = ptr->slot_number;
2594 first_frag = ptr->slot_frag;
2595 ptr->slot_number = 0;
2596 /* Find either the next body/prologue start, or the end of
2597 the list, and determine the size of the region. */
2598 last_addr = unwind.next_slot_number;
2599 last_frag = unwind.next_slot_frag;
2600 for (last = ptr->next; last != NULL; last = last->next)
2601 if (last->r.type == prologue || last->r.type == prologue_gr
2602 || last->r.type == body)
2604 last_addr = last->slot_number;
2605 last_frag = last->slot_frag;
2608 else if (!last->next)
2610 /* In the absence of an explicit .body directive,
2611 the prologue ends after the last instruction
2612 covered by an unwind directive. */
2613 if (ptr->r.type != body)
2615 last_addr = last->slot_number;
2616 last_frag = last->slot_frag;
2617 switch (last->r.type)
2620 dir_len = (count_bits (last->r.record.p.frmask)
2621 + count_bits (last->r.record.p.grmask));
2625 dir_len += count_bits (last->r.record.p.rmask);
2629 dir_len += count_bits (last->r.record.p.brmask);
2632 dir_len += count_bits (last->r.record.p.grmask);
2641 size = (slot_index (last_addr, last_frag, first_addr, first_frag)
2643 rlen = ptr->r.record.r.rlen = size;
2648 ptr->r.record.b.t = rlen - 1 - t;
2659 case priunat_when_gr:
2660 case priunat_when_mem:
2664 ptr->r.record.p.t = t;
2672 case spill_psprel_p:
2673 ptr->r.record.x.t = t;
2679 as_bad ("frgr_mem record before region record!\n");
2682 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2683 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2684 set_imask (region, ptr->r.record.p.frmask, t, 1);
2685 set_imask (region, ptr->r.record.p.grmask, t, 2);
2690 as_bad ("fr_mem record before region record!\n");
2693 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2694 set_imask (region, ptr->r.record.p.rmask, t, 1);
2699 as_bad ("gr_mem record before region record!\n");
2702 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2703 set_imask (region, ptr->r.record.p.rmask, t, 2);
2708 as_bad ("br_mem record before region record!\n");
2711 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2712 set_imask (region, ptr->r.record.p.brmask, t, 3);
2718 as_bad ("gr_gr record before region record!\n");
2721 set_imask (region, ptr->r.record.p.grmask, t, 2);
2726 as_bad ("br_gr record before region record!\n");
2729 set_imask (region, ptr->r.record.p.brmask, t, 3);
2738 /* Generate an unwind image from a record list. Returns the number of
2739 bytes in the resulting image. The memory image itselof is returned
2740 in the 'ptr' parameter. */
2742 output_unw_records (list, ptr)
2746 int size, x, extra = 0;
2751 list = optimize_unw_records (list);
2752 fixup_unw_records (list);
2753 size = calc_record_size (list);
2755 /* pad to 8 byte boundry. */
2760 if (size > 0 || unwind.force_unwind_entry)
2762 unwind.force_unwind_entry = 0;
2764 /* Add 8 for the header + 8 more bytes for the personality offset. */
2765 mem = xmalloc (size + extra + 16);
2767 vbyte_mem_ptr = mem + 8;
2768 /* Clear the padding area and personality. */
2769 memset (mem + 8 + size, 0 , extra + 8);
2770 /* Initialize the header area. */
2771 md_number_to_chars (mem,
2772 (((bfd_vma) 1 << 48) /* version */
2773 | (unwind.personality_routine
2774 ? ((bfd_vma) 3 << 32) /* U & E handler flags */
2776 | ((size + extra) / 8)), /* length (dwords) */
2779 process_unw_records (list, output_vbyte_mem);
2789 convert_expr_to_ab_reg (e, ab, regp)
2796 if (e->X_op != O_register)
2799 reg = e->X_add_number;
2800 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2803 *regp = reg - REG_GR;
2805 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2806 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2809 *regp = reg - REG_FR;
2811 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2814 *regp = reg - REG_BR;
2821 case REG_PR: *regp = 0; break;
2822 case REG_PSP: *regp = 1; break;
2823 case REG_PRIUNAT: *regp = 2; break;
2824 case REG_BR + 0: *regp = 3; break;
2825 case REG_AR + AR_BSP: *regp = 4; break;
2826 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2827 case REG_AR + AR_RNAT: *regp = 6; break;
2828 case REG_AR + AR_UNAT: *regp = 7; break;
2829 case REG_AR + AR_FPSR: *regp = 8; break;
2830 case REG_AR + AR_PFS: *regp = 9; break;
2831 case REG_AR + AR_LC: *regp = 10; break;
2841 convert_expr_to_xy_reg (e, xy, regp)
2848 if (e->X_op != O_register)
2851 reg = e->X_add_number;
2853 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2856 *regp = reg - REG_GR;
2858 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2861 *regp = reg - REG_FR;
2863 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2866 *regp = reg - REG_BR;
2875 int dummy ATTRIBUTE_UNUSED;
2880 radix = *input_line_pointer++;
2882 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
2884 as_bad ("Radix `%c' unsupported", *input_line_pointer);
2885 ignore_rest_of_line ();
2890 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
2892 dot_special_section (which)
2895 set_section ((char *) special_section_name[which]);
2899 add_unwind_entry (ptr)
2903 unwind.tail->next = ptr;
2908 /* The current entry can in fact be a chain of unwind entries. */
2909 if (unwind.current_entry == NULL)
2910 unwind.current_entry = ptr;
2915 int dummy ATTRIBUTE_UNUSED;
2921 if (e.X_op != O_constant)
2922 as_bad ("Operand to .fframe must be a constant");
2924 add_unwind_entry (output_mem_stack_f (e.X_add_number));
2929 int dummy ATTRIBUTE_UNUSED;
2935 reg = e.X_add_number - REG_GR;
2936 if (e.X_op == O_register && reg < 128)
2938 add_unwind_entry (output_mem_stack_v ());
2939 if (! (unwind.prologue_mask & 2))
2940 add_unwind_entry (output_psp_gr (reg));
2943 as_bad ("First operand to .vframe must be a general register");
2947 dot_vframesp (dummy)
2948 int dummy ATTRIBUTE_UNUSED;
2953 if (e.X_op == O_constant)
2955 add_unwind_entry (output_mem_stack_v ());
2956 add_unwind_entry (output_psp_sprel (e.X_add_number));
2959 as_bad ("First operand to .vframesp must be a general register");
2963 dot_vframepsp (dummy)
2964 int dummy ATTRIBUTE_UNUSED;
2969 if (e.X_op == O_constant)
2971 add_unwind_entry (output_mem_stack_v ());
2972 add_unwind_entry (output_psp_sprel (e.X_add_number));
2975 as_bad ("First operand to .vframepsp must be a general register");
2980 int dummy ATTRIBUTE_UNUSED;
2986 sep = parse_operand (&e1);
2988 as_bad ("No second operand to .save");
2989 sep = parse_operand (&e2);
2991 reg1 = e1.X_add_number;
2992 reg2 = e2.X_add_number - REG_GR;
2994 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
2995 if (e1.X_op == O_register)
2997 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3001 case REG_AR + AR_BSP:
3002 add_unwind_entry (output_bsp_when ());
3003 add_unwind_entry (output_bsp_gr (reg2));
3005 case REG_AR + AR_BSPSTORE:
3006 add_unwind_entry (output_bspstore_when ());
3007 add_unwind_entry (output_bspstore_gr (reg2));
3009 case REG_AR + AR_RNAT:
3010 add_unwind_entry (output_rnat_when ());
3011 add_unwind_entry (output_rnat_gr (reg2));
3013 case REG_AR + AR_UNAT:
3014 add_unwind_entry (output_unat_when ());
3015 add_unwind_entry (output_unat_gr (reg2));
3017 case REG_AR + AR_FPSR:
3018 add_unwind_entry (output_fpsr_when ());
3019 add_unwind_entry (output_fpsr_gr (reg2));
3021 case REG_AR + AR_PFS:
3022 add_unwind_entry (output_pfs_when ());
3023 if (! (unwind.prologue_mask & 4))
3024 add_unwind_entry (output_pfs_gr (reg2));
3026 case REG_AR + AR_LC:
3027 add_unwind_entry (output_lc_when ());
3028 add_unwind_entry (output_lc_gr (reg2));
3031 add_unwind_entry (output_rp_when ());
3032 if (! (unwind.prologue_mask & 8))
3033 add_unwind_entry (output_rp_gr (reg2));
3036 add_unwind_entry (output_preds_when ());
3037 if (! (unwind.prologue_mask & 1))
3038 add_unwind_entry (output_preds_gr (reg2));
3041 add_unwind_entry (output_priunat_when_gr ());
3042 add_unwind_entry (output_priunat_gr (reg2));
3045 as_bad ("First operand not a valid register");
3049 as_bad (" Second operand not a valid register");
3052 as_bad ("First operand not a register");
3057 int dummy ATTRIBUTE_UNUSED;
3060 unsigned long ecount; /* # of _additional_ regions to pop */
3063 sep = parse_operand (&e1);
3064 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3066 as_bad ("First operand to .restore must be stack pointer (sp)");
3072 parse_operand (&e2);
3073 if (e2.X_op != O_constant || e2.X_add_number < 0)
3075 as_bad ("Second operand to .restore must be a constant >= 0");
3078 ecount = e2.X_add_number;
3081 ecount = unwind.prologue_count - 1;
3082 add_unwind_entry (output_epilogue (ecount));
3084 if (ecount < unwind.prologue_count)
3085 unwind.prologue_count -= ecount + 1;
3087 unwind.prologue_count = 0;
3091 dot_restorereg (dummy)
3092 int dummy ATTRIBUTE_UNUSED;
3094 unsigned int ab, reg;
3099 if (!convert_expr_to_ab_reg (&e, &ab, ®))
3101 as_bad ("First operand to .restorereg must be a preserved register");
3104 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3108 dot_restorereg_p (dummy)
3109 int dummy ATTRIBUTE_UNUSED;
3111 unsigned int qp, ab, reg;
3115 sep = parse_operand (&e1);
3118 as_bad ("No second operand to .restorereg.p");
3122 parse_operand (&e2);
3124 qp = e1.X_add_number - REG_P;
3125 if (e1.X_op != O_register || qp > 63)
3127 as_bad ("First operand to .restorereg.p must be a predicate");
3131 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3133 as_bad ("Second operand to .restorereg.p must be a preserved register");
3136 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3140 generate_unwind_image (text_name)
3141 const char *text_name;
3144 unsigned char *unw_rec;
3146 /* Force out pending instructions, to make sure all unwind records have
3147 a valid slot_number field. */
3148 ia64_flush_insns ();
3150 /* Generate the unwind record. */
3151 size = output_unw_records (unwind.list, (void **) &unw_rec);
3153 as_bad ("Unwind record is not a multiple of 8 bytes.");
3155 /* If there are unwind records, switch sections, and output the info. */
3158 unsigned char *where;
3162 make_unw_section_name (SPECIAL_SECTION_UNWIND_INFO, text_name, sec_name);
3163 set_section (sec_name);
3164 bfd_set_section_flags (stdoutput, now_seg,
3165 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3167 /* Make sure the section has 8 byte alignment. */
3168 frag_align (3, 0, 0);
3169 record_alignment (now_seg, 3);
3171 /* Set expression which points to start of unwind descriptor area. */
3172 unwind.info = expr_build_dot ();
3174 where = (unsigned char *) frag_more (size);
3176 /* Issue a label for this address, and keep track of it to put it
3177 in the unwind section. */
3179 /* Copy the information from the unwind record into this section. The
3180 data is already in the correct byte order. */
3181 memcpy (where, unw_rec, size);
3183 /* Add the personality address to the image. */
3184 if (unwind.personality_routine != 0)
3186 exp.X_op = O_symbol;
3187 exp.X_add_symbol = unwind.personality_routine;
3188 exp.X_add_number = 0;
3189 fix_new_exp (frag_now, frag_now_fix () - 8, 8,
3190 &exp, 0, BFD_RELOC_IA64_LTOFF_FPTR64LSB);
3191 unwind.personality_routine = 0;
3195 free_list_records (unwind.list);
3196 unwind.list = unwind.tail = unwind.current_entry = NULL;
3202 dot_handlerdata (dummy)
3203 int dummy ATTRIBUTE_UNUSED;
3205 const char *text_name = segment_name (now_seg);
3207 /* If text section name starts with ".text" (which it should),
3208 strip this prefix off. */
3209 if (strcmp (text_name, ".text") == 0)
3212 unwind.force_unwind_entry = 1;
3214 /* Remember which segment we're in so we can switch back after .endp */
3215 unwind.saved_text_seg = now_seg;
3216 unwind.saved_text_subseg = now_subseg;
3218 /* Generate unwind info into unwind-info section and then leave that
3219 section as the currently active one so dataXX directives go into
3220 the language specific data area of the unwind info block. */
3221 generate_unwind_image (text_name);
3222 demand_empty_rest_of_line ();
3226 dot_unwentry (dummy)
3227 int dummy ATTRIBUTE_UNUSED;
3229 unwind.force_unwind_entry = 1;
3230 demand_empty_rest_of_line ();
3235 int dummy ATTRIBUTE_UNUSED;
3241 reg = e.X_add_number - REG_BR;
3242 if (e.X_op == O_register && reg < 8)
3243 add_unwind_entry (output_rp_br (reg));
3245 as_bad ("First operand not a valid branch register");
3249 dot_savemem (psprel)
3256 sep = parse_operand (&e1);
3258 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3259 sep = parse_operand (&e2);
3261 reg1 = e1.X_add_number;
3262 val = e2.X_add_number;
3264 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3265 if (e1.X_op == O_register)
3267 if (e2.X_op == O_constant)
3271 case REG_AR + AR_BSP:
3272 add_unwind_entry (output_bsp_when ());
3273 add_unwind_entry ((psprel
3275 : output_bsp_sprel) (val));
3277 case REG_AR + AR_BSPSTORE:
3278 add_unwind_entry (output_bspstore_when ());
3279 add_unwind_entry ((psprel
3280 ? output_bspstore_psprel
3281 : output_bspstore_sprel) (val));
3283 case REG_AR + AR_RNAT:
3284 add_unwind_entry (output_rnat_when ());
3285 add_unwind_entry ((psprel
3286 ? output_rnat_psprel
3287 : output_rnat_sprel) (val));
3289 case REG_AR + AR_UNAT:
3290 add_unwind_entry (output_unat_when ());
3291 add_unwind_entry ((psprel
3292 ? output_unat_psprel
3293 : output_unat_sprel) (val));
3295 case REG_AR + AR_FPSR:
3296 add_unwind_entry (output_fpsr_when ());
3297 add_unwind_entry ((psprel
3298 ? output_fpsr_psprel
3299 : output_fpsr_sprel) (val));
3301 case REG_AR + AR_PFS:
3302 add_unwind_entry (output_pfs_when ());
3303 add_unwind_entry ((psprel
3305 : output_pfs_sprel) (val));
3307 case REG_AR + AR_LC:
3308 add_unwind_entry (output_lc_when ());
3309 add_unwind_entry ((psprel
3311 : output_lc_sprel) (val));
3314 add_unwind_entry (output_rp_when ());
3315 add_unwind_entry ((psprel
3317 : output_rp_sprel) (val));
3320 add_unwind_entry (output_preds_when ());
3321 add_unwind_entry ((psprel
3322 ? output_preds_psprel
3323 : output_preds_sprel) (val));
3326 add_unwind_entry (output_priunat_when_mem ());
3327 add_unwind_entry ((psprel
3328 ? output_priunat_psprel
3329 : output_priunat_sprel) (val));
3332 as_bad ("First operand not a valid register");
3336 as_bad (" Second operand not a valid constant");
3339 as_bad ("First operand not a register");
3344 int dummy ATTRIBUTE_UNUSED;
3348 sep = parse_operand (&e1);
3350 parse_operand (&e2);
3352 if (e1.X_op != O_constant)
3353 as_bad ("First operand to .save.g must be a constant.");
3356 int grmask = e1.X_add_number;
3358 add_unwind_entry (output_gr_mem (grmask));
3361 int reg = e2.X_add_number - REG_GR;
3362 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3363 add_unwind_entry (output_gr_gr (grmask, reg));
3365 as_bad ("Second operand is an invalid register.");
3372 int dummy ATTRIBUTE_UNUSED;
3376 sep = parse_operand (&e1);
3378 if (e1.X_op != O_constant)
3379 as_bad ("Operand to .save.f must be a constant.");
3381 add_unwind_entry (output_fr_mem (e1.X_add_number));
3386 int dummy ATTRIBUTE_UNUSED;
3393 sep = parse_operand (&e1);
3394 if (e1.X_op != O_constant)
3396 as_bad ("First operand to .save.b must be a constant.");
3399 brmask = e1.X_add_number;
3403 sep = parse_operand (&e2);
3404 reg = e2.X_add_number - REG_GR;
3405 if (e2.X_op != O_register || reg > 127)
3407 as_bad ("Second operand to .save.b must be a general register.");
3410 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3413 add_unwind_entry (output_br_mem (brmask));
3415 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3416 ignore_rest_of_line ();
3421 int dummy ATTRIBUTE_UNUSED;
3425 sep = parse_operand (&e1);
3427 parse_operand (&e2);
3429 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3430 as_bad ("Both operands of .save.gf must be constants.");
3433 int grmask = e1.X_add_number;
3434 int frmask = e2.X_add_number;
3435 add_unwind_entry (output_frgr_mem (grmask, frmask));
3441 int dummy ATTRIBUTE_UNUSED;
3446 sep = parse_operand (&e);
3447 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3448 ignore_rest_of_line ();
3450 if (e.X_op != O_constant)
3451 as_bad ("Operand to .spill must be a constant");
3453 add_unwind_entry (output_spill_base (e.X_add_number));
3457 dot_spillreg (dummy)
3458 int dummy ATTRIBUTE_UNUSED;
3460 int sep, ab, xy, reg, treg;
3463 sep = parse_operand (&e1);
3466 as_bad ("No second operand to .spillreg");
3470 parse_operand (&e2);
3472 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3474 as_bad ("First operand to .spillreg must be a preserved register");
3478 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3480 as_bad ("Second operand to .spillreg must be a register");
3484 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3488 dot_spillmem (psprel)
3494 sep = parse_operand (&e1);
3497 as_bad ("Second operand missing");
3501 parse_operand (&e2);
3503 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3505 as_bad ("First operand to .spill%s must be a preserved register",
3506 psprel ? "psp" : "sp");
3510 if (e2.X_op != O_constant)
3512 as_bad ("Second operand to .spill%s must be a constant",
3513 psprel ? "psp" : "sp");
3518 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3520 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3524 dot_spillreg_p (dummy)
3525 int dummy ATTRIBUTE_UNUSED;
3527 int sep, ab, xy, reg, treg;
3528 expressionS e1, e2, e3;
3531 sep = parse_operand (&e1);
3534 as_bad ("No second and third operand to .spillreg.p");
3538 sep = parse_operand (&e2);
3541 as_bad ("No third operand to .spillreg.p");
3545 parse_operand (&e3);
3547 qp = e1.X_add_number - REG_P;
3549 if (e1.X_op != O_register || qp > 63)
3551 as_bad ("First operand to .spillreg.p must be a predicate");
3555 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3557 as_bad ("Second operand to .spillreg.p must be a preserved register");
3561 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3563 as_bad ("Third operand to .spillreg.p must be a register");
3567 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3571 dot_spillmem_p (psprel)
3574 expressionS e1, e2, e3;
3578 sep = parse_operand (&e1);
3581 as_bad ("Second operand missing");
3585 parse_operand (&e2);
3588 as_bad ("Second operand missing");
3592 parse_operand (&e3);
3594 qp = e1.X_add_number - REG_P;
3595 if (e1.X_op != O_register || qp > 63)
3597 as_bad ("First operand to .spill%s_p must be a predicate",
3598 psprel ? "psp" : "sp");
3602 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3604 as_bad ("Second operand to .spill%s_p must be a preserved register",
3605 psprel ? "psp" : "sp");
3609 if (e3.X_op != O_constant)
3611 as_bad ("Third operand to .spill%s_p must be a constant",
3612 psprel ? "psp" : "sp");
3617 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3619 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3623 dot_label_state (dummy)
3624 int dummy ATTRIBUTE_UNUSED;
3629 if (e.X_op != O_constant)
3631 as_bad ("Operand to .label_state must be a constant");
3634 add_unwind_entry (output_label_state (e.X_add_number));
3638 dot_copy_state (dummy)
3639 int dummy ATTRIBUTE_UNUSED;
3644 if (e.X_op != O_constant)
3646 as_bad ("Operand to .copy_state must be a constant");
3649 add_unwind_entry (output_copy_state (e.X_add_number));
3654 int dummy ATTRIBUTE_UNUSED;
3659 sep = parse_operand (&e1);
3662 as_bad ("Second operand to .unwabi missing");
3665 sep = parse_operand (&e2);
3666 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3667 ignore_rest_of_line ();
3669 if (e1.X_op != O_constant)
3671 as_bad ("First operand to .unwabi must be a constant");
3675 if (e2.X_op != O_constant)
3677 as_bad ("Second operand to .unwabi must be a constant");
3681 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3685 dot_personality (dummy)
3686 int dummy ATTRIBUTE_UNUSED;
3690 name = input_line_pointer;
3691 c = get_symbol_end ();
3692 p = input_line_pointer;
3693 unwind.personality_routine = symbol_find_or_make (name);
3694 unwind.force_unwind_entry = 1;
3697 demand_empty_rest_of_line ();
3702 int dummy ATTRIBUTE_UNUSED;
3707 unwind.proc_start = expr_build_dot ();
3708 /* Parse names of main and alternate entry points and mark them as
3709 function symbols: */
3713 name = input_line_pointer;
3714 c = get_symbol_end ();
3715 p = input_line_pointer;
3716 sym = symbol_find_or_make (name);
3717 if (unwind.proc_start == 0)
3719 unwind.proc_start = sym;
3721 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3724 if (*input_line_pointer != ',')
3726 ++input_line_pointer;
3728 demand_empty_rest_of_line ();
3731 unwind.prologue_count = 0;
3732 unwind.list = unwind.tail = unwind.current_entry = NULL;
3733 unwind.personality_routine = 0;
3738 int dummy ATTRIBUTE_UNUSED;
3740 unwind.prologue = 0;
3741 unwind.prologue_mask = 0;
3743 add_unwind_entry (output_body ());
3744 demand_empty_rest_of_line ();
3748 dot_prologue (dummy)
3749 int dummy ATTRIBUTE_UNUSED;
3752 int mask = 0, grsave = 0;
3754 if (!is_it_end_of_statement ())
3757 sep = parse_operand (&e1);
3759 as_bad ("No second operand to .prologue");
3760 sep = parse_operand (&e2);
3761 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3762 ignore_rest_of_line ();
3764 if (e1.X_op == O_constant)
3766 mask = e1.X_add_number;
3768 if (e2.X_op == O_constant)
3769 grsave = e2.X_add_number;
3770 else if (e2.X_op == O_register
3771 && (grsave = e2.X_add_number - REG_GR) < 128)
3774 as_bad ("Second operand not a constant or general register");
3776 add_unwind_entry (output_prologue_gr (mask, grsave));
3779 as_bad ("First operand not a constant");
3782 add_unwind_entry (output_prologue ());
3784 unwind.prologue = 1;
3785 unwind.prologue_mask = mask;
3786 ++unwind.prologue_count;
3791 int dummy ATTRIBUTE_UNUSED;
3795 int bytes_per_address;
3798 subsegT saved_subseg;
3799 const char *sec_name, *text_name;
3801 if (unwind.saved_text_seg)
3803 saved_seg = unwind.saved_text_seg;
3804 saved_subseg = unwind.saved_text_subseg;
3805 unwind.saved_text_seg = NULL;
3809 saved_seg = now_seg;
3810 saved_subseg = now_subseg;
3814 Use a slightly ugly scheme to derive the unwind section names from
3815 the text section name:
3817 text sect. unwind table sect.
3818 name: name: comments:
3819 ---------- ----------------- --------------------------------
3821 .text.foo .IA_64.unwind.text.foo
3822 .foo .IA_64.unwind.foo
3823 _info .IA_64.unwind_info gas issues error message (ditto)
3824 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3826 This mapping is done so that:
3828 (a) An object file with unwind info only in .text will use
3829 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3830 This follows the letter of the ABI and also ensures backwards
3831 compatibility with older toolchains.
3833 (b) An object file with unwind info in multiple text sections
3834 will use separate unwind sections for each text section.
3835 This allows us to properly set the "sh_info" and "sh_link"
3836 fields in SHT_IA_64_UNWIND as required by the ABI and also
3837 lets GNU ld support programs with multiple segments
3838 containing unwind info (as might be the case for certain
3839 embedded applications).
3841 (c) An error is issued if there would be a name clash.
3843 text_name = segment_name (saved_seg);
3844 if (strncmp (text_name, "_info", 5) == 0)
3846 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3848 ignore_rest_of_line ();
3851 if (strcmp (text_name, ".text") == 0)
3855 demand_empty_rest_of_line ();
3857 insn_group_break (1, 0, 0);
3859 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
3861 generate_unwind_image (text_name);
3863 if (unwind.info || unwind.force_unwind_entry)
3865 subseg_set (md.last_text_seg, 0);
3866 unwind.proc_end = expr_build_dot ();
3868 make_unw_section_name (SPECIAL_SECTION_UNWIND, text_name, sec_name);
3869 set_section ((char *) sec_name);
3870 bfd_set_section_flags (stdoutput, now_seg,
3871 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3873 /* Make sure the section has 8 byte alignment. */
3874 record_alignment (now_seg, 3);
3876 ptr = frag_more (24);
3877 where = frag_now_fix () - 24;
3878 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
3880 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
3881 e.X_op = O_pseudo_fixup;
3882 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3884 e.X_add_symbol = unwind.proc_start;
3885 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
3887 e.X_op = O_pseudo_fixup;
3888 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3890 e.X_add_symbol = unwind.proc_end;
3891 ia64_cons_fix_new (frag_now, where + bytes_per_address,
3892 bytes_per_address, &e);
3896 e.X_op = O_pseudo_fixup;
3897 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3899 e.X_add_symbol = unwind.info;
3900 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
3901 bytes_per_address, &e);
3904 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
3908 subseg_set (saved_seg, saved_subseg);
3909 unwind.proc_start = unwind.proc_end = unwind.info = 0;
3913 dot_template (template)
3916 CURR_SLOT.user_template = template;
3921 int dummy ATTRIBUTE_UNUSED;
3923 int ins, locs, outs, rots;
3925 if (is_it_end_of_statement ())
3926 ins = locs = outs = rots = 0;
3929 ins = get_absolute_expression ();
3930 if (*input_line_pointer++ != ',')
3932 locs = get_absolute_expression ();
3933 if (*input_line_pointer++ != ',')
3935 outs = get_absolute_expression ();
3936 if (*input_line_pointer++ != ',')
3938 rots = get_absolute_expression ();
3940 set_regstack (ins, locs, outs, rots);
3944 as_bad ("Comma expected");
3945 ignore_rest_of_line ();
3952 unsigned num_regs, num_alloced = 0;
3953 struct dynreg **drpp, *dr;
3954 int ch, base_reg = 0;
3960 case DYNREG_GR: base_reg = REG_GR + 32; break;
3961 case DYNREG_FR: base_reg = REG_FR + 32; break;
3962 case DYNREG_PR: base_reg = REG_P + 16; break;
3966 /* First, remove existing names from hash table. */
3967 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
3969 hash_delete (md.dynreg_hash, dr->name);
3973 drpp = &md.dynreg[type];
3976 start = input_line_pointer;
3977 ch = get_symbol_end ();
3978 *input_line_pointer = ch;
3979 len = (input_line_pointer - start);
3982 if (*input_line_pointer != '[')
3984 as_bad ("Expected '['");
3987 ++input_line_pointer; /* skip '[' */
3989 num_regs = get_absolute_expression ();
3991 if (*input_line_pointer++ != ']')
3993 as_bad ("Expected ']'");
3998 num_alloced += num_regs;
4002 if (num_alloced > md.rot.num_regs)
4004 as_bad ("Used more than the declared %d rotating registers",
4010 if (num_alloced > 96)
4012 as_bad ("Used more than the available 96 rotating registers");
4017 if (num_alloced > 48)
4019 as_bad ("Used more than the available 48 rotating registers");
4028 name = obstack_alloc (¬es, len + 1);
4029 memcpy (name, start, len);
4034 *drpp = obstack_alloc (¬es, sizeof (*dr));
4035 memset (*drpp, 0, sizeof (*dr));
4040 dr->num_regs = num_regs;
4041 dr->base = base_reg;
4043 base_reg += num_regs;
4045 if (hash_insert (md.dynreg_hash, name, dr))
4047 as_bad ("Attempt to redefine register set `%s'", name);
4051 if (*input_line_pointer != ',')
4053 ++input_line_pointer; /* skip comma */
4056 demand_empty_rest_of_line ();
4060 ignore_rest_of_line ();
4064 dot_byteorder (byteorder)
4067 target_big_endian = byteorder;
4072 int dummy ATTRIBUTE_UNUSED;
4079 option = input_line_pointer;
4080 ch = get_symbol_end ();
4081 if (strcmp (option, "lsb") == 0)
4082 md.flags &= ~EF_IA_64_BE;
4083 else if (strcmp (option, "msb") == 0)
4084 md.flags |= EF_IA_64_BE;
4085 else if (strcmp (option, "abi32") == 0)
4086 md.flags &= ~EF_IA_64_ABI64;
4087 else if (strcmp (option, "abi64") == 0)
4088 md.flags |= EF_IA_64_ABI64;
4090 as_bad ("Unknown psr option `%s'", option);
4091 *input_line_pointer = ch;
4094 if (*input_line_pointer != ',')
4097 ++input_line_pointer;
4100 demand_empty_rest_of_line ();
4105 int dummy ATTRIBUTE_UNUSED;
4107 as_bad (".alias not implemented yet");
4112 int dummy ATTRIBUTE_UNUSED;
4114 new_logical_line (0, get_absolute_expression ());
4115 demand_empty_rest_of_line ();
4119 parse_section_name ()
4125 if (*input_line_pointer != '"')
4127 as_bad ("Missing section name");
4128 ignore_rest_of_line ();
4131 name = demand_copy_C_string (&len);
4134 ignore_rest_of_line ();
4138 if (*input_line_pointer != ',')
4140 as_bad ("Comma expected after section name");
4141 ignore_rest_of_line ();
4144 ++input_line_pointer; /* skip comma */
4152 char *name = parse_section_name ();
4156 md.keep_pending_output = 1;
4159 obj_elf_previous (0);
4160 md.keep_pending_output = 0;
4163 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4166 stmt_float_cons (kind)
4173 case 'd': size = 8; break;
4174 case 'x': size = 10; break;
4181 ia64_do_align (size);
4189 int saved_auto_align = md.auto_align;
4193 md.auto_align = saved_auto_align;
4197 dot_xfloat_cons (kind)
4200 char *name = parse_section_name ();
4204 md.keep_pending_output = 1;
4206 stmt_float_cons (kind);
4207 obj_elf_previous (0);
4208 md.keep_pending_output = 0;
4212 dot_xstringer (zero)
4215 char *name = parse_section_name ();
4219 md.keep_pending_output = 1;
4222 obj_elf_previous (0);
4223 md.keep_pending_output = 0;
4230 int saved_auto_align = md.auto_align;
4231 char *name = parse_section_name ();
4235 md.keep_pending_output = 1;
4239 md.auto_align = saved_auto_align;
4240 obj_elf_previous (0);
4241 md.keep_pending_output = 0;
4245 dot_xfloat_cons_ua (kind)
4248 int saved_auto_align = md.auto_align;
4249 char *name = parse_section_name ();
4253 md.keep_pending_output = 1;
4256 stmt_float_cons (kind);
4257 md.auto_align = saved_auto_align;
4258 obj_elf_previous (0);
4259 md.keep_pending_output = 0;
4262 /* .reg.val <regname>,value */
4266 int dummy ATTRIBUTE_UNUSED;
4271 if (reg.X_op != O_register)
4273 as_bad (_("Register name expected"));
4274 ignore_rest_of_line ();
4276 else if (*input_line_pointer++ != ',')
4278 as_bad (_("Comma expected"));
4279 ignore_rest_of_line ();
4283 valueT value = get_absolute_expression ();
4284 int regno = reg.X_add_number;
4285 if (regno < REG_GR || regno > REG_GR + 128)
4286 as_warn (_("Register value annotation ignored"));
4289 gr_values[regno - REG_GR].known = 1;
4290 gr_values[regno - REG_GR].value = value;
4291 gr_values[regno - REG_GR].path = md.path;
4294 demand_empty_rest_of_line ();
4297 /* select dv checking mode
4302 A stop is inserted when changing modes
4309 if (md.manual_bundling)
4310 as_warn (_("Directive invalid within a bundle"));
4312 if (type == 'E' || type == 'A')
4313 md.mode_explicitly_set = 0;
4315 md.mode_explicitly_set = 1;
4322 if (md.explicit_mode)
4323 insn_group_break (1, 0, 0);
4324 md.explicit_mode = 0;
4328 if (!md.explicit_mode)
4329 insn_group_break (1, 0, 0);
4330 md.explicit_mode = 1;
4334 if (md.explicit_mode != md.default_explicit_mode)
4335 insn_group_break (1, 0, 0);
4336 md.explicit_mode = md.default_explicit_mode;
4337 md.mode_explicitly_set = 0;
4348 for (regno = 0; regno < 64; regno++)
4350 if (mask & ((valueT) 1 << regno))
4352 fprintf (stderr, "%s p%d", comma, regno);
4359 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4360 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4361 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4362 .pred.safe_across_calls p1 [, p2 [,...]]
4371 int p1 = -1, p2 = -1;
4375 if (*input_line_pointer != '"')
4377 as_bad (_("Missing predicate relation type"));
4378 ignore_rest_of_line ();
4384 char *form = demand_copy_C_string (&len);
4385 if (strcmp (form, "mutex") == 0)
4387 else if (strcmp (form, "clear") == 0)
4389 else if (strcmp (form, "imply") == 0)
4393 as_bad (_("Unrecognized predicate relation type"));
4394 ignore_rest_of_line ();
4398 if (*input_line_pointer == ',')
4399 ++input_line_pointer;
4409 if (toupper (*input_line_pointer) != 'P'
4410 || (regno = atoi (++input_line_pointer)) < 0
4413 as_bad (_("Predicate register expected"));
4414 ignore_rest_of_line ();
4417 while (isdigit (*input_line_pointer))
4418 ++input_line_pointer;
4425 as_warn (_("Duplicate predicate register ignored"));
4428 /* See if it's a range. */
4429 if (*input_line_pointer == '-')
4432 ++input_line_pointer;
4434 if (toupper (*input_line_pointer) != 'P'
4435 || (regno = atoi (++input_line_pointer)) < 0
4438 as_bad (_("Predicate register expected"));
4439 ignore_rest_of_line ();
4442 while (isdigit (*input_line_pointer))
4443 ++input_line_pointer;
4447 as_bad (_("Bad register range"));
4448 ignore_rest_of_line ();
4459 if (*input_line_pointer != ',')
4461 ++input_line_pointer;
4470 clear_qp_mutex (mask);
4471 clear_qp_implies (mask, (valueT) 0);
4474 if (count != 2 || p1 == -1 || p2 == -1)
4475 as_bad (_("Predicate source and target required"));
4476 else if (p1 == 0 || p2 == 0)
4477 as_bad (_("Use of p0 is not valid in this context"));
4479 add_qp_imply (p1, p2);
4484 as_bad (_("At least two PR arguments expected"));
4489 as_bad (_("Use of p0 is not valid in this context"));
4492 add_qp_mutex (mask);
4495 /* note that we don't override any existing relations */
4498 as_bad (_("At least one PR argument expected"));
4503 fprintf (stderr, "Safe across calls: ");
4504 print_prmask (mask);
4505 fprintf (stderr, "\n");
4507 qp_safe_across_calls = mask;
4510 demand_empty_rest_of_line ();
4513 /* .entry label [, label [, ...]]
4514 Hint to DV code that the given labels are to be considered entry points.
4515 Otherwise, only global labels are considered entry points. */
4519 int dummy ATTRIBUTE_UNUSED;
4528 name = input_line_pointer;
4529 c = get_symbol_end ();
4530 symbolP = symbol_find_or_make (name);
4532 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4534 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4537 *input_line_pointer = c;
4539 c = *input_line_pointer;
4542 input_line_pointer++;
4544 if (*input_line_pointer == '\n')
4550 demand_empty_rest_of_line ();
4553 /* .mem.offset offset, base
4554 "base" is used to distinguish between offsets from a different base. */
4557 dot_mem_offset (dummy)
4558 int dummy ATTRIBUTE_UNUSED;
4560 md.mem_offset.hint = 1;
4561 md.mem_offset.offset = get_absolute_expression ();
4562 if (*input_line_pointer != ',')
4564 as_bad (_("Comma expected"));
4565 ignore_rest_of_line ();
4568 ++input_line_pointer;
4569 md.mem_offset.base = get_absolute_expression ();
4570 demand_empty_rest_of_line ();
4573 /* ia64-specific pseudo-ops: */
4574 const pseudo_typeS md_pseudo_table[] =
4576 { "radix", dot_radix, 0 },
4577 { "lcomm", s_lcomm_bytes, 1 },
4578 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4579 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4580 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4581 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4582 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4583 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4584 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4585 { "proc", dot_proc, 0 },
4586 { "body", dot_body, 0 },
4587 { "prologue", dot_prologue, 0 },
4588 { "endp", dot_endp, 0 },
4589 { "file", dwarf2_directive_file, 0 },
4590 { "loc", dwarf2_directive_loc, 0 },
4592 { "fframe", dot_fframe, 0 },
4593 { "vframe", dot_vframe, 0 },
4594 { "vframesp", dot_vframesp, 0 },
4595 { "vframepsp", dot_vframepsp, 0 },
4596 { "save", dot_save, 0 },
4597 { "restore", dot_restore, 0 },
4598 { "restorereg", dot_restorereg, 0 },
4599 { "restorereg.p", dot_restorereg_p, 0 },
4600 { "handlerdata", dot_handlerdata, 0 },
4601 { "unwentry", dot_unwentry, 0 },
4602 { "altrp", dot_altrp, 0 },
4603 { "savesp", dot_savemem, 0 },
4604 { "savepsp", dot_savemem, 1 },
4605 { "save.g", dot_saveg, 0 },
4606 { "save.f", dot_savef, 0 },
4607 { "save.b", dot_saveb, 0 },
4608 { "save.gf", dot_savegf, 0 },
4609 { "spill", dot_spill, 0 },
4610 { "spillreg", dot_spillreg, 0 },
4611 { "spillsp", dot_spillmem, 0 },
4612 { "spillpsp", dot_spillmem, 1 },
4613 { "spillreg.p", dot_spillreg_p, 0 },
4614 { "spillsp.p", dot_spillmem_p, 0 },
4615 { "spillpsp.p", dot_spillmem_p, 1 },
4616 { "label_state", dot_label_state, 0 },
4617 { "copy_state", dot_copy_state, 0 },
4618 { "unwabi", dot_unwabi, 0 },
4619 { "personality", dot_personality, 0 },
4621 { "estate", dot_estate, 0 },
4623 { "mii", dot_template, 0x0 },
4624 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4625 { "mlx", dot_template, 0x2 },
4626 { "mmi", dot_template, 0x4 },
4627 { "mfi", dot_template, 0x6 },
4628 { "mmf", dot_template, 0x7 },
4629 { "mib", dot_template, 0x8 },
4630 { "mbb", dot_template, 0x9 },
4631 { "bbb", dot_template, 0xb },
4632 { "mmb", dot_template, 0xc },
4633 { "mfb", dot_template, 0xe },
4635 { "lb", dot_scope, 0 },
4636 { "le", dot_scope, 1 },
4638 { "align", s_align_bytes, 0 },
4639 { "regstk", dot_regstk, 0 },
4640 { "rotr", dot_rot, DYNREG_GR },
4641 { "rotf", dot_rot, DYNREG_FR },
4642 { "rotp", dot_rot, DYNREG_PR },
4643 { "lsb", dot_byteorder, 0 },
4644 { "msb", dot_byteorder, 1 },
4645 { "psr", dot_psr, 0 },
4646 { "alias", dot_alias, 0 },
4647 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4649 { "xdata1", dot_xdata, 1 },
4650 { "xdata2", dot_xdata, 2 },
4651 { "xdata4", dot_xdata, 4 },
4652 { "xdata8", dot_xdata, 8 },
4653 { "xreal4", dot_xfloat_cons, 'f' },
4654 { "xreal8", dot_xfloat_cons, 'd' },
4655 { "xreal10", dot_xfloat_cons, 'x' },
4656 { "xstring", dot_xstringer, 0 },
4657 { "xstringz", dot_xstringer, 1 },
4659 /* unaligned versions: */
4660 { "xdata2.ua", dot_xdata_ua, 2 },
4661 { "xdata4.ua", dot_xdata_ua, 4 },
4662 { "xdata8.ua", dot_xdata_ua, 8 },
4663 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4664 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4665 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4667 /* annotations/DV checking support */
4668 { "entry", dot_entry, 0 },
4669 { "mem.offset", dot_mem_offset, 0 },
4670 { "pred.rel", dot_pred_rel, 0 },
4671 { "pred.rel.clear", dot_pred_rel, 'c' },
4672 { "pred.rel.imply", dot_pred_rel, 'i' },
4673 { "pred.rel.mutex", dot_pred_rel, 'm' },
4674 { "pred.safe_across_calls", dot_pred_rel, 's' },
4675 { "reg.val", dot_reg_val, 0 },
4676 { "auto", dot_dv_mode, 'a' },
4677 { "explicit", dot_dv_mode, 'e' },
4678 { "default", dot_dv_mode, 'd' },
4683 static const struct pseudo_opcode
4686 void (*handler) (int);
4691 /* these are more like pseudo-ops, but don't start with a dot */
4692 { "data1", cons, 1 },
4693 { "data2", cons, 2 },
4694 { "data4", cons, 4 },
4695 { "data8", cons, 8 },
4696 { "real4", stmt_float_cons, 'f' },
4697 { "real8", stmt_float_cons, 'd' },
4698 { "real10", stmt_float_cons, 'x' },
4699 { "string", stringer, 0 },
4700 { "stringz", stringer, 1 },
4702 /* unaligned versions: */
4703 { "data2.ua", stmt_cons_ua, 2 },
4704 { "data4.ua", stmt_cons_ua, 4 },
4705 { "data8.ua", stmt_cons_ua, 8 },
4706 { "real4.ua", float_cons, 'f' },
4707 { "real8.ua", float_cons, 'd' },
4708 { "real10.ua", float_cons, 'x' },
4711 /* Declare a register by creating a symbol for it and entering it in
4712 the symbol table. */
4715 declare_register (name, regnum)
4722 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
4724 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
4726 as_fatal ("Inserting \"%s\" into register table failed: %s",
4733 declare_register_set (prefix, num_regs, base_regnum)
4741 for (i = 0; i < num_regs; ++i)
4743 sprintf (name, "%s%u", prefix, i);
4744 declare_register (name, base_regnum + i);
4749 operand_width (opnd)
4750 enum ia64_opnd opnd;
4752 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
4753 unsigned int bits = 0;
4757 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
4758 bits += odesc->field[i].bits;
4763 static enum operand_match_result
4764 operand_match (idesc, index, e)
4765 const struct ia64_opcode *idesc;
4769 enum ia64_opnd opnd = idesc->operands[index];
4770 int bits, relocatable = 0;
4771 struct insn_fix *fix;
4778 case IA64_OPND_AR_CCV:
4779 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
4780 return OPERAND_MATCH;
4783 case IA64_OPND_AR_PFS:
4784 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
4785 return OPERAND_MATCH;
4789 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
4790 return OPERAND_MATCH;
4794 if (e->X_op == O_register && e->X_add_number == REG_IP)
4795 return OPERAND_MATCH;
4799 if (e->X_op == O_register && e->X_add_number == REG_PR)
4800 return OPERAND_MATCH;
4803 case IA64_OPND_PR_ROT:
4804 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
4805 return OPERAND_MATCH;
4809 if (e->X_op == O_register && e->X_add_number == REG_PSR)
4810 return OPERAND_MATCH;
4813 case IA64_OPND_PSR_L:
4814 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
4815 return OPERAND_MATCH;
4818 case IA64_OPND_PSR_UM:
4819 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
4820 return OPERAND_MATCH;
4824 if (e->X_op == O_constant)
4826 if (e->X_add_number == 1)
4827 return OPERAND_MATCH;
4829 return OPERAND_OUT_OF_RANGE;
4834 if (e->X_op == O_constant)
4836 if (e->X_add_number == 8)
4837 return OPERAND_MATCH;
4839 return OPERAND_OUT_OF_RANGE;
4844 if (e->X_op == O_constant)
4846 if (e->X_add_number == 16)
4847 return OPERAND_MATCH;
4849 return OPERAND_OUT_OF_RANGE;
4853 /* register operands: */
4856 if (e->X_op == O_register && e->X_add_number >= REG_AR
4857 && e->X_add_number < REG_AR + 128)
4858 return OPERAND_MATCH;
4863 if (e->X_op == O_register && e->X_add_number >= REG_BR
4864 && e->X_add_number < REG_BR + 8)
4865 return OPERAND_MATCH;
4869 if (e->X_op == O_register && e->X_add_number >= REG_CR
4870 && e->X_add_number < REG_CR + 128)
4871 return OPERAND_MATCH;
4878 if (e->X_op == O_register && e->X_add_number >= REG_FR
4879 && e->X_add_number < REG_FR + 128)
4880 return OPERAND_MATCH;
4885 if (e->X_op == O_register && e->X_add_number >= REG_P
4886 && e->X_add_number < REG_P + 64)
4887 return OPERAND_MATCH;
4893 if (e->X_op == O_register && e->X_add_number >= REG_GR
4894 && e->X_add_number < REG_GR + 128)
4895 return OPERAND_MATCH;
4898 case IA64_OPND_R3_2:
4899 if (e->X_op == O_register && e->X_add_number >= REG_GR)
4901 if (e->X_add_number < REG_GR + 4)
4902 return OPERAND_MATCH;
4903 else if (e->X_add_number < REG_GR + 128)
4904 return OPERAND_OUT_OF_RANGE;
4908 /* indirect operands: */
4909 case IA64_OPND_CPUID_R3:
4910 case IA64_OPND_DBR_R3:
4911 case IA64_OPND_DTR_R3:
4912 case IA64_OPND_ITR_R3:
4913 case IA64_OPND_IBR_R3:
4914 case IA64_OPND_MSR_R3:
4915 case IA64_OPND_PKR_R3:
4916 case IA64_OPND_PMC_R3:
4917 case IA64_OPND_PMD_R3:
4918 case IA64_OPND_RR_R3:
4919 if (e->X_op == O_index && e->X_op_symbol
4920 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
4921 == opnd - IA64_OPND_CPUID_R3))
4922 return OPERAND_MATCH;
4926 if (e->X_op == O_index && !e->X_op_symbol)
4927 return OPERAND_MATCH;
4930 /* immediate operands: */
4931 case IA64_OPND_CNT2a:
4932 case IA64_OPND_LEN4:
4933 case IA64_OPND_LEN6:
4934 bits = operand_width (idesc->operands[index]);
4935 if (e->X_op == O_constant)
4937 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
4938 return OPERAND_MATCH;
4940 return OPERAND_OUT_OF_RANGE;
4944 case IA64_OPND_CNT2b:
4945 if (e->X_op == O_constant)
4947 if ((bfd_vma) (e->X_add_number - 1) < 3)
4948 return OPERAND_MATCH;
4950 return OPERAND_OUT_OF_RANGE;
4954 case IA64_OPND_CNT2c:
4955 val = e->X_add_number;
4956 if (e->X_op == O_constant)
4958 if ((val == 0 || val == 7 || val == 15 || val == 16))
4959 return OPERAND_MATCH;
4961 return OPERAND_OUT_OF_RANGE;
4966 /* SOR must be an integer multiple of 8 */
4967 if (e->X_op == O_constant && e->X_add_number & 0x7)
4968 return OPERAND_OUT_OF_RANGE;
4971 if (e->X_op == O_constant)
4973 if ((bfd_vma) e->X_add_number <= 96)
4974 return OPERAND_MATCH;
4976 return OPERAND_OUT_OF_RANGE;
4980 case IA64_OPND_IMMU62:
4981 if (e->X_op == O_constant)
4983 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
4984 return OPERAND_MATCH;
4986 return OPERAND_OUT_OF_RANGE;
4990 /* FIXME -- need 62-bit relocation type */
4991 as_bad (_("62-bit relocation not yet implemented"));
4995 case IA64_OPND_IMMU64:
4996 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
4997 || e->X_op == O_subtract)
4999 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5000 fix->code = BFD_RELOC_IA64_IMM64;
5001 if (e->X_op != O_subtract)
5003 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5004 if (e->X_op == O_pseudo_fixup)
5008 fix->opnd = idesc->operands[index];
5011 ++CURR_SLOT.num_fixups;
5012 return OPERAND_MATCH;
5014 else if (e->X_op == O_constant)
5015 return OPERAND_MATCH;
5018 case IA64_OPND_CCNT5:
5019 case IA64_OPND_CNT5:
5020 case IA64_OPND_CNT6:
5021 case IA64_OPND_CPOS6a:
5022 case IA64_OPND_CPOS6b:
5023 case IA64_OPND_CPOS6c:
5024 case IA64_OPND_IMMU2:
5025 case IA64_OPND_IMMU7a:
5026 case IA64_OPND_IMMU7b:
5027 case IA64_OPND_IMMU21:
5028 case IA64_OPND_IMMU24:
5029 case IA64_OPND_MBTYPE4:
5030 case IA64_OPND_MHTYPE8:
5031 case IA64_OPND_POS6:
5032 bits = operand_width (idesc->operands[index]);
5033 if (e->X_op == O_constant)
5035 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5036 return OPERAND_MATCH;
5038 return OPERAND_OUT_OF_RANGE;
5042 case IA64_OPND_IMMU9:
5043 bits = operand_width (idesc->operands[index]);
5044 if (e->X_op == O_constant)
5046 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5048 int lobits = e->X_add_number & 0x3;
5049 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5050 e->X_add_number |= (bfd_vma) 0x3;
5051 return OPERAND_MATCH;
5054 return OPERAND_OUT_OF_RANGE;
5058 case IA64_OPND_IMM44:
5059 /* least 16 bits must be zero */
5060 if ((e->X_add_number & 0xffff) != 0)
5061 /* XXX technically, this is wrong: we should not be issuing warning
5062 messages until we're sure this instruction pattern is going to
5064 as_warn (_("lower 16 bits of mask ignored"));
5066 if (e->X_op == O_constant)
5068 if (((e->X_add_number >= 0
5069 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5070 || (e->X_add_number < 0
5071 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5074 if (e->X_add_number >= 0
5075 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5077 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5079 return OPERAND_MATCH;
5082 return OPERAND_OUT_OF_RANGE;
5086 case IA64_OPND_IMM17:
5087 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5088 if (e->X_op == O_constant)
5090 if (((e->X_add_number >= 0
5091 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5092 || (e->X_add_number < 0
5093 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5096 if (e->X_add_number >= 0
5097 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5099 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5101 return OPERAND_MATCH;
5104 return OPERAND_OUT_OF_RANGE;
5108 case IA64_OPND_IMM14:
5109 case IA64_OPND_IMM22:
5111 case IA64_OPND_IMM1:
5112 case IA64_OPND_IMM8:
5113 case IA64_OPND_IMM8U4:
5114 case IA64_OPND_IMM8M1:
5115 case IA64_OPND_IMM8M1U4:
5116 case IA64_OPND_IMM8M1U8:
5117 case IA64_OPND_IMM9a:
5118 case IA64_OPND_IMM9b:
5119 bits = operand_width (idesc->operands[index]);
5120 if (relocatable && (e->X_op == O_symbol
5121 || e->X_op == O_subtract
5122 || e->X_op == O_pseudo_fixup))
5124 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5126 if (idesc->operands[index] == IA64_OPND_IMM14)
5127 fix->code = BFD_RELOC_IA64_IMM14;
5129 fix->code = BFD_RELOC_IA64_IMM22;
5131 if (e->X_op != O_subtract)
5133 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5134 if (e->X_op == O_pseudo_fixup)
5138 fix->opnd = idesc->operands[index];
5141 ++CURR_SLOT.num_fixups;
5142 return OPERAND_MATCH;
5144 else if (e->X_op != O_constant
5145 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5146 return OPERAND_MISMATCH;
5148 if (opnd == IA64_OPND_IMM8M1U4)
5150 /* Zero is not valid for unsigned compares that take an adjusted
5151 constant immediate range. */
5152 if (e->X_add_number == 0)
5153 return OPERAND_OUT_OF_RANGE;
5155 /* Sign-extend 32-bit unsigned numbers, so that the following range
5156 checks will work. */
5157 val = e->X_add_number;
5158 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5159 && ((val & ((bfd_vma) 1 << 31)) != 0))
5160 val = ((val << 32) >> 32);
5162 /* Check for 0x100000000. This is valid because
5163 0x100000000-1 is the same as ((uint32_t) -1). */
5164 if (val == ((bfd_signed_vma) 1 << 32))
5165 return OPERAND_MATCH;
5169 else if (opnd == IA64_OPND_IMM8M1U8)
5171 /* Zero is not valid for unsigned compares that take an adjusted
5172 constant immediate range. */
5173 if (e->X_add_number == 0)
5174 return OPERAND_OUT_OF_RANGE;
5176 /* Check for 0x10000000000000000. */
5177 if (e->X_op == O_big)
5179 if (generic_bignum[0] == 0
5180 && generic_bignum[1] == 0
5181 && generic_bignum[2] == 0
5182 && generic_bignum[3] == 0
5183 && generic_bignum[4] == 1)
5184 return OPERAND_MATCH;
5186 return OPERAND_OUT_OF_RANGE;
5189 val = e->X_add_number - 1;
5191 else if (opnd == IA64_OPND_IMM8M1)
5192 val = e->X_add_number - 1;
5193 else if (opnd == IA64_OPND_IMM8U4)
5195 /* Sign-extend 32-bit unsigned numbers, so that the following range
5196 checks will work. */
5197 val = e->X_add_number;
5198 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5199 && ((val & ((bfd_vma) 1 << 31)) != 0))
5200 val = ((val << 32) >> 32);
5203 val = e->X_add_number;
5205 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5206 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5207 return OPERAND_MATCH;
5209 return OPERAND_OUT_OF_RANGE;
5211 case IA64_OPND_INC3:
5212 /* +/- 1, 4, 8, 16 */
5213 val = e->X_add_number;
5216 if (e->X_op == O_constant)
5218 if ((val == 1 || val == 4 || val == 8 || val == 16))
5219 return OPERAND_MATCH;
5221 return OPERAND_OUT_OF_RANGE;
5225 case IA64_OPND_TGT25:
5226 case IA64_OPND_TGT25b:
5227 case IA64_OPND_TGT25c:
5228 case IA64_OPND_TGT64:
5229 if (e->X_op == O_symbol)
5231 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5232 if (opnd == IA64_OPND_TGT25)
5233 fix->code = BFD_RELOC_IA64_PCREL21F;
5234 else if (opnd == IA64_OPND_TGT25b)
5235 fix->code = BFD_RELOC_IA64_PCREL21M;
5236 else if (opnd == IA64_OPND_TGT25c)
5237 fix->code = BFD_RELOC_IA64_PCREL21B;
5238 else if (opnd == IA64_OPND_TGT64)
5239 fix->code = BFD_RELOC_IA64_PCREL60B;
5243 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5244 fix->opnd = idesc->operands[index];
5247 ++CURR_SLOT.num_fixups;
5248 return OPERAND_MATCH;
5250 case IA64_OPND_TAG13:
5251 case IA64_OPND_TAG13b:
5255 return OPERAND_MATCH;
5258 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5259 /* There are no external relocs for TAG13/TAG13b fields, so we
5260 create a dummy reloc. This will not live past md_apply_fix3. */
5261 fix->code = BFD_RELOC_UNUSED;
5262 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5263 fix->opnd = idesc->operands[index];
5266 ++CURR_SLOT.num_fixups;
5267 return OPERAND_MATCH;
5277 return OPERAND_MISMATCH;
5286 memset (e, 0, sizeof (*e));
5289 if (*input_line_pointer != '}')
5291 sep = *input_line_pointer++;
5295 if (!md.manual_bundling)
5296 as_warn ("Found '}' when manual bundling is off");
5298 CURR_SLOT.manual_bundling_off = 1;
5299 md.manual_bundling = 0;
5305 /* Returns the next entry in the opcode table that matches the one in
5306 IDESC, and frees the entry in IDESC. If no matching entry is
5307 found, NULL is returned instead. */
5309 static struct ia64_opcode *
5310 get_next_opcode (struct ia64_opcode *idesc)
5312 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5313 ia64_free_opcode (idesc);
5317 /* Parse the operands for the opcode and find the opcode variant that
5318 matches the specified operands, or NULL if no match is possible. */
5320 static struct ia64_opcode *
5321 parse_operands (idesc)
5322 struct ia64_opcode *idesc;
5324 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5325 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5326 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5327 enum operand_match_result result;
5329 char *first_arg = 0, *end, *saved_input_pointer;
5332 assert (strlen (idesc->name) <= 128);
5334 strcpy (mnemonic, idesc->name);
5335 if (idesc->operands[2] == IA64_OPND_SOF)
5337 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5338 can't parse the first operand until we have parsed the
5339 remaining operands of the "alloc" instruction. */
5341 first_arg = input_line_pointer;
5342 end = strchr (input_line_pointer, '=');
5345 as_bad ("Expected separator `='");
5348 input_line_pointer = end + 1;
5353 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5355 sep = parse_operand (CURR_SLOT.opnd + i);
5356 if (CURR_SLOT.opnd[i].X_op == O_absent)
5361 if (sep != '=' && sep != ',')
5366 if (num_outputs > 0)
5367 as_bad ("Duplicate equal sign (=) in instruction");
5369 num_outputs = i + 1;
5374 as_bad ("Illegal operand separator `%c'", sep);
5378 if (idesc->operands[2] == IA64_OPND_SOF)
5380 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5381 know (strcmp (idesc->name, "alloc") == 0);
5382 if (num_operands == 5 /* first_arg not included in this count! */
5383 && CURR_SLOT.opnd[2].X_op == O_constant
5384 && CURR_SLOT.opnd[3].X_op == O_constant
5385 && CURR_SLOT.opnd[4].X_op == O_constant
5386 && CURR_SLOT.opnd[5].X_op == O_constant)
5388 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5389 CURR_SLOT.opnd[3].X_add_number,
5390 CURR_SLOT.opnd[4].X_add_number,
5391 CURR_SLOT.opnd[5].X_add_number);
5393 /* now we can parse the first arg: */
5394 saved_input_pointer = input_line_pointer;
5395 input_line_pointer = first_arg;
5396 sep = parse_operand (CURR_SLOT.opnd + 0);
5398 --num_outputs; /* force error */
5399 input_line_pointer = saved_input_pointer;
5401 CURR_SLOT.opnd[2].X_add_number = sof;
5402 CURR_SLOT.opnd[3].X_add_number
5403 = sof - CURR_SLOT.opnd[4].X_add_number;
5404 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5408 highest_unmatched_operand = 0;
5409 curr_out_of_range_pos = -1;
5411 expected_operand = idesc->operands[0];
5412 for (; idesc; idesc = get_next_opcode (idesc))
5414 if (num_outputs != idesc->num_outputs)
5415 continue; /* mismatch in # of outputs */
5417 CURR_SLOT.num_fixups = 0;
5419 /* Try to match all operands. If we see an out-of-range operand,
5420 then continue trying to match the rest of the operands, since if
5421 the rest match, then this idesc will give the best error message. */
5423 out_of_range_pos = -1;
5424 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5426 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5427 if (result != OPERAND_MATCH)
5429 if (result != OPERAND_OUT_OF_RANGE)
5431 if (out_of_range_pos < 0)
5432 /* remember position of the first out-of-range operand: */
5433 out_of_range_pos = i;
5437 /* If we did not match all operands, or if at least one operand was
5438 out-of-range, then this idesc does not match. Keep track of which
5439 idesc matched the most operands before failing. If we have two
5440 idescs that failed at the same position, and one had an out-of-range
5441 operand, then prefer the out-of-range operand. Thus if we have
5442 "add r0=0x1000000,r1" we get an error saying the constant is out
5443 of range instead of an error saying that the constant should have been
5446 if (i != num_operands || out_of_range_pos >= 0)
5448 if (i > highest_unmatched_operand
5449 || (i == highest_unmatched_operand
5450 && out_of_range_pos > curr_out_of_range_pos))
5452 highest_unmatched_operand = i;
5453 if (out_of_range_pos >= 0)
5455 expected_operand = idesc->operands[out_of_range_pos];
5456 error_pos = out_of_range_pos;
5460 expected_operand = idesc->operands[i];
5463 curr_out_of_range_pos = out_of_range_pos;
5468 if (num_operands < NELEMS (idesc->operands)
5469 && idesc->operands[num_operands])
5470 continue; /* mismatch in number of arguments */
5476 if (expected_operand)
5477 as_bad ("Operand %u of `%s' should be %s",
5478 error_pos + 1, mnemonic,
5479 elf64_ia64_operands[expected_operand].desc);
5481 as_bad ("Operand mismatch");
5487 /* Keep track of state necessary to determine whether a NOP is necessary
5488 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5489 detect a case where additional NOPs may be necessary. */
5491 errata_nop_necessary_p (slot, insn_unit)
5493 enum ia64_unit insn_unit;
5496 struct group *this_group = md.last_groups + md.group_idx;
5497 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5498 struct ia64_opcode *idesc = slot->idesc;
5500 /* Test whether this could be the first insn in a problematic sequence. */
5501 if (insn_unit == IA64_UNIT_F)
5503 for (i = 0; i < idesc->num_outputs; i++)
5504 if (idesc->operands[i] == IA64_OPND_P1
5505 || idesc->operands[i] == IA64_OPND_P2)
5507 int regno = slot->opnd[i].X_add_number - REG_P;
5508 /* Ignore invalid operands; they generate errors elsewhere. */
5511 this_group->p_reg_set[regno] = 1;
5515 /* Test whether this could be the second insn in a problematic sequence. */
5516 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5517 && prev_group->p_reg_set[slot->qp_regno])
5519 for (i = 0; i < idesc->num_outputs; i++)
5520 if (idesc->operands[i] == IA64_OPND_R1
5521 || idesc->operands[i] == IA64_OPND_R2
5522 || idesc->operands[i] == IA64_OPND_R3)
5524 int regno = slot->opnd[i].X_add_number - REG_GR;
5525 /* Ignore invalid operands; they generate errors elsewhere. */
5528 if (strncmp (idesc->name, "add", 3) != 0
5529 && strncmp (idesc->name, "sub", 3) != 0
5530 && strncmp (idesc->name, "shladd", 6) != 0
5531 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5532 this_group->g_reg_set_conditionally[regno] = 1;
5536 /* Test whether this could be the third insn in a problematic sequence. */
5537 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5539 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5540 idesc->operands[i] == IA64_OPND_R3
5541 /* For mov indirect. */
5542 || idesc->operands[i] == IA64_OPND_RR_R3
5543 || idesc->operands[i] == IA64_OPND_DBR_R3
5544 || idesc->operands[i] == IA64_OPND_IBR_R3
5545 || idesc->operands[i] == IA64_OPND_PKR_R3
5546 || idesc->operands[i] == IA64_OPND_PMC_R3
5547 || idesc->operands[i] == IA64_OPND_PMD_R3
5548 || idesc->operands[i] == IA64_OPND_MSR_R3
5549 || idesc->operands[i] == IA64_OPND_CPUID_R3
5551 || idesc->operands[i] == IA64_OPND_ITR_R3
5552 || idesc->operands[i] == IA64_OPND_DTR_R3
5553 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5554 || idesc->operands[i] == IA64_OPND_MR3)
5556 int regno = slot->opnd[i].X_add_number - REG_GR;
5557 /* Ignore invalid operands; they generate errors elsewhere. */
5560 if (idesc->operands[i] == IA64_OPND_R3)
5562 if (strcmp (idesc->name, "fc") != 0
5563 && strcmp (idesc->name, "tak") != 0
5564 && strcmp (idesc->name, "thash") != 0
5565 && strcmp (idesc->name, "tpa") != 0
5566 && strcmp (idesc->name, "ttag") != 0
5567 && strncmp (idesc->name, "ptr", 3) != 0
5568 && strncmp (idesc->name, "ptc", 3) != 0
5569 && strncmp (idesc->name, "probe", 5) != 0)
5572 if (prev_group->g_reg_set_conditionally[regno])
5580 build_insn (slot, insnp)
5584 const struct ia64_operand *odesc, *o2desc;
5585 struct ia64_opcode *idesc = slot->idesc;
5586 bfd_signed_vma insn, val;
5590 insn = idesc->opcode | slot->qp_regno;
5592 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5594 if (slot->opnd[i].X_op == O_register
5595 || slot->opnd[i].X_op == O_constant
5596 || slot->opnd[i].X_op == O_index)
5597 val = slot->opnd[i].X_add_number;
5598 else if (slot->opnd[i].X_op == O_big)
5600 /* This must be the value 0x10000000000000000. */
5601 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5607 switch (idesc->operands[i])
5609 case IA64_OPND_IMMU64:
5610 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5611 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5612 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5613 | (((val >> 63) & 0x1) << 36));
5616 case IA64_OPND_IMMU62:
5617 val &= 0x3fffffffffffffffULL;
5618 if (val != slot->opnd[i].X_add_number)
5619 as_warn (_("Value truncated to 62 bits"));
5620 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5621 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5624 case IA64_OPND_TGT64:
5626 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5627 insn |= ((((val >> 59) & 0x1) << 36)
5628 | (((val >> 0) & 0xfffff) << 13));
5659 case IA64_OPND_R3_2:
5660 case IA64_OPND_CPUID_R3:
5661 case IA64_OPND_DBR_R3:
5662 case IA64_OPND_DTR_R3:
5663 case IA64_OPND_ITR_R3:
5664 case IA64_OPND_IBR_R3:
5666 case IA64_OPND_MSR_R3:
5667 case IA64_OPND_PKR_R3:
5668 case IA64_OPND_PMC_R3:
5669 case IA64_OPND_PMD_R3:
5670 case IA64_OPND_RR_R3:
5678 odesc = elf64_ia64_operands + idesc->operands[i];
5679 err = (*odesc->insert) (odesc, val, &insn);
5681 as_bad_where (slot->src_file, slot->src_line,
5682 "Bad operand value: %s", err);
5683 if (idesc->flags & IA64_OPCODE_PSEUDO)
5685 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
5686 && odesc == elf64_ia64_operands + IA64_OPND_F3)
5688 o2desc = elf64_ia64_operands + IA64_OPND_F2;
5689 (*o2desc->insert) (o2desc, val, &insn);
5691 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
5692 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
5693 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
5695 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
5696 (*o2desc->insert) (o2desc, 64 - val, &insn);
5706 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
5707 unsigned int manual_bundling = 0;
5708 enum ia64_unit required_unit, insn_unit = 0;
5709 enum ia64_insn_type type[3], insn_type;
5710 unsigned int template, orig_template;
5711 bfd_vma insn[3] = { -1, -1, -1 };
5712 struct ia64_opcode *idesc;
5713 int end_of_insn_group = 0, user_template = -1;
5714 int n, i, j, first, curr;
5716 bfd_vma t0 = 0, t1 = 0;
5717 struct label_fix *lfix;
5718 struct insn_fix *ifix;
5723 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
5724 know (first >= 0 & first < NUM_SLOTS);
5725 n = MIN (3, md.num_slots_in_use);
5727 /* Determine template: user user_template if specified, best match
5730 if (md.slot[first].user_template >= 0)
5731 user_template = template = md.slot[first].user_template;
5734 /* Auto select appropriate template. */
5735 memset (type, 0, sizeof (type));
5737 for (i = 0; i < n; ++i)
5739 if (md.slot[curr].label_fixups && i != 0)
5741 type[i] = md.slot[curr].idesc->type;
5742 curr = (curr + 1) % NUM_SLOTS;
5744 template = best_template[type[0]][type[1]][type[2]];
5747 /* initialize instructions with appropriate nops: */
5748 for (i = 0; i < 3; ++i)
5749 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
5753 /* now fill in slots with as many insns as possible: */
5755 idesc = md.slot[curr].idesc;
5756 end_of_insn_group = 0;
5757 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
5759 /* Set the slot number for prologue/body records now as those
5760 refer to the current point, not the point after the
5761 instruction has been issued: */
5762 /* Don't try to delete prologue/body records here, as that will cause
5763 them to also be deleted from the master list of unwind records. */
5764 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
5765 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
5766 || ptr->r.type == body)
5768 ptr->slot_number = (unsigned long) f + i;
5769 ptr->slot_frag = frag_now;
5772 if (idesc->flags & IA64_OPCODE_SLOT2)
5774 if (manual_bundling && i != 2)
5775 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5776 "`%s' must be last in bundle", idesc->name);
5780 if (idesc->flags & IA64_OPCODE_LAST)
5783 unsigned int required_template;
5785 /* If we need a stop bit after an M slot, our only choice is
5786 template 5 (M;;MI). If we need a stop bit after a B
5787 slot, our only choice is to place it at the end of the
5788 bundle, because the only available templates are MIB,
5789 MBB, BBB, MMB, and MFB. We don't handle anything other
5790 than M and B slots because these are the only kind of
5791 instructions that can have the IA64_OPCODE_LAST bit set. */
5792 required_template = template;
5793 switch (idesc->type)
5797 required_template = 5;
5805 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5806 "Internal error: don't know how to force %s to end"
5807 "of instruction group", idesc->name);
5811 if (manual_bundling && i != required_slot)
5812 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5813 "`%s' must be last in instruction group",
5815 if (required_slot < i)
5816 /* Can't fit this instruction. */
5820 if (required_template != template)
5822 /* If we switch the template, we need to reset the NOPs
5823 after slot i. The slot-types of the instructions ahead
5824 of i never change, so we don't need to worry about
5825 changing NOPs in front of this slot. */
5826 for (j = i; j < 3; ++j)
5827 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
5829 template = required_template;
5831 if (curr != first && md.slot[curr].label_fixups)
5833 if (manual_bundling_on)
5834 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5835 "Label must be first in a bundle");
5836 /* This insn must go into the first slot of a bundle. */
5840 manual_bundling_on = md.slot[curr].manual_bundling_on;
5841 manual_bundling_off = md.slot[curr].manual_bundling_off;
5843 if (manual_bundling_on)
5846 manual_bundling = 1;
5848 break; /* need to start a new bundle */
5851 if (end_of_insn_group && md.num_slots_in_use >= 1)
5853 /* We need an instruction group boundary in the middle of a
5854 bundle. See if we can switch to an other template with
5855 an appropriate boundary. */
5857 orig_template = template;
5858 if (i == 1 && (user_template == 4
5859 || (user_template < 0
5860 && (ia64_templ_desc[template].exec_unit[0]
5864 end_of_insn_group = 0;
5866 else if (i == 2 && (user_template == 0
5867 || (user_template < 0
5868 && (ia64_templ_desc[template].exec_unit[1]
5870 /* This test makes sure we don't switch the template if
5871 the next instruction is one that needs to be first in
5872 an instruction group. Since all those instructions are
5873 in the M group, there is no way such an instruction can
5874 fit in this bundle even if we switch the template. The
5875 reason we have to check for this is that otherwise we
5876 may end up generating "MI;;I M.." which has the deadly
5877 effect that the second M instruction is no longer the
5878 first in the bundle! --davidm 99/12/16 */
5879 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
5882 end_of_insn_group = 0;
5884 else if (curr != first)
5885 /* can't fit this insn */
5888 if (template != orig_template)
5889 /* if we switch the template, we need to reset the NOPs
5890 after slot i. The slot-types of the instructions ahead
5891 of i never change, so we don't need to worry about
5892 changing NOPs in front of this slot. */
5893 for (j = i; j < 3; ++j)
5894 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
5896 required_unit = ia64_templ_desc[template].exec_unit[i];
5898 /* resolve dynamic opcodes such as "break" and "nop": */
5899 if (idesc->type == IA64_TYPE_DYN)
5901 if ((strcmp (idesc->name, "nop") == 0)
5902 || (strcmp (idesc->name, "break") == 0))
5903 insn_unit = required_unit;
5904 else if (strcmp (idesc->name, "chk.s") == 0)
5906 insn_unit = IA64_UNIT_M;
5907 if (required_unit == IA64_UNIT_I)
5908 insn_unit = IA64_UNIT_I;
5911 as_fatal ("emit_one_bundle: unexpected dynamic op");
5913 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
5914 ia64_free_opcode (idesc);
5915 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
5917 know (!idesc->next); /* no resolved dynamic ops have collisions */
5922 insn_type = idesc->type;
5923 insn_unit = IA64_UNIT_NIL;
5927 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
5928 insn_unit = required_unit;
5930 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
5931 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
5932 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
5933 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
5934 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
5939 if (insn_unit != required_unit)
5941 if (required_unit == IA64_UNIT_L
5942 && insn_unit == IA64_UNIT_I
5943 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
5945 /* we got ourselves an MLX template but the current
5946 instruction isn't an X-unit, or an I-unit instruction
5947 that can go into the X slot of an MLX template. Duh. */
5948 if (md.num_slots_in_use >= NUM_SLOTS)
5950 as_bad_where (md.slot[curr].src_file,
5951 md.slot[curr].src_line,
5952 "`%s' can't go in X slot of "
5953 "MLX template", idesc->name);
5954 /* drop this insn so we don't livelock: */
5955 --md.num_slots_in_use;
5959 continue; /* try next slot */
5965 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
5966 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
5969 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
5970 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
5972 build_insn (md.slot + curr, insn + i);
5974 /* Set slot counts for non prologue/body unwind records. */
5975 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
5976 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
5977 && ptr->r.type != body)
5979 ptr->slot_number = (unsigned long) f + i;
5980 ptr->slot_frag = frag_now;
5982 md.slot[curr].unwind_record = NULL;
5984 if (required_unit == IA64_UNIT_L)
5987 /* skip one slot for long/X-unit instructions */
5990 --md.num_slots_in_use;
5992 /* now is a good time to fix up the labels for this insn: */
5993 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
5995 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
5996 symbol_set_frag (lfix->sym, frag_now);
5998 /* and fix up the tags also. */
5999 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6001 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6002 symbol_set_frag (lfix->sym, frag_now);
6005 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6007 ifix = md.slot[curr].fixup + j;
6008 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6009 &ifix->expr, ifix->is_pcrel, ifix->code);
6010 fix->tc_fix_data.opnd = ifix->opnd;
6011 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6012 fix->fx_file = md.slot[curr].src_file;
6013 fix->fx_line = md.slot[curr].src_line;
6016 end_of_insn_group = md.slot[curr].end_of_insn_group;
6018 if (end_of_insn_group)
6020 md.group_idx = (md.group_idx + 1) % 3;
6021 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6025 ia64_free_opcode (md.slot[curr].idesc);
6026 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6027 md.slot[curr].user_template = -1;
6029 if (manual_bundling_off)
6031 manual_bundling = 0;
6034 curr = (curr + 1) % NUM_SLOTS;
6035 idesc = md.slot[curr].idesc;
6037 if (manual_bundling)
6039 if (md.num_slots_in_use > 0)
6040 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6041 "`%s' does not fit into %s template",
6042 idesc->name, ia64_templ_desc[template].name);
6044 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6045 "Missing '}' at end of file");
6047 know (md.num_slots_in_use < NUM_SLOTS);
6049 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6050 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6052 number_to_chars_littleendian (f + 0, t0, 8);
6053 number_to_chars_littleendian (f + 8, t1, 8);
6055 unwind.next_slot_number = (unsigned long) f + 16;
6056 unwind.next_slot_frag = frag_now;
6060 md_parse_option (c, arg)
6067 /* Switches from the Intel assembler. */
6069 if (strcmp (arg, "ilp64") == 0
6070 || strcmp (arg, "lp64") == 0
6071 || strcmp (arg, "p64") == 0)
6073 md.flags |= EF_IA_64_ABI64;
6075 else if (strcmp (arg, "ilp32") == 0)
6077 md.flags &= ~EF_IA_64_ABI64;
6079 else if (strcmp (arg, "le") == 0)
6081 md.flags &= ~EF_IA_64_BE;
6083 else if (strcmp (arg, "be") == 0)
6085 md.flags |= EF_IA_64_BE;
6092 if (strcmp (arg, "so") == 0)
6094 /* Suppress signon message. */
6096 else if (strcmp (arg, "pi") == 0)
6098 /* Reject privileged instructions. FIXME */
6100 else if (strcmp (arg, "us") == 0)
6102 /* Allow union of signed and unsigned range. FIXME */
6104 else if (strcmp (arg, "close_fcalls") == 0)
6106 /* Do not resolve global function calls. */
6113 /* temp[="prefix"] Insert temporary labels into the object file
6114 symbol table prefixed by "prefix".
6115 Default prefix is ":temp:".
6120 /* indirect=<tgt> Assume unannotated indirect branches behavior
6121 according to <tgt> --
6122 exit: branch out from the current context (default)
6123 labels: all labels in context may be branch targets
6125 if (strncmp (arg, "indirect=", 9) != 0)
6130 /* -X conflicts with an ignored option, use -x instead */
6132 if (!arg || strcmp (arg, "explicit") == 0)
6134 /* set default mode to explicit */
6135 md.default_explicit_mode = 1;
6138 else if (strcmp (arg, "auto") == 0)
6140 md.default_explicit_mode = 0;
6142 else if (strcmp (arg, "debug") == 0)
6146 else if (strcmp (arg, "debugx") == 0)
6148 md.default_explicit_mode = 1;
6153 as_bad (_("Unrecognized option '-x%s'"), arg);
6158 /* nops Print nops statistics. */
6161 /* GNU specific switches for gcc. */
6162 case OPTION_MCONSTANT_GP:
6163 md.flags |= EF_IA_64_CONS_GP;
6166 case OPTION_MAUTO_PIC:
6167 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6178 md_show_usage (stream)
6183 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6184 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6185 -x | -xexplicit turn on dependency violation checking (default)\n\
6186 -xauto automagically remove dependency violations\n\
6187 -xdebug debug dependency violation checker\n"),
6191 /* Return true if TYPE fits in TEMPL at SLOT. */
6194 match (int templ, int type, int slot)
6196 enum ia64_unit unit;
6199 unit = ia64_templ_desc[templ].exec_unit[slot];
6202 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6204 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6206 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6207 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6208 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6209 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6210 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6211 default: result = 0; break;
6216 /* Add a bit of extra goodness if a nop of type F or B would fit
6217 in TEMPL at SLOT. */
6220 extra_goodness (int templ, int slot)
6222 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6224 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6229 /* This function is called once, at assembler startup time. It sets
6230 up all the tables, etc. that the MD part of the assembler will need
6231 that can be determined before arguments are parsed. */
6235 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6240 md.explicit_mode = md.default_explicit_mode;
6242 bfd_set_section_alignment (stdoutput, text_section, 4);
6244 target_big_endian = TARGET_BYTES_BIG_ENDIAN;
6245 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6246 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6247 &zero_address_frag);
6249 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6250 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6251 &zero_address_frag);
6253 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6254 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6255 &zero_address_frag);
6257 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6258 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6259 &zero_address_frag);
6261 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6262 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6263 &zero_address_frag);
6265 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6266 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6267 &zero_address_frag);
6269 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6270 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6271 &zero_address_frag);
6273 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6274 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6275 &zero_address_frag);
6277 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6278 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6279 &zero_address_frag);
6281 /* Compute the table of best templates. We compute goodness as a
6282 base 4 value, in which each match counts for 3, each F counts
6283 for 2, each B counts for 1. This should maximize the number of
6284 F and B nops in the chosen bundles, which is good because these
6285 pipelines are least likely to be overcommitted. */
6286 for (i = 0; i < IA64_NUM_TYPES; ++i)
6287 for (j = 0; j < IA64_NUM_TYPES; ++j)
6288 for (k = 0; k < IA64_NUM_TYPES; ++k)
6291 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6294 if (match (t, i, 0))
6296 if (match (t, j, 1))
6298 if (match (t, k, 2))
6299 goodness = 3 + 3 + 3;
6301 goodness = 3 + 3 + extra_goodness (t, 2);
6303 else if (match (t, j, 2))
6304 goodness = 3 + 3 + extra_goodness (t, 1);
6308 goodness += extra_goodness (t, 1);
6309 goodness += extra_goodness (t, 2);
6312 else if (match (t, i, 1))
6314 if (match (t, j, 2))
6317 goodness = 3 + extra_goodness (t, 2);
6319 else if (match (t, i, 2))
6320 goodness = 3 + extra_goodness (t, 1);
6322 if (goodness > best)
6325 best_template[i][j][k] = t;
6330 for (i = 0; i < NUM_SLOTS; ++i)
6331 md.slot[i].user_template = -1;
6333 md.pseudo_hash = hash_new ();
6334 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6336 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6337 (void *) (pseudo_opcode + i));
6339 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6340 pseudo_opcode[i].name, err);
6343 md.reg_hash = hash_new ();
6344 md.dynreg_hash = hash_new ();
6345 md.const_hash = hash_new ();
6346 md.entry_hash = hash_new ();
6348 /* general registers: */
6351 for (i = 0; i < total; ++i)
6353 sprintf (name, "r%d", i - REG_GR);
6354 md.regsym[i] = declare_register (name, i);
6357 /* floating point registers: */
6359 for (; i < total; ++i)
6361 sprintf (name, "f%d", i - REG_FR);
6362 md.regsym[i] = declare_register (name, i);
6365 /* application registers: */
6368 for (; i < total; ++i)
6370 sprintf (name, "ar%d", i - REG_AR);
6371 md.regsym[i] = declare_register (name, i);
6374 /* control registers: */
6377 for (; i < total; ++i)
6379 sprintf (name, "cr%d", i - REG_CR);
6380 md.regsym[i] = declare_register (name, i);
6383 /* predicate registers: */
6385 for (; i < total; ++i)
6387 sprintf (name, "p%d", i - REG_P);
6388 md.regsym[i] = declare_register (name, i);
6391 /* branch registers: */
6393 for (; i < total; ++i)
6395 sprintf (name, "b%d", i - REG_BR);
6396 md.regsym[i] = declare_register (name, i);
6399 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6400 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6401 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6402 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6403 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6404 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6405 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6407 for (i = 0; i < NELEMS (indirect_reg); ++i)
6409 regnum = indirect_reg[i].regnum;
6410 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6413 /* define synonyms for application registers: */
6414 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6415 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6416 REG_AR + ar[i - REG_AR].regnum);
6418 /* define synonyms for control registers: */
6419 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6420 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6421 REG_CR + cr[i - REG_CR].regnum);
6423 declare_register ("gp", REG_GR + 1);
6424 declare_register ("sp", REG_GR + 12);
6425 declare_register ("rp", REG_BR + 0);
6427 /* pseudo-registers used to specify unwind info: */
6428 declare_register ("psp", REG_PSP);
6430 declare_register_set ("ret", 4, REG_GR + 8);
6431 declare_register_set ("farg", 8, REG_FR + 8);
6432 declare_register_set ("fret", 8, REG_FR + 8);
6434 for (i = 0; i < NELEMS (const_bits); ++i)
6436 err = hash_insert (md.const_hash, const_bits[i].name,
6437 (PTR) (const_bits + i));
6439 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6443 /* Set the architecture and machine depending on defaults and command line
6445 if (md.flags & EF_IA_64_ABI64)
6446 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6448 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6451 as_warn (_("Could not set architecture and machine"));
6453 md.mem_offset.hint = 0;
6456 md.entry_labels = NULL;
6459 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6460 because that is called after md_parse_option which is where we do the
6461 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6462 default endianness. */
6465 ia64_init (argc, argv)
6466 int argc ATTRIBUTE_UNUSED;
6467 char **argv ATTRIBUTE_UNUSED;
6469 md.flags = EF_IA_64_ABI64;
6470 if (TARGET_BYTES_BIG_ENDIAN)
6471 md.flags |= EF_IA_64_BE;
6474 /* Return a string for the target object file format. */
6477 ia64_target_format ()
6479 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6481 if (md.flags & EF_IA_64_BE)
6483 if (md.flags & EF_IA_64_ABI64)
6485 return "elf64-ia64-aix-big";
6487 return "elf64-ia64-big";
6491 return "elf32-ia64-aix-big";
6493 return "elf32-ia64-big";
6498 if (md.flags & EF_IA_64_ABI64)
6500 return "elf64-ia64-aix-little";
6502 return "elf64-ia64-little";
6506 return "elf32-ia64-aix-little";
6508 return "elf32-ia64-little";
6513 return "unknown-format";
6517 ia64_end_of_source ()
6519 /* terminate insn group upon reaching end of file: */
6520 insn_group_break (1, 0, 0);
6522 /* emits slots we haven't written yet: */
6523 ia64_flush_insns ();
6525 bfd_set_private_flags (stdoutput, md.flags);
6527 md.mem_offset.hint = 0;
6533 if (md.qp.X_op == O_register)
6534 as_bad ("qualifying predicate not followed by instruction");
6535 md.qp.X_op = O_absent;
6537 if (ignore_input ())
6540 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
6542 if (md.detect_dv && !md.explicit_mode)
6543 as_warn (_("Explicit stops are ignored in auto mode"));
6545 insn_group_break (1, 0, 0);
6549 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
6551 static int defining_tag = 0;
6554 ia64_unrecognized_line (ch)
6560 expression (&md.qp);
6561 if (*input_line_pointer++ != ')')
6563 as_bad ("Expected ')'");
6566 if (md.qp.X_op != O_register)
6568 as_bad ("Qualifying predicate expected");
6571 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
6573 as_bad ("Predicate register expected");
6579 if (md.manual_bundling)
6580 as_warn ("Found '{' when manual bundling is already turned on");
6582 CURR_SLOT.manual_bundling_on = 1;
6583 md.manual_bundling = 1;
6585 /* Bundling is only acceptable in explicit mode
6586 or when in default automatic mode. */
6587 if (md.detect_dv && !md.explicit_mode)
6589 if (!md.mode_explicitly_set
6590 && !md.default_explicit_mode)
6593 as_warn (_("Found '{' after explicit switch to automatic mode"));
6598 if (!md.manual_bundling)
6599 as_warn ("Found '}' when manual bundling is off");
6601 PREV_SLOT.manual_bundling_off = 1;
6602 md.manual_bundling = 0;
6604 /* switch back to automatic mode, if applicable */
6607 && !md.mode_explicitly_set
6608 && !md.default_explicit_mode)
6611 /* Allow '{' to follow on the same line. We also allow ";;", but that
6612 happens automatically because ';' is an end of line marker. */
6614 if (input_line_pointer[0] == '{')
6616 input_line_pointer++;
6617 return ia64_unrecognized_line ('{');
6620 demand_empty_rest_of_line ();
6630 if (md.qp.X_op == O_register)
6632 as_bad ("Tag must come before qualifying predicate.");
6636 /* This implements just enough of read_a_source_file in read.c to
6637 recognize labels. */
6638 if (is_name_beginner (*input_line_pointer))
6640 s = input_line_pointer;
6641 c = get_symbol_end ();
6643 else if (LOCAL_LABELS_FB
6644 && isdigit ((unsigned char) *input_line_pointer))
6647 while (isdigit ((unsigned char) *input_line_pointer))
6648 temp = (temp * 10) + *input_line_pointer++ - '0';
6649 fb_label_instance_inc (temp);
6650 s = fb_label_name (temp, 0);
6651 c = *input_line_pointer;
6660 /* Put ':' back for error messages' sake. */
6661 *input_line_pointer++ = ':';
6662 as_bad ("Expected ':'");
6669 /* Put ':' back for error messages' sake. */
6670 *input_line_pointer++ = ':';
6671 if (*input_line_pointer++ != ']')
6673 as_bad ("Expected ']'");
6678 as_bad ("Tag name expected");
6688 /* Not a valid line. */
6693 ia64_frob_label (sym)
6696 struct label_fix *fix;
6698 /* Tags need special handling since they are not bundle breaks like
6702 fix = obstack_alloc (¬es, sizeof (*fix));
6704 fix->next = CURR_SLOT.tag_fixups;
6705 CURR_SLOT.tag_fixups = fix;
6710 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
6712 md.last_text_seg = now_seg;
6713 fix = obstack_alloc (¬es, sizeof (*fix));
6715 fix->next = CURR_SLOT.label_fixups;
6716 CURR_SLOT.label_fixups = fix;
6718 /* Keep track of how many code entry points we've seen. */
6719 if (md.path == md.maxpaths)
6722 md.entry_labels = (const char **)
6723 xrealloc ((void *) md.entry_labels,
6724 md.maxpaths * sizeof (char *));
6726 md.entry_labels[md.path++] = S_GET_NAME (sym);
6731 ia64_flush_pending_output ()
6733 if (!md.keep_pending_output
6734 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
6736 /* ??? This causes many unnecessary stop bits to be emitted.
6737 Unfortunately, it isn't clear if it is safe to remove this. */
6738 insn_group_break (1, 0, 0);
6739 ia64_flush_insns ();
6743 /* Do ia64-specific expression optimization. All that's done here is
6744 to transform index expressions that are either due to the indexing
6745 of rotating registers or due to the indexing of indirect register
6748 ia64_optimize_expr (l, op, r)
6757 if (l->X_op == O_register && r->X_op == O_constant)
6759 num_regs = (l->X_add_number >> 16);
6760 if ((unsigned) r->X_add_number >= num_regs)
6763 as_bad ("No current frame");
6765 as_bad ("Index out of range 0..%u", num_regs - 1);
6766 r->X_add_number = 0;
6768 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
6771 else if (l->X_op == O_register && r->X_op == O_register)
6773 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
6774 || l->X_add_number == IND_MEM)
6776 as_bad ("Indirect register set name expected");
6777 l->X_add_number = IND_CPUID;
6780 l->X_op_symbol = md.regsym[l->X_add_number];
6781 l->X_add_number = r->X_add_number;
6789 ia64_parse_name (name, e)
6793 struct const_desc *cdesc;
6794 struct dynreg *dr = 0;
6795 unsigned int regnum;
6799 /* first see if NAME is a known register name: */
6800 sym = hash_find (md.reg_hash, name);
6803 e->X_op = O_register;
6804 e->X_add_number = S_GET_VALUE (sym);
6808 cdesc = hash_find (md.const_hash, name);
6811 e->X_op = O_constant;
6812 e->X_add_number = cdesc->value;
6816 /* check for inN, locN, or outN: */
6820 if (name[1] == 'n' && isdigit (name[2]))
6828 if (name[1] == 'o' && name[2] == 'c' && isdigit (name[3]))
6836 if (name[1] == 'u' && name[2] == 't' && isdigit (name[3]))
6849 /* The name is inN, locN, or outN; parse the register number. */
6850 regnum = strtoul (name, &end, 10);
6851 if (end > name && *end == '\0')
6853 if ((unsigned) regnum >= dr->num_regs)
6856 as_bad ("No current frame");
6858 as_bad ("Register number out of range 0..%u",
6862 e->X_op = O_register;
6863 e->X_add_number = dr->base + regnum;
6868 if ((dr = hash_find (md.dynreg_hash, name)))
6870 /* We've got ourselves the name of a rotating register set.
6871 Store the base register number in the low 16 bits of
6872 X_add_number and the size of the register set in the top 16
6874 e->X_op = O_register;
6875 e->X_add_number = dr->base | (dr->num_regs << 16);
6881 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
6884 ia64_canonicalize_symbol_name (name)
6887 size_t len = strlen (name);
6888 if (len > 1 && name[len - 1] == '#')
6889 name[len - 1] = '\0';
6893 /* Return true if idesc is a conditional branch instruction. */
6896 is_conditional_branch (idesc)
6897 struct ia64_opcode *idesc;
6899 /* br is a conditional branch. Everything that starts with br. except
6900 br.ia is a conditional branch. Everything that starts with brl is a
6901 conditional branch. */
6902 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
6903 && (idesc->name[2] == '\0'
6904 || (idesc->name[2] == '.' && idesc->name[3] != 'i')
6905 || idesc->name[2] == 'l'));
6908 /* Return whether the given opcode is a taken branch. If there's any doubt,
6912 is_taken_branch (idesc)
6913 struct ia64_opcode *idesc;
6915 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
6916 || strncmp (idesc->name, "br.ia", 5) == 0);
6919 /* Return whether the given opcode is an interruption or rfi. If there's any
6920 doubt, returns zero. */
6923 is_interruption_or_rfi (idesc)
6924 struct ia64_opcode *idesc;
6926 if (strcmp (idesc->name, "rfi") == 0)
6931 /* Returns the index of the given dependency in the opcode's list of chks, or
6932 -1 if there is no dependency. */
6935 depends_on (depind, idesc)
6937 struct ia64_opcode *idesc;
6940 const struct ia64_opcode_dependency *dep = idesc->dependencies;
6941 for (i = 0; i < dep->nchks; i++)
6943 if (depind == DEP (dep->chks[i]))
6949 /* Determine a set of specific resources used for a particular resource
6950 class. Returns the number of specific resources identified For those
6951 cases which are not determinable statically, the resource returned is
6954 Meanings of value in 'NOTE':
6955 1) only read/write when the register number is explicitly encoded in the
6957 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
6958 accesses CFM when qualifying predicate is in the rotating region.
6959 3) general register value is used to specify an indirect register; not
6960 determinable statically.
6961 4) only read the given resource when bits 7:0 of the indirect index
6962 register value does not match the register number of the resource; not
6963 determinable statically.
6964 5) all rules are implementation specific.
6965 6) only when both the index specified by the reader and the index specified
6966 by the writer have the same value in bits 63:61; not determinable
6968 7) only access the specified resource when the corresponding mask bit is
6970 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
6971 only read when these insns reference FR2-31
6972 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
6973 written when these insns write FR32-127
6974 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
6976 11) The target predicates are written independently of PR[qp], but source
6977 registers are only read if PR[qp] is true. Since the state of PR[qp]
6978 cannot statically be determined, all source registers are marked used.
6979 12) This insn only reads the specified predicate register when that
6980 register is the PR[qp].
6981 13) This reference to ld-c only applies to teh GR whose value is loaded
6982 with data returned from memory, not the post-incremented address register.
6983 14) The RSE resource includes the implementation-specific RSE internal
6984 state resources. At least one (and possibly more) of these resources are
6985 read by each instruction listed in IC:rse-readers. At least one (and
6986 possibly more) of these resources are written by each insn listed in
6988 15+16) Represents reserved instructions, which the assembler does not
6991 Memory resources (i.e. locations in memory) are *not* marked or tracked by
6992 this code; there are no dependency violations based on memory access.
6995 #define MAX_SPECS 256
7000 specify_resource (dep, idesc, type, specs, note, path)
7001 const struct ia64_dependency *dep;
7002 struct ia64_opcode *idesc;
7003 int type; /* is this a DV chk or a DV reg? */
7004 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7005 int note; /* resource note for this insn's usage */
7006 int path; /* which execution path to examine */
7013 if (dep->mode == IA64_DV_WAW
7014 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7015 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7018 /* template for any resources we identify */
7019 tmpl.dependency = dep;
7021 tmpl.insn_srlz = tmpl.data_srlz = 0;
7022 tmpl.qp_regno = CURR_SLOT.qp_regno;
7023 tmpl.link_to_qp_branch = 1;
7024 tmpl.mem_offset.hint = 0;
7027 tmpl.cmp_type = CMP_NONE;
7030 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7031 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7032 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7034 /* we don't need to track these */
7035 if (dep->semantics == IA64_DVS_NONE)
7038 switch (dep->specifier)
7043 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7045 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7046 if (regno >= 0 && regno <= 7)
7048 specs[count] = tmpl;
7049 specs[count++].index = regno;
7055 for (i = 0; i < 8; i++)
7057 specs[count] = tmpl;
7058 specs[count++].index = i;
7067 case IA64_RS_AR_UNAT:
7068 /* This is a mov =AR or mov AR= instruction. */
7069 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7071 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7072 if (regno == AR_UNAT)
7074 specs[count++] = tmpl;
7079 /* This is a spill/fill, or other instruction that modifies the
7082 /* Unless we can determine the specific bits used, mark the whole
7083 thing; bits 8:3 of the memory address indicate the bit used in
7084 UNAT. The .mem.offset hint may be used to eliminate a small
7085 subset of conflicts. */
7086 specs[count] = tmpl;
7087 if (md.mem_offset.hint)
7090 fprintf (stderr, " Using hint for spill/fill\n");
7091 /* The index isn't actually used, just set it to something
7092 approximating the bit index. */
7093 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7094 specs[count].mem_offset.hint = 1;
7095 specs[count].mem_offset.offset = md.mem_offset.offset;
7096 specs[count++].mem_offset.base = md.mem_offset.base;
7100 specs[count++].specific = 0;
7108 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7110 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7111 if ((regno >= 8 && regno <= 15)
7112 || (regno >= 20 && regno <= 23)
7113 || (regno >= 31 && regno <= 39)
7114 || (regno >= 41 && regno <= 47)
7115 || (regno >= 67 && regno <= 111))
7117 specs[count] = tmpl;
7118 specs[count++].index = regno;
7131 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7133 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7134 if ((regno >= 48 && regno <= 63)
7135 || (regno >= 112 && regno <= 127))
7137 specs[count] = tmpl;
7138 specs[count++].index = regno;
7144 for (i = 48; i < 64; i++)
7146 specs[count] = tmpl;
7147 specs[count++].index = i;
7149 for (i = 112; i < 128; i++)
7151 specs[count] = tmpl;
7152 specs[count++].index = i;
7170 for (i = 0; i < idesc->num_outputs; i++)
7171 if (idesc->operands[i] == IA64_OPND_B1
7172 || idesc->operands[i] == IA64_OPND_B2)
7174 specs[count] = tmpl;
7175 specs[count++].index =
7176 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7181 for (i = idesc->num_outputs;i < NELEMS (idesc->operands); i++)
7182 if (idesc->operands[i] == IA64_OPND_B1
7183 || idesc->operands[i] == IA64_OPND_B2)
7185 specs[count] = tmpl;
7186 specs[count++].index =
7187 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7193 case IA64_RS_CPUID: /* four or more registers */
7196 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7198 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7199 if (regno >= 0 && regno < NELEMS (gr_values)
7202 specs[count] = tmpl;
7203 specs[count++].index = gr_values[regno].value & 0xFF;
7207 specs[count] = tmpl;
7208 specs[count++].specific = 0;
7218 case IA64_RS_DBR: /* four or more registers */
7221 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7223 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7224 if (regno >= 0 && regno < NELEMS (gr_values)
7227 specs[count] = tmpl;
7228 specs[count++].index = gr_values[regno].value & 0xFF;
7232 specs[count] = tmpl;
7233 specs[count++].specific = 0;
7237 else if (note == 0 && !rsrc_write)
7239 specs[count] = tmpl;
7240 specs[count++].specific = 0;
7248 case IA64_RS_IBR: /* four or more registers */
7251 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7253 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7254 if (regno >= 0 && regno < NELEMS (gr_values)
7257 specs[count] = tmpl;
7258 specs[count++].index = gr_values[regno].value & 0xFF;
7262 specs[count] = tmpl;
7263 specs[count++].specific = 0;
7276 /* These are implementation specific. Force all references to
7277 conflict with all other references. */
7278 specs[count] = tmpl;
7279 specs[count++].specific = 0;
7287 case IA64_RS_PKR: /* 16 or more registers */
7288 if (note == 3 || note == 4)
7290 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7292 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7293 if (regno >= 0 && regno < NELEMS (gr_values)
7298 specs[count] = tmpl;
7299 specs[count++].index = gr_values[regno].value & 0xFF;
7302 for (i = 0; i < NELEMS (gr_values); i++)
7304 /* Uses all registers *except* the one in R3. */
7305 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7307 specs[count] = tmpl;
7308 specs[count++].index = i;
7314 specs[count] = tmpl;
7315 specs[count++].specific = 0;
7322 specs[count] = tmpl;
7323 specs[count++].specific = 0;
7327 case IA64_RS_PMC: /* four or more registers */
7330 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7331 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7334 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7336 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7337 if (regno >= 0 && regno < NELEMS (gr_values)
7340 specs[count] = tmpl;
7341 specs[count++].index = gr_values[regno].value & 0xFF;
7345 specs[count] = tmpl;
7346 specs[count++].specific = 0;
7356 case IA64_RS_PMD: /* four or more registers */
7359 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7361 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7362 if (regno >= 0 && regno < NELEMS (gr_values)
7365 specs[count] = tmpl;
7366 specs[count++].index = gr_values[regno].value & 0xFF;
7370 specs[count] = tmpl;
7371 specs[count++].specific = 0;
7381 case IA64_RS_RR: /* eight registers */
7384 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7386 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7387 if (regno >= 0 && regno < NELEMS (gr_values)
7390 specs[count] = tmpl;
7391 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7395 specs[count] = tmpl;
7396 specs[count++].specific = 0;
7400 else if (note == 0 && !rsrc_write)
7402 specs[count] = tmpl;
7403 specs[count++].specific = 0;
7411 case IA64_RS_CR_IRR:
7414 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7415 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7417 && idesc->operands[1] == IA64_OPND_CR3
7420 for (i = 0; i < 4; i++)
7422 specs[count] = tmpl;
7423 specs[count++].index = CR_IRR0 + i;
7429 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7430 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7432 && regno <= CR_IRR3)
7434 specs[count] = tmpl;
7435 specs[count++].index = regno;
7444 case IA64_RS_CR_LRR:
7451 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7452 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7453 && (regno == CR_LRR0 || regno == CR_LRR1))
7455 specs[count] = tmpl;
7456 specs[count++].index = regno;
7464 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7466 specs[count] = tmpl;
7467 specs[count++].index =
7468 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7483 else if (rsrc_write)
7485 if (dep->specifier == IA64_RS_FRb
7486 && idesc->operands[0] == IA64_OPND_F1)
7488 specs[count] = tmpl;
7489 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
7494 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7496 if (idesc->operands[i] == IA64_OPND_F2
7497 || idesc->operands[i] == IA64_OPND_F3
7498 || idesc->operands[i] == IA64_OPND_F4)
7500 specs[count] = tmpl;
7501 specs[count++].index =
7502 CURR_SLOT.opnd[i].X_add_number - REG_FR;
7511 /* This reference applies only to the GR whose value is loaded with
7512 data returned from memory. */
7513 specs[count] = tmpl;
7514 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7520 for (i = 0; i < idesc->num_outputs; i++)
7521 if (idesc->operands[i] == IA64_OPND_R1
7522 || idesc->operands[i] == IA64_OPND_R2
7523 || idesc->operands[i] == IA64_OPND_R3)
7525 specs[count] = tmpl;
7526 specs[count++].index =
7527 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7529 if (idesc->flags & IA64_OPCODE_POSTINC)
7530 for (i = 0; i < NELEMS (idesc->operands); i++)
7531 if (idesc->operands[i] == IA64_OPND_MR3)
7533 specs[count] = tmpl;
7534 specs[count++].index =
7535 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7540 /* Look for anything that reads a GR. */
7541 for (i = 0; i < NELEMS (idesc->operands); i++)
7543 if (idesc->operands[i] == IA64_OPND_MR3
7544 || idesc->operands[i] == IA64_OPND_CPUID_R3
7545 || idesc->operands[i] == IA64_OPND_DBR_R3
7546 || idesc->operands[i] == IA64_OPND_IBR_R3
7547 || idesc->operands[i] == IA64_OPND_MSR_R3
7548 || idesc->operands[i] == IA64_OPND_PKR_R3
7549 || idesc->operands[i] == IA64_OPND_PMC_R3
7550 || idesc->operands[i] == IA64_OPND_PMD_R3
7551 || idesc->operands[i] == IA64_OPND_RR_R3
7552 || ((i >= idesc->num_outputs)
7553 && (idesc->operands[i] == IA64_OPND_R1
7554 || idesc->operands[i] == IA64_OPND_R2
7555 || idesc->operands[i] == IA64_OPND_R3
7556 /* addl source register. */
7557 || idesc->operands[i] == IA64_OPND_R3_2)))
7559 specs[count] = tmpl;
7560 specs[count++].index =
7561 CURR_SLOT.opnd[i].X_add_number - REG_GR;
7572 /* This is the same as IA64_RS_PRr, except that the register range is
7573 from 1 - 15, and there are no rotating register reads/writes here. */
7577 for (i = 1; i < 16; i++)
7579 specs[count] = tmpl;
7580 specs[count++].index = i;
7586 /* Mark only those registers indicated by the mask. */
7589 mask = CURR_SLOT.opnd[2].X_add_number;
7590 for (i = 1; i < 16; i++)
7591 if (mask & ((valueT) 1 << i))
7593 specs[count] = tmpl;
7594 specs[count++].index = i;
7602 else if (note == 11) /* note 11 implies note 1 as well */
7606 for (i = 0; i < idesc->num_outputs; i++)
7608 if (idesc->operands[i] == IA64_OPND_P1
7609 || idesc->operands[i] == IA64_OPND_P2)
7611 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
7612 if (regno >= 1 && regno < 16)
7614 specs[count] = tmpl;
7615 specs[count++].index = regno;
7625 else if (note == 12)
7627 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
7629 specs[count] = tmpl;
7630 specs[count++].index = CURR_SLOT.qp_regno;
7637 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7638 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7639 int or_andcm = strstr(idesc->name, "or.andcm") != NULL;
7640 int and_orcm = strstr(idesc->name, "and.orcm") != NULL;
7642 if ((idesc->operands[0] == IA64_OPND_P1
7643 || idesc->operands[0] == IA64_OPND_P2)
7644 && p1 >= 1 && p1 < 16)
7646 specs[count] = tmpl;
7647 specs[count].cmp_type =
7648 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
7649 specs[count++].index = p1;
7651 if ((idesc->operands[1] == IA64_OPND_P1
7652 || idesc->operands[1] == IA64_OPND_P2)
7653 && p2 >= 1 && p2 < 16)
7655 specs[count] = tmpl;
7656 specs[count].cmp_type =
7657 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
7658 specs[count++].index = p2;
7663 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
7665 specs[count] = tmpl;
7666 specs[count++].index = CURR_SLOT.qp_regno;
7668 if (idesc->operands[1] == IA64_OPND_PR)
7670 for (i = 1; i < 16; i++)
7672 specs[count] = tmpl;
7673 specs[count++].index = i;
7684 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
7685 simplified cases of this. */
7689 for (i = 16; i < 63; i++)
7691 specs[count] = tmpl;
7692 specs[count++].index = i;
7698 /* Mark only those registers indicated by the mask. */
7700 && idesc->operands[0] == IA64_OPND_PR)
7702 mask = CURR_SLOT.opnd[2].X_add_number;
7703 if (mask & ((valueT) 1<<16))
7704 for (i = 16; i < 63; i++)
7706 specs[count] = tmpl;
7707 specs[count++].index = i;
7711 && idesc->operands[0] == IA64_OPND_PR_ROT)
7713 for (i = 16; i < 63; i++)
7715 specs[count] = tmpl;
7716 specs[count++].index = i;
7724 else if (note == 11) /* note 11 implies note 1 as well */
7728 for (i = 0; i < idesc->num_outputs; i++)
7730 if (idesc->operands[i] == IA64_OPND_P1
7731 || idesc->operands[i] == IA64_OPND_P2)
7733 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
7734 if (regno >= 16 && regno < 63)
7736 specs[count] = tmpl;
7737 specs[count++].index = regno;
7747 else if (note == 12)
7749 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
7751 specs[count] = tmpl;
7752 specs[count++].index = CURR_SLOT.qp_regno;
7759 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7760 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7761 int or_andcm = strstr(idesc->name, "or.andcm") != NULL;
7762 int and_orcm = strstr(idesc->name, "and.orcm") != NULL;
7764 if ((idesc->operands[0] == IA64_OPND_P1
7765 || idesc->operands[0] == IA64_OPND_P2)
7766 && p1 >= 16 && p1 < 63)
7768 specs[count] = tmpl;
7769 specs[count].cmp_type =
7770 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
7771 specs[count++].index = p1;
7773 if ((idesc->operands[1] == IA64_OPND_P1
7774 || idesc->operands[1] == IA64_OPND_P2)
7775 && p2 >= 16 && p2 < 63)
7777 specs[count] = tmpl;
7778 specs[count].cmp_type =
7779 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
7780 specs[count++].index = p2;
7785 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
7787 specs[count] = tmpl;
7788 specs[count++].index = CURR_SLOT.qp_regno;
7790 if (idesc->operands[1] == IA64_OPND_PR)
7792 for (i = 16; i < 63; i++)
7794 specs[count] = tmpl;
7795 specs[count++].index = i;
7807 /* Verify that the instruction is using the PSR bit indicated in
7811 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
7813 if (dep->regindex < 6)
7815 specs[count++] = tmpl;
7818 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
7820 if (dep->regindex < 32
7821 || dep->regindex == 35
7822 || dep->regindex == 36
7823 || (!rsrc_write && dep->regindex == PSR_CPL))
7825 specs[count++] = tmpl;
7828 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
7830 if (dep->regindex < 32
7831 || dep->regindex == 35
7832 || dep->regindex == 36
7833 || (rsrc_write && dep->regindex == PSR_CPL))
7835 specs[count++] = tmpl;
7840 /* Several PSR bits have very specific dependencies. */
7841 switch (dep->regindex)
7844 specs[count++] = tmpl;
7849 specs[count++] = tmpl;
7853 /* Only certain CR accesses use PSR.ic */
7854 if (idesc->operands[0] == IA64_OPND_CR3
7855 || idesc->operands[1] == IA64_OPND_CR3)
7858 ((idesc->operands[0] == IA64_OPND_CR3)
7861 CURR_SLOT.opnd[index].X_add_number - REG_CR;
7876 specs[count++] = tmpl;
7885 specs[count++] = tmpl;
7889 /* Only some AR accesses use cpl */
7890 if (idesc->operands[0] == IA64_OPND_AR3
7891 || idesc->operands[1] == IA64_OPND_AR3)
7894 ((idesc->operands[0] == IA64_OPND_AR3)
7897 CURR_SLOT.opnd[index].X_add_number - REG_AR;
7904 && regno <= AR_K7))))
7906 specs[count++] = tmpl;
7911 specs[count++] = tmpl;
7921 if (idesc->operands[0] == IA64_OPND_IMMU24)
7923 mask = CURR_SLOT.opnd[0].X_add_number;
7929 if (mask & ((valueT) 1 << dep->regindex))
7931 specs[count++] = tmpl;
7936 int min = dep->regindex == PSR_DFL ? 2 : 32;
7937 int max = dep->regindex == PSR_DFL ? 31 : 127;
7938 /* dfh is read on FR32-127; dfl is read on FR2-31 */
7939 for (i = 0; i < NELEMS (idesc->operands); i++)
7941 if (idesc->operands[i] == IA64_OPND_F1
7942 || idesc->operands[i] == IA64_OPND_F2
7943 || idesc->operands[i] == IA64_OPND_F3
7944 || idesc->operands[i] == IA64_OPND_F4)
7946 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
7947 if (reg >= min && reg <= max)
7949 specs[count++] = tmpl;
7956 int min = dep->regindex == PSR_MFL ? 2 : 32;
7957 int max = dep->regindex == PSR_MFL ? 31 : 127;
7958 /* mfh is read on writes to FR32-127; mfl is read on writes to
7960 for (i = 0; i < idesc->num_outputs; i++)
7962 if (idesc->operands[i] == IA64_OPND_F1)
7964 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
7965 if (reg >= min && reg <= max)
7967 specs[count++] = tmpl;
7972 else if (note == 10)
7974 for (i = 0; i < NELEMS (idesc->operands); i++)
7976 if (idesc->operands[i] == IA64_OPND_R1
7977 || idesc->operands[i] == IA64_OPND_R2
7978 || idesc->operands[i] == IA64_OPND_R3)
7980 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
7981 if (regno >= 16 && regno <= 31)
7983 specs[count++] = tmpl;
7994 case IA64_RS_AR_FPSR:
7995 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7997 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7998 if (regno == AR_FPSR)
8000 specs[count++] = tmpl;
8005 specs[count++] = tmpl;
8010 /* Handle all AR[REG] resources */
8011 if (note == 0 || note == 1)
8013 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8014 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8015 && regno == dep->regindex)
8017 specs[count++] = tmpl;
8019 /* other AR[REG] resources may be affected by AR accesses */
8020 else if (idesc->operands[0] == IA64_OPND_AR3)
8023 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8024 switch (dep->regindex)
8030 if (regno == AR_BSPSTORE)
8032 specs[count++] = tmpl;
8036 (regno == AR_BSPSTORE
8037 || regno == AR_RNAT))
8039 specs[count++] = tmpl;
8044 else if (idesc->operands[1] == IA64_OPND_AR3)
8047 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8048 switch (dep->regindex)
8053 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8055 specs[count++] = tmpl;
8062 specs[count++] = tmpl;
8072 /* Handle all CR[REG] resources */
8073 if (note == 0 || note == 1)
8075 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8077 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8078 if (regno == dep->regindex)
8080 specs[count++] = tmpl;
8082 else if (!rsrc_write)
8084 /* Reads from CR[IVR] affect other resources. */
8085 if (regno == CR_IVR)
8087 if ((dep->regindex >= CR_IRR0
8088 && dep->regindex <= CR_IRR3)
8089 || dep->regindex == CR_TPR)
8091 specs[count++] = tmpl;
8098 specs[count++] = tmpl;
8107 case IA64_RS_INSERVICE:
8108 /* look for write of EOI (67) or read of IVR (65) */
8109 if ((idesc->operands[0] == IA64_OPND_CR3
8110 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8111 || (idesc->operands[1] == IA64_OPND_CR3
8112 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8114 specs[count++] = tmpl;
8121 specs[count++] = tmpl;
8132 specs[count++] = tmpl;
8136 /* Check if any of the registers accessed are in the rotating region.
8137 mov to/from pr accesses CFM only when qp_regno is in the rotating
8139 for (i = 0; i < NELEMS (idesc->operands); i++)
8141 if (idesc->operands[i] == IA64_OPND_R1
8142 || idesc->operands[i] == IA64_OPND_R2
8143 || idesc->operands[i] == IA64_OPND_R3)
8145 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8146 /* Assumes that md.rot.num_regs is always valid */
8147 if (md.rot.num_regs > 0
8149 && num < 31 + md.rot.num_regs)
8151 specs[count] = tmpl;
8152 specs[count++].specific = 0;
8155 else if (idesc->operands[i] == IA64_OPND_F1
8156 || idesc->operands[i] == IA64_OPND_F2
8157 || idesc->operands[i] == IA64_OPND_F3
8158 || idesc->operands[i] == IA64_OPND_F4)
8160 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8163 specs[count] = tmpl;
8164 specs[count++].specific = 0;
8167 else if (idesc->operands[i] == IA64_OPND_P1
8168 || idesc->operands[i] == IA64_OPND_P2)
8170 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8173 specs[count] = tmpl;
8174 specs[count++].specific = 0;
8178 if (CURR_SLOT.qp_regno > 15)
8180 specs[count] = tmpl;
8181 specs[count++].specific = 0;
8186 /* This is the same as IA64_RS_PRr, except simplified to account for
8187 the fact that there is only one register. */
8191 specs[count++] = tmpl;
8196 if (idesc->operands[2] == IA64_OPND_IMM17)
8197 mask = CURR_SLOT.opnd[2].X_add_number;
8198 if (mask & ((valueT) 1 << 63))
8199 specs[count++] = tmpl;
8201 else if (note == 11)
8203 if ((idesc->operands[0] == IA64_OPND_P1
8204 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8205 || (idesc->operands[1] == IA64_OPND_P2
8206 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8208 specs[count++] = tmpl;
8211 else if (note == 12)
8213 if (CURR_SLOT.qp_regno == 63)
8215 specs[count++] = tmpl;
8222 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8223 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8224 int or_andcm = strstr(idesc->name, "or.andcm") != NULL;
8225 int and_orcm = strstr(idesc->name, "and.orcm") != NULL;
8228 && (idesc->operands[0] == IA64_OPND_P1
8229 || idesc->operands[0] == IA64_OPND_P2))
8231 specs[count] = tmpl;
8232 specs[count++].cmp_type =
8233 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8236 && (idesc->operands[1] == IA64_OPND_P1
8237 || idesc->operands[1] == IA64_OPND_P2))
8239 specs[count] = tmpl;
8240 specs[count++].cmp_type =
8241 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8246 if (CURR_SLOT.qp_regno == 63)
8248 specs[count++] = tmpl;
8259 /* FIXME we can identify some individual RSE written resources, but RSE
8260 read resources have not yet been completely identified, so for now
8261 treat RSE as a single resource */
8262 if (strncmp (idesc->name, "mov", 3) == 0)
8266 if (idesc->operands[0] == IA64_OPND_AR3
8267 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8269 specs[count] = tmpl;
8270 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8275 if (idesc->operands[0] == IA64_OPND_AR3)
8277 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8278 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8280 specs[count++] = tmpl;
8283 else if (idesc->operands[1] == IA64_OPND_AR3)
8285 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8286 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8287 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8289 specs[count++] = tmpl;
8296 specs[count++] = tmpl;
8301 /* FIXME -- do any of these need to be non-specific? */
8302 specs[count++] = tmpl;
8306 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8313 /* Clear branch flags on marked resources. This breaks the link between the
8314 QP of the marking instruction and a subsequent branch on the same QP. */
8317 clear_qp_branch_flag (mask)
8321 for (i = 0; i < regdepslen; i++)
8323 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8324 if ((bit & mask) != 0)
8326 regdeps[i].link_to_qp_branch = 0;
8331 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8333 Any changes to a PR clears the mutex relations which include that PR. */
8336 clear_qp_mutex (mask)
8342 while (i < qp_mutexeslen)
8344 if ((qp_mutexes[i].prmask & mask) != 0)
8348 fprintf (stderr, " Clearing mutex relation");
8349 print_prmask (qp_mutexes[i].prmask);
8350 fprintf (stderr, "\n");
8352 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8359 /* Clear implies relations which contain PRs in the given masks.
8360 P1_MASK indicates the source of the implies relation, while P2_MASK
8361 indicates the implied PR. */
8364 clear_qp_implies (p1_mask, p2_mask)
8371 while (i < qp_implieslen)
8373 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8374 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8377 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8378 qp_implies[i].p1, qp_implies[i].p2);
8379 qp_implies[i] = qp_implies[--qp_implieslen];
8386 /* Add the PRs specified to the list of implied relations. */
8389 add_qp_imply (p1, p2)
8396 /* p0 is not meaningful here. */
8397 if (p1 == 0 || p2 == 0)
8403 /* If it exists already, ignore it. */
8404 for (i = 0; i < qp_implieslen; i++)
8406 if (qp_implies[i].p1 == p1
8407 && qp_implies[i].p2 == p2
8408 && qp_implies[i].path == md.path
8409 && !qp_implies[i].p2_branched)
8413 if (qp_implieslen == qp_impliestotlen)
8415 qp_impliestotlen += 20;
8416 qp_implies = (struct qp_imply *)
8417 xrealloc ((void *) qp_implies,
8418 qp_impliestotlen * sizeof (struct qp_imply));
8421 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
8422 qp_implies[qp_implieslen].p1 = p1;
8423 qp_implies[qp_implieslen].p2 = p2;
8424 qp_implies[qp_implieslen].path = md.path;
8425 qp_implies[qp_implieslen++].p2_branched = 0;
8427 /* Add in the implied transitive relations; for everything that p2 implies,
8428 make p1 imply that, too; for everything that implies p1, make it imply p2
8430 for (i = 0; i < qp_implieslen; i++)
8432 if (qp_implies[i].p1 == p2)
8433 add_qp_imply (p1, qp_implies[i].p2);
8434 if (qp_implies[i].p2 == p1)
8435 add_qp_imply (qp_implies[i].p1, p2);
8437 /* Add in mutex relations implied by this implies relation; for each mutex
8438 relation containing p2, duplicate it and replace p2 with p1. */
8439 bit = (valueT) 1 << p1;
8440 mask = (valueT) 1 << p2;
8441 for (i = 0; i < qp_mutexeslen; i++)
8443 if (qp_mutexes[i].prmask & mask)
8444 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
8448 /* Add the PRs specified in the mask to the mutex list; this means that only
8449 one of the PRs can be true at any time. PR0 should never be included in
8459 if (qp_mutexeslen == qp_mutexestotlen)
8461 qp_mutexestotlen += 20;
8462 qp_mutexes = (struct qpmutex *)
8463 xrealloc ((void *) qp_mutexes,
8464 qp_mutexestotlen * sizeof (struct qpmutex));
8468 fprintf (stderr, " Registering mutex on");
8469 print_prmask (mask);
8470 fprintf (stderr, "\n");
8472 qp_mutexes[qp_mutexeslen].path = md.path;
8473 qp_mutexes[qp_mutexeslen++].prmask = mask;
8477 clear_register_values ()
8481 fprintf (stderr, " Clearing register values\n");
8482 for (i = 1; i < NELEMS (gr_values); i++)
8483 gr_values[i].known = 0;
8486 /* Keep track of register values/changes which affect DV tracking.
8488 optimization note: should add a flag to classes of insns where otherwise we
8489 have to examine a group of strings to identify them. */
8492 note_register_values (idesc)
8493 struct ia64_opcode *idesc;
8495 valueT qp_changemask = 0;
8498 /* Invalidate values for registers being written to. */
8499 for (i = 0; i < idesc->num_outputs; i++)
8501 if (idesc->operands[i] == IA64_OPND_R1
8502 || idesc->operands[i] == IA64_OPND_R2
8503 || idesc->operands[i] == IA64_OPND_R3)
8505 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8506 if (regno > 0 && regno < NELEMS (gr_values))
8507 gr_values[regno].known = 0;
8509 else if (idesc->operands[i] == IA64_OPND_R3_2)
8511 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8512 if (regno > 0 && regno < 4)
8513 gr_values[regno].known = 0;
8515 else if (idesc->operands[i] == IA64_OPND_P1
8516 || idesc->operands[i] == IA64_OPND_P2)
8518 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8519 qp_changemask |= (valueT) 1 << regno;
8521 else if (idesc->operands[i] == IA64_OPND_PR)
8523 if (idesc->operands[2] & (valueT) 0x10000)
8524 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
8526 qp_changemask = idesc->operands[2];
8529 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
8531 if (idesc->operands[1] & ((valueT) 1 << 43))
8532 qp_changemask = ~(valueT) 0xFFFFFFFFFFF | idesc->operands[1];
8534 qp_changemask = idesc->operands[1];
8535 qp_changemask &= ~(valueT) 0xFFFF;
8540 /* Always clear qp branch flags on any PR change. */
8541 /* FIXME there may be exceptions for certain compares. */
8542 clear_qp_branch_flag (qp_changemask);
8544 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
8545 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
8547 qp_changemask |= ~(valueT) 0xFFFF;
8548 if (strcmp (idesc->name, "clrrrb.pr") != 0)
8550 for (i = 32; i < 32 + md.rot.num_regs; i++)
8551 gr_values[i].known = 0;
8553 clear_qp_mutex (qp_changemask);
8554 clear_qp_implies (qp_changemask, qp_changemask);
8556 /* After a call, all register values are undefined, except those marked
8558 else if (strncmp (idesc->name, "br.call", 6) == 0
8559 || strncmp (idesc->name, "brl.call", 7) == 0)
8561 /* FIXME keep GR values which are marked as "safe_across_calls" */
8562 clear_register_values ();
8563 clear_qp_mutex (~qp_safe_across_calls);
8564 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
8565 clear_qp_branch_flag (~qp_safe_across_calls);
8567 else if (is_interruption_or_rfi (idesc)
8568 || is_taken_branch (idesc))
8570 clear_register_values ();
8571 clear_qp_mutex (~(valueT) 0);
8572 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
8574 /* Look for mutex and implies relations. */
8575 else if ((idesc->operands[0] == IA64_OPND_P1
8576 || idesc->operands[0] == IA64_OPND_P2)
8577 && (idesc->operands[1] == IA64_OPND_P1
8578 || idesc->operands[1] == IA64_OPND_P2))
8580 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8581 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8582 valueT p1mask = (valueT) 1 << p1;
8583 valueT p2mask = (valueT) 1 << p2;
8585 /* If one of the PRs is PR0, we can't really do anything. */
8586 if (p1 == 0 || p2 == 0)
8589 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
8591 /* In general, clear mutexes and implies which include P1 or P2,
8592 with the following exceptions. */
8593 else if (strstr (idesc->name, ".or.andcm") != NULL)
8595 add_qp_mutex (p1mask | p2mask);
8596 clear_qp_implies (p2mask, p1mask);
8598 else if (strstr (idesc->name, ".and.orcm") != NULL)
8600 add_qp_mutex (p1mask | p2mask);
8601 clear_qp_implies (p1mask, p2mask);
8603 else if (strstr (idesc->name, ".and") != NULL)
8605 clear_qp_implies (0, p1mask | p2mask);
8607 else if (strstr (idesc->name, ".or") != NULL)
8609 clear_qp_mutex (p1mask | p2mask);
8610 clear_qp_implies (p1mask | p2mask, 0);
8614 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
8615 if (strstr (idesc->name, ".unc") != NULL)
8617 add_qp_mutex (p1mask | p2mask);
8618 if (CURR_SLOT.qp_regno != 0)
8620 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
8621 CURR_SLOT.qp_regno);
8622 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
8623 CURR_SLOT.qp_regno);
8626 else if (CURR_SLOT.qp_regno == 0)
8628 add_qp_mutex (p1mask | p2mask);
8632 clear_qp_mutex (p1mask | p2mask);
8636 /* Look for mov imm insns into GRs. */
8637 else if (idesc->operands[0] == IA64_OPND_R1
8638 && (idesc->operands[1] == IA64_OPND_IMM22
8639 || idesc->operands[1] == IA64_OPND_IMMU64)
8640 && (strcmp (idesc->name, "mov") == 0
8641 || strcmp (idesc->name, "movl") == 0))
8643 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8644 if (regno > 0 && regno < NELEMS (gr_values))
8646 gr_values[regno].known = 1;
8647 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
8648 gr_values[regno].path = md.path;
8651 fprintf (stderr, " Know gr%d = ", regno);
8652 fprintf_vma (stderr, gr_values[regno].value);
8653 fputs ("\n", stderr);
8659 clear_qp_mutex (qp_changemask);
8660 clear_qp_implies (qp_changemask, qp_changemask);
8664 /* Return whether the given predicate registers are currently mutex. */
8667 qp_mutex (p1, p2, path)
8677 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
8678 for (i = 0; i < qp_mutexeslen; i++)
8680 if (qp_mutexes[i].path >= path
8681 && (qp_mutexes[i].prmask & mask) == mask)
8688 /* Return whether the given resource is in the given insn's list of chks
8689 Return 1 if the conflict is absolutely determined, 2 if it's a potential
8693 resources_match (rs, idesc, note, qp_regno, path)
8695 struct ia64_opcode *idesc;
8700 struct rsrc specs[MAX_SPECS];
8703 /* If the marked resource's qp_regno and the given qp_regno are mutex,
8704 we don't need to check. One exception is note 11, which indicates that
8705 target predicates are written regardless of PR[qp]. */
8706 if (qp_mutex (rs->qp_regno, qp_regno, path)
8710 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
8713 /* UNAT checking is a bit more specific than other resources */
8714 if (rs->dependency->specifier == IA64_RS_AR_UNAT
8715 && specs[count].mem_offset.hint
8716 && rs->mem_offset.hint)
8718 if (rs->mem_offset.base == specs[count].mem_offset.base)
8720 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
8721 ((specs[count].mem_offset.offset >> 3) & 0x3F))
8728 /* Skip apparent PR write conflicts where both writes are an AND or both
8729 writes are an OR. */
8730 if (rs->dependency->specifier == IA64_RS_PR
8731 || rs->dependency->specifier == IA64_RS_PRr
8732 || rs->dependency->specifier == IA64_RS_PR63)
8734 if (specs[count].cmp_type != CMP_NONE
8735 && specs[count].cmp_type == rs->cmp_type)
8738 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
8739 dv_mode[rs->dependency->mode],
8740 rs->dependency->specifier != IA64_RS_PR63 ?
8741 specs[count].index : 63);
8746 " %s on parallel compare conflict %s vs %s on PR%d\n",
8747 dv_mode[rs->dependency->mode],
8748 dv_cmp_type[rs->cmp_type],
8749 dv_cmp_type[specs[count].cmp_type],
8750 rs->dependency->specifier != IA64_RS_PR63 ?
8751 specs[count].index : 63);
8755 /* If either resource is not specific, conservatively assume a conflict
8757 if (!specs[count].specific || !rs->specific)
8759 else if (specs[count].index == rs->index)
8764 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
8770 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
8771 insert a stop to create the break. Update all resource dependencies
8772 appropriately. If QP_REGNO is non-zero, only apply the break to resources
8773 which use the same QP_REGNO and have the link_to_qp_branch flag set.
8774 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
8778 insn_group_break (insert_stop, qp_regno, save_current)
8785 if (insert_stop && md.num_slots_in_use > 0)
8786 PREV_SLOT.end_of_insn_group = 1;
8790 fprintf (stderr, " Insn group break%s",
8791 (insert_stop ? " (w/stop)" : ""));
8793 fprintf (stderr, " effective for QP=%d", qp_regno);
8794 fprintf (stderr, "\n");
8798 while (i < regdepslen)
8800 const struct ia64_dependency *dep = regdeps[i].dependency;
8803 && regdeps[i].qp_regno != qp_regno)
8810 && CURR_SLOT.src_file == regdeps[i].file
8811 && CURR_SLOT.src_line == regdeps[i].line)
8817 /* clear dependencies which are automatically cleared by a stop, or
8818 those that have reached the appropriate state of insn serialization */
8819 if (dep->semantics == IA64_DVS_IMPLIED
8820 || dep->semantics == IA64_DVS_IMPLIEDF
8821 || regdeps[i].insn_srlz == STATE_SRLZ)
8823 print_dependency ("Removing", i);
8824 regdeps[i] = regdeps[--regdepslen];
8828 if (dep->semantics == IA64_DVS_DATA
8829 || dep->semantics == IA64_DVS_INSTR
8830 || dep->semantics == IA64_DVS_SPECIFIC)
8832 if (regdeps[i].insn_srlz == STATE_NONE)
8833 regdeps[i].insn_srlz = STATE_STOP;
8834 if (regdeps[i].data_srlz == STATE_NONE)
8835 regdeps[i].data_srlz = STATE_STOP;
8842 /* Add the given resource usage spec to the list of active dependencies. */
8845 mark_resource (idesc, dep, spec, depind, path)
8846 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
8847 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
8852 if (regdepslen == regdepstotlen)
8854 regdepstotlen += 20;
8855 regdeps = (struct rsrc *)
8856 xrealloc ((void *) regdeps,
8857 regdepstotlen * sizeof (struct rsrc));
8860 regdeps[regdepslen] = *spec;
8861 regdeps[regdepslen].depind = depind;
8862 regdeps[regdepslen].path = path;
8863 regdeps[regdepslen].file = CURR_SLOT.src_file;
8864 regdeps[regdepslen].line = CURR_SLOT.src_line;
8866 print_dependency ("Adding", regdepslen);
8872 print_dependency (action, depind)
8878 fprintf (stderr, " %s %s '%s'",
8879 action, dv_mode[(regdeps[depind].dependency)->mode],
8880 (regdeps[depind].dependency)->name);
8881 if (regdeps[depind].specific && regdeps[depind].index != 0)
8882 fprintf (stderr, " (%d)", regdeps[depind].index);
8883 if (regdeps[depind].mem_offset.hint)
8885 fputs (" ", stderr);
8886 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
8887 fputs ("+", stderr);
8888 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
8890 fprintf (stderr, "\n");
8895 instruction_serialization ()
8899 fprintf (stderr, " Instruction serialization\n");
8900 for (i = 0; i < regdepslen; i++)
8901 if (regdeps[i].insn_srlz == STATE_STOP)
8902 regdeps[i].insn_srlz = STATE_SRLZ;
8906 data_serialization ()
8910 fprintf (stderr, " Data serialization\n");
8911 while (i < regdepslen)
8913 if (regdeps[i].data_srlz == STATE_STOP
8914 /* Note: as of 991210, all "other" dependencies are cleared by a
8915 data serialization. This might change with new tables */
8916 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
8918 print_dependency ("Removing", i);
8919 regdeps[i] = regdeps[--regdepslen];
8926 /* Insert stops and serializations as needed to avoid DVs. */
8929 remove_marked_resource (rs)
8932 switch (rs->dependency->semantics)
8934 case IA64_DVS_SPECIFIC:
8936 fprintf (stderr, "Implementation-specific, assume worst case...\n");
8937 /* ...fall through... */
8938 case IA64_DVS_INSTR:
8940 fprintf (stderr, "Inserting instr serialization\n");
8941 if (rs->insn_srlz < STATE_STOP)
8942 insn_group_break (1, 0, 0);
8943 if (rs->insn_srlz < STATE_SRLZ)
8945 int oldqp = CURR_SLOT.qp_regno;
8946 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
8947 /* Manually jam a srlz.i insn into the stream */
8948 CURR_SLOT.qp_regno = 0;
8949 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
8950 instruction_serialization ();
8951 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
8952 if (++md.num_slots_in_use >= NUM_SLOTS)
8954 CURR_SLOT.qp_regno = oldqp;
8955 CURR_SLOT.idesc = oldidesc;
8957 insn_group_break (1, 0, 0);
8959 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
8960 "other" types of DV are eliminated
8961 by a data serialization */
8964 fprintf (stderr, "Inserting data serialization\n");
8965 if (rs->data_srlz < STATE_STOP)
8966 insn_group_break (1, 0, 0);
8968 int oldqp = CURR_SLOT.qp_regno;
8969 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
8970 /* Manually jam a srlz.d insn into the stream */
8971 CURR_SLOT.qp_regno = 0;
8972 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
8973 data_serialization ();
8974 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
8975 if (++md.num_slots_in_use >= NUM_SLOTS)
8977 CURR_SLOT.qp_regno = oldqp;
8978 CURR_SLOT.idesc = oldidesc;
8981 case IA64_DVS_IMPLIED:
8982 case IA64_DVS_IMPLIEDF:
8984 fprintf (stderr, "Inserting stop\n");
8985 insn_group_break (1, 0, 0);
8992 /* Check the resources used by the given opcode against the current dependency
8995 The check is run once for each execution path encountered. In this case,
8996 a unique execution path is the sequence of instructions following a code
8997 entry point, e.g. the following has three execution paths, one starting
8998 at L0, one at L1, and one at L2.
9007 check_dependencies (idesc)
9008 struct ia64_opcode *idesc;
9010 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9014 /* Note that the number of marked resources may change within the
9015 loop if in auto mode. */
9017 while (i < regdepslen)
9019 struct rsrc *rs = ®deps[i];
9020 const struct ia64_dependency *dep = rs->dependency;
9025 if (dep->semantics == IA64_DVS_NONE
9026 || (chkind = depends_on (rs->depind, idesc)) == -1)
9032 note = NOTE (opdeps->chks[chkind]);
9034 /* Check this resource against each execution path seen thus far. */
9035 for (path = 0; path <= md.path; path++)
9039 /* If the dependency wasn't on the path being checked, ignore it. */
9040 if (rs->path < path)
9043 /* If the QP for this insn implies a QP which has branched, don't
9044 bother checking. Ed. NOTE: I don't think this check is terribly
9045 useful; what's the point of generating code which will only be
9046 reached if its QP is zero?
9047 This code was specifically inserted to handle the following code,
9048 based on notes from Intel's DV checking code, where p1 implies p2.
9054 if (CURR_SLOT.qp_regno != 0)
9058 for (implies = 0; implies < qp_implieslen; implies++)
9060 if (qp_implies[implies].path >= path
9061 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9062 && qp_implies[implies].p2_branched)
9072 if ((matchtype = resources_match (rs, idesc, note,
9073 CURR_SLOT.qp_regno, path)) != 0)
9076 char pathmsg[256] = "";
9077 char indexmsg[256] = "";
9078 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9081 sprintf (pathmsg, " when entry is at label '%s'",
9082 md.entry_labels[path - 1]);
9083 if (rs->specific && rs->index != 0)
9084 sprintf (indexmsg, ", specific resource number is %d",
9086 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9088 (certain ? "violates" : "may violate"),
9089 dv_mode[dep->mode], dep->name,
9090 dv_sem[dep->semantics],
9093 if (md.explicit_mode)
9095 as_warn ("%s", msg);
9097 as_warn (_("Only the first path encountering the conflict "
9099 as_warn_where (rs->file, rs->line,
9100 _("This is the location of the "
9101 "conflicting usage"));
9102 /* Don't bother checking other paths, to avoid duplicating
9109 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9111 remove_marked_resource (rs);
9113 /* since the set of dependencies has changed, start over */
9114 /* FIXME -- since we're removing dvs as we go, we
9115 probably don't really need to start over... */
9128 /* Register new dependencies based on the given opcode. */
9131 mark_resources (idesc)
9132 struct ia64_opcode *idesc;
9135 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9136 int add_only_qp_reads = 0;
9138 /* A conditional branch only uses its resources if it is taken; if it is
9139 taken, we stop following that path. The other branch types effectively
9140 *always* write their resources. If it's not taken, register only QP
9142 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9144 add_only_qp_reads = 1;
9148 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9150 for (i = 0; i < opdeps->nregs; i++)
9152 const struct ia64_dependency *dep;
9153 struct rsrc specs[MAX_SPECS];
9158 dep = ia64_find_dependency (opdeps->regs[i]);
9159 note = NOTE (opdeps->regs[i]);
9161 if (add_only_qp_reads
9162 && !(dep->mode == IA64_DV_WAR
9163 && (dep->specifier == IA64_RS_PR
9164 || dep->specifier == IA64_RS_PRr
9165 || dep->specifier == IA64_RS_PR63)))
9168 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9171 if (md.debug_dv && !count)
9172 fprintf (stderr, " No %s %s usage found (path %d)\n",
9173 dv_mode[dep->mode], dep->name, md.path);
9178 mark_resource (idesc, dep, &specs[count],
9179 DEP (opdeps->regs[i]), md.path);
9182 /* The execution path may affect register values, which may in turn
9183 affect which indirect-access resources are accessed. */
9184 switch (dep->specifier)
9196 for (path = 0; path < md.path; path++)
9198 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9200 mark_resource (idesc, dep, &specs[count],
9201 DEP (opdeps->regs[i]), path);
9208 /* Remove dependencies when they no longer apply. */
9211 update_dependencies (idesc)
9212 struct ia64_opcode *idesc;
9216 if (strcmp (idesc->name, "srlz.i") == 0)
9218 instruction_serialization ();
9220 else if (strcmp (idesc->name, "srlz.d") == 0)
9222 data_serialization ();
9224 else if (is_interruption_or_rfi (idesc)
9225 || is_taken_branch (idesc))
9227 /* Although technically the taken branch doesn't clear dependencies
9228 which require a srlz.[id], we don't follow the branch; the next
9229 instruction is assumed to start with a clean slate. */
9233 else if (is_conditional_branch (idesc)
9234 && CURR_SLOT.qp_regno != 0)
9236 int is_call = strstr (idesc->name, ".call") != NULL;
9238 for (i = 0; i < qp_implieslen; i++)
9240 /* If the conditional branch's predicate is implied by the predicate
9241 in an existing dependency, remove that dependency. */
9242 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9245 /* Note that this implied predicate takes a branch so that if
9246 a later insn generates a DV but its predicate implies this
9247 one, we can avoid the false DV warning. */
9248 qp_implies[i].p2_branched = 1;
9249 while (depind < regdepslen)
9251 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9253 print_dependency ("Removing", depind);
9254 regdeps[depind] = regdeps[--regdepslen];
9261 /* Any marked resources which have this same predicate should be
9262 cleared, provided that the QP hasn't been modified between the
9263 marking instruction and the branch. */
9266 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9271 while (i < regdepslen)
9273 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9274 && regdeps[i].link_to_qp_branch
9275 && (regdeps[i].file != CURR_SLOT.src_file
9276 || regdeps[i].line != CURR_SLOT.src_line))
9278 /* Treat like a taken branch */
9279 print_dependency ("Removing", i);
9280 regdeps[i] = regdeps[--regdepslen];
9289 /* Examine the current instruction for dependency violations. */
9293 struct ia64_opcode *idesc;
9297 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9298 idesc->name, CURR_SLOT.src_line,
9299 idesc->dependencies->nchks,
9300 idesc->dependencies->nregs);
9303 /* Look through the list of currently marked resources; if the current
9304 instruction has the dependency in its chks list which uses that resource,
9305 check against the specific resources used. */
9306 check_dependencies (idesc);
9308 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9309 then add them to the list of marked resources. */
9310 mark_resources (idesc);
9312 /* There are several types of dependency semantics, and each has its own
9313 requirements for being cleared
9315 Instruction serialization (insns separated by interruption, rfi, or
9316 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9318 Data serialization (instruction serialization, or writer + srlz.d +
9319 reader, where writer and srlz.d are in separate groups) clears
9320 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9321 always be the case).
9323 Instruction group break (groups separated by stop, taken branch,
9324 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9326 update_dependencies (idesc);
9328 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9329 warning. Keep track of as many as possible that are useful. */
9330 note_register_values (idesc);
9332 /* We don't need or want this anymore. */
9333 md.mem_offset.hint = 0;
9338 /* Translate one line of assembly. Pseudo ops and labels do not show
9344 char *saved_input_line_pointer, *mnemonic;
9345 const struct pseudo_opcode *pdesc;
9346 struct ia64_opcode *idesc;
9347 unsigned char qp_regno;
9351 saved_input_line_pointer = input_line_pointer;
9352 input_line_pointer = str;
9354 /* extract the opcode (mnemonic): */
9356 mnemonic = input_line_pointer;
9357 ch = get_symbol_end ();
9358 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9361 *input_line_pointer = ch;
9362 (*pdesc->handler) (pdesc->arg);
9366 /* Find the instruction descriptor matching the arguments. */
9368 idesc = ia64_find_opcode (mnemonic);
9369 *input_line_pointer = ch;
9372 as_bad ("Unknown opcode `%s'", mnemonic);
9376 idesc = parse_operands (idesc);
9380 /* Handle the dynamic ops we can handle now: */
9381 if (idesc->type == IA64_TYPE_DYN)
9383 if (strcmp (idesc->name, "add") == 0)
9385 if (CURR_SLOT.opnd[2].X_op == O_register
9386 && CURR_SLOT.opnd[2].X_add_number < 4)
9390 ia64_free_opcode (idesc);
9391 idesc = ia64_find_opcode (mnemonic);
9393 know (!idesc->next);
9396 else if (strcmp (idesc->name, "mov") == 0)
9398 enum ia64_opnd opnd1, opnd2;
9401 opnd1 = idesc->operands[0];
9402 opnd2 = idesc->operands[1];
9403 if (opnd1 == IA64_OPND_AR3)
9405 else if (opnd2 == IA64_OPND_AR3)
9409 if (CURR_SLOT.opnd[rop].X_op == O_register
9410 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
9414 ia64_free_opcode (idesc);
9415 idesc = ia64_find_opcode (mnemonic);
9416 while (idesc != NULL
9417 && (idesc->operands[0] != opnd1
9418 || idesc->operands[1] != opnd2))
9419 idesc = get_next_opcode (idesc);
9424 if (md.qp.X_op == O_register)
9426 qp_regno = md.qp.X_add_number - REG_P;
9427 md.qp.X_op = O_absent;
9430 flags = idesc->flags;
9432 if ((flags & IA64_OPCODE_FIRST) != 0)
9433 insn_group_break (1, 0, 0);
9435 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
9437 as_bad ("`%s' cannot be predicated", idesc->name);
9441 /* Build the instruction. */
9442 CURR_SLOT.qp_regno = qp_regno;
9443 CURR_SLOT.idesc = idesc;
9444 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
9445 dwarf2_where (&CURR_SLOT.debug_line);
9447 /* Add unwind entry, if there is one. */
9448 if (unwind.current_entry)
9450 CURR_SLOT.unwind_record = unwind.current_entry;
9451 unwind.current_entry = NULL;
9454 /* Check for dependency violations. */
9458 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9459 if (++md.num_slots_in_use >= NUM_SLOTS)
9462 if ((flags & IA64_OPCODE_LAST) != 0)
9463 insn_group_break (1, 0, 0);
9465 md.last_text_seg = now_seg;
9468 input_line_pointer = saved_input_line_pointer;
9471 /* Called when symbol NAME cannot be found in the symbol table.
9472 Should be used for dynamic valued symbols only. */
9475 md_undefined_symbol (name)
9476 char *name ATTRIBUTE_UNUSED;
9481 /* Called for any expression that can not be recognized. When the
9482 function is called, `input_line_pointer' will point to the start of
9489 enum pseudo_type pseudo_type;
9494 switch (*input_line_pointer)
9497 /* Find what relocation pseudo-function we're dealing with. */
9499 ch = *++input_line_pointer;
9500 for (i = 0; i < NELEMS (pseudo_func); ++i)
9501 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
9503 len = strlen (pseudo_func[i].name);
9504 if (strncmp (pseudo_func[i].name + 1,
9505 input_line_pointer + 1, len - 1) == 0
9506 && !is_part_of_name (input_line_pointer[len]))
9508 input_line_pointer += len;
9509 pseudo_type = pseudo_func[i].type;
9513 switch (pseudo_type)
9515 case PSEUDO_FUNC_RELOC:
9517 if (*input_line_pointer != '(')
9519 as_bad ("Expected '('");
9523 ++input_line_pointer;
9525 if (*input_line_pointer++ != ')')
9527 as_bad ("Missing ')'");
9530 if (e->X_op != O_symbol)
9532 if (e->X_op != O_pseudo_fixup)
9534 as_bad ("Not a symbolic expression");
9537 if (S_GET_VALUE (e->X_op_symbol) == FUNC_FPTR_RELATIVE
9538 && i == FUNC_LT_RELATIVE)
9539 i = FUNC_LT_FPTR_RELATIVE;
9542 as_bad ("Illegal combination of relocation functions");
9546 /* Make sure gas doesn't get rid of local symbols that are used
9548 e->X_op = O_pseudo_fixup;
9549 e->X_op_symbol = pseudo_func[i].u.sym;
9552 case PSEUDO_FUNC_CONST:
9553 e->X_op = O_constant;
9554 e->X_add_number = pseudo_func[i].u.ival;
9557 case PSEUDO_FUNC_REG:
9558 e->X_op = O_register;
9559 e->X_add_number = pseudo_func[i].u.ival;
9563 name = input_line_pointer - 1;
9565 as_bad ("Unknown pseudo function `%s'", name);
9571 ++input_line_pointer;
9573 if (*input_line_pointer != ']')
9575 as_bad ("Closing bracket misssing");
9580 if (e->X_op != O_register)
9581 as_bad ("Register expected as index");
9583 ++input_line_pointer;
9594 ignore_rest_of_line ();
9597 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
9598 a section symbol plus some offset. For relocs involving @fptr(),
9599 directives we don't want such adjustments since we need to have the
9600 original symbol's name in the reloc. */
9602 ia64_fix_adjustable (fix)
9605 /* Prevent all adjustments to global symbols */
9606 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
9609 switch (fix->fx_r_type)
9611 case BFD_RELOC_IA64_FPTR64I:
9612 case BFD_RELOC_IA64_FPTR32MSB:
9613 case BFD_RELOC_IA64_FPTR32LSB:
9614 case BFD_RELOC_IA64_FPTR64MSB:
9615 case BFD_RELOC_IA64_FPTR64LSB:
9616 case BFD_RELOC_IA64_LTOFF_FPTR22:
9617 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9627 ia64_force_relocation (fix)
9630 switch (fix->fx_r_type)
9632 case BFD_RELOC_IA64_FPTR64I:
9633 case BFD_RELOC_IA64_FPTR32MSB:
9634 case BFD_RELOC_IA64_FPTR32LSB:
9635 case BFD_RELOC_IA64_FPTR64MSB:
9636 case BFD_RELOC_IA64_FPTR64LSB:
9638 case BFD_RELOC_IA64_LTOFF22:
9639 case BFD_RELOC_IA64_LTOFF64I:
9640 case BFD_RELOC_IA64_LTOFF_FPTR22:
9641 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9642 case BFD_RELOC_IA64_PLTOFF22:
9643 case BFD_RELOC_IA64_PLTOFF64I:
9644 case BFD_RELOC_IA64_PLTOFF64MSB:
9645 case BFD_RELOC_IA64_PLTOFF64LSB:
9654 /* Decide from what point a pc-relative relocation is relative to,
9655 relative to the pc-relative fixup. Er, relatively speaking. */
9657 ia64_pcrel_from_section (fix, sec)
9661 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
9663 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
9669 /* This is called whenever some data item (not an instruction) needs a
9670 fixup. We pick the right reloc code depending on the byteorder
9671 currently in effect. */
9673 ia64_cons_fix_new (f, where, nbytes, exp)
9679 bfd_reloc_code_real_type code;
9684 /* There are no reloc for 8 and 16 bit quantities, but we allow
9685 them here since they will work fine as long as the expression
9686 is fully defined at the end of the pass over the source file. */
9687 case 1: code = BFD_RELOC_8; break;
9688 case 2: code = BFD_RELOC_16; break;
9690 if (target_big_endian)
9691 code = BFD_RELOC_IA64_DIR32MSB;
9693 code = BFD_RELOC_IA64_DIR32LSB;
9697 if (target_big_endian)
9698 code = BFD_RELOC_IA64_DIR64MSB;
9700 code = BFD_RELOC_IA64_DIR64LSB;
9704 as_bad ("Unsupported fixup size %d", nbytes);
9705 ignore_rest_of_line ();
9708 if (exp->X_op == O_pseudo_fixup)
9711 exp->X_op = O_symbol;
9712 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
9714 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
9715 /* We need to store the byte order in effect in case we're going
9716 to fix an 8 or 16 bit relocation (for which there no real
9717 relocs available). See md_apply_fix(). */
9718 fix->tc_fix_data.bigendian = target_big_endian;
9721 /* Return the actual relocation we wish to associate with the pseudo
9722 reloc described by SYM and R_TYPE. SYM should be one of the
9723 symbols in the pseudo_func array, or NULL. */
9725 static bfd_reloc_code_real_type
9726 ia64_gen_real_reloc_type (sym, r_type)
9728 bfd_reloc_code_real_type r_type;
9730 bfd_reloc_code_real_type new = 0;
9737 switch (S_GET_VALUE (sym))
9739 case FUNC_FPTR_RELATIVE:
9742 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
9743 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
9744 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
9745 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
9746 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
9751 case FUNC_GP_RELATIVE:
9754 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
9755 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
9756 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
9757 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
9758 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
9759 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
9764 case FUNC_LT_RELATIVE:
9767 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
9768 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
9773 case FUNC_PC_RELATIVE:
9776 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
9777 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
9778 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
9779 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
9780 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
9781 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
9786 case FUNC_PLT_RELATIVE:
9789 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
9790 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
9791 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
9792 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
9797 case FUNC_SEC_RELATIVE:
9800 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
9801 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
9802 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
9803 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
9808 case FUNC_SEG_RELATIVE:
9811 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
9812 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
9813 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
9814 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
9819 case FUNC_LTV_RELATIVE:
9822 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
9823 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
9824 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
9825 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
9830 case FUNC_LT_FPTR_RELATIVE:
9833 case BFD_RELOC_IA64_IMM22:
9834 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
9835 case BFD_RELOC_IA64_IMM64:
9836 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
9844 /* Hmmmm. Should this ever occur? */
9851 /* Here is where generate the appropriate reloc for pseudo relocation
9854 ia64_validate_fix (fix)
9857 switch (fix->fx_r_type)
9859 case BFD_RELOC_IA64_FPTR64I:
9860 case BFD_RELOC_IA64_FPTR32MSB:
9861 case BFD_RELOC_IA64_FPTR64LSB:
9862 case BFD_RELOC_IA64_LTOFF_FPTR22:
9863 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9864 if (fix->fx_offset != 0)
9865 as_bad_where (fix->fx_file, fix->fx_line,
9866 "No addend allowed in @fptr() relocation");
9876 fix_insn (fix, odesc, value)
9878 const struct ia64_operand *odesc;
9881 bfd_vma insn[3], t0, t1, control_bits;
9886 slot = fix->fx_where & 0x3;
9887 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
9889 /* Bundles are always in little-endian byte order */
9890 t0 = bfd_getl64 (fixpos);
9891 t1 = bfd_getl64 (fixpos + 8);
9892 control_bits = t0 & 0x1f;
9893 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
9894 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
9895 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
9898 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
9900 insn[1] = (value >> 22) & 0x1ffffffffffLL;
9901 insn[2] |= (((value & 0x7f) << 13)
9902 | (((value >> 7) & 0x1ff) << 27)
9903 | (((value >> 16) & 0x1f) << 22)
9904 | (((value >> 21) & 0x1) << 21)
9905 | (((value >> 63) & 0x1) << 36));
9907 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
9909 if (value & ~0x3fffffffffffffffULL)
9910 err = "integer operand out of range";
9911 insn[1] = (value >> 21) & 0x1ffffffffffLL;
9912 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
9914 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
9917 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
9918 insn[2] |= ((((value >> 59) & 0x1) << 36)
9919 | (((value >> 0) & 0xfffff) << 13));
9922 err = (*odesc->insert) (odesc, value, insn + slot);
9925 as_bad_where (fix->fx_file, fix->fx_line, err);
9927 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
9928 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
9929 number_to_chars_littleendian (fixpos + 0, t0, 8);
9930 number_to_chars_littleendian (fixpos + 8, t1, 8);
9933 /* Attempt to simplify or even eliminate a fixup. The return value is
9934 ignored; perhaps it was once meaningful, but now it is historical.
9935 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
9937 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
9940 md_apply_fix3 (fix, valuep, seg)
9943 segT seg ATTRIBUTE_UNUSED;
9946 valueT value = *valuep;
9949 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
9953 switch (fix->fx_r_type)
9955 case BFD_RELOC_IA64_DIR32MSB:
9956 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
9960 case BFD_RELOC_IA64_DIR32LSB:
9961 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
9965 case BFD_RELOC_IA64_DIR64MSB:
9966 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
9970 case BFD_RELOC_IA64_DIR64LSB:
9971 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
9981 if (fix->fx_r_type == (int) BFD_RELOC_UNUSED)
9983 /* This must be a TAG13 or TAG13b operand. There are no external
9984 relocs defined for them, so we must give an error. */
9985 as_bad_where (fix->fx_file, fix->fx_line,
9986 "%s must have a constant value",
9987 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
9992 /* ??? This is a hack copied from tc-i386.c to make PCREL relocs
9993 work. There should be a better way to handle this. */
9995 fix->fx_offset += fix->fx_where + fix->fx_frag->fr_address;
9997 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
9999 if (fix->tc_fix_data.bigendian)
10000 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10002 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10008 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10015 /* Generate the BFD reloc to be stuck in the object file from the
10016 fixup used internally in the assembler. */
10019 tc_gen_reloc (sec, fixp)
10020 asection *sec ATTRIBUTE_UNUSED;
10025 reloc = xmalloc (sizeof (*reloc));
10026 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10027 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10028 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10029 reloc->addend = fixp->fx_offset;
10030 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10034 as_bad_where (fixp->fx_file, fixp->fx_line,
10035 "Cannot represent %s relocation in object file",
10036 bfd_get_reloc_code_name (fixp->fx_r_type));
10041 /* Turn a string in input_line_pointer into a floating point constant
10042 of type TYPE, and store the appropriate bytes in *LIT. The number
10043 of LITTLENUMS emitted is stored in *SIZE. An error message is
10044 returned, or NULL on OK. */
10046 #define MAX_LITTLENUMS 5
10049 md_atof (type, lit, size)
10054 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10055 LITTLENUM_TYPE *word;
10085 return "Bad call to MD_ATOF()";
10087 t = atof_ieee (input_line_pointer, type, words);
10089 input_line_pointer = t;
10090 *size = prec * sizeof (LITTLENUM_TYPE);
10092 for (word = words + prec - 1; prec--;)
10094 md_number_to_chars (lit, (long) (*word--), sizeof (LITTLENUM_TYPE));
10095 lit += sizeof (LITTLENUM_TYPE);
10100 /* Round up a section's size to the appropriate boundary. */
10102 md_section_align (seg, size)
10106 int align = bfd_get_section_alignment (stdoutput, seg);
10107 valueT mask = ((valueT) 1 << align) - 1;
10109 return (size + mask) & ~mask;
10112 /* Handle ia64 specific semantics of the align directive. */
10115 ia64_md_do_align (n, fill, len, max)
10116 int n ATTRIBUTE_UNUSED;
10117 const char *fill ATTRIBUTE_UNUSED;
10118 int len ATTRIBUTE_UNUSED;
10119 int max ATTRIBUTE_UNUSED;
10121 if (subseg_text_p (now_seg))
10122 ia64_flush_insns ();
10125 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10126 of an rs_align_code fragment. */
10129 ia64_handle_align (fragp)
10132 /* Use mfi bundle of nops with no stop bits. */
10133 static const unsigned char be_nop[]
10134 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
10135 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
10136 static const unsigned char le_nop[]
10137 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10138 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10143 if (fragp->fr_type != rs_align_code)
10146 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10147 p = fragp->fr_literal + fragp->fr_fix;
10149 /* Make sure we are on a 16-byte boundary, in case someone has been
10150 putting data into a text section. */
10153 int fix = bytes & 15;
10154 memset (p, 0, fix);
10157 fragp->fr_fix += fix;
10160 memcpy (p, (target_big_endian ? be_nop : le_nop), 16);
10161 fragp->fr_var = 16;