1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright (C) 1998, 1999, 2000 Free Software Foundation.
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 /* On the ia64, we can't know the address of a text label until the
128 instructions are packed into a bundle. To handle this, we keep
129 track of the list of labels that appear in front of each
133 struct label_fix *next;
137 extern int target_big_endian;
139 /* Characters which always start a comment. */
140 const char comment_chars[] = "";
142 /* Characters which start a comment at the beginning of a line. */
143 const char line_comment_chars[] = "#";
145 /* Characters which may be used to separate multiple commands on a
147 const char line_separator_chars[] = ";";
149 /* Characters which are used to indicate an exponent in a floating
151 const char EXP_CHARS[] = "eE";
153 /* Characters which mean that a number is a floating point constant,
155 const char FLT_CHARS[] = "rRsSfFdDxXpP";
157 /* ia64-specific option processing: */
159 const char *md_shortopts = "M:N:x::";
161 struct option md_longopts[] =
163 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
164 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
165 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
166 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
169 size_t md_longopts_size = sizeof (md_longopts);
173 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
174 struct hash_control *reg_hash; /* register name hash table */
175 struct hash_control *dynreg_hash; /* dynamic register hash table */
176 struct hash_control *const_hash; /* constant hash table */
177 struct hash_control *entry_hash; /* code entry hint hash table */
179 symbolS *regsym[REG_NUM];
181 /* If X_op is != O_absent, the registername for the instruction's
182 qualifying predicate. If NULL, p0 is assumed for instructions
183 that are predicatable. */
190 explicit_mode : 1, /* which mode we're in */
191 default_explicit_mode : 1, /* which mode is the default */
192 mode_explicitly_set : 1, /* was the current mode explicitly set? */
195 /* Each bundle consists of up to three instructions. We keep
196 track of four most recent instructions so we can correctly set
197 the end_of_insn_group for the last instruction in a bundle. */
199 int num_slots_in_use;
203 end_of_insn_group : 1,
204 manual_bundling_on : 1,
205 manual_bundling_off : 1;
206 signed char user_template; /* user-selected template, if any */
207 unsigned char qp_regno; /* qualifying predicate */
208 /* This duplicates a good fraction of "struct fix" but we
209 can't use a "struct fix" instead since we can't call
210 fix_new_exp() until we know the address of the instruction. */
214 bfd_reloc_code_real_type code;
215 enum ia64_opnd opnd; /* type of operand in need of fix */
216 unsigned int is_pcrel : 1; /* is operand pc-relative? */
217 expressionS expr; /* the value to be inserted */
219 fixup[2]; /* at most two fixups per insn */
220 struct ia64_opcode *idesc;
221 struct label_fix *label_fixups;
222 struct unw_rec_list *unwind_record; /* Unwind directive. */
225 unsigned int src_line;
226 struct dwarf2_line_info debug_line;
234 struct dynreg *next; /* next dynamic register */
236 unsigned short base; /* the base register number */
237 unsigned short num_regs; /* # of registers in this set */
239 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
241 flagword flags; /* ELF-header flags */
244 unsigned hint:1; /* is this hint currently valid? */
245 bfd_vma offset; /* mem.offset offset */
246 bfd_vma base; /* mem.offset base */
249 int path; /* number of alt. entry points seen */
250 const char **entry_labels; /* labels of all alternate paths in
251 the current DV-checking block. */
252 int maxpaths; /* size currently allocated for
257 /* application registers: */
263 #define AR_BSPSTORE 18
278 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
279 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
280 {"ar.rsc", 16}, {"ar.bsp", 17},
281 {"ar.bspstore", 18}, {"ar.rnat", 19},
282 {"ar.fcr", 21}, {"ar.eflag", 24},
283 {"ar.csd", 25}, {"ar.ssd", 26},
284 {"ar.cflg", 27}, {"ar.fsr", 28},
285 {"ar.fir", 29}, {"ar.fdr", 30},
286 {"ar.ccv", 32}, {"ar.unat", 36},
287 {"ar.fpsr", 40}, {"ar.itc", 44},
288 {"ar.pfs", 64}, {"ar.lc", 65},
309 /* control registers: */
351 static const struct const_desc
358 /* PSR constant masks: */
361 {"psr.be", ((valueT) 1) << 1},
362 {"psr.up", ((valueT) 1) << 2},
363 {"psr.ac", ((valueT) 1) << 3},
364 {"psr.mfl", ((valueT) 1) << 4},
365 {"psr.mfh", ((valueT) 1) << 5},
367 {"psr.ic", ((valueT) 1) << 13},
368 {"psr.i", ((valueT) 1) << 14},
369 {"psr.pk", ((valueT) 1) << 15},
371 {"psr.dt", ((valueT) 1) << 17},
372 {"psr.dfl", ((valueT) 1) << 18},
373 {"psr.dfh", ((valueT) 1) << 19},
374 {"psr.sp", ((valueT) 1) << 20},
375 {"psr.pp", ((valueT) 1) << 21},
376 {"psr.di", ((valueT) 1) << 22},
377 {"psr.si", ((valueT) 1) << 23},
378 {"psr.db", ((valueT) 1) << 24},
379 {"psr.lp", ((valueT) 1) << 25},
380 {"psr.tb", ((valueT) 1) << 26},
381 {"psr.rt", ((valueT) 1) << 27},
382 /* 28-31: reserved */
383 /* 32-33: cpl (current privilege level) */
384 {"psr.is", ((valueT) 1) << 34},
385 {"psr.mc", ((valueT) 1) << 35},
386 {"psr.it", ((valueT) 1) << 36},
387 {"psr.id", ((valueT) 1) << 37},
388 {"psr.da", ((valueT) 1) << 38},
389 {"psr.dd", ((valueT) 1) << 39},
390 {"psr.ss", ((valueT) 1) << 40},
391 /* 41-42: ri (restart instruction) */
392 {"psr.ed", ((valueT) 1) << 43},
393 {"psr.bn", ((valueT) 1) << 44},
396 /* indirect register-sets/memory: */
405 { "CPUID", IND_CPUID },
406 { "cpuid", IND_CPUID },
418 /* Pseudo functions used to indicate relocation types (these functions
419 start with an at sign (@). */
441 /* reloc pseudo functions (these must come first!): */
442 { "fptr", PSEUDO_FUNC_RELOC },
443 { "gprel", PSEUDO_FUNC_RELOC },
444 { "ltoff", PSEUDO_FUNC_RELOC },
445 { "pcrel", PSEUDO_FUNC_RELOC },
446 { "pltoff", PSEUDO_FUNC_RELOC },
447 { "secrel", PSEUDO_FUNC_RELOC },
448 { "segrel", PSEUDO_FUNC_RELOC },
449 { "ltv", PSEUDO_FUNC_RELOC },
450 { 0, }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
452 /* mbtype4 constants: */
453 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
454 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
455 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
456 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
457 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
459 /* fclass constants: */
460 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
461 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
462 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
463 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
464 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
465 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
466 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
467 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
468 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
470 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
472 /* unwind-related constants: */
473 { "svr4", PSEUDO_FUNC_CONST, { 0 } },
474 { "hpux", PSEUDO_FUNC_CONST, { 1 } },
475 { "nt", PSEUDO_FUNC_CONST, { 2 } },
477 /* unwind-related registers: */
478 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
481 /* 41-bit nop opcodes (one per unit): */
482 static const bfd_vma nop[IA64_NUM_UNITS] =
484 0x0000000000LL, /* NIL => break 0 */
485 0x0008000000LL, /* I-unit nop */
486 0x0008000000LL, /* M-unit nop */
487 0x4000000000LL, /* B-unit nop */
488 0x0008000000LL, /* F-unit nop */
489 0x0008000000LL, /* L-"unit" nop */
490 0x0008000000LL, /* X-unit nop */
493 /* Can't be `const' as it's passed to input routines (which have the
494 habit of setting temporary sentinels. */
495 static char special_section_name[][20] =
497 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
498 {".IA_64.unwind"}, {".IA_64.unwind_info"}
501 /* The best template for a particular sequence of up to three
503 #define N IA64_NUM_TYPES
504 static unsigned char best_template[N][N][N];
507 /* Resource dependencies currently in effect */
509 int depind; /* dependency index */
510 const struct ia64_dependency *dependency; /* actual dependency */
511 unsigned specific:1, /* is this a specific bit/regno? */
512 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
513 int index; /* specific regno/bit within dependency */
514 int note; /* optional qualifying note (0 if none) */
518 int insn_srlz; /* current insn serialization state */
519 int data_srlz; /* current data serialization state */
520 int qp_regno; /* qualifying predicate for this usage */
521 char *file; /* what file marked this dependency */
522 int line; /* what line marked this dependency */
523 struct mem_offset mem_offset; /* optional memory offset hint */
524 int path; /* corresponding code entry index */
526 static int regdepslen = 0;
527 static int regdepstotlen = 0;
528 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
529 static const char *dv_sem[] = { "none", "implied", "impliedf",
530 "data", "instr", "specific", "other" };
532 /* Current state of PR mutexation */
533 static struct qpmutex {
536 } *qp_mutexes = NULL; /* QP mutex bitmasks */
537 static int qp_mutexeslen = 0;
538 static int qp_mutexestotlen = 0;
539 static valueT qp_safe_across_calls = 0;
541 /* Current state of PR implications */
542 static struct qp_imply {
545 unsigned p2_branched:1;
547 } *qp_implies = NULL;
548 static int qp_implieslen = 0;
549 static int qp_impliestotlen = 0;
551 /* Keep track of static GR values so that indirect register usage can
552 sometimes be tracked. */
557 } gr_values[128] = {{ 1, 0 }};
559 /* These are the routines required to output the various types of
562 typedef struct unw_rec_list {
564 unsigned long slot_number;
565 struct unw_rec_list *next;
568 #define SLOT_NUM_NOT_SET -1
572 unsigned long next_slot_number;
574 /* Maintain a list of unwind entries for the current function. */
578 /* Any unwind entires that should be attached to the current slot
579 that an insn is being constructed for. */
580 unw_rec_list *current_entry;
582 /* These are used to create the unwind table entry for this function. */
585 symbolS *info; /* pointer to unwind info */
586 symbolS *personality_routine;
588 /* TRUE if processing unwind directives in a prologue region. */
593 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
595 /* Forward delarations: */
596 static int ar_is_in_integer_unit PARAMS ((int regnum));
597 static void set_section PARAMS ((char *name));
598 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
599 unsigned int, unsigned int));
600 static void dot_radix PARAMS ((int));
601 static void dot_special_section PARAMS ((int));
602 static void dot_proc PARAMS ((int));
603 static void dot_fframe PARAMS ((int));
604 static void dot_vframe PARAMS ((int));
605 static void dot_vframesp PARAMS ((int));
606 static void dot_vframepsp PARAMS ((int));
607 static void dot_save PARAMS ((int));
608 static void dot_restore PARAMS ((int));
609 static void dot_restorereg PARAMS ((int));
610 static void dot_restorereg_p PARAMS ((int));
611 static void dot_handlerdata PARAMS ((int));
612 static void dot_unwentry PARAMS ((int));
613 static void dot_altrp PARAMS ((int));
614 static void dot_savemem PARAMS ((int));
615 static void dot_saveg PARAMS ((int));
616 static void dot_savef PARAMS ((int));
617 static void dot_saveb PARAMS ((int));
618 static void dot_savegf PARAMS ((int));
619 static void dot_spill PARAMS ((int));
620 static void dot_spillreg PARAMS ((int));
621 static void dot_spillmem PARAMS ((int));
622 static void dot_spillreg_p PARAMS ((int));
623 static void dot_spillmem_p PARAMS ((int));
624 static void dot_label_state PARAMS ((int));
625 static void dot_copy_state PARAMS ((int));
626 static void dot_unwabi PARAMS ((int));
627 static void dot_personality PARAMS ((int));
628 static void dot_body PARAMS ((int));
629 static void dot_prologue PARAMS ((int));
630 static void dot_endp PARAMS ((int));
631 static void dot_template PARAMS ((int));
632 static void dot_regstk PARAMS ((int));
633 static void dot_rot PARAMS ((int));
634 static void dot_byteorder PARAMS ((int));
635 static void dot_psr PARAMS ((int));
636 static void dot_alias PARAMS ((int));
637 static void dot_ln PARAMS ((int));
638 static char *parse_section_name PARAMS ((void));
639 static void dot_xdata PARAMS ((int));
640 static void stmt_float_cons PARAMS ((int));
641 static void stmt_cons_ua PARAMS ((int));
642 static void dot_xfloat_cons PARAMS ((int));
643 static void dot_xstringer PARAMS ((int));
644 static void dot_xdata_ua PARAMS ((int));
645 static void dot_xfloat_cons_ua PARAMS ((int));
646 static void print_prmask PARAMS ((valueT mask));
647 static void dot_pred_rel PARAMS ((int));
648 static void dot_reg_val PARAMS ((int));
649 static void dot_dv_mode PARAMS ((int));
650 static void dot_entry PARAMS ((int));
651 static void dot_mem_offset PARAMS ((int));
652 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
653 static symbolS *declare_register PARAMS ((const char *name, int regnum));
654 static void declare_register_set PARAMS ((const char *, int, int));
655 static unsigned int operand_width PARAMS ((enum ia64_opnd));
656 static int operand_match PARAMS ((const struct ia64_opcode *idesc,
657 int index, expressionS *e));
658 static int parse_operand PARAMS ((expressionS *e));
659 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
660 static void build_insn PARAMS ((struct slot *, bfd_vma *));
661 static void emit_one_bundle PARAMS ((void));
662 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
663 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
664 bfd_reloc_code_real_type r_type));
665 static void insn_group_break PARAMS ((int, int, int));
666 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
667 struct rsrc *, int depind, int path));
668 static void add_qp_mutex PARAMS((valueT mask));
669 static void add_qp_imply PARAMS((int p1, int p2));
670 static void clear_qp_branch_flag PARAMS((valueT mask));
671 static void clear_qp_mutex PARAMS((valueT mask));
672 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
673 static void clear_register_values PARAMS ((void));
674 static void print_dependency PARAMS ((const char *action, int depind));
675 static void instruction_serialization PARAMS ((void));
676 static void data_serialization PARAMS ((void));
677 static void remove_marked_resource PARAMS ((struct rsrc *));
678 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
679 static int is_taken_branch PARAMS ((struct ia64_opcode *));
680 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
681 static int depends_on PARAMS ((int, struct ia64_opcode *));
682 static int specify_resource PARAMS ((const struct ia64_dependency *,
683 struct ia64_opcode *, int, struct rsrc [], int, int));
684 static int check_dv PARAMS((struct ia64_opcode *idesc));
685 static void check_dependencies PARAMS((struct ia64_opcode *));
686 static void mark_resources PARAMS((struct ia64_opcode *));
687 static void update_dependencies PARAMS((struct ia64_opcode *));
688 static void note_register_values PARAMS((struct ia64_opcode *));
689 static int qp_mutex PARAMS ((int, int, int));
690 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
691 static void output_vbyte_mem PARAMS ((int, char *, char *));
692 static void count_output PARAMS ((int, char *, char *));
693 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
694 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
695 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
696 static void output_P1_format PARAMS ((vbyte_func, int));
697 static void output_P2_format PARAMS ((vbyte_func, int, int));
698 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
699 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
700 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
701 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
702 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
703 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
704 static void output_P9_format PARAMS ((vbyte_func, int, int));
705 static void output_P10_format PARAMS ((vbyte_func, int, int));
706 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
707 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
708 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
709 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
710 static char format_ab_reg PARAMS ((int, int));
711 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
713 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
714 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
716 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
717 static void free_list_records PARAMS ((unw_rec_list *));
718 static unw_rec_list *output_prologue PARAMS ((void));
719 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
720 static unw_rec_list *output_body PARAMS ((void));
721 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
722 static unw_rec_list *output_mem_stack_v PARAMS ((void));
723 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
724 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
725 static unw_rec_list *output_rp_when PARAMS ((void));
726 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
727 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
728 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
729 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
730 static unw_rec_list *output_pfs_when PARAMS ((void));
731 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
732 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
733 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
734 static unw_rec_list *output_preds_when PARAMS ((void));
735 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
736 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
737 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
738 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
739 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
740 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
741 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
742 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
743 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
744 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
745 static unw_rec_list *output_unat_when PARAMS ((void));
746 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
747 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
748 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
749 static unw_rec_list *output_lc_when PARAMS ((void));
750 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
751 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
752 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
753 static unw_rec_list *output_fpsr_when PARAMS ((void));
754 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
755 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
756 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
757 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
758 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
759 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
760 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
761 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
762 static unw_rec_list *output_bsp_when PARAMS ((void));
763 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
764 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
765 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
766 static unw_rec_list *output_bspstore_when PARAMS ((void));
767 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
768 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
769 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
770 static unw_rec_list *output_rnat_when PARAMS ((void));
771 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
772 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
773 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
774 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
775 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
776 static unw_rec_list *output_label_state PARAMS ((unsigned long));
777 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
778 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
779 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
780 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
782 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
784 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
786 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
787 unsigned int, unsigned int));
788 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
789 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
790 static int calc_record_size PARAMS ((unw_rec_list *));
791 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
792 static int count_bits PARAMS ((unsigned long));
793 static unsigned long slot_index PARAMS ((unsigned long, unsigned long));
794 static void fixup_unw_records PARAMS ((unw_rec_list *));
795 static int output_unw_records PARAMS ((unw_rec_list *, void **));
796 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
797 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
798 static int generate_unwind_image PARAMS ((void));
800 /* Determine if application register REGNUM resides in the integer
801 unit (as opposed to the memory unit). */
803 ar_is_in_integer_unit (reg)
808 return (reg == 64 /* pfs */
809 || reg == 65 /* lc */
810 || reg == 66 /* ec */
811 /* ??? ias accepts and puts these in the integer unit. */
812 || (reg >= 112 && reg <= 127));
815 /* Switch to section NAME and create section if necessary. It's
816 rather ugly that we have to manipulate input_line_pointer but I
817 don't see any other way to accomplish the same thing without
818 changing obj-elf.c (which may be the Right Thing, in the end). */
823 char *saved_input_line_pointer;
825 saved_input_line_pointer = input_line_pointer;
826 input_line_pointer = name;
828 input_line_pointer = saved_input_line_pointer;
831 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
834 ia64_elf_section_flags (flags, attr, type)
838 if (attr & SHF_IA_64_SHORT)
839 flags |= SEC_SMALL_DATA;
844 set_regstack (ins, locs, outs, rots)
845 unsigned int ins, locs, outs, rots;
850 sof = ins + locs + outs;
853 as_bad ("Size of frame exceeds maximum of 96 registers");
858 as_warn ("Size of rotating registers exceeds frame size");
861 md.in.base = REG_GR + 32;
862 md.loc.base = md.in.base + ins;
863 md.out.base = md.loc.base + locs;
865 md.in.num_regs = ins;
866 md.loc.num_regs = locs;
867 md.out.num_regs = outs;
868 md.rot.num_regs = rots;
875 struct label_fix *lfix;
877 subsegT saved_subseg;
879 if (!md.last_text_seg)
883 saved_subseg = now_subseg;
885 subseg_set (md.last_text_seg, 0);
887 while (md.num_slots_in_use > 0)
888 emit_one_bundle (); /* force out queued instructions */
890 /* In case there are labels following the last instruction, resolve
892 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
894 S_SET_VALUE (lfix->sym, frag_now_fix ());
895 symbol_set_frag (lfix->sym, frag_now);
897 CURR_SLOT.label_fixups = 0;
899 subseg_set (saved_seg, saved_subseg);
903 ia64_do_align (nbytes)
906 char *saved_input_line_pointer = input_line_pointer;
908 input_line_pointer = "";
909 s_align_bytes (nbytes);
910 input_line_pointer = saved_input_line_pointer;
914 ia64_cons_align (nbytes)
919 char *saved_input_line_pointer = input_line_pointer;
920 input_line_pointer = "";
921 s_align_bytes (nbytes);
922 input_line_pointer = saved_input_line_pointer;
926 /* Output COUNT bytes to a memory location. */
927 static unsigned char *vbyte_mem_ptr = NULL;
930 output_vbyte_mem (count, ptr, comment)
936 if (vbyte_mem_ptr == NULL)
941 for (x = 0; x < count; x++)
942 *(vbyte_mem_ptr++) = ptr[x];
945 /* Count the number of bytes required for records. */
946 static int vbyte_count = 0;
948 count_output (count, ptr, comment)
953 vbyte_count += count;
957 output_R1_format (f, rtype, rlen)
959 unw_record_type rtype;
966 output_R3_format (f, rtype, rlen);
972 else if (rtype != prologue)
973 as_bad ("record type is not valid");
975 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
976 (*f) (1, &byte, NULL);
980 output_R2_format (f, mask, grsave, rlen)
987 mask = (mask & 0x0f);
988 grsave = (grsave & 0x7f);
990 bytes[0] = (UNW_R2 | (mask >> 1));
991 bytes[1] = (((mask & 0x01) << 7) | grsave);
992 count += output_leb128 (bytes + 2, rlen, 0);
993 (*f) (count, bytes, NULL);
997 output_R3_format (f, rtype, rlen)
999 unw_record_type rtype;
1006 output_R1_format (f, rtype, rlen);
1012 else if (rtype != prologue)
1013 as_bad ("record type is not valid");
1014 bytes[0] = (UNW_R3 | r);
1015 count = output_leb128 (bytes + 1, rlen, 0);
1016 (*f) (count + 1, bytes, NULL);
1020 output_P1_format (f, brmask)
1025 byte = UNW_P1 | (brmask & 0x1f);
1026 (*f) (1, &byte, NULL);
1030 output_P2_format (f, brmask, gr)
1036 brmask = (brmask & 0x1f);
1037 bytes[0] = UNW_P2 | (brmask >> 1);
1038 bytes[1] = (((brmask & 1) << 7) | gr);
1039 (*f) (2, bytes, NULL);
1043 output_P3_format (f, rtype, reg)
1045 unw_record_type rtype;
1090 as_bad ("Invalid record type for P3 format.");
1092 bytes[0] = (UNW_P3 | (r >> 1));
1093 bytes[1] = (((r & 1) << 7) | reg);
1094 (*f) (2, bytes, NULL);
1098 output_P4_format (f, imask, imask_size)
1100 unsigned char *imask;
1101 unsigned long imask_size;
1104 (*f) (imask_size, imask, NULL);
1108 output_P5_format (f, grmask, frmask)
1111 unsigned long frmask;
1114 grmask = (grmask & 0x0f);
1117 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1118 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1119 bytes[3] = (frmask & 0x000000ff);
1120 (*f) (4, bytes, NULL);
1124 output_P6_format (f, rtype, rmask)
1126 unw_record_type rtype;
1132 if (rtype == gr_mem)
1134 else if (rtype != fr_mem)
1135 as_bad ("Invalid record type for format P6");
1136 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1137 (*f) (1, &byte, NULL);
1141 output_P7_format (f, rtype, w1, w2)
1143 unw_record_type rtype;
1150 count += output_leb128 (bytes + 1, w1, 0);
1155 count += output_leb128 (bytes + count, w2 >> 4, 0);
1205 bytes[0] = (UNW_P7 | r);
1206 (*f) (count, bytes, NULL);
1210 output_P8_format (f, rtype, t)
1212 unw_record_type rtype;
1251 case bspstore_psprel:
1254 case bspstore_sprel:
1266 case priunat_when_gr:
1269 case priunat_psprel:
1275 case priunat_when_mem:
1282 count += output_leb128 (bytes + 2, t, 0);
1283 (*f) (count, bytes, NULL);
1287 output_P9_format (f, grmask, gr)
1294 bytes[1] = (grmask & 0x0f);
1295 bytes[2] = (gr & 0x7f);
1296 (*f) (3, bytes, NULL);
1300 output_P10_format (f, abi, context)
1307 bytes[1] = (abi & 0xff);
1308 bytes[2] = (context & 0xff);
1309 (*f) (3, bytes, NULL);
1313 output_B1_format (f, rtype, label)
1315 unw_record_type rtype;
1316 unsigned long label;
1322 output_B4_format (f, rtype, label);
1325 if (rtype == copy_state)
1327 else if (rtype != label_state)
1328 as_bad ("Invalid record type for format B1");
1330 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1331 (*f) (1, &byte, NULL);
1335 output_B2_format (f, ecount, t)
1337 unsigned long ecount;
1344 output_B3_format (f, ecount, t);
1347 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1348 count += output_leb128 (bytes + 1, t, 0);
1349 (*f) (count, bytes, NULL);
1353 output_B3_format (f, ecount, t)
1355 unsigned long ecount;
1362 output_B2_format (f, ecount, t);
1366 count += output_leb128 (bytes + 1, t, 0);
1367 count += output_leb128 (bytes + count, ecount, 0);
1368 (*f) (count, bytes, NULL);
1372 output_B4_format (f, rtype, label)
1374 unw_record_type rtype;
1375 unsigned long label;
1382 output_B1_format (f, rtype, label);
1386 if (rtype == copy_state)
1388 else if (rtype != label_state)
1389 as_bad ("Invalid record type for format B1");
1391 bytes[0] = (UNW_B4 | (r << 3));
1392 count += output_leb128 (bytes + 1, label, 0);
1393 (*f) (count, bytes, NULL);
1397 format_ab_reg (ab, reg)
1404 ret = (ab << 5) | reg;
1409 output_X1_format (f, rtype, ab, reg, t, w1)
1411 unw_record_type rtype;
1421 if (rtype == spill_sprel)
1423 else if (rtype != spill_psprel)
1424 as_bad ("Invalid record type for format X1");
1425 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1426 count += output_leb128 (bytes + 2, t, 0);
1427 count += output_leb128 (bytes + count, w1, 0);
1428 (*f) (count, bytes, NULL);
1432 output_X2_format (f, ab, reg, x, y, treg, t)
1441 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1442 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1443 count += output_leb128 (bytes + 3, t, 0);
1444 (*f) (count, bytes, NULL);
1448 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1450 unw_record_type rtype;
1461 if (rtype == spill_sprel_p)
1463 else if (rtype != spill_psprel_p)
1464 as_bad ("Invalid record type for format X3");
1465 bytes[1] = ((r << 7) | (qp & 0x3f));
1466 bytes[2] = format_ab_reg (ab, reg);
1467 count += output_leb128 (bytes + 3, t, 0);
1468 count += output_leb128 (bytes + count, w1, 0);
1469 (*f) (count, bytes, NULL);
1473 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1483 bytes[1] = (qp & 0x3f);
1484 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1485 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1486 count += output_leb128 (bytes + 4, t, 0);
1487 (*f) (count, bytes, NULL);
1490 /* This function allocates a record list structure, and initializes fields. */
1492 static unw_rec_list *
1493 alloc_record (unw_record_type t)
1496 ptr = xmalloc (sizeof (*ptr));
1498 ptr->slot_number = SLOT_NUM_NOT_SET;
1503 /* This function frees an entire list of record structures. */
1506 free_list_records (unw_rec_list *first)
1509 for (ptr = first; ptr != NULL;)
1511 unw_rec_list *tmp = ptr;
1513 if ((tmp->r.type == prologue || tmp->r.type == prologue_gr)
1514 && tmp->r.record.r.mask.i)
1515 free (tmp->r.record.r.mask.i);
1522 static unw_rec_list *
1525 unw_rec_list *ptr = alloc_record (prologue);
1526 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1530 static unw_rec_list *
1531 output_prologue_gr (saved_mask, reg)
1532 unsigned int saved_mask;
1535 unw_rec_list *ptr = alloc_record (prologue_gr);
1536 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1537 ptr->r.record.r.grmask = saved_mask;
1538 ptr->r.record.r.grsave = reg;
1542 static unw_rec_list *
1545 unw_rec_list *ptr = alloc_record (body);
1549 static unw_rec_list *
1550 output_mem_stack_f (size)
1553 unw_rec_list *ptr = alloc_record (mem_stack_f);
1554 ptr->r.record.p.size = size;
1558 static unw_rec_list *
1559 output_mem_stack_v ()
1561 unw_rec_list *ptr = alloc_record (mem_stack_v);
1565 static unw_rec_list *
1569 unw_rec_list *ptr = alloc_record (psp_gr);
1570 ptr->r.record.p.gr = gr;
1574 static unw_rec_list *
1575 output_psp_sprel (offset)
1576 unsigned int offset;
1578 unw_rec_list *ptr = alloc_record (psp_sprel);
1579 ptr->r.record.p.spoff = offset / 4;
1583 static unw_rec_list *
1586 unw_rec_list *ptr = alloc_record (rp_when);
1590 static unw_rec_list *
1594 unw_rec_list *ptr = alloc_record (rp_gr);
1595 ptr->r.record.p.gr = gr;
1599 static unw_rec_list *
1603 unw_rec_list *ptr = alloc_record (rp_br);
1604 ptr->r.record.p.br = br;
1608 static unw_rec_list *
1609 output_rp_psprel (offset)
1610 unsigned int offset;
1612 unw_rec_list *ptr = alloc_record (rp_psprel);
1613 ptr->r.record.p.pspoff = offset / 4;
1617 static unw_rec_list *
1618 output_rp_sprel (offset)
1619 unsigned int offset;
1621 unw_rec_list *ptr = alloc_record (rp_sprel);
1622 ptr->r.record.p.spoff = offset / 4;
1626 static unw_rec_list *
1629 unw_rec_list *ptr = alloc_record (pfs_when);
1633 static unw_rec_list *
1637 unw_rec_list *ptr = alloc_record (pfs_gr);
1638 ptr->r.record.p.gr = gr;
1642 static unw_rec_list *
1643 output_pfs_psprel (offset)
1644 unsigned int offset;
1646 unw_rec_list *ptr = alloc_record (pfs_psprel);
1647 ptr->r.record.p.pspoff = offset / 4;
1651 static unw_rec_list *
1652 output_pfs_sprel (offset)
1653 unsigned int offset;
1655 unw_rec_list *ptr = alloc_record (pfs_sprel);
1656 ptr->r.record.p.spoff = offset / 4;
1660 static unw_rec_list *
1661 output_preds_when ()
1663 unw_rec_list *ptr = alloc_record (preds_when);
1667 static unw_rec_list *
1668 output_preds_gr (gr)
1671 unw_rec_list *ptr = alloc_record (preds_gr);
1672 ptr->r.record.p.gr = gr;
1676 static unw_rec_list *
1677 output_preds_psprel (offset)
1678 unsigned int offset;
1680 unw_rec_list *ptr = alloc_record (preds_psprel);
1681 ptr->r.record.p.pspoff = offset / 4;
1685 static unw_rec_list *
1686 output_preds_sprel (offset)
1687 unsigned int offset;
1689 unw_rec_list *ptr = alloc_record (preds_sprel);
1690 ptr->r.record.p.spoff = offset / 4;
1694 static unw_rec_list *
1695 output_fr_mem (mask)
1698 unw_rec_list *ptr = alloc_record (fr_mem);
1699 ptr->r.record.p.rmask = mask;
1703 static unw_rec_list *
1704 output_frgr_mem (gr_mask, fr_mask)
1705 unsigned int gr_mask;
1706 unsigned int fr_mask;
1708 unw_rec_list *ptr = alloc_record (frgr_mem);
1709 ptr->r.record.p.grmask = gr_mask;
1710 ptr->r.record.p.frmask = fr_mask;
1714 static unw_rec_list *
1715 output_gr_gr (mask, reg)
1719 unw_rec_list *ptr = alloc_record (gr_gr);
1720 ptr->r.record.p.grmask = mask;
1721 ptr->r.record.p.gr = reg;
1725 static unw_rec_list *
1726 output_gr_mem (mask)
1729 unw_rec_list *ptr = alloc_record (gr_mem);
1730 ptr->r.record.p.rmask = mask;
1734 static unw_rec_list *
1735 output_br_mem (unsigned int mask)
1737 unw_rec_list *ptr = alloc_record (br_mem);
1738 ptr->r.record.p.brmask = mask;
1742 static unw_rec_list *
1743 output_br_gr (save_mask, reg)
1744 unsigned int save_mask;
1747 unw_rec_list *ptr = alloc_record (br_gr);
1748 ptr->r.record.p.brmask = save_mask;
1749 ptr->r.record.p.gr = reg;
1753 static unw_rec_list *
1754 output_spill_base (offset)
1755 unsigned int offset;
1757 unw_rec_list *ptr = alloc_record (spill_base);
1758 ptr->r.record.p.pspoff = offset / 4;
1762 static unw_rec_list *
1765 unw_rec_list *ptr = alloc_record (unat_when);
1769 static unw_rec_list *
1773 unw_rec_list *ptr = alloc_record (unat_gr);
1774 ptr->r.record.p.gr = gr;
1778 static unw_rec_list *
1779 output_unat_psprel (offset)
1780 unsigned int offset;
1782 unw_rec_list *ptr = alloc_record (unat_psprel);
1783 ptr->r.record.p.pspoff = offset / 4;
1787 static unw_rec_list *
1788 output_unat_sprel (offset)
1789 unsigned int offset;
1791 unw_rec_list *ptr = alloc_record (unat_sprel);
1792 ptr->r.record.p.spoff = offset / 4;
1796 static unw_rec_list *
1799 unw_rec_list *ptr = alloc_record (lc_when);
1803 static unw_rec_list *
1807 unw_rec_list *ptr = alloc_record (lc_gr);
1808 ptr->r.record.p.gr = gr;
1812 static unw_rec_list *
1813 output_lc_psprel (offset)
1814 unsigned int offset;
1816 unw_rec_list *ptr = alloc_record (lc_psprel);
1817 ptr->r.record.p.pspoff = offset / 4;
1821 static unw_rec_list *
1822 output_lc_sprel (offset)
1823 unsigned int offset;
1825 unw_rec_list *ptr = alloc_record (lc_sprel);
1826 ptr->r.record.p.spoff = offset / 4;
1830 static unw_rec_list *
1833 unw_rec_list *ptr = alloc_record (fpsr_when);
1837 static unw_rec_list *
1841 unw_rec_list *ptr = alloc_record (fpsr_gr);
1842 ptr->r.record.p.gr = gr;
1846 static unw_rec_list *
1847 output_fpsr_psprel (offset)
1848 unsigned int offset;
1850 unw_rec_list *ptr = alloc_record (fpsr_psprel);
1851 ptr->r.record.p.pspoff = offset / 4;
1855 static unw_rec_list *
1856 output_fpsr_sprel (offset)
1857 unsigned int offset;
1859 unw_rec_list *ptr = alloc_record (fpsr_sprel);
1860 ptr->r.record.p.spoff = offset / 4;
1864 static unw_rec_list *
1865 output_priunat_when_gr ()
1867 unw_rec_list *ptr = alloc_record (priunat_when_gr);
1871 static unw_rec_list *
1872 output_priunat_when_mem ()
1874 unw_rec_list *ptr = alloc_record (priunat_when_mem);
1878 static unw_rec_list *
1879 output_priunat_gr (gr)
1882 unw_rec_list *ptr = alloc_record (priunat_gr);
1883 ptr->r.record.p.gr = gr;
1887 static unw_rec_list *
1888 output_priunat_psprel (offset)
1889 unsigned int offset;
1891 unw_rec_list *ptr = alloc_record (priunat_psprel);
1892 ptr->r.record.p.pspoff = offset / 4;
1896 static unw_rec_list *
1897 output_priunat_sprel (offset)
1898 unsigned int offset;
1900 unw_rec_list *ptr = alloc_record (priunat_sprel);
1901 ptr->r.record.p.spoff = offset / 4;
1905 static unw_rec_list *
1908 unw_rec_list *ptr = alloc_record (bsp_when);
1912 static unw_rec_list *
1916 unw_rec_list *ptr = alloc_record (bsp_gr);
1917 ptr->r.record.p.gr = gr;
1921 static unw_rec_list *
1922 output_bsp_psprel (offset)
1923 unsigned int offset;
1925 unw_rec_list *ptr = alloc_record (bsp_psprel);
1926 ptr->r.record.p.pspoff = offset / 4;
1930 static unw_rec_list *
1931 output_bsp_sprel (offset)
1932 unsigned int offset;
1934 unw_rec_list *ptr = alloc_record (bsp_sprel);
1935 ptr->r.record.p.spoff = offset / 4;
1939 static unw_rec_list *
1940 output_bspstore_when ()
1942 unw_rec_list *ptr = alloc_record (bspstore_when);
1946 static unw_rec_list *
1947 output_bspstore_gr (gr)
1950 unw_rec_list *ptr = alloc_record (bspstore_gr);
1951 ptr->r.record.p.gr = gr;
1955 static unw_rec_list *
1956 output_bspstore_psprel (offset)
1957 unsigned int offset;
1959 unw_rec_list *ptr = alloc_record (bspstore_psprel);
1960 ptr->r.record.p.pspoff = offset / 4;
1964 static unw_rec_list *
1965 output_bspstore_sprel (offset)
1966 unsigned int offset;
1968 unw_rec_list *ptr = alloc_record (bspstore_sprel);
1969 ptr->r.record.p.spoff = offset / 4;
1973 static unw_rec_list *
1976 unw_rec_list *ptr = alloc_record (rnat_when);
1980 static unw_rec_list *
1984 unw_rec_list *ptr = alloc_record (rnat_gr);
1985 ptr->r.record.p.gr = gr;
1989 static unw_rec_list *
1990 output_rnat_psprel (offset)
1991 unsigned int offset;
1993 unw_rec_list *ptr = alloc_record (rnat_psprel);
1994 ptr->r.record.p.pspoff = offset / 4;
1998 static unw_rec_list *
1999 output_rnat_sprel (offset)
2000 unsigned int offset;
2002 unw_rec_list *ptr = alloc_record (rnat_sprel);
2003 ptr->r.record.p.spoff = offset / 4;
2007 static unw_rec_list *
2008 output_unwabi (abi, context)
2010 unsigned long context;
2012 unw_rec_list *ptr = alloc_record (unwabi);
2013 ptr->r.record.p.abi = abi;
2014 ptr->r.record.p.context = context;
2018 static unw_rec_list *
2019 output_epilogue (unsigned long ecount)
2021 unw_rec_list *ptr = alloc_record (epilogue);
2022 ptr->r.record.b.ecount = ecount;
2026 static unw_rec_list *
2027 output_label_state (unsigned long label)
2029 unw_rec_list *ptr = alloc_record (label_state);
2030 ptr->r.record.b.label = label;
2034 static unw_rec_list *
2035 output_copy_state (unsigned long label)
2037 unw_rec_list *ptr = alloc_record (copy_state);
2038 ptr->r.record.b.label = label;
2042 static unw_rec_list *
2043 output_spill_psprel (ab, reg, offset)
2046 unsigned int offset;
2048 unw_rec_list *ptr = alloc_record (spill_psprel);
2049 ptr->r.record.x.ab = ab;
2050 ptr->r.record.x.reg = reg;
2051 ptr->r.record.x.pspoff = offset / 4;
2055 static unw_rec_list *
2056 output_spill_sprel (ab, reg, offset)
2059 unsigned int offset;
2061 unw_rec_list *ptr = alloc_record (spill_sprel);
2062 ptr->r.record.x.ab = ab;
2063 ptr->r.record.x.reg = reg;
2064 ptr->r.record.x.spoff = offset / 4;
2068 static unw_rec_list *
2069 output_spill_psprel_p (ab, reg, offset, predicate)
2072 unsigned int offset;
2073 unsigned int predicate;
2075 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2076 ptr->r.record.x.ab = ab;
2077 ptr->r.record.x.reg = reg;
2078 ptr->r.record.x.pspoff = offset / 4;
2079 ptr->r.record.x.qp = predicate;
2083 static unw_rec_list *
2084 output_spill_sprel_p (ab, reg, offset, predicate)
2087 unsigned int offset;
2088 unsigned int predicate;
2090 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2091 ptr->r.record.x.ab = ab;
2092 ptr->r.record.x.reg = reg;
2093 ptr->r.record.x.spoff = offset / 4;
2094 ptr->r.record.x.qp = predicate;
2098 static unw_rec_list *
2099 output_spill_reg (ab, reg, targ_reg, xy)
2102 unsigned int targ_reg;
2105 unw_rec_list *ptr = alloc_record (spill_reg);
2106 ptr->r.record.x.ab = ab;
2107 ptr->r.record.x.reg = reg;
2108 ptr->r.record.x.treg = targ_reg;
2109 ptr->r.record.x.xy = xy;
2113 static unw_rec_list *
2114 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2117 unsigned int targ_reg;
2119 unsigned int predicate;
2121 unw_rec_list *ptr = alloc_record (spill_reg_p);
2122 ptr->r.record.x.ab = ab;
2123 ptr->r.record.x.reg = reg;
2124 ptr->r.record.x.treg = targ_reg;
2125 ptr->r.record.x.xy = xy;
2126 ptr->r.record.x.qp = predicate;
2130 /* Given a unw_rec_list process the correct format with the
2131 specified function. */
2134 process_one_record (ptr, f)
2138 unsigned long fr_mask, gr_mask;
2140 switch (ptr->r.type)
2146 /* These are taken care of by prologue/prologue_gr. */
2151 if (ptr->r.type == prologue_gr)
2152 output_R2_format (f, ptr->r.record.r.grmask,
2153 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2155 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2157 /* Output descriptor(s) for union of register spills (if any). */
2158 gr_mask = ptr->r.record.r.mask.gr_mem;
2159 fr_mask = ptr->r.record.r.mask.fr_mem;
2162 if ((fr_mask & ~0xfUL) == 0)
2163 output_P6_format (f, fr_mem, fr_mask);
2166 output_P5_format (f, gr_mask, fr_mask);
2171 output_P6_format (f, gr_mem, gr_mask);
2172 if (ptr->r.record.r.mask.br_mem)
2173 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2175 /* output imask descriptor if necessary: */
2176 if (ptr->r.record.r.mask.i)
2177 output_P4_format (f, ptr->r.record.r.mask.i,
2178 ptr->r.record.r.imask_size);
2182 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2186 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2187 ptr->r.record.p.size);
2200 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2203 output_P3_format (f, rp_br, ptr->r.record.p.br);
2206 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2214 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2223 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2233 case bspstore_sprel:
2235 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2238 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2241 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2244 as_bad ("spill_mask record unimplemented.");
2246 case priunat_when_gr:
2247 case priunat_when_mem:
2251 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2253 case priunat_psprel:
2255 case bspstore_psprel:
2257 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2260 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2263 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2267 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2270 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2271 ptr->r.record.x.reg, ptr->r.record.x.t,
2272 ptr->r.record.x.pspoff);
2275 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2276 ptr->r.record.x.reg, ptr->r.record.x.t,
2277 ptr->r.record.x.spoff);
2280 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2281 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2282 ptr->r.record.x.treg, ptr->r.record.x.t);
2284 case spill_psprel_p:
2285 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2286 ptr->r.record.x.ab, ptr->r.record.x.reg,
2287 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2290 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2291 ptr->r.record.x.ab, ptr->r.record.x.reg,
2292 ptr->r.record.x.t, ptr->r.record.x.spoff);
2295 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2296 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2297 ptr->r.record.x.xy, ptr->r.record.x.treg,
2301 as_bad ("record_type_not_valid");
2306 /* Given a unw_rec_list list, process all the records with
2307 the specified function. */
2309 process_unw_records (list, f)
2314 for (ptr = list; ptr; ptr = ptr->next)
2315 process_one_record (ptr, f);
2318 /* Determine the size of a record list in bytes. */
2320 calc_record_size (list)
2324 process_unw_records (list, count_output);
2328 /* Update IMASK bitmask to reflect the fact that one or more registers
2329 of type TYPE are saved starting at instruction with index T. If N
2330 bits are set in REGMASK, it is assumed that instructions T through
2331 T+N-1 save these registers.
2335 1: instruction saves next fp reg
2336 2: instruction saves next general reg
2337 3: instruction saves next branch reg */
2339 set_imask (region, regmask, t, type)
2340 unw_rec_list *region;
2341 unsigned long regmask;
2345 unsigned char *imask;
2346 unsigned long imask_size;
2350 imask = region->r.record.r.mask.i;
2351 imask_size = region->r.record.r.imask_size;
2354 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2355 imask = xmalloc (imask_size);
2356 memset (imask, 0, imask_size);
2358 region->r.record.r.imask_size = imask_size;
2359 region->r.record.r.mask.i = imask;
2363 pos = 2 * (3 - t % 4);
2366 if (i >= imask_size)
2368 as_bad ("Ignoring attempt to spill beyond end of region");
2372 imask[i] |= (type & 0x3) << pos;
2374 regmask &= (regmask - 1);
2385 count_bits (unsigned long mask)
2398 slot_index (unsigned long slot_addr, unsigned long first_addr)
2400 return (3 * ((slot_addr >> 4) - (first_addr >> 4))
2401 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2404 /* Given a complete record list, process any records which have
2405 unresolved fields, (ie length counts for a prologue). After
2406 this has been run, all neccessary information should be available
2407 within each record to generate an image. */
2410 fixup_unw_records (list)
2413 unw_rec_list *ptr, *region = 0;
2414 unsigned long first_addr = 0, rlen = 0, t;
2416 for (ptr = list; ptr; ptr = ptr->next)
2418 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2419 as_bad (" Insn slot not set in unwind record.");
2420 t = slot_index (ptr->slot_number, first_addr);
2421 switch (ptr->r.type)
2428 int size, dir_len = 0;
2429 unsigned long last_addr;
2431 first_addr = ptr->slot_number;
2432 ptr->slot_number = 0;
2433 /* Find either the next body/prologue start, or the end of
2434 the list, and determine the size of the region. */
2435 last_addr = unwind.next_slot_number;
2436 for (last = ptr->next; last != NULL; last = last->next)
2437 if (last->r.type == prologue || last->r.type == prologue_gr
2438 || last->r.type == body)
2440 last_addr = last->slot_number;
2443 else if (!last->next)
2445 /* In the absence of an explicit .body directive,
2446 the prologue ends after the last instruction
2447 covered by an unwind directive. */
2448 if (ptr->r.type != body)
2450 last_addr = last->slot_number;
2451 switch (last->r.type)
2454 dir_len = (count_bits (last->r.record.p.frmask)
2455 + count_bits (last->r.record.p.grmask));
2459 dir_len += count_bits (last->r.record.p.rmask);
2463 dir_len += count_bits (last->r.record.p.brmask);
2466 dir_len += count_bits (last->r.record.p.grmask);
2475 size = slot_index (last_addr, first_addr) + dir_len;
2476 rlen = ptr->r.record.r.rlen = size;
2481 ptr->r.record.b.t = rlen - 1 - t;
2492 case priunat_when_gr:
2493 case priunat_when_mem:
2497 ptr->r.record.p.t = t;
2505 case spill_psprel_p:
2506 ptr->r.record.x.t = t;
2512 as_bad ("frgr_mem record before region record!\n");
2515 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2516 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2517 set_imask (region, ptr->r.record.p.frmask, t, 1);
2518 set_imask (region, ptr->r.record.p.grmask, t, 2);
2523 as_bad ("fr_mem record before region record!\n");
2526 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2527 set_imask (region, ptr->r.record.p.rmask, t, 1);
2532 as_bad ("gr_mem record before region record!\n");
2535 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2536 set_imask (region, ptr->r.record.p.rmask, t, 2);
2541 as_bad ("br_mem record before region record!\n");
2544 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2545 set_imask (region, ptr->r.record.p.brmask, t, 3);
2551 as_bad ("gr_gr record before region record!\n");
2554 set_imask (region, ptr->r.record.p.grmask, t, 2);
2559 as_bad ("br_gr record before region record!\n");
2562 set_imask (region, ptr->r.record.p.brmask, t, 3);
2571 /* Generate an unwind image from a record list. Returns the number of
2572 bytes in the resulting image. The memory image itselof is returned
2573 in the 'ptr' parameter. */
2575 output_unw_records (list, ptr)
2579 int size, x, extra = 0;
2582 fixup_unw_records (list);
2583 size = calc_record_size (list);
2585 /* pad to 8 byte boundry. */
2589 /* Add 8 for the header + 8 more bytes for the personality offset. */
2590 mem = xmalloc (size + extra + 16);
2592 vbyte_mem_ptr = mem + 8;
2593 /* Clear the padding area and personality. */
2594 memset (mem + 8 + size, 0 , extra + 8);
2595 /* Initialize the header area. */
2596 md_number_to_chars (mem, (((bfd_vma) 1 << 48) /* version */
2597 | (unwind.personality_routine
2598 ? ((bfd_vma) 3 << 32) /* U & E handler flags */
2600 | ((size + extra) / 8)), /* length (dwords) */
2603 process_unw_records (list, output_vbyte_mem);
2606 return size + extra + 16;
2610 convert_expr_to_ab_reg (e, ab, regp)
2617 if (e->X_op != O_register)
2620 reg = e->X_add_number;
2621 if (reg >= REG_GR + 4 && reg <= REG_GR + 7)
2624 *regp = reg - REG_GR;
2626 else if ((reg >= REG_FR + 2 && reg <= REG_FR + 5)
2627 || (reg >= REG_FR + 16 && reg <= REG_FR + 31))
2630 *regp = reg - REG_FR;
2632 else if (reg >= REG_BR + 1 && reg <= REG_BR + 5)
2635 *regp = reg - REG_BR;
2642 case REG_PR: *regp = 0; break;
2643 case REG_PSP: *regp = 1; break;
2644 case REG_PRIUNAT: *regp = 2; break;
2645 case REG_BR + 0: *regp = 3; break;
2646 case REG_AR + AR_BSP: *regp = 4; break;
2647 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2648 case REG_AR + AR_RNAT: *regp = 6; break;
2649 case REG_AR + AR_UNAT: *regp = 7; break;
2650 case REG_AR + AR_FPSR: *regp = 8; break;
2651 case REG_AR + AR_PFS: *regp = 9; break;
2652 case REG_AR + AR_LC: *regp = 10; break;
2662 convert_expr_to_xy_reg (e, xy, regp)
2669 if (e->X_op != O_register)
2672 reg = e->X_add_number;
2674 if (reg >= REG_GR && reg <= REG_GR + 127)
2677 *regp = reg - REG_GR;
2679 else if (reg >= REG_FR && reg <= REG_FR + 127)
2682 *regp = reg - REG_FR;
2684 else if (reg >= REG_BR && reg <= REG_BR + 7)
2687 *regp = reg - REG_BR;
2701 radix = *input_line_pointer++;
2703 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
2705 as_bad ("Radix `%c' unsupported", *input_line_pointer);
2706 ignore_rest_of_line ();
2711 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
2713 dot_special_section (which)
2716 set_section ((char *) special_section_name[which]);
2720 add_unwind_entry (ptr)
2724 unwind.tail->next = ptr;
2729 /* The current entry can in fact be a chain of unwind entries. */
2730 if (unwind.current_entry == NULL)
2731 unwind.current_entry = ptr;
2742 if (e.X_op != O_constant)
2743 as_bad ("Operand to .fframe must be a constant");
2745 add_unwind_entry (output_mem_stack_f (e.X_add_number));
2756 reg = e.X_add_number - REG_GR;
2757 if (e.X_op == O_register && reg < 128)
2759 add_unwind_entry (output_mem_stack_v ());
2760 if (! (unwind.prologue_mask & 2))
2761 add_unwind_entry (output_psp_gr (reg));
2764 as_bad ("First operand to .vframe must be a general register");
2768 dot_vframesp (dummy)
2774 if (e.X_op == O_constant)
2776 add_unwind_entry (output_mem_stack_v ());
2777 add_unwind_entry (output_psp_sprel (e.X_add_number));
2780 as_bad ("First operand to .vframesp must be a general register");
2784 dot_vframepsp (dummy)
2790 if (e.X_op == O_constant)
2792 add_unwind_entry (output_mem_stack_v ());
2793 add_unwind_entry (output_psp_sprel (e.X_add_number));
2796 as_bad ("First operand to .vframepsp must be a general register");
2807 sep = parse_operand (&e1);
2809 as_bad ("No second operand to .save");
2810 sep = parse_operand (&e2);
2812 reg1 = e1.X_add_number;
2813 reg2 = e2.X_add_number - REG_GR;
2815 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
2816 if (e1.X_op == O_register)
2818 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
2822 case REG_AR + AR_BSP:
2823 add_unwind_entry (output_bsp_when ());
2824 add_unwind_entry (output_bsp_gr (reg2));
2826 case REG_AR + AR_BSPSTORE:
2827 add_unwind_entry (output_bspstore_when ());
2828 add_unwind_entry (output_bspstore_gr (reg2));
2830 case REG_AR + AR_RNAT:
2831 add_unwind_entry (output_rnat_when ());
2832 add_unwind_entry (output_rnat_gr (reg2));
2834 case REG_AR + AR_UNAT:
2835 add_unwind_entry (output_unat_when ());
2836 add_unwind_entry (output_unat_gr (reg2));
2838 case REG_AR + AR_FPSR:
2839 add_unwind_entry (output_fpsr_when ());
2840 add_unwind_entry (output_fpsr_gr (reg2));
2842 case REG_AR + AR_PFS:
2843 add_unwind_entry (output_pfs_when ());
2844 if (! (unwind.prologue_mask & 4))
2845 add_unwind_entry (output_pfs_gr (reg2));
2847 case REG_AR + AR_LC:
2848 add_unwind_entry (output_lc_when ());
2849 add_unwind_entry (output_lc_gr (reg2));
2852 add_unwind_entry (output_rp_when ());
2853 if (! (unwind.prologue_mask & 8))
2854 add_unwind_entry (output_rp_gr (reg2));
2857 add_unwind_entry (output_preds_when ());
2858 if (! (unwind.prologue_mask & 1))
2859 add_unwind_entry (output_preds_gr (reg2));
2862 add_unwind_entry (output_priunat_when_gr ());
2863 add_unwind_entry (output_priunat_gr (reg2));
2866 as_bad ("First operand not a valid register");
2870 as_bad (" Second operand not a valid register");
2873 as_bad ("First operand not a register");
2881 unsigned long ecount = 0;
2884 sep = parse_operand (&e1);
2885 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
2887 as_bad ("First operand to .restore must be stack pointer (sp)");
2893 parse_operand (&e2);
2894 if (e1.X_op != O_constant)
2896 as_bad ("Second operand to .restore must be constant");
2901 add_unwind_entry (output_epilogue (ecount));
2905 dot_restorereg (dummy)
2908 unsigned int ab, reg;
2913 if (!convert_expr_to_ab_reg (&e, &ab, ®))
2915 as_bad ("First operand to .restorereg must be a preserved register");
2918 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
2922 dot_restorereg_p (dummy)
2925 unsigned int qp, ab, reg;
2929 sep = parse_operand (&e1);
2932 as_bad ("No second operand to .restorereg.p");
2936 parse_operand (&e2);
2938 qp = e1.X_add_number - REG_P;
2939 if (e1.X_op != O_register || qp > 63)
2941 as_bad ("First operand to .restorereg.p must be a predicate");
2945 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
2947 as_bad ("Second operand to .restorereg.p must be a preserved register");
2950 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
2954 generate_unwind_image ()
2957 unsigned char *unw_rec;
2959 /* Force out pending instructions, to make sure all unwind records have
2960 a valid slot_number field. */
2961 ia64_flush_insns ();
2963 /* Generate the unwind record. */
2964 size = output_unw_records (unwind.list, (void **) &unw_rec);
2966 as_bad ("Unwind record is not a multiple of 8 bytes.");
2968 /* If there are unwind records, switch sections, and output the info. */
2971 unsigned char *where;
2973 set_section ((char *) special_section_name[SPECIAL_SECTION_UNWIND_INFO]);
2975 /* Set expression which points to start of unwind descriptor area. */
2976 unwind.info = expr_build_dot ();
2978 where = (unsigned char *) frag_more (size);
2980 /* Issue a label for this address, and keep track of it to put it
2981 in the unwind section. */
2983 /* Copy the information from the unwind record into this section. The
2984 data is already in the correct byte order. */
2985 memcpy (where, unw_rec, size);
2986 /* Add the personality address to the image. */
2987 if (unwind.personality_routine != 0)
2989 exp.X_op = O_symbol;
2990 exp.X_add_symbol = unwind.personality_routine;
2991 exp.X_add_number = 0;
2992 fix_new_exp (frag_now, frag_now_fix () - 8, 8,
2993 &exp, 0, BFD_RELOC_IA64_LTOFF_FPTR64LSB);
2994 unwind.personality_routine = 0;
2996 obj_elf_previous (0);
2999 free_list_records (unwind.list);
3000 unwind.list = unwind.tail = unwind.current_entry = NULL;
3006 dot_handlerdata (dummy)
3009 generate_unwind_image ();
3010 demand_empty_rest_of_line ();
3014 dot_unwentry (dummy)
3017 demand_empty_rest_of_line ();
3028 reg = e.X_add_number - REG_BR;
3029 if (e.X_op == O_register && reg < 8)
3030 add_unwind_entry (output_rp_br (reg));
3032 as_bad ("First operand not a valid branch register");
3036 dot_savemem (psprel)
3043 sep = parse_operand (&e1);
3045 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3046 sep = parse_operand (&e2);
3048 reg1 = e1.X_add_number;
3049 val = e2.X_add_number;
3051 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3052 if (e1.X_op == O_register)
3054 if (e2.X_op == O_constant)
3058 case REG_AR + AR_BSP:
3059 add_unwind_entry (output_bsp_when ());
3060 add_unwind_entry ((psprel
3062 : output_bsp_sprel) (val));
3064 case REG_AR + AR_BSPSTORE:
3065 add_unwind_entry (output_bspstore_when ());
3066 add_unwind_entry ((psprel
3067 ? output_bspstore_psprel
3068 : output_bspstore_sprel) (val));
3070 case REG_AR + AR_RNAT:
3071 add_unwind_entry (output_rnat_when ());
3072 add_unwind_entry ((psprel
3073 ? output_rnat_psprel
3074 : output_rnat_sprel) (val));
3076 case REG_AR + AR_UNAT:
3077 add_unwind_entry (output_unat_when ());
3078 add_unwind_entry ((psprel
3079 ? output_unat_psprel
3080 : output_unat_sprel) (val));
3082 case REG_AR + AR_FPSR:
3083 add_unwind_entry (output_fpsr_when ());
3084 add_unwind_entry ((psprel
3085 ? output_fpsr_psprel
3086 : output_fpsr_sprel) (val));
3088 case REG_AR + AR_PFS:
3089 add_unwind_entry (output_pfs_when ());
3090 add_unwind_entry ((psprel
3092 : output_pfs_sprel) (val));
3094 case REG_AR + AR_LC:
3095 add_unwind_entry (output_lc_when ());
3096 add_unwind_entry ((psprel
3098 : output_lc_sprel) (val));
3101 add_unwind_entry (output_rp_when ());
3102 add_unwind_entry ((psprel
3104 : output_rp_sprel) (val));
3107 add_unwind_entry (output_preds_when ());
3108 add_unwind_entry ((psprel
3109 ? output_preds_psprel
3110 : output_preds_sprel) (val));
3113 add_unwind_entry (output_priunat_when_mem ());
3114 add_unwind_entry ((psprel
3115 ? output_priunat_psprel
3116 : output_priunat_sprel) (val));
3119 as_bad ("First operand not a valid register");
3123 as_bad (" Second operand not a valid constant");
3126 as_bad ("First operand not a register");
3135 sep = parse_operand (&e1);
3137 parse_operand (&e2);
3139 if (e1.X_op != O_constant)
3140 as_bad ("First operand to .save.g must be a constant.");
3143 int grmask = e1.X_add_number;
3145 add_unwind_entry (output_gr_mem (grmask));
3148 int reg = e2.X_add_number - REG_GR;
3149 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3150 add_unwind_entry (output_gr_gr (grmask, reg));
3152 as_bad ("Second operand is an invalid register.");
3163 sep = parse_operand (&e1);
3165 if (e1.X_op != O_constant)
3166 as_bad ("Operand to .save.f must be a constant.");
3168 add_unwind_entry (output_fr_mem (e1.X_add_number));
3180 sep = parse_operand (&e1);
3181 if (e1.X_op != O_constant)
3183 as_bad ("First operand to .save.b must be a constant.");
3186 brmask = e1.X_add_number;
3190 sep = parse_operand (&e2);
3191 reg = e2.X_add_number - REG_GR;
3192 if (e2.X_op != O_register || reg > 127)
3194 as_bad ("Second operand to .save.b must be a general register.");
3197 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3200 add_unwind_entry (output_br_mem (brmask));
3202 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3203 ignore_rest_of_line ();
3212 sep = parse_operand (&e1);
3214 parse_operand (&e2);
3216 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3217 as_bad ("Both operands of .save.gf must be constants.");
3220 int grmask = e1.X_add_number;
3221 int frmask = e2.X_add_number;
3222 add_unwind_entry (output_frgr_mem (grmask, frmask));
3233 sep = parse_operand (&e);
3234 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3235 ignore_rest_of_line ();
3237 if (e.X_op != O_constant)
3238 as_bad ("Operand to .spill must be a constant");
3240 add_unwind_entry (output_spill_base (e.X_add_number));
3244 dot_spillreg (dummy)
3247 int sep, ab, xy, reg, treg;
3250 sep = parse_operand (&e1);
3253 as_bad ("No second operand to .spillreg");
3257 parse_operand (&e2);
3259 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3261 as_bad ("First operand to .spillreg must be a preserved register");
3265 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3267 as_bad ("Second operand to .spillreg must be a register");
3271 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3275 dot_spillmem (psprel)
3281 sep = parse_operand (&e1);
3284 as_bad ("Second operand missing");
3288 parse_operand (&e2);
3290 if (!convert_expr_to_ab_reg (&e1, &ab, ®))
3292 as_bad ("First operand to .spill%s must be a preserved register",
3293 psprel ? "psp" : "sp");
3297 if (e2.X_op != O_constant)
3299 as_bad ("Second operand to .spill%s must be a constant",
3300 psprel ? "psp" : "sp");
3305 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3307 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3311 dot_spillreg_p (dummy)
3314 int sep, ab, xy, reg, treg;
3315 expressionS e1, e2, e3;
3318 sep = parse_operand (&e1);
3321 as_bad ("No second and third operand to .spillreg.p");
3325 sep = parse_operand (&e2);
3328 as_bad ("No third operand to .spillreg.p");
3332 parse_operand (&e3);
3334 qp = e1.X_add_number - REG_P;
3336 if (e1.X_op != O_register || qp > 63)
3338 as_bad ("First operand to .spillreg.p must be a predicate");
3342 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3344 as_bad ("Second operand to .spillreg.p must be a preserved register");
3348 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3350 as_bad ("Third operand to .spillreg.p must be a register");
3354 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3358 dot_spillmem_p (psprel)
3361 expressionS e1, e2, e3;
3365 sep = parse_operand (&e1);
3368 as_bad ("Second operand missing");
3372 parse_operand (&e2);
3375 as_bad ("Second operand missing");
3379 parse_operand (&e3);
3381 qp = e1.X_add_number - REG_P;
3382 if (e1.X_op != O_register || qp > 63)
3384 as_bad ("First operand to .spill%s_p must be a predicate",
3385 psprel ? "psp" : "sp");
3389 if (!convert_expr_to_ab_reg (&e2, &ab, ®))
3391 as_bad ("Second operand to .spill%s_p must be a preserved register",
3392 psprel ? "psp" : "sp");
3396 if (e3.X_op != O_constant)
3398 as_bad ("Third operand to .spill%s_p must be a constant",
3399 psprel ? "psp" : "sp");
3404 add_unwind_entry (output_spill_psprel_p (qp, ab, reg, e3.X_add_number));
3406 add_unwind_entry (output_spill_sprel_p (qp, ab, reg, e3.X_add_number));
3410 dot_label_state (dummy)
3416 if (e.X_op != O_constant)
3418 as_bad ("Operand to .label_state must be a constant");
3421 add_unwind_entry (output_label_state (e.X_add_number));
3425 dot_copy_state (dummy)
3431 if (e.X_op != O_constant)
3433 as_bad ("Operand to .copy_state must be a constant");
3436 add_unwind_entry (output_copy_state (e.X_add_number));
3446 sep = parse_operand (&e1);
3449 as_bad ("Second operand to .unwabi missing");
3452 sep = parse_operand (&e2);
3453 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3454 ignore_rest_of_line ();
3456 if (e1.X_op != O_constant)
3458 as_bad ("First operand to .unwabi must be a constant");
3462 if (e2.X_op != O_constant)
3464 as_bad ("Second operand to .unwabi must be a constant");
3468 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
3472 dot_personality (dummy)
3477 name = input_line_pointer;
3478 c = get_symbol_end ();
3479 p = input_line_pointer;
3480 unwind.personality_routine = symbol_find_or_make (name);
3483 demand_empty_rest_of_line ();
3493 unwind.proc_start = expr_build_dot ();
3494 /* Parse names of main and alternate entry points and mark them as
3495 function symbols: */
3499 name = input_line_pointer;
3500 c = get_symbol_end ();
3501 p = input_line_pointer;
3502 sym = symbol_find_or_make (name);
3503 if (unwind.proc_start == 0)
3505 unwind.proc_start = sym;
3507 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
3510 if (*input_line_pointer != ',')
3512 ++input_line_pointer;
3514 demand_empty_rest_of_line ();
3517 unwind.list = unwind.tail = unwind.current_entry = NULL;
3518 unwind.personality_routine = 0;
3525 unwind.prologue = 0;
3526 unwind.prologue_mask = 0;
3528 add_unwind_entry (output_body ());
3529 demand_empty_rest_of_line ();
3533 dot_prologue (dummy)
3537 int mask = 0, grsave;
3539 if (!is_it_end_of_statement ())
3542 sep = parse_operand (&e1);
3544 as_bad ("No second operand to .prologue");
3545 sep = parse_operand (&e2);
3546 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3547 ignore_rest_of_line ();
3549 if (e1.X_op == O_constant)
3551 mask = e1.X_add_number;
3553 if (e2.X_op == O_constant)
3554 grsave = e2.X_add_number;
3555 else if (e2.X_op == O_register
3556 && (grsave = e2.X_add_number - REG_GR) < 128)
3559 as_bad ("Second operand not a constant or general register");
3561 add_unwind_entry (output_prologue_gr (mask, grsave));
3564 as_bad ("First operand not a constant");
3567 add_unwind_entry (output_prologue ());
3569 unwind.prologue = 1;
3570 unwind.prologue_mask = mask;
3581 subsegT saved_subseg;
3583 saved_seg = now_seg;
3584 saved_subseg = now_subseg;
3587 demand_empty_rest_of_line ();
3589 insn_group_break (1, 0, 0);
3591 /* If there was a .handlerdata, we haven't generated an image yet. */
3592 if (unwind.info == 0)
3594 generate_unwind_image ();
3597 subseg_set (md.last_text_seg, 0);
3598 unwind.proc_end = expr_build_dot ();
3600 set_section ((char *) special_section_name[SPECIAL_SECTION_UNWIND]);
3601 ptr = frag_more (24);
3602 where = frag_now_fix () - 24;
3604 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
3605 e.X_op = O_pseudo_fixup;
3606 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3608 e.X_add_symbol = unwind.proc_start;
3609 ia64_cons_fix_new (frag_now, where, 8, &e);
3611 e.X_op = O_pseudo_fixup;
3612 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3614 e.X_add_symbol = unwind.proc_end;
3615 ia64_cons_fix_new (frag_now, where + 8, 8, &e);
3617 if (unwind.info != 0)
3619 e.X_op = O_pseudo_fixup;
3620 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
3622 e.X_add_symbol = unwind.info;
3623 ia64_cons_fix_new (frag_now, where + 16, 8, &e);
3626 md_number_to_chars (ptr + 16, 0, 8);
3628 subseg_set (saved_seg, saved_subseg);
3629 unwind.proc_start = unwind.proc_end = unwind.info = 0;
3633 dot_template (template)
3636 CURR_SLOT.user_template = template;
3643 int ins, locs, outs, rots;
3645 if (is_it_end_of_statement ())
3646 ins = locs = outs = rots = 0;
3649 ins = get_absolute_expression ();
3650 if (*input_line_pointer++ != ',')
3652 locs = get_absolute_expression ();
3653 if (*input_line_pointer++ != ',')
3655 outs = get_absolute_expression ();
3656 if (*input_line_pointer++ != ',')
3658 rots = get_absolute_expression ();
3660 set_regstack (ins, locs, outs, rots);
3664 as_bad ("Comma expected");
3665 ignore_rest_of_line ();
3672 unsigned num_regs, num_alloced = 0;
3673 struct dynreg **drpp, *dr;
3674 int ch, base_reg = 0;
3680 case DYNREG_GR: base_reg = REG_GR + 32; break;
3681 case DYNREG_FR: base_reg = REG_FR + 32; break;
3682 case DYNREG_PR: base_reg = REG_P + 16; break;
3686 /* First, remove existing names from hash table. */
3687 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
3689 hash_delete (md.dynreg_hash, dr->name);
3693 drpp = &md.dynreg[type];
3696 start = input_line_pointer;
3697 ch = get_symbol_end ();
3698 *input_line_pointer = ch;
3699 len = (input_line_pointer - start);
3702 if (*input_line_pointer != '[')
3704 as_bad ("Expected '['");
3707 ++input_line_pointer; /* skip '[' */
3709 num_regs = get_absolute_expression ();
3711 if (*input_line_pointer++ != ']')
3713 as_bad ("Expected ']'");
3718 num_alloced += num_regs;
3722 if (num_alloced > md.rot.num_regs)
3724 as_bad ("Used more than the declared %d rotating registers",
3730 if (num_alloced > 96)
3732 as_bad ("Used more than the available 96 rotating registers");
3737 if (num_alloced > 48)
3739 as_bad ("Used more than the available 48 rotating registers");
3748 name = obstack_alloc (¬es, len + 1);
3749 memcpy (name, start, len);
3754 *drpp = obstack_alloc (¬es, sizeof (*dr));
3755 memset (*drpp, 0, sizeof (*dr));
3760 dr->num_regs = num_regs;
3761 dr->base = base_reg;
3763 base_reg += num_regs;
3765 if (hash_insert (md.dynreg_hash, name, dr))
3767 as_bad ("Attempt to redefine register set `%s'", name);
3771 if (*input_line_pointer != ',')
3773 ++input_line_pointer; /* skip comma */
3776 demand_empty_rest_of_line ();
3780 ignore_rest_of_line ();
3784 dot_byteorder (byteorder)
3787 target_big_endian = byteorder;
3799 option = input_line_pointer;
3800 ch = get_symbol_end ();
3801 if (strcmp (option, "lsb") == 0)
3802 md.flags &= ~EF_IA_64_BE;
3803 else if (strcmp (option, "msb") == 0)
3804 md.flags |= EF_IA_64_BE;
3805 else if (strcmp (option, "abi32") == 0)
3806 md.flags &= ~EF_IA_64_ABI64;
3807 else if (strcmp (option, "abi64") == 0)
3808 md.flags |= EF_IA_64_ABI64;
3810 as_bad ("Unknown psr option `%s'", option);
3811 *input_line_pointer = ch;
3814 if (*input_line_pointer != ',')
3817 ++input_line_pointer;
3820 demand_empty_rest_of_line ();
3827 as_bad (".alias not implemented yet");
3834 new_logical_line (0, get_absolute_expression ());
3835 demand_empty_rest_of_line ();
3839 parse_section_name ()
3845 if (*input_line_pointer != '"')
3847 as_bad ("Missing section name");
3848 ignore_rest_of_line ();
3851 name = demand_copy_C_string (&len);
3854 ignore_rest_of_line ();
3858 if (*input_line_pointer != ',')
3860 as_bad ("Comma expected after section name");
3861 ignore_rest_of_line ();
3864 ++input_line_pointer; /* skip comma */
3872 char *name = parse_section_name ();
3878 obj_elf_previous (0);
3881 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
3884 stmt_float_cons (kind)
3891 case 'd': size = 8; break;
3892 case 'x': size = 10; break;
3899 ia64_do_align (size);
3907 int saved_auto_align = md.auto_align;
3911 md.auto_align = saved_auto_align;
3915 dot_xfloat_cons (kind)
3918 char *name = parse_section_name ();
3923 stmt_float_cons (kind);
3924 obj_elf_previous (0);
3928 dot_xstringer (zero)
3931 char *name = parse_section_name ();
3937 obj_elf_previous (0);
3944 int saved_auto_align = md.auto_align;
3945 char *name = parse_section_name ();
3952 md.auto_align = saved_auto_align;
3953 obj_elf_previous (0);
3957 dot_xfloat_cons_ua (kind)
3960 int saved_auto_align = md.auto_align;
3961 char *name = parse_section_name ();
3967 stmt_float_cons (kind);
3968 md.auto_align = saved_auto_align;
3969 obj_elf_previous (0);
3972 /* .reg.val <regname>,value */
3981 if (reg.X_op != O_register)
3983 as_bad (_("Register name expected"));
3984 ignore_rest_of_line ();
3986 else if (*input_line_pointer++ != ',')
3988 as_bad (_("Comma expected"));
3989 ignore_rest_of_line ();
3993 valueT value = get_absolute_expression ();
3994 int regno = reg.X_add_number;
3995 if (regno < REG_GR || regno > REG_GR + 128)
3996 as_warn (_("Register value annotation ignored"));
3999 gr_values[regno - REG_GR].known = 1;
4000 gr_values[regno - REG_GR].value = value;
4001 gr_values[regno - REG_GR].path = md.path;
4004 demand_empty_rest_of_line ();
4007 /* select dv checking mode
4012 A stop is inserted when changing modes
4019 if (md.manual_bundling)
4020 as_warn (_("Directive invalid within a bundle"));
4022 if (type == 'E' || type == 'A')
4023 md.mode_explicitly_set = 0;
4025 md.mode_explicitly_set = 1;
4032 if (md.explicit_mode)
4033 insn_group_break (1, 0, 0);
4034 md.explicit_mode = 0;
4038 if (!md.explicit_mode)
4039 insn_group_break (1, 0, 0);
4040 md.explicit_mode = 1;
4044 if (md.explicit_mode != md.default_explicit_mode)
4045 insn_group_break (1, 0, 0);
4046 md.explicit_mode = md.default_explicit_mode;
4047 md.mode_explicitly_set = 0;
4058 for (regno = 0; regno < 64; regno++)
4060 if (mask & ((valueT) 1 << regno))
4062 fprintf (stderr, "%s p%d", comma, regno);
4069 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4070 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4071 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4072 .pred.safe_across_calls p1 [, p2 [,...]]
4081 int p1 = -1, p2 = -1;
4085 if (*input_line_pointer != '"')
4087 as_bad (_("Missing predicate relation type"));
4088 ignore_rest_of_line ();
4094 char *form = demand_copy_C_string (&len);
4095 if (strcmp (form, "mutex") == 0)
4097 else if (strcmp (form, "clear") == 0)
4099 else if (strcmp (form, "imply") == 0)
4103 as_bad (_("Unrecognized predicate relation type"));
4104 ignore_rest_of_line ();
4108 if (*input_line_pointer == ',')
4109 ++input_line_pointer;
4119 if (toupper (*input_line_pointer) != 'P'
4120 || (regno = atoi (++input_line_pointer)) < 0
4123 as_bad (_("Predicate register expected"));
4124 ignore_rest_of_line ();
4127 while (isdigit (*input_line_pointer))
4128 ++input_line_pointer;
4135 as_warn (_("Duplicate predicate register ignored"));
4138 /* See if it's a range. */
4139 if (*input_line_pointer == '-')
4142 ++input_line_pointer;
4144 if (toupper (*input_line_pointer) != 'P'
4145 || (regno = atoi (++input_line_pointer)) < 0
4148 as_bad (_("Predicate register expected"));
4149 ignore_rest_of_line ();
4152 while (isdigit (*input_line_pointer))
4153 ++input_line_pointer;
4157 as_bad (_("Bad register range"));
4158 ignore_rest_of_line ();
4169 if (*input_line_pointer != ',')
4171 ++input_line_pointer;
4180 clear_qp_mutex (mask);
4181 clear_qp_implies (mask, (valueT) 0);
4184 if (count != 2 || p1 == -1 || p2 == -1)
4185 as_bad (_("Predicate source and target required"));
4186 else if (p1 == 0 || p2 == 0)
4187 as_bad (_("Use of p0 is not valid in this context"));
4189 add_qp_imply (p1, p2);
4194 as_bad (_("At least two PR arguments expected"));
4199 as_bad (_("Use of p0 is not valid in this context"));
4202 add_qp_mutex (mask);
4205 /* note that we don't override any existing relations */
4208 as_bad (_("At least one PR argument expected"));
4213 fprintf (stderr, "Safe across calls: ");
4214 print_prmask (mask);
4215 fprintf (stderr, "\n");
4217 qp_safe_across_calls = mask;
4220 demand_empty_rest_of_line ();
4223 /* .entry label [, label [, ...]]
4224 Hint to DV code that the given labels are to be considered entry points.
4225 Otherwise, only global labels are considered entry points. */
4238 name = input_line_pointer;
4239 c = get_symbol_end ();
4240 symbolP = symbol_find_or_make (name);
4242 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4244 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4247 *input_line_pointer = c;
4249 c = *input_line_pointer;
4252 input_line_pointer++;
4254 if (*input_line_pointer == '\n')
4260 demand_empty_rest_of_line ();
4263 /* .mem.offset offset, base
4264 "base" is used to distinguish between offsets from a different base. */
4267 dot_mem_offset (dummy)
4270 md.mem_offset.hint = 1;
4271 md.mem_offset.offset = get_absolute_expression ();
4272 if (*input_line_pointer != ',')
4274 as_bad (_("Comma expected"));
4275 ignore_rest_of_line ();
4278 ++input_line_pointer;
4279 md.mem_offset.base = get_absolute_expression ();
4280 demand_empty_rest_of_line ();
4283 /* ia64-specific pseudo-ops: */
4284 const pseudo_typeS md_pseudo_table[] =
4286 { "radix", dot_radix, 0 },
4287 { "lcomm", s_lcomm_bytes, 1 },
4288 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4289 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4290 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4291 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4292 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4293 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4294 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4295 { "proc", dot_proc, 0 },
4296 { "body", dot_body, 0 },
4297 { "prologue", dot_prologue, 0 },
4298 { "endp", dot_endp },
4299 { "file", dwarf2_directive_file },
4300 { "loc", dwarf2_directive_loc },
4302 { "fframe", dot_fframe },
4303 { "vframe", dot_vframe },
4304 { "vframesp", dot_vframesp },
4305 { "vframepsp", dot_vframepsp },
4306 { "save", dot_save },
4307 { "restore", dot_restore },
4308 { "restorereg", dot_restorereg },
4309 { "restorereg.p", dot_restorereg_p },
4310 { "handlerdata", dot_handlerdata },
4311 { "unwentry", dot_unwentry },
4312 { "altrp", dot_altrp },
4313 { "savesp", dot_savemem, 0 },
4314 { "savepsp", dot_savemem, 1 },
4315 { "save.g", dot_saveg },
4316 { "save.f", dot_savef },
4317 { "save.b", dot_saveb },
4318 { "save.gf", dot_savegf },
4319 { "spill", dot_spill },
4320 { "spillreg", dot_spillreg },
4321 { "spillsp", dot_spillmem, 0 },
4322 { "spillpsp", dot_spillmem, 1 },
4323 { "spillreg.p", dot_spillreg_p },
4324 { "spillsp.p", dot_spillmem_p, 0 },
4325 { "spillpsp.p", dot_spillmem_p, 1 },
4326 { "label_state", dot_label_state },
4327 { "copy_state", dot_copy_state },
4328 { "unwabi", dot_unwabi },
4329 { "personality", dot_personality },
4331 { "estate", dot_estate },
4333 { "mii", dot_template, 0x0 },
4334 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
4335 { "mlx", dot_template, 0x2 },
4336 { "mmi", dot_template, 0x4 },
4337 { "mfi", dot_template, 0x6 },
4338 { "mmf", dot_template, 0x7 },
4339 { "mib", dot_template, 0x8 },
4340 { "mbb", dot_template, 0x9 },
4341 { "bbb", dot_template, 0xb },
4342 { "mmb", dot_template, 0xc },
4343 { "mfb", dot_template, 0xe },
4345 { "lb", dot_scope, 0 },
4346 { "le", dot_scope, 1 },
4348 { "align", s_align_bytes, 0 },
4349 { "regstk", dot_regstk, 0 },
4350 { "rotr", dot_rot, DYNREG_GR },
4351 { "rotf", dot_rot, DYNREG_FR },
4352 { "rotp", dot_rot, DYNREG_PR },
4353 { "lsb", dot_byteorder, 0 },
4354 { "msb", dot_byteorder, 1 },
4355 { "psr", dot_psr, 0 },
4356 { "alias", dot_alias, 0 },
4357 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
4359 { "xdata1", dot_xdata, 1 },
4360 { "xdata2", dot_xdata, 2 },
4361 { "xdata4", dot_xdata, 4 },
4362 { "xdata8", dot_xdata, 8 },
4363 { "xreal4", dot_xfloat_cons, 'f' },
4364 { "xreal8", dot_xfloat_cons, 'd' },
4365 { "xreal10", dot_xfloat_cons, 'x' },
4366 { "xstring", dot_xstringer, 0 },
4367 { "xstringz", dot_xstringer, 1 },
4369 /* unaligned versions: */
4370 { "xdata2.ua", dot_xdata_ua, 2 },
4371 { "xdata4.ua", dot_xdata_ua, 4 },
4372 { "xdata8.ua", dot_xdata_ua, 8 },
4373 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
4374 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
4375 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
4377 /* annotations/DV checking support */
4378 { "entry", dot_entry, 0 },
4379 { "mem.offset", dot_mem_offset },
4380 { "pred.rel", dot_pred_rel, 0 },
4381 { "pred.rel.clear", dot_pred_rel, 'c' },
4382 { "pred.rel.imply", dot_pred_rel, 'i' },
4383 { "pred.rel.mutex", dot_pred_rel, 'm' },
4384 { "pred.safe_across_calls", dot_pred_rel, 's' },
4385 { "reg.val", dot_reg_val },
4386 { "auto", dot_dv_mode, 'a' },
4387 { "explicit", dot_dv_mode, 'e' },
4388 { "default", dot_dv_mode, 'd' },
4393 static const struct pseudo_opcode
4396 void (*handler) (int);
4401 /* these are more like pseudo-ops, but don't start with a dot */
4402 { "data1", cons, 1 },
4403 { "data2", cons, 2 },
4404 { "data4", cons, 4 },
4405 { "data8", cons, 8 },
4406 { "real4", stmt_float_cons, 'f' },
4407 { "real8", stmt_float_cons, 'd' },
4408 { "real10", stmt_float_cons, 'x' },
4409 { "string", stringer, 0 },
4410 { "stringz", stringer, 1 },
4412 /* unaligned versions: */
4413 { "data2.ua", stmt_cons_ua, 2 },
4414 { "data4.ua", stmt_cons_ua, 4 },
4415 { "data8.ua", stmt_cons_ua, 8 },
4416 { "real4.ua", float_cons, 'f' },
4417 { "real8.ua", float_cons, 'd' },
4418 { "real10.ua", float_cons, 'x' },
4421 /* Declare a register by creating a symbol for it and entering it in
4422 the symbol table. */
4425 declare_register (name, regnum)
4432 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
4434 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
4436 as_fatal ("Inserting \"%s\" into register table failed: %s",
4443 declare_register_set (prefix, num_regs, base_regnum)
4451 for (i = 0; i < num_regs; ++i)
4453 sprintf (name, "%s%u", prefix, i);
4454 declare_register (name, base_regnum + i);
4459 operand_width (opnd)
4460 enum ia64_opnd opnd;
4462 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
4463 unsigned int bits = 0;
4467 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
4468 bits += odesc->field[i].bits;
4474 operand_match (idesc, index, e)
4475 const struct ia64_opcode *idesc;
4479 enum ia64_opnd opnd = idesc->operands[index];
4480 int bits, relocatable = 0;
4481 struct insn_fix *fix;
4488 case IA64_OPND_AR_CCV:
4489 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
4493 case IA64_OPND_AR_PFS:
4494 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
4499 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
4504 if (e->X_op == O_register && e->X_add_number == REG_IP)
4509 if (e->X_op == O_register && e->X_add_number == REG_PR)
4513 case IA64_OPND_PR_ROT:
4514 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
4519 if (e->X_op == O_register && e->X_add_number == REG_PSR)
4523 case IA64_OPND_PSR_L:
4524 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
4528 case IA64_OPND_PSR_UM:
4529 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
4534 if (e->X_op == O_constant && e->X_add_number == 1)
4539 if (e->X_op == O_constant && e->X_add_number == 8)
4544 if (e->X_op == O_constant && e->X_add_number == 16)
4548 /* register operands: */
4551 if (e->X_op == O_register && e->X_add_number >= REG_AR
4552 && e->X_add_number < REG_AR + 128)
4558 if (e->X_op == O_register && e->X_add_number >= REG_BR
4559 && e->X_add_number < REG_BR + 8)
4564 if (e->X_op == O_register && e->X_add_number >= REG_CR
4565 && e->X_add_number < REG_CR + 128)
4573 if (e->X_op == O_register && e->X_add_number >= REG_FR
4574 && e->X_add_number < REG_FR + 128)
4580 if (e->X_op == O_register && e->X_add_number >= REG_P
4581 && e->X_add_number < REG_P + 64)
4588 if (e->X_op == O_register && e->X_add_number >= REG_GR
4589 && e->X_add_number < REG_GR + 128)
4593 case IA64_OPND_R3_2:
4594 if (e->X_op == O_register && e->X_add_number >= REG_GR
4595 && e->X_add_number < REG_GR + 4)
4599 /* indirect operands: */
4600 case IA64_OPND_CPUID_R3:
4601 case IA64_OPND_DBR_R3:
4602 case IA64_OPND_DTR_R3:
4603 case IA64_OPND_ITR_R3:
4604 case IA64_OPND_IBR_R3:
4605 case IA64_OPND_MSR_R3:
4606 case IA64_OPND_PKR_R3:
4607 case IA64_OPND_PMC_R3:
4608 case IA64_OPND_PMD_R3:
4609 case IA64_OPND_RR_R3:
4610 if (e->X_op == O_index && e->X_op_symbol
4611 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
4612 == opnd - IA64_OPND_CPUID_R3))
4617 if (e->X_op == O_index && !e->X_op_symbol)
4621 /* immediate operands: */
4622 case IA64_OPND_CNT2a:
4623 case IA64_OPND_LEN4:
4624 case IA64_OPND_LEN6:
4625 bits = operand_width (idesc->operands[index]);
4626 if (e->X_op == O_constant
4627 && (bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
4631 case IA64_OPND_CNT2b:
4632 if (e->X_op == O_constant
4633 && (bfd_vma) (e->X_add_number - 1) < 3)
4637 case IA64_OPND_CNT2c:
4638 val = e->X_add_number;
4639 if (e->X_op == O_constant
4640 && (val == 0 || val == 7 || val == 15 || val == 16))
4645 /* SOR must be an integer multiple of 8 */
4646 if (e->X_add_number & 0x7)
4650 if (e->X_op == O_constant &&
4651 (bfd_vma) e->X_add_number <= 96)
4655 case IA64_OPND_IMMU62:
4656 if (e->X_op == O_constant)
4658 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
4663 /* FIXME -- need 62-bit relocation type */
4664 as_bad (_("62-bit relocation not yet implemented"));
4668 case IA64_OPND_IMMU64:
4669 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
4670 || e->X_op == O_subtract)
4672 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
4673 fix->code = BFD_RELOC_IA64_IMM64;
4674 if (e->X_op != O_subtract)
4676 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
4677 if (e->X_op == O_pseudo_fixup)
4681 fix->opnd = idesc->operands[index];
4684 ++CURR_SLOT.num_fixups;
4687 else if (e->X_op == O_constant)
4691 case IA64_OPND_CCNT5:
4692 case IA64_OPND_CNT5:
4693 case IA64_OPND_CNT6:
4694 case IA64_OPND_CPOS6a:
4695 case IA64_OPND_CPOS6b:
4696 case IA64_OPND_CPOS6c:
4697 case IA64_OPND_IMMU2:
4698 case IA64_OPND_IMMU7a:
4699 case IA64_OPND_IMMU7b:
4700 case IA64_OPND_IMMU21:
4701 case IA64_OPND_IMMU24:
4702 case IA64_OPND_MBTYPE4:
4703 case IA64_OPND_MHTYPE8:
4704 case IA64_OPND_POS6:
4705 bits = operand_width (idesc->operands[index]);
4706 if (e->X_op == O_constant
4707 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
4711 case IA64_OPND_IMMU9:
4712 bits = operand_width (idesc->operands[index]);
4713 if (e->X_op == O_constant
4714 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
4716 int lobits = e->X_add_number & 0x3;
4717 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
4718 e->X_add_number |= (bfd_vma) 0x3;
4723 case IA64_OPND_IMM44:
4724 /* least 16 bits must be zero */
4725 if ((e->X_add_number & 0xffff) != 0)
4726 as_warn (_("lower 16 bits of mask ignored"));
4728 if (e->X_op == O_constant
4729 && ((e->X_add_number >= 0
4730 && e->X_add_number < ((bfd_vma) 1 << 44))
4731 || (e->X_add_number < 0
4732 && -e->X_add_number <= ((bfd_vma) 1 << 44))))
4735 if (e->X_add_number >= 0
4736 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
4738 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
4744 case IA64_OPND_IMM17:
4745 /* bit 0 is a don't care (pr0 is hardwired to 1) */
4746 if (e->X_op == O_constant
4747 && ((e->X_add_number >= 0
4748 && e->X_add_number < ((bfd_vma) 1 << 17))
4749 || (e->X_add_number < 0
4750 && -e->X_add_number <= ((bfd_vma) 1 << 17))))
4753 if (e->X_add_number >= 0
4754 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
4756 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
4762 case IA64_OPND_IMM14:
4763 case IA64_OPND_IMM22:
4765 case IA64_OPND_IMM1:
4766 case IA64_OPND_IMM8:
4767 case IA64_OPND_IMM8U4:
4768 case IA64_OPND_IMM8M1:
4769 case IA64_OPND_IMM8M1U4:
4770 case IA64_OPND_IMM8M1U8:
4771 case IA64_OPND_IMM9a:
4772 case IA64_OPND_IMM9b:
4773 bits = operand_width (idesc->operands[index]);
4774 if (relocatable && (e->X_op == O_symbol
4775 || e->X_op == O_subtract
4776 || e->X_op == O_pseudo_fixup))
4778 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
4780 if (idesc->operands[index] == IA64_OPND_IMM14)
4781 fix->code = BFD_RELOC_IA64_IMM14;
4783 fix->code = BFD_RELOC_IA64_IMM22;
4785 if (e->X_op != O_subtract)
4787 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
4788 if (e->X_op == O_pseudo_fixup)
4792 fix->opnd = idesc->operands[index];
4795 ++CURR_SLOT.num_fixups;
4798 else if (e->X_op != O_constant
4799 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
4802 if (opnd == IA64_OPND_IMM8M1U4)
4804 /* Zero is not valid for unsigned compares that take an adjusted
4805 constant immediate range. */
4806 if (e->X_add_number == 0)
4809 /* Sign-extend 32-bit unsigned numbers, so that the following range
4810 checks will work. */
4811 val = e->X_add_number;
4812 if (((val & (~(bfd_vma) 0 << 32)) == 0)
4813 && ((val & ((bfd_vma) 1 << 31)) != 0))
4814 val = ((val << 32) >> 32);
4816 /* Check for 0x100000000. This is valid because
4817 0x100000000-1 is the same as ((uint32_t) -1). */
4818 if (val == ((bfd_signed_vma) 1 << 32))
4823 else if (opnd == IA64_OPND_IMM8M1U8)
4825 /* Zero is not valid for unsigned compares that take an adjusted
4826 constant immediate range. */
4827 if (e->X_add_number == 0)
4830 /* Check for 0x10000000000000000. */
4831 if (e->X_op == O_big)
4833 if (generic_bignum[0] == 0
4834 && generic_bignum[1] == 0
4835 && generic_bignum[2] == 0
4836 && generic_bignum[3] == 0
4837 && generic_bignum[4] == 1)
4843 val = e->X_add_number - 1;
4845 else if (opnd == IA64_OPND_IMM8M1)
4846 val = e->X_add_number - 1;
4847 else if (opnd == IA64_OPND_IMM8U4)
4849 /* Sign-extend 32-bit unsigned numbers, so that the following range
4850 checks will work. */
4851 val = e->X_add_number;
4852 if (((val & (~(bfd_vma) 0 << 32)) == 0)
4853 && ((val & ((bfd_vma) 1 << 31)) != 0))
4854 val = ((val << 32) >> 32);
4857 val = e->X_add_number;
4859 if ((val >= 0 && val < ((bfd_vma) 1 << (bits - 1)))
4860 || (val < 0 && -val <= ((bfd_vma) 1 << (bits - 1))))
4864 case IA64_OPND_INC3:
4865 /* +/- 1, 4, 8, 16 */
4866 val = e->X_add_number;
4869 if (e->X_op == O_constant
4870 && (val == 1 || val == 4 || val == 8 || val == 16))
4874 case IA64_OPND_TGT25:
4875 case IA64_OPND_TGT25b:
4876 case IA64_OPND_TGT25c:
4877 case IA64_OPND_TGT64:
4878 if (e->X_op == O_symbol)
4880 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
4881 if (opnd == IA64_OPND_TGT25)
4882 fix->code = BFD_RELOC_IA64_PCREL21F;
4883 else if (opnd == IA64_OPND_TGT25b)
4884 fix->code = BFD_RELOC_IA64_PCREL21M;
4885 else if (opnd == IA64_OPND_TGT25c)
4886 fix->code = BFD_RELOC_IA64_PCREL21B;
4887 else if (opnd == IA64_OPND_TGT64)
4888 fix->code = BFD_RELOC_IA64_PCREL60B;
4892 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
4893 fix->opnd = idesc->operands[index];
4896 ++CURR_SLOT.num_fixups;
4899 case IA64_OPND_TAG13:
4900 case IA64_OPND_TAG13b:
4907 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
4908 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, 0);
4909 fix->opnd = idesc->operands[index];
4912 ++CURR_SLOT.num_fixups;
4932 memset (e, 0, sizeof (*e));
4935 if (*input_line_pointer != '}')
4937 sep = *input_line_pointer++;
4941 if (!md.manual_bundling)
4942 as_warn ("Found '}' when manual bundling is off");
4944 CURR_SLOT.manual_bundling_off = 1;
4945 md.manual_bundling = 0;
4951 /* Returns the next entry in the opcode table that matches the one in
4952 IDESC, and frees the entry in IDESC. If no matching entry is
4953 found, NULL is returned instead. */
4955 static struct ia64_opcode *
4956 get_next_opcode (struct ia64_opcode *idesc)
4958 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
4959 ia64_free_opcode (idesc);
4963 /* Parse the operands for the opcode and find the opcode variant that
4964 matches the specified operands, or NULL if no match is possible. */
4966 static struct ia64_opcode *
4967 parse_operands (idesc)
4968 struct ia64_opcode *idesc;
4970 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
4972 enum ia64_opnd expected_operand = IA64_OPND_NIL;
4974 char *first_arg = 0, *end, *saved_input_pointer;
4977 assert (strlen (idesc->name) <= 128);
4979 strcpy (mnemonic, idesc->name);
4980 if (idesc->operands[2] == IA64_OPND_SOF)
4982 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
4983 can't parse the first operand until we have parsed the
4984 remaining operands of the "alloc" instruction. */
4986 first_arg = input_line_pointer;
4987 end = strchr (input_line_pointer, '=');
4990 as_bad ("Expected separator `='");
4993 input_line_pointer = end + 1;
4998 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5000 sep = parse_operand (CURR_SLOT.opnd + i);
5001 if (CURR_SLOT.opnd[i].X_op == O_absent)
5006 if (sep != '=' && sep != ',')
5011 if (num_outputs > 0)
5012 as_bad ("Duplicate equal sign (=) in instruction");
5014 num_outputs = i + 1;
5019 as_bad ("Illegal operand separator `%c'", sep);
5023 if (idesc->operands[2] == IA64_OPND_SOF)
5025 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5026 know (strcmp (idesc->name, "alloc") == 0);
5027 if (num_operands == 5 /* first_arg not included in this count! */
5028 && CURR_SLOT.opnd[2].X_op == O_constant
5029 && CURR_SLOT.opnd[3].X_op == O_constant
5030 && CURR_SLOT.opnd[4].X_op == O_constant
5031 && CURR_SLOT.opnd[5].X_op == O_constant)
5033 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5034 CURR_SLOT.opnd[3].X_add_number,
5035 CURR_SLOT.opnd[4].X_add_number,
5036 CURR_SLOT.opnd[5].X_add_number);
5038 /* now we can parse the first arg: */
5039 saved_input_pointer = input_line_pointer;
5040 input_line_pointer = first_arg;
5041 sep = parse_operand (CURR_SLOT.opnd + 0);
5043 --num_outputs; /* force error */
5044 input_line_pointer = saved_input_pointer;
5046 CURR_SLOT.opnd[2].X_add_number = sof;
5047 CURR_SLOT.opnd[3].X_add_number
5048 = sof - CURR_SLOT.opnd[4].X_add_number;
5049 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5053 highest_unmatched_operand = 0;
5054 expected_operand = idesc->operands[0];
5055 for (; idesc; idesc = get_next_opcode (idesc))
5057 if (num_outputs != idesc->num_outputs)
5058 continue; /* mismatch in # of outputs */
5060 CURR_SLOT.num_fixups = 0;
5061 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5062 if (!operand_match (idesc, i, CURR_SLOT.opnd + i))
5065 if (i != num_operands)
5067 if (i > highest_unmatched_operand)
5069 highest_unmatched_operand = i;
5070 expected_operand = idesc->operands[i];
5075 if (num_operands < NELEMS (idesc->operands)
5076 && idesc->operands[num_operands])
5077 continue; /* mismatch in number of arguments */
5083 if (expected_operand)
5084 as_bad ("Operand %u of `%s' should be %s",
5085 highest_unmatched_operand + 1, mnemonic,
5086 elf64_ia64_operands[expected_operand].desc);
5088 as_bad ("Operand mismatch");
5095 build_insn (slot, insnp)
5099 const struct ia64_operand *odesc, *o2desc;
5100 struct ia64_opcode *idesc = slot->idesc;
5101 bfd_signed_vma insn, val;
5105 insn = idesc->opcode | slot->qp_regno;
5107 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
5109 if (slot->opnd[i].X_op == O_register
5110 || slot->opnd[i].X_op == O_constant
5111 || slot->opnd[i].X_op == O_index)
5112 val = slot->opnd[i].X_add_number;
5113 else if (slot->opnd[i].X_op == O_big)
5115 /* This must be the value 0x10000000000000000. */
5116 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
5122 switch (idesc->operands[i])
5124 case IA64_OPND_IMMU64:
5125 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
5126 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
5127 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
5128 | (((val >> 63) & 0x1) << 36));
5131 case IA64_OPND_IMMU62:
5132 val &= 0x3fffffffffffffffULL;
5133 if (val != slot->opnd[i].X_add_number)
5134 as_warn (_("Value truncated to 62 bits"));
5135 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
5136 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
5139 case IA64_OPND_TGT64:
5141 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
5142 insn |= ((((val >> 59) & 0x1) << 36)
5143 | (((val >> 0) & 0xfffff) << 13));
5174 case IA64_OPND_R3_2:
5175 case IA64_OPND_CPUID_R3:
5176 case IA64_OPND_DBR_R3:
5177 case IA64_OPND_DTR_R3:
5178 case IA64_OPND_ITR_R3:
5179 case IA64_OPND_IBR_R3:
5181 case IA64_OPND_MSR_R3:
5182 case IA64_OPND_PKR_R3:
5183 case IA64_OPND_PMC_R3:
5184 case IA64_OPND_PMD_R3:
5185 case IA64_OPND_RR_R3:
5193 odesc = elf64_ia64_operands + idesc->operands[i];
5194 err = (*odesc->insert) (odesc, val, &insn);
5196 as_bad_where (slot->src_file, slot->src_line,
5197 "Bad operand value: %s", err);
5198 if (idesc->flags & IA64_OPCODE_PSEUDO)
5200 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
5201 && odesc == elf64_ia64_operands + IA64_OPND_F3)
5203 o2desc = elf64_ia64_operands + IA64_OPND_F2;
5204 (*o2desc->insert) (o2desc, val, &insn);
5206 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
5207 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
5208 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
5210 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
5211 (*o2desc->insert) (o2desc, 64 - val, &insn);
5221 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
5222 unsigned int manual_bundling = 0;
5223 enum ia64_unit required_unit, insn_unit = 0;
5224 enum ia64_insn_type type[3], insn_type;
5225 unsigned int template, orig_template;
5226 bfd_vma insn[3] = { -1, -1, -1 };
5227 struct ia64_opcode *idesc;
5228 int end_of_insn_group = 0, user_template = -1;
5229 int n, i, j, first, curr;
5230 unw_rec_list *ptr, *prev;
5231 bfd_vma t0 = 0, t1 = 0;
5232 struct label_fix *lfix;
5233 struct insn_fix *ifix;
5238 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
5239 know (first >= 0 & first < NUM_SLOTS);
5240 n = MIN (3, md.num_slots_in_use);
5242 /* Determine template: user user_template if specified, best match
5245 if (md.slot[first].user_template >= 0)
5246 user_template = template = md.slot[first].user_template;
5249 /* Auto select appropriate template. */
5250 memset (type, 0, sizeof (type));
5252 for (i = 0; i < n; ++i)
5254 if (md.slot[curr].label_fixups && i != 0)
5256 type[i] = md.slot[curr].idesc->type;
5257 curr = (curr + 1) % NUM_SLOTS;
5259 template = best_template[type[0]][type[1]][type[2]];
5262 /* initialize instructions with appropriate nops: */
5263 for (i = 0; i < 3; ++i)
5264 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
5268 /* now fill in slots with as many insns as possible: */
5270 idesc = md.slot[curr].idesc;
5271 end_of_insn_group = 0;
5272 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
5274 /* Set the slot number for prologue/body records now as those
5275 refer to the current point, not the point after the
5276 instruction has been issued: */
5277 /* Don't try to delete prologue/body records here, as that will cause
5278 them to also be deleted from the master list of unwind records. */
5279 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
5280 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
5281 || ptr->r.type == body)
5282 ptr->slot_number = (unsigned long) f + i;
5284 if (idesc->flags & IA64_OPCODE_SLOT2)
5286 if (manual_bundling && i != 2)
5287 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5288 "`%s' must be last in bundle", idesc->name);
5292 if (idesc->flags & IA64_OPCODE_LAST)
5294 int required_slot, required_template;
5296 /* If we need a stop bit after an M slot, our only choice is
5297 template 5 (M;;MI). If we need a stop bit after a B
5298 slot, our only choice is to place it at the end of the
5299 bundle, because the only available templates are MIB,
5300 MBB, BBB, MMB, and MFB. We don't handle anything other
5301 than M and B slots because these are the only kind of
5302 instructions that can have the IA64_OPCODE_LAST bit set. */
5303 required_template = template;
5304 switch (idesc->type)
5308 required_template = 5;
5316 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5317 "Internal error: don't know how to force %s to end"
5318 "of instruction group", idesc->name);
5322 if (manual_bundling && i != required_slot)
5323 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5324 "`%s' must be last in instruction group",
5326 if (required_slot < i)
5327 /* Can't fit this instruction. */
5331 if (required_template != template)
5333 /* If we switch the template, we need to reset the NOPs
5334 after slot i. The slot-types of the instructions ahead
5335 of i never change, so we don't need to worry about
5336 changing NOPs in front of this slot. */
5337 for (j = i; j < 3; ++j)
5338 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
5340 template = required_template;
5342 if (curr != first && md.slot[curr].label_fixups)
5344 if (manual_bundling_on)
5345 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5346 "Label must be first in a bundle");
5347 /* This insn must go into the first slot of a bundle. */
5351 manual_bundling_on = md.slot[curr].manual_bundling_on;
5352 manual_bundling_off = md.slot[curr].manual_bundling_off;
5354 if (manual_bundling_on)
5357 manual_bundling = 1;
5359 break; /* need to start a new bundle */
5362 if (end_of_insn_group && md.num_slots_in_use >= 1)
5364 /* We need an instruction group boundary in the middle of a
5365 bundle. See if we can switch to an other template with
5366 an appropriate boundary. */
5368 orig_template = template;
5369 if (i == 1 && (user_template == 4
5370 || (user_template < 0
5371 && (ia64_templ_desc[template].exec_unit[0]
5375 end_of_insn_group = 0;
5377 else if (i == 2 && (user_template == 0
5378 || (user_template < 0
5379 && (ia64_templ_desc[template].exec_unit[1]
5381 /* This test makes sure we don't switch the template if
5382 the next instruction is one that needs to be first in
5383 an instruction group. Since all those instructions are
5384 in the M group, there is no way such an instruction can
5385 fit in this bundle even if we switch the template. The
5386 reason we have to check for this is that otherwise we
5387 may end up generating "MI;;I M.." which has the deadly
5388 effect that the second M instruction is no longer the
5389 first in the bundle! --davidm 99/12/16 */
5390 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
5393 end_of_insn_group = 0;
5395 else if (curr != first)
5396 /* can't fit this insn */
5399 if (template != orig_template)
5400 /* if we switch the template, we need to reset the NOPs
5401 after slot i. The slot-types of the instructions ahead
5402 of i never change, so we don't need to worry about
5403 changing NOPs in front of this slot. */
5404 for (j = i; j < 3; ++j)
5405 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
5407 required_unit = ia64_templ_desc[template].exec_unit[i];
5409 /* resolve dynamic opcodes such as "break" and "nop": */
5410 if (idesc->type == IA64_TYPE_DYN)
5412 if ((strcmp (idesc->name, "nop") == 0)
5413 || (strcmp (idesc->name, "break") == 0))
5414 insn_unit = required_unit;
5415 else if (strcmp (idesc->name, "chk.s") == 0)
5417 insn_unit = IA64_UNIT_M;
5418 if (required_unit == IA64_UNIT_I)
5419 insn_unit = IA64_UNIT_I;
5422 as_fatal ("emit_one_bundle: unexpected dynamic op");
5424 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
5425 ia64_free_opcode (idesc);
5426 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
5428 know (!idesc->next); /* no resolved dynamic ops have collisions */
5433 insn_type = idesc->type;
5434 insn_unit = IA64_UNIT_NIL;
5438 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
5439 insn_unit = required_unit;
5441 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
5442 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
5443 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
5444 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
5445 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
5450 if (insn_unit != required_unit)
5452 if (required_unit == IA64_UNIT_L
5453 && insn_unit == IA64_UNIT_I
5454 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
5456 /* we got ourselves an MLX template but the current
5457 instruction isn't an X-unit, or an I-unit instruction
5458 that can go into the X slot of an MLX template. Duh. */
5459 if (md.num_slots_in_use >= NUM_SLOTS)
5461 as_bad_where (md.slot[curr].src_file,
5462 md.slot[curr].src_line,
5463 "`%s' can't go in X slot of "
5464 "MLX template", idesc->name);
5465 /* drop this insn so we don't livelock: */
5466 --md.num_slots_in_use;
5470 continue; /* try next slot */
5473 if (debug_type == DEBUG_DWARF2)
5477 addr = frag_now->fr_address + frag_now_fix () - 16 + 1 * i;
5478 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
5481 build_insn (md.slot + curr, insn + i);
5483 /* Set slot counts for non prologue/body unwind records. */
5484 for (ptr = md.slot[curr].unwind_record; ptr; ptr = ptr->next)
5485 if (ptr->r.type != prologue && ptr->r.type != prologue_gr
5486 && ptr->r.type != body)
5487 ptr->slot_number = (unsigned long) f + i;
5488 md.slot[curr].unwind_record = NULL;
5489 unwind.next_slot_number = (unsigned long) f + i + ((i == 2)?(0x10-2):1);
5491 if (required_unit == IA64_UNIT_L)
5494 /* skip one slot for long/X-unit instructions */
5497 --md.num_slots_in_use;
5499 /* now is a good time to fix up the labels for this insn: */
5500 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
5502 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
5503 symbol_set_frag (lfix->sym, frag_now);
5506 for (j = 0; j < md.slot[curr].num_fixups; ++j)
5508 ifix = md.slot[curr].fixup + j;
5509 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 4,
5510 &ifix->expr, ifix->is_pcrel, ifix->code);
5511 fix->tc_fix_data.opnd = ifix->opnd;
5512 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
5513 fix->fx_file = md.slot[curr].src_file;
5514 fix->fx_line = md.slot[curr].src_line;
5517 end_of_insn_group = md.slot[curr].end_of_insn_group;
5520 ia64_free_opcode (md.slot[curr].idesc);
5521 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
5522 md.slot[curr].user_template = -1;
5524 if (manual_bundling_off)
5526 manual_bundling = 0;
5529 curr = (curr + 1) % NUM_SLOTS;
5530 idesc = md.slot[curr].idesc;
5532 if (manual_bundling)
5534 if (md.num_slots_in_use > 0)
5535 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5536 "`%s' does not fit into %s template",
5537 idesc->name, ia64_templ_desc[template].name);
5539 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
5540 "Missing '}' at end of file");
5542 know (md.num_slots_in_use < NUM_SLOTS);
5544 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
5545 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
5547 md_number_to_chars (f + 0, t0, 8);
5548 md_number_to_chars (f + 8, t1, 8);
5552 md_parse_option (c, arg)
5558 /* Switches from the Intel assembler. */
5560 if (strcmp (arg, "ilp64") == 0
5561 || strcmp (arg, "lp64") == 0
5562 || strcmp (arg, "p64") == 0)
5564 md.flags |= EF_IA_64_ABI64;
5566 else if (strcmp (arg, "ilp32") == 0)
5568 md.flags &= ~EF_IA_64_ABI64;
5570 else if (strcmp (arg, "le") == 0)
5572 md.flags &= ~EF_IA_64_BE;
5574 else if (strcmp (arg, "be") == 0)
5576 md.flags |= EF_IA_64_BE;
5583 if (strcmp (arg, "so") == 0)
5585 /* Suppress signon message. */
5587 else if (strcmp (arg, "pi") == 0)
5589 /* Reject privileged instructions. FIXME */
5591 else if (strcmp (arg, "us") == 0)
5593 /* Allow union of signed and unsigned range. FIXME */
5595 else if (strcmp (arg, "close_fcalls") == 0)
5597 /* Do not resolve global function calls. */
5604 /* temp[="prefix"] Insert temporary labels into the object file
5605 symbol table prefixed by "prefix".
5606 Default prefix is ":temp:".
5611 /* ??? Conflicts with gas' listing option. */
5612 /* indirect=<tgt> Assume unannotated indirect branches behavior
5613 according to <tgt> --
5614 exit: branch out from the current context (default)
5615 labels: all labels in context may be branch targets
5620 /* -X conflicts with an ignored option, use -x instead */
5622 if (!arg || strcmp (arg, "explicit") == 0)
5624 /* set default mode to explicit */
5625 md.default_explicit_mode = 1;
5628 else if (strcmp (arg, "auto") == 0)
5630 md.default_explicit_mode = 0;
5632 else if (strcmp (arg, "debug") == 0)
5636 else if (strcmp (arg, "debugx") == 0)
5638 md.default_explicit_mode = 1;
5643 as_bad (_("Unrecognized option '-x%s'"), arg);
5648 /* nops Print nops statistics. */
5651 /* GNU specific switches for gcc. */
5652 case OPTION_MCONSTANT_GP:
5653 md.flags |= EF_IA_64_CONS_GP;
5656 case OPTION_MAUTO_PIC:
5657 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
5668 md_show_usage (stream)
5673 -Milp32|-Milp64|-Mlp64|-Mp64 select data model (default -Mlp64)\n\
5674 -Mle | -Mbe select little- or big-endian byte order (default -Mle)\n\
5675 -x | -xexplicit turn on dependency violation checking (default)\n\
5676 -xauto automagically remove dependency violations\n\
5677 -xdebug debug dependency violation checker\n"),
5681 /* Return true if TYPE fits in TEMPL at SLOT. */
5684 match (int templ, int type, int slot)
5686 enum ia64_unit unit;
5689 unit = ia64_templ_desc[templ].exec_unit[slot];
5692 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
5694 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
5696 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
5697 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
5698 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
5699 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
5700 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
5701 default: result = 0; break;
5706 /* Add a bit of extra goodness if a nop of type F or B would fit
5707 in TEMPL at SLOT. */
5710 extra_goodness (int templ, int slot)
5712 if (match (templ, IA64_TYPE_F, slot))
5714 if (match (templ, IA64_TYPE_B, slot))
5719 /* This function is called once, at assembler startup time. It sets
5720 up all the tables, etc. that the MD part of the assembler will need
5721 that can be determined before arguments are parsed. */
5725 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum;
5730 md.explicit_mode = md.default_explicit_mode;
5732 bfd_set_section_alignment (stdoutput, text_section, 4);
5734 target_big_endian = 0;
5735 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
5736 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
5737 &zero_address_frag);
5739 pseudo_func[FUNC_GP_RELATIVE].u.sym =
5740 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
5741 &zero_address_frag);
5743 pseudo_func[FUNC_LT_RELATIVE].u.sym =
5744 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
5745 &zero_address_frag);
5747 pseudo_func[FUNC_PC_RELATIVE].u.sym =
5748 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
5749 &zero_address_frag);
5751 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
5752 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
5753 &zero_address_frag);
5755 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
5756 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
5757 &zero_address_frag);
5759 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
5760 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
5761 &zero_address_frag);
5763 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
5764 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
5765 &zero_address_frag);
5767 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
5768 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
5769 &zero_address_frag);
5771 /* Compute the table of best templates. We compute goodness as a
5772 base 4 value, in which each match counts for 3, each F counts
5773 for 2, each B counts for 1. This should maximize the number of
5774 F and B nops in the chosen bundles, which is good because these
5775 pipelines are least likely to be overcommitted. */
5776 for (i = 0; i < IA64_NUM_TYPES; ++i)
5777 for (j = 0; j < IA64_NUM_TYPES; ++j)
5778 for (k = 0; k < IA64_NUM_TYPES; ++k)
5781 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
5784 if (match (t, i, 0))
5786 if (match (t, j, 1))
5788 if (match (t, k, 2))
5789 goodness = 3 + 3 + 3;
5791 goodness = 3 + 3 + extra_goodness (t, 2);
5793 else if (match (t, j, 2))
5794 goodness = 3 + 3 + extra_goodness (t, 1);
5798 goodness += extra_goodness (t, 1);
5799 goodness += extra_goodness (t, 2);
5802 else if (match (t, i, 1))
5804 if (match (t, j, 2))
5807 goodness = 3 + extra_goodness (t, 2);
5809 else if (match (t, i, 2))
5810 goodness = 3 + extra_goodness (t, 1);
5812 if (goodness > best)
5815 best_template[i][j][k] = t;
5820 for (i = 0; i < NUM_SLOTS; ++i)
5821 md.slot[i].user_template = -1;
5823 md.pseudo_hash = hash_new ();
5824 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
5826 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
5827 (void *) (pseudo_opcode + i));
5829 as_fatal ("ia64.md_begin: can't hash `%s': %s",
5830 pseudo_opcode[i].name, err);
5833 md.reg_hash = hash_new ();
5834 md.dynreg_hash = hash_new ();
5835 md.const_hash = hash_new ();
5836 md.entry_hash = hash_new ();
5838 /* general registers: */
5841 for (i = 0; i < total; ++i)
5843 sprintf (name, "r%d", i - REG_GR);
5844 md.regsym[i] = declare_register (name, i);
5847 /* floating point registers: */
5849 for (; i < total; ++i)
5851 sprintf (name, "f%d", i - REG_FR);
5852 md.regsym[i] = declare_register (name, i);
5855 /* application registers: */
5858 for (; i < total; ++i)
5860 sprintf (name, "ar%d", i - REG_AR);
5861 md.regsym[i] = declare_register (name, i);
5864 /* control registers: */
5867 for (; i < total; ++i)
5869 sprintf (name, "cr%d", i - REG_CR);
5870 md.regsym[i] = declare_register (name, i);
5873 /* predicate registers: */
5875 for (; i < total; ++i)
5877 sprintf (name, "p%d", i - REG_P);
5878 md.regsym[i] = declare_register (name, i);
5881 /* branch registers: */
5883 for (; i < total; ++i)
5885 sprintf (name, "b%d", i - REG_BR);
5886 md.regsym[i] = declare_register (name, i);
5889 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
5890 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
5891 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
5892 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
5893 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
5894 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
5895 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
5897 for (i = 0; i < NELEMS (indirect_reg); ++i)
5899 regnum = indirect_reg[i].regnum;
5900 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
5903 /* define synonyms for application registers: */
5904 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
5905 md.regsym[i] = declare_register (ar[i - REG_AR].name,
5906 REG_AR + ar[i - REG_AR].regnum);
5908 /* define synonyms for control registers: */
5909 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
5910 md.regsym[i] = declare_register (cr[i - REG_CR].name,
5911 REG_CR + cr[i - REG_CR].regnum);
5913 declare_register ("gp", REG_GR + 1);
5914 declare_register ("sp", REG_GR + 12);
5915 declare_register ("rp", REG_BR + 0);
5917 /* pseudo-registers used to specify unwind info: */
5918 declare_register ("psp", REG_PSP);
5920 declare_register_set ("ret", 4, REG_GR + 8);
5921 declare_register_set ("farg", 8, REG_FR + 8);
5922 declare_register_set ("fret", 8, REG_FR + 8);
5924 for (i = 0; i < NELEMS (const_bits); ++i)
5926 err = hash_insert (md.const_hash, const_bits[i].name,
5927 (PTR) (const_bits + i));
5929 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
5933 /* Default to 64-bit mode. */
5934 /* ??? This overrides the -M options, but they aren't working anyways. */
5935 md.flags |= EF_IA_64_ABI64;
5937 md.mem_offset.hint = 0;
5940 md.entry_labels = NULL;
5944 ia64_end_of_source ()
5946 /* terminate insn group upon reaching end of file: */
5947 insn_group_break (1, 0, 0);
5949 /* emits slots we haven't written yet: */
5950 ia64_flush_insns ();
5952 bfd_set_private_flags (stdoutput, md.flags);
5954 if (debug_type == DEBUG_DWARF2)
5957 md.mem_offset.hint = 0;
5963 md.qp.X_op = O_absent;
5965 if (ignore_input ())
5968 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
5970 if (md.detect_dv && !md.explicit_mode)
5971 as_warn (_("Explicit stops are ignored in auto mode"));
5973 insn_group_break (1, 0, 0);
5978 ia64_unrecognized_line (ch)
5984 expression (&md.qp);
5985 if (*input_line_pointer++ != ')')
5987 as_bad ("Expected ')'");
5990 if (md.qp.X_op != O_register)
5992 as_bad ("Qualifying predicate expected");
5995 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
5997 as_bad ("Predicate register expected");
6003 if (md.manual_bundling)
6004 as_warn ("Found '{' when manual bundling is already turned on");
6006 CURR_SLOT.manual_bundling_on = 1;
6007 md.manual_bundling = 1;
6009 /* Bundling is only acceptable in explicit mode
6010 or when in default automatic mode. */
6011 if (md.detect_dv && !md.explicit_mode)
6013 if (!md.mode_explicitly_set
6014 && !md.default_explicit_mode)
6017 as_warn (_("Found '{' after explicit switch to automatic mode"));
6022 if (!md.manual_bundling)
6023 as_warn ("Found '}' when manual bundling is off");
6025 PREV_SLOT.manual_bundling_off = 1;
6026 md.manual_bundling = 0;
6028 /* switch back to automatic mode, if applicable */
6031 && !md.mode_explicitly_set
6032 && !md.default_explicit_mode)
6035 /* Allow '{' to follow on the same line. We also allow ";;", but that
6036 happens automatically because ';' is an end of line marker. */
6038 if (input_line_pointer[0] == '{')
6040 input_line_pointer++;
6041 return ia64_unrecognized_line ('{');
6044 demand_empty_rest_of_line ();
6051 /* Not a valid line. */
6056 ia64_frob_label (sym)
6059 struct label_fix *fix;
6061 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
6063 md.last_text_seg = now_seg;
6064 fix = obstack_alloc (¬es, sizeof (*fix));
6066 fix->next = CURR_SLOT.label_fixups;
6067 CURR_SLOT.label_fixups = fix;
6069 /* Keep track of how many code entry points we've seen. */
6070 if (md.path == md.maxpaths)
6073 md.entry_labels = (const char **)
6074 xrealloc ((void *) md.entry_labels,
6075 md.maxpaths * sizeof (char *));
6077 md.entry_labels[md.path++] = S_GET_NAME (sym);
6082 ia64_flush_pending_output ()
6084 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
6086 /* ??? This causes many unnecessary stop bits to be emitted.
6087 Unfortunately, it isn't clear if it is safe to remove this. */
6088 insn_group_break (1, 0, 0);
6089 ia64_flush_insns ();
6093 /* Do ia64-specific expression optimization. All that's done here is
6094 to transform index expressions that are either due to the indexing
6095 of rotating registers or due to the indexing of indirect register
6098 ia64_optimize_expr (l, op, r)
6107 if (l->X_op == O_register && r->X_op == O_constant)
6109 num_regs = (l->X_add_number >> 16);
6110 if ((unsigned) r->X_add_number >= num_regs)
6113 as_bad ("No current frame");
6115 as_bad ("Index out of range 0..%u", num_regs - 1);
6116 r->X_add_number = 0;
6118 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
6121 else if (l->X_op == O_register && r->X_op == O_register)
6123 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
6124 || l->X_add_number == IND_MEM)
6126 as_bad ("Indirect register set name expected");
6127 l->X_add_number = IND_CPUID;
6130 l->X_op_symbol = md.regsym[l->X_add_number];
6131 l->X_add_number = r->X_add_number;
6139 ia64_parse_name (name, e)
6143 struct const_desc *cdesc;
6144 struct dynreg *dr = 0;
6145 unsigned int regnum;
6149 /* first see if NAME is a known register name: */
6150 sym = hash_find (md.reg_hash, name);
6153 e->X_op = O_register;
6154 e->X_add_number = S_GET_VALUE (sym);
6158 cdesc = hash_find (md.const_hash, name);
6161 e->X_op = O_constant;
6162 e->X_add_number = cdesc->value;
6166 /* check for inN, locN, or outN: */
6170 if (name[1] == 'n' && isdigit (name[2]))
6178 if (name[1] == 'o' && name[2] == 'c' && isdigit (name[3]))
6186 if (name[1] == 'u' && name[2] == 't' && isdigit (name[3]))
6199 /* The name is inN, locN, or outN; parse the register number. */
6200 regnum = strtoul (name, &end, 10);
6201 if (end > name && *end == '\0')
6203 if ((unsigned) regnum >= dr->num_regs)
6206 as_bad ("No current frame");
6208 as_bad ("Register number out of range 0..%u",
6212 e->X_op = O_register;
6213 e->X_add_number = dr->base + regnum;
6218 if ((dr = hash_find (md.dynreg_hash, name)))
6220 /* We've got ourselves the name of a rotating register set.
6221 Store the base register number in the low 16 bits of
6222 X_add_number and the size of the register set in the top 16
6224 e->X_op = O_register;
6225 e->X_add_number = dr->base | (dr->num_regs << 16);
6231 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
6234 ia64_canonicalize_symbol_name (name)
6237 size_t len = strlen (name);
6238 if (len > 1 && name[len - 1] == '#')
6239 name[len - 1] = '\0';
6244 is_conditional_branch (idesc)
6245 struct ia64_opcode *idesc;
6247 return (strncmp (idesc->name, "br", 2) == 0
6248 && (strcmp (idesc->name, "br") == 0
6249 || strncmp (idesc->name, "br.cond", 7) == 0
6250 || strncmp (idesc->name, "br.call", 7) == 0
6251 || strncmp (idesc->name, "br.ret", 6) == 0
6252 || strcmp (idesc->name, "brl") == 0
6253 || strncmp (idesc->name, "brl.cond", 7) == 0
6254 || strncmp (idesc->name, "brl.call", 7) == 0
6255 || strncmp (idesc->name, "brl.ret", 6) == 0));
6258 /* Return whether the given opcode is a taken branch. If there's any doubt,
6262 is_taken_branch (idesc)
6263 struct ia64_opcode *idesc;
6265 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
6266 || strncmp (idesc->name, "br.ia", 5) == 0);
6269 /* Return whether the given opcode is an interruption or rfi. If there's any
6270 doubt, returns zero. */
6273 is_interruption_or_rfi (idesc)
6274 struct ia64_opcode *idesc;
6276 if (strcmp (idesc->name, "rfi") == 0)
6281 /* Returns the index of the given dependency in the opcode's list of chks, or
6282 -1 if there is no dependency. */
6285 depends_on (depind, idesc)
6287 struct ia64_opcode *idesc;
6290 const struct ia64_opcode_dependency *dep = idesc->dependencies;
6291 for (i = 0; i < dep->nchks; i++)
6293 if (depind == DEP (dep->chks[i]))
6299 /* Determine a set of specific resources used for a particular resource
6300 class. Returns the number of specific resources identified For those
6301 cases which are not determinable statically, the resource returned is
6304 Meanings of value in 'NOTE':
6305 1) only read/write when the register number is explicitly encoded in the
6307 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
6308 accesses CFM when qualifying predicate is in the rotating region.
6309 3) general register value is used to specify an indirect register; not
6310 determinable statically.
6311 4) only read the given resource when bits 7:0 of the indirect index
6312 register value does not match the register number of the resource; not
6313 determinable statically.
6314 5) all rules are implementation specific.
6315 6) only when both the index specified by the reader and the index specified
6316 by the writer have the same value in bits 63:61; not determinable
6318 7) only access the specified resource when the corresponding mask bit is
6320 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
6321 only read when these insns reference FR2-31
6322 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
6323 written when these insns write FR32-127
6324 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
6326 11) The target predicates are written independently of PR[qp], but source
6327 registers are only read if PR[qp] is true. Since the state of PR[qp]
6328 cannot statically be determined, all source registers are marked used.
6329 12) This insn only reads the specified predicate register when that
6330 register is the PR[qp].
6331 13) This reference to ld-c only applies to teh GR whose value is loaded
6332 with data returned from memory, not the post-incremented address register.
6333 14) The RSE resource includes the implementation-specific RSE internal
6334 state resources. At least one (and possibly more) of these resources are
6335 read by each instruction listed in IC:rse-readers. At least one (and
6336 possibly more) of these resources are written by each insn listed in
6338 15+16) Represents reserved instructions, which the assembler does not
6341 Memory resources (i.e. locations in memory) are *not* marked or tracked by
6342 this code; there are no dependency violations based on memory access.
6345 #define MAX_SPECS 256
6350 specify_resource (dep, idesc, type, specs, note, path)
6351 const struct ia64_dependency *dep;
6352 struct ia64_opcode *idesc;
6353 int type; /* is this a DV chk or a DV reg? */
6354 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
6355 int note; /* resource note for this insn's usage */
6356 int path; /* which execution path to examine */
6363 if (dep->mode == IA64_DV_WAW
6364 || (dep->mode == IA64_DV_RAW && type == DV_REG)
6365 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
6368 /* template for any resources we identify */
6369 tmpl.dependency = dep;
6371 tmpl.insn_srlz = tmpl.data_srlz = 0;
6372 tmpl.qp_regno = CURR_SLOT.qp_regno;
6373 tmpl.link_to_qp_branch = 1;
6374 tmpl.mem_offset.hint = 0;
6379 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
6380 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
6381 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
6383 /* we don't need to track these */
6384 if (dep->semantics == IA64_DVS_NONE)
6387 switch (dep->specifier)
6392 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
6394 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
6395 if (regno >= 0 && regno <= 7)
6397 specs[count] = tmpl;
6398 specs[count++].index = regno;
6404 for (i = 0; i < 8; i++)
6406 specs[count] = tmpl;
6407 specs[count++].index = i;
6416 case IA64_RS_AR_UNAT:
6417 /* This is a mov =AR or mov AR= instruction. */
6418 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
6420 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
6421 if (regno == AR_UNAT)
6423 specs[count++] = tmpl;
6428 /* This is a spill/fill, or other instruction that modifies the
6431 /* Unless we can determine the specific bits used, mark the whole
6432 thing; bits 8:3 of the memory address indicate the bit used in
6433 UNAT. The .mem.offset hint may be used to eliminate a small
6434 subset of conflicts. */
6435 specs[count] = tmpl;
6436 if (md.mem_offset.hint)
6439 fprintf (stderr, " Using hint for spill/fill\n");
6440 /* The index isn't actually used, just set it to something
6441 approximating the bit index. */
6442 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
6443 specs[count].mem_offset.hint = 1;
6444 specs[count].mem_offset.offset = md.mem_offset.offset;
6445 specs[count++].mem_offset.base = md.mem_offset.base;
6449 specs[count++].specific = 0;
6457 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
6459 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
6460 if ((regno >= 8 && regno <= 15)
6461 || (regno >= 20 && regno <= 23)
6462 || (regno >= 31 && regno <= 39)
6463 || (regno >= 41 && regno <= 47)
6464 || (regno >= 67 && regno <= 111))
6466 specs[count] = tmpl;
6467 specs[count++].index = regno;
6480 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
6482 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
6483 if ((regno >= 48 && regno <= 63)
6484 || (regno >= 112 && regno <= 127))
6486 specs[count] = tmpl;
6487 specs[count++].index = regno;
6493 for (i = 48; i < 64; i++)
6495 specs[count] = tmpl;
6496 specs[count++].index = i;
6498 for (i = 112; i < 128; i++)
6500 specs[count] = tmpl;
6501 specs[count++].index = i;
6519 for (i = 0; i < idesc->num_outputs; i++)
6520 if (idesc->operands[i] == IA64_OPND_B1
6521 || idesc->operands[i] == IA64_OPND_B2)
6523 specs[count] = tmpl;
6524 specs[count++].index =
6525 CURR_SLOT.opnd[i].X_add_number - REG_BR;
6530 for (i = idesc->num_outputs;i < NELEMS (idesc->operands); i++)
6531 if (idesc->operands[i] == IA64_OPND_B1
6532 || idesc->operands[i] == IA64_OPND_B2)
6534 specs[count] = tmpl;
6535 specs[count++].index =
6536 CURR_SLOT.opnd[i].X_add_number - REG_BR;
6542 case IA64_RS_CPUID: /* four or more registers */
6545 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
6547 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
6548 if (regno >= 0 && regno < NELEMS (gr_values)
6551 specs[count] = tmpl;
6552 specs[count++].index = gr_values[regno].value & 0xFF;
6556 specs[count] = tmpl;
6557 specs[count++].specific = 0;
6567 case IA64_RS_DBR: /* four or more registers */
6570 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
6572 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
6573 if (regno >= 0 && regno < NELEMS (gr_values)
6576 specs[count] = tmpl;
6577 specs[count++].index = gr_values[regno].value & 0xFF;
6581 specs[count] = tmpl;
6582 specs[count++].specific = 0;
6586 else if (note == 0 && !rsrc_write)
6588 specs[count] = tmpl;
6589 specs[count++].specific = 0;
6597 case IA64_RS_IBR: /* four or more registers */
6600 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
6602 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
6603 if (regno >= 0 && regno < NELEMS (gr_values)
6606 specs[count] = tmpl;
6607 specs[count++].index = gr_values[regno].value & 0xFF;
6611 specs[count] = tmpl;
6612 specs[count++].specific = 0;
6625 /* These are implementation specific. Force all references to
6626 conflict with all other references. */
6627 specs[count] = tmpl;
6628 specs[count++].specific = 0;
6636 case IA64_RS_PKR: /* 16 or more registers */
6637 if (note == 3 || note == 4)
6639 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
6641 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
6642 if (regno >= 0 && regno < NELEMS (gr_values)
6647 specs[count] = tmpl;
6648 specs[count++].index = gr_values[regno].value & 0xFF;
6651 for (i = 0; i < NELEMS (gr_values); i++)
6653 /* Uses all registers *except* the one in R3. */
6654 if (i != (gr_values[regno].value & 0xFF))
6656 specs[count] = tmpl;
6657 specs[count++].index = i;
6663 specs[count] = tmpl;
6664 specs[count++].specific = 0;
6671 specs[count] = tmpl;
6672 specs[count++].specific = 0;
6676 case IA64_RS_PMC: /* four or more registers */
6679 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
6680 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
6683 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
6685 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
6686 if (regno >= 0 && regno < NELEMS (gr_values)
6689 specs[count] = tmpl;
6690 specs[count++].index = gr_values[regno].value & 0xFF;
6694 specs[count] = tmpl;
6695 specs[count++].specific = 0;
6705 case IA64_RS_PMD: /* four or more registers */
6708 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
6710 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
6711 if (regno >= 0 && regno < NELEMS (gr_values)
6714 specs[count] = tmpl;
6715 specs[count++].index = gr_values[regno].value & 0xFF;
6719 specs[count] = tmpl;
6720 specs[count++].specific = 0;
6730 case IA64_RS_RR: /* eight registers */
6733 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
6735 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
6736 if (regno >= 0 && regno < NELEMS (gr_values)
6739 specs[count] = tmpl;
6740 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
6744 specs[count] = tmpl;
6745 specs[count++].specific = 0;
6749 else if (note == 0 && !rsrc_write)
6751 specs[count] = tmpl;
6752 specs[count++].specific = 0;
6760 case IA64_RS_CR_IRR:
6763 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
6764 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
6766 && idesc->operands[1] == IA64_OPND_CR3
6769 for (i = 0; i < 4; i++)
6771 specs[count] = tmpl;
6772 specs[count++].index = CR_IRR0 + i;
6778 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
6779 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
6781 && regno <= CR_IRR3)
6783 specs[count] = tmpl;
6784 specs[count++].index = regno;
6793 case IA64_RS_CR_LRR:
6800 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
6801 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
6802 && (regno == CR_LRR0 || regno == CR_LRR1))
6804 specs[count] = tmpl;
6805 specs[count++].index = regno;
6813 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
6815 specs[count] = tmpl;
6816 specs[count++].index =
6817 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
6832 else if (rsrc_write)
6834 if (dep->specifier == IA64_RS_FRb
6835 && idesc->operands[0] == IA64_OPND_F1)
6837 specs[count] = tmpl;
6838 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
6843 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
6845 if (idesc->operands[i] == IA64_OPND_F2
6846 || idesc->operands[i] == IA64_OPND_F3
6847 || idesc->operands[i] == IA64_OPND_F4)
6849 specs[count] = tmpl;
6850 specs[count++].index =
6851 CURR_SLOT.opnd[i].X_add_number - REG_FR;
6860 /* This reference applies only to the GR whose value is loaded with
6861 data returned from memory. */
6862 specs[count] = tmpl;
6863 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
6869 for (i = 0; i < idesc->num_outputs; i++)
6870 if (idesc->operands[i] == IA64_OPND_R1
6871 || idesc->operands[i] == IA64_OPND_R2
6872 || idesc->operands[i] == IA64_OPND_R3)
6874 specs[count] = tmpl;
6875 specs[count++].index =
6876 CURR_SLOT.opnd[i].X_add_number - REG_GR;
6878 if (idesc->flags & IA64_OPCODE_POSTINC)
6879 for (i = 0; i < NELEMS (idesc->operands); i++)
6880 if (idesc->operands[i] == IA64_OPND_MR3)
6882 specs[count] = tmpl;
6883 specs[count++].index =
6884 CURR_SLOT.opnd[i].X_add_number - REG_GR;
6889 /* Look for anything that reads a GR. */
6890 for (i = 0; i < NELEMS (idesc->operands); i++)
6892 if (idesc->operands[i] == IA64_OPND_MR3
6893 || idesc->operands[i] == IA64_OPND_CPUID_R3
6894 || idesc->operands[i] == IA64_OPND_DBR_R3
6895 || idesc->operands[i] == IA64_OPND_IBR_R3
6896 || idesc->operands[i] == IA64_OPND_MSR_R3
6897 || idesc->operands[i] == IA64_OPND_PKR_R3
6898 || idesc->operands[i] == IA64_OPND_PMC_R3
6899 || idesc->operands[i] == IA64_OPND_PMD_R3
6900 || idesc->operands[i] == IA64_OPND_RR_R3
6901 || ((i >= idesc->num_outputs)
6902 && (idesc->operands[i] == IA64_OPND_R1
6903 || idesc->operands[i] == IA64_OPND_R2
6904 || idesc->operands[i] == IA64_OPND_R3
6905 /* addl source register. */
6906 || idesc->operands[i] == IA64_OPND_R3_2)))
6908 specs[count] = tmpl;
6909 specs[count++].index =
6910 CURR_SLOT.opnd[i].X_add_number - REG_GR;
6924 if (idesc->operands[0] == IA64_OPND_PR_ROT)
6926 for (i = 16; i < 63; i++)
6928 specs[count] = tmpl;
6929 specs[count++].index = i;
6934 for (i = 1; i < 63; i++)
6936 specs[count] = tmpl;
6937 specs[count++].index = i;
6944 /* Mark only those registers indicated by the mask. */
6946 && idesc->operands[0] == IA64_OPND_PR)
6948 mask = CURR_SLOT.opnd[2].X_add_number;
6949 if (mask & ((valueT) 1 << 16))
6950 mask |= ~(valueT) 0xffff;
6951 for (i = 1; i < 63; i++)
6953 if (mask & ((valueT) 1 << i))
6955 specs[count] = tmpl;
6956 specs[count++].index = i;
6961 && idesc->operands[0] == IA64_OPND_PR_ROT)
6963 for (i = 16; i < 63; i++)
6965 specs[count] = tmpl;
6966 specs[count++].index = i;
6974 else if (note == 11) /* note 11 implies note 1 as well */
6978 for (i = 0; i < idesc->num_outputs; i++)
6980 if (idesc->operands[i] == IA64_OPND_P1
6981 || idesc->operands[i] == IA64_OPND_P2)
6983 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
6986 specs[count] = tmpl;
6987 specs[count++].index = regno;
6997 else if (note == 12)
6999 if (CURR_SLOT.qp_regno != 0)
7001 specs[count] = tmpl;
7002 specs[count++].index = CURR_SLOT.qp_regno;
7009 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7010 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7011 if ((idesc->operands[0] == IA64_OPND_P1
7012 || idesc->operands[0] == IA64_OPND_P2)
7013 && p1 != 0 && p1 != 63)
7015 specs[count] = tmpl;
7016 specs[count++].index = p1;
7018 if ((idesc->operands[1] == IA64_OPND_P1
7019 || idesc->operands[1] == IA64_OPND_P2)
7020 && p2 != 0 && p2 != 63)
7022 specs[count] = tmpl;
7023 specs[count++].index = p2;
7028 if (CURR_SLOT.qp_regno != 0)
7030 specs[count] = tmpl;
7031 specs[count++].index = CURR_SLOT.qp_regno;
7033 if (idesc->operands[1] == IA64_OPND_PR)
7035 for (i = 1; i < 63; i++)
7037 specs[count] = tmpl;
7038 specs[count++].index = i;
7050 /* Verify that the instruction is using the PSR bit indicated in
7054 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
7056 if (dep->regindex < 6)
7058 specs[count++] = tmpl;
7061 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
7063 if (dep->regindex < 32
7064 || dep->regindex == 35
7065 || dep->regindex == 36
7066 || (!rsrc_write && dep->regindex == PSR_CPL))
7068 specs[count++] = tmpl;
7071 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
7073 if (dep->regindex < 32
7074 || dep->regindex == 35
7075 || dep->regindex == 36
7076 || (rsrc_write && dep->regindex == PSR_CPL))
7078 specs[count++] = tmpl;
7083 /* Several PSR bits have very specific dependencies. */
7084 switch (dep->regindex)
7087 specs[count++] = tmpl;
7092 specs[count++] = tmpl;
7096 /* Only certain CR accesses use PSR.ic */
7097 if (idesc->operands[0] == IA64_OPND_CR3
7098 || idesc->operands[1] == IA64_OPND_CR3)
7101 ((idesc->operands[0] == IA64_OPND_CR3)
7104 CURR_SLOT.opnd[index].X_add_number - REG_CR;
7119 specs[count++] = tmpl;
7128 specs[count++] = tmpl;
7132 /* Only some AR accesses use cpl */
7133 if (idesc->operands[0] == IA64_OPND_AR3
7134 || idesc->operands[1] == IA64_OPND_AR3)
7137 ((idesc->operands[0] == IA64_OPND_AR3)
7140 CURR_SLOT.opnd[index].X_add_number - REG_AR;
7147 && regno <= AR_K7))))
7149 specs[count++] = tmpl;
7154 specs[count++] = tmpl;
7164 if (idesc->operands[0] == IA64_OPND_IMMU24)
7166 mask = CURR_SLOT.opnd[0].X_add_number;
7172 if (mask & ((valueT) 1 << dep->regindex))
7174 specs[count++] = tmpl;
7179 int min = dep->regindex == PSR_DFL ? 2 : 32;
7180 int max = dep->regindex == PSR_DFL ? 31 : 127;
7181 /* dfh is read on FR32-127; dfl is read on FR2-31 */
7182 for (i = 0; i < NELEMS (idesc->operands); i++)
7184 if (idesc->operands[i] == IA64_OPND_F1
7185 || idesc->operands[i] == IA64_OPND_F2
7186 || idesc->operands[i] == IA64_OPND_F3
7187 || idesc->operands[i] == IA64_OPND_F4)
7189 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
7190 if (reg >= min && reg <= max)
7192 specs[count++] = tmpl;
7199 int min = dep->regindex == PSR_MFL ? 2 : 32;
7200 int max = dep->regindex == PSR_MFL ? 31 : 127;
7201 /* mfh is read on writes to FR32-127; mfl is read on writes to
7203 for (i = 0; i < idesc->num_outputs; i++)
7205 if (idesc->operands[i] == IA64_OPND_F1)
7207 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
7208 if (reg >= min && reg <= max)
7210 specs[count++] = tmpl;
7215 else if (note == 10)
7217 for (i = 0; i < NELEMS (idesc->operands); i++)
7219 if (idesc->operands[i] == IA64_OPND_R1
7220 || idesc->operands[i] == IA64_OPND_R2
7221 || idesc->operands[i] == IA64_OPND_R3)
7223 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
7224 if (regno >= 16 && regno <= 31)
7226 specs[count++] = tmpl;
7237 case IA64_RS_AR_FPSR:
7238 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7240 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7241 if (regno == AR_FPSR)
7243 specs[count++] = tmpl;
7248 specs[count++] = tmpl;
7253 /* Handle all AR[REG] resources */
7254 if (note == 0 || note == 1)
7256 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7257 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
7258 && regno == dep->regindex)
7260 specs[count++] = tmpl;
7262 /* other AR[REG] resources may be affected by AR accesses */
7263 else if (idesc->operands[0] == IA64_OPND_AR3)
7266 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
7267 switch (dep->regindex)
7273 if (regno == AR_BSPSTORE)
7275 specs[count++] = tmpl;
7279 (regno == AR_BSPSTORE
7280 || regno == AR_RNAT))
7282 specs[count++] = tmpl;
7287 else if (idesc->operands[1] == IA64_OPND_AR3)
7290 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
7291 switch (dep->regindex)
7296 if (regno == AR_BSPSTORE || regno == AR_RNAT)
7298 specs[count++] = tmpl;
7305 specs[count++] = tmpl;
7315 /* Handle all CR[REG] resources */
7316 if (note == 0 || note == 1)
7318 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7320 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7321 if (regno == dep->regindex)
7323 specs[count++] = tmpl;
7325 else if (!rsrc_write)
7327 /* Reads from CR[IVR] affect other resources. */
7328 if (regno == CR_IVR)
7330 if ((dep->regindex >= CR_IRR0
7331 && dep->regindex <= CR_IRR3)
7332 || dep->regindex == CR_TPR)
7334 specs[count++] = tmpl;
7341 specs[count++] = tmpl;
7350 case IA64_RS_INSERVICE:
7351 /* look for write of EOI (67) or read of IVR (65) */
7352 if ((idesc->operands[0] == IA64_OPND_CR3
7353 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
7354 || (idesc->operands[1] == IA64_OPND_CR3
7355 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
7357 specs[count++] = tmpl;
7364 specs[count++] = tmpl;
7375 specs[count++] = tmpl;
7379 /* Check if any of the registers accessed are in the rotating region.
7380 mov to/from pr accesses CFM only when qp_regno is in the rotating
7382 for (i = 0; i < NELEMS (idesc->operands); i++)
7384 if (idesc->operands[i] == IA64_OPND_R1
7385 || idesc->operands[i] == IA64_OPND_R2
7386 || idesc->operands[i] == IA64_OPND_R3)
7388 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
7389 /* Assumes that md.rot.num_regs is always valid */
7390 if (md.rot.num_regs > 0
7392 && num < 31 + md.rot.num_regs)
7394 specs[count] = tmpl;
7395 specs[count++].specific = 0;
7398 else if (idesc->operands[i] == IA64_OPND_F1
7399 || idesc->operands[i] == IA64_OPND_F2
7400 || idesc->operands[i] == IA64_OPND_F3
7401 || idesc->operands[i] == IA64_OPND_F4)
7403 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
7406 specs[count] = tmpl;
7407 specs[count++].specific = 0;
7410 else if (idesc->operands[i] == IA64_OPND_P1
7411 || idesc->operands[i] == IA64_OPND_P2)
7413 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
7416 specs[count] = tmpl;
7417 specs[count++].specific = 0;
7421 if (CURR_SLOT.qp_regno > 15)
7423 specs[count] = tmpl;
7424 specs[count++].specific = 0;
7432 specs[count++] = tmpl;
7434 else if (note == 11)
7436 if ((idesc->operands[0] == IA64_OPND_P1
7437 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
7438 || (idesc->operands[1] == IA64_OPND_P2
7439 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
7441 specs[count++] = tmpl;
7444 else if (note == 12)
7446 if (CURR_SLOT.qp_regno == 63)
7448 specs[count++] = tmpl;
7454 if (idesc->operands[2] == IA64_OPND_IMM17)
7455 mask = CURR_SLOT.opnd[2].X_add_number;
7456 if (mask & ((valueT) 1 << 63))
7458 specs[count++] = tmpl;
7465 for (i = 0; i < idesc->num_outputs; i++)
7466 if ((idesc->operands[i] == IA64_OPND_P1
7467 || idesc->operands[i] == IA64_OPND_P2)
7468 && CURR_SLOT.opnd[i].X_add_number - REG_P == 63)
7470 specs[count++] = tmpl;
7475 if (CURR_SLOT.qp_regno == 63)
7477 specs[count++] = tmpl;
7488 /* FIXME we can identify some individual RSE written resources, but RSE
7489 read resources have not yet been completely identified, so for now
7490 treat RSE as a single resource */
7491 if (strncmp (idesc->name, "mov", 3) == 0)
7495 if (idesc->operands[0] == IA64_OPND_AR3
7496 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
7498 specs[count] = tmpl;
7499 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
7504 if (idesc->operands[0] == IA64_OPND_AR3)
7506 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
7507 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
7509 specs[count++] = tmpl;
7512 else if (idesc->operands[1] == IA64_OPND_AR3)
7514 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
7515 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
7516 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
7518 specs[count++] = tmpl;
7525 specs[count++] = tmpl;
7530 /* FIXME -- do any of these need to be non-specific? */
7531 specs[count++] = tmpl;
7535 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
7542 /* Clear branch flags on marked resources. This breaks the link between the
7543 QP of the marking instruction and a subsequent branch on the same QP. */
7546 clear_qp_branch_flag (mask)
7550 for (i = 0; i < regdepslen; i++)
7552 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
7553 if ((bit & mask) != 0)
7555 regdeps[i].link_to_qp_branch = 0;
7560 /* Remove any mutexes which contain any of the PRs indicated in the mask.
7562 Any changes to a PR clears the mutex relations which include that PR. */
7565 clear_qp_mutex (mask)
7571 while (i < qp_mutexeslen)
7573 if ((qp_mutexes[i].prmask & mask) != 0)
7577 fprintf (stderr, " Clearing mutex relation");
7578 print_prmask (qp_mutexes[i].prmask);
7579 fprintf (stderr, "\n");
7581 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
7588 /* Clear implies relations which contain PRs in the given masks.
7589 P1_MASK indicates the source of the implies relation, while P2_MASK
7590 indicates the implied PR. */
7593 clear_qp_implies (p1_mask, p2_mask)
7600 while (i < qp_implieslen)
7602 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
7603 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
7606 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
7607 qp_implies[i].p1, qp_implies[i].p2);
7608 qp_implies[i] = qp_implies[--qp_implieslen];
7615 /* Add the PRs specified to the list of implied relations. */
7618 add_qp_imply (p1, p2)
7625 /* p0 is not meaningful here. */
7626 if (p1 == 0 || p2 == 0)
7632 /* If it exists already, ignore it. */
7633 for (i = 0; i < qp_implieslen; i++)
7635 if (qp_implies[i].p1 == p1
7636 && qp_implies[i].p2 == p2
7637 && qp_implies[i].path == md.path
7638 && !qp_implies[i].p2_branched)
7642 if (qp_implieslen == qp_impliestotlen)
7644 qp_impliestotlen += 20;
7645 qp_implies = (struct qp_imply *)
7646 xrealloc ((void *) qp_implies,
7647 qp_impliestotlen * sizeof (struct qp_imply));
7650 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
7651 qp_implies[qp_implieslen].p1 = p1;
7652 qp_implies[qp_implieslen].p2 = p2;
7653 qp_implies[qp_implieslen].path = md.path;
7654 qp_implies[qp_implieslen++].p2_branched = 0;
7656 /* Add in the implied transitive relations; for everything that p2 implies,
7657 make p1 imply that, too; for everything that implies p1, make it imply p2
7659 for (i = 0; i < qp_implieslen; i++)
7661 if (qp_implies[i].p1 == p2)
7662 add_qp_imply (p1, qp_implies[i].p2);
7663 if (qp_implies[i].p2 == p1)
7664 add_qp_imply (qp_implies[i].p1, p2);
7666 /* Add in mutex relations implied by this implies relation; for each mutex
7667 relation containing p2, duplicate it and replace p2 with p1. */
7668 bit = (valueT) 1 << p1;
7669 mask = (valueT) 1 << p2;
7670 for (i = 0; i < qp_mutexeslen; i++)
7672 if (qp_mutexes[i].prmask & mask)
7673 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
7677 /* Add the PRs specified in the mask to the mutex list; this means that only
7678 one of the PRs can be true at any time. PR0 should never be included in
7688 if (qp_mutexeslen == qp_mutexestotlen)
7690 qp_mutexestotlen += 20;
7691 qp_mutexes = (struct qpmutex *)
7692 xrealloc ((void *) qp_mutexes,
7693 qp_mutexestotlen * sizeof (struct qpmutex));
7697 fprintf (stderr, " Registering mutex on");
7698 print_prmask (mask);
7699 fprintf (stderr, "\n");
7701 qp_mutexes[qp_mutexeslen].path = md.path;
7702 qp_mutexes[qp_mutexeslen++].prmask = mask;
7706 clear_register_values ()
7710 fprintf (stderr, " Clearing register values\n");
7711 for (i = 1; i < NELEMS (gr_values); i++)
7712 gr_values[i].known = 0;
7715 /* Keep track of register values/changes which affect DV tracking.
7717 optimization note: should add a flag to classes of insns where otherwise we
7718 have to examine a group of strings to identify them. */
7721 note_register_values (idesc)
7722 struct ia64_opcode *idesc;
7724 valueT qp_changemask = 0;
7727 /* Invalidate values for registers being written to. */
7728 for (i = 0; i < idesc->num_outputs; i++)
7730 if (idesc->operands[i] == IA64_OPND_R1
7731 || idesc->operands[i] == IA64_OPND_R2
7732 || idesc->operands[i] == IA64_OPND_R3)
7734 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
7735 if (regno > 0 && regno < NELEMS (gr_values))
7736 gr_values[regno].known = 0;
7738 else if (idesc->operands[i] == IA64_OPND_R3_2)
7740 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
7741 if (regno > 0 && regno < 4)
7742 gr_values[regno].known = 0;
7744 else if (idesc->operands[i] == IA64_OPND_P1
7745 || idesc->operands[i] == IA64_OPND_P2)
7747 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
7748 qp_changemask |= (valueT) 1 << regno;
7750 else if (idesc->operands[i] == IA64_OPND_PR)
7752 if (idesc->operands[2] & (valueT) 0x10000)
7753 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
7755 qp_changemask = idesc->operands[2];
7758 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
7760 if (idesc->operands[1] & ((valueT) 1 << 43))
7761 qp_changemask = ~(valueT) 0xFFFFFFFFFFF | idesc->operands[1];
7763 qp_changemask = idesc->operands[1];
7764 qp_changemask &= ~(valueT) 0xFFFF;
7769 /* Always clear qp branch flags on any PR change. */
7770 /* FIXME there may be exceptions for certain compares. */
7771 clear_qp_branch_flag (qp_changemask);
7773 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
7774 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
7776 qp_changemask |= ~(valueT) 0xFFFF;
7777 if (strcmp (idesc->name, "clrrrb.pr") != 0)
7779 for (i = 32; i < 32 + md.rot.num_regs; i++)
7780 gr_values[i].known = 0;
7782 clear_qp_mutex (qp_changemask);
7783 clear_qp_implies (qp_changemask, qp_changemask);
7785 /* After a call, all register values are undefined, except those marked
7787 else if (strncmp (idesc->name, "br.call", 6) == 0
7788 || strncmp (idesc->name, "brl.call", 7) == 0)
7790 // FIXME keep GR values which are marked as "safe_across_calls"
7791 clear_register_values ();
7792 clear_qp_mutex (~qp_safe_across_calls);
7793 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
7794 clear_qp_branch_flag (~qp_safe_across_calls);
7796 else if (is_interruption_or_rfi (idesc)
7797 || is_taken_branch (idesc))
7799 clear_register_values ();
7800 clear_qp_mutex (~(valueT) 0);
7801 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
7803 /* Look for mutex and implies relations. */
7804 else if ((idesc->operands[0] == IA64_OPND_P1
7805 || idesc->operands[0] == IA64_OPND_P2)
7806 && (idesc->operands[1] == IA64_OPND_P1
7807 || idesc->operands[1] == IA64_OPND_P2))
7809 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
7810 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
7811 valueT p1mask = (valueT) 1 << p1;
7812 valueT p2mask = (valueT) 1 << p2;
7814 /* If one of the PRs is PR0, we can't really do anything. */
7815 if (p1 == 0 || p2 == 0)
7818 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
7820 /* In general, clear mutexes and implies which include P1 or P2,
7821 with the following exceptions. */
7822 else if (strstr (idesc->name, ".or.andcm") != NULL)
7824 add_qp_mutex (p1mask | p2mask);
7825 clear_qp_implies (p2mask, p1mask);
7827 else if (strstr (idesc->name, ".and.orcm") != NULL)
7829 add_qp_mutex (p1mask | p2mask);
7830 clear_qp_implies (p1mask, p2mask);
7832 else if (strstr (idesc->name, ".and") != NULL)
7834 clear_qp_implies (0, p1mask | p2mask);
7836 else if (strstr (idesc->name, ".or") != NULL)
7838 clear_qp_mutex (p1mask | p2mask);
7839 clear_qp_implies (p1mask | p2mask, 0);
7843 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
7844 if (strstr (idesc->name, ".unc") != NULL)
7846 add_qp_mutex (p1mask | p2mask);
7847 if (CURR_SLOT.qp_regno != 0)
7849 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
7850 CURR_SLOT.qp_regno);
7851 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
7852 CURR_SLOT.qp_regno);
7855 else if (CURR_SLOT.qp_regno == 0)
7857 add_qp_mutex (p1mask | p2mask);
7861 clear_qp_mutex (p1mask | p2mask);
7865 /* Look for mov imm insns into GRs. */
7866 else if (idesc->operands[0] == IA64_OPND_R1
7867 && (idesc->operands[1] == IA64_OPND_IMM22
7868 || idesc->operands[1] == IA64_OPND_IMMU64)
7869 && (strcmp (idesc->name, "mov") == 0
7870 || strcmp (idesc->name, "movl") == 0))
7872 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
7873 if (regno > 0 && regno < NELEMS (gr_values))
7875 gr_values[regno].known = 1;
7876 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
7877 gr_values[regno].path = md.path;
7879 fprintf (stderr, " Know gr%d = 0x%llx\n",
7880 regno, gr_values[regno].value);
7885 clear_qp_mutex (qp_changemask);
7886 clear_qp_implies (qp_changemask, qp_changemask);
7890 /* Return whether the given predicate registers are currently mutex. */
7893 qp_mutex (p1, p2, path)
7903 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
7904 for (i = 0; i < qp_mutexeslen; i++)
7906 if (qp_mutexes[i].path >= path
7907 && (qp_mutexes[i].prmask & mask) == mask)
7914 /* Return whether the given resource is in the given insn's list of chks
7915 Return 1 if the conflict is absolutely determined, 2 if it's a potential
7919 resources_match (rs, idesc, note, qp_regno, path)
7921 struct ia64_opcode *idesc;
7926 struct rsrc specs[MAX_SPECS];
7929 /* If the marked resource's qp_regno and the given qp_regno are mutex,
7930 we don't need to check. One exception is note 11, which indicates that
7931 target predicates are written regardless of PR[qp]. */
7932 if (qp_mutex (rs->qp_regno, qp_regno, path)
7936 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
7939 /* UNAT checking is a bit more specific than other resources */
7940 if (rs->dependency->specifier == IA64_RS_AR_UNAT
7941 && specs[count].mem_offset.hint
7942 && rs->mem_offset.hint)
7944 if (rs->mem_offset.base == specs[count].mem_offset.base)
7946 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
7947 ((specs[count].mem_offset.offset >> 3) & 0x3F))
7954 /* If either resource is not specific, conservatively assume a conflict
7956 if (!specs[count].specific || !rs->specific)
7958 else if (specs[count].index == rs->index)
7963 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
7969 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
7970 insert a stop to create the break. Update all resource dependencies
7971 appropriately. If QP_REGNO is non-zero, only apply the break to resources
7972 which use the same QP_REGNO and have the link_to_qp_branch flag set.
7973 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
7977 insn_group_break (insert_stop, qp_regno, save_current)
7984 if (insert_stop && md.num_slots_in_use > 0)
7985 PREV_SLOT.end_of_insn_group = 1;
7989 fprintf (stderr, " Insn group break%s",
7990 (insert_stop ? " (w/stop)" : ""));
7992 fprintf (stderr, " effective for QP=%d", qp_regno);
7993 fprintf (stderr, "\n");
7997 while (i < regdepslen)
7999 const struct ia64_dependency *dep = regdeps[i].dependency;
8002 && regdeps[i].qp_regno != qp_regno)
8009 && CURR_SLOT.src_file == regdeps[i].file
8010 && CURR_SLOT.src_line == regdeps[i].line)
8016 /* clear dependencies which are automatically cleared by a stop, or
8017 those that have reached the appropriate state of insn serialization */
8018 if (dep->semantics == IA64_DVS_IMPLIED
8019 || dep->semantics == IA64_DVS_IMPLIEDF
8020 || regdeps[i].insn_srlz == STATE_SRLZ)
8022 print_dependency ("Removing", i);
8023 regdeps[i] = regdeps[--regdepslen];
8027 if (dep->semantics == IA64_DVS_DATA
8028 || dep->semantics == IA64_DVS_INSTR
8029 || dep->semantics == IA64_DVS_SPECIFIC)
8031 if (regdeps[i].insn_srlz == STATE_NONE)
8032 regdeps[i].insn_srlz = STATE_STOP;
8033 if (regdeps[i].data_srlz == STATE_NONE)
8034 regdeps[i].data_srlz = STATE_STOP;
8041 /* Add the given resource usage spec to the list of active dependencies. */
8044 mark_resource (idesc, dep, spec, depind, path)
8045 struct ia64_opcode *idesc;
8046 const struct ia64_dependency *dep;
8051 if (regdepslen == regdepstotlen)
8053 regdepstotlen += 20;
8054 regdeps = (struct rsrc *)
8055 xrealloc ((void *) regdeps,
8056 regdepstotlen * sizeof(struct rsrc));
8059 regdeps[regdepslen] = *spec;
8060 regdeps[regdepslen].depind = depind;
8061 regdeps[regdepslen].path = path;
8062 regdeps[regdepslen].file = CURR_SLOT.src_file;
8063 regdeps[regdepslen].line = CURR_SLOT.src_line;
8065 print_dependency ("Adding", regdepslen);
8071 print_dependency (action, depind)
8077 fprintf (stderr, " %s %s '%s'",
8078 action, dv_mode[(regdeps[depind].dependency)->mode],
8079 (regdeps[depind].dependency)->name);
8080 if (regdeps[depind].specific && regdeps[depind].index != 0)
8081 fprintf (stderr, " (%d)", regdeps[depind].index);
8082 if (regdeps[depind].mem_offset.hint)
8083 fprintf (stderr, " 0x%llx+0x%llx",
8084 regdeps[depind].mem_offset.base,
8085 regdeps[depind].mem_offset.offset);
8086 fprintf (stderr, "\n");
8091 instruction_serialization ()
8095 fprintf (stderr, " Instruction serialization\n");
8096 for (i = 0; i < regdepslen; i++)
8097 if (regdeps[i].insn_srlz == STATE_STOP)
8098 regdeps[i].insn_srlz = STATE_SRLZ;
8102 data_serialization ()
8106 fprintf (stderr, " Data serialization\n");
8107 while (i < regdepslen)
8109 if (regdeps[i].data_srlz == STATE_STOP
8110 /* Note: as of 991210, all "other" dependencies are cleared by a
8111 data serialization. This might change with new tables */
8112 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
8114 print_dependency ("Removing", i);
8115 regdeps[i] = regdeps[--regdepslen];
8122 /* Insert stops and serializations as needed to avoid DVs. */
8125 remove_marked_resource (rs)
8128 switch (rs->dependency->semantics)
8130 case IA64_DVS_SPECIFIC:
8132 fprintf (stderr, "Implementation-specific, assume worst case...\n");
8133 /* ...fall through... */
8134 case IA64_DVS_INSTR:
8136 fprintf (stderr, "Inserting instr serialization\n");
8137 if (rs->insn_srlz < STATE_STOP)
8138 insn_group_break (1, 0, 0);
8139 if (rs->insn_srlz < STATE_SRLZ)
8141 int oldqp = CURR_SLOT.qp_regno;
8142 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
8143 /* Manually jam a srlz.i insn into the stream */
8144 CURR_SLOT.qp_regno = 0;
8145 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
8146 instruction_serialization ();
8147 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
8148 if (++md.num_slots_in_use >= NUM_SLOTS)
8150 CURR_SLOT.qp_regno = oldqp;
8151 CURR_SLOT.idesc = oldidesc;
8153 insn_group_break (1, 0, 0);
8155 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
8156 "other" types of DV are eliminated
8157 by a data serialization */
8160 fprintf (stderr, "Inserting data serialization\n");
8161 if (rs->data_srlz < STATE_STOP)
8162 insn_group_break (1, 0, 0);
8164 int oldqp = CURR_SLOT.qp_regno;
8165 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
8166 /* Manually jam a srlz.d insn into the stream */
8167 CURR_SLOT.qp_regno = 0;
8168 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
8169 data_serialization ();
8170 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
8171 if (++md.num_slots_in_use >= NUM_SLOTS)
8173 CURR_SLOT.qp_regno = oldqp;
8174 CURR_SLOT.idesc = oldidesc;
8177 case IA64_DVS_IMPLIED:
8178 case IA64_DVS_IMPLIEDF:
8180 fprintf (stderr, "Inserting stop\n");
8181 insn_group_break (1, 0, 0);
8188 /* Check the resources used by the given opcode against the current dependency
8191 The check is run once for each execution path encountered. In this case,
8192 a unique execution path is the sequence of instructions following a code
8193 entry point, e.g. the following has three execution paths, one starting
8194 at L0, one at L1, and one at L2.
8203 check_dependencies (idesc)
8204 struct ia64_opcode *idesc;
8206 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
8210 /* Note that the number of marked resources may change within the
8211 loop if in auto mode. */
8213 while (i < regdepslen)
8215 struct rsrc *rs = ®deps[i];
8216 const struct ia64_dependency *dep = rs->dependency;
8221 if (dep->semantics == IA64_DVS_NONE
8222 || (chkind = depends_on (rs->depind, idesc)) == -1)
8228 note = NOTE (opdeps->chks[chkind]);
8230 /* Check this resource against each execution path seen thus far. */
8231 for (path = 0; path <= md.path; path++)
8235 /* If the dependency wasn't on the path being checked, ignore it. */
8236 if (rs->path < path)
8239 /* If the QP for this insn implies a QP which has branched, don't
8240 bother checking. Ed. NOTE: I don't think this check is terribly
8241 useful; what's the point of generating code which will only be
8242 reached if its QP is zero?
8243 This code was specifically inserted to handle the following code,
8244 based on notes from Intel's DV checking code, where p1 implies p2.
8250 if (CURR_SLOT.qp_regno != 0)
8254 for (implies = 0; implies < qp_implieslen; implies++)
8256 if (qp_implies[implies].path >= path
8257 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
8258 && qp_implies[implies].p2_branched)
8268 if ((matchtype = resources_match (rs, idesc, note,
8269 CURR_SLOT.qp_regno, path)) != 0)
8272 char pathmsg[256] = "";
8273 char indexmsg[256] = "";
8274 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
8277 sprintf (pathmsg, " when entry is at label '%s'",
8278 md.entry_labels[path - 1]);
8279 if (rs->specific && rs->index != 0)
8280 sprintf (indexmsg, ", specific resource number is %d",
8282 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
8284 (certain ? "violates" : "may violate"),
8285 dv_mode[dep->mode], dep->name,
8286 dv_sem[dep->semantics],
8289 if (md.explicit_mode)
8291 as_warn ("%s", msg);
8293 as_warn (_("Only the first path encountering the conflict "
8295 as_warn_where (rs->file, rs->line,
8296 _("This is the location of the "
8297 "conflicting usage"));
8298 /* Don't bother checking other paths, to avoid duplicating
8305 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
8307 remove_marked_resource (rs);
8309 /* since the set of dependencies has changed, start over */
8310 /* FIXME -- since we're removing dvs as we go, we
8311 probably don't really need to start over... */
8324 /* Register new dependencies based on the given opcode. */
8327 mark_resources (idesc)
8328 struct ia64_opcode *idesc;
8331 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
8332 int add_only_qp_reads = 0;
8334 /* A conditional branch only uses its resources if it is taken; if it is
8335 taken, we stop following that path. The other branch types effectively
8336 *always* write their resources. If it's not taken, register only QP
8338 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
8340 add_only_qp_reads = 1;
8344 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
8346 for (i = 0; i < opdeps->nregs; i++)
8348 const struct ia64_dependency *dep;
8349 struct rsrc specs[MAX_SPECS];
8354 dep = ia64_find_dependency (opdeps->regs[i]);
8355 note = NOTE (opdeps->regs[i]);
8357 if (add_only_qp_reads
8358 && !(dep->mode == IA64_DV_WAR
8359 && (dep->specifier == IA64_RS_PR
8360 || dep->specifier == IA64_RS_PR63)))
8363 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
8366 if (md.debug_dv && !count)
8367 fprintf (stderr, " No %s %s usage found (path %d)\n",
8368 dv_mode[dep->mode], dep->name, md.path);
8373 mark_resource (idesc, dep, &specs[count],
8374 DEP (opdeps->regs[i]), md.path);
8377 /* The execution path may affect register values, which may in turn
8378 affect which indirect-access resources are accessed. */
8379 switch (dep->specifier)
8391 for (path = 0; path < md.path; path++)
8393 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
8395 mark_resource (idesc, dep, &specs[count],
8396 DEP (opdeps->regs[i]), path);
8403 /* Remove dependencies when they no longer apply. */
8406 update_dependencies (idesc)
8407 struct ia64_opcode *idesc;
8411 if (strcmp (idesc->name, "srlz.i") == 0)
8413 instruction_serialization ();
8415 else if (strcmp (idesc->name, "srlz.d") == 0)
8417 data_serialization ();
8419 else if (is_interruption_or_rfi (idesc)
8420 || is_taken_branch (idesc))
8422 /* Although technically the taken branch doesn't clear dependencies
8423 which require a srlz.[id], we don't follow the branch; the next
8424 instruction is assumed to start with a clean slate. */
8428 else if (is_conditional_branch (idesc)
8429 && CURR_SLOT.qp_regno != 0)
8431 int is_call = strstr (idesc->name, ".call") != NULL;
8433 for (i = 0; i < qp_implieslen; i++)
8435 /* If the conditional branch's predicate is implied by the predicate
8436 in an existing dependency, remove that dependency. */
8437 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
8440 /* Note that this implied predicate takes a branch so that if
8441 a later insn generates a DV but its predicate implies this
8442 one, we can avoid the false DV warning. */
8443 qp_implies[i].p2_branched = 1;
8444 while (depind < regdepslen)
8446 if (regdeps[depind].qp_regno == qp_implies[i].p1)
8448 print_dependency ("Removing", depind);
8449 regdeps[depind] = regdeps[--regdepslen];
8456 /* Any marked resources which have this same predicate should be
8457 cleared, provided that the QP hasn't been modified between the
8458 marking instruction and the branch. */
8461 insn_group_break (0, CURR_SLOT.qp_regno, 1);
8466 while (i < regdepslen)
8468 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
8469 && regdeps[i].link_to_qp_branch
8470 && (regdeps[i].file != CURR_SLOT.src_file
8471 || regdeps[i].line != CURR_SLOT.src_line))
8473 /* Treat like a taken branch */
8474 print_dependency ("Removing", i);
8475 regdeps[i] = regdeps[--regdepslen];
8484 /* Examine the current instruction for dependency violations. */
8488 struct ia64_opcode *idesc;
8492 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
8493 idesc->name, CURR_SLOT.src_line,
8494 idesc->dependencies->nchks,
8495 idesc->dependencies->nregs);
8498 /* Look through the list of currently marked resources; if the current
8499 instruction has the dependency in its chks list which uses that resource,
8500 check against the specific resources used. */
8501 check_dependencies (idesc);
8503 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
8504 then add them to the list of marked resources. */
8505 mark_resources (idesc);
8507 /* There are several types of dependency semantics, and each has its own
8508 requirements for being cleared
8510 Instruction serialization (insns separated by interruption, rfi, or
8511 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
8513 Data serialization (instruction serialization, or writer + srlz.d +
8514 reader, where writer and srlz.d are in separate groups) clears
8515 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
8516 always be the case).
8518 Instruction group break (groups separated by stop, taken branch,
8519 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
8521 update_dependencies (idesc);
8523 /* Sometimes, knowing a register value allows us to avoid giving a false DV
8524 warning. Keep track of as many as possible that are useful. */
8525 note_register_values (idesc);
8527 /* We don't need or want this anymore. */
8528 md.mem_offset.hint = 0;
8533 /* Translate one line of assembly. Pseudo ops and labels do not show
8539 char *saved_input_line_pointer, *mnemonic;
8540 const struct pseudo_opcode *pdesc;
8541 struct ia64_opcode *idesc;
8542 unsigned char qp_regno;
8546 saved_input_line_pointer = input_line_pointer;
8547 input_line_pointer = str;
8549 /* extract the opcode (mnemonic): */
8551 mnemonic = input_line_pointer;
8552 ch = get_symbol_end ();
8553 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
8556 *input_line_pointer = ch;
8557 (*pdesc->handler) (pdesc->arg);
8561 /* Find the instruction descriptor matching the arguments. */
8563 idesc = ia64_find_opcode (mnemonic);
8564 *input_line_pointer = ch;
8567 as_bad ("Unknown opcode `%s'", mnemonic);
8571 idesc = parse_operands (idesc);
8575 /* Handle the dynamic ops we can handle now: */
8576 if (idesc->type == IA64_TYPE_DYN)
8578 if (strcmp (idesc->name, "add") == 0)
8580 if (CURR_SLOT.opnd[2].X_op == O_register
8581 && CURR_SLOT.opnd[2].X_add_number < 4)
8585 ia64_free_opcode (idesc);
8586 idesc = ia64_find_opcode (mnemonic);
8588 know (!idesc->next);
8591 else if (strcmp (idesc->name, "mov") == 0)
8593 enum ia64_opnd opnd1, opnd2;
8596 opnd1 = idesc->operands[0];
8597 opnd2 = idesc->operands[1];
8598 if (opnd1 == IA64_OPND_AR3)
8600 else if (opnd2 == IA64_OPND_AR3)
8604 if (CURR_SLOT.opnd[rop].X_op == O_register
8605 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
8609 ia64_free_opcode (idesc);
8610 idesc = ia64_find_opcode (mnemonic);
8611 while (idesc != NULL
8612 && (idesc->operands[0] != opnd1
8613 || idesc->operands[1] != opnd2))
8614 idesc = get_next_opcode (idesc);
8619 if (md.qp.X_op == O_register)
8620 qp_regno = md.qp.X_add_number - REG_P;
8622 flags = idesc->flags;
8624 if ((flags & IA64_OPCODE_FIRST) != 0)
8625 insn_group_break (1, 0, 0);
8627 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
8629 as_bad ("`%s' cannot be predicated", idesc->name);
8633 /* Build the instruction. */
8634 CURR_SLOT.qp_regno = qp_regno;
8635 CURR_SLOT.idesc = idesc;
8636 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
8637 if (debug_type == DEBUG_DWARF2)
8638 dwarf2_where (&CURR_SLOT.debug_line);
8640 /* Add unwind entry, if there is one. */
8641 if (unwind.current_entry)
8643 CURR_SLOT.unwind_record = unwind.current_entry;
8644 unwind.current_entry = NULL;
8647 /* Check for dependency violations. */
8651 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
8652 if (++md.num_slots_in_use >= NUM_SLOTS)
8655 if ((flags & IA64_OPCODE_LAST) != 0)
8656 insn_group_break (1, 0, 0);
8658 md.last_text_seg = now_seg;
8661 input_line_pointer = saved_input_line_pointer;
8664 /* Called when symbol NAME cannot be found in the symbol table.
8665 Should be used for dynamic valued symbols only. */
8668 md_undefined_symbol (name)
8674 /* Called for any expression that can not be recognized. When the
8675 function is called, `input_line_pointer' will point to the start of
8682 enum pseudo_type pseudo_type;
8687 switch (*input_line_pointer)
8690 /* Find what relocation pseudo-function we're dealing with. */
8692 ch = *++input_line_pointer;
8693 for (i = 0; i < NELEMS (pseudo_func); ++i)
8694 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
8696 len = strlen (pseudo_func[i].name);
8697 if (strncmp (pseudo_func[i].name + 1,
8698 input_line_pointer + 1, len - 1) == 0
8699 && !is_part_of_name (input_line_pointer[len]))
8701 input_line_pointer += len;
8702 pseudo_type = pseudo_func[i].type;
8706 switch (pseudo_type)
8708 case PSEUDO_FUNC_RELOC:
8710 if (*input_line_pointer != '(')
8712 as_bad ("Expected '('");
8716 ++input_line_pointer;
8718 if (*input_line_pointer++ != ')')
8720 as_bad ("Missing ')'");
8723 if (e->X_op != O_symbol)
8725 if (e->X_op != O_pseudo_fixup)
8727 as_bad ("Not a symbolic expression");
8730 if (S_GET_VALUE (e->X_op_symbol) == FUNC_FPTR_RELATIVE
8731 && i == FUNC_LT_RELATIVE)
8732 i = FUNC_LT_FPTR_RELATIVE;
8735 as_bad ("Illegal combination of relocation functions");
8739 /* Make sure gas doesn't get rid of local symbols that are used
8741 e->X_op = O_pseudo_fixup;
8742 e->X_op_symbol = pseudo_func[i].u.sym;
8745 case PSEUDO_FUNC_CONST:
8746 e->X_op = O_constant;
8747 e->X_add_number = pseudo_func[i].u.ival;
8750 case PSEUDO_FUNC_REG:
8751 e->X_op = O_register;
8752 e->X_add_number = pseudo_func[i].u.ival;
8756 name = input_line_pointer - 1;
8758 as_bad ("Unknown pseudo function `%s'", name);
8764 ++input_line_pointer;
8766 if (*input_line_pointer != ']')
8768 as_bad ("Closing bracket misssing");
8773 if (e->X_op != O_register)
8774 as_bad ("Register expected as index");
8776 ++input_line_pointer;
8787 ignore_rest_of_line ();
8790 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
8791 a section symbol plus some offset. For relocs involving @fptr(),
8792 directives we don't want such adjustments since we need to have the
8793 original symbol's name in the reloc. */
8795 ia64_fix_adjustable (fix)
8798 /* Prevent all adjustments to global symbols */
8799 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
8802 switch (fix->fx_r_type)
8804 case BFD_RELOC_IA64_FPTR64I:
8805 case BFD_RELOC_IA64_FPTR32MSB:
8806 case BFD_RELOC_IA64_FPTR32LSB:
8807 case BFD_RELOC_IA64_FPTR64MSB:
8808 case BFD_RELOC_IA64_FPTR64LSB:
8809 case BFD_RELOC_IA64_LTOFF_FPTR22:
8810 case BFD_RELOC_IA64_LTOFF_FPTR64I:
8820 ia64_force_relocation (fix)
8823 switch (fix->fx_r_type)
8825 case BFD_RELOC_IA64_FPTR64I:
8826 case BFD_RELOC_IA64_FPTR32MSB:
8827 case BFD_RELOC_IA64_FPTR32LSB:
8828 case BFD_RELOC_IA64_FPTR64MSB:
8829 case BFD_RELOC_IA64_FPTR64LSB:
8831 case BFD_RELOC_IA64_LTOFF22:
8832 case BFD_RELOC_IA64_LTOFF64I:
8833 case BFD_RELOC_IA64_LTOFF_FPTR22:
8834 case BFD_RELOC_IA64_LTOFF_FPTR64I:
8835 case BFD_RELOC_IA64_PLTOFF22:
8836 case BFD_RELOC_IA64_PLTOFF64I:
8837 case BFD_RELOC_IA64_PLTOFF64MSB:
8838 case BFD_RELOC_IA64_PLTOFF64LSB:
8847 /* Decide from what point a pc-relative relocation is relative to,
8848 relative to the pc-relative fixup. Er, relatively speaking. */
8850 ia64_pcrel_from_section (fix, sec)
8854 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
8856 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
8862 /* This is called whenever some data item (not an instruction) needs a
8863 fixup. We pick the right reloc code depending on the byteorder
8864 currently in effect. */
8866 ia64_cons_fix_new (f, where, nbytes, exp)
8872 bfd_reloc_code_real_type code;
8877 /* There are no reloc for 8 and 16 bit quantities, but we allow
8878 them here since they will work fine as long as the expression
8879 is fully defined at the end of the pass over the source file. */
8880 case 1: code = BFD_RELOC_8; break;
8881 case 2: code = BFD_RELOC_16; break;
8883 if (target_big_endian)
8884 code = BFD_RELOC_IA64_DIR32MSB;
8886 code = BFD_RELOC_IA64_DIR32LSB;
8890 if (target_big_endian)
8891 code = BFD_RELOC_IA64_DIR64MSB;
8893 code = BFD_RELOC_IA64_DIR64LSB;
8897 as_bad ("Unsupported fixup size %d", nbytes);
8898 ignore_rest_of_line ();
8901 if (exp->X_op == O_pseudo_fixup)
8904 exp->X_op = O_symbol;
8905 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
8907 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
8908 /* We need to store the byte order in effect in case we're going
8909 to fix an 8 or 16 bit relocation (for which there no real
8910 relocs available). See md_apply_fix(). */
8911 fix->tc_fix_data.bigendian = target_big_endian;
8914 /* Return the actual relocation we wish to associate with the pseudo
8915 reloc described by SYM and R_TYPE. SYM should be one of the
8916 symbols in the pseudo_func array, or NULL. */
8918 static bfd_reloc_code_real_type
8919 ia64_gen_real_reloc_type (sym, r_type)
8921 bfd_reloc_code_real_type r_type;
8923 bfd_reloc_code_real_type new = 0;
8930 switch (S_GET_VALUE (sym))
8932 case FUNC_FPTR_RELATIVE:
8935 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
8936 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
8937 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
8938 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
8939 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
8944 case FUNC_GP_RELATIVE:
8947 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
8948 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
8949 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
8950 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
8951 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
8952 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
8957 case FUNC_LT_RELATIVE:
8960 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
8961 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
8966 case FUNC_PC_RELATIVE:
8969 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
8970 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
8971 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
8972 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
8973 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
8974 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
8979 case FUNC_PLT_RELATIVE:
8982 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
8983 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
8984 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
8985 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
8990 case FUNC_SEC_RELATIVE:
8993 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
8994 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
8995 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
8996 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
9001 case FUNC_SEG_RELATIVE:
9004 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
9005 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
9006 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
9007 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
9012 case FUNC_LTV_RELATIVE:
9015 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
9016 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
9017 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
9018 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
9023 case FUNC_LT_FPTR_RELATIVE:
9026 case BFD_RELOC_IA64_IMM22:
9027 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
9028 case BFD_RELOC_IA64_IMM64:
9029 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
9037 /* Hmmmm. Should this ever occur? */
9044 /* Here is where generate the appropriate reloc for pseudo relocation
9047 ia64_validate_fix (fix)
9050 switch (fix->fx_r_type)
9052 case BFD_RELOC_IA64_FPTR64I:
9053 case BFD_RELOC_IA64_FPTR32MSB:
9054 case BFD_RELOC_IA64_FPTR64LSB:
9055 case BFD_RELOC_IA64_LTOFF_FPTR22:
9056 case BFD_RELOC_IA64_LTOFF_FPTR64I:
9057 if (fix->fx_offset != 0)
9058 as_bad_where (fix->fx_file, fix->fx_line,
9059 "No addend allowed in @fptr() relocation");
9069 fix_insn (fix, odesc, value)
9071 const struct ia64_operand *odesc;
9074 bfd_vma insn[3], t0, t1, control_bits;
9079 slot = fix->fx_where & 0x3;
9080 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
9082 /* Bundles are always in little-endian byte order */
9083 t0 = bfd_getl64 (fixpos);
9084 t1 = bfd_getl64 (fixpos + 8);
9085 control_bits = t0 & 0x1f;
9086 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
9087 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
9088 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
9091 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
9093 insn[1] = (value >> 22) & 0x1ffffffffffLL;
9094 insn[2] |= (((value & 0x7f) << 13)
9095 | (((value >> 7) & 0x1ff) << 27)
9096 | (((value >> 16) & 0x1f) << 22)
9097 | (((value >> 21) & 0x1) << 21)
9098 | (((value >> 63) & 0x1) << 36));
9100 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
9102 if (value & ~0x3fffffffffffffffULL)
9103 err = "integer operand out of range";
9104 insn[1] = (value >> 21) & 0x1ffffffffffLL;
9105 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
9107 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
9110 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
9111 insn[2] |= ((((value >> 59) & 0x1) << 36)
9112 | (((value >> 0) & 0xfffff) << 13));
9115 err = (*odesc->insert) (odesc, value, insn + slot);
9118 as_bad_where (fix->fx_file, fix->fx_line, err);
9120 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
9121 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
9122 md_number_to_chars (fixpos + 0, t0, 8);
9123 md_number_to_chars (fixpos + 8, t1, 8);
9126 /* Attempt to simplify or even eliminate a fixup. The return value is
9127 ignored; perhaps it was once meaningful, but now it is historical.
9128 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
9130 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
9133 md_apply_fix3 (fix, valuep, seg)
9139 valueT value = *valuep;
9142 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
9146 switch (fix->fx_r_type)
9148 case BFD_RELOC_IA64_DIR32MSB:
9149 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
9153 case BFD_RELOC_IA64_DIR32LSB:
9154 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
9158 case BFD_RELOC_IA64_DIR64MSB:
9159 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
9163 case BFD_RELOC_IA64_DIR64LSB:
9164 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
9174 switch (fix->fx_r_type)
9177 as_bad_where (fix->fx_file, fix->fx_line,
9178 "%s must have a constant value",
9179 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
9186 /* ??? This is a hack copied from tc-i386.c to make PCREL relocs
9187 work. There should be a better way to handle this. */
9189 fix->fx_offset += fix->fx_where + fix->fx_frag->fr_address;
9191 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
9193 if (fix->tc_fix_data.bigendian)
9194 number_to_chars_bigendian (fixpos, value, fix->fx_size);
9196 number_to_chars_littleendian (fixpos, value, fix->fx_size);
9202 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
9209 /* Generate the BFD reloc to be stuck in the object file from the
9210 fixup used internally in the assembler. */
9213 tc_gen_reloc (sec, fixp)
9219 reloc = xmalloc (sizeof (*reloc));
9220 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
9221 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
9222 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
9223 reloc->addend = fixp->fx_offset;
9224 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
9228 as_bad_where (fixp->fx_file, fixp->fx_line,
9229 "Cannot represent %s relocation in object file",
9230 bfd_get_reloc_code_name (fixp->fx_r_type));
9235 /* Turn a string in input_line_pointer into a floating point constant
9236 of type TYPE, and store the appropriate bytes in *LIT. The number
9237 of LITTLENUMS emitted is stored in *SIZE. An error message is
9238 returned, or NULL on OK. */
9240 #define MAX_LITTLENUMS 5
9243 md_atof (type, lit, size)
9248 LITTLENUM_TYPE words[MAX_LITTLENUMS];
9249 LITTLENUM_TYPE *word;
9279 return "Bad call to MD_ATOF()";
9281 t = atof_ieee (input_line_pointer, type, words);
9283 input_line_pointer = t;
9284 *size = prec * sizeof (LITTLENUM_TYPE);
9286 for (word = words + prec - 1; prec--;)
9288 md_number_to_chars (lit, (long) (*word--), sizeof (LITTLENUM_TYPE));
9289 lit += sizeof (LITTLENUM_TYPE);
9294 /* Round up a section's size to the appropriate boundary. */
9296 md_section_align (seg, size)
9300 int align = bfd_get_section_alignment (stdoutput, seg);
9301 valueT mask = ((valueT) 1 << align) - 1;
9303 return (size + mask) & ~mask;
9306 /* Handle ia64 specific semantics of the align directive. */
9309 ia64_md_do_align (n, fill, len, max)
9315 /* Fill any pending bundle with nops. */
9316 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
9317 ia64_flush_insns ();
9319 /* When we align code in a text section, emit a bundle of 3 nops instead of
9320 zero bytes. We can only do this if a multiple of 16 bytes was requested.
9321 N is log base 2 of the requested alignment. */
9323 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE
9326 /* Use mfi bundle of nops with no stop bits. */
9327 static const unsigned char be_nop[]
9328 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
9329 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
9330 static const unsigned char le_nop[]
9331 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
9332 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
9334 /* Make sure we are on a 16-byte boundary, in case someone has been
9335 putting data into a text section. */
9336 frag_align (4, 0, 0);
9338 if (target_big_endian)
9339 frag_align_pattern (n, be_nop, 16, max);
9341 frag_align_pattern (n, le_nop, 16, max);