]> Git Repo - binutils.git/blob - gas/config/tc-ia64.c
gas/
[binutils.git] / gas / config / tc-ia64.c
1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2    Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3    Free Software Foundation, Inc.
4    Contributed by David Mosberger-Tang <[email protected]>
5
6    This file is part of GAS, the GNU Assembler.
7
8    GAS is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2, or (at your option)
11    any later version.
12
13    GAS is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GAS; see the file COPYING.  If not, write to
20    the Free Software Foundation, 51 Franklin Street - Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22
23 /*
24   TODO:
25
26   - optional operands
27   - directives:
28         .eb
29         .estate
30         .lb
31         .popsection
32         .previous
33         .psr
34         .pushsection
35   - labels are wrong if automatic alignment is introduced
36     (e.g., checkout the second real10 definition in test-data.s)
37   - DV-related stuff:
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
41         notes)
42
43  */
44
45 #include "as.h"
46 #include "safe-ctype.h"
47 #include "dwarf2dbg.h"
48 #include "subsegs.h"
49
50 #include "opcode/ia64.h"
51
52 #include "elf/ia64.h"
53
54 #ifdef HAVE_LIMITS_H
55 #include <limits.h>
56 #endif
57
58 #define NELEMS(a)       ((int) (sizeof (a)/sizeof ((a)[0])))
59
60 /* Some systems define MIN in, e.g., param.h.  */
61 #undef MIN
62 #define MIN(a,b)        ((a) < (b) ? (a) : (b))
63
64 #define NUM_SLOTS       4
65 #define PREV_SLOT       md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
66 #define CURR_SLOT       md.slot[md.curr_slot]
67
68 #define O_pseudo_fixup (O_max + 1)
69
70 enum special_section
71   {
72     /* IA-64 ABI section pseudo-ops.  */
73     SPECIAL_SECTION_BSS = 0,
74     SPECIAL_SECTION_SBSS,
75     SPECIAL_SECTION_SDATA,
76     SPECIAL_SECTION_RODATA,
77     SPECIAL_SECTION_COMMENT,
78     SPECIAL_SECTION_UNWIND,
79     SPECIAL_SECTION_UNWIND_INFO,
80     /* HPUX specific section pseudo-ops.  */
81     SPECIAL_SECTION_INIT_ARRAY,
82     SPECIAL_SECTION_FINI_ARRAY,
83   };
84
85 enum reloc_func
86   {
87     FUNC_DTP_MODULE,
88     FUNC_DTP_RELATIVE,
89     FUNC_FPTR_RELATIVE,
90     FUNC_GP_RELATIVE,
91     FUNC_LT_RELATIVE,
92     FUNC_LT_RELATIVE_X,
93     FUNC_PC_RELATIVE,
94     FUNC_PLT_RELATIVE,
95     FUNC_SEC_RELATIVE,
96     FUNC_SEG_RELATIVE,
97     FUNC_TP_RELATIVE,
98     FUNC_LTV_RELATIVE,
99     FUNC_LT_FPTR_RELATIVE,
100     FUNC_LT_DTP_MODULE,
101     FUNC_LT_DTP_RELATIVE,
102     FUNC_LT_TP_RELATIVE,
103     FUNC_IPLT_RELOC,
104   };
105
106 enum reg_symbol
107   {
108     REG_GR      = 0,
109     REG_FR      = (REG_GR + 128),
110     REG_AR      = (REG_FR + 128),
111     REG_CR      = (REG_AR + 128),
112     REG_P       = (REG_CR + 128),
113     REG_BR      = (REG_P  + 64),
114     REG_IP      = (REG_BR + 8),
115     REG_CFM,
116     REG_PR,
117     REG_PR_ROT,
118     REG_PSR,
119     REG_PSR_L,
120     REG_PSR_UM,
121     /* The following are pseudo-registers for use by gas only.  */
122     IND_CPUID,
123     IND_DBR,
124     IND_DTR,
125     IND_ITR,
126     IND_IBR,
127     IND_MEM,
128     IND_MSR,
129     IND_PKR,
130     IND_PMC,
131     IND_PMD,
132     IND_RR,
133     /* The following pseudo-registers are used for unwind directives only:  */
134     REG_PSP,
135     REG_PRIUNAT,
136     REG_NUM
137   };
138
139 enum dynreg_type
140   {
141     DYNREG_GR = 0,      /* dynamic general purpose register */
142     DYNREG_FR,          /* dynamic floating point register */
143     DYNREG_PR,          /* dynamic predicate register */
144     DYNREG_NUM_TYPES
145   };
146
147 enum operand_match_result
148   {
149     OPERAND_MATCH,
150     OPERAND_OUT_OF_RANGE,
151     OPERAND_MISMATCH
152   };
153
154 /* On the ia64, we can't know the address of a text label until the
155    instructions are packed into a bundle.  To handle this, we keep
156    track of the list of labels that appear in front of each
157    instruction.  */
158 struct label_fix
159 {
160   struct label_fix *next;
161   struct symbol *sym;
162 };
163
164 /* This is the endianness of the current section.  */
165 extern int target_big_endian;
166
167 /* This is the default endianness.  */
168 static int default_big_endian = TARGET_BYTES_BIG_ENDIAN;
169
170 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
171
172 static void ia64_float_to_chars_bigendian
173   PARAMS ((char *, LITTLENUM_TYPE *, int));
174 static void ia64_float_to_chars_littleendian
175   PARAMS ((char *, LITTLENUM_TYPE *, int));
176 static void (*ia64_float_to_chars)
177   PARAMS ((char *, LITTLENUM_TYPE *, int));
178
179 static struct hash_control *alias_hash;
180 static struct hash_control *alias_name_hash;
181 static struct hash_control *secalias_hash;
182 static struct hash_control *secalias_name_hash;
183
184 /* List of chars besides those in app.c:symbol_chars that can start an
185    operand.  Used to prevent the scrubber eating vital white-space.  */
186 const char ia64_symbol_chars[] = "@?";
187
188 /* Characters which always start a comment.  */
189 const char comment_chars[] = "";
190
191 /* Characters which start a comment at the beginning of a line.  */
192 const char line_comment_chars[] = "#";
193
194 /* Characters which may be used to separate multiple commands on a
195    single line.  */
196 const char line_separator_chars[] = ";";
197
198 /* Characters which are used to indicate an exponent in a floating
199    point number.  */
200 const char EXP_CHARS[] = "eE";
201
202 /* Characters which mean that a number is a floating point constant,
203    as in 0d1.0.  */
204 const char FLT_CHARS[] = "rRsSfFdDxXpP";
205
206 /* ia64-specific option processing:  */
207
208 const char *md_shortopts = "m:N:x::";
209
210 struct option md_longopts[] =
211   {
212 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
213     {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
214 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
215     {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
216   };
217
218 size_t md_longopts_size = sizeof (md_longopts);
219
220 static struct
221   {
222     struct hash_control *pseudo_hash;   /* pseudo opcode hash table */
223     struct hash_control *reg_hash;      /* register name hash table */
224     struct hash_control *dynreg_hash;   /* dynamic register hash table */
225     struct hash_control *const_hash;    /* constant hash table */
226     struct hash_control *entry_hash;    /* code entry hint hash table */
227
228     symbolS *regsym[REG_NUM];
229
230     /* If X_op is != O_absent, the registername for the instruction's
231        qualifying predicate.  If NULL, p0 is assumed for instructions
232        that are predicatable.  */
233     expressionS qp;
234
235     /* Optimize for which CPU.  */
236     enum
237       {
238         itanium1,
239         itanium2
240       } tune;
241
242     /* What to do when hint.b is used.  */
243     enum
244       {
245         hint_b_error,
246         hint_b_warning,
247         hint_b_ok
248       } hint_b;
249
250     unsigned int
251       manual_bundling : 1,
252       debug_dv: 1,
253       detect_dv: 1,
254       explicit_mode : 1,            /* which mode we're in */
255       default_explicit_mode : 1,    /* which mode is the default */
256       mode_explicitly_set : 1,      /* was the current mode explicitly set? */
257       auto_align : 1,
258       keep_pending_output : 1;
259
260     /* What to do when something is wrong with unwind directives.  */
261     enum
262       {
263         unwind_check_warning,
264         unwind_check_error
265       } unwind_check;
266
267     /* Each bundle consists of up to three instructions.  We keep
268        track of four most recent instructions so we can correctly set
269        the end_of_insn_group for the last instruction in a bundle.  */
270     int curr_slot;
271     int num_slots_in_use;
272     struct slot
273       {
274         unsigned int
275           end_of_insn_group : 1,
276           manual_bundling_on : 1,
277           manual_bundling_off : 1,
278           loc_directive_seen : 1;
279         signed char user_template;      /* user-selected template, if any */
280         unsigned char qp_regno;         /* qualifying predicate */
281         /* This duplicates a good fraction of "struct fix" but we
282            can't use a "struct fix" instead since we can't call
283            fix_new_exp() until we know the address of the instruction.  */
284         int num_fixups;
285         struct insn_fix
286           {
287             bfd_reloc_code_real_type code;
288             enum ia64_opnd opnd;        /* type of operand in need of fix */
289             unsigned int is_pcrel : 1;  /* is operand pc-relative? */
290             expressionS expr;           /* the value to be inserted */
291           }
292         fixup[2];                       /* at most two fixups per insn */
293         struct ia64_opcode *idesc;
294         struct label_fix *label_fixups;
295         struct label_fix *tag_fixups;
296         struct unw_rec_list *unwind_record;     /* Unwind directive.  */
297         expressionS opnd[6];
298         char *src_file;
299         unsigned int src_line;
300         struct dwarf2_line_info debug_line;
301       }
302     slot[NUM_SLOTS];
303
304     segT last_text_seg;
305
306     struct dynreg
307       {
308         struct dynreg *next;            /* next dynamic register */
309         const char *name;
310         unsigned short base;            /* the base register number */
311         unsigned short num_regs;        /* # of registers in this set */
312       }
313     *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
314
315     flagword flags;                     /* ELF-header flags */
316
317     struct mem_offset {
318       unsigned hint:1;              /* is this hint currently valid? */
319       bfd_vma offset;               /* mem.offset offset */
320       bfd_vma base;                 /* mem.offset base */
321     } mem_offset;
322
323     int path;                       /* number of alt. entry points seen */
324     const char **entry_labels;      /* labels of all alternate paths in
325                                        the current DV-checking block.  */
326     int maxpaths;                   /* size currently allocated for
327                                        entry_labels */
328
329     int pointer_size;       /* size in bytes of a pointer */
330     int pointer_size_shift; /* shift size of a pointer for alignment */
331   }
332 md;
333
334 /* These are not const, because they are modified to MMI for non-itanium1
335    targets below.  */
336 /* MFI bundle of nops.  */
337 static unsigned char le_nop[16] =
338 {
339   0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
340   0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00
341 };
342 /* MFI bundle of nops with stop-bit.  */
343 static unsigned char le_nop_stop[16] =
344 {
345   0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
346   0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00
347 };
348
349 /* application registers:  */
350
351 #define AR_K0           0
352 #define AR_K7           7
353 #define AR_RSC          16
354 #define AR_BSP          17
355 #define AR_BSPSTORE     18
356 #define AR_RNAT         19
357 #define AR_UNAT         36
358 #define AR_FPSR         40
359 #define AR_ITC          44
360 #define AR_PFS          64
361 #define AR_LC           65
362
363 static const struct
364   {
365     const char *name;
366     int regnum;
367   }
368 ar[] =
369   {
370     {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
371     {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
372     {"ar.rsc",          16}, {"ar.bsp",         17},
373     {"ar.bspstore",     18}, {"ar.rnat",        19},
374     {"ar.fcr",          21}, {"ar.eflag",       24},
375     {"ar.csd",          25}, {"ar.ssd",         26},
376     {"ar.cflg",         27}, {"ar.fsr",         28},
377     {"ar.fir",          29}, {"ar.fdr",         30},
378     {"ar.ccv",          32}, {"ar.unat",        36},
379     {"ar.fpsr",         40}, {"ar.itc",         44},
380     {"ar.pfs",          64}, {"ar.lc",          65},
381     {"ar.ec",           66},
382   };
383
384 #define CR_IPSR         16
385 #define CR_ISR          17
386 #define CR_IIP          19
387 #define CR_IFA          20
388 #define CR_ITIR         21
389 #define CR_IIPA         22
390 #define CR_IFS          23
391 #define CR_IIM          24
392 #define CR_IHA          25
393 #define CR_IVR          65
394 #define CR_TPR          66
395 #define CR_EOI          67
396 #define CR_IRR0         68
397 #define CR_IRR3         71
398 #define CR_LRR0         80
399 #define CR_LRR1         81
400
401 /* control registers:  */
402 static const struct
403   {
404     const char *name;
405     int regnum;
406   }
407 cr[] =
408   {
409     {"cr.dcr",   0},
410     {"cr.itm",   1},
411     {"cr.iva",   2},
412     {"cr.pta",   8},
413     {"cr.gpta",  9},
414     {"cr.ipsr", 16},
415     {"cr.isr",  17},
416     {"cr.iip",  19},
417     {"cr.ifa",  20},
418     {"cr.itir", 21},
419     {"cr.iipa", 22},
420     {"cr.ifs",  23},
421     {"cr.iim",  24},
422     {"cr.iha",  25},
423     {"cr.lid",  64},
424     {"cr.ivr",  65},
425     {"cr.tpr",  66},
426     {"cr.eoi",  67},
427     {"cr.irr0", 68},
428     {"cr.irr1", 69},
429     {"cr.irr2", 70},
430     {"cr.irr3", 71},
431     {"cr.itv",  72},
432     {"cr.pmv",  73},
433     {"cr.cmcv", 74},
434     {"cr.lrr0", 80},
435     {"cr.lrr1", 81}
436   };
437
438 #define PSR_MFL         4
439 #define PSR_IC          13
440 #define PSR_DFL         18
441 #define PSR_CPL         32
442
443 static const struct const_desc
444   {
445     const char *name;
446     valueT value;
447   }
448 const_bits[] =
449   {
450     /* PSR constant masks:  */
451
452     /* 0: reserved */
453     {"psr.be",  ((valueT) 1) << 1},
454     {"psr.up",  ((valueT) 1) << 2},
455     {"psr.ac",  ((valueT) 1) << 3},
456     {"psr.mfl", ((valueT) 1) << 4},
457     {"psr.mfh", ((valueT) 1) << 5},
458     /* 6-12: reserved */
459     {"psr.ic",  ((valueT) 1) << 13},
460     {"psr.i",   ((valueT) 1) << 14},
461     {"psr.pk",  ((valueT) 1) << 15},
462     /* 16: reserved */
463     {"psr.dt",  ((valueT) 1) << 17},
464     {"psr.dfl", ((valueT) 1) << 18},
465     {"psr.dfh", ((valueT) 1) << 19},
466     {"psr.sp",  ((valueT) 1) << 20},
467     {"psr.pp",  ((valueT) 1) << 21},
468     {"psr.di",  ((valueT) 1) << 22},
469     {"psr.si",  ((valueT) 1) << 23},
470     {"psr.db",  ((valueT) 1) << 24},
471     {"psr.lp",  ((valueT) 1) << 25},
472     {"psr.tb",  ((valueT) 1) << 26},
473     {"psr.rt",  ((valueT) 1) << 27},
474     /* 28-31: reserved */
475     /* 32-33: cpl (current privilege level) */
476     {"psr.is",  ((valueT) 1) << 34},
477     {"psr.mc",  ((valueT) 1) << 35},
478     {"psr.it",  ((valueT) 1) << 36},
479     {"psr.id",  ((valueT) 1) << 37},
480     {"psr.da",  ((valueT) 1) << 38},
481     {"psr.dd",  ((valueT) 1) << 39},
482     {"psr.ss",  ((valueT) 1) << 40},
483     /* 41-42: ri (restart instruction) */
484     {"psr.ed",  ((valueT) 1) << 43},
485     {"psr.bn",  ((valueT) 1) << 44},
486   };
487
488 /* indirect register-sets/memory:  */
489
490 static const struct
491   {
492     const char *name;
493     int regnum;
494   }
495 indirect_reg[] =
496   {
497     { "CPUID",  IND_CPUID },
498     { "cpuid",  IND_CPUID },
499     { "dbr",    IND_DBR },
500     { "dtr",    IND_DTR },
501     { "itr",    IND_ITR },
502     { "ibr",    IND_IBR },
503     { "msr",    IND_MSR },
504     { "pkr",    IND_PKR },
505     { "pmc",    IND_PMC },
506     { "pmd",    IND_PMD },
507     { "rr",     IND_RR },
508   };
509
510 /* Pseudo functions used to indicate relocation types (these functions
511    start with an at sign (@).  */
512 static struct
513   {
514     const char *name;
515     enum pseudo_type
516       {
517         PSEUDO_FUNC_NONE,
518         PSEUDO_FUNC_RELOC,
519         PSEUDO_FUNC_CONST,
520         PSEUDO_FUNC_REG,
521         PSEUDO_FUNC_FLOAT
522       }
523     type;
524     union
525       {
526         unsigned long ival;
527         symbolS *sym;
528       }
529     u;
530   }
531 pseudo_func[] =
532   {
533     /* reloc pseudo functions (these must come first!):  */
534     { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
535     { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
536     { "fptr",   PSEUDO_FUNC_RELOC, { 0 } },
537     { "gprel",  PSEUDO_FUNC_RELOC, { 0 } },
538     { "ltoff",  PSEUDO_FUNC_RELOC, { 0 } },
539     { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
540     { "pcrel",  PSEUDO_FUNC_RELOC, { 0 } },
541     { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
542     { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
543     { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
544     { "tprel",  PSEUDO_FUNC_RELOC, { 0 } },
545     { "ltv",    PSEUDO_FUNC_RELOC, { 0 } },
546     { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
547     { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
548     { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
549     { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
550     { "iplt",   PSEUDO_FUNC_RELOC, { 0 } },
551
552     /* mbtype4 constants:  */
553     { "alt",    PSEUDO_FUNC_CONST, { 0xa } },
554     { "brcst",  PSEUDO_FUNC_CONST, { 0x0 } },
555     { "mix",    PSEUDO_FUNC_CONST, { 0x8 } },
556     { "rev",    PSEUDO_FUNC_CONST, { 0xb } },
557     { "shuf",   PSEUDO_FUNC_CONST, { 0x9 } },
558
559     /* fclass constants:  */
560     { "nat",    PSEUDO_FUNC_CONST, { 0x100 } },
561     { "qnan",   PSEUDO_FUNC_CONST, { 0x080 } },
562     { "snan",   PSEUDO_FUNC_CONST, { 0x040 } },
563     { "pos",    PSEUDO_FUNC_CONST, { 0x001 } },
564     { "neg",    PSEUDO_FUNC_CONST, { 0x002 } },
565     { "zero",   PSEUDO_FUNC_CONST, { 0x004 } },
566     { "unorm",  PSEUDO_FUNC_CONST, { 0x008 } },
567     { "norm",   PSEUDO_FUNC_CONST, { 0x010 } },
568     { "inf",    PSEUDO_FUNC_CONST, { 0x020 } },
569
570     { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
571
572     /* hint constants: */
573     { "pause",  PSEUDO_FUNC_CONST, { 0x0 } },
574
575     /* unwind-related constants:  */
576     { "svr4",   PSEUDO_FUNC_CONST,      { ELFOSABI_NONE } },
577     { "hpux",   PSEUDO_FUNC_CONST,      { ELFOSABI_HPUX } },
578     { "nt",     PSEUDO_FUNC_CONST,      { 2 } },                /* conflicts w/ELFOSABI_NETBSD */
579     { "linux",  PSEUDO_FUNC_CONST,      { ELFOSABI_LINUX } },
580     { "freebsd", PSEUDO_FUNC_CONST,     { ELFOSABI_FREEBSD } },
581     { "openvms", PSEUDO_FUNC_CONST,     { ELFOSABI_OPENVMS } },
582     { "nsk",    PSEUDO_FUNC_CONST,      { ELFOSABI_NSK } },
583
584     /* unwind-related registers:  */
585     { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
586   };
587
588 /* 41-bit nop opcodes (one per unit):  */
589 static const bfd_vma nop[IA64_NUM_UNITS] =
590   {
591     0x0000000000LL,     /* NIL => break 0 */
592     0x0008000000LL,     /* I-unit nop */
593     0x0008000000LL,     /* M-unit nop */
594     0x4000000000LL,     /* B-unit nop */
595     0x0008000000LL,     /* F-unit nop */
596     0x0008000000LL,     /* L-"unit" nop */
597     0x0008000000LL,     /* X-unit nop */
598   };
599
600 /* Can't be `const' as it's passed to input routines (which have the
601    habit of setting temporary sentinels.  */
602 static char special_section_name[][20] =
603   {
604     {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
605     {".IA_64.unwind"}, {".IA_64.unwind_info"},
606     {".init_array"}, {".fini_array"}
607   };
608
609 /* The best template for a particular sequence of up to three
610    instructions:  */
611 #define N       IA64_NUM_TYPES
612 static unsigned char best_template[N][N][N];
613 #undef N
614
615 /* Resource dependencies currently in effect */
616 static struct rsrc {
617   int depind;                       /* dependency index */
618   const struct ia64_dependency *dependency; /* actual dependency */
619   unsigned specific:1,              /* is this a specific bit/regno? */
620     link_to_qp_branch:1;           /* will a branch on the same QP clear it?*/
621   int index;                        /* specific regno/bit within dependency */
622   int note;                         /* optional qualifying note (0 if none) */
623 #define STATE_NONE 0
624 #define STATE_STOP 1
625 #define STATE_SRLZ 2
626   int insn_srlz;                    /* current insn serialization state */
627   int data_srlz;                    /* current data serialization state */
628   int qp_regno;                     /* qualifying predicate for this usage */
629   char *file;                       /* what file marked this dependency */
630   unsigned int line;                /* what line marked this dependency */
631   struct mem_offset mem_offset;     /* optional memory offset hint */
632   enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
633   int path;                         /* corresponding code entry index */
634 } *regdeps = NULL;
635 static int regdepslen = 0;
636 static int regdepstotlen = 0;
637 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
638 static const char *dv_sem[] = { "none", "implied", "impliedf",
639                                 "data", "instr", "specific", "stop", "other" };
640 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
641
642 /* Current state of PR mutexation */
643 static struct qpmutex {
644   valueT prmask;
645   int path;
646 } *qp_mutexes = NULL;          /* QP mutex bitmasks */
647 static int qp_mutexeslen = 0;
648 static int qp_mutexestotlen = 0;
649 static valueT qp_safe_across_calls = 0;
650
651 /* Current state of PR implications */
652 static struct qp_imply {
653   unsigned p1:6;
654   unsigned p2:6;
655   unsigned p2_branched:1;
656   int path;
657 } *qp_implies = NULL;
658 static int qp_implieslen = 0;
659 static int qp_impliestotlen = 0;
660
661 /* Keep track of static GR values so that indirect register usage can
662    sometimes be tracked.  */
663 static struct gr {
664   unsigned known:1;
665   int path;
666   valueT value;
667 } gr_values[128] = {
668   {
669     1,
670 #ifdef INT_MAX
671     INT_MAX,
672 #else
673     (((1 << (8 * sizeof(gr_values->path) - 2)) - 1) << 1) + 1,
674 #endif
675     0
676   }
677 };
678
679 /* Remember the alignment frag.  */
680 static fragS *align_frag;
681
682 /* These are the routines required to output the various types of
683    unwind records.  */
684
685 /* A slot_number is a frag address plus the slot index (0-2).  We use the
686    frag address here so that if there is a section switch in the middle of
687    a function, then instructions emitted to a different section are not
688    counted.  Since there may be more than one frag for a function, this
689    means we also need to keep track of which frag this address belongs to
690    so we can compute inter-frag distances.  This also nicely solves the
691    problem with nops emitted for align directives, which can't easily be
692    counted, but can easily be derived from frag sizes.  */
693
694 typedef struct unw_rec_list {
695   unwind_record r;
696   unsigned long slot_number;
697   fragS *slot_frag;
698   struct unw_rec_list *next;
699 } unw_rec_list;
700
701 #define SLOT_NUM_NOT_SET        (unsigned)-1
702
703 /* Linked list of saved prologue counts.  A very poor
704    implementation of a map from label numbers to prologue counts.  */
705 typedef struct label_prologue_count
706 {
707   struct label_prologue_count *next;
708   unsigned long label_number;
709   unsigned int prologue_count;
710 } label_prologue_count;
711
712 static struct
713 {
714   /* Maintain a list of unwind entries for the current function.  */
715   unw_rec_list *list;
716   unw_rec_list *tail;
717
718   /* Any unwind entires that should be attached to the current slot
719      that an insn is being constructed for.  */
720   unw_rec_list *current_entry;
721
722   /* These are used to create the unwind table entry for this function.  */
723   symbolS *proc_start;
724   symbolS *info;                /* pointer to unwind info */
725   symbolS *personality_routine;
726   segT saved_text_seg;
727   subsegT saved_text_subseg;
728   unsigned int force_unwind_entry : 1;  /* force generation of unwind entry? */
729
730   /* TRUE if processing unwind directives in a prologue region.  */
731   unsigned int prologue : 1;
732   unsigned int prologue_mask : 4;
733   unsigned int body : 1;
734   unsigned int insn : 1;
735   unsigned int prologue_count;  /* number of .prologues seen so far */
736   /* Prologue counts at previous .label_state directives.  */
737   struct label_prologue_count * saved_prologue_counts;
738 } unwind;
739
740 /* The input value is a negated offset from psp, and specifies an address
741    psp - offset.  The encoded value is psp + 16 - (4 * offset).  Thus we
742    must add 16 and divide by 4 to get the encoded value.  */
743
744 #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4)
745
746 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
747
748 /* Forward declarations:  */
749 static void set_section PARAMS ((char *name));
750 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
751                                           unsigned int, unsigned int));
752 static void dot_align (int);
753 static void dot_radix PARAMS ((int));
754 static void dot_special_section PARAMS ((int));
755 static void dot_proc PARAMS ((int));
756 static void dot_fframe PARAMS ((int));
757 static void dot_vframe PARAMS ((int));
758 static void dot_vframesp PARAMS ((int));
759 static void dot_vframepsp PARAMS ((int));
760 static void dot_save PARAMS ((int));
761 static void dot_restore PARAMS ((int));
762 static void dot_restorereg PARAMS ((int));
763 static void dot_restorereg_p PARAMS ((int));
764 static void dot_handlerdata  PARAMS ((int));
765 static void dot_unwentry PARAMS ((int));
766 static void dot_altrp PARAMS ((int));
767 static void dot_savemem PARAMS ((int));
768 static void dot_saveg PARAMS ((int));
769 static void dot_savef PARAMS ((int));
770 static void dot_saveb PARAMS ((int));
771 static void dot_savegf PARAMS ((int));
772 static void dot_spill PARAMS ((int));
773 static void dot_spillreg PARAMS ((int));
774 static void dot_spillmem PARAMS ((int));
775 static void dot_spillreg_p PARAMS ((int));
776 static void dot_spillmem_p PARAMS ((int));
777 static void dot_label_state PARAMS ((int));
778 static void dot_copy_state PARAMS ((int));
779 static void dot_unwabi PARAMS ((int));
780 static void dot_personality PARAMS ((int));
781 static void dot_body PARAMS ((int));
782 static void dot_prologue PARAMS ((int));
783 static void dot_endp PARAMS ((int));
784 static void dot_template PARAMS ((int));
785 static void dot_regstk PARAMS ((int));
786 static void dot_rot PARAMS ((int));
787 static void dot_byteorder PARAMS ((int));
788 static void dot_psr PARAMS ((int));
789 static void dot_alias PARAMS ((int));
790 static void dot_ln PARAMS ((int));
791 static void cross_section PARAMS ((int ref, void (*cons) PARAMS((int)), int ua));
792 static void dot_xdata PARAMS ((int));
793 static void stmt_float_cons PARAMS ((int));
794 static void stmt_cons_ua PARAMS ((int));
795 static void dot_xfloat_cons PARAMS ((int));
796 static void dot_xstringer PARAMS ((int));
797 static void dot_xdata_ua PARAMS ((int));
798 static void dot_xfloat_cons_ua PARAMS ((int));
799 static void print_prmask PARAMS ((valueT mask));
800 static void dot_pred_rel PARAMS ((int));
801 static void dot_reg_val PARAMS ((int));
802 static void dot_serialize PARAMS ((int));
803 static void dot_dv_mode PARAMS ((int));
804 static void dot_entry PARAMS ((int));
805 static void dot_mem_offset PARAMS ((int));
806 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
807 static symbolS *declare_register PARAMS ((const char *name, int regnum));
808 static void declare_register_set PARAMS ((const char *, int, int));
809 static unsigned int operand_width PARAMS ((enum ia64_opnd));
810 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
811                                                         int index,
812                                                         expressionS *e));
813 static int parse_operand PARAMS ((expressionS *e));
814 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
815 static void build_insn PARAMS ((struct slot *, bfd_vma *));
816 static void emit_one_bundle PARAMS ((void));
817 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
818 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
819                                                                   bfd_reloc_code_real_type r_type));
820 static void insn_group_break PARAMS ((int, int, int));
821 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
822                                    struct rsrc *, int depind, int path));
823 static void add_qp_mutex PARAMS((valueT mask));
824 static void add_qp_imply PARAMS((int p1, int p2));
825 static void clear_qp_branch_flag PARAMS((valueT mask));
826 static void clear_qp_mutex PARAMS((valueT mask));
827 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
828 static int has_suffix_p PARAMS((const char *, const char *));
829 static void clear_register_values PARAMS ((void));
830 static void print_dependency PARAMS ((const char *action, int depind));
831 static void instruction_serialization PARAMS ((void));
832 static void data_serialization PARAMS ((void));
833 static void remove_marked_resource PARAMS ((struct rsrc *));
834 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
835 static int is_taken_branch PARAMS ((struct ia64_opcode *));
836 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
837 static int depends_on PARAMS ((int, struct ia64_opcode *));
838 static int specify_resource PARAMS ((const struct ia64_dependency *,
839                                      struct ia64_opcode *, int, struct rsrc [], int, int));
840 static int check_dv PARAMS((struct ia64_opcode *idesc));
841 static void check_dependencies PARAMS((struct ia64_opcode *));
842 static void mark_resources PARAMS((struct ia64_opcode *));
843 static void update_dependencies PARAMS((struct ia64_opcode *));
844 static void note_register_values PARAMS((struct ia64_opcode *));
845 static int qp_mutex PARAMS ((int, int, int));
846 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
847 static void output_vbyte_mem PARAMS ((int, char *, char *));
848 static void count_output PARAMS ((int, char *, char *));
849 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
850 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
851 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
852 static void output_P1_format PARAMS ((vbyte_func, int));
853 static void output_P2_format PARAMS ((vbyte_func, int, int));
854 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
855 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
856 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
857 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
858 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
859 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
860 static void output_P9_format PARAMS ((vbyte_func, int, int));
861 static void output_P10_format PARAMS ((vbyte_func, int, int));
862 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
863 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
864 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
865 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
866 static char format_ab_reg PARAMS ((int, int));
867 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
868                                       unsigned long));
869 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
870 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
871                                       unsigned long));
872 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
873 static unw_rec_list *output_endp PARAMS ((void));
874 static unw_rec_list *output_prologue PARAMS ((void));
875 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
876 static unw_rec_list *output_body PARAMS ((void));
877 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
878 static unw_rec_list *output_mem_stack_v PARAMS ((void));
879 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
880 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
881 static unw_rec_list *output_rp_when PARAMS ((void));
882 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
883 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
884 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
885 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
886 static unw_rec_list *output_pfs_when PARAMS ((void));
887 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
888 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
889 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
890 static unw_rec_list *output_preds_when PARAMS ((void));
891 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
892 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
893 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
894 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
895 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
896 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
897 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
898 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
899 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
900 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
901 static unw_rec_list *output_unat_when PARAMS ((void));
902 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
903 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
904 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
905 static unw_rec_list *output_lc_when PARAMS ((void));
906 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
907 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
908 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
909 static unw_rec_list *output_fpsr_when PARAMS ((void));
910 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
911 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
912 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
913 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
914 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
915 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
916 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
917 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
918 static unw_rec_list *output_bsp_when PARAMS ((void));
919 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
920 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
921 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
922 static unw_rec_list *output_bspstore_when PARAMS ((void));
923 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
924 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
925 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
926 static unw_rec_list *output_rnat_when PARAMS ((void));
927 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
928 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
929 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
930 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
931 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
932 static unw_rec_list *output_label_state PARAMS ((unsigned long));
933 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
934 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
935 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
936 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
937                                                     unsigned int));
938 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
939                                                    unsigned int));
940 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
941                                                unsigned int));
942 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
943                                                  unsigned int, unsigned int));
944 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
945 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
946 static int calc_record_size PARAMS ((unw_rec_list *));
947 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
948 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
949                                          unsigned long, fragS *,
950                                          int));
951 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
952 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
953 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
954 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
955 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
956 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
957 static void free_saved_prologue_counts PARAMS ((void));
958
959 /* Determine if application register REGNUM resides only in the integer
960    unit (as opposed to the memory unit).  */
961 static int
962 ar_is_only_in_integer_unit (int reg)
963 {
964   reg -= REG_AR;
965   return reg >= 64 && reg <= 111;
966 }
967
968 /* Determine if application register REGNUM resides only in the memory 
969    unit (as opposed to the integer unit).  */
970 static int
971 ar_is_only_in_memory_unit (int reg)
972 {
973   reg -= REG_AR;
974   return reg >= 0 && reg <= 47;
975 }
976
977 /* Switch to section NAME and create section if necessary.  It's
978    rather ugly that we have to manipulate input_line_pointer but I
979    don't see any other way to accomplish the same thing without
980    changing obj-elf.c (which may be the Right Thing, in the end).  */
981 static void
982 set_section (name)
983      char *name;
984 {
985   char *saved_input_line_pointer;
986
987   saved_input_line_pointer = input_line_pointer;
988   input_line_pointer = name;
989   obj_elf_section (0);
990   input_line_pointer = saved_input_line_pointer;
991 }
992
993 /* Map 's' to SHF_IA_64_SHORT.  */
994
995 int
996 ia64_elf_section_letter (letter, ptr_msg)
997      int letter;
998      char **ptr_msg;
999 {
1000   if (letter == 's')
1001     return SHF_IA_64_SHORT;
1002   else if (letter == 'o')
1003     return SHF_LINK_ORDER;
1004
1005   *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
1006   return -1;
1007 }
1008
1009 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA.  */
1010
1011 flagword
1012 ia64_elf_section_flags (flags, attr, type)
1013      flagword flags;
1014      int attr, type ATTRIBUTE_UNUSED;
1015 {
1016   if (attr & SHF_IA_64_SHORT)
1017     flags |= SEC_SMALL_DATA;
1018   return flags;
1019 }
1020
1021 int
1022 ia64_elf_section_type (str, len)
1023      const char *str;
1024      size_t len;
1025 {
1026 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
1027
1028   if (STREQ (ELF_STRING_ia64_unwind_info))
1029     return SHT_PROGBITS;
1030
1031   if (STREQ (ELF_STRING_ia64_unwind_info_once))
1032     return SHT_PROGBITS;
1033
1034   if (STREQ (ELF_STRING_ia64_unwind))
1035     return SHT_IA_64_UNWIND;
1036
1037   if (STREQ (ELF_STRING_ia64_unwind_once))
1038     return SHT_IA_64_UNWIND;
1039
1040   if (STREQ ("unwind"))
1041     return SHT_IA_64_UNWIND;
1042
1043   return -1;
1044 #undef STREQ
1045 }
1046
1047 static unsigned int
1048 set_regstack (ins, locs, outs, rots)
1049      unsigned int ins, locs, outs, rots;
1050 {
1051   /* Size of frame.  */
1052   unsigned int sof;
1053
1054   sof = ins + locs + outs;
1055   if (sof > 96)
1056     {
1057       as_bad ("Size of frame exceeds maximum of 96 registers");
1058       return 0;
1059     }
1060   if (rots > sof)
1061     {
1062       as_warn ("Size of rotating registers exceeds frame size");
1063       return 0;
1064     }
1065   md.in.base = REG_GR + 32;
1066   md.loc.base = md.in.base + ins;
1067   md.out.base = md.loc.base + locs;
1068
1069   md.in.num_regs  = ins;
1070   md.loc.num_regs = locs;
1071   md.out.num_regs = outs;
1072   md.rot.num_regs = rots;
1073   return sof;
1074 }
1075
1076 void
1077 ia64_flush_insns ()
1078 {
1079   struct label_fix *lfix;
1080   segT saved_seg;
1081   subsegT saved_subseg;
1082   unw_rec_list *ptr;
1083
1084   if (!md.last_text_seg)
1085     return;
1086
1087   saved_seg = now_seg;
1088   saved_subseg = now_subseg;
1089
1090   subseg_set (md.last_text_seg, 0);
1091
1092   while (md.num_slots_in_use > 0)
1093     emit_one_bundle ();         /* force out queued instructions */
1094
1095   /* In case there are labels following the last instruction, resolve
1096      those now:  */
1097   for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1098     {
1099       S_SET_VALUE (lfix->sym, frag_now_fix ());
1100       symbol_set_frag (lfix->sym, frag_now);
1101     }
1102   CURR_SLOT.label_fixups = 0;
1103   for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1104     {
1105       S_SET_VALUE (lfix->sym, frag_now_fix ());
1106       symbol_set_frag (lfix->sym, frag_now);
1107     }
1108   CURR_SLOT.tag_fixups = 0;
1109
1110   /* In case there are unwind directives following the last instruction,
1111      resolve those now.  We only handle prologue, body, and endp directives
1112      here.  Give an error for others.  */
1113   for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1114     {
1115       switch (ptr->r.type)
1116         {
1117         case prologue:
1118         case prologue_gr:
1119         case body:
1120         case endp:
1121           ptr->slot_number = (unsigned long) frag_more (0);
1122           ptr->slot_frag = frag_now;
1123           break;
1124
1125           /* Allow any record which doesn't have a "t" field (i.e.,
1126              doesn't relate to a particular instruction).  */
1127         case unwabi:
1128         case br_gr:
1129         case copy_state:
1130         case fr_mem:
1131         case frgr_mem:
1132         case gr_gr:
1133         case gr_mem:
1134         case label_state:
1135         case rp_br:
1136         case spill_base:
1137         case spill_mask:
1138           /* nothing */
1139           break;
1140
1141         default:
1142           as_bad (_("Unwind directive not followed by an instruction."));
1143           break;
1144         }
1145     }
1146   unwind.current_entry = NULL;
1147
1148   subseg_set (saved_seg, saved_subseg);
1149
1150   if (md.qp.X_op == O_register)
1151     as_bad ("qualifying predicate not followed by instruction");
1152 }
1153
1154 static void
1155 ia64_do_align (int nbytes)
1156 {
1157   char *saved_input_line_pointer = input_line_pointer;
1158
1159   input_line_pointer = "";
1160   s_align_bytes (nbytes);
1161   input_line_pointer = saved_input_line_pointer;
1162 }
1163
1164 void
1165 ia64_cons_align (nbytes)
1166      int nbytes;
1167 {
1168   if (md.auto_align)
1169     {
1170       char *saved_input_line_pointer = input_line_pointer;
1171       input_line_pointer = "";
1172       s_align_bytes (nbytes);
1173       input_line_pointer = saved_input_line_pointer;
1174     }
1175 }
1176
1177 /* Output COUNT bytes to a memory location.  */
1178 static char *vbyte_mem_ptr = NULL;
1179
1180 void
1181 output_vbyte_mem (count, ptr, comment)
1182      int count;
1183      char *ptr;
1184      char *comment ATTRIBUTE_UNUSED;
1185 {
1186   int x;
1187   if (vbyte_mem_ptr == NULL)
1188     abort ();
1189
1190   if (count == 0)
1191     return;
1192   for (x = 0; x < count; x++)
1193     *(vbyte_mem_ptr++) = ptr[x];
1194 }
1195
1196 /* Count the number of bytes required for records.  */
1197 static int vbyte_count = 0;
1198 void
1199 count_output (count, ptr, comment)
1200      int count;
1201      char *ptr ATTRIBUTE_UNUSED;
1202      char *comment ATTRIBUTE_UNUSED;
1203 {
1204   vbyte_count += count;
1205 }
1206
1207 static void
1208 output_R1_format (f, rtype, rlen)
1209      vbyte_func f;
1210      unw_record_type rtype;
1211      int rlen;
1212 {
1213   int r = 0;
1214   char byte;
1215   if (rlen > 0x1f)
1216     {
1217       output_R3_format (f, rtype, rlen);
1218       return;
1219     }
1220
1221   if (rtype == body)
1222     r = 1;
1223   else if (rtype != prologue)
1224     as_bad ("record type is not valid");
1225
1226   byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1227   (*f) (1, &byte, NULL);
1228 }
1229
1230 static void
1231 output_R2_format (f, mask, grsave, rlen)
1232      vbyte_func f;
1233      int mask, grsave;
1234      unsigned long rlen;
1235 {
1236   char bytes[20];
1237   int count = 2;
1238   mask = (mask & 0x0f);
1239   grsave = (grsave & 0x7f);
1240
1241   bytes[0] = (UNW_R2 | (mask >> 1));
1242   bytes[1] = (((mask & 0x01) << 7) | grsave);
1243   count += output_leb128 (bytes + 2, rlen, 0);
1244   (*f) (count, bytes, NULL);
1245 }
1246
1247 static void
1248 output_R3_format (f, rtype, rlen)
1249      vbyte_func f;
1250      unw_record_type rtype;
1251      unsigned long rlen;
1252 {
1253   int r = 0, count;
1254   char bytes[20];
1255   if (rlen <= 0x1f)
1256     {
1257       output_R1_format (f, rtype, rlen);
1258       return;
1259     }
1260
1261   if (rtype == body)
1262     r = 1;
1263   else if (rtype != prologue)
1264     as_bad ("record type is not valid");
1265   bytes[0] = (UNW_R3 | r);
1266   count = output_leb128 (bytes + 1, rlen, 0);
1267   (*f) (count + 1, bytes, NULL);
1268 }
1269
1270 static void
1271 output_P1_format (f, brmask)
1272      vbyte_func f;
1273      int brmask;
1274 {
1275   char byte;
1276   byte = UNW_P1 | (brmask & 0x1f);
1277   (*f) (1, &byte, NULL);
1278 }
1279
1280 static void
1281 output_P2_format (f, brmask, gr)
1282      vbyte_func f;
1283      int brmask;
1284      int gr;
1285 {
1286   char bytes[2];
1287   brmask = (brmask & 0x1f);
1288   bytes[0] = UNW_P2 | (brmask >> 1);
1289   bytes[1] = (((brmask & 1) << 7) | gr);
1290   (*f) (2, bytes, NULL);
1291 }
1292
1293 static void
1294 output_P3_format (f, rtype, reg)
1295      vbyte_func f;
1296      unw_record_type rtype;
1297      int reg;
1298 {
1299   char bytes[2];
1300   int r = 0;
1301   reg = (reg & 0x7f);
1302   switch (rtype)
1303     {
1304     case psp_gr:
1305       r = 0;
1306       break;
1307     case rp_gr:
1308       r = 1;
1309       break;
1310     case pfs_gr:
1311       r = 2;
1312       break;
1313     case preds_gr:
1314       r = 3;
1315       break;
1316     case unat_gr:
1317       r = 4;
1318       break;
1319     case lc_gr:
1320       r = 5;
1321       break;
1322     case rp_br:
1323       r = 6;
1324       break;
1325     case rnat_gr:
1326       r = 7;
1327       break;
1328     case bsp_gr:
1329       r = 8;
1330       break;
1331     case bspstore_gr:
1332       r = 9;
1333       break;
1334     case fpsr_gr:
1335       r = 10;
1336       break;
1337     case priunat_gr:
1338       r = 11;
1339       break;
1340     default:
1341       as_bad ("Invalid record type for P3 format.");
1342     }
1343   bytes[0] = (UNW_P3 | (r >> 1));
1344   bytes[1] = (((r & 1) << 7) | reg);
1345   (*f) (2, bytes, NULL);
1346 }
1347
1348 static void
1349 output_P4_format (f, imask, imask_size)
1350      vbyte_func f;
1351      unsigned char *imask;
1352      unsigned long imask_size;
1353 {
1354   imask[0] = UNW_P4;
1355   (*f) (imask_size, (char *) imask, NULL);
1356 }
1357
1358 static void
1359 output_P5_format (f, grmask, frmask)
1360      vbyte_func f;
1361      int grmask;
1362      unsigned long frmask;
1363 {
1364   char bytes[4];
1365   grmask = (grmask & 0x0f);
1366
1367   bytes[0] = UNW_P5;
1368   bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1369   bytes[2] = ((frmask & 0x0000ff00) >> 8);
1370   bytes[3] = (frmask & 0x000000ff);
1371   (*f) (4, bytes, NULL);
1372 }
1373
1374 static void
1375 output_P6_format (f, rtype, rmask)
1376      vbyte_func f;
1377      unw_record_type rtype;
1378      int rmask;
1379 {
1380   char byte;
1381   int r = 0;
1382
1383   if (rtype == gr_mem)
1384     r = 1;
1385   else if (rtype != fr_mem)
1386     as_bad ("Invalid record type for format P6");
1387   byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1388   (*f) (1, &byte, NULL);
1389 }
1390
1391 static void
1392 output_P7_format (f, rtype, w1, w2)
1393      vbyte_func f;
1394      unw_record_type rtype;
1395      unsigned long w1;
1396      unsigned long w2;
1397 {
1398   char bytes[20];
1399   int count = 1;
1400   int r = 0;
1401   count += output_leb128 (bytes + 1, w1, 0);
1402   switch (rtype)
1403     {
1404     case mem_stack_f:
1405       r = 0;
1406       count += output_leb128 (bytes + count, w2 >> 4, 0);
1407       break;
1408     case mem_stack_v:
1409       r = 1;
1410       break;
1411     case spill_base:
1412       r = 2;
1413       break;
1414     case psp_sprel:
1415       r = 3;
1416       break;
1417     case rp_when:
1418       r = 4;
1419       break;
1420     case rp_psprel:
1421       r = 5;
1422       break;
1423     case pfs_when:
1424       r = 6;
1425       break;
1426     case pfs_psprel:
1427       r = 7;
1428       break;
1429     case preds_when:
1430       r = 8;
1431       break;
1432     case preds_psprel:
1433       r = 9;
1434       break;
1435     case lc_when:
1436       r = 10;
1437       break;
1438     case lc_psprel:
1439       r = 11;
1440       break;
1441     case unat_when:
1442       r = 12;
1443       break;
1444     case unat_psprel:
1445       r = 13;
1446       break;
1447     case fpsr_when:
1448       r = 14;
1449       break;
1450     case fpsr_psprel:
1451       r = 15;
1452       break;
1453     default:
1454       break;
1455     }
1456   bytes[0] = (UNW_P7 | r);
1457   (*f) (count, bytes, NULL);
1458 }
1459
1460 static void
1461 output_P8_format (f, rtype, t)
1462      vbyte_func f;
1463      unw_record_type rtype;
1464      unsigned long t;
1465 {
1466   char bytes[20];
1467   int r = 0;
1468   int count = 2;
1469   bytes[0] = UNW_P8;
1470   switch (rtype)
1471     {
1472     case rp_sprel:
1473       r = 1;
1474       break;
1475     case pfs_sprel:
1476       r = 2;
1477       break;
1478     case preds_sprel:
1479       r = 3;
1480       break;
1481     case lc_sprel:
1482       r = 4;
1483       break;
1484     case unat_sprel:
1485       r = 5;
1486       break;
1487     case fpsr_sprel:
1488       r = 6;
1489       break;
1490     case bsp_when:
1491       r = 7;
1492       break;
1493     case bsp_psprel:
1494       r = 8;
1495       break;
1496     case bsp_sprel:
1497       r = 9;
1498       break;
1499     case bspstore_when:
1500       r = 10;
1501       break;
1502     case bspstore_psprel:
1503       r = 11;
1504       break;
1505     case bspstore_sprel:
1506       r = 12;
1507       break;
1508     case rnat_when:
1509       r = 13;
1510       break;
1511     case rnat_psprel:
1512       r = 14;
1513       break;
1514     case rnat_sprel:
1515       r = 15;
1516       break;
1517     case priunat_when_gr:
1518       r = 16;
1519       break;
1520     case priunat_psprel:
1521       r = 17;
1522       break;
1523     case priunat_sprel:
1524       r = 18;
1525       break;
1526     case priunat_when_mem:
1527       r = 19;
1528       break;
1529     default:
1530       break;
1531     }
1532   bytes[1] = r;
1533   count += output_leb128 (bytes + 2, t, 0);
1534   (*f) (count, bytes, NULL);
1535 }
1536
1537 static void
1538 output_P9_format (f, grmask, gr)
1539      vbyte_func f;
1540      int grmask;
1541      int gr;
1542 {
1543   char bytes[3];
1544   bytes[0] = UNW_P9;
1545   bytes[1] = (grmask & 0x0f);
1546   bytes[2] = (gr & 0x7f);
1547   (*f) (3, bytes, NULL);
1548 }
1549
1550 static void
1551 output_P10_format (f, abi, context)
1552      vbyte_func f;
1553      int abi;
1554      int context;
1555 {
1556   char bytes[3];
1557   bytes[0] = UNW_P10;
1558   bytes[1] = (abi & 0xff);
1559   bytes[2] = (context & 0xff);
1560   (*f) (3, bytes, NULL);
1561 }
1562
1563 static void
1564 output_B1_format (f, rtype, label)
1565      vbyte_func f;
1566      unw_record_type rtype;
1567      unsigned long label;
1568 {
1569   char byte;
1570   int r = 0;
1571   if (label > 0x1f)
1572     {
1573       output_B4_format (f, rtype, label);
1574       return;
1575     }
1576   if (rtype == copy_state)
1577     r = 1;
1578   else if (rtype != label_state)
1579     as_bad ("Invalid record type for format B1");
1580
1581   byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1582   (*f) (1, &byte, NULL);
1583 }
1584
1585 static void
1586 output_B2_format (f, ecount, t)
1587      vbyte_func f;
1588      unsigned long ecount;
1589      unsigned long t;
1590 {
1591   char bytes[20];
1592   int count = 1;
1593   if (ecount > 0x1f)
1594     {
1595       output_B3_format (f, ecount, t);
1596       return;
1597     }
1598   bytes[0] = (UNW_B2 | (ecount & 0x1f));
1599   count += output_leb128 (bytes + 1, t, 0);
1600   (*f) (count, bytes, NULL);
1601 }
1602
1603 static void
1604 output_B3_format (f, ecount, t)
1605      vbyte_func f;
1606      unsigned long ecount;
1607      unsigned long t;
1608 {
1609   char bytes[20];
1610   int count = 1;
1611   if (ecount <= 0x1f)
1612     {
1613       output_B2_format (f, ecount, t);
1614       return;
1615     }
1616   bytes[0] = UNW_B3;
1617   count += output_leb128 (bytes + 1, t, 0);
1618   count += output_leb128 (bytes + count, ecount, 0);
1619   (*f) (count, bytes, NULL);
1620 }
1621
1622 static void
1623 output_B4_format (f, rtype, label)
1624      vbyte_func f;
1625      unw_record_type rtype;
1626      unsigned long label;
1627 {
1628   char bytes[20];
1629   int r = 0;
1630   int count = 1;
1631   if (label <= 0x1f)
1632     {
1633       output_B1_format (f, rtype, label);
1634       return;
1635     }
1636
1637   if (rtype == copy_state)
1638     r = 1;
1639   else if (rtype != label_state)
1640     as_bad ("Invalid record type for format B1");
1641
1642   bytes[0] = (UNW_B4 | (r << 3));
1643   count += output_leb128 (bytes + 1, label, 0);
1644   (*f) (count, bytes, NULL);
1645 }
1646
1647 static char
1648 format_ab_reg (ab, reg)
1649      int ab;
1650      int reg;
1651 {
1652   int ret;
1653   ab = (ab & 3);
1654   reg = (reg & 0x1f);
1655   ret = (ab << 5) | reg;
1656   return ret;
1657 }
1658
1659 static void
1660 output_X1_format (f, rtype, ab, reg, t, w1)
1661      vbyte_func f;
1662      unw_record_type rtype;
1663      int ab, reg;
1664      unsigned long t;
1665      unsigned long w1;
1666 {
1667   char bytes[20];
1668   int r = 0;
1669   int count = 2;
1670   bytes[0] = UNW_X1;
1671
1672   if (rtype == spill_sprel)
1673     r = 1;
1674   else if (rtype != spill_psprel)
1675     as_bad ("Invalid record type for format X1");
1676   bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1677   count += output_leb128 (bytes + 2, t, 0);
1678   count += output_leb128 (bytes + count, w1, 0);
1679   (*f) (count, bytes, NULL);
1680 }
1681
1682 static void
1683 output_X2_format (f, ab, reg, x, y, treg, t)
1684      vbyte_func f;
1685      int ab, reg;
1686      int x, y, treg;
1687      unsigned long t;
1688 {
1689   char bytes[20];
1690   int count = 3;
1691   bytes[0] = UNW_X2;
1692   bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1693   bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1694   count += output_leb128 (bytes + 3, t, 0);
1695   (*f) (count, bytes, NULL);
1696 }
1697
1698 static void
1699 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1700      vbyte_func f;
1701      unw_record_type rtype;
1702      int qp;
1703      int ab, reg;
1704      unsigned long t;
1705      unsigned long w1;
1706 {
1707   char bytes[20];
1708   int r = 0;
1709   int count = 3;
1710   bytes[0] = UNW_X3;
1711
1712   if (rtype == spill_sprel_p)
1713     r = 1;
1714   else if (rtype != spill_psprel_p)
1715     as_bad ("Invalid record type for format X3");
1716   bytes[1] = ((r << 7) | (qp & 0x3f));
1717   bytes[2] = format_ab_reg (ab, reg);
1718   count += output_leb128 (bytes + 3, t, 0);
1719   count += output_leb128 (bytes + count, w1, 0);
1720   (*f) (count, bytes, NULL);
1721 }
1722
1723 static void
1724 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1725      vbyte_func f;
1726      int qp;
1727      int ab, reg;
1728      int x, y, treg;
1729      unsigned long t;
1730 {
1731   char bytes[20];
1732   int count = 4;
1733   bytes[0] = UNW_X4;
1734   bytes[1] = (qp & 0x3f);
1735   bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1736   bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1737   count += output_leb128 (bytes + 4, t, 0);
1738   (*f) (count, bytes, NULL);
1739 }
1740
1741 /* This function allocates a record list structure, and initializes fields.  */
1742
1743 static unw_rec_list *
1744 alloc_record (unw_record_type t)
1745 {
1746   unw_rec_list *ptr;
1747   ptr = xmalloc (sizeof (*ptr));
1748   ptr->next = NULL;
1749   ptr->slot_number = SLOT_NUM_NOT_SET;
1750   ptr->r.type = t;
1751   return ptr;
1752 }
1753
1754 /* Dummy unwind record used for calculating the length of the last prologue or
1755    body region.  */
1756
1757 static unw_rec_list *
1758 output_endp ()
1759 {
1760   unw_rec_list *ptr = alloc_record (endp);
1761   return ptr;
1762 }
1763
1764 static unw_rec_list *
1765 output_prologue ()
1766 {
1767   unw_rec_list *ptr = alloc_record (prologue);
1768   memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1769   return ptr;
1770 }
1771
1772 static unw_rec_list *
1773 output_prologue_gr (saved_mask, reg)
1774      unsigned int saved_mask;
1775      unsigned int reg;
1776 {
1777   unw_rec_list *ptr = alloc_record (prologue_gr);
1778   memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1779   ptr->r.record.r.grmask = saved_mask;
1780   ptr->r.record.r.grsave = reg;
1781   return ptr;
1782 }
1783
1784 static unw_rec_list *
1785 output_body ()
1786 {
1787   unw_rec_list *ptr = alloc_record (body);
1788   return ptr;
1789 }
1790
1791 static unw_rec_list *
1792 output_mem_stack_f (size)
1793      unsigned int size;
1794 {
1795   unw_rec_list *ptr = alloc_record (mem_stack_f);
1796   ptr->r.record.p.size = size;
1797   return ptr;
1798 }
1799
1800 static unw_rec_list *
1801 output_mem_stack_v ()
1802 {
1803   unw_rec_list *ptr = alloc_record (mem_stack_v);
1804   return ptr;
1805 }
1806
1807 static unw_rec_list *
1808 output_psp_gr (gr)
1809      unsigned int gr;
1810 {
1811   unw_rec_list *ptr = alloc_record (psp_gr);
1812   ptr->r.record.p.gr = gr;
1813   return ptr;
1814 }
1815
1816 static unw_rec_list *
1817 output_psp_sprel (offset)
1818      unsigned int offset;
1819 {
1820   unw_rec_list *ptr = alloc_record (psp_sprel);
1821   ptr->r.record.p.spoff = offset / 4;
1822   return ptr;
1823 }
1824
1825 static unw_rec_list *
1826 output_rp_when ()
1827 {
1828   unw_rec_list *ptr = alloc_record (rp_when);
1829   return ptr;
1830 }
1831
1832 static unw_rec_list *
1833 output_rp_gr (gr)
1834      unsigned int gr;
1835 {
1836   unw_rec_list *ptr = alloc_record (rp_gr);
1837   ptr->r.record.p.gr = gr;
1838   return ptr;
1839 }
1840
1841 static unw_rec_list *
1842 output_rp_br (br)
1843      unsigned int br;
1844 {
1845   unw_rec_list *ptr = alloc_record (rp_br);
1846   ptr->r.record.p.br = br;
1847   return ptr;
1848 }
1849
1850 static unw_rec_list *
1851 output_rp_psprel (offset)
1852      unsigned int offset;
1853 {
1854   unw_rec_list *ptr = alloc_record (rp_psprel);
1855   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1856   return ptr;
1857 }
1858
1859 static unw_rec_list *
1860 output_rp_sprel (offset)
1861      unsigned int offset;
1862 {
1863   unw_rec_list *ptr = alloc_record (rp_sprel);
1864   ptr->r.record.p.spoff = offset / 4;
1865   return ptr;
1866 }
1867
1868 static unw_rec_list *
1869 output_pfs_when ()
1870 {
1871   unw_rec_list *ptr = alloc_record (pfs_when);
1872   return ptr;
1873 }
1874
1875 static unw_rec_list *
1876 output_pfs_gr (gr)
1877      unsigned int gr;
1878 {
1879   unw_rec_list *ptr = alloc_record (pfs_gr);
1880   ptr->r.record.p.gr = gr;
1881   return ptr;
1882 }
1883
1884 static unw_rec_list *
1885 output_pfs_psprel (offset)
1886      unsigned int offset;
1887 {
1888   unw_rec_list *ptr = alloc_record (pfs_psprel);
1889   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1890   return ptr;
1891 }
1892
1893 static unw_rec_list *
1894 output_pfs_sprel (offset)
1895      unsigned int offset;
1896 {
1897   unw_rec_list *ptr = alloc_record (pfs_sprel);
1898   ptr->r.record.p.spoff = offset / 4;
1899   return ptr;
1900 }
1901
1902 static unw_rec_list *
1903 output_preds_when ()
1904 {
1905   unw_rec_list *ptr = alloc_record (preds_when);
1906   return ptr;
1907 }
1908
1909 static unw_rec_list *
1910 output_preds_gr (gr)
1911      unsigned int gr;
1912 {
1913   unw_rec_list *ptr = alloc_record (preds_gr);
1914   ptr->r.record.p.gr = gr;
1915   return ptr;
1916 }
1917
1918 static unw_rec_list *
1919 output_preds_psprel (offset)
1920      unsigned int offset;
1921 {
1922   unw_rec_list *ptr = alloc_record (preds_psprel);
1923   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1924   return ptr;
1925 }
1926
1927 static unw_rec_list *
1928 output_preds_sprel (offset)
1929      unsigned int offset;
1930 {
1931   unw_rec_list *ptr = alloc_record (preds_sprel);
1932   ptr->r.record.p.spoff = offset / 4;
1933   return ptr;
1934 }
1935
1936 static unw_rec_list *
1937 output_fr_mem (mask)
1938      unsigned int mask;
1939 {
1940   unw_rec_list *ptr = alloc_record (fr_mem);
1941   ptr->r.record.p.rmask = mask;
1942   return ptr;
1943 }
1944
1945 static unw_rec_list *
1946 output_frgr_mem (gr_mask, fr_mask)
1947      unsigned int gr_mask;
1948      unsigned int fr_mask;
1949 {
1950   unw_rec_list *ptr = alloc_record (frgr_mem);
1951   ptr->r.record.p.grmask = gr_mask;
1952   ptr->r.record.p.frmask = fr_mask;
1953   return ptr;
1954 }
1955
1956 static unw_rec_list *
1957 output_gr_gr (mask, reg)
1958      unsigned int mask;
1959      unsigned int reg;
1960 {
1961   unw_rec_list *ptr = alloc_record (gr_gr);
1962   ptr->r.record.p.grmask = mask;
1963   ptr->r.record.p.gr = reg;
1964   return ptr;
1965 }
1966
1967 static unw_rec_list *
1968 output_gr_mem (mask)
1969      unsigned int mask;
1970 {
1971   unw_rec_list *ptr = alloc_record (gr_mem);
1972   ptr->r.record.p.rmask = mask;
1973   return ptr;
1974 }
1975
1976 static unw_rec_list *
1977 output_br_mem (unsigned int mask)
1978 {
1979   unw_rec_list *ptr = alloc_record (br_mem);
1980   ptr->r.record.p.brmask = mask;
1981   return ptr;
1982 }
1983
1984 static unw_rec_list *
1985 output_br_gr (save_mask, reg)
1986      unsigned int save_mask;
1987      unsigned int reg;
1988 {
1989   unw_rec_list *ptr = alloc_record (br_gr);
1990   ptr->r.record.p.brmask = save_mask;
1991   ptr->r.record.p.gr = reg;
1992   return ptr;
1993 }
1994
1995 static unw_rec_list *
1996 output_spill_base (offset)
1997      unsigned int offset;
1998 {
1999   unw_rec_list *ptr = alloc_record (spill_base);
2000   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2001   return ptr;
2002 }
2003
2004 static unw_rec_list *
2005 output_unat_when ()
2006 {
2007   unw_rec_list *ptr = alloc_record (unat_when);
2008   return ptr;
2009 }
2010
2011 static unw_rec_list *
2012 output_unat_gr (gr)
2013      unsigned int gr;
2014 {
2015   unw_rec_list *ptr = alloc_record (unat_gr);
2016   ptr->r.record.p.gr = gr;
2017   return ptr;
2018 }
2019
2020 static unw_rec_list *
2021 output_unat_psprel (offset)
2022      unsigned int offset;
2023 {
2024   unw_rec_list *ptr = alloc_record (unat_psprel);
2025   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2026   return ptr;
2027 }
2028
2029 static unw_rec_list *
2030 output_unat_sprel (offset)
2031      unsigned int offset;
2032 {
2033   unw_rec_list *ptr = alloc_record (unat_sprel);
2034   ptr->r.record.p.spoff = offset / 4;
2035   return ptr;
2036 }
2037
2038 static unw_rec_list *
2039 output_lc_when ()
2040 {
2041   unw_rec_list *ptr = alloc_record (lc_when);
2042   return ptr;
2043 }
2044
2045 static unw_rec_list *
2046 output_lc_gr (gr)
2047      unsigned int gr;
2048 {
2049   unw_rec_list *ptr = alloc_record (lc_gr);
2050   ptr->r.record.p.gr = gr;
2051   return ptr;
2052 }
2053
2054 static unw_rec_list *
2055 output_lc_psprel (offset)
2056      unsigned int offset;
2057 {
2058   unw_rec_list *ptr = alloc_record (lc_psprel);
2059   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2060   return ptr;
2061 }
2062
2063 static unw_rec_list *
2064 output_lc_sprel (offset)
2065      unsigned int offset;
2066 {
2067   unw_rec_list *ptr = alloc_record (lc_sprel);
2068   ptr->r.record.p.spoff = offset / 4;
2069   return ptr;
2070 }
2071
2072 static unw_rec_list *
2073 output_fpsr_when ()
2074 {
2075   unw_rec_list *ptr = alloc_record (fpsr_when);
2076   return ptr;
2077 }
2078
2079 static unw_rec_list *
2080 output_fpsr_gr (gr)
2081      unsigned int gr;
2082 {
2083   unw_rec_list *ptr = alloc_record (fpsr_gr);
2084   ptr->r.record.p.gr = gr;
2085   return ptr;
2086 }
2087
2088 static unw_rec_list *
2089 output_fpsr_psprel (offset)
2090      unsigned int offset;
2091 {
2092   unw_rec_list *ptr = alloc_record (fpsr_psprel);
2093   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2094   return ptr;
2095 }
2096
2097 static unw_rec_list *
2098 output_fpsr_sprel (offset)
2099      unsigned int offset;
2100 {
2101   unw_rec_list *ptr = alloc_record (fpsr_sprel);
2102   ptr->r.record.p.spoff = offset / 4;
2103   return ptr;
2104 }
2105
2106 static unw_rec_list *
2107 output_priunat_when_gr ()
2108 {
2109   unw_rec_list *ptr = alloc_record (priunat_when_gr);
2110   return ptr;
2111 }
2112
2113 static unw_rec_list *
2114 output_priunat_when_mem ()
2115 {
2116   unw_rec_list *ptr = alloc_record (priunat_when_mem);
2117   return ptr;
2118 }
2119
2120 static unw_rec_list *
2121 output_priunat_gr (gr)
2122      unsigned int gr;
2123 {
2124   unw_rec_list *ptr = alloc_record (priunat_gr);
2125   ptr->r.record.p.gr = gr;
2126   return ptr;
2127 }
2128
2129 static unw_rec_list *
2130 output_priunat_psprel (offset)
2131      unsigned int offset;
2132 {
2133   unw_rec_list *ptr = alloc_record (priunat_psprel);
2134   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2135   return ptr;
2136 }
2137
2138 static unw_rec_list *
2139 output_priunat_sprel (offset)
2140      unsigned int offset;
2141 {
2142   unw_rec_list *ptr = alloc_record (priunat_sprel);
2143   ptr->r.record.p.spoff = offset / 4;
2144   return ptr;
2145 }
2146
2147 static unw_rec_list *
2148 output_bsp_when ()
2149 {
2150   unw_rec_list *ptr = alloc_record (bsp_when);
2151   return ptr;
2152 }
2153
2154 static unw_rec_list *
2155 output_bsp_gr (gr)
2156      unsigned int gr;
2157 {
2158   unw_rec_list *ptr = alloc_record (bsp_gr);
2159   ptr->r.record.p.gr = gr;
2160   return ptr;
2161 }
2162
2163 static unw_rec_list *
2164 output_bsp_psprel (offset)
2165      unsigned int offset;
2166 {
2167   unw_rec_list *ptr = alloc_record (bsp_psprel);
2168   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2169   return ptr;
2170 }
2171
2172 static unw_rec_list *
2173 output_bsp_sprel (offset)
2174      unsigned int offset;
2175 {
2176   unw_rec_list *ptr = alloc_record (bsp_sprel);
2177   ptr->r.record.p.spoff = offset / 4;
2178   return ptr;
2179 }
2180
2181 static unw_rec_list *
2182 output_bspstore_when ()
2183 {
2184   unw_rec_list *ptr = alloc_record (bspstore_when);
2185   return ptr;
2186 }
2187
2188 static unw_rec_list *
2189 output_bspstore_gr (gr)
2190      unsigned int gr;
2191 {
2192   unw_rec_list *ptr = alloc_record (bspstore_gr);
2193   ptr->r.record.p.gr = gr;
2194   return ptr;
2195 }
2196
2197 static unw_rec_list *
2198 output_bspstore_psprel (offset)
2199      unsigned int offset;
2200 {
2201   unw_rec_list *ptr = alloc_record (bspstore_psprel);
2202   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2203   return ptr;
2204 }
2205
2206 static unw_rec_list *
2207 output_bspstore_sprel (offset)
2208      unsigned int offset;
2209 {
2210   unw_rec_list *ptr = alloc_record (bspstore_sprel);
2211   ptr->r.record.p.spoff = offset / 4;
2212   return ptr;
2213 }
2214
2215 static unw_rec_list *
2216 output_rnat_when ()
2217 {
2218   unw_rec_list *ptr = alloc_record (rnat_when);
2219   return ptr;
2220 }
2221
2222 static unw_rec_list *
2223 output_rnat_gr (gr)
2224      unsigned int gr;
2225 {
2226   unw_rec_list *ptr = alloc_record (rnat_gr);
2227   ptr->r.record.p.gr = gr;
2228   return ptr;
2229 }
2230
2231 static unw_rec_list *
2232 output_rnat_psprel (offset)
2233      unsigned int offset;
2234 {
2235   unw_rec_list *ptr = alloc_record (rnat_psprel);
2236   ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2237   return ptr;
2238 }
2239
2240 static unw_rec_list *
2241 output_rnat_sprel (offset)
2242      unsigned int offset;
2243 {
2244   unw_rec_list *ptr = alloc_record (rnat_sprel);
2245   ptr->r.record.p.spoff = offset / 4;
2246   return ptr;
2247 }
2248
2249 static unw_rec_list *
2250 output_unwabi (abi, context)
2251      unsigned long abi;
2252      unsigned long context;
2253 {
2254   unw_rec_list *ptr = alloc_record (unwabi);
2255   ptr->r.record.p.abi = abi;
2256   ptr->r.record.p.context = context;
2257   return ptr;
2258 }
2259
2260 static unw_rec_list *
2261 output_epilogue (unsigned long ecount)
2262 {
2263   unw_rec_list *ptr = alloc_record (epilogue);
2264   ptr->r.record.b.ecount = ecount;
2265   return ptr;
2266 }
2267
2268 static unw_rec_list *
2269 output_label_state (unsigned long label)
2270 {
2271   unw_rec_list *ptr = alloc_record (label_state);
2272   ptr->r.record.b.label = label;
2273   return ptr;
2274 }
2275
2276 static unw_rec_list *
2277 output_copy_state (unsigned long label)
2278 {
2279   unw_rec_list *ptr = alloc_record (copy_state);
2280   ptr->r.record.b.label = label;
2281   return ptr;
2282 }
2283
2284 static unw_rec_list *
2285 output_spill_psprel (ab, reg, offset)
2286      unsigned int ab;
2287      unsigned int reg;
2288      unsigned int offset;
2289 {
2290   unw_rec_list *ptr = alloc_record (spill_psprel);
2291   ptr->r.record.x.ab = ab;
2292   ptr->r.record.x.reg = reg;
2293   ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2294   return ptr;
2295 }
2296
2297 static unw_rec_list *
2298 output_spill_sprel (ab, reg, offset)
2299      unsigned int ab;
2300      unsigned int reg;
2301      unsigned int offset;
2302 {
2303   unw_rec_list *ptr = alloc_record (spill_sprel);
2304   ptr->r.record.x.ab = ab;
2305   ptr->r.record.x.reg = reg;
2306   ptr->r.record.x.spoff = offset / 4;
2307   return ptr;
2308 }
2309
2310 static unw_rec_list *
2311 output_spill_psprel_p (ab, reg, offset, predicate)
2312      unsigned int ab;
2313      unsigned int reg;
2314      unsigned int offset;
2315      unsigned int predicate;
2316 {
2317   unw_rec_list *ptr = alloc_record (spill_psprel_p);
2318   ptr->r.record.x.ab = ab;
2319   ptr->r.record.x.reg = reg;
2320   ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2321   ptr->r.record.x.qp = predicate;
2322   return ptr;
2323 }
2324
2325 static unw_rec_list *
2326 output_spill_sprel_p (ab, reg, offset, predicate)
2327      unsigned int ab;
2328      unsigned int reg;
2329      unsigned int offset;
2330      unsigned int predicate;
2331 {
2332   unw_rec_list *ptr = alloc_record (spill_sprel_p);
2333   ptr->r.record.x.ab = ab;
2334   ptr->r.record.x.reg = reg;
2335   ptr->r.record.x.spoff = offset / 4;
2336   ptr->r.record.x.qp = predicate;
2337   return ptr;
2338 }
2339
2340 static unw_rec_list *
2341 output_spill_reg (ab, reg, targ_reg, xy)
2342      unsigned int ab;
2343      unsigned int reg;
2344      unsigned int targ_reg;
2345      unsigned int xy;
2346 {
2347   unw_rec_list *ptr = alloc_record (spill_reg);
2348   ptr->r.record.x.ab = ab;
2349   ptr->r.record.x.reg = reg;
2350   ptr->r.record.x.treg = targ_reg;
2351   ptr->r.record.x.xy = xy;
2352   return ptr;
2353 }
2354
2355 static unw_rec_list *
2356 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2357      unsigned int ab;
2358      unsigned int reg;
2359      unsigned int targ_reg;
2360      unsigned int xy;
2361      unsigned int predicate;
2362 {
2363   unw_rec_list *ptr = alloc_record (spill_reg_p);
2364   ptr->r.record.x.ab = ab;
2365   ptr->r.record.x.reg = reg;
2366   ptr->r.record.x.treg = targ_reg;
2367   ptr->r.record.x.xy = xy;
2368   ptr->r.record.x.qp = predicate;
2369   return ptr;
2370 }
2371
2372 /* Given a unw_rec_list process the correct format with the
2373    specified function.  */
2374
2375 static void
2376 process_one_record (ptr, f)
2377      unw_rec_list *ptr;
2378      vbyte_func f;
2379 {
2380   unsigned long fr_mask, gr_mask;
2381
2382   switch (ptr->r.type)
2383     {
2384       /* This is a dummy record that takes up no space in the output.  */
2385     case endp:
2386       break;
2387
2388     case gr_mem:
2389     case fr_mem:
2390     case br_mem:
2391     case frgr_mem:
2392       /* These are taken care of by prologue/prologue_gr.  */
2393       break;
2394
2395     case prologue_gr:
2396     case prologue:
2397       if (ptr->r.type == prologue_gr)
2398         output_R2_format (f, ptr->r.record.r.grmask,
2399                           ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2400       else
2401         output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2402
2403       /* Output descriptor(s) for union of register spills (if any).  */
2404       gr_mask = ptr->r.record.r.mask.gr_mem;
2405       fr_mask = ptr->r.record.r.mask.fr_mem;
2406       if (fr_mask)
2407         {
2408           if ((fr_mask & ~0xfUL) == 0)
2409             output_P6_format (f, fr_mem, fr_mask);
2410           else
2411             {
2412               output_P5_format (f, gr_mask, fr_mask);
2413               gr_mask = 0;
2414             }
2415         }
2416       if (gr_mask)
2417         output_P6_format (f, gr_mem, gr_mask);
2418       if (ptr->r.record.r.mask.br_mem)
2419         output_P1_format (f, ptr->r.record.r.mask.br_mem);
2420
2421       /* output imask descriptor if necessary:  */
2422       if (ptr->r.record.r.mask.i)
2423         output_P4_format (f, ptr->r.record.r.mask.i,
2424                           ptr->r.record.r.imask_size);
2425       break;
2426
2427     case body:
2428       output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2429       break;
2430     case mem_stack_f:
2431     case mem_stack_v:
2432       output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2433                         ptr->r.record.p.size);
2434       break;
2435     case psp_gr:
2436     case rp_gr:
2437     case pfs_gr:
2438     case preds_gr:
2439     case unat_gr:
2440     case lc_gr:
2441     case fpsr_gr:
2442     case priunat_gr:
2443     case bsp_gr:
2444     case bspstore_gr:
2445     case rnat_gr:
2446       output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2447       break;
2448     case rp_br:
2449       output_P3_format (f, rp_br, ptr->r.record.p.br);
2450       break;
2451     case psp_sprel:
2452       output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2453       break;
2454     case rp_when:
2455     case pfs_when:
2456     case preds_when:
2457     case unat_when:
2458     case lc_when:
2459     case fpsr_when:
2460       output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2461       break;
2462     case rp_psprel:
2463     case pfs_psprel:
2464     case preds_psprel:
2465     case unat_psprel:
2466     case lc_psprel:
2467     case fpsr_psprel:
2468     case spill_base:
2469       output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2470       break;
2471     case rp_sprel:
2472     case pfs_sprel:
2473     case preds_sprel:
2474     case unat_sprel:
2475     case lc_sprel:
2476     case fpsr_sprel:
2477     case priunat_sprel:
2478     case bsp_sprel:
2479     case bspstore_sprel:
2480     case rnat_sprel:
2481       output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2482       break;
2483     case gr_gr:
2484       output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2485       break;
2486     case br_gr:
2487       output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2488       break;
2489     case spill_mask:
2490       as_bad ("spill_mask record unimplemented.");
2491       break;
2492     case priunat_when_gr:
2493     case priunat_when_mem:
2494     case bsp_when:
2495     case bspstore_when:
2496     case rnat_when:
2497       output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2498       break;
2499     case priunat_psprel:
2500     case bsp_psprel:
2501     case bspstore_psprel:
2502     case rnat_psprel:
2503       output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2504       break;
2505     case unwabi:
2506       output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2507       break;
2508     case epilogue:
2509       output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2510       break;
2511     case label_state:
2512     case copy_state:
2513       output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2514       break;
2515     case spill_psprel:
2516       output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2517                         ptr->r.record.x.reg, ptr->r.record.x.t,
2518                         ptr->r.record.x.pspoff);
2519       break;
2520     case spill_sprel:
2521       output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2522                         ptr->r.record.x.reg, ptr->r.record.x.t,
2523                         ptr->r.record.x.spoff);
2524       break;
2525     case spill_reg:
2526       output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2527                         ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2528                         ptr->r.record.x.treg, ptr->r.record.x.t);
2529       break;
2530     case spill_psprel_p:
2531       output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2532                         ptr->r.record.x.ab, ptr->r.record.x.reg,
2533                         ptr->r.record.x.t, ptr->r.record.x.pspoff);
2534       break;
2535     case spill_sprel_p:
2536       output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2537                         ptr->r.record.x.ab, ptr->r.record.x.reg,
2538                         ptr->r.record.x.t, ptr->r.record.x.spoff);
2539       break;
2540     case spill_reg_p:
2541       output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2542                         ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2543                         ptr->r.record.x.xy, ptr->r.record.x.treg,
2544                         ptr->r.record.x.t);
2545       break;
2546     default:
2547       as_bad ("record_type_not_valid");
2548       break;
2549     }
2550 }
2551
2552 /* Given a unw_rec_list list, process all the records with
2553    the specified function.  */
2554 static void
2555 process_unw_records (list, f)
2556      unw_rec_list *list;
2557      vbyte_func f;
2558 {
2559   unw_rec_list *ptr;
2560   for (ptr = list; ptr; ptr = ptr->next)
2561     process_one_record (ptr, f);
2562 }
2563
2564 /* Determine the size of a record list in bytes.  */
2565 static int
2566 calc_record_size (list)
2567      unw_rec_list *list;
2568 {
2569   vbyte_count = 0;
2570   process_unw_records (list, count_output);
2571   return vbyte_count;
2572 }
2573
2574 /* Update IMASK bitmask to reflect the fact that one or more registers
2575    of type TYPE are saved starting at instruction with index T.  If N
2576    bits are set in REGMASK, it is assumed that instructions T through
2577    T+N-1 save these registers.
2578
2579    TYPE values:
2580         0: no save
2581         1: instruction saves next fp reg
2582         2: instruction saves next general reg
2583         3: instruction saves next branch reg */
2584 static void
2585 set_imask (region, regmask, t, type)
2586      unw_rec_list *region;
2587      unsigned long regmask;
2588      unsigned long t;
2589      unsigned int type;
2590 {
2591   unsigned char *imask;
2592   unsigned long imask_size;
2593   unsigned int i;
2594   int pos;
2595
2596   imask = region->r.record.r.mask.i;
2597   imask_size = region->r.record.r.imask_size;
2598   if (!imask)
2599     {
2600       imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2601       imask = xmalloc (imask_size);
2602       memset (imask, 0, imask_size);
2603
2604       region->r.record.r.imask_size = imask_size;
2605       region->r.record.r.mask.i = imask;
2606     }
2607
2608   i = (t / 4) + 1;
2609   pos = 2 * (3 - t % 4);
2610   while (regmask)
2611     {
2612       if (i >= imask_size)
2613         {
2614           as_bad ("Ignoring attempt to spill beyond end of region");
2615           return;
2616         }
2617
2618       imask[i] |= (type & 0x3) << pos;
2619
2620       regmask &= (regmask - 1);
2621       pos -= 2;
2622       if (pos < 0)
2623         {
2624           pos = 0;
2625           ++i;
2626         }
2627     }
2628 }
2629
2630 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2631    SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2632    containing FIRST_ADDR.  If BEFORE_RELAX, then we use worst-case estimates
2633    for frag sizes.  */
2634
2635 unsigned long
2636 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2637      unsigned long slot_addr;
2638      fragS *slot_frag;
2639      unsigned long first_addr;
2640      fragS *first_frag;
2641      int before_relax;
2642 {
2643   unsigned long index = 0;
2644
2645   /* First time we are called, the initial address and frag are invalid.  */
2646   if (first_addr == 0)
2647     return 0;
2648
2649   /* If the two addresses are in different frags, then we need to add in
2650      the remaining size of this frag, and then the entire size of intermediate
2651      frags.  */
2652   while (slot_frag != first_frag)
2653     {
2654       unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2655
2656       if (! before_relax)
2657         {
2658           /* We can get the final addresses only during and after
2659              relaxation.  */
2660           if (first_frag->fr_next && first_frag->fr_next->fr_address)
2661             index += 3 * ((first_frag->fr_next->fr_address
2662                            - first_frag->fr_address
2663                              - first_frag->fr_fix) >> 4);
2664         }
2665       else
2666         /* We don't know what the final addresses will be. We try our
2667            best to estimate.  */
2668         switch (first_frag->fr_type)
2669           {
2670           default:
2671             break;
2672
2673           case rs_space:
2674             as_fatal ("only constant space allocation is supported");
2675             break;
2676
2677           case rs_align:
2678           case rs_align_code:
2679           case rs_align_test:
2680             /* Take alignment into account.  Assume the worst case
2681                before relaxation.  */
2682             index += 3 * ((1 << first_frag->fr_offset) >> 4);
2683             break;
2684
2685           case rs_org:
2686             if (first_frag->fr_symbol)
2687               {
2688                 as_fatal ("only constant offsets are supported");
2689                 break;
2690               }
2691           case rs_fill:
2692             index += 3 * (first_frag->fr_offset >> 4);
2693             break;
2694           }
2695
2696       /* Add in the full size of the frag converted to instruction slots.  */
2697       index += 3 * (first_frag->fr_fix >> 4);
2698       /* Subtract away the initial part before first_addr.  */
2699       index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2700                 + ((first_addr & 0x3) - (start_addr & 0x3)));
2701
2702       /* Move to the beginning of the next frag.  */
2703       first_frag = first_frag->fr_next;
2704       first_addr = (unsigned long) &first_frag->fr_literal;
2705     }
2706
2707   /* Add in the used part of the last frag.  */
2708   index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2709             + ((slot_addr & 0x3) - (first_addr & 0x3)));
2710   return index;
2711 }
2712
2713 /* Optimize unwind record directives.  */
2714
2715 static unw_rec_list *
2716 optimize_unw_records (list)
2717      unw_rec_list *list;
2718 {
2719   if (!list)
2720     return NULL;
2721
2722   /* If the only unwind record is ".prologue" or ".prologue" followed
2723      by ".body", then we can optimize the unwind directives away.  */
2724   if (list->r.type == prologue
2725       && (list->next->r.type == endp
2726           || (list->next->r.type == body && list->next->next->r.type == endp)))
2727     return NULL;
2728
2729   return list;
2730 }
2731
2732 /* Given a complete record list, process any records which have
2733    unresolved fields, (ie length counts for a prologue).  After
2734    this has been run, all necessary information should be available
2735    within each record to generate an image.  */
2736
2737 static void
2738 fixup_unw_records (list, before_relax)
2739      unw_rec_list *list;
2740      int before_relax;
2741 {
2742   unw_rec_list *ptr, *region = 0;
2743   unsigned long first_addr = 0, rlen = 0, t;
2744   fragS *first_frag = 0;
2745
2746   for (ptr = list; ptr; ptr = ptr->next)
2747     {
2748       if (ptr->slot_number == SLOT_NUM_NOT_SET)
2749         as_bad (" Insn slot not set in unwind record.");
2750       t = slot_index (ptr->slot_number, ptr->slot_frag,
2751                       first_addr, first_frag, before_relax);
2752       switch (ptr->r.type)
2753         {
2754         case prologue:
2755         case prologue_gr:
2756         case body:
2757           {
2758             unw_rec_list *last;
2759             int size;
2760             unsigned long last_addr = 0;
2761             fragS *last_frag = NULL;
2762
2763             first_addr = ptr->slot_number;
2764             first_frag = ptr->slot_frag;
2765             /* Find either the next body/prologue start, or the end of
2766                the function, and determine the size of the region.  */
2767             for (last = ptr->next; last != NULL; last = last->next)
2768               if (last->r.type == prologue || last->r.type == prologue_gr
2769                   || last->r.type == body || last->r.type == endp)
2770                 {
2771                   last_addr = last->slot_number;
2772                   last_frag = last->slot_frag;
2773                   break;
2774                 }
2775             size = slot_index (last_addr, last_frag, first_addr, first_frag,
2776                                before_relax);
2777             rlen = ptr->r.record.r.rlen = size;
2778             if (ptr->r.type == body)
2779               /* End of region.  */
2780               region = 0;
2781             else
2782               region = ptr;
2783             break;
2784           }
2785         case epilogue:
2786           if (t < rlen)
2787             ptr->r.record.b.t = rlen - 1 - t;
2788           else
2789             /* This happens when a memory-stack-less procedure uses a
2790                ".restore sp" directive at the end of a region to pop
2791                the frame state.  */
2792             ptr->r.record.b.t = 0;
2793           break;
2794
2795         case mem_stack_f:
2796         case mem_stack_v:
2797         case rp_when:
2798         case pfs_when:
2799         case preds_when:
2800         case unat_when:
2801         case lc_when:
2802         case fpsr_when:
2803         case priunat_when_gr:
2804         case priunat_when_mem:
2805         case bsp_when:
2806         case bspstore_when:
2807         case rnat_when:
2808           ptr->r.record.p.t = t;
2809           break;
2810
2811         case spill_reg:
2812         case spill_sprel:
2813         case spill_psprel:
2814         case spill_reg_p:
2815         case spill_sprel_p:
2816         case spill_psprel_p:
2817           ptr->r.record.x.t = t;
2818           break;
2819
2820         case frgr_mem:
2821           if (!region)
2822             {
2823               as_bad ("frgr_mem record before region record!");
2824               return;
2825             }
2826           region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2827           region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2828           set_imask (region, ptr->r.record.p.frmask, t, 1);
2829           set_imask (region, ptr->r.record.p.grmask, t, 2);
2830           break;
2831         case fr_mem:
2832           if (!region)
2833             {
2834               as_bad ("fr_mem record before region record!");
2835               return;
2836             }
2837           region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2838           set_imask (region, ptr->r.record.p.rmask, t, 1);
2839           break;
2840         case gr_mem:
2841           if (!region)
2842             {
2843               as_bad ("gr_mem record before region record!");
2844               return;
2845             }
2846           region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2847           set_imask (region, ptr->r.record.p.rmask, t, 2);
2848           break;
2849         case br_mem:
2850           if (!region)
2851             {
2852               as_bad ("br_mem record before region record!");
2853               return;
2854             }
2855           region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2856           set_imask (region, ptr->r.record.p.brmask, t, 3);
2857           break;
2858
2859         case gr_gr:
2860           if (!region)
2861             {
2862               as_bad ("gr_gr record before region record!");
2863               return;
2864             }
2865           set_imask (region, ptr->r.record.p.grmask, t, 2);
2866           break;
2867         case br_gr:
2868           if (!region)
2869             {
2870               as_bad ("br_gr record before region record!");
2871               return;
2872             }
2873           set_imask (region, ptr->r.record.p.brmask, t, 3);
2874           break;
2875
2876         default:
2877           break;
2878         }
2879     }
2880 }
2881
2882 /* Estimate the size of a frag before relaxing.  We only have one type of frag
2883    to handle here, which is the unwind info frag.  */
2884
2885 int
2886 ia64_estimate_size_before_relax (fragS *frag,
2887                                  asection *segtype ATTRIBUTE_UNUSED)
2888 {
2889   unw_rec_list *list;
2890   int len, size, pad;
2891
2892   /* ??? This code is identical to the first part of ia64_convert_frag.  */
2893   list = (unw_rec_list *) frag->fr_opcode;
2894   fixup_unw_records (list, 0);
2895
2896   len = calc_record_size (list);
2897   /* pad to pointer-size boundary.  */
2898   pad = len % md.pointer_size;
2899   if (pad != 0)
2900     len += md.pointer_size - pad;
2901   /* Add 8 for the header.  */
2902   size = len + 8;
2903   /* Add a pointer for the personality offset.  */
2904   if (frag->fr_offset)
2905     size += md.pointer_size;
2906
2907   /* fr_var carries the max_chars that we created the fragment with.
2908      We must, of course, have allocated enough memory earlier.  */
2909   assert (frag->fr_var >= size);
2910
2911   return frag->fr_fix + size;
2912 }
2913
2914 /* This function converts a rs_machine_dependent variant frag into a
2915   normal fill frag with the unwind image from the the record list.  */
2916 void
2917 ia64_convert_frag (fragS *frag)
2918 {
2919   unw_rec_list *list;
2920   int len, size, pad;
2921   valueT flag_value;
2922
2923   /* ??? This code is identical to ia64_estimate_size_before_relax.  */
2924   list = (unw_rec_list *) frag->fr_opcode;
2925   fixup_unw_records (list, 0);
2926
2927   len = calc_record_size (list);
2928   /* pad to pointer-size boundary.  */
2929   pad = len % md.pointer_size;
2930   if (pad != 0)
2931     len += md.pointer_size - pad;
2932   /* Add 8 for the header.  */
2933   size = len + 8;
2934   /* Add a pointer for the personality offset.  */
2935   if (frag->fr_offset)
2936     size += md.pointer_size;
2937
2938   /* fr_var carries the max_chars that we created the fragment with.
2939      We must, of course, have allocated enough memory earlier.  */
2940   assert (frag->fr_var >= size);
2941
2942   /* Initialize the header area. fr_offset is initialized with
2943      unwind.personality_routine.  */
2944   if (frag->fr_offset)
2945     {
2946       if (md.flags & EF_IA_64_ABI64)
2947         flag_value = (bfd_vma) 3 << 32;
2948       else
2949         /* 32-bit unwind info block.  */
2950         flag_value = (bfd_vma) 0x1003 << 32;
2951     }
2952   else
2953     flag_value = 0;
2954
2955  md_number_to_chars (frag->fr_literal,
2956                      (((bfd_vma) 1 << 48) /* Version.  */
2957                       | flag_value        /* U & E handler flags.  */
2958                       | (len / md.pointer_size)), /* Length.  */
2959                      8);
2960
2961   /* Skip the header.  */
2962   vbyte_mem_ptr = frag->fr_literal + 8;
2963   process_unw_records (list, output_vbyte_mem);
2964
2965   /* Fill the padding bytes with zeros.  */
2966   if (pad != 0)
2967     md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2968                         md.pointer_size - pad);
2969
2970   frag->fr_fix += size;
2971   frag->fr_type = rs_fill;
2972   frag->fr_var = 0;
2973   frag->fr_offset = 0;
2974 }
2975
2976 static int
2977 convert_expr_to_ab_reg (e, ab, regp)
2978      expressionS *e;
2979      unsigned int *ab;
2980      unsigned int *regp;
2981 {
2982   unsigned int reg;
2983
2984   if (e->X_op != O_register)
2985     return 0;
2986
2987   reg = e->X_add_number;
2988   if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2989     {
2990       *ab = 0;
2991       *regp = reg - REG_GR;
2992     }
2993   else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2994            || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2995     {
2996       *ab = 1;
2997       *regp = reg - REG_FR;
2998     }
2999   else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
3000     {
3001       *ab = 2;
3002       *regp = reg - REG_BR;
3003     }
3004   else
3005     {
3006       *ab = 3;
3007       switch (reg)
3008         {
3009         case REG_PR:            *regp =  0; break;
3010         case REG_PSP:           *regp =  1; break;
3011         case REG_PRIUNAT:       *regp =  2; break;
3012         case REG_BR + 0:        *regp =  3; break;
3013         case REG_AR + AR_BSP:   *regp =  4; break;
3014         case REG_AR + AR_BSPSTORE: *regp = 5; break;
3015         case REG_AR + AR_RNAT:  *regp =  6; break;
3016         case REG_AR + AR_UNAT:  *regp =  7; break;
3017         case REG_AR + AR_FPSR:  *regp =  8; break;
3018         case REG_AR + AR_PFS:   *regp =  9; break;
3019         case REG_AR + AR_LC:    *regp = 10; break;
3020
3021         default:
3022           return 0;
3023         }
3024     }
3025   return 1;
3026 }
3027
3028 static int
3029 convert_expr_to_xy_reg (e, xy, regp)
3030      expressionS *e;
3031      unsigned int *xy;
3032      unsigned int *regp;
3033 {
3034   unsigned int reg;
3035
3036   if (e->X_op != O_register)
3037     return 0;
3038
3039   reg = e->X_add_number;
3040
3041   if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
3042     {
3043       *xy = 0;
3044       *regp = reg - REG_GR;
3045     }
3046   else if (reg >= REG_FR && reg <= (REG_FR + 127))
3047     {
3048       *xy = 1;
3049       *regp = reg - REG_FR;
3050     }
3051   else if (reg >= REG_BR && reg <= (REG_BR + 7))
3052     {
3053       *xy = 2;
3054       *regp = reg - REG_BR;
3055     }
3056   else
3057     return -1;
3058   return 1;
3059 }
3060
3061 static void
3062 dot_align (int arg)
3063 {
3064   /* The current frag is an alignment frag.  */
3065   align_frag = frag_now;
3066   s_align_bytes (arg);
3067 }
3068
3069 static void
3070 dot_radix (dummy)
3071      int dummy ATTRIBUTE_UNUSED;
3072 {
3073   char *radix;
3074   int ch;
3075
3076   SKIP_WHITESPACE ();
3077
3078   if (is_it_end_of_statement ())
3079     return;
3080   radix = input_line_pointer;
3081   ch = get_symbol_end ();
3082   ia64_canonicalize_symbol_name (radix);
3083   if (strcasecmp (radix, "C"))
3084     as_bad ("Radix `%s' unsupported or invalid", radix);
3085   *input_line_pointer = ch;
3086   demand_empty_rest_of_line ();
3087 }
3088
3089 /* Helper function for .loc directives.  If the assembler is not generating
3090    line number info, then we need to remember which instructions have a .loc
3091    directive, and only call dwarf2_gen_line_info for those instructions.  */
3092
3093 static void
3094 dot_loc (int x)
3095 {
3096   CURR_SLOT.loc_directive_seen = 1;
3097   dwarf2_directive_loc (x);
3098 }
3099
3100 /* .sbss, .bss etc. are macros that expand into ".section SECNAME".  */
3101 static void
3102 dot_special_section (which)
3103      int which;
3104 {
3105   set_section ((char *) special_section_name[which]);
3106 }
3107
3108 /* Return -1 for warning and 0 for error.  */
3109
3110 static int
3111 unwind_diagnostic (const char * region, const char *directive)
3112 {
3113   if (md.unwind_check == unwind_check_warning)
3114     {
3115       as_warn (".%s outside of %s", directive, region);
3116       return -1;
3117     }
3118   else
3119     {
3120       as_bad (".%s outside of %s", directive, region);
3121       ignore_rest_of_line ();
3122       return 0;
3123     }
3124 }
3125
3126 /* Return 1 if a directive is in a procedure, -1 if a directive isn't in
3127    a procedure but the unwind directive check is set to warning, 0 if
3128    a directive isn't in a procedure and the unwind directive check is set
3129    to error.  */
3130
3131 static int
3132 in_procedure (const char *directive)
3133 {
3134   if (unwind.proc_start
3135       && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0))
3136     return 1;
3137   return unwind_diagnostic ("procedure", directive);
3138 }
3139
3140 /* Return 1 if a directive is in a prologue, -1 if a directive isn't in
3141    a prologue but the unwind directive check is set to warning, 0 if
3142    a directive isn't in a prologue and the unwind directive check is set
3143    to error.  */
3144
3145 static int
3146 in_prologue (const char *directive)
3147 {
3148   int in = in_procedure (directive);
3149   if (in)
3150     {
3151       /* We are in a procedure. Check if we are in a prologue.  */
3152       if (unwind.prologue)
3153         return 1;
3154       /* We only want to issue one message.  */
3155       if (in == 1)
3156         return unwind_diagnostic ("prologue", directive);
3157       else
3158         return -1;
3159     }
3160   return 0;
3161 }
3162
3163 /* Return 1 if a directive is in a body, -1 if a directive isn't in
3164    a body but the unwind directive check is set to warning, 0 if
3165    a directive isn't in a body and the unwind directive check is set
3166    to error.  */
3167
3168 static int
3169 in_body (const char *directive)
3170 {
3171   int in = in_procedure (directive);
3172   if (in)
3173     {
3174       /* We are in a procedure. Check if we are in a body.  */
3175       if (unwind.body)
3176         return 1;
3177       /* We only want to issue one message.  */
3178       if (in == 1)
3179         return unwind_diagnostic ("body region", directive);
3180       else
3181         return -1;
3182     }
3183   return 0;
3184 }
3185
3186 static void
3187 add_unwind_entry (ptr)
3188      unw_rec_list *ptr;
3189 {
3190   if (unwind.tail)
3191     unwind.tail->next = ptr;
3192   else
3193     unwind.list = ptr;
3194   unwind.tail = ptr;
3195
3196   /* The current entry can in fact be a chain of unwind entries.  */
3197   if (unwind.current_entry == NULL)
3198     unwind.current_entry = ptr;
3199 }
3200
3201 static void
3202 dot_fframe (dummy)
3203      int dummy ATTRIBUTE_UNUSED;
3204 {
3205   expressionS e;
3206
3207   if (!in_prologue ("fframe"))
3208     return;
3209
3210   parse_operand (&e);
3211
3212   if (e.X_op != O_constant)
3213     as_bad ("Operand to .fframe must be a constant");
3214   else
3215     add_unwind_entry (output_mem_stack_f (e.X_add_number));
3216 }
3217
3218 static void
3219 dot_vframe (dummy)
3220      int dummy ATTRIBUTE_UNUSED;
3221 {
3222   expressionS e;
3223   unsigned reg;
3224
3225   if (!in_prologue ("vframe"))
3226     return;
3227
3228   parse_operand (&e);
3229   reg = e.X_add_number - REG_GR;
3230   if (e.X_op == O_register && reg < 128)
3231     {
3232       add_unwind_entry (output_mem_stack_v ());
3233       if (! (unwind.prologue_mask & 2))
3234         add_unwind_entry (output_psp_gr (reg));
3235     }
3236   else
3237     as_bad ("First operand to .vframe must be a general register");
3238 }
3239
3240 static void
3241 dot_vframesp (dummy)
3242      int dummy ATTRIBUTE_UNUSED;
3243 {
3244   expressionS e;
3245
3246   if (!in_prologue ("vframesp"))
3247     return;
3248
3249   parse_operand (&e);
3250   if (e.X_op == O_constant)
3251     {
3252       add_unwind_entry (output_mem_stack_v ());
3253       add_unwind_entry (output_psp_sprel (e.X_add_number));
3254     }
3255   else
3256     as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3257 }
3258
3259 static void
3260 dot_vframepsp (dummy)
3261      int dummy ATTRIBUTE_UNUSED;
3262 {
3263   expressionS e;
3264
3265   if (!in_prologue ("vframepsp"))
3266     return;
3267
3268   parse_operand (&e);
3269   if (e.X_op == O_constant)
3270     {
3271       add_unwind_entry (output_mem_stack_v ());
3272       add_unwind_entry (output_psp_sprel (e.X_add_number));
3273     }
3274   else
3275     as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3276 }
3277
3278 static void
3279 dot_save (dummy)
3280      int dummy ATTRIBUTE_UNUSED;
3281 {
3282   expressionS e1, e2;
3283   int sep;
3284   int reg1, reg2;
3285
3286   if (!in_prologue ("save"))
3287     return;
3288
3289   sep = parse_operand (&e1);
3290   if (sep != ',')
3291     as_bad ("No second operand to .save");
3292   sep = parse_operand (&e2);
3293
3294   reg1 = e1.X_add_number;
3295   reg2 = e2.X_add_number - REG_GR;
3296
3297   /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'.  */
3298   if (e1.X_op == O_register)
3299     {
3300       if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3301         {
3302           switch (reg1)
3303             {
3304             case REG_AR + AR_BSP:
3305               add_unwind_entry (output_bsp_when ());
3306               add_unwind_entry (output_bsp_gr (reg2));
3307               break;
3308             case REG_AR + AR_BSPSTORE:
3309               add_unwind_entry (output_bspstore_when ());
3310               add_unwind_entry (output_bspstore_gr (reg2));
3311               break;
3312             case REG_AR + AR_RNAT:
3313               add_unwind_entry (output_rnat_when ());
3314               add_unwind_entry (output_rnat_gr (reg2));
3315               break;
3316             case REG_AR + AR_UNAT:
3317               add_unwind_entry (output_unat_when ());
3318               add_unwind_entry (output_unat_gr (reg2));
3319               break;
3320             case REG_AR + AR_FPSR:
3321               add_unwind_entry (output_fpsr_when ());
3322               add_unwind_entry (output_fpsr_gr (reg2));
3323               break;
3324             case REG_AR + AR_PFS:
3325               add_unwind_entry (output_pfs_when ());
3326               if (! (unwind.prologue_mask & 4))
3327                 add_unwind_entry (output_pfs_gr (reg2));
3328               break;
3329             case REG_AR + AR_LC:
3330               add_unwind_entry (output_lc_when ());
3331               add_unwind_entry (output_lc_gr (reg2));
3332               break;
3333             case REG_BR:
3334               add_unwind_entry (output_rp_when ());
3335               if (! (unwind.prologue_mask & 8))
3336                 add_unwind_entry (output_rp_gr (reg2));
3337               break;
3338             case REG_PR:
3339               add_unwind_entry (output_preds_when ());
3340               if (! (unwind.prologue_mask & 1))
3341                 add_unwind_entry (output_preds_gr (reg2));
3342               break;
3343             case REG_PRIUNAT:
3344               add_unwind_entry (output_priunat_when_gr ());
3345               add_unwind_entry (output_priunat_gr (reg2));
3346               break;
3347             default:
3348               as_bad ("First operand not a valid register");
3349             }
3350         }
3351       else
3352         as_bad (" Second operand not a valid register");
3353     }
3354   else
3355     as_bad ("First operand not a register");
3356 }
3357
3358 static void
3359 dot_restore (dummy)
3360      int dummy ATTRIBUTE_UNUSED;
3361 {
3362   expressionS e1, e2;
3363   unsigned long ecount; /* # of _additional_ regions to pop */
3364   int sep;
3365
3366   if (!in_body ("restore"))
3367     return;
3368
3369   sep = parse_operand (&e1);
3370   if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3371     {
3372       as_bad ("First operand to .restore must be stack pointer (sp)");
3373       return;
3374     }
3375
3376   if (sep == ',')
3377     {
3378       parse_operand (&e2);
3379       if (e2.X_op != O_constant || e2.X_add_number < 0)
3380         {
3381           as_bad ("Second operand to .restore must be a constant >= 0");
3382           return;
3383         }
3384       ecount = e2.X_add_number;
3385     }
3386   else
3387     ecount = unwind.prologue_count - 1;
3388
3389   if (ecount >= unwind.prologue_count)
3390     {
3391       as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3392               ecount + 1, unwind.prologue_count);
3393       return;
3394     }
3395
3396   add_unwind_entry (output_epilogue (ecount));
3397
3398   if (ecount < unwind.prologue_count)
3399     unwind.prologue_count -= ecount + 1;
3400   else
3401     unwind.prologue_count = 0;
3402 }
3403
3404 static void
3405 dot_restorereg (dummy)
3406      int dummy ATTRIBUTE_UNUSED;
3407 {
3408   unsigned int ab, reg;
3409   expressionS e;
3410
3411   if (!in_procedure ("restorereg"))
3412     return;
3413
3414   parse_operand (&e);
3415
3416   if (!convert_expr_to_ab_reg (&e, &ab, &reg))
3417     {
3418       as_bad ("First operand to .restorereg must be a preserved register");
3419       return;
3420     }
3421   add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3422 }
3423
3424 static void
3425 dot_restorereg_p (dummy)
3426      int dummy ATTRIBUTE_UNUSED;
3427 {
3428   unsigned int qp, ab, reg;
3429   expressionS e1, e2;
3430   int sep;
3431
3432   if (!in_procedure ("restorereg.p"))
3433     return;
3434
3435   sep = parse_operand (&e1);
3436   if (sep != ',')
3437     {
3438       as_bad ("No second operand to .restorereg.p");
3439       return;
3440     }
3441
3442   parse_operand (&e2);
3443
3444   qp = e1.X_add_number - REG_P;
3445   if (e1.X_op != O_register || qp > 63)
3446     {
3447       as_bad ("First operand to .restorereg.p must be a predicate");
3448       return;
3449     }
3450
3451   if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
3452     {
3453       as_bad ("Second operand to .restorereg.p must be a preserved register");
3454       return;
3455     }
3456   add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3457 }
3458
3459 static char *special_linkonce_name[] =
3460   {
3461     ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3462   };
3463
3464 static void
3465 start_unwind_section (const segT text_seg, int sec_index)
3466 {
3467   /*
3468     Use a slightly ugly scheme to derive the unwind section names from
3469     the text section name:
3470
3471     text sect.  unwind table sect.
3472     name:       name:                      comments:
3473     ----------  -----------------          --------------------------------
3474     .text       .IA_64.unwind
3475     .text.foo   .IA_64.unwind.text.foo
3476     .foo        .IA_64.unwind.foo
3477     .gnu.linkonce.t.foo
3478                 .gnu.linkonce.ia64unw.foo
3479     _info       .IA_64.unwind_info         gas issues error message (ditto)
3480     _infoFOO    .IA_64.unwind_infoFOO      gas issues error message (ditto)
3481
3482     This mapping is done so that:
3483
3484         (a) An object file with unwind info only in .text will use
3485             unwind section names .IA_64.unwind and .IA_64.unwind_info.
3486             This follows the letter of the ABI and also ensures backwards
3487             compatibility with older toolchains.
3488
3489         (b) An object file with unwind info in multiple text sections
3490             will use separate unwind sections for each text section.
3491             This allows us to properly set the "sh_info" and "sh_link"
3492             fields in SHT_IA_64_UNWIND as required by the ABI and also
3493             lets GNU ld support programs with multiple segments
3494             containing unwind info (as might be the case for certain
3495             embedded applications).
3496
3497         (c) An error is issued if there would be a name clash.
3498   */
3499
3500   const char *text_name, *sec_text_name;
3501   char *sec_name;
3502   const char *prefix = special_section_name [sec_index];
3503   const char *suffix;
3504   size_t prefix_len, suffix_len, sec_name_len;
3505
3506   sec_text_name = segment_name (text_seg);
3507   text_name = sec_text_name;
3508   if (strncmp (text_name, "_info", 5) == 0)
3509     {
3510       as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3511               text_name);
3512       ignore_rest_of_line ();
3513       return;
3514     }
3515   if (strcmp (text_name, ".text") == 0)
3516     text_name = "";
3517
3518   /* Build the unwind section name by appending the (possibly stripped)
3519      text section name to the unwind prefix.  */
3520   suffix = text_name;
3521   if (strncmp (text_name, ".gnu.linkonce.t.",
3522                sizeof (".gnu.linkonce.t.") - 1) == 0)
3523     {
3524       prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3525       suffix += sizeof (".gnu.linkonce.t.") - 1;
3526     }
3527
3528   prefix_len = strlen (prefix);
3529   suffix_len = strlen (suffix);
3530   sec_name_len = prefix_len + suffix_len;
3531   sec_name = alloca (sec_name_len + 1);
3532   memcpy (sec_name, prefix, prefix_len);
3533   memcpy (sec_name + prefix_len, suffix, suffix_len);
3534   sec_name [sec_name_len] = '\0';
3535
3536   /* Handle COMDAT group.  */
3537   if ((text_seg->flags & SEC_LINK_ONCE) != 0
3538       && (elf_section_flags (text_seg) & SHF_GROUP) != 0)
3539     {
3540       char *section;
3541       size_t len, group_name_len;
3542       const char *group_name = elf_group_name (text_seg);
3543
3544       if (group_name == NULL)
3545         {
3546           as_bad ("Group section `%s' has no group signature",
3547                   sec_text_name);
3548           ignore_rest_of_line ();
3549           return;
3550         }
3551       /* We have to construct a fake section directive. */
3552       group_name_len = strlen (group_name);
3553       len = (sec_name_len
3554              + 16                       /* ,"aG",@progbits,  */
3555              + group_name_len           /* ,group_name  */
3556              + 7);                      /* ,comdat  */
3557
3558       section = alloca (len + 1);
3559       memcpy (section, sec_name, sec_name_len);
3560       memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3561       memcpy (section + sec_name_len + 16, group_name, group_name_len);
3562       memcpy (section + len - 7, ",comdat", 7);
3563       section [len] = '\0';
3564       set_section (section);
3565     }
3566   else
3567     {
3568       set_section (sec_name);
3569       bfd_set_section_flags (stdoutput, now_seg,
3570                              SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3571     }
3572
3573   elf_linked_to_section (now_seg) = text_seg;
3574 }
3575
3576 static void
3577 generate_unwind_image (const segT text_seg)
3578 {
3579   int size, pad;
3580   unw_rec_list *list;
3581
3582   /* Mark the end of the unwind info, so that we can compute the size of the
3583      last unwind region.  */
3584   add_unwind_entry (output_endp ());
3585
3586   /* Force out pending instructions, to make sure all unwind records have
3587      a valid slot_number field.  */
3588   ia64_flush_insns ();
3589
3590   /* Generate the unwind record.  */
3591   list = optimize_unw_records (unwind.list);
3592   fixup_unw_records (list, 1);
3593   size = calc_record_size (list);
3594
3595   if (size > 0 || unwind.force_unwind_entry)
3596     {
3597       unwind.force_unwind_entry = 0;
3598       /* pad to pointer-size boundary.  */
3599       pad = size % md.pointer_size;
3600       if (pad != 0)
3601         size += md.pointer_size - pad;
3602       /* Add 8 for the header.  */
3603       size += 8;
3604       /* Add a pointer for the personality offset.  */
3605       if (unwind.personality_routine)
3606         size += md.pointer_size;
3607     }
3608
3609   /* If there are unwind records, switch sections, and output the info.  */
3610   if (size != 0)
3611     {
3612       expressionS exp;
3613       bfd_reloc_code_real_type reloc;
3614
3615       start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO);
3616
3617       /* Make sure the section has 4 byte alignment for ILP32 and
3618          8 byte alignment for LP64.  */
3619       frag_align (md.pointer_size_shift, 0, 0);
3620       record_alignment (now_seg, md.pointer_size_shift);
3621
3622       /* Set expression which points to start of unwind descriptor area.  */
3623       unwind.info = expr_build_dot ();
3624       
3625       frag_var (rs_machine_dependent, size, size, 0, 0,
3626                 (offsetT) (long) unwind.personality_routine,
3627                 (char *) list);
3628
3629       /* Add the personality address to the image.  */
3630       if (unwind.personality_routine != 0)
3631         {
3632           exp.X_op = O_symbol;
3633           exp.X_add_symbol = unwind.personality_routine;
3634           exp.X_add_number = 0;
3635
3636           if (md.flags & EF_IA_64_BE)
3637             {
3638               if (md.flags & EF_IA_64_ABI64)
3639                 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3640               else
3641                 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3642             }
3643           else
3644             {
3645               if (md.flags & EF_IA_64_ABI64)
3646                 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3647               else
3648                 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3649             }
3650
3651           fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3652                        md.pointer_size, &exp, 0, reloc);
3653           unwind.personality_routine = 0;
3654         }
3655     }
3656
3657   free_saved_prologue_counts ();
3658   unwind.list = unwind.tail = unwind.current_entry = NULL;
3659 }
3660
3661 static void
3662 dot_handlerdata (dummy)
3663      int dummy ATTRIBUTE_UNUSED;
3664 {
3665   if (!in_procedure ("handlerdata"))
3666     return;
3667   unwind.force_unwind_entry = 1;
3668
3669   /* Remember which segment we're in so we can switch back after .endp */
3670   unwind.saved_text_seg = now_seg;
3671   unwind.saved_text_subseg = now_subseg;
3672
3673   /* Generate unwind info into unwind-info section and then leave that
3674      section as the currently active one so dataXX directives go into
3675      the language specific data area of the unwind info block.  */
3676   generate_unwind_image (now_seg);
3677   demand_empty_rest_of_line ();
3678 }
3679
3680 static void
3681 dot_unwentry (dummy)
3682      int dummy ATTRIBUTE_UNUSED;
3683 {
3684   if (!in_procedure ("unwentry"))
3685     return;
3686   unwind.force_unwind_entry = 1;
3687   demand_empty_rest_of_line ();
3688 }
3689
3690 static void
3691 dot_altrp (dummy)
3692      int dummy ATTRIBUTE_UNUSED;
3693 {
3694   expressionS e;
3695   unsigned reg;
3696
3697   if (!in_prologue ("altrp"))
3698     return;
3699
3700   parse_operand (&e);
3701   reg = e.X_add_number - REG_BR;
3702   if (e.X_op == O_register && reg < 8)
3703     add_unwind_entry (output_rp_br (reg));
3704   else
3705     as_bad ("First operand not a valid branch register");
3706 }
3707
3708 static void
3709 dot_savemem (psprel)
3710      int psprel;
3711 {
3712   expressionS e1, e2;
3713   int sep;
3714   int reg1, val;
3715
3716   if (!in_prologue (psprel ? "savepsp" : "savesp"))
3717     return;
3718
3719   sep = parse_operand (&e1);
3720   if (sep != ',')
3721     as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3722   sep = parse_operand (&e2);
3723
3724   reg1 = e1.X_add_number;
3725   val = e2.X_add_number;
3726
3727   /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'.  */
3728   if (e1.X_op == O_register)
3729     {
3730       if (e2.X_op == O_constant)
3731         {
3732           switch (reg1)
3733             {
3734             case REG_AR + AR_BSP:
3735               add_unwind_entry (output_bsp_when ());
3736               add_unwind_entry ((psprel
3737                                  ? output_bsp_psprel
3738                                  : output_bsp_sprel) (val));
3739               break;
3740             case REG_AR + AR_BSPSTORE:
3741               add_unwind_entry (output_bspstore_when ());
3742               add_unwind_entry ((psprel
3743                                  ? output_bspstore_psprel
3744                                  : output_bspstore_sprel) (val));
3745               break;
3746             case REG_AR + AR_RNAT:
3747               add_unwind_entry (output_rnat_when ());
3748               add_unwind_entry ((psprel
3749                                  ? output_rnat_psprel
3750                                  : output_rnat_sprel) (val));
3751               break;
3752             case REG_AR + AR_UNAT:
3753               add_unwind_entry (output_unat_when ());
3754               add_unwind_entry ((psprel
3755                                  ? output_unat_psprel
3756                                  : output_unat_sprel) (val));
3757               break;
3758             case REG_AR + AR_FPSR:
3759               add_unwind_entry (output_fpsr_when ());
3760               add_unwind_entry ((psprel
3761                                  ? output_fpsr_psprel
3762                                  : output_fpsr_sprel) (val));
3763               break;
3764             case REG_AR + AR_PFS:
3765               add_unwind_entry (output_pfs_when ());
3766               add_unwind_entry ((psprel
3767                                  ? output_pfs_psprel
3768                                  : output_pfs_sprel) (val));
3769               break;
3770             case REG_AR + AR_LC:
3771               add_unwind_entry (output_lc_when ());
3772               add_unwind_entry ((psprel
3773                                  ? output_lc_psprel
3774                                  : output_lc_sprel) (val));
3775               break;
3776             case REG_BR:
3777               add_unwind_entry (output_rp_when ());
3778               add_unwind_entry ((psprel
3779                                  ? output_rp_psprel
3780                                  : output_rp_sprel) (val));
3781               break;
3782             case REG_PR:
3783               add_unwind_entry (output_preds_when ());
3784               add_unwind_entry ((psprel
3785                                  ? output_preds_psprel
3786                                  : output_preds_sprel) (val));
3787               break;
3788             case REG_PRIUNAT:
3789               add_unwind_entry (output_priunat_when_mem ());
3790               add_unwind_entry ((psprel
3791                                  ? output_priunat_psprel
3792                                  : output_priunat_sprel) (val));
3793               break;
3794             default:
3795               as_bad ("First operand not a valid register");
3796             }
3797         }
3798       else
3799         as_bad (" Second operand not a valid constant");
3800     }
3801   else
3802     as_bad ("First operand not a register");
3803 }
3804
3805 static void
3806 dot_saveg (dummy)
3807      int dummy ATTRIBUTE_UNUSED;
3808 {
3809   expressionS e1, e2;
3810   int sep;
3811
3812   if (!in_prologue ("save.g"))
3813     return;
3814
3815   sep = parse_operand (&e1);
3816   if (sep == ',')
3817     parse_operand (&e2);
3818
3819   if (e1.X_op != O_constant)
3820     as_bad ("First operand to .save.g must be a constant.");
3821   else
3822     {
3823       int grmask = e1.X_add_number;
3824       if (sep != ',')
3825         add_unwind_entry (output_gr_mem (grmask));
3826       else
3827         {
3828           int reg = e2.X_add_number - REG_GR;
3829           if (e2.X_op == O_register && reg >= 0 && reg < 128)
3830             add_unwind_entry (output_gr_gr (grmask, reg));
3831           else
3832             as_bad ("Second operand is an invalid register.");
3833         }
3834     }
3835 }
3836
3837 static void
3838 dot_savef (dummy)
3839      int dummy ATTRIBUTE_UNUSED;
3840 {
3841   expressionS e1;
3842   int sep;
3843
3844   if (!in_prologue ("save.f"))
3845     return;
3846
3847   sep = parse_operand (&e1);
3848
3849   if (e1.X_op != O_constant)
3850     as_bad ("Operand to .save.f must be a constant.");
3851   else
3852     add_unwind_entry (output_fr_mem (e1.X_add_number));
3853 }
3854
3855 static void
3856 dot_saveb (dummy)
3857      int dummy ATTRIBUTE_UNUSED;
3858 {
3859   expressionS e1, e2;
3860   unsigned int reg;
3861   unsigned char sep;
3862   int brmask;
3863
3864   if (!in_prologue ("save.b"))
3865     return;
3866
3867   sep = parse_operand (&e1);
3868   if (e1.X_op != O_constant)
3869     {
3870       as_bad ("First operand to .save.b must be a constant.");
3871       return;
3872     }
3873   brmask = e1.X_add_number;
3874
3875   if (sep == ',')
3876     {
3877       sep = parse_operand (&e2);
3878       reg = e2.X_add_number - REG_GR;
3879       if (e2.X_op != O_register || reg > 127)
3880         {
3881           as_bad ("Second operand to .save.b must be a general register.");
3882           return;
3883         }
3884       add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3885     }
3886   else
3887     add_unwind_entry (output_br_mem (brmask));
3888
3889   if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3890     demand_empty_rest_of_line ();
3891 }
3892
3893 static void
3894 dot_savegf (dummy)
3895      int dummy ATTRIBUTE_UNUSED;
3896 {
3897   expressionS e1, e2;
3898   int sep;
3899
3900   if (!in_prologue ("save.gf"))
3901     return;
3902
3903   sep = parse_operand (&e1);
3904   if (sep == ',')
3905     parse_operand (&e2);
3906
3907   if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3908     as_bad ("Both operands of .save.gf must be constants.");
3909   else
3910     {
3911       int grmask = e1.X_add_number;
3912       int frmask = e2.X_add_number;
3913       add_unwind_entry (output_frgr_mem (grmask, frmask));
3914     }
3915 }
3916
3917 static void
3918 dot_spill (dummy)
3919      int dummy ATTRIBUTE_UNUSED;
3920 {
3921   expressionS e;
3922   unsigned char sep;
3923
3924   if (!in_prologue ("spill"))
3925     return;
3926
3927   sep = parse_operand (&e);
3928   if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3929     demand_empty_rest_of_line ();
3930
3931   if (e.X_op != O_constant)
3932     as_bad ("Operand to .spill must be a constant");
3933   else
3934     add_unwind_entry (output_spill_base (e.X_add_number));
3935 }
3936
3937 static void
3938 dot_spillreg (dummy)
3939      int dummy ATTRIBUTE_UNUSED;
3940 {
3941   int sep;
3942   unsigned int ab, xy, reg, treg;
3943   expressionS e1, e2;
3944
3945   if (!in_procedure ("spillreg"))
3946     return;
3947
3948   sep = parse_operand (&e1);
3949   if (sep != ',')
3950     {
3951       as_bad ("No second operand to .spillreg");
3952       return;
3953     }
3954
3955   parse_operand (&e2);
3956
3957   if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3958     {
3959       as_bad ("First operand to .spillreg must be a preserved register");
3960       return;
3961     }
3962
3963   if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3964     {
3965       as_bad ("Second operand to .spillreg must be a register");
3966       return;
3967     }
3968
3969   add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3970 }
3971
3972 static void
3973 dot_spillmem (psprel)
3974      int psprel;
3975 {
3976   expressionS e1, e2;
3977   int sep;
3978   unsigned int ab, reg;
3979
3980   if (!in_procedure ("spillmem"))
3981     return;
3982
3983   sep = parse_operand (&e1);
3984   if (sep != ',')
3985     {
3986       as_bad ("Second operand missing");
3987       return;
3988     }
3989
3990   parse_operand (&e2);
3991
3992   if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3993     {
3994       as_bad ("First operand to .spill%s must be a preserved register",
3995               psprel ? "psp" : "sp");
3996       return;
3997     }
3998
3999   if (e2.X_op != O_constant)
4000     {
4001       as_bad ("Second operand to .spill%s must be a constant",
4002               psprel ? "psp" : "sp");
4003       return;
4004     }
4005
4006   if (psprel)
4007     add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
4008   else
4009     add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
4010 }
4011
4012 static void
4013 dot_spillreg_p (dummy)
4014      int dummy ATTRIBUTE_UNUSED;
4015 {
4016   int sep;
4017   unsigned int ab, xy, reg, treg;
4018   expressionS e1, e2, e3;
4019   unsigned int qp;
4020
4021   if (!in_procedure ("spillreg.p"))
4022     return;
4023
4024   sep = parse_operand (&e1);
4025   if (sep != ',')
4026     {
4027       as_bad ("No second and third operand to .spillreg.p");
4028       return;
4029     }
4030
4031   sep = parse_operand (&e2);
4032   if (sep != ',')
4033     {
4034       as_bad ("No third operand to .spillreg.p");
4035       return;
4036     }
4037
4038   parse_operand (&e3);
4039
4040   qp = e1.X_add_number - REG_P;
4041
4042   if (e1.X_op != O_register || qp > 63)
4043     {
4044       as_bad ("First operand to .spillreg.p must be a predicate");
4045       return;
4046     }
4047
4048   if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
4049     {
4050       as_bad ("Second operand to .spillreg.p must be a preserved register");
4051       return;
4052     }
4053
4054   if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
4055     {
4056       as_bad ("Third operand to .spillreg.p must be a register");
4057       return;
4058     }
4059
4060   add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
4061 }
4062
4063 static void
4064 dot_spillmem_p (psprel)
4065      int psprel;
4066 {
4067   expressionS e1, e2, e3;
4068   int sep;
4069   unsigned int ab, reg;
4070   unsigned int qp;
4071
4072   if (!in_procedure ("spillmem.p"))
4073     return;
4074
4075   sep = parse_operand (&e1);
4076   if (sep != ',')
4077     {
4078       as_bad ("Second operand missing");
4079       return;
4080     }
4081
4082   parse_operand (&e2);
4083   if (sep != ',')
4084     {
4085       as_bad ("Second operand missing");
4086       return;
4087     }
4088
4089   parse_operand (&e3);
4090
4091   qp = e1.X_add_number - REG_P;
4092   if (e1.X_op != O_register || qp > 63)
4093     {
4094       as_bad ("First operand to .spill%s_p must be a predicate",
4095               psprel ? "psp" : "sp");
4096       return;
4097     }
4098
4099   if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
4100     {
4101       as_bad ("Second operand to .spill%s_p must be a preserved register",
4102               psprel ? "psp" : "sp");
4103       return;
4104     }
4105
4106   if (e3.X_op != O_constant)
4107     {
4108       as_bad ("Third operand to .spill%s_p must be a constant",
4109               psprel ? "psp" : "sp");
4110       return;
4111     }
4112
4113   if (psprel)
4114     add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
4115   else
4116     add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
4117 }
4118
4119 static unsigned int
4120 get_saved_prologue_count (lbl)
4121      unsigned long lbl;
4122 {
4123   label_prologue_count *lpc = unwind.saved_prologue_counts;
4124
4125   while (lpc != NULL && lpc->label_number != lbl)
4126     lpc = lpc->next;
4127
4128   if (lpc != NULL)
4129     return lpc->prologue_count;
4130
4131   as_bad ("Missing .label_state %ld", lbl);
4132   return 1;
4133 }
4134
4135 static void
4136 save_prologue_count (lbl, count)
4137      unsigned long lbl;
4138      unsigned int count;
4139 {
4140   label_prologue_count *lpc = unwind.saved_prologue_counts;
4141
4142   while (lpc != NULL && lpc->label_number != lbl)
4143     lpc = lpc->next;
4144
4145   if (lpc != NULL)
4146     lpc->prologue_count = count;
4147   else
4148     {
4149       label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
4150
4151       new_lpc->next = unwind.saved_prologue_counts;
4152       new_lpc->label_number = lbl;
4153       new_lpc->prologue_count = count;
4154       unwind.saved_prologue_counts = new_lpc;
4155     }
4156 }
4157
4158 static void
4159 free_saved_prologue_counts ()
4160 {
4161   label_prologue_count *lpc = unwind.saved_prologue_counts;
4162   label_prologue_count *next;
4163
4164   while (lpc != NULL)
4165     {
4166       next = lpc->next;
4167       free (lpc);
4168       lpc = next;
4169     }
4170
4171   unwind.saved_prologue_counts = NULL;
4172 }
4173
4174 static void
4175 dot_label_state (dummy)
4176      int dummy ATTRIBUTE_UNUSED;
4177 {
4178   expressionS e;
4179
4180   if (!in_body ("label_state"))
4181     return;
4182
4183   parse_operand (&e);
4184   if (e.X_op != O_constant)
4185     {
4186       as_bad ("Operand to .label_state must be a constant");
4187       return;
4188     }
4189   add_unwind_entry (output_label_state (e.X_add_number));
4190   save_prologue_count (e.X_add_number, unwind.prologue_count);
4191 }
4192
4193 static void
4194 dot_copy_state (dummy)
4195      int dummy ATTRIBUTE_UNUSED;
4196 {
4197   expressionS e;
4198
4199   if (!in_body ("copy_state"))
4200     return;
4201
4202   parse_operand (&e);
4203   if (e.X_op != O_constant)
4204     {
4205       as_bad ("Operand to .copy_state must be a constant");
4206       return;
4207     }
4208   add_unwind_entry (output_copy_state (e.X_add_number));
4209   unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
4210 }
4211
4212 static void
4213 dot_unwabi (dummy)
4214      int dummy ATTRIBUTE_UNUSED;
4215 {
4216   expressionS e1, e2;
4217   unsigned char sep;
4218
4219   if (!in_procedure ("unwabi"))
4220     return;
4221
4222   sep = parse_operand (&e1);
4223   if (sep != ',')
4224     {
4225       as_bad ("Second operand to .unwabi missing");
4226       return;
4227     }
4228   sep = parse_operand (&e2);
4229   if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4230     demand_empty_rest_of_line ();
4231
4232   if (e1.X_op != O_constant)
4233     {
4234       as_bad ("First operand to .unwabi must be a constant");
4235       return;
4236     }
4237
4238   if (e2.X_op != O_constant)
4239     {
4240       as_bad ("Second operand to .unwabi must be a constant");
4241       return;
4242     }
4243
4244   add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4245 }
4246
4247 static void
4248 dot_personality (dummy)
4249      int dummy ATTRIBUTE_UNUSED;
4250 {
4251   char *name, *p, c;
4252   if (!in_procedure ("personality"))
4253     return;
4254   SKIP_WHITESPACE ();
4255   name = input_line_pointer;
4256   c = get_symbol_end ();
4257   p = input_line_pointer;
4258   unwind.personality_routine = symbol_find_or_make (name);
4259   unwind.force_unwind_entry = 1;
4260   *p = c;
4261   SKIP_WHITESPACE ();
4262   demand_empty_rest_of_line ();
4263 }
4264
4265 static void
4266 dot_proc (dummy)
4267      int dummy ATTRIBUTE_UNUSED;
4268 {
4269   char *name, *p, c;
4270   symbolS *sym;
4271
4272   unwind.proc_start = 0;
4273   /* Parse names of main and alternate entry points and mark them as
4274      function symbols:  */
4275   while (1)
4276     {
4277       SKIP_WHITESPACE ();
4278       name = input_line_pointer;
4279       c = get_symbol_end ();
4280       p = input_line_pointer;
4281       if (!*name)
4282         as_bad ("Empty argument of .proc");
4283       else
4284         {
4285           sym = symbol_find_or_make (name);
4286           if (S_IS_DEFINED (sym))
4287             as_bad ("`%s' was already defined", name);
4288           else if (unwind.proc_start == 0)
4289             {
4290               unwind.proc_start = sym;
4291             }
4292           symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4293         }
4294       *p = c;
4295       SKIP_WHITESPACE ();
4296       if (*input_line_pointer != ',')
4297         break;
4298       ++input_line_pointer;
4299     }
4300   if (unwind.proc_start == 0)
4301     unwind.proc_start = expr_build_dot ();
4302   demand_empty_rest_of_line ();
4303   ia64_do_align (16);
4304
4305   unwind.prologue = 0;
4306   unwind.prologue_count = 0;
4307   unwind.body = 0;
4308   unwind.insn = 0;
4309   unwind.list = unwind.tail = unwind.current_entry = NULL;
4310   unwind.personality_routine = 0;
4311 }
4312
4313 static void
4314 dot_body (dummy)
4315      int dummy ATTRIBUTE_UNUSED;
4316 {
4317   if (!in_procedure ("body"))
4318     return;
4319   if (!unwind.prologue && !unwind.body && unwind.insn)
4320     as_warn ("Initial .body should precede any instructions");
4321
4322   unwind.prologue = 0;
4323   unwind.prologue_mask = 0;
4324   unwind.body = 1;
4325
4326   add_unwind_entry (output_body ());
4327   demand_empty_rest_of_line ();
4328 }
4329
4330 static void
4331 dot_prologue (dummy)
4332      int dummy ATTRIBUTE_UNUSED;
4333 {
4334   unsigned char sep;
4335   int mask = 0, grsave = 0;
4336
4337   if (!in_procedure ("prologue"))
4338     return;
4339   if (unwind.prologue)
4340     {
4341       as_bad (".prologue within prologue");
4342       ignore_rest_of_line ();
4343       return;
4344     }
4345   if (!unwind.body && unwind.insn)
4346     as_warn ("Initial .prologue should precede any instructions");
4347
4348   if (!is_it_end_of_statement ())
4349     {
4350       expressionS e1, e2;
4351       sep = parse_operand (&e1);
4352       if (sep != ',')
4353         as_bad ("No second operand to .prologue");
4354       sep = parse_operand (&e2);
4355       if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4356         demand_empty_rest_of_line ();
4357
4358       if (e1.X_op == O_constant)
4359         {
4360           mask = e1.X_add_number;
4361
4362           if (e2.X_op == O_constant)
4363             grsave = e2.X_add_number;
4364           else if (e2.X_op == O_register
4365                    && (grsave = e2.X_add_number - REG_GR) < 128)
4366             ;
4367           else
4368             as_bad ("Second operand not a constant or general register");
4369
4370           add_unwind_entry (output_prologue_gr (mask, grsave));
4371         }
4372       else
4373         as_bad ("First operand not a constant");
4374     }
4375   else
4376     add_unwind_entry (output_prologue ());
4377
4378   unwind.prologue = 1;
4379   unwind.prologue_mask = mask;
4380   unwind.body = 0;
4381   ++unwind.prologue_count;
4382 }
4383
4384 static void
4385 dot_endp (dummy)
4386      int dummy ATTRIBUTE_UNUSED;
4387 {
4388   expressionS e;
4389   int bytes_per_address;
4390   long where;
4391   segT saved_seg;
4392   subsegT saved_subseg;
4393   char *name, *default_name, *p, c;
4394   symbolS *sym;
4395   int unwind_check = md.unwind_check;
4396
4397   md.unwind_check = unwind_check_error;
4398   if (!in_procedure ("endp"))
4399     return;
4400   md.unwind_check = unwind_check;
4401
4402   if (unwind.saved_text_seg)
4403     {
4404       saved_seg = unwind.saved_text_seg;
4405       saved_subseg = unwind.saved_text_subseg;
4406       unwind.saved_text_seg = NULL;
4407     }
4408   else
4409     {
4410       saved_seg = now_seg;
4411       saved_subseg = now_subseg;
4412     }
4413
4414   insn_group_break (1, 0, 0);
4415
4416   /* If there wasn't a .handlerdata, we haven't generated an image yet.  */
4417   if (!unwind.info)
4418     generate_unwind_image (saved_seg);
4419
4420   if (unwind.info || unwind.force_unwind_entry)
4421     {
4422       symbolS *proc_end;
4423
4424       subseg_set (md.last_text_seg, 0);
4425       proc_end = expr_build_dot ();
4426
4427       start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND);
4428
4429       /* Make sure that section has 4 byte alignment for ILP32 and
4430          8 byte alignment for LP64.  */
4431       record_alignment (now_seg, md.pointer_size_shift);
4432
4433       /* Need space for 3 pointers for procedure start, procedure end,
4434          and unwind info.  */
4435       memset (frag_more (3 * md.pointer_size), 0, 3 * md.pointer_size);
4436       where = frag_now_fix () - (3 * md.pointer_size);
4437       bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4438
4439       /* Issue the values of  a) Proc Begin, b) Proc End, c) Unwind Record.  */
4440       e.X_op = O_pseudo_fixup;
4441       e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4442       e.X_add_number = 0;
4443       if (!S_IS_LOCAL (unwind.proc_start)
4444           && S_IS_DEFINED (unwind.proc_start))
4445         e.X_add_symbol = symbol_temp_new (S_GET_SEGMENT (unwind.proc_start),
4446                                           S_GET_VALUE (unwind.proc_start),
4447                                           symbol_get_frag (unwind.proc_start));
4448       else
4449         e.X_add_symbol = unwind.proc_start;
4450       ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4451
4452       e.X_op = O_pseudo_fixup;
4453       e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4454       e.X_add_number = 0;
4455       e.X_add_symbol = proc_end;
4456       ia64_cons_fix_new (frag_now, where + bytes_per_address,
4457                          bytes_per_address, &e);
4458
4459       if (unwind.info)
4460         {
4461           e.X_op = O_pseudo_fixup;
4462           e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4463           e.X_add_number = 0;
4464           e.X_add_symbol = unwind.info;
4465           ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4466                              bytes_per_address, &e);
4467         }
4468     }
4469   subseg_set (saved_seg, saved_subseg);
4470
4471   if (unwind.proc_start)
4472     default_name = (char *) S_GET_NAME (unwind.proc_start);
4473   else
4474     default_name = NULL;
4475
4476   /* Parse names of main and alternate entry points and set symbol sizes.  */
4477   while (1)
4478     {
4479       SKIP_WHITESPACE ();
4480       name = input_line_pointer;
4481       c = get_symbol_end ();
4482       p = input_line_pointer;
4483       if (!*name)
4484         {
4485           if (md.unwind_check == unwind_check_warning)
4486             {
4487               if (default_name)
4488                 {
4489                   as_warn ("Empty argument of .endp. Use the default name `%s'",
4490                            default_name);
4491                   name = default_name;
4492                 }
4493               else
4494                 as_warn ("Empty argument of .endp");
4495             }
4496           else
4497             as_bad ("Empty argument of .endp");
4498         }
4499       if (*name)
4500         {
4501           sym = symbol_find (name);
4502           if (!sym
4503               && md.unwind_check == unwind_check_warning
4504               && default_name
4505               && default_name != name)
4506             {
4507               /* We have a bad name. Try the default one if needed.  */
4508               as_warn ("`%s' was not defined within procedure. Use the default name `%s'",
4509                        name, default_name);
4510               name = default_name;
4511               sym = symbol_find (name);
4512             }
4513           if (!sym || !S_IS_DEFINED (sym))
4514             as_bad ("`%s' was not defined within procedure", name);
4515           else if (unwind.proc_start
4516               && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4517               && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4518             {
4519               fragS *fr = symbol_get_frag (unwind.proc_start);
4520               fragS *frag = symbol_get_frag (sym);
4521
4522               /* Check whether the function label is at or beyond last
4523                  .proc directive.  */
4524               while (fr && fr != frag)
4525                 fr = fr->fr_next;
4526               if (fr)
4527                 {
4528                   if (frag == frag_now && SEG_NORMAL (now_seg))
4529                     S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4530                   else
4531                     {
4532                       symbol_get_obj (sym)->size =
4533                         (expressionS *) xmalloc (sizeof (expressionS));
4534                       symbol_get_obj (sym)->size->X_op = O_subtract;
4535                       symbol_get_obj (sym)->size->X_add_symbol
4536                         = symbol_new (FAKE_LABEL_NAME, now_seg,
4537                                       frag_now_fix (), frag_now);
4538                       symbol_get_obj (sym)->size->X_op_symbol = sym;
4539                       symbol_get_obj (sym)->size->X_add_number = 0;
4540                     }
4541                 }
4542             }
4543         }
4544       *p = c;
4545       SKIP_WHITESPACE ();
4546       if (*input_line_pointer != ',')
4547         break;
4548       ++input_line_pointer;
4549     }
4550   demand_empty_rest_of_line ();
4551   unwind.proc_start = unwind.info = 0;
4552 }
4553
4554 static void
4555 dot_template (template)
4556      int template;
4557 {
4558   CURR_SLOT.user_template = template;
4559 }
4560
4561 static void
4562 dot_regstk (dummy)
4563      int dummy ATTRIBUTE_UNUSED;
4564 {
4565   int ins, locs, outs, rots;
4566
4567   if (is_it_end_of_statement ())
4568     ins = locs = outs = rots = 0;
4569   else
4570     {
4571       ins = get_absolute_expression ();
4572       if (*input_line_pointer++ != ',')
4573         goto err;
4574       locs = get_absolute_expression ();
4575       if (*input_line_pointer++ != ',')
4576         goto err;
4577       outs = get_absolute_expression ();
4578       if (*input_line_pointer++ != ',')
4579         goto err;
4580       rots = get_absolute_expression ();
4581     }
4582   set_regstack (ins, locs, outs, rots);
4583   return;
4584
4585  err:
4586   as_bad ("Comma expected");
4587   ignore_rest_of_line ();
4588 }
4589
4590 static void
4591 dot_rot (type)
4592      int type;
4593 {
4594   unsigned num_regs, num_alloced = 0;
4595   struct dynreg **drpp, *dr;
4596   int ch, base_reg = 0;
4597   char *name, *start;
4598   size_t len;
4599
4600   switch (type)
4601     {
4602     case DYNREG_GR: base_reg = REG_GR + 32; break;
4603     case DYNREG_FR: base_reg = REG_FR + 32; break;
4604     case DYNREG_PR: base_reg = REG_P + 16; break;
4605     default: break;
4606     }
4607
4608   /* First, remove existing names from hash table.  */
4609   for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4610     {
4611       hash_delete (md.dynreg_hash, dr->name);
4612       /* FIXME: Free dr->name.  */
4613       dr->num_regs = 0;
4614     }
4615
4616   drpp = &md.dynreg[type];
4617   while (1)
4618     {
4619       start = input_line_pointer;
4620       ch = get_symbol_end ();
4621       len = strlen (ia64_canonicalize_symbol_name (start));
4622       *input_line_pointer = ch;
4623
4624       SKIP_WHITESPACE ();
4625       if (*input_line_pointer != '[')
4626         {
4627           as_bad ("Expected '['");
4628           goto err;
4629         }
4630       ++input_line_pointer;     /* skip '[' */
4631
4632       num_regs = get_absolute_expression ();
4633
4634       if (*input_line_pointer++ != ']')
4635         {
4636           as_bad ("Expected ']'");
4637           goto err;
4638         }
4639       SKIP_WHITESPACE ();
4640
4641       num_alloced += num_regs;
4642       switch (type)
4643         {
4644         case DYNREG_GR:
4645           if (num_alloced > md.rot.num_regs)
4646             {
4647               as_bad ("Used more than the declared %d rotating registers",
4648                       md.rot.num_regs);
4649               goto err;
4650             }
4651           break;
4652         case DYNREG_FR:
4653           if (num_alloced > 96)
4654             {
4655               as_bad ("Used more than the available 96 rotating registers");
4656               goto err;
4657             }
4658           break;
4659         case DYNREG_PR:
4660           if (num_alloced > 48)
4661             {
4662               as_bad ("Used more than the available 48 rotating registers");
4663               goto err;
4664             }
4665           break;
4666
4667         default:
4668           break;
4669         }
4670
4671       if (!*drpp)
4672         {
4673           *drpp = obstack_alloc (&notes, sizeof (*dr));
4674           memset (*drpp, 0, sizeof (*dr));
4675         }
4676
4677       name = obstack_alloc (&notes, len + 1);
4678       memcpy (name, start, len);
4679       name[len] = '\0';
4680
4681       dr = *drpp;
4682       dr->name = name;
4683       dr->num_regs = num_regs;
4684       dr->base = base_reg;
4685       drpp = &dr->next;
4686       base_reg += num_regs;
4687
4688       if (hash_insert (md.dynreg_hash, name, dr))
4689         {
4690           as_bad ("Attempt to redefine register set `%s'", name);
4691           obstack_free (&notes, name);
4692           goto err;
4693         }
4694
4695       if (*input_line_pointer != ',')
4696         break;
4697       ++input_line_pointer;     /* skip comma */
4698       SKIP_WHITESPACE ();
4699     }
4700   demand_empty_rest_of_line ();
4701   return;
4702
4703  err:
4704   ignore_rest_of_line ();
4705 }
4706
4707 static void
4708 dot_byteorder (byteorder)
4709      int byteorder;
4710 {
4711   segment_info_type *seginfo = seg_info (now_seg);
4712
4713   if (byteorder == -1)
4714     {
4715       if (seginfo->tc_segment_info_data.endian == 0)
4716         seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2;
4717       byteorder = seginfo->tc_segment_info_data.endian == 1;
4718     }
4719   else
4720     seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4721
4722   if (target_big_endian != byteorder)
4723     {
4724       target_big_endian = byteorder;
4725       if (target_big_endian)
4726         {
4727           ia64_number_to_chars = number_to_chars_bigendian;
4728           ia64_float_to_chars = ia64_float_to_chars_bigendian;
4729         }
4730       else
4731         {
4732           ia64_number_to_chars = number_to_chars_littleendian;
4733           ia64_float_to_chars = ia64_float_to_chars_littleendian;
4734         }
4735     }
4736 }
4737
4738 static void
4739 dot_psr (dummy)
4740      int dummy ATTRIBUTE_UNUSED;
4741 {
4742   char *option;
4743   int ch;
4744
4745   while (1)
4746     {
4747       option = input_line_pointer;
4748       ch = get_symbol_end ();
4749       if (strcmp (option, "lsb") == 0)
4750         md.flags &= ~EF_IA_64_BE;
4751       else if (strcmp (option, "msb") == 0)
4752         md.flags |= EF_IA_64_BE;
4753       else if (strcmp (option, "abi32") == 0)
4754         md.flags &= ~EF_IA_64_ABI64;
4755       else if (strcmp (option, "abi64") == 0)
4756         md.flags |= EF_IA_64_ABI64;
4757       else
4758         as_bad ("Unknown psr option `%s'", option);
4759       *input_line_pointer = ch;
4760
4761       SKIP_WHITESPACE ();
4762       if (*input_line_pointer != ',')
4763         break;
4764
4765       ++input_line_pointer;
4766       SKIP_WHITESPACE ();
4767     }
4768   demand_empty_rest_of_line ();
4769 }
4770
4771 static void
4772 dot_ln (dummy)
4773      int dummy ATTRIBUTE_UNUSED;
4774 {
4775   new_logical_line (0, get_absolute_expression ());
4776   demand_empty_rest_of_line ();
4777 }
4778
4779 static void
4780 cross_section (ref, cons, ua)
4781      int ref;
4782      void (*cons) PARAMS((int));
4783      int ua;
4784 {
4785   char *start, *end;
4786   int saved_auto_align;
4787   unsigned int section_count;
4788
4789   SKIP_WHITESPACE ();
4790   start = input_line_pointer;
4791   if (*start == '"')
4792     {
4793       int len;
4794       char *name;
4795
4796       name = demand_copy_C_string (&len);
4797       obstack_free(&notes, name);
4798       if (!name)
4799         {
4800           ignore_rest_of_line ();
4801           return;
4802         }
4803     }
4804   else
4805     {
4806       char c = get_symbol_end ();
4807
4808       if (input_line_pointer == start)
4809         {
4810           as_bad ("Missing section name");
4811           ignore_rest_of_line ();
4812           return;
4813         }
4814       *input_line_pointer = c;
4815     }
4816   end = input_line_pointer;
4817   SKIP_WHITESPACE ();
4818   if (*input_line_pointer != ',')
4819     {
4820       as_bad ("Comma expected after section name");
4821       ignore_rest_of_line ();
4822       return;
4823     }
4824   *end = '\0';
4825   end = input_line_pointer + 1;         /* skip comma */
4826   input_line_pointer = start;
4827   md.keep_pending_output = 1;
4828   section_count = bfd_count_sections(stdoutput);
4829   obj_elf_section (0);
4830   if (section_count != bfd_count_sections(stdoutput))
4831     as_warn ("Creating sections with .xdataN/.xrealN/.xstringZ is deprecated.");
4832   input_line_pointer = end;
4833   saved_auto_align = md.auto_align;
4834   if (ua)
4835     md.auto_align = 0;
4836   (*cons) (ref);
4837   if (ua)
4838     md.auto_align = saved_auto_align;
4839   obj_elf_previous (0);
4840   md.keep_pending_output = 0;
4841 }
4842
4843 static void
4844 dot_xdata (size)
4845      int size;
4846 {
4847   cross_section (size, cons, 0);
4848 }
4849
4850 /* Why doesn't float_cons() call md_cons_align() the way cons() does?  */
4851
4852 static void
4853 stmt_float_cons (kind)
4854      int kind;
4855 {
4856   size_t alignment;
4857
4858   switch (kind)
4859     {
4860     case 'd':
4861       alignment = 8;
4862       break;
4863
4864     case 'x':
4865     case 'X':
4866       alignment = 16;
4867       break;
4868
4869     case 'f':
4870     default:
4871       alignment = 4;
4872       break;
4873     }
4874   ia64_do_align (alignment);
4875   float_cons (kind);
4876 }
4877
4878 static void
4879 stmt_cons_ua (size)
4880      int size;
4881 {
4882   int saved_auto_align = md.auto_align;
4883
4884   md.auto_align = 0;
4885   cons (size);
4886   md.auto_align = saved_auto_align;
4887 }
4888
4889 static void
4890 dot_xfloat_cons (kind)
4891      int kind;
4892 {
4893   cross_section (kind, stmt_float_cons, 0);
4894 }
4895
4896 static void
4897 dot_xstringer (zero)
4898      int zero;
4899 {
4900   cross_section (zero, stringer, 0);
4901 }
4902
4903 static void
4904 dot_xdata_ua (size)
4905      int size;
4906 {
4907   cross_section (size, cons, 1);
4908 }
4909
4910 static void
4911 dot_xfloat_cons_ua (kind)
4912      int kind;
4913 {
4914   cross_section (kind, float_cons, 1);
4915 }
4916
4917 /* .reg.val <regname>,value */
4918
4919 static void
4920 dot_reg_val (dummy)
4921      int dummy ATTRIBUTE_UNUSED;
4922 {
4923   expressionS reg;
4924
4925   expression (&reg);
4926   if (reg.X_op != O_register)
4927     {
4928       as_bad (_("Register name expected"));
4929       ignore_rest_of_line ();
4930     }
4931   else if (*input_line_pointer++ != ',')
4932     {
4933       as_bad (_("Comma expected"));
4934       ignore_rest_of_line ();
4935     }
4936   else
4937     {
4938       valueT value = get_absolute_expression ();
4939       int regno = reg.X_add_number;
4940       if (regno <= REG_GR || regno > REG_GR + 127)
4941         as_warn (_("Register value annotation ignored"));
4942       else
4943         {
4944           gr_values[regno - REG_GR].known = 1;
4945           gr_values[regno - REG_GR].value = value;
4946           gr_values[regno - REG_GR].path = md.path;
4947         }
4948     }
4949   demand_empty_rest_of_line ();
4950 }
4951
4952 /*
4953   .serialize.data
4954   .serialize.instruction
4955  */
4956 static void
4957 dot_serialize (type)
4958      int type;
4959 {
4960   insn_group_break (0, 0, 0);
4961   if (type)
4962     instruction_serialization ();
4963   else
4964     data_serialization ();
4965   insn_group_break (0, 0, 0);
4966   demand_empty_rest_of_line ();
4967 }
4968
4969 /* select dv checking mode
4970    .auto
4971    .explicit
4972    .default
4973
4974    A stop is inserted when changing modes
4975  */
4976
4977 static void
4978 dot_dv_mode (type)
4979      int type;
4980 {
4981   if (md.manual_bundling)
4982     as_warn (_("Directive invalid within a bundle"));
4983
4984   if (type == 'E' || type == 'A')
4985     md.mode_explicitly_set = 0;
4986   else
4987     md.mode_explicitly_set = 1;
4988
4989   md.detect_dv = 1;
4990   switch (type)
4991     {
4992     case 'A':
4993     case 'a':
4994       if (md.explicit_mode)
4995         insn_group_break (1, 0, 0);
4996       md.explicit_mode = 0;
4997       break;
4998     case 'E':
4999     case 'e':
5000       if (!md.explicit_mode)
5001         insn_group_break (1, 0, 0);
5002       md.explicit_mode = 1;
5003       break;
5004     default:
5005     case 'd':
5006       if (md.explicit_mode != md.default_explicit_mode)
5007         insn_group_break (1, 0, 0);
5008       md.explicit_mode = md.default_explicit_mode;
5009       md.mode_explicitly_set = 0;
5010       break;
5011     }
5012 }
5013
5014 static void
5015 print_prmask (mask)
5016      valueT mask;
5017 {
5018   int regno;
5019   char *comma = "";
5020   for (regno = 0; regno < 64; regno++)
5021     {
5022       if (mask & ((valueT) 1 << regno))
5023         {
5024           fprintf (stderr, "%s p%d", comma, regno);
5025           comma = ",";
5026         }
5027     }
5028 }
5029
5030 /*
5031   .pred.rel.clear [p1 [,p2 [,...]]]     (also .pred.rel "clear" or @clear)
5032   .pred.rel.imply p1, p2                (also .pred.rel "imply" or @imply)
5033   .pred.rel.mutex p1, p2 [,...]         (also .pred.rel "mutex" or @mutex)
5034   .pred.safe_across_calls p1 [, p2 [,...]]
5035  */
5036
5037 static void
5038 dot_pred_rel (type)
5039      int type;
5040 {
5041   valueT mask = 0;
5042   int count = 0;
5043   int p1 = -1, p2 = -1;
5044
5045   if (type == 0)
5046     {
5047       if (*input_line_pointer == '"')
5048         {
5049           int len;
5050           char *form = demand_copy_C_string (&len);
5051
5052           if (strcmp (form, "mutex") == 0)
5053             type = 'm';
5054           else if (strcmp (form, "clear") == 0)
5055             type = 'c';
5056           else if (strcmp (form, "imply") == 0)
5057             type = 'i';
5058           obstack_free (&notes, form);
5059         }
5060       else if (*input_line_pointer == '@')
5061         {
5062           char *form = ++input_line_pointer;
5063           char c = get_symbol_end();
5064
5065           if (strcmp (form, "mutex") == 0)
5066             type = 'm';
5067           else if (strcmp (form, "clear") == 0)
5068             type = 'c';
5069           else if (strcmp (form, "imply") == 0)
5070             type = 'i';
5071           *input_line_pointer = c;
5072         }
5073       else
5074         {
5075           as_bad (_("Missing predicate relation type"));
5076           ignore_rest_of_line ();
5077           return;
5078         }
5079       if (type == 0)
5080         {
5081           as_bad (_("Unrecognized predicate relation type"));
5082           ignore_rest_of_line ();
5083           return;
5084         }
5085       if (*input_line_pointer == ',')
5086         ++input_line_pointer;
5087       SKIP_WHITESPACE ();
5088     }
5089
5090   SKIP_WHITESPACE ();
5091   while (1)
5092     {
5093       valueT bits = 1;
5094       int regno;
5095       expressionS pr, *pr1, *pr2;
5096
5097       expression (&pr);
5098       if (pr.X_op == O_register
5099           && pr.X_add_number >= REG_P
5100           && pr.X_add_number <= REG_P + 63)
5101         {
5102           regno = pr.X_add_number - REG_P;
5103           bits <<= regno;
5104           count++;
5105           if (p1 == -1)
5106             p1 = regno;
5107           else if (p2 == -1)
5108             p2 = regno;
5109         }
5110       else if (type != 'i'
5111           && pr.X_op == O_subtract
5112           && (pr1 = symbol_get_value_expression (pr.X_add_symbol))
5113           && pr1->X_op == O_register
5114           && pr1->X_add_number >= REG_P
5115           && pr1->X_add_number <= REG_P + 63
5116           && (pr2 = symbol_get_value_expression (pr.X_op_symbol))
5117           && pr2->X_op == O_register
5118           && pr2->X_add_number >= REG_P
5119           && pr2->X_add_number <= REG_P + 63)
5120         {
5121           /* It's a range.  */
5122           int stop;
5123
5124           regno = pr1->X_add_number - REG_P;
5125           stop = pr2->X_add_number - REG_P;
5126           if (regno >= stop)
5127             {
5128               as_bad (_("Bad register range"));
5129               ignore_rest_of_line ();
5130               return;
5131             }
5132           bits = ((bits << stop) << 1) - (bits << regno);
5133           count += stop - regno + 1;
5134         }
5135       else
5136         {
5137           as_bad (_("Predicate register expected"));
5138           ignore_rest_of_line ();
5139           return;
5140         }
5141       if (mask & bits)
5142         as_warn (_("Duplicate predicate register ignored"));
5143       mask |= bits;
5144       if (*input_line_pointer != ',')
5145         break;
5146       ++input_line_pointer;
5147       SKIP_WHITESPACE ();
5148     }
5149
5150   switch (type)
5151     {
5152     case 'c':
5153       if (count == 0)
5154         mask = ~(valueT) 0;
5155       clear_qp_mutex (mask);
5156       clear_qp_implies (mask, (valueT) 0);
5157       break;
5158     case 'i':
5159       if (count != 2 || p1 == -1 || p2 == -1)
5160         as_bad (_("Predicate source and target required"));
5161       else if (p1 == 0 || p2 == 0)
5162         as_bad (_("Use of p0 is not valid in this context"));
5163       else
5164         add_qp_imply (p1, p2);
5165       break;
5166     case 'm':
5167       if (count < 2)
5168         {
5169           as_bad (_("At least two PR arguments expected"));
5170           break;
5171         }
5172       else if (mask & 1)
5173         {
5174           as_bad (_("Use of p0 is not valid in this context"));
5175           break;
5176         }
5177       add_qp_mutex (mask);
5178       break;
5179     case 's':
5180       /* note that we don't override any existing relations */
5181       if (count == 0)
5182         {
5183           as_bad (_("At least one PR argument expected"));
5184           break;
5185         }
5186       if (md.debug_dv)
5187         {
5188           fprintf (stderr, "Safe across calls: ");
5189           print_prmask (mask);
5190           fprintf (stderr, "\n");
5191         }
5192       qp_safe_across_calls = mask;
5193       break;
5194     }
5195   demand_empty_rest_of_line ();
5196 }
5197
5198 /* .entry label [, label [, ...]]
5199    Hint to DV code that the given labels are to be considered entry points.
5200    Otherwise, only global labels are considered entry points.  */
5201
5202 static void
5203 dot_entry (dummy)
5204      int dummy ATTRIBUTE_UNUSED;
5205 {
5206   const char *err;
5207   char *name;
5208   int c;
5209   symbolS *symbolP;
5210
5211   do
5212     {
5213       name = input_line_pointer;
5214       c = get_symbol_end ();
5215       symbolP = symbol_find_or_make (name);
5216
5217       err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
5218       if (err)
5219         as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
5220                   name, err);
5221
5222       *input_line_pointer = c;
5223       SKIP_WHITESPACE ();
5224       c = *input_line_pointer;
5225       if (c == ',')
5226         {
5227           input_line_pointer++;
5228           SKIP_WHITESPACE ();
5229           if (*input_line_pointer == '\n')
5230             c = '\n';
5231         }
5232     }
5233   while (c == ',');
5234
5235   demand_empty_rest_of_line ();
5236 }
5237
5238 /* .mem.offset offset, base
5239    "base" is used to distinguish between offsets from a different base.  */
5240
5241 static void
5242 dot_mem_offset (dummy)
5243   int dummy ATTRIBUTE_UNUSED;
5244 {
5245   md.mem_offset.hint = 1;
5246   md.mem_offset.offset = get_absolute_expression ();
5247   if (*input_line_pointer != ',')
5248     {
5249       as_bad (_("Comma expected"));
5250       ignore_rest_of_line ();
5251       return;
5252     }
5253   ++input_line_pointer;
5254   md.mem_offset.base = get_absolute_expression ();
5255   demand_empty_rest_of_line ();
5256 }
5257
5258 /* ia64-specific pseudo-ops:  */
5259 const pseudo_typeS md_pseudo_table[] =
5260   {
5261     { "radix", dot_radix, 0 },
5262     { "lcomm", s_lcomm_bytes, 1 },
5263     { "loc", dot_loc, 0 },
5264     { "bss", dot_special_section, SPECIAL_SECTION_BSS },
5265     { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
5266     { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
5267     { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
5268     { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
5269     { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
5270     { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
5271     { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
5272     { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
5273     { "proc", dot_proc, 0 },
5274     { "body", dot_body, 0 },
5275     { "prologue", dot_prologue, 0 },
5276     { "endp", dot_endp, 0 },
5277
5278     { "fframe", dot_fframe, 0 },
5279     { "vframe", dot_vframe, 0 },
5280     { "vframesp", dot_vframesp, 0 },
5281     { "vframepsp", dot_vframepsp, 0 },
5282     { "save", dot_save, 0 },
5283     { "restore", dot_restore, 0 },
5284     { "restorereg", dot_restorereg, 0 },
5285     { "restorereg.p", dot_restorereg_p, 0 },
5286     { "handlerdata", dot_handlerdata, 0 },
5287     { "unwentry", dot_unwentry, 0 },
5288     { "altrp", dot_altrp, 0 },
5289     { "savesp", dot_savemem, 0 },
5290     { "savepsp", dot_savemem, 1 },
5291     { "save.g", dot_saveg, 0 },
5292     { "save.f", dot_savef, 0 },
5293     { "save.b", dot_saveb, 0 },
5294     { "save.gf", dot_savegf, 0 },
5295     { "spill", dot_spill, 0 },
5296     { "spillreg", dot_spillreg, 0 },
5297     { "spillsp", dot_spillmem, 0 },
5298     { "spillpsp", dot_spillmem, 1 },
5299     { "spillreg.p", dot_spillreg_p, 0 },
5300     { "spillsp.p", dot_spillmem_p, 0 },
5301     { "spillpsp.p", dot_spillmem_p, 1 },
5302     { "label_state", dot_label_state, 0 },
5303     { "copy_state", dot_copy_state, 0 },
5304     { "unwabi", dot_unwabi, 0 },
5305     { "personality", dot_personality, 0 },
5306     { "mii", dot_template, 0x0 },
5307     { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5308     { "mlx", dot_template, 0x2 },
5309     { "mmi", dot_template, 0x4 },
5310     { "mfi", dot_template, 0x6 },
5311     { "mmf", dot_template, 0x7 },
5312     { "mib", dot_template, 0x8 },
5313     { "mbb", dot_template, 0x9 },
5314     { "bbb", dot_template, 0xb },
5315     { "mmb", dot_template, 0xc },
5316     { "mfb", dot_template, 0xe },
5317     { "align", dot_align, 0 },
5318     { "regstk", dot_regstk, 0 },
5319     { "rotr", dot_rot, DYNREG_GR },
5320     { "rotf", dot_rot, DYNREG_FR },
5321     { "rotp", dot_rot, DYNREG_PR },
5322     { "lsb", dot_byteorder, 0 },
5323     { "msb", dot_byteorder, 1 },
5324     { "psr", dot_psr, 0 },
5325     { "alias", dot_alias, 0 },
5326     { "secalias", dot_alias, 1 },
5327     { "ln", dot_ln, 0 },                /* source line info (for debugging) */
5328
5329     { "xdata1", dot_xdata, 1 },
5330     { "xdata2", dot_xdata, 2 },
5331     { "xdata4", dot_xdata, 4 },
5332     { "xdata8", dot_xdata, 8 },
5333     { "xdata16", dot_xdata, 16 },
5334     { "xreal4", dot_xfloat_cons, 'f' },
5335     { "xreal8", dot_xfloat_cons, 'd' },
5336     { "xreal10", dot_xfloat_cons, 'x' },
5337     { "xreal16", dot_xfloat_cons, 'X' },
5338     { "xstring", dot_xstringer, 0 },
5339     { "xstringz", dot_xstringer, 1 },
5340
5341     /* unaligned versions:  */
5342     { "xdata2.ua", dot_xdata_ua, 2 },
5343     { "xdata4.ua", dot_xdata_ua, 4 },
5344     { "xdata8.ua", dot_xdata_ua, 8 },
5345     { "xdata16.ua", dot_xdata_ua, 16 },
5346     { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5347     { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5348     { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5349     { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5350
5351     /* annotations/DV checking support */
5352     { "entry", dot_entry, 0 },
5353     { "mem.offset", dot_mem_offset, 0 },
5354     { "pred.rel", dot_pred_rel, 0 },
5355     { "pred.rel.clear", dot_pred_rel, 'c' },
5356     { "pred.rel.imply", dot_pred_rel, 'i' },
5357     { "pred.rel.mutex", dot_pred_rel, 'm' },
5358     { "pred.safe_across_calls", dot_pred_rel, 's' },
5359     { "reg.val", dot_reg_val, 0 },
5360     { "serialize.data", dot_serialize, 0 },
5361     { "serialize.instruction", dot_serialize, 1 },
5362     { "auto", dot_dv_mode, 'a' },
5363     { "explicit", dot_dv_mode, 'e' },
5364     { "default", dot_dv_mode, 'd' },
5365
5366     /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5367        IA-64 aligns data allocation pseudo-ops by default, so we have to
5368        tell it that these ones are supposed to be unaligned.  Long term,
5369        should rewrite so that only IA-64 specific data allocation pseudo-ops
5370        are aligned by default.  */
5371     {"2byte", stmt_cons_ua, 2},
5372     {"4byte", stmt_cons_ua, 4},
5373     {"8byte", stmt_cons_ua, 8},
5374
5375     { NULL, 0, 0 }
5376   };
5377
5378 static const struct pseudo_opcode
5379   {
5380     const char *name;
5381     void (*handler) (int);
5382     int arg;
5383   }
5384 pseudo_opcode[] =
5385   {
5386     /* these are more like pseudo-ops, but don't start with a dot */
5387     { "data1", cons, 1 },
5388     { "data2", cons, 2 },
5389     { "data4", cons, 4 },
5390     { "data8", cons, 8 },
5391     { "data16", cons, 16 },
5392     { "real4", stmt_float_cons, 'f' },
5393     { "real8", stmt_float_cons, 'd' },
5394     { "real10", stmt_float_cons, 'x' },
5395     { "real16", stmt_float_cons, 'X' },
5396     { "string", stringer, 0 },
5397     { "stringz", stringer, 1 },
5398
5399     /* unaligned versions:  */
5400     { "data2.ua", stmt_cons_ua, 2 },
5401     { "data4.ua", stmt_cons_ua, 4 },
5402     { "data8.ua", stmt_cons_ua, 8 },
5403     { "data16.ua", stmt_cons_ua, 16 },
5404     { "real4.ua", float_cons, 'f' },
5405     { "real8.ua", float_cons, 'd' },
5406     { "real10.ua", float_cons, 'x' },
5407     { "real16.ua", float_cons, 'X' },
5408   };
5409
5410 /* Declare a register by creating a symbol for it and entering it in
5411    the symbol table.  */
5412
5413 static symbolS *
5414 declare_register (name, regnum)
5415      const char *name;
5416      int regnum;
5417 {
5418   const char *err;
5419   symbolS *sym;
5420
5421   sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5422
5423   err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5424   if (err)
5425     as_fatal ("Inserting \"%s\" into register table failed: %s",
5426               name, err);
5427
5428   return sym;
5429 }
5430
5431 static void
5432 declare_register_set (prefix, num_regs, base_regnum)
5433      const char *prefix;
5434      int num_regs;
5435      int base_regnum;
5436 {
5437   char name[8];
5438   int i;
5439
5440   for (i = 0; i < num_regs; ++i)
5441     {
5442       sprintf (name, "%s%u", prefix, i);
5443       declare_register (name, base_regnum + i);
5444     }
5445 }
5446
5447 static unsigned int
5448 operand_width (opnd)
5449      enum ia64_opnd opnd;
5450 {
5451   const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5452   unsigned int bits = 0;
5453   int i;
5454
5455   bits = 0;
5456   for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5457     bits += odesc->field[i].bits;
5458
5459   return bits;
5460 }
5461
5462 static enum operand_match_result
5463 operand_match (idesc, index, e)
5464      const struct ia64_opcode *idesc;
5465      int index;
5466      expressionS *e;
5467 {
5468   enum ia64_opnd opnd = idesc->operands[index];
5469   int bits, relocatable = 0;
5470   struct insn_fix *fix;
5471   bfd_signed_vma val;
5472
5473   switch (opnd)
5474     {
5475       /* constants:  */
5476
5477     case IA64_OPND_AR_CCV:
5478       if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5479         return OPERAND_MATCH;
5480       break;
5481
5482     case IA64_OPND_AR_CSD:
5483       if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5484         return OPERAND_MATCH;
5485       break;
5486
5487     case IA64_OPND_AR_PFS:
5488       if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5489         return OPERAND_MATCH;
5490       break;
5491
5492     case IA64_OPND_GR0:
5493       if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5494         return OPERAND_MATCH;
5495       break;
5496
5497     case IA64_OPND_IP:
5498       if (e->X_op == O_register && e->X_add_number == REG_IP)
5499         return OPERAND_MATCH;
5500       break;
5501
5502     case IA64_OPND_PR:
5503       if (e->X_op == O_register && e->X_add_number == REG_PR)
5504         return OPERAND_MATCH;
5505       break;
5506
5507     case IA64_OPND_PR_ROT:
5508       if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5509         return OPERAND_MATCH;
5510       break;
5511
5512     case IA64_OPND_PSR:
5513       if (e->X_op == O_register && e->X_add_number == REG_PSR)
5514         return OPERAND_MATCH;
5515       break;
5516
5517     case IA64_OPND_PSR_L:
5518       if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5519         return OPERAND_MATCH;
5520       break;
5521
5522     case IA64_OPND_PSR_UM:
5523       if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5524         return OPERAND_MATCH;
5525       break;
5526
5527     case IA64_OPND_C1:
5528       if (e->X_op == O_constant)
5529         {
5530           if (e->X_add_number == 1)
5531             return OPERAND_MATCH;
5532           else
5533             return OPERAND_OUT_OF_RANGE;
5534         }
5535       break;
5536
5537     case IA64_OPND_C8:
5538       if (e->X_op == O_constant)
5539         {
5540           if (e->X_add_number == 8)
5541             return OPERAND_MATCH;
5542           else
5543             return OPERAND_OUT_OF_RANGE;
5544         }
5545       break;
5546
5547     case IA64_OPND_C16:
5548       if (e->X_op == O_constant)
5549         {
5550           if (e->X_add_number == 16)
5551             return OPERAND_MATCH;
5552           else
5553             return OPERAND_OUT_OF_RANGE;
5554         }
5555       break;
5556
5557       /* register operands:  */
5558
5559     case IA64_OPND_AR3:
5560       if (e->X_op == O_register && e->X_add_number >= REG_AR
5561           && e->X_add_number < REG_AR + 128)
5562         return OPERAND_MATCH;
5563       break;
5564
5565     case IA64_OPND_B1:
5566     case IA64_OPND_B2:
5567       if (e->X_op == O_register && e->X_add_number >= REG_BR
5568           && e->X_add_number < REG_BR + 8)
5569         return OPERAND_MATCH;
5570       break;
5571
5572     case IA64_OPND_CR3:
5573       if (e->X_op == O_register && e->X_add_number >= REG_CR
5574           && e->X_add_number < REG_CR + 128)
5575         return OPERAND_MATCH;
5576       break;
5577
5578     case IA64_OPND_F1:
5579     case IA64_OPND_F2:
5580     case IA64_OPND_F3:
5581     case IA64_OPND_F4:
5582       if (e->X_op == O_register && e->X_add_number >= REG_FR
5583           && e->X_add_number < REG_FR + 128)
5584         return OPERAND_MATCH;
5585       break;
5586
5587     case IA64_OPND_P1:
5588     case IA64_OPND_P2:
5589       if (e->X_op == O_register && e->X_add_number >= REG_P
5590           && e->X_add_number < REG_P + 64)
5591         return OPERAND_MATCH;
5592       break;
5593
5594     case IA64_OPND_R1:
5595     case IA64_OPND_R2:
5596     case IA64_OPND_R3:
5597       if (e->X_op == O_register && e->X_add_number >= REG_GR
5598           && e->X_add_number < REG_GR + 128)
5599         return OPERAND_MATCH;
5600       break;
5601
5602     case IA64_OPND_R3_2:
5603       if (e->X_op == O_register && e->X_add_number >= REG_GR)
5604         {
5605           if (e->X_add_number < REG_GR + 4)
5606             return OPERAND_MATCH;
5607           else if (e->X_add_number < REG_GR + 128)
5608             return OPERAND_OUT_OF_RANGE;
5609         }
5610       break;
5611
5612       /* indirect operands:  */
5613     case IA64_OPND_CPUID_R3:
5614     case IA64_OPND_DBR_R3:
5615     case IA64_OPND_DTR_R3:
5616     case IA64_OPND_ITR_R3:
5617     case IA64_OPND_IBR_R3:
5618     case IA64_OPND_MSR_R3:
5619     case IA64_OPND_PKR_R3:
5620     case IA64_OPND_PMC_R3:
5621     case IA64_OPND_PMD_R3:
5622     case IA64_OPND_RR_R3:
5623       if (e->X_op == O_index && e->X_op_symbol
5624           && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5625               == opnd - IA64_OPND_CPUID_R3))
5626         return OPERAND_MATCH;
5627       break;
5628
5629     case IA64_OPND_MR3:
5630       if (e->X_op == O_index && !e->X_op_symbol)
5631         return OPERAND_MATCH;
5632       break;
5633
5634       /* immediate operands:  */
5635     case IA64_OPND_CNT2a:
5636     case IA64_OPND_LEN4:
5637     case IA64_OPND_LEN6:
5638       bits = operand_width (idesc->operands[index]);
5639       if (e->X_op == O_constant)
5640         {
5641           if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5642             return OPERAND_MATCH;
5643           else
5644             return OPERAND_OUT_OF_RANGE;
5645         }
5646       break;
5647
5648     case IA64_OPND_CNT2b:
5649       if (e->X_op == O_constant)
5650         {
5651           if ((bfd_vma) (e->X_add_number - 1) < 3)
5652             return OPERAND_MATCH;
5653           else
5654             return OPERAND_OUT_OF_RANGE;
5655         }
5656       break;
5657
5658     case IA64_OPND_CNT2c:
5659       val = e->X_add_number;
5660       if (e->X_op == O_constant)
5661         {
5662           if ((val == 0 || val == 7 || val == 15 || val == 16))
5663             return OPERAND_MATCH;
5664           else
5665             return OPERAND_OUT_OF_RANGE;
5666         }
5667       break;
5668
5669     case IA64_OPND_SOR:
5670       /* SOR must be an integer multiple of 8 */
5671       if (e->X_op == O_constant && e->X_add_number & 0x7)
5672         return OPERAND_OUT_OF_RANGE;
5673     case IA64_OPND_SOF:
5674     case IA64_OPND_SOL:
5675       if (e->X_op == O_constant)
5676         {
5677           if ((bfd_vma) e->X_add_number <= 96)
5678             return OPERAND_MATCH;
5679           else
5680             return OPERAND_OUT_OF_RANGE;
5681         }
5682       break;
5683
5684     case IA64_OPND_IMMU62:
5685       if (e->X_op == O_constant)
5686         {
5687           if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5688             return OPERAND_MATCH;
5689           else
5690             return OPERAND_OUT_OF_RANGE;
5691         }
5692       else
5693         {
5694           /* FIXME -- need 62-bit relocation type */
5695           as_bad (_("62-bit relocation not yet implemented"));
5696         }
5697       break;
5698
5699     case IA64_OPND_IMMU64:
5700       if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5701           || e->X_op == O_subtract)
5702         {
5703           fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5704           fix->code = BFD_RELOC_IA64_IMM64;
5705           if (e->X_op != O_subtract)
5706             {
5707               fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5708               if (e->X_op == O_pseudo_fixup)
5709                 e->X_op = O_symbol;
5710             }
5711
5712           fix->opnd = idesc->operands[index];
5713           fix->expr = *e;
5714           fix->is_pcrel = 0;
5715           ++CURR_SLOT.num_fixups;
5716           return OPERAND_MATCH;
5717         }
5718       else if (e->X_op == O_constant)
5719         return OPERAND_MATCH;
5720       break;
5721
5722     case IA64_OPND_CCNT5:
5723     case IA64_OPND_CNT5:
5724     case IA64_OPND_CNT6:
5725     case IA64_OPND_CPOS6a:
5726     case IA64_OPND_CPOS6b:
5727     case IA64_OPND_CPOS6c:
5728     case IA64_OPND_IMMU2:
5729     case IA64_OPND_IMMU7a:
5730     case IA64_OPND_IMMU7b:
5731     case IA64_OPND_IMMU21:
5732     case IA64_OPND_IMMU24:
5733     case IA64_OPND_MBTYPE4:
5734     case IA64_OPND_MHTYPE8:
5735     case IA64_OPND_POS6:
5736       bits = operand_width (idesc->operands[index]);
5737       if (e->X_op == O_constant)
5738         {
5739           if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5740             return OPERAND_MATCH;
5741           else
5742             return OPERAND_OUT_OF_RANGE;
5743         }
5744       break;
5745
5746     case IA64_OPND_IMMU9:
5747       bits = operand_width (idesc->operands[index]);
5748       if (e->X_op == O_constant)
5749         {
5750           if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5751             {
5752               int lobits = e->X_add_number & 0x3;
5753               if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5754                 e->X_add_number |= (bfd_vma) 0x3;
5755               return OPERAND_MATCH;
5756             }
5757           else
5758             return OPERAND_OUT_OF_RANGE;
5759         }
5760       break;
5761
5762     case IA64_OPND_IMM44:
5763       /* least 16 bits must be zero */
5764       if ((e->X_add_number & 0xffff) != 0)
5765         /* XXX technically, this is wrong: we should not be issuing warning
5766            messages until we're sure this instruction pattern is going to
5767            be used! */
5768         as_warn (_("lower 16 bits of mask ignored"));
5769
5770       if (e->X_op == O_constant)
5771         {
5772           if (((e->X_add_number >= 0
5773                 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5774                || (e->X_add_number < 0
5775                    && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5776             {
5777               /* sign-extend */
5778               if (e->X_add_number >= 0
5779                   && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5780                 {
5781                   e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5782                 }
5783               return OPERAND_MATCH;
5784             }
5785           else
5786             return OPERAND_OUT_OF_RANGE;
5787         }
5788       break;
5789
5790     case IA64_OPND_IMM17:
5791       /* bit 0 is a don't care (pr0 is hardwired to 1) */
5792       if (e->X_op == O_constant)
5793         {
5794           if (((e->X_add_number >= 0
5795                 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5796                || (e->X_add_number < 0
5797                    && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5798             {
5799               /* sign-extend */
5800               if (e->X_add_number >= 0
5801                   && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5802                 {
5803                   e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5804                 }
5805               return OPERAND_MATCH;
5806             }
5807           else
5808             return OPERAND_OUT_OF_RANGE;
5809         }
5810       break;
5811
5812     case IA64_OPND_IMM14:
5813     case IA64_OPND_IMM22:
5814       relocatable = 1;
5815     case IA64_OPND_IMM1:
5816     case IA64_OPND_IMM8:
5817     case IA64_OPND_IMM8U4:
5818     case IA64_OPND_IMM8M1:
5819     case IA64_OPND_IMM8M1U4:
5820     case IA64_OPND_IMM8M1U8:
5821     case IA64_OPND_IMM9a:
5822     case IA64_OPND_IMM9b:
5823       bits = operand_width (idesc->operands[index]);
5824       if (relocatable && (e->X_op == O_symbol
5825                           || e->X_op == O_subtract
5826                           || e->X_op == O_pseudo_fixup))
5827         {
5828           fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5829
5830           if (idesc->operands[index] == IA64_OPND_IMM14)
5831             fix->code = BFD_RELOC_IA64_IMM14;
5832           else
5833             fix->code = BFD_RELOC_IA64_IMM22;
5834
5835           if (e->X_op != O_subtract)
5836             {
5837               fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5838               if (e->X_op == O_pseudo_fixup)
5839                 e->X_op = O_symbol;
5840             }
5841
5842           fix->opnd = idesc->operands[index];
5843           fix->expr = *e;
5844           fix->is_pcrel = 0;
5845           ++CURR_SLOT.num_fixups;
5846           return OPERAND_MATCH;
5847         }
5848       else if (e->X_op != O_constant
5849                && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5850         return OPERAND_MISMATCH;
5851
5852       if (opnd == IA64_OPND_IMM8M1U4)
5853         {
5854           /* Zero is not valid for unsigned compares that take an adjusted
5855              constant immediate range.  */
5856           if (e->X_add_number == 0)
5857             return OPERAND_OUT_OF_RANGE;
5858
5859           /* Sign-extend 32-bit unsigned numbers, so that the following range
5860              checks will work.  */
5861           val = e->X_add_number;
5862           if (((val & (~(bfd_vma) 0 << 32)) == 0)
5863               && ((val & ((bfd_vma) 1 << 31)) != 0))
5864             val = ((val << 32) >> 32);
5865
5866           /* Check for 0x100000000.  This is valid because
5867              0x100000000-1 is the same as ((uint32_t) -1).  */
5868           if (val == ((bfd_signed_vma) 1 << 32))
5869             return OPERAND_MATCH;
5870
5871           val = val - 1;
5872         }
5873       else if (opnd == IA64_OPND_IMM8M1U8)
5874         {
5875           /* Zero is not valid for unsigned compares that take an adjusted
5876              constant immediate range.  */
5877           if (e->X_add_number == 0)
5878             return OPERAND_OUT_OF_RANGE;
5879
5880           /* Check for 0x10000000000000000.  */
5881           if (e->X_op == O_big)
5882             {
5883               if (generic_bignum[0] == 0
5884                   && generic_bignum[1] == 0
5885                   && generic_bignum[2] == 0
5886                   && generic_bignum[3] == 0
5887                   && generic_bignum[4] == 1)
5888                 return OPERAND_MATCH;
5889               else
5890                 return OPERAND_OUT_OF_RANGE;
5891             }
5892           else
5893             val = e->X_add_number - 1;
5894         }
5895       else if (opnd == IA64_OPND_IMM8M1)
5896         val = e->X_add_number - 1;
5897       else if (opnd == IA64_OPND_IMM8U4)
5898         {
5899           /* Sign-extend 32-bit unsigned numbers, so that the following range
5900              checks will work.  */
5901           val = e->X_add_number;
5902           if (((val & (~(bfd_vma) 0 << 32)) == 0)
5903               && ((val & ((bfd_vma) 1 << 31)) != 0))
5904             val = ((val << 32) >> 32);
5905         }
5906       else
5907         val = e->X_add_number;
5908
5909       if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5910           || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5911         return OPERAND_MATCH;
5912       else
5913         return OPERAND_OUT_OF_RANGE;
5914
5915     case IA64_OPND_INC3:
5916       /* +/- 1, 4, 8, 16 */
5917       val = e->X_add_number;
5918       if (val < 0)
5919         val = -val;
5920       if (e->X_op == O_constant)
5921         {
5922           if ((val == 1 || val == 4 || val == 8 || val == 16))
5923             return OPERAND_MATCH;
5924           else
5925             return OPERAND_OUT_OF_RANGE;
5926         }
5927       break;
5928
5929     case IA64_OPND_TGT25:
5930     case IA64_OPND_TGT25b:
5931     case IA64_OPND_TGT25c:
5932     case IA64_OPND_TGT64:
5933       if (e->X_op == O_symbol)
5934         {
5935           fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5936           if (opnd == IA64_OPND_TGT25)
5937             fix->code = BFD_RELOC_IA64_PCREL21F;
5938           else if (opnd == IA64_OPND_TGT25b)
5939             fix->code = BFD_RELOC_IA64_PCREL21M;
5940           else if (opnd == IA64_OPND_TGT25c)
5941             fix->code = BFD_RELOC_IA64_PCREL21B;
5942           else if (opnd == IA64_OPND_TGT64)
5943             fix->code = BFD_RELOC_IA64_PCREL60B;
5944           else
5945             abort ();
5946
5947           fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5948           fix->opnd = idesc->operands[index];
5949           fix->expr = *e;
5950           fix->is_pcrel = 1;
5951           ++CURR_SLOT.num_fixups;
5952           return OPERAND_MATCH;
5953         }
5954     case IA64_OPND_TAG13:
5955     case IA64_OPND_TAG13b:
5956       switch (e->X_op)
5957         {
5958         case O_constant:
5959           return OPERAND_MATCH;
5960
5961         case O_symbol:
5962           fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5963           /* There are no external relocs for TAG13/TAG13b fields, so we
5964              create a dummy reloc.  This will not live past md_apply_fix3.  */
5965           fix->code = BFD_RELOC_UNUSED;
5966           fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5967           fix->opnd = idesc->operands[index];
5968           fix->expr = *e;
5969           fix->is_pcrel = 1;
5970           ++CURR_SLOT.num_fixups;
5971           return OPERAND_MATCH;
5972
5973         default:
5974           break;
5975         }
5976       break;
5977
5978     case IA64_OPND_LDXMOV:
5979       fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5980       fix->code = BFD_RELOC_IA64_LDXMOV;
5981       fix->opnd = idesc->operands[index];
5982       fix->expr = *e;
5983       fix->is_pcrel = 0;
5984       ++CURR_SLOT.num_fixups;
5985       return OPERAND_MATCH;
5986
5987     default:
5988       break;
5989     }
5990   return OPERAND_MISMATCH;
5991 }
5992
5993 static int
5994 parse_operand (e)
5995      expressionS *e;
5996 {
5997   int sep = '\0';
5998
5999   memset (e, 0, sizeof (*e));
6000   e->X_op = O_absent;
6001   SKIP_WHITESPACE ();
6002   if (*input_line_pointer != '}')
6003     expression (e);
6004   sep = *input_line_pointer++;
6005
6006   if (sep == '}')
6007     {
6008       if (!md.manual_bundling)
6009         as_warn ("Found '}' when manual bundling is off");
6010       else
6011         CURR_SLOT.manual_bundling_off = 1;
6012       md.manual_bundling = 0;
6013       sep = '\0';
6014     }
6015   return sep;
6016 }
6017
6018 /* Returns the next entry in the opcode table that matches the one in
6019    IDESC, and frees the entry in IDESC.  If no matching entry is
6020    found, NULL is returned instead.  */
6021
6022 static struct ia64_opcode *
6023 get_next_opcode (struct ia64_opcode *idesc)
6024 {
6025   struct ia64_opcode *next = ia64_find_next_opcode (idesc);
6026   ia64_free_opcode (idesc);
6027   return next;
6028 }
6029
6030 /* Parse the operands for the opcode and find the opcode variant that
6031    matches the specified operands, or NULL if no match is possible.  */
6032
6033 static struct ia64_opcode *
6034 parse_operands (idesc)
6035      struct ia64_opcode *idesc;
6036 {
6037   int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
6038   int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
6039   int reg1, reg2;
6040   char reg_class;
6041   enum ia64_opnd expected_operand = IA64_OPND_NIL;
6042   enum operand_match_result result;
6043   char mnemonic[129];
6044   char *first_arg = 0, *end, *saved_input_pointer;
6045   unsigned int sof;
6046
6047   assert (strlen (idesc->name) <= 128);
6048
6049   strcpy (mnemonic, idesc->name);
6050   if (idesc->operands[2] == IA64_OPND_SOF
6051       || idesc->operands[1] == IA64_OPND_SOF)
6052     {
6053       /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
6054          can't parse the first operand until we have parsed the
6055          remaining operands of the "alloc" instruction.  */
6056       SKIP_WHITESPACE ();
6057       first_arg = input_line_pointer;
6058       end = strchr (input_line_pointer, '=');
6059       if (!end)
6060         {
6061           as_bad ("Expected separator `='");
6062           return 0;
6063         }
6064       input_line_pointer = end + 1;
6065       ++i;
6066       ++num_outputs;
6067     }
6068
6069   for (; ; ++i)
6070     {
6071       if (i < NELEMS (CURR_SLOT.opnd)) 
6072         {
6073           sep = parse_operand (CURR_SLOT.opnd + i);
6074           if (CURR_SLOT.opnd[i].X_op == O_absent)
6075             break;
6076         }
6077       else
6078         {
6079           expressionS dummy;
6080
6081           sep = parse_operand (&dummy);
6082           if (dummy.X_op == O_absent)
6083             break;
6084         }
6085
6086       ++num_operands;
6087
6088       if (sep != '=' && sep != ',')
6089         break;
6090
6091       if (sep == '=')
6092         {
6093           if (num_outputs > 0)
6094             as_bad ("Duplicate equal sign (=) in instruction");
6095           else
6096             num_outputs = i + 1;
6097         }
6098     }
6099   if (sep != '\0')
6100     {
6101       as_bad ("Illegal operand separator `%c'", sep);
6102       return 0;
6103     }
6104
6105   if (idesc->operands[2] == IA64_OPND_SOF
6106       || idesc->operands[1] == IA64_OPND_SOF)
6107     {
6108       /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
6109       know (strcmp (idesc->name, "alloc") == 0);
6110       i = (CURR_SLOT.opnd[1].X_op == O_register
6111           && CURR_SLOT.opnd[1].X_add_number == REG_AR + AR_PFS) ? 2 : 1;
6112       if (num_operands == i + 3 /* first_arg not included in this count! */
6113           && CURR_SLOT.opnd[i].X_op == O_constant
6114           && CURR_SLOT.opnd[i + 1].X_op == O_constant
6115           && CURR_SLOT.opnd[i + 2].X_op == O_constant
6116           && CURR_SLOT.opnd[i + 3].X_op == O_constant)
6117         {
6118           sof = set_regstack (CURR_SLOT.opnd[i].X_add_number,
6119                               CURR_SLOT.opnd[i + 1].X_add_number,
6120                               CURR_SLOT.opnd[i + 2].X_add_number,
6121                               CURR_SLOT.opnd[i + 3].X_add_number);
6122
6123           /* now we can parse the first arg:  */
6124           saved_input_pointer = input_line_pointer;
6125           input_line_pointer = first_arg;
6126           sep = parse_operand (CURR_SLOT.opnd + 0);
6127           if (sep != '=')
6128             --num_outputs;      /* force error */
6129           input_line_pointer = saved_input_pointer;
6130
6131           CURR_SLOT.opnd[i].X_add_number = sof;
6132           CURR_SLOT.opnd[i + 1].X_add_number
6133             = sof - CURR_SLOT.opnd[i + 2].X_add_number;
6134           CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3];
6135         }
6136     }
6137
6138   highest_unmatched_operand = -4;
6139   curr_out_of_range_pos = -1;
6140   error_pos = 0;
6141   for (; idesc; idesc = get_next_opcode (idesc))
6142     {
6143       if (num_outputs != idesc->num_outputs)
6144         continue;               /* mismatch in # of outputs */
6145       if (highest_unmatched_operand < 0)
6146         highest_unmatched_operand |= 1;
6147       if (num_operands > NELEMS (idesc->operands)
6148           || (num_operands < NELEMS (idesc->operands)
6149            && idesc->operands[num_operands])
6150           || (num_operands > 0 && !idesc->operands[num_operands - 1]))
6151         continue;               /* mismatch in number of arguments */
6152       if (highest_unmatched_operand < 0)
6153         highest_unmatched_operand |= 2;
6154
6155       CURR_SLOT.num_fixups = 0;
6156
6157       /* Try to match all operands.  If we see an out-of-range operand,
6158          then continue trying to match the rest of the operands, since if
6159          the rest match, then this idesc will give the best error message.  */
6160
6161       out_of_range_pos = -1;
6162       for (i = 0; i < num_operands && idesc->operands[i]; ++i)
6163         {
6164           result = operand_match (idesc, i, CURR_SLOT.opnd + i);
6165           if (result != OPERAND_MATCH)
6166             {
6167               if (result != OPERAND_OUT_OF_RANGE)
6168                 break;
6169               if (out_of_range_pos < 0)
6170                 /* remember position of the first out-of-range operand: */
6171                 out_of_range_pos = i;
6172             }
6173         }
6174
6175       /* If we did not match all operands, or if at least one operand was
6176          out-of-range, then this idesc does not match.  Keep track of which
6177          idesc matched the most operands before failing.  If we have two
6178          idescs that failed at the same position, and one had an out-of-range
6179          operand, then prefer the out-of-range operand.  Thus if we have
6180          "add r0=0x1000000,r1" we get an error saying the constant is out
6181          of range instead of an error saying that the constant should have been
6182          a register.  */
6183
6184       if (i != num_operands || out_of_range_pos >= 0)
6185         {
6186           if (i > highest_unmatched_operand
6187               || (i == highest_unmatched_operand
6188                   && out_of_range_pos > curr_out_of_range_pos))
6189             {
6190               highest_unmatched_operand = i;
6191               if (out_of_range_pos >= 0)
6192                 {
6193                   expected_operand = idesc->operands[out_of_range_pos];
6194                   error_pos = out_of_range_pos;
6195                 }
6196               else
6197                 {
6198                   expected_operand = idesc->operands[i];
6199                   error_pos = i;
6200                 }
6201               curr_out_of_range_pos = out_of_range_pos;
6202             }
6203           continue;
6204         }
6205
6206       break;
6207     }
6208   if (!idesc)
6209     {
6210       if (expected_operand)
6211         as_bad ("Operand %u of `%s' should be %s",
6212                 error_pos + 1, mnemonic,
6213                 elf64_ia64_operands[expected_operand].desc);
6214       else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1))
6215         as_bad ("Wrong number of output operands");
6216       else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2))
6217         as_bad ("Wrong number of input operands");
6218       else
6219         as_bad ("Operand mismatch");
6220       return 0;
6221     }
6222
6223   /* Check that the instruction doesn't use
6224      - r0, f0, or f1 as output operands
6225      - the same predicate twice as output operands
6226      - r0 as address of a base update load or store
6227      - the same GR as output and address of a base update load
6228      - two even- or two odd-numbered FRs as output operands of a floating
6229        point parallel load.
6230      At most two (conflicting) output (or output-like) operands can exist,
6231      (floating point parallel loads have three outputs, but the base register,
6232      if updated, cannot conflict with the actual outputs).  */
6233   reg2 = reg1 = -1;
6234   for (i = 0; i < num_operands; ++i)
6235     {
6236       int regno = 0;
6237
6238       reg_class = 0;
6239       switch (idesc->operands[i])
6240         {
6241         case IA64_OPND_R1:
6242         case IA64_OPND_R2:
6243         case IA64_OPND_R3:
6244           if (i < num_outputs)
6245             {
6246               if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6247                 reg_class = 'r';
6248               else if (reg1 < 0)
6249                 reg1 = CURR_SLOT.opnd[i].X_add_number;
6250               else if (reg2 < 0)
6251                 reg2 = CURR_SLOT.opnd[i].X_add_number;
6252             }
6253           break;
6254         case IA64_OPND_P1:
6255         case IA64_OPND_P2:
6256           if (i < num_outputs)
6257             {
6258               if (reg1 < 0)
6259                 reg1 = CURR_SLOT.opnd[i].X_add_number;
6260               else if (reg2 < 0)
6261                 reg2 = CURR_SLOT.opnd[i].X_add_number;
6262             }
6263           break;
6264         case IA64_OPND_F1:
6265         case IA64_OPND_F2:
6266         case IA64_OPND_F3:
6267         case IA64_OPND_F4:
6268           if (i < num_outputs)
6269             {
6270               if (CURR_SLOT.opnd[i].X_add_number >= REG_FR
6271                   && CURR_SLOT.opnd[i].X_add_number <= REG_FR + 1)
6272                 {
6273                   reg_class = 'f';
6274                   regno = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6275                 }
6276               else if (reg1 < 0)
6277                 reg1 = CURR_SLOT.opnd[i].X_add_number;
6278               else if (reg2 < 0)
6279                 reg2 = CURR_SLOT.opnd[i].X_add_number;
6280             }
6281           break;
6282         case IA64_OPND_MR3:
6283           if (idesc->flags & IA64_OPCODE_POSTINC)
6284             {
6285               if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6286                 reg_class = 'm';
6287               else if (reg1 < 0)
6288                 reg1 = CURR_SLOT.opnd[i].X_add_number;
6289               else if (reg2 < 0)
6290                 reg2 = CURR_SLOT.opnd[i].X_add_number;
6291             }
6292           break;
6293         default:
6294           break;
6295         }
6296       switch (reg_class)
6297         {
6298         case 0:
6299           break;
6300         default:
6301           as_warn ("Invalid use of `%c%d' as output operand", reg_class, regno);
6302           break;
6303         case 'm':
6304           as_warn ("Invalid use of `r%d' as base update address operand", regno);
6305           break;
6306         }
6307     }
6308   if (reg1 == reg2)
6309     {
6310       if (reg1 >= REG_GR && reg1 <= REG_GR + 127)
6311         {
6312           reg1 -= REG_GR;
6313           reg_class = 'r';
6314         }
6315       else if (reg1 >= REG_P && reg1 <= REG_P + 63)
6316         {
6317           reg1 -= REG_P;
6318           reg_class = 'p';
6319         }
6320       else if (reg1 >= REG_FR && reg1 <= REG_FR + 127)
6321         {
6322           reg1 -= REG_FR;
6323           reg_class = 'f';
6324         }
6325       else
6326         reg_class = 0;
6327       if (reg_class)
6328         as_warn ("Invalid duplicate use of `%c%d'", reg_class, reg1);
6329     }
6330   else if (((reg1 >= REG_FR && reg1 <= REG_FR + 31
6331              && reg2 >= REG_FR && reg2 <= REG_FR + 31)
6332             || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6333              && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127))
6334            && ! ((reg1 ^ reg2) & 1))
6335     as_warn ("Invalid simultaneous use of `f%d' and `f%d'",
6336              reg1 - REG_FR, reg2 - REG_FR);
6337   else if ((reg1 >= REG_FR && reg1 <= REG_FR + 31
6338             && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127)
6339            || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6340             && reg2 >= REG_FR && reg2 <= REG_FR + 31))
6341     as_warn ("Dangerous simultaneous use of `f%d' and `f%d'",
6342              reg1 - REG_FR, reg2 - REG_FR);
6343   return idesc;
6344 }
6345
6346 static void
6347 build_insn (slot, insnp)
6348      struct slot *slot;
6349      bfd_vma *insnp;
6350 {
6351   const struct ia64_operand *odesc, *o2desc;
6352   struct ia64_opcode *idesc = slot->idesc;
6353   bfd_vma insn;
6354   bfd_signed_vma val;
6355   const char *err;
6356   int i;
6357
6358   insn = idesc->opcode | slot->qp_regno;
6359
6360   for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6361     {
6362       if (slot->opnd[i].X_op == O_register
6363           || slot->opnd[i].X_op == O_constant
6364           || slot->opnd[i].X_op == O_index)
6365         val = slot->opnd[i].X_add_number;
6366       else if (slot->opnd[i].X_op == O_big)
6367         {
6368           /* This must be the value 0x10000000000000000.  */
6369           assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6370           val = 0;
6371         }
6372       else
6373         val = 0;
6374
6375       switch (idesc->operands[i])
6376         {
6377         case IA64_OPND_IMMU64:
6378           *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6379           insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6380                    | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6381                    | (((val >> 63) & 0x1) << 36));
6382           continue;
6383
6384         case IA64_OPND_IMMU62:
6385           val &= 0x3fffffffffffffffULL;
6386           if (val != slot->opnd[i].X_add_number)
6387             as_warn (_("Value truncated to 62 bits"));
6388           *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6389           insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6390           continue;
6391
6392         case IA64_OPND_TGT64:
6393           val >>= 4;
6394           *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6395           insn |= ((((val >> 59) & 0x1) << 36)
6396                    | (((val >> 0) & 0xfffff) << 13));
6397           continue;
6398
6399         case IA64_OPND_AR3:
6400           val -= REG_AR;
6401           break;
6402
6403         case IA64_OPND_B1:
6404         case IA64_OPND_B2:
6405           val -= REG_BR;
6406           break;
6407
6408         case IA64_OPND_CR3:
6409           val -= REG_CR;
6410           break;
6411
6412         case IA64_OPND_F1:
6413         case IA64_OPND_F2:
6414         case IA64_OPND_F3:
6415         case IA64_OPND_F4:
6416           val -= REG_FR;
6417           break;
6418
6419         case IA64_OPND_P1:
6420         case IA64_OPND_P2:
6421           val -= REG_P;
6422           break;
6423
6424         case IA64_OPND_R1:
6425         case IA64_OPND_R2:
6426         case IA64_OPND_R3:
6427         case IA64_OPND_R3_2:
6428         case IA64_OPND_CPUID_R3:
6429         case IA64_OPND_DBR_R3:
6430         case IA64_OPND_DTR_R3:
6431         case IA64_OPND_ITR_R3:
6432         case IA64_OPND_IBR_R3:
6433         case IA64_OPND_MR3:
6434         case IA64_OPND_MSR_R3:
6435         case IA64_OPND_PKR_R3:
6436         case IA64_OPND_PMC_R3:
6437         case IA64_OPND_PMD_R3:
6438         case IA64_OPND_RR_R3:
6439           val -= REG_GR;
6440           break;
6441
6442         default:
6443           break;
6444         }
6445
6446       odesc = elf64_ia64_operands + idesc->operands[i];
6447       err = (*odesc->insert) (odesc, val, &insn);
6448       if (err)
6449         as_bad_where (slot->src_file, slot->src_line,
6450                       "Bad operand value: %s", err);
6451       if (idesc->flags & IA64_OPCODE_PSEUDO)
6452         {
6453           if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6454               && odesc == elf64_ia64_operands + IA64_OPND_F3)
6455             {
6456               o2desc = elf64_ia64_operands + IA64_OPND_F2;
6457               (*o2desc->insert) (o2desc, val, &insn);
6458             }
6459           if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6460               && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6461                   || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6462             {
6463               o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6464               (*o2desc->insert) (o2desc, 64 - val, &insn);
6465             }
6466         }
6467     }
6468   *insnp = insn;
6469 }
6470
6471 static void
6472 emit_one_bundle ()
6473 {
6474   int manual_bundling_off = 0, manual_bundling = 0;
6475   enum ia64_unit required_unit, insn_unit = 0;
6476   enum ia64_insn_type type[3], insn_type;
6477   unsigned int template, orig_template;
6478   bfd_vma insn[3] = { -1, -1, -1 };
6479   struct ia64_opcode *idesc;
6480   int end_of_insn_group = 0, user_template = -1;
6481   int n, i, j, first, curr, last_slot;
6482   bfd_vma t0 = 0, t1 = 0;
6483   struct label_fix *lfix;
6484   struct insn_fix *ifix;
6485   char mnemonic[16];
6486   fixS *fix;
6487   char *f;
6488   int addr_mod;
6489
6490   first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6491   know (first >= 0 & first < NUM_SLOTS);
6492   n = MIN (3, md.num_slots_in_use);
6493
6494   /* Determine template: user user_template if specified, best match
6495      otherwise:  */
6496
6497   if (md.slot[first].user_template >= 0)
6498     user_template = template = md.slot[first].user_template;
6499   else
6500     {
6501       /* Auto select appropriate template.  */
6502       memset (type, 0, sizeof (type));
6503       curr = first;
6504       for (i = 0; i < n; ++i)
6505         {
6506           if (md.slot[curr].label_fixups && i != 0)
6507             break;
6508           type[i] = md.slot[curr].idesc->type;
6509           curr = (curr + 1) % NUM_SLOTS;
6510         }
6511       template = best_template[type[0]][type[1]][type[2]];
6512     }
6513
6514   /* initialize instructions with appropriate nops:  */
6515   for (i = 0; i < 3; ++i)
6516     insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6517
6518   f = frag_more (16);
6519
6520   /* Check to see if this bundle is at an offset that is a multiple of 16-bytes
6521      from the start of the frag.  */
6522   addr_mod = frag_now_fix () & 15;
6523   if (frag_now->has_code && frag_now->insn_addr != addr_mod)
6524     as_bad (_("instruction address is not a multiple of 16"));
6525   frag_now->insn_addr = addr_mod;
6526   frag_now->has_code = 1;
6527
6528   /* now fill in slots with as many insns as possible:  */
6529   curr = first;
6530   idesc = md.slot[curr].idesc;
6531   end_of_insn_group = 0;
6532   last_slot = -1;
6533   for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6534     {
6535       /* If we have unwind records, we may need to update some now.  */
6536       unw_rec_list *ptr = md.slot[curr].unwind_record;
6537       unw_rec_list *end_ptr = NULL;
6538
6539       if (ptr)
6540         {
6541           /* Find the last prologue/body record in the list for the current
6542              insn, and set the slot number for all records up to that point.
6543              This needs to be done now, because prologue/body records refer to
6544              the current point, not the point after the instruction has been
6545              issued.  This matters because there may have been nops emitted
6546              meanwhile.  Any non-prologue non-body record followed by a
6547              prologue/body record must also refer to the current point.  */
6548           unw_rec_list *last_ptr;
6549
6550           for (j = 1; end_ptr == NULL && j < md.num_slots_in_use; ++j)
6551             end_ptr = md.slot[(curr + j) % NUM_SLOTS].unwind_record;
6552           for (last_ptr = NULL; ptr != end_ptr; ptr = ptr->next)
6553             if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6554                 || ptr->r.type == body)
6555               last_ptr = ptr;
6556           if (last_ptr)
6557             {
6558               /* Make last_ptr point one after the last prologue/body
6559                  record.  */
6560               last_ptr = last_ptr->next;
6561               for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6562                    ptr = ptr->next)
6563                 {
6564                   ptr->slot_number = (unsigned long) f + i;
6565                   ptr->slot_frag = frag_now;
6566                 }
6567               /* Remove the initialized records, so that we won't accidentally
6568                  update them again if we insert a nop and continue.  */
6569               md.slot[curr].unwind_record = last_ptr;
6570             }
6571         }
6572
6573       manual_bundling_off = md.slot[curr].manual_bundling_off;
6574       if (md.slot[curr].manual_bundling_on)
6575         {
6576           if (curr == first)
6577             manual_bundling = 1;
6578           else
6579           break; /* Need to start a new bundle.  */
6580         }
6581
6582       /* If this instruction specifies a template, then it must be the first
6583          instruction of a bundle.  */
6584       if (curr != first && md.slot[curr].user_template >= 0)
6585         break;
6586
6587       if (idesc->flags & IA64_OPCODE_SLOT2)
6588         {
6589           if (manual_bundling && !manual_bundling_off)
6590             {
6591               as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6592                             "`%s' must be last in bundle", idesc->name);
6593               if (i < 2)
6594                 manual_bundling = -1; /* Suppress meaningless post-loop errors.  */
6595             }
6596           i = 2;
6597         }
6598       if (idesc->flags & IA64_OPCODE_LAST)
6599         {
6600           int required_slot;
6601           unsigned int required_template;
6602
6603           /* If we need a stop bit after an M slot, our only choice is
6604              template 5 (M;;MI).  If we need a stop bit after a B
6605              slot, our only choice is to place it at the end of the
6606              bundle, because the only available templates are MIB,
6607              MBB, BBB, MMB, and MFB.  We don't handle anything other
6608              than M and B slots because these are the only kind of
6609              instructions that can have the IA64_OPCODE_LAST bit set.  */
6610           required_template = template;
6611           switch (idesc->type)
6612             {
6613             case IA64_TYPE_M:
6614               required_slot = 0;
6615               required_template = 5;
6616               break;
6617
6618             case IA64_TYPE_B:
6619               required_slot = 2;
6620               break;
6621
6622             default:
6623               as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6624                             "Internal error: don't know how to force %s to end"
6625                             "of instruction group", idesc->name);
6626               required_slot = i;
6627               break;
6628             }
6629           if (manual_bundling
6630               && (i > required_slot
6631                   || (required_slot == 2 && !manual_bundling_off)
6632                   || (user_template >= 0
6633                       /* Changing from MMI to M;MI is OK.  */
6634                       && (template ^ required_template) > 1)))
6635             {
6636               as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6637                             "`%s' must be last in instruction group",
6638                             idesc->name);
6639               if (i < 2 && required_slot == 2 && !manual_bundling_off)
6640                 manual_bundling = -1; /* Suppress meaningless post-loop errors.  */
6641             }
6642           if (required_slot < i)
6643             /* Can't fit this instruction.  */
6644             break;
6645
6646           i = required_slot;
6647           if (required_template != template)
6648             {
6649               /* If we switch the template, we need to reset the NOPs
6650                  after slot i.  The slot-types of the instructions ahead
6651                  of i never change, so we don't need to worry about
6652                  changing NOPs in front of this slot.  */
6653               for (j = i; j < 3; ++j)
6654                 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6655             }
6656           template = required_template;
6657         }
6658       if (curr != first && md.slot[curr].label_fixups)
6659         {
6660           if (manual_bundling)
6661             {
6662               as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6663                           "Label must be first in a bundle");
6664               manual_bundling = -1; /* Suppress meaningless post-loop errors.  */
6665             }
6666           /* This insn must go into the first slot of a bundle.  */
6667           break;
6668         }
6669
6670       if (end_of_insn_group && md.num_slots_in_use >= 1)
6671         {
6672           /* We need an instruction group boundary in the middle of a
6673              bundle.  See if we can switch to an other template with
6674              an appropriate boundary.  */
6675
6676           orig_template = template;
6677           if (i == 1 && (user_template == 4
6678                          || (user_template < 0
6679                              && (ia64_templ_desc[template].exec_unit[0]
6680                                  == IA64_UNIT_M))))
6681             {
6682               template = 5;
6683               end_of_insn_group = 0;
6684             }
6685           else if (i == 2 && (user_template == 0
6686                               || (user_template < 0
6687                                   && (ia64_templ_desc[template].exec_unit[1]
6688                                       == IA64_UNIT_I)))
6689                    /* This test makes sure we don't switch the template if
6690                       the next instruction is one that needs to be first in
6691                       an instruction group.  Since all those instructions are
6692                       in the M group, there is no way such an instruction can
6693                       fit in this bundle even if we switch the template.  The
6694                       reason we have to check for this is that otherwise we
6695                       may end up generating "MI;;I M.." which has the deadly
6696                       effect that the second M instruction is no longer the
6697                       first in the group! --davidm 99/12/16  */
6698                    && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6699             {
6700               template = 1;
6701               end_of_insn_group = 0;
6702             }
6703           else if (i == 1
6704                    && user_template == 0
6705                    && !(idesc->flags & IA64_OPCODE_FIRST))
6706             /* Use the next slot.  */
6707             continue;
6708           else if (curr != first)
6709             /* can't fit this insn */
6710             break;
6711
6712           if (template != orig_template)
6713             /* if we switch the template, we need to reset the NOPs
6714                after slot i.  The slot-types of the instructions ahead
6715                of i never change, so we don't need to worry about
6716                changing NOPs in front of this slot.  */
6717             for (j = i; j < 3; ++j)
6718               insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6719         }
6720       required_unit = ia64_templ_desc[template].exec_unit[i];
6721
6722       /* resolve dynamic opcodes such as "break", "hint", and "nop":  */
6723       if (idesc->type == IA64_TYPE_DYN)
6724         {
6725           enum ia64_opnd opnd1, opnd2;
6726
6727           if ((strcmp (idesc->name, "nop") == 0)
6728               || (strcmp (idesc->name, "break") == 0))
6729             insn_unit = required_unit;
6730           else if (strcmp (idesc->name, "hint") == 0)
6731             {
6732               insn_unit = required_unit;
6733               if (required_unit == IA64_UNIT_B)
6734                 {
6735                   switch (md.hint_b)
6736                     {
6737                     case hint_b_ok:
6738                       break;
6739                     case hint_b_warning:
6740                       as_warn ("hint in B unit may be treated as nop");
6741                       break;
6742                     case hint_b_error:
6743                       /* When manual bundling is off and there is no
6744                          user template, we choose a different unit so
6745                          that hint won't go into the current slot. We
6746                          will fill the current bundle with nops and
6747                          try to put hint into the next bundle.  */
6748                       if (!manual_bundling && user_template < 0)
6749                         insn_unit = IA64_UNIT_I;
6750                       else
6751                         as_bad ("hint in B unit can't be used");
6752                       break;
6753                     }
6754                 }
6755             }
6756           else if (strcmp (idesc->name, "chk.s") == 0
6757               || strcmp (idesc->name, "mov") == 0)
6758             {
6759               insn_unit = IA64_UNIT_M;
6760               if (required_unit == IA64_UNIT_I
6761                   || (required_unit == IA64_UNIT_F && template == 6))
6762                 insn_unit = IA64_UNIT_I;
6763             }
6764           else
6765             as_fatal ("emit_one_bundle: unexpected dynamic op");
6766
6767           sprintf (mnemonic, "%s.%c", idesc->name, "?imbfxx"[insn_unit]);
6768           opnd1 = idesc->operands[0];
6769           opnd2 = idesc->operands[1];
6770           ia64_free_opcode (idesc);
6771           idesc = ia64_find_opcode (mnemonic);
6772           /* moves to/from ARs have collisions */
6773           if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3)
6774             {
6775               while (idesc != NULL
6776                      && (idesc->operands[0] != opnd1
6777                          || idesc->operands[1] != opnd2))
6778                 idesc = get_next_opcode (idesc);
6779             }
6780           md.slot[curr].idesc = idesc;
6781         }
6782       else
6783         {
6784           insn_type = idesc->type;
6785           insn_unit = IA64_UNIT_NIL;
6786           switch (insn_type)
6787             {
6788             case IA64_TYPE_A:
6789               if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6790                 insn_unit = required_unit;
6791               break;
6792             case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6793             case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6794             case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6795             case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6796             case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6797             default:                                   break;
6798             }
6799         }
6800
6801       if (insn_unit != required_unit)
6802         continue;               /* Try next slot.  */
6803
6804       if (debug_type == DEBUG_DWARF2 || md.slot[curr].loc_directive_seen)
6805         {
6806           bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6807
6808           md.slot[curr].loc_directive_seen = 0;
6809           dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6810         }
6811
6812       build_insn (md.slot + curr, insn + i);
6813
6814       ptr = md.slot[curr].unwind_record;
6815       if (ptr)
6816         {
6817           /* Set slot numbers for all remaining unwind records belonging to the
6818              current insn.  There can not be any prologue/body unwind records
6819              here.  */
6820           for (; ptr != end_ptr; ptr = ptr->next)
6821             {
6822               ptr->slot_number = (unsigned long) f + i;
6823               ptr->slot_frag = frag_now;
6824             }
6825           md.slot[curr].unwind_record = NULL;
6826         }
6827
6828       if (required_unit == IA64_UNIT_L)
6829         {
6830           know (i == 1);
6831           /* skip one slot for long/X-unit instructions */
6832           ++i;
6833         }
6834       --md.num_slots_in_use;
6835       last_slot = i;
6836
6837       /* now is a good time to fix up the labels for this insn:  */
6838       for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6839         {
6840           S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6841           symbol_set_frag (lfix->sym, frag_now);
6842         }
6843       /* and fix up the tags also.  */
6844       for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6845         {
6846           S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6847           symbol_set_frag (lfix->sym, frag_now);
6848         }
6849
6850       for (j = 0; j < md.slot[curr].num_fixups; ++j)
6851         {
6852           ifix = md.slot[curr].fixup + j;
6853           fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6854                              &ifix->expr, ifix->is_pcrel, ifix->code);
6855           fix->tc_fix_data.opnd = ifix->opnd;
6856           fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6857           fix->fx_file = md.slot[curr].src_file;
6858           fix->fx_line = md.slot[curr].src_line;
6859         }
6860
6861       end_of_insn_group = md.slot[curr].end_of_insn_group;
6862
6863       /* clear slot:  */
6864       ia64_free_opcode (md.slot[curr].idesc);
6865       memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6866       md.slot[curr].user_template = -1;
6867
6868       if (manual_bundling_off)
6869         {
6870           manual_bundling = 0;
6871           break;
6872         }
6873       curr = (curr + 1) % NUM_SLOTS;
6874       idesc = md.slot[curr].idesc;
6875     }
6876   if (manual_bundling > 0)
6877     {
6878       if (md.num_slots_in_use > 0)
6879         {
6880           if (last_slot >= 2)
6881             as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6882                           "`%s' does not fit into bundle", idesc->name);
6883           else if (last_slot < 0)
6884             {
6885               as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6886                             "`%s' does not fit into %s template",
6887                             idesc->name, ia64_templ_desc[template].name);
6888               /* Drop first insn so we don't livelock.  */
6889               --md.num_slots_in_use;
6890               know (curr == first);
6891               ia64_free_opcode (md.slot[curr].idesc);
6892               memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6893               md.slot[curr].user_template = -1;
6894             }
6895           else
6896             {
6897               const char *where;
6898
6899               if (template == 2)
6900                 where = "X slot";
6901               else if (last_slot == 0)
6902                 where = "slots 2 or 3";
6903               else
6904                 where = "slot 3";
6905               as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6906                             "`%s' can't go in %s of %s template",
6907                             idesc->name, where, ia64_templ_desc[template].name);
6908             }
6909         }
6910       else
6911         as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6912                       "Missing '}' at end of file");
6913     }
6914   know (md.num_slots_in_use < NUM_SLOTS);
6915
6916   t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6917   t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6918
6919   number_to_chars_littleendian (f + 0, t0, 8);
6920   number_to_chars_littleendian (f + 8, t1, 8);
6921 }
6922
6923 int
6924 md_parse_option (c, arg)
6925      int c;
6926      char *arg;
6927 {
6928
6929   switch (c)
6930     {
6931     /* Switches from the Intel assembler.  */
6932     case 'm':
6933       if (strcmp (arg, "ilp64") == 0
6934           || strcmp (arg, "lp64") == 0
6935           || strcmp (arg, "p64") == 0)
6936         {
6937           md.flags |= EF_IA_64_ABI64;
6938         }
6939       else if (strcmp (arg, "ilp32") == 0)
6940         {
6941           md.flags &= ~EF_IA_64_ABI64;
6942         }
6943       else if (strcmp (arg, "le") == 0)
6944         {
6945           md.flags &= ~EF_IA_64_BE;
6946           default_big_endian = 0;
6947         }
6948       else if (strcmp (arg, "be") == 0)
6949         {
6950           md.flags |= EF_IA_64_BE;
6951           default_big_endian = 1;
6952         }
6953       else if (strncmp (arg, "unwind-check=", 13) == 0)
6954         {
6955           arg += 13;
6956           if (strcmp (arg, "warning") == 0)
6957             md.unwind_check = unwind_check_warning;
6958           else if (strcmp (arg, "error") == 0)
6959             md.unwind_check = unwind_check_error;
6960           else
6961             return 0;
6962         }
6963       else if (strncmp (arg, "hint.b=", 7) == 0)
6964         {
6965           arg += 7;
6966           if (strcmp (arg, "ok") == 0)
6967             md.hint_b = hint_b_ok;
6968           else if (strcmp (arg, "warning") == 0)
6969             md.hint_b = hint_b_warning;
6970           else if (strcmp (arg, "error") == 0)
6971             md.hint_b = hint_b_error;
6972           else
6973             return 0;
6974         }
6975       else if (strncmp (arg, "tune=", 5) == 0)
6976         {
6977           arg += 5;
6978           if (strcmp (arg, "itanium1") == 0)
6979             md.tune = itanium1;
6980           else if (strcmp (arg, "itanium2") == 0)
6981             md.tune = itanium2;
6982           else
6983             return 0;
6984         }
6985       else
6986         return 0;
6987       break;
6988
6989     case 'N':
6990       if (strcmp (arg, "so") == 0)
6991         {
6992           /* Suppress signon message.  */
6993         }
6994       else if (strcmp (arg, "pi") == 0)
6995         {
6996           /* Reject privileged instructions.  FIXME */
6997         }
6998       else if (strcmp (arg, "us") == 0)
6999         {
7000           /* Allow union of signed and unsigned range.  FIXME */
7001         }
7002       else if (strcmp (arg, "close_fcalls") == 0)
7003         {
7004           /* Do not resolve global function calls.  */
7005         }
7006       else
7007         return 0;
7008       break;
7009
7010     case 'C':
7011       /* temp[="prefix"]  Insert temporary labels into the object file
7012                           symbol table prefixed by "prefix".
7013                           Default prefix is ":temp:".
7014        */
7015       break;
7016
7017     case 'a':
7018       /* indirect=<tgt> Assume unannotated indirect branches behavior
7019                         according to <tgt> --
7020                         exit:   branch out from the current context (default)
7021                         labels: all labels in context may be branch targets
7022        */
7023       if (strncmp (arg, "indirect=", 9) != 0)
7024         return 0;
7025       break;
7026
7027     case 'x':
7028       /* -X conflicts with an ignored option, use -x instead */
7029       md.detect_dv = 1;
7030       if (!arg || strcmp (arg, "explicit") == 0)
7031         {
7032           /* set default mode to explicit */
7033           md.default_explicit_mode = 1;
7034           break;
7035         }
7036       else if (strcmp (arg, "auto") == 0)
7037         {
7038           md.default_explicit_mode = 0;
7039         }
7040       else if (strcmp (arg, "none") == 0)
7041         {
7042           md.detect_dv = 0;
7043         }
7044       else if (strcmp (arg, "debug") == 0)
7045         {
7046           md.debug_dv = 1;
7047         }
7048       else if (strcmp (arg, "debugx") == 0)
7049         {
7050           md.default_explicit_mode = 1;
7051           md.debug_dv = 1;
7052         }
7053       else if (strcmp (arg, "debugn") == 0)
7054         {
7055           md.debug_dv = 1;
7056           md.detect_dv = 0;
7057         }
7058       else
7059         {
7060           as_bad (_("Unrecognized option '-x%s'"), arg);
7061         }
7062       break;
7063
7064     case 'S':
7065       /* nops           Print nops statistics.  */
7066       break;
7067
7068     /* GNU specific switches for gcc.  */
7069     case OPTION_MCONSTANT_GP:
7070       md.flags |= EF_IA_64_CONS_GP;
7071       break;
7072
7073     case OPTION_MAUTO_PIC:
7074       md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
7075       break;
7076
7077     default:
7078       return 0;
7079     }
7080
7081   return 1;
7082 }
7083
7084 void
7085 md_show_usage (stream)
7086      FILE *stream;
7087 {
7088   fputs (_("\
7089 IA-64 options:\n\
7090   --mconstant-gp          mark output file as using the constant-GP model\n\
7091                           (sets ELF header flag EF_IA_64_CONS_GP)\n\
7092   --mauto-pic             mark output file as using the constant-GP model\n\
7093                           without function descriptors (sets ELF header flag\n\
7094                           EF_IA_64_NOFUNCDESC_CONS_GP)\n\
7095   -milp32|-milp64|-mlp64|-mp64  select data model (default -mlp64)\n\
7096   -mle | -mbe             select little- or big-endian byte order (default -mle)\n\
7097   -mtune=[itanium1|itanium2]\n\
7098                           tune for a specific CPU (default -mtune=itanium2)\n\
7099   -munwind-check=[warning|error]\n\
7100                           unwind directive check (default -munwind-check=warning)\n\
7101   -mhint.b=[ok|warning|error]\n\
7102                           hint.b check (default -mhint.b=error)\n\
7103   -x | -xexplicit         turn on dependency violation checking\n\
7104   -xauto                  automagically remove dependency violations (default)\n\
7105   -xnone                  turn off dependency violation checking\n\
7106   -xdebug                 debug dependency violation checker\n\
7107   -xdebugn                debug dependency violation checker but turn off\n\
7108                           dependency violation checking\n\
7109   -xdebugx                debug dependency violation checker and turn on\n\
7110                           dependency violation checking\n"),
7111         stream);
7112 }
7113
7114 void
7115 ia64_after_parse_args ()
7116 {
7117   if (debug_type == DEBUG_STABS)
7118     as_fatal (_("--gstabs is not supported for ia64"));
7119 }
7120
7121 /* Return true if TYPE fits in TEMPL at SLOT.  */
7122
7123 static int
7124 match (int templ, int type, int slot)
7125 {
7126   enum ia64_unit unit;
7127   int result;
7128
7129   unit = ia64_templ_desc[templ].exec_unit[slot];
7130   switch (type)
7131     {
7132     case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
7133     case IA64_TYPE_A:
7134       result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
7135       break;
7136     case IA64_TYPE_X:   result = (unit == IA64_UNIT_L); break;
7137     case IA64_TYPE_I:   result = (unit == IA64_UNIT_I); break;
7138     case IA64_TYPE_M:   result = (unit == IA64_UNIT_M); break;
7139     case IA64_TYPE_B:   result = (unit == IA64_UNIT_B); break;
7140     case IA64_TYPE_F:   result = (unit == IA64_UNIT_F); break;
7141     default:            result = 0; break;
7142     }
7143   return result;
7144 }
7145
7146 /* For Itanium 1, add a bit of extra goodness if a nop of type F or B would fit
7147    in TEMPL at SLOT.  For Itanium 2, add a bit of extra goodness if a nop of
7148    type M or I would fit in TEMPL at SLOT.  */
7149
7150 static inline int
7151 extra_goodness (int templ, int slot)
7152 {
7153   switch (md.tune)
7154     {
7155     case itanium1:
7156       if (slot == 1 && match (templ, IA64_TYPE_F, slot))
7157         return 2;
7158       else if (slot == 2 && match (templ, IA64_TYPE_B, slot))
7159         return 1;
7160       else
7161         return 0;
7162       break;
7163     case itanium2:
7164       if (match (templ, IA64_TYPE_M, slot)
7165           || match (templ, IA64_TYPE_I, slot))
7166         /* Favor M- and I-unit NOPs.  We definitely want to avoid
7167            F-unit and B-unit may cause split-issue or less-than-optimal
7168            branch-prediction.  */
7169         return 2;
7170       else
7171         return 0;
7172       break;
7173     default:
7174       abort ();
7175       return 0;
7176     }
7177 }
7178
7179 /* This function is called once, at assembler startup time.  It sets
7180    up all the tables, etc. that the MD part of the assembler will need
7181    that can be determined before arguments are parsed.  */
7182 void
7183 md_begin ()
7184 {
7185   int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
7186   const char *err;
7187   char name[8];
7188
7189   md.auto_align = 1;
7190   md.explicit_mode = md.default_explicit_mode;
7191
7192   bfd_set_section_alignment (stdoutput, text_section, 4);
7193
7194   /* Make sure function pointers get initialized.  */
7195   target_big_endian = -1;
7196   dot_byteorder (default_big_endian);
7197
7198   alias_hash = hash_new ();
7199   alias_name_hash = hash_new ();
7200   secalias_hash = hash_new ();
7201   secalias_name_hash = hash_new ();
7202
7203   pseudo_func[FUNC_DTP_MODULE].u.sym =
7204     symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
7205                 &zero_address_frag);
7206
7207   pseudo_func[FUNC_DTP_RELATIVE].u.sym =
7208     symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
7209                 &zero_address_frag);
7210
7211   pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
7212     symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
7213                 &zero_address_frag);
7214
7215   pseudo_func[FUNC_GP_RELATIVE].u.sym =
7216     symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
7217                 &zero_address_frag);
7218
7219   pseudo_func[FUNC_LT_RELATIVE].u.sym =
7220     symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
7221                 &zero_address_frag);
7222
7223   pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
7224     symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
7225                 &zero_address_frag);
7226
7227   pseudo_func[FUNC_PC_RELATIVE].u.sym =
7228     symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
7229                 &zero_address_frag);
7230
7231   pseudo_func[FUNC_PLT_RELATIVE].u.sym =
7232     symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
7233                 &zero_address_frag);
7234
7235   pseudo_func[FUNC_SEC_RELATIVE].u.sym =
7236     symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
7237                 &zero_address_frag);
7238
7239   pseudo_func[FUNC_SEG_RELATIVE].u.sym =
7240     symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
7241                 &zero_address_frag);
7242
7243   pseudo_func[FUNC_TP_RELATIVE].u.sym =
7244     symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
7245                 &zero_address_frag);
7246
7247   pseudo_func[FUNC_LTV_RELATIVE].u.sym =
7248     symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
7249                 &zero_address_frag);
7250
7251   pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
7252     symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
7253                 &zero_address_frag);
7254
7255   pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
7256     symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
7257                 &zero_address_frag);
7258
7259   pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
7260     symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
7261                 &zero_address_frag);
7262
7263   pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
7264     symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
7265                 &zero_address_frag);
7266
7267   pseudo_func[FUNC_IPLT_RELOC].u.sym =
7268     symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
7269                 &zero_address_frag);
7270
7271  if (md.tune != itanium1)
7272    {
7273      /* Convert MFI NOPs bundles into MMI NOPs bundles.  */
7274      le_nop[0] = 0x8;
7275      le_nop_stop[0] = 0x9;
7276    }
7277
7278   /* Compute the table of best templates.  We compute goodness as a
7279      base 4 value, in which each match counts for 3.  Match-failures
7280      result in NOPs and we use extra_goodness() to pick the execution
7281      units that are best suited for issuing the NOP.  */
7282   for (i = 0; i < IA64_NUM_TYPES; ++i)
7283     for (j = 0; j < IA64_NUM_TYPES; ++j)
7284       for (k = 0; k < IA64_NUM_TYPES; ++k)
7285         {
7286           best = 0;
7287           for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
7288             {
7289               goodness = 0;
7290               if (match (t, i, 0))
7291                 {
7292                   if (match (t, j, 1))
7293                     {
7294                       if ((t == 2 && j == IA64_TYPE_X) || match (t, k, 2))
7295                         goodness = 3 + 3 + 3;
7296                       else
7297                         goodness = 3 + 3 + extra_goodness (t, 2);
7298                     }
7299                   else if (match (t, j, 2))
7300                     goodness = 3 + 3 + extra_goodness (t, 1);
7301                   else
7302                     {
7303                       goodness = 3;
7304                       goodness += extra_goodness (t, 1);
7305                       goodness += extra_goodness (t, 2);
7306                     }
7307                 }
7308               else if (match (t, i, 1))
7309                 {
7310                   if ((t == 2 && i == IA64_TYPE_X) || match (t, j, 2))
7311                     goodness = 3 + 3;
7312                   else
7313                     goodness = 3 + extra_goodness (t, 2);
7314                 }
7315               else if (match (t, i, 2))
7316                 goodness = 3 + extra_goodness (t, 1);
7317
7318               if (goodness > best)
7319                 {
7320                   best = goodness;
7321                   best_template[i][j][k] = t;
7322                 }
7323             }
7324         }
7325
7326 #ifdef DEBUG_TEMPLATES
7327   /* For debugging changes to the best_template calculations.  We don't care
7328      about combinations with invalid instructions, so start the loops at 1.  */
7329   for (i = 0; i < IA64_NUM_TYPES; ++i)
7330     for (j = 0; j < IA64_NUM_TYPES; ++j)
7331       for (k = 0; k < IA64_NUM_TYPES; ++k)
7332         {
7333           char type_letter[IA64_NUM_TYPES] = { 'n', 'a', 'i', 'm', 'b', 'f',
7334                                                'x', 'd' };
7335           fprintf (stderr, "%c%c%c %s\n", type_letter[i], type_letter[j],
7336                    type_letter[k],
7337                    ia64_templ_desc[best_template[i][j][k]].name);
7338         }
7339 #endif
7340
7341   for (i = 0; i < NUM_SLOTS; ++i)
7342     md.slot[i].user_template = -1;
7343
7344   md.pseudo_hash = hash_new ();
7345   for (i = 0; i < NELEMS (pseudo_opcode); ++i)
7346     {
7347       err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
7348                          (void *) (pseudo_opcode + i));
7349       if (err)
7350         as_fatal ("ia64.md_begin: can't hash `%s': %s",
7351                   pseudo_opcode[i].name, err);
7352     }
7353
7354   md.reg_hash = hash_new ();
7355   md.dynreg_hash = hash_new ();
7356   md.const_hash = hash_new ();
7357   md.entry_hash = hash_new ();
7358
7359   /* general registers:  */
7360
7361   total = 128;
7362   for (i = 0; i < total; ++i)
7363     {
7364       sprintf (name, "r%d", i - REG_GR);
7365       md.regsym[i] = declare_register (name, i);
7366     }
7367
7368   /* floating point registers:  */
7369   total += 128;
7370   for (; i < total; ++i)
7371     {
7372       sprintf (name, "f%d", i - REG_FR);
7373       md.regsym[i] = declare_register (name, i);
7374     }
7375
7376   /* application registers:  */
7377   total += 128;
7378   ar_base = i;
7379   for (; i < total; ++i)
7380     {
7381       sprintf (name, "ar%d", i - REG_AR);
7382       md.regsym[i] = declare_register (name, i);
7383     }
7384
7385   /* control registers:  */
7386   total += 128;
7387   cr_base = i;
7388   for (; i < total; ++i)
7389     {
7390       sprintf (name, "cr%d", i - REG_CR);
7391       md.regsym[i] = declare_register (name, i);
7392     }
7393
7394   /* predicate registers:  */
7395   total += 64;
7396   for (; i < total; ++i)
7397     {
7398       sprintf (name, "p%d", i - REG_P);
7399       md.regsym[i] = declare_register (name, i);
7400     }
7401
7402   /* branch registers:  */
7403   total += 8;
7404   for (; i < total; ++i)
7405     {
7406       sprintf (name, "b%d", i - REG_BR);
7407       md.regsym[i] = declare_register (name, i);
7408     }
7409
7410   md.regsym[REG_IP] = declare_register ("ip", REG_IP);
7411   md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
7412   md.regsym[REG_PR] = declare_register ("pr", REG_PR);
7413   md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
7414   md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
7415   md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
7416   md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
7417
7418   for (i = 0; i < NELEMS (indirect_reg); ++i)
7419     {
7420       regnum = indirect_reg[i].regnum;
7421       md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
7422     }
7423
7424   /* define synonyms for application registers:  */
7425   for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
7426     md.regsym[i] = declare_register (ar[i - REG_AR].name,
7427                                      REG_AR + ar[i - REG_AR].regnum);
7428
7429   /* define synonyms for control registers:  */
7430   for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
7431     md.regsym[i] = declare_register (cr[i - REG_CR].name,
7432                                      REG_CR + cr[i - REG_CR].regnum);
7433
7434   declare_register ("gp", REG_GR +  1);
7435   declare_register ("sp", REG_GR + 12);
7436   declare_register ("rp", REG_BR +  0);
7437
7438   /* pseudo-registers used to specify unwind info:  */
7439   declare_register ("psp", REG_PSP);
7440
7441   declare_register_set ("ret", 4, REG_GR + 8);
7442   declare_register_set ("farg", 8, REG_FR + 8);
7443   declare_register_set ("fret", 8, REG_FR + 8);
7444
7445   for (i = 0; i < NELEMS (const_bits); ++i)
7446     {
7447       err = hash_insert (md.const_hash, const_bits[i].name,
7448                          (PTR) (const_bits + i));
7449       if (err)
7450         as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
7451                   name, err);
7452     }
7453
7454   /* Set the architecture and machine depending on defaults and command line
7455      options.  */
7456   if (md.flags & EF_IA_64_ABI64)
7457     ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
7458   else
7459     ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
7460
7461   if (! ok)
7462      as_warn (_("Could not set architecture and machine"));
7463
7464   /* Set the pointer size and pointer shift size depending on md.flags */
7465
7466   if (md.flags & EF_IA_64_ABI64)
7467     {
7468       md.pointer_size = 8;         /* pointers are 8 bytes */
7469       md.pointer_size_shift = 3;   /* alignment is 8 bytes = 2^2 */
7470     }
7471   else
7472     {
7473       md.pointer_size = 4;         /* pointers are 4 bytes */
7474       md.pointer_size_shift = 2;   /* alignment is 4 bytes = 2^2 */
7475     }
7476
7477   md.mem_offset.hint = 0;
7478   md.path = 0;
7479   md.maxpaths = 0;
7480   md.entry_labels = NULL;
7481 }
7482
7483 /* Set the default options in md.  Cannot do this in md_begin because
7484    that is called after md_parse_option which is where we set the
7485    options in md based on command line options.  */
7486
7487 void
7488 ia64_init (argc, argv)
7489      int argc ATTRIBUTE_UNUSED;
7490      char **argv ATTRIBUTE_UNUSED;
7491 {
7492   md.flags = MD_FLAGS_DEFAULT;
7493   md.detect_dv = 1;
7494   /* FIXME: We should change it to unwind_check_error someday.  */
7495   md.unwind_check = unwind_check_warning;
7496   md.hint_b = hint_b_error;
7497   md.tune = itanium2;
7498 }
7499
7500 /* Return a string for the target object file format.  */
7501
7502 const char *
7503 ia64_target_format ()
7504 {
7505   if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7506     {
7507       if (md.flags & EF_IA_64_BE)
7508         {
7509           if (md.flags & EF_IA_64_ABI64)
7510 #if defined(TE_AIX50)
7511             return "elf64-ia64-aix-big";
7512 #elif defined(TE_HPUX)
7513             return "elf64-ia64-hpux-big";
7514 #else
7515             return "elf64-ia64-big";
7516 #endif
7517           else
7518 #if defined(TE_AIX50)
7519             return "elf32-ia64-aix-big";
7520 #elif defined(TE_HPUX)
7521             return "elf32-ia64-hpux-big";
7522 #else
7523             return "elf32-ia64-big";
7524 #endif
7525         }
7526       else
7527         {
7528           if (md.flags & EF_IA_64_ABI64)
7529 #ifdef TE_AIX50
7530             return "elf64-ia64-aix-little";
7531 #else
7532             return "elf64-ia64-little";
7533 #endif
7534           else
7535 #ifdef TE_AIX50
7536             return "elf32-ia64-aix-little";
7537 #else
7538             return "elf32-ia64-little";
7539 #endif
7540         }
7541     }
7542   else
7543     return "unknown-format";
7544 }
7545
7546 void
7547 ia64_end_of_source ()
7548 {
7549   /* terminate insn group upon reaching end of file:  */
7550   insn_group_break (1, 0, 0);
7551
7552   /* emits slots we haven't written yet:  */
7553   ia64_flush_insns ();
7554
7555   bfd_set_private_flags (stdoutput, md.flags);
7556
7557   md.mem_offset.hint = 0;
7558 }
7559
7560 void
7561 ia64_start_line ()
7562 {
7563   if (md.qp.X_op == O_register)
7564     as_bad ("qualifying predicate not followed by instruction");
7565   md.qp.X_op = O_absent;
7566
7567   if (ignore_input ())
7568     return;
7569
7570   if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7571     {
7572       if (md.detect_dv && !md.explicit_mode)
7573         {
7574           static int warned;
7575
7576           if (!warned)
7577             {
7578               warned = 1;
7579               as_warn (_("Explicit stops are ignored in auto mode"));
7580             }
7581         }
7582       else
7583         insn_group_break (1, 0, 0);
7584     }
7585 }
7586
7587 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7588    labels.  */
7589 static int defining_tag = 0;
7590
7591 int
7592 ia64_unrecognized_line (ch)
7593      int ch;
7594 {
7595   switch (ch)
7596     {
7597     case '(':
7598       expression (&md.qp);
7599       if (*input_line_pointer++ != ')')
7600         {
7601           as_bad ("Expected ')'");
7602           return 0;
7603         }
7604       if (md.qp.X_op != O_register)
7605         {
7606           as_bad ("Qualifying predicate expected");
7607           return 0;
7608         }
7609       if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7610         {
7611           as_bad ("Predicate register expected");
7612           return 0;
7613         }
7614       return 1;
7615
7616     case '{':
7617       if (md.manual_bundling)
7618         as_warn ("Found '{' when manual bundling is already turned on");
7619       else
7620         CURR_SLOT.manual_bundling_on = 1;
7621       md.manual_bundling = 1;
7622
7623       /* Bundling is only acceptable in explicit mode
7624          or when in default automatic mode.  */
7625       if (md.detect_dv && !md.explicit_mode)
7626         {
7627           if (!md.mode_explicitly_set
7628               && !md.default_explicit_mode)
7629             dot_dv_mode ('E');
7630           else
7631             as_warn (_("Found '{' after explicit switch to automatic mode"));
7632         }
7633       return 1;
7634
7635     case '}':
7636       if (!md.manual_bundling)
7637         as_warn ("Found '}' when manual bundling is off");
7638       else
7639         PREV_SLOT.manual_bundling_off = 1;
7640       md.manual_bundling = 0;
7641
7642       /* switch back to automatic mode, if applicable */
7643       if (md.detect_dv
7644           && md.explicit_mode
7645           && !md.mode_explicitly_set
7646           && !md.default_explicit_mode)
7647         dot_dv_mode ('A');
7648
7649       /* Allow '{' to follow on the same line.  We also allow ";;", but that
7650          happens automatically because ';' is an end of line marker.  */
7651       SKIP_WHITESPACE ();
7652       if (input_line_pointer[0] == '{')
7653         {
7654           input_line_pointer++;
7655           return ia64_unrecognized_line ('{');
7656         }
7657
7658       demand_empty_rest_of_line ();
7659       return 1;
7660
7661     case '[':
7662       {
7663         char *s;
7664         char c;
7665         symbolS *tag;
7666         int temp;
7667
7668         if (md.qp.X_op == O_register)
7669           {
7670             as_bad ("Tag must come before qualifying predicate.");
7671             return 0;
7672           }
7673
7674         /* This implements just enough of read_a_source_file in read.c to
7675            recognize labels.  */
7676         if (is_name_beginner (*input_line_pointer))
7677           {
7678             s = input_line_pointer;
7679             c = get_symbol_end ();
7680           }
7681         else if (LOCAL_LABELS_FB
7682                  && ISDIGIT (*input_line_pointer))
7683           {
7684             temp = 0;
7685             while (ISDIGIT (*input_line_pointer))
7686               temp = (temp * 10) + *input_line_pointer++ - '0';
7687             fb_label_instance_inc (temp);
7688             s = fb_label_name (temp, 0);
7689             c = *input_line_pointer;
7690           }
7691         else
7692           {
7693             s = NULL;
7694             c = '\0';
7695           }
7696         if (c != ':')
7697           {
7698             /* Put ':' back for error messages' sake.  */
7699             *input_line_pointer++ = ':';
7700             as_bad ("Expected ':'");
7701             return 0;
7702           }
7703
7704         defining_tag = 1;
7705         tag = colon (s);
7706         defining_tag = 0;
7707         /* Put ':' back for error messages' sake.  */
7708         *input_line_pointer++ = ':';
7709         if (*input_line_pointer++ != ']')
7710           {
7711             as_bad ("Expected ']'");
7712             return 0;
7713           }
7714         if (! tag)
7715           {
7716             as_bad ("Tag name expected");
7717             return 0;
7718           }
7719         return 1;
7720       }
7721
7722     default:
7723       break;
7724     }
7725
7726   /* Not a valid line.  */
7727   return 0;
7728 }
7729
7730 void
7731 ia64_frob_label (sym)
7732      struct symbol *sym;
7733 {
7734   struct label_fix *fix;
7735
7736   /* Tags need special handling since they are not bundle breaks like
7737      labels.  */
7738   if (defining_tag)
7739     {
7740       fix = obstack_alloc (&notes, sizeof (*fix));
7741       fix->sym = sym;
7742       fix->next = CURR_SLOT.tag_fixups;
7743       CURR_SLOT.tag_fixups = fix;
7744
7745       return;
7746     }
7747
7748   if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7749     {
7750       md.last_text_seg = now_seg;
7751       fix = obstack_alloc (&notes, sizeof (*fix));
7752       fix->sym = sym;
7753       fix->next = CURR_SLOT.label_fixups;
7754       CURR_SLOT.label_fixups = fix;
7755
7756       /* Keep track of how many code entry points we've seen.  */
7757       if (md.path == md.maxpaths)
7758         {
7759           md.maxpaths += 20;
7760           md.entry_labels = (const char **)
7761             xrealloc ((void *) md.entry_labels,
7762                       md.maxpaths * sizeof (char *));
7763         }
7764       md.entry_labels[md.path++] = S_GET_NAME (sym);
7765     }
7766 }
7767
7768 #ifdef TE_HPUX
7769 /* The HP-UX linker will give unresolved symbol errors for symbols
7770    that are declared but unused.  This routine removes declared,
7771    unused symbols from an object.  */
7772 int
7773 ia64_frob_symbol (sym)
7774      struct symbol *sym;
7775 {
7776   if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7777        ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7778       || (S_GET_SEGMENT (sym) == &bfd_abs_section
7779           && ! S_IS_EXTERNAL (sym)))
7780     return 1;
7781   return 0;
7782 }
7783 #endif
7784
7785 void
7786 ia64_flush_pending_output ()
7787 {
7788   if (!md.keep_pending_output
7789       && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7790     {
7791       /* ??? This causes many unnecessary stop bits to be emitted.
7792          Unfortunately, it isn't clear if it is safe to remove this.  */
7793       insn_group_break (1, 0, 0);
7794       ia64_flush_insns ();
7795     }
7796 }
7797
7798 /* Do ia64-specific expression optimization.  All that's done here is
7799    to transform index expressions that are either due to the indexing
7800    of rotating registers or due to the indexing of indirect register
7801    sets.  */
7802 int
7803 ia64_optimize_expr (l, op, r)
7804      expressionS *l;
7805      operatorT op;
7806      expressionS *r;
7807 {
7808   unsigned num_regs;
7809
7810   if (op == O_index)
7811     {
7812       if (l->X_op == O_register && r->X_op == O_constant)
7813         {
7814           num_regs = (l->X_add_number >> 16);
7815           if ((unsigned) r->X_add_number >= num_regs)
7816             {
7817               if (!num_regs)
7818                 as_bad ("No current frame");
7819               else
7820                 as_bad ("Index out of range 0..%u", num_regs - 1);
7821               r->X_add_number = 0;
7822             }
7823           l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7824           return 1;
7825         }
7826       else if (l->X_op == O_register && r->X_op == O_register)
7827         {
7828           if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7829               || l->X_add_number == IND_MEM)
7830             {
7831               as_bad ("Indirect register set name expected");
7832               l->X_add_number = IND_CPUID;
7833             }
7834           l->X_op = O_index;
7835           l->X_op_symbol = md.regsym[l->X_add_number];
7836           l->X_add_number = r->X_add_number;
7837           return 1;
7838         }
7839     }
7840   return 0;
7841 }
7842
7843 int
7844 ia64_parse_name (name, e, nextcharP)
7845      char *name;
7846      expressionS *e;
7847      char *nextcharP;
7848 {
7849   struct const_desc *cdesc;
7850   struct dynreg *dr = 0;
7851   unsigned int idx;
7852   struct symbol *sym;
7853   char *end;
7854
7855   if (*name == '@')
7856     {
7857       enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE;
7858
7859       /* Find what relocation pseudo-function we're dealing with.  */
7860       for (idx = 0; idx < NELEMS (pseudo_func); ++idx)
7861         if (pseudo_func[idx].name
7862             && pseudo_func[idx].name[0] == name[1]
7863             && strcmp (pseudo_func[idx].name + 1, name + 2) == 0)
7864           {
7865             pseudo_type = pseudo_func[idx].type;
7866             break;
7867           }
7868       switch (pseudo_type)
7869         {
7870         case PSEUDO_FUNC_RELOC:
7871           end = input_line_pointer;
7872           if (*nextcharP != '(')
7873             {
7874               as_bad ("Expected '('");
7875               break;
7876             }
7877           /* Skip '('.  */
7878           ++input_line_pointer;
7879           expression (e);
7880           if (*input_line_pointer != ')')
7881             {
7882               as_bad ("Missing ')'");
7883               goto done;
7884             }
7885           /* Skip ')'.  */
7886           ++input_line_pointer;
7887           if (e->X_op != O_symbol)
7888             {
7889               if (e->X_op != O_pseudo_fixup)
7890                 {
7891                   as_bad ("Not a symbolic expression");
7892                   goto done;
7893                 }
7894               if (idx != FUNC_LT_RELATIVE)
7895                 {
7896                   as_bad ("Illegal combination of relocation functions");
7897                   goto done;
7898                 }
7899               switch (S_GET_VALUE (e->X_op_symbol))
7900                 {
7901                 case FUNC_FPTR_RELATIVE:
7902                   idx = FUNC_LT_FPTR_RELATIVE; break;
7903                 case FUNC_DTP_MODULE:
7904                   idx = FUNC_LT_DTP_MODULE; break;
7905                 case FUNC_DTP_RELATIVE:
7906                   idx = FUNC_LT_DTP_RELATIVE; break;
7907                 case FUNC_TP_RELATIVE:
7908                   idx = FUNC_LT_TP_RELATIVE; break;
7909                 default:
7910                   as_bad ("Illegal combination of relocation functions");
7911                   goto done;
7912                 }
7913             }
7914           /* Make sure gas doesn't get rid of local symbols that are used
7915              in relocs.  */
7916           e->X_op = O_pseudo_fixup;
7917           e->X_op_symbol = pseudo_func[idx].u.sym;
7918         done:
7919           *nextcharP = *input_line_pointer;
7920           break;
7921
7922         case PSEUDO_FUNC_CONST:
7923           e->X_op = O_constant;
7924           e->X_add_number = pseudo_func[idx].u.ival;
7925           break;
7926
7927         case PSEUDO_FUNC_REG:
7928           e->X_op = O_register;
7929           e->X_add_number = pseudo_func[idx].u.ival;
7930           break;
7931
7932         default:
7933           return 0;
7934         }
7935       return 1;
7936     }
7937
7938   /* first see if NAME is a known register name:  */
7939   sym = hash_find (md.reg_hash, name);
7940   if (sym)
7941     {
7942       e->X_op = O_register;
7943       e->X_add_number = S_GET_VALUE (sym);
7944       return 1;
7945     }
7946
7947   cdesc = hash_find (md.const_hash, name);
7948   if (cdesc)
7949     {
7950       e->X_op = O_constant;
7951       e->X_add_number = cdesc->value;
7952       return 1;
7953     }
7954
7955   /* check for inN, locN, or outN:  */
7956   idx = 0;
7957   switch (name[0])
7958     {
7959     case 'i':
7960       if (name[1] == 'n' && ISDIGIT (name[2]))
7961         {
7962           dr = &md.in;
7963           idx = 2;
7964         }
7965       break;
7966
7967     case 'l':
7968       if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7969         {
7970           dr = &md.loc;
7971           idx = 3;
7972         }
7973       break;
7974
7975     case 'o':
7976       if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7977         {
7978           dr = &md.out;
7979           idx = 3;
7980         }
7981       break;
7982
7983     default:
7984       break;
7985     }
7986
7987   /* Ignore register numbers with leading zeroes, except zero itself.  */
7988   if (dr && (name[idx] != '0' || name[idx + 1] == '\0'))
7989     {
7990       unsigned long regnum;
7991
7992       /* The name is inN, locN, or outN; parse the register number.  */
7993       regnum = strtoul (name + idx, &end, 10);
7994       if (end > name + idx && *end == '\0' && regnum < 96)
7995         {
7996           if (regnum >= dr->num_regs)
7997             {
7998               if (!dr->num_regs)
7999                 as_bad ("No current frame");
8000               else
8001                 as_bad ("Register number out of range 0..%u",
8002                         dr->num_regs - 1);
8003               regnum = 0;
8004             }
8005           e->X_op = O_register;
8006           e->X_add_number = dr->base + regnum;
8007           return 1;
8008         }
8009     }
8010
8011   end = alloca (strlen (name) + 1);
8012   strcpy (end, name);
8013   name = ia64_canonicalize_symbol_name (end);
8014   if ((dr = hash_find (md.dynreg_hash, name)))
8015     {
8016       /* We've got ourselves the name of a rotating register set.
8017          Store the base register number in the low 16 bits of
8018          X_add_number and the size of the register set in the top 16
8019          bits.  */
8020       e->X_op = O_register;
8021       e->X_add_number = dr->base | (dr->num_regs << 16);
8022       return 1;
8023     }
8024   return 0;
8025 }
8026
8027 /* Remove the '#' suffix that indicates a symbol as opposed to a register.  */
8028
8029 char *
8030 ia64_canonicalize_symbol_name (name)
8031      char *name;
8032 {
8033   size_t len = strlen (name), full = len;
8034
8035   while (len > 0 && name[len - 1] == '#')
8036     --len;
8037   if (len <= 0)
8038     {
8039       if (full > 0)
8040         as_bad ("Standalone `#' is illegal");
8041     }
8042   else if (len < full - 1)
8043     as_warn ("Redundant `#' suffix operators");
8044   name[len] = '\0';
8045   return name;
8046 }
8047
8048 /* Return true if idesc is a conditional branch instruction.  This excludes
8049    the modulo scheduled branches, and br.ia.  Mod-sched branches are excluded
8050    because they always read/write resources regardless of the value of the
8051    qualifying predicate.  br.ia must always use p0, and hence is always
8052    taken.  Thus this function returns true for branches which can fall
8053    through, and which use no resources if they do fall through.  */
8054
8055 static int
8056 is_conditional_branch (idesc)
8057      struct ia64_opcode *idesc;
8058 {
8059   /* br is a conditional branch.  Everything that starts with br. except
8060      br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
8061      Everything that starts with brl is a conditional branch.  */
8062   return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
8063           && (idesc->name[2] == '\0'
8064               || (idesc->name[2] == '.' && idesc->name[3] != 'i'
8065                   && idesc->name[3] != 'c' && idesc->name[3] != 'w')
8066               || idesc->name[2] == 'l'
8067               /* br.cond, br.call, br.clr  */
8068               || (idesc->name[2] == '.' && idesc->name[3] == 'c'
8069                   && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
8070                       || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
8071 }
8072
8073 /* Return whether the given opcode is a taken branch.  If there's any doubt,
8074    returns zero.  */
8075
8076 static int
8077 is_taken_branch (idesc)
8078      struct ia64_opcode *idesc;
8079 {
8080   return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
8081           || strncmp (idesc->name, "br.ia", 5) == 0);
8082 }
8083
8084 /* Return whether the given opcode is an interruption or rfi.  If there's any
8085    doubt, returns zero.  */
8086
8087 static int
8088 is_interruption_or_rfi (idesc)
8089      struct ia64_opcode *idesc;
8090 {
8091   if (strcmp (idesc->name, "rfi") == 0)
8092     return 1;
8093   return 0;
8094 }
8095
8096 /* Returns the index of the given dependency in the opcode's list of chks, or
8097    -1 if there is no dependency.  */
8098
8099 static int
8100 depends_on (depind, idesc)
8101      int depind;
8102      struct ia64_opcode *idesc;
8103 {
8104   int i;
8105   const struct ia64_opcode_dependency *dep = idesc->dependencies;
8106   for (i = 0; i < dep->nchks; i++)
8107     {
8108       if (depind == DEP (dep->chks[i]))
8109         return i;
8110     }
8111   return -1;
8112 }
8113
8114 /* Determine a set of specific resources used for a particular resource
8115    class.  Returns the number of specific resources identified  For those
8116    cases which are not determinable statically, the resource returned is
8117    marked nonspecific.
8118
8119    Meanings of value in 'NOTE':
8120    1) only read/write when the register number is explicitly encoded in the
8121    insn.
8122    2) only read CFM when accessing a rotating GR, FR, or PR.  mov pr only
8123    accesses CFM when qualifying predicate is in the rotating region.
8124    3) general register value is used to specify an indirect register; not
8125    determinable statically.
8126    4) only read the given resource when bits 7:0 of the indirect index
8127    register value does not match the register number of the resource; not
8128    determinable statically.
8129    5) all rules are implementation specific.
8130    6) only when both the index specified by the reader and the index specified
8131    by the writer have the same value in bits 63:61; not determinable
8132    statically.
8133    7) only access the specified resource when the corresponding mask bit is
8134    set
8135    8) PSR.dfh is only read when these insns reference FR32-127.  PSR.dfl is
8136    only read when these insns reference FR2-31
8137    9) PSR.mfl is only written when these insns write FR2-31.  PSR.mfh is only
8138    written when these insns write FR32-127
8139    10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
8140    instruction
8141    11) The target predicates are written independently of PR[qp], but source
8142    registers are only read if PR[qp] is true.  Since the state of PR[qp]
8143    cannot statically be determined, all source registers are marked used.
8144    12) This insn only reads the specified predicate register when that
8145    register is the PR[qp].
8146    13) This reference to ld-c only applies to teh GR whose value is loaded
8147    with data returned from memory, not the post-incremented address register.
8148    14) The RSE resource includes the implementation-specific RSE internal
8149    state resources.  At least one (and possibly more) of these resources are
8150    read by each instruction listed in IC:rse-readers.  At least one (and
8151    possibly more) of these resources are written by each insn listed in
8152    IC:rse-writers.
8153    15+16) Represents reserved instructions, which the assembler does not
8154    generate.
8155
8156    Memory resources (i.e. locations in memory) are *not* marked or tracked by
8157    this code; there are no dependency violations based on memory access.
8158 */
8159
8160 #define MAX_SPECS 256
8161 #define DV_CHK 1
8162 #define DV_REG 0
8163
8164 static int
8165 specify_resource (dep, idesc, type, specs, note, path)
8166      const struct ia64_dependency *dep;
8167      struct ia64_opcode *idesc;
8168      int type;                         /* is this a DV chk or a DV reg? */
8169      struct rsrc specs[MAX_SPECS];     /* returned specific resources */
8170      int note;                         /* resource note for this insn's usage */
8171      int path;                         /* which execution path to examine */
8172 {
8173   int count = 0;
8174   int i;
8175   int rsrc_write = 0;
8176   struct rsrc tmpl;
8177
8178   if (dep->mode == IA64_DV_WAW
8179       || (dep->mode == IA64_DV_RAW && type == DV_REG)
8180       || (dep->mode == IA64_DV_WAR && type == DV_CHK))
8181     rsrc_write = 1;
8182
8183   /* template for any resources we identify */
8184   tmpl.dependency = dep;
8185   tmpl.note = note;
8186   tmpl.insn_srlz = tmpl.data_srlz = 0;
8187   tmpl.qp_regno = CURR_SLOT.qp_regno;
8188   tmpl.link_to_qp_branch = 1;
8189   tmpl.mem_offset.hint = 0;
8190   tmpl.mem_offset.offset = 0;
8191   tmpl.mem_offset.base = 0;
8192   tmpl.specific = 1;
8193   tmpl.index = -1;
8194   tmpl.cmp_type = CMP_NONE;
8195   tmpl.depind = 0;
8196   tmpl.file = NULL;
8197   tmpl.line = 0;
8198   tmpl.path = 0;
8199
8200 #define UNHANDLED \
8201 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
8202 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
8203 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
8204
8205   /* we don't need to track these */
8206   if (dep->semantics == IA64_DVS_NONE)
8207     return 0;
8208
8209   switch (dep->specifier)
8210     {
8211     case IA64_RS_AR_K:
8212       if (note == 1)
8213         {
8214           if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8215             {
8216               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8217               if (regno >= 0 && regno <= 7)
8218                 {
8219                   specs[count] = tmpl;
8220                   specs[count++].index = regno;
8221                 }
8222             }
8223         }
8224       else if (note == 0)
8225         {
8226           for (i = 0; i < 8; i++)
8227             {
8228               specs[count] = tmpl;
8229               specs[count++].index = i;
8230             }
8231         }
8232       else
8233         {
8234           UNHANDLED;
8235         }
8236       break;
8237
8238     case IA64_RS_AR_UNAT:
8239       /* This is a mov =AR or mov AR= instruction.  */
8240       if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8241         {
8242           int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8243           if (regno == AR_UNAT)
8244             {
8245               specs[count++] = tmpl;
8246             }
8247         }
8248       else
8249         {
8250           /* This is a spill/fill, or other instruction that modifies the
8251              unat register.  */
8252
8253           /* Unless we can determine the specific bits used, mark the whole
8254              thing; bits 8:3 of the memory address indicate the bit used in
8255              UNAT.  The .mem.offset hint may be used to eliminate a small
8256              subset of conflicts.  */
8257           specs[count] = tmpl;
8258           if (md.mem_offset.hint)
8259             {
8260               if (md.debug_dv)
8261                 fprintf (stderr, "  Using hint for spill/fill\n");
8262               /* The index isn't actually used, just set it to something
8263                  approximating the bit index.  */
8264               specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
8265               specs[count].mem_offset.hint = 1;
8266               specs[count].mem_offset.offset = md.mem_offset.offset;
8267               specs[count++].mem_offset.base = md.mem_offset.base;
8268             }
8269           else
8270             {
8271               specs[count++].specific = 0;
8272             }
8273         }
8274       break;
8275
8276     case IA64_RS_AR:
8277       if (note == 1)
8278         {
8279           if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8280             {
8281               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8282               if ((regno >= 8 && regno <= 15)
8283                   || (regno >= 20 && regno <= 23)
8284                   || (regno >= 31 && regno <= 39)
8285                   || (regno >= 41 && regno <= 47)
8286                   || (regno >= 67 && regno <= 111))
8287                 {
8288                   specs[count] = tmpl;
8289                   specs[count++].index = regno;
8290                 }
8291             }
8292         }
8293       else
8294         {
8295           UNHANDLED;
8296         }
8297       break;
8298
8299     case IA64_RS_ARb:
8300       if (note == 1)
8301         {
8302           if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8303             {
8304               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8305               if ((regno >= 48 && regno <= 63)
8306                   || (regno >= 112 && regno <= 127))
8307                 {
8308                   specs[count] = tmpl;
8309                   specs[count++].index = regno;
8310                 }
8311             }
8312         }
8313       else if (note == 0)
8314         {
8315           for (i = 48; i < 64; i++)
8316             {
8317               specs[count] = tmpl;
8318               specs[count++].index = i;
8319             }
8320           for (i = 112; i < 128; i++)
8321             {
8322               specs[count] = tmpl;
8323               specs[count++].index = i;
8324             }
8325         }
8326       else
8327         {
8328           UNHANDLED;
8329         }
8330       break;
8331
8332     case IA64_RS_BR:
8333       if (note != 1)
8334         {
8335           UNHANDLED;
8336         }
8337       else
8338         {
8339           if (rsrc_write)
8340             {
8341               for (i = 0; i < idesc->num_outputs; i++)
8342                 if (idesc->operands[i] == IA64_OPND_B1
8343                     || idesc->operands[i] == IA64_OPND_B2)
8344                   {
8345                     specs[count] = tmpl;
8346                     specs[count++].index =
8347                       CURR_SLOT.opnd[i].X_add_number - REG_BR;
8348                   }
8349             }
8350           else
8351             {
8352               for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8353                 if (idesc->operands[i] == IA64_OPND_B1
8354                     || idesc->operands[i] == IA64_OPND_B2)
8355                   {
8356                     specs[count] = tmpl;
8357                     specs[count++].index =
8358                       CURR_SLOT.opnd[i].X_add_number - REG_BR;
8359                   }
8360             }
8361         }
8362       break;
8363
8364     case IA64_RS_CPUID: /* four or more registers */
8365       if (note == 3)
8366         {
8367           if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
8368             {
8369               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8370               if (regno >= 0 && regno < NELEMS (gr_values)
8371                   && KNOWN (regno))
8372                 {
8373                   specs[count] = tmpl;
8374                   specs[count++].index = gr_values[regno].value & 0xFF;
8375                 }
8376               else
8377                 {
8378                   specs[count] = tmpl;
8379                   specs[count++].specific = 0;
8380                 }
8381             }
8382         }
8383       else
8384         {
8385           UNHANDLED;
8386         }
8387       break;
8388
8389     case IA64_RS_DBR: /* four or more registers */
8390       if (note == 3)
8391         {
8392           if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
8393             {
8394               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8395               if (regno >= 0 && regno < NELEMS (gr_values)
8396                   && KNOWN (regno))
8397                 {
8398                   specs[count] = tmpl;
8399                   specs[count++].index = gr_values[regno].value & 0xFF;
8400                 }
8401               else
8402                 {
8403                   specs[count] = tmpl;
8404                   specs[count++].specific = 0;
8405                 }
8406             }
8407         }
8408       else if (note == 0 && !rsrc_write)
8409         {
8410           specs[count] = tmpl;
8411           specs[count++].specific = 0;
8412         }
8413       else
8414         {
8415           UNHANDLED;
8416         }
8417       break;
8418
8419     case IA64_RS_IBR: /* four or more registers */
8420       if (note == 3)
8421         {
8422           if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
8423             {
8424               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8425               if (regno >= 0 && regno < NELEMS (gr_values)
8426                   && KNOWN (regno))
8427                 {
8428                   specs[count] = tmpl;
8429                   specs[count++].index = gr_values[regno].value & 0xFF;
8430                 }
8431               else
8432                 {
8433                   specs[count] = tmpl;
8434                   specs[count++].specific = 0;
8435                 }
8436             }
8437         }
8438       else
8439         {
8440           UNHANDLED;
8441         }
8442       break;
8443
8444     case IA64_RS_MSR:
8445       if (note == 5)
8446         {
8447           /* These are implementation specific.  Force all references to
8448              conflict with all other references.  */
8449           specs[count] = tmpl;
8450           specs[count++].specific = 0;
8451         }
8452       else
8453         {
8454           UNHANDLED;
8455         }
8456       break;
8457
8458     case IA64_RS_PKR: /* 16 or more registers */
8459       if (note == 3 || note == 4)
8460         {
8461           if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
8462             {
8463               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8464               if (regno >= 0 && regno < NELEMS (gr_values)
8465                   && KNOWN (regno))
8466                 {
8467                   if (note == 3)
8468                     {
8469                       specs[count] = tmpl;
8470                       specs[count++].index = gr_values[regno].value & 0xFF;
8471                     }
8472                   else
8473                     for (i = 0; i < NELEMS (gr_values); i++)
8474                       {
8475                         /* Uses all registers *except* the one in R3.  */
8476                         if ((unsigned)i != (gr_values[regno].value & 0xFF))
8477                           {
8478                             specs[count] = tmpl;
8479                             specs[count++].index = i;
8480                           }
8481                       }
8482                 }
8483               else
8484                 {
8485                   specs[count] = tmpl;
8486                   specs[count++].specific = 0;
8487                 }
8488             }
8489         }
8490       else if (note == 0)
8491         {
8492           /* probe et al.  */
8493           specs[count] = tmpl;
8494           specs[count++].specific = 0;
8495         }
8496       break;
8497
8498     case IA64_RS_PMC: /* four or more registers */
8499       if (note == 3)
8500         {
8501           if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
8502               || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
8503
8504             {
8505               int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
8506                            ? 1 : !rsrc_write);
8507               int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
8508               if (regno >= 0 && regno < NELEMS (gr_values)
8509                   && KNOWN (regno))
8510                 {
8511                   specs[count] = tmpl;
8512                   specs[count++].index = gr_values[regno].value & 0xFF;
8513                 }
8514               else
8515                 {
8516                   specs[count] = tmpl;
8517                   specs[count++].specific = 0;
8518                 }
8519             }
8520         }
8521       else
8522         {
8523           UNHANDLED;
8524         }
8525       break;
8526
8527     case IA64_RS_PMD: /* four or more registers */
8528       if (note == 3)
8529         {
8530           if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
8531             {
8532               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8533               if (regno >= 0 && regno < NELEMS (gr_values)
8534                   && KNOWN (regno))
8535                 {
8536                   specs[count] = tmpl;
8537                   specs[count++].index = gr_values[regno].value & 0xFF;
8538                 }
8539               else
8540                 {
8541                   specs[count] = tmpl;
8542                   specs[count++].specific = 0;
8543                 }
8544             }
8545         }
8546       else
8547         {
8548           UNHANDLED;
8549         }
8550       break;
8551
8552     case IA64_RS_RR: /* eight registers */
8553       if (note == 6)
8554         {
8555           if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
8556             {
8557               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8558               if (regno >= 0 && regno < NELEMS (gr_values)
8559                   && KNOWN (regno))
8560                 {
8561                   specs[count] = tmpl;
8562                   specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
8563                 }
8564               else
8565                 {
8566                   specs[count] = tmpl;
8567                   specs[count++].specific = 0;
8568                 }
8569             }
8570         }
8571       else if (note == 0 && !rsrc_write)
8572         {
8573           specs[count] = tmpl;
8574           specs[count++].specific = 0;
8575         }
8576       else
8577         {
8578           UNHANDLED;
8579         }
8580       break;
8581
8582     case IA64_RS_CR_IRR:
8583       if (note == 0)
8584         {
8585           /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
8586           int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
8587           if (rsrc_write
8588               && idesc->operands[1] == IA64_OPND_CR3
8589               && regno == CR_IVR)
8590             {
8591               for (i = 0; i < 4; i++)
8592                 {
8593                   specs[count] = tmpl;
8594                   specs[count++].index = CR_IRR0 + i;
8595                 }
8596             }
8597         }
8598       else if (note == 1)
8599         {
8600           int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8601           if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8602               && regno >= CR_IRR0
8603               && regno <= CR_IRR3)
8604             {
8605               specs[count] = tmpl;
8606               specs[count++].index = regno;
8607             }
8608         }
8609       else
8610         {
8611           UNHANDLED;
8612         }
8613       break;
8614
8615     case IA64_RS_CR_LRR:
8616       if (note != 1)
8617         {
8618           UNHANDLED;
8619         }
8620       else
8621         {
8622           int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8623           if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8624               && (regno == CR_LRR0 || regno == CR_LRR1))
8625             {
8626               specs[count] = tmpl;
8627               specs[count++].index = regno;
8628             }
8629         }
8630       break;
8631
8632     case IA64_RS_CR:
8633       if (note == 1)
8634         {
8635           if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8636             {
8637               specs[count] = tmpl;
8638               specs[count++].index =
8639                 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8640             }
8641         }
8642       else
8643         {
8644           UNHANDLED;
8645         }
8646       break;
8647
8648     case IA64_RS_FR:
8649     case IA64_RS_FRb:
8650       if (note != 1)
8651         {
8652           UNHANDLED;
8653         }
8654       else if (rsrc_write)
8655         {
8656           if (dep->specifier == IA64_RS_FRb
8657               && idesc->operands[0] == IA64_OPND_F1)
8658             {
8659               specs[count] = tmpl;
8660               specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8661             }
8662         }
8663       else
8664         {
8665           for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8666             {
8667               if (idesc->operands[i] == IA64_OPND_F2
8668                   || idesc->operands[i] == IA64_OPND_F3
8669                   || idesc->operands[i] == IA64_OPND_F4)
8670                 {
8671                   specs[count] = tmpl;
8672                   specs[count++].index =
8673                     CURR_SLOT.opnd[i].X_add_number - REG_FR;
8674                 }
8675             }
8676         }
8677       break;
8678
8679     case IA64_RS_GR:
8680       if (note == 13)
8681         {
8682           /* This reference applies only to the GR whose value is loaded with
8683              data returned from memory.  */
8684           specs[count] = tmpl;
8685           specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8686         }
8687       else if (note == 1)
8688         {
8689           if (rsrc_write)
8690             {
8691               for (i = 0; i < idesc->num_outputs; i++)
8692                 if (idesc->operands[i] == IA64_OPND_R1
8693                     || idesc->operands[i] == IA64_OPND_R2
8694                     || idesc->operands[i] == IA64_OPND_R3)
8695                   {
8696                     specs[count] = tmpl;
8697                     specs[count++].index =
8698                       CURR_SLOT.opnd[i].X_add_number - REG_GR;
8699                   }
8700               if (idesc->flags & IA64_OPCODE_POSTINC)
8701                 for (i = 0; i < NELEMS (idesc->operands); i++)
8702                   if (idesc->operands[i] == IA64_OPND_MR3)
8703                     {
8704                       specs[count] = tmpl;
8705                       specs[count++].index =
8706                         CURR_SLOT.opnd[i].X_add_number - REG_GR;
8707                     }
8708             }
8709           else
8710             {
8711               /* Look for anything that reads a GR.  */
8712               for (i = 0; i < NELEMS (idesc->operands); i++)
8713                 {
8714                   if (idesc->operands[i] == IA64_OPND_MR3
8715                       || idesc->operands[i] == IA64_OPND_CPUID_R3
8716                       || idesc->operands[i] == IA64_OPND_DBR_R3
8717                       || idesc->operands[i] == IA64_OPND_IBR_R3
8718                       || idesc->operands[i] == IA64_OPND_MSR_R3
8719                       || idesc->operands[i] == IA64_OPND_PKR_R3
8720                       || idesc->operands[i] == IA64_OPND_PMC_R3
8721                       || idesc->operands[i] == IA64_OPND_PMD_R3
8722                       || idesc->operands[i] == IA64_OPND_RR_R3
8723                       || ((i >= idesc->num_outputs)
8724                           && (idesc->operands[i] == IA64_OPND_R1
8725                               || idesc->operands[i] == IA64_OPND_R2
8726                               || idesc->operands[i] == IA64_OPND_R3
8727                               /* addl source register.  */
8728                               || idesc->operands[i] == IA64_OPND_R3_2)))
8729                     {
8730                       specs[count] = tmpl;
8731                       specs[count++].index =
8732                         CURR_SLOT.opnd[i].X_add_number - REG_GR;
8733                     }
8734                 }
8735             }
8736         }
8737       else
8738         {
8739           UNHANDLED;
8740         }
8741       break;
8742
8743       /* This is the same as IA64_RS_PRr, except that the register range is
8744          from 1 - 15, and there are no rotating register reads/writes here.  */
8745     case IA64_RS_PR:
8746       if (note == 0)
8747         {
8748           for (i = 1; i < 16; i++)
8749             {
8750               specs[count] = tmpl;
8751               specs[count++].index = i;
8752             }
8753         }
8754       else if (note == 7)
8755         {
8756           valueT mask = 0;
8757           /* Mark only those registers indicated by the mask.  */
8758           if (rsrc_write)
8759             {
8760               mask = CURR_SLOT.opnd[2].X_add_number;
8761               for (i = 1; i < 16; i++)
8762                 if (mask & ((valueT) 1 << i))
8763                   {
8764                     specs[count] = tmpl;
8765                     specs[count++].index = i;
8766                   }
8767             }
8768           else
8769             {
8770               UNHANDLED;
8771             }
8772         }
8773       else if (note == 11) /* note 11 implies note 1 as well */
8774         {
8775           if (rsrc_write)
8776             {
8777               for (i = 0; i < idesc->num_outputs; i++)
8778                 {
8779                   if (idesc->operands[i] == IA64_OPND_P1
8780                       || idesc->operands[i] == IA64_OPND_P2)
8781                     {
8782                       int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8783                       if (regno >= 1 && regno < 16)
8784                         {
8785                           specs[count] = tmpl;
8786                           specs[count++].index = regno;
8787                         }
8788                     }
8789                 }
8790             }
8791           else
8792             {
8793               UNHANDLED;
8794             }
8795         }
8796       else if (note == 12)
8797         {
8798           if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8799             {
8800               specs[count] = tmpl;
8801               specs[count++].index = CURR_SLOT.qp_regno;
8802             }
8803         }
8804       else if (note == 1)
8805         {
8806           if (rsrc_write)
8807             {
8808               int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8809               int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8810               int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8811               int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8812
8813               if ((idesc->operands[0] == IA64_OPND_P1
8814                    || idesc->operands[0] == IA64_OPND_P2)
8815                   && p1 >= 1 && p1 < 16)
8816                 {
8817                   specs[count] = tmpl;
8818                   specs[count].cmp_type =
8819                     (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8820                   specs[count++].index = p1;
8821                 }
8822               if ((idesc->operands[1] == IA64_OPND_P1
8823                    || idesc->operands[1] == IA64_OPND_P2)
8824                   && p2 >= 1 && p2 < 16)
8825                 {
8826                   specs[count] = tmpl;
8827                   specs[count].cmp_type =
8828                     (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8829                   specs[count++].index = p2;
8830                 }
8831             }
8832           else
8833             {
8834               if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8835                 {
8836                   specs[count] = tmpl;
8837                   specs[count++].index = CURR_SLOT.qp_regno;
8838                 }
8839               if (idesc->operands[1] == IA64_OPND_PR)
8840                 {
8841                   for (i = 1; i < 16; i++)
8842                     {
8843                       specs[count] = tmpl;
8844                       specs[count++].index = i;
8845                     }
8846                 }
8847             }
8848         }
8849       else
8850         {
8851           UNHANDLED;
8852         }
8853       break;
8854
8855       /* This is the general case for PRs.  IA64_RS_PR and IA64_RS_PR63 are
8856          simplified cases of this.  */
8857     case IA64_RS_PRr:
8858       if (note == 0)
8859         {
8860           for (i = 16; i < 63; i++)
8861             {
8862               specs[count] = tmpl;
8863               specs[count++].index = i;
8864             }
8865         }
8866       else if (note == 7)
8867         {
8868           valueT mask = 0;
8869           /* Mark only those registers indicated by the mask.  */
8870           if (rsrc_write
8871               && idesc->operands[0] == IA64_OPND_PR)
8872             {
8873               mask = CURR_SLOT.opnd[2].X_add_number;
8874               if (mask & ((valueT) 1 << 16))
8875                 for (i = 16; i < 63; i++)
8876                   {
8877                     specs[count] = tmpl;
8878                     specs[count++].index = i;
8879                   }
8880             }
8881           else if (rsrc_write
8882                    && idesc->operands[0] == IA64_OPND_PR_ROT)
8883             {
8884               for (i = 16; i < 63; i++)
8885                 {
8886                   specs[count] = tmpl;
8887                   specs[count++].index = i;
8888                 }
8889             }
8890           else
8891             {
8892               UNHANDLED;
8893             }
8894         }
8895       else if (note == 11) /* note 11 implies note 1 as well */
8896         {
8897           if (rsrc_write)
8898             {
8899               for (i = 0; i < idesc->num_outputs; i++)
8900                 {
8901                   if (idesc->operands[i] == IA64_OPND_P1
8902                       || idesc->operands[i] == IA64_OPND_P2)
8903                     {
8904                       int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8905                       if (regno >= 16 && regno < 63)
8906                         {
8907                           specs[count] = tmpl;
8908                           specs[count++].index = regno;
8909                         }
8910                     }
8911                 }
8912             }
8913           else
8914             {
8915               UNHANDLED;
8916             }
8917         }
8918       else if (note == 12)
8919         {
8920           if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8921             {
8922               specs[count] = tmpl;
8923               specs[count++].index = CURR_SLOT.qp_regno;
8924             }
8925         }
8926       else if (note == 1)
8927         {
8928           if (rsrc_write)
8929             {
8930               int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8931               int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8932               int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8933               int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8934
8935               if ((idesc->operands[0] == IA64_OPND_P1
8936                    || idesc->operands[0] == IA64_OPND_P2)
8937                   && p1 >= 16 && p1 < 63)
8938                 {
8939                   specs[count] = tmpl;
8940                   specs[count].cmp_type =
8941                     (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8942                   specs[count++].index = p1;
8943                 }
8944               if ((idesc->operands[1] == IA64_OPND_P1
8945                    || idesc->operands[1] == IA64_OPND_P2)
8946                   && p2 >= 16 && p2 < 63)
8947                 {
8948                   specs[count] = tmpl;
8949                   specs[count].cmp_type =
8950                     (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8951                   specs[count++].index = p2;
8952                 }
8953             }
8954           else
8955             {
8956               if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8957                 {
8958                   specs[count] = tmpl;
8959                   specs[count++].index = CURR_SLOT.qp_regno;
8960                 }
8961               if (idesc->operands[1] == IA64_OPND_PR)
8962                 {
8963                   for (i = 16; i < 63; i++)
8964                     {
8965                       specs[count] = tmpl;
8966                       specs[count++].index = i;
8967                     }
8968                 }
8969             }
8970         }
8971       else
8972         {
8973           UNHANDLED;
8974         }
8975       break;
8976
8977     case IA64_RS_PSR:
8978       /* Verify that the instruction is using the PSR bit indicated in
8979          dep->regindex.  */
8980       if (note == 0)
8981         {
8982           if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8983             {
8984               if (dep->regindex < 6)
8985                 {
8986                   specs[count++] = tmpl;
8987                 }
8988             }
8989           else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8990             {
8991               if (dep->regindex < 32
8992                   || dep->regindex == 35
8993                   || dep->regindex == 36
8994                   || (!rsrc_write && dep->regindex == PSR_CPL))
8995                 {
8996                   specs[count++] = tmpl;
8997                 }
8998             }
8999           else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
9000             {
9001               if (dep->regindex < 32
9002                   || dep->regindex == 35
9003                   || dep->regindex == 36
9004                   || (rsrc_write && dep->regindex == PSR_CPL))
9005                 {
9006                   specs[count++] = tmpl;
9007                 }
9008             }
9009           else
9010             {
9011               /* Several PSR bits have very specific dependencies.  */
9012               switch (dep->regindex)
9013                 {
9014                 default:
9015                   specs[count++] = tmpl;
9016                   break;
9017                 case PSR_IC:
9018                   if (rsrc_write)
9019                     {
9020                       specs[count++] = tmpl;
9021                     }
9022                   else
9023                     {
9024                       /* Only certain CR accesses use PSR.ic */
9025                       if (idesc->operands[0] == IA64_OPND_CR3
9026                           || idesc->operands[1] == IA64_OPND_CR3)
9027                         {
9028                           int index =
9029                             ((idesc->operands[0] == IA64_OPND_CR3)
9030                              ? 0 : 1);
9031                           int regno =
9032                             CURR_SLOT.opnd[index].X_add_number - REG_CR;
9033
9034                           switch (regno)
9035                             {
9036                             default:
9037                               break;
9038                             case CR_ITIR:
9039                             case CR_IFS:
9040                             case CR_IIM:
9041                             case CR_IIP:
9042                             case CR_IPSR:
9043                             case CR_ISR:
9044                             case CR_IFA:
9045                             case CR_IHA:
9046                             case CR_IIPA:
9047                               specs[count++] = tmpl;
9048                               break;
9049                             }
9050                         }
9051                     }
9052                   break;
9053                 case PSR_CPL:
9054                   if (rsrc_write)
9055                     {
9056                       specs[count++] = tmpl;
9057                     }
9058                   else
9059                     {
9060                       /* Only some AR accesses use cpl */
9061                       if (idesc->operands[0] == IA64_OPND_AR3
9062                           || idesc->operands[1] == IA64_OPND_AR3)
9063                         {
9064                           int index =
9065                             ((idesc->operands[0] == IA64_OPND_AR3)
9066                              ? 0 : 1);
9067                           int regno =
9068                             CURR_SLOT.opnd[index].X_add_number - REG_AR;
9069
9070                           if (regno == AR_ITC
9071                               || (index == 0
9072                                   && (regno == AR_ITC
9073                                       || regno == AR_RSC
9074                                       || (regno >= AR_K0
9075                                           && regno <= AR_K7))))
9076                             {
9077                               specs[count++] = tmpl;
9078                             }
9079                         }
9080                       else
9081                         {
9082                           specs[count++] = tmpl;
9083                         }
9084                       break;
9085                     }
9086                 }
9087             }
9088         }
9089       else if (note == 7)
9090         {
9091           valueT mask = 0;
9092           if (idesc->operands[0] == IA64_OPND_IMMU24)
9093             {
9094               mask = CURR_SLOT.opnd[0].X_add_number;
9095             }
9096           else
9097             {
9098               UNHANDLED;
9099             }
9100           if (mask & ((valueT) 1 << dep->regindex))
9101             {
9102               specs[count++] = tmpl;
9103             }
9104         }
9105       else if (note == 8)
9106         {
9107           int min = dep->regindex == PSR_DFL ? 2 : 32;
9108           int max = dep->regindex == PSR_DFL ? 31 : 127;
9109           /* dfh is read on FR32-127; dfl is read on FR2-31 */
9110           for (i = 0; i < NELEMS (idesc->operands); i++)
9111             {
9112               if (idesc->operands[i] == IA64_OPND_F1
9113                   || idesc->operands[i] == IA64_OPND_F2
9114                   || idesc->operands[i] == IA64_OPND_F3
9115                   || idesc->operands[i] == IA64_OPND_F4)
9116                 {
9117                   int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9118                   if (reg >= min && reg <= max)
9119                     {
9120                       specs[count++] = tmpl;
9121                     }
9122                 }
9123             }
9124         }
9125       else if (note == 9)
9126         {
9127           int min = dep->regindex == PSR_MFL ? 2 : 32;
9128           int max = dep->regindex == PSR_MFL ? 31 : 127;
9129           /* mfh is read on writes to FR32-127; mfl is read on writes to
9130              FR2-31 */
9131           for (i = 0; i < idesc->num_outputs; i++)
9132             {
9133               if (idesc->operands[i] == IA64_OPND_F1)
9134                 {
9135                   int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9136                   if (reg >= min && reg <= max)
9137                     {
9138                       specs[count++] = tmpl;
9139                     }
9140                 }
9141             }
9142         }
9143       else if (note == 10)
9144         {
9145           for (i = 0; i < NELEMS (idesc->operands); i++)
9146             {
9147               if (idesc->operands[i] == IA64_OPND_R1
9148                   || idesc->operands[i] == IA64_OPND_R2
9149                   || idesc->operands[i] == IA64_OPND_R3)
9150                 {
9151                   int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9152                   if (regno >= 16 && regno <= 31)
9153                     {
9154                       specs[count++] = tmpl;
9155                     }
9156                 }
9157             }
9158         }
9159       else
9160         {
9161           UNHANDLED;
9162         }
9163       break;
9164
9165     case IA64_RS_AR_FPSR:
9166       if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
9167         {
9168           int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9169           if (regno == AR_FPSR)
9170             {
9171               specs[count++] = tmpl;
9172             }
9173         }
9174       else
9175         {
9176           specs[count++] = tmpl;
9177         }
9178       break;
9179
9180     case IA64_RS_ARX:
9181       /* Handle all AR[REG] resources */
9182       if (note == 0 || note == 1)
9183         {
9184           int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9185           if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
9186               && regno == dep->regindex)
9187             {
9188               specs[count++] = tmpl;
9189             }
9190           /* other AR[REG] resources may be affected by AR accesses */
9191           else if (idesc->operands[0] == IA64_OPND_AR3)
9192             {
9193               /* AR[] writes */
9194               regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
9195               switch (dep->regindex)
9196                 {
9197                 default:
9198                   break;
9199                 case AR_BSP:
9200                 case AR_RNAT:
9201                   if (regno == AR_BSPSTORE)
9202                     {
9203                       specs[count++] = tmpl;
9204                     }
9205                 case AR_RSC:
9206                   if (!rsrc_write &&
9207                       (regno == AR_BSPSTORE
9208                        || regno == AR_RNAT))
9209                     {
9210                       specs[count++] = tmpl;
9211                     }
9212                   break;
9213                 }
9214             }
9215           else if (idesc->operands[1] == IA64_OPND_AR3)
9216             {
9217               /* AR[] reads */
9218               regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
9219               switch (dep->regindex)
9220                 {
9221                 default:
9222                   break;
9223                 case AR_RSC:
9224                   if (regno == AR_BSPSTORE || regno == AR_RNAT)
9225                     {
9226                       specs[count++] = tmpl;
9227                     }
9228                   break;
9229                 }
9230             }
9231           else
9232             {
9233               specs[count++] = tmpl;
9234             }
9235         }
9236       else
9237         {
9238           UNHANDLED;
9239         }
9240       break;
9241
9242     case IA64_RS_CRX:
9243       /* Handle all CR[REG] resources */
9244       if (note == 0 || note == 1)
9245         {
9246           if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
9247             {
9248               int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
9249               if (regno == dep->regindex)
9250                 {
9251                   specs[count++] = tmpl;
9252                 }
9253               else if (!rsrc_write)
9254                 {
9255                   /* Reads from CR[IVR] affect other resources.  */
9256                   if (regno == CR_IVR)
9257                     {
9258                       if ((dep->regindex >= CR_IRR0
9259                            && dep->regindex <= CR_IRR3)
9260                           || dep->regindex == CR_TPR)
9261                         {
9262                           specs[count++] = tmpl;
9263                         }
9264                     }
9265                 }
9266             }
9267           else
9268             {
9269               specs[count++] = tmpl;
9270             }
9271         }
9272       else
9273         {
9274           UNHANDLED;
9275         }
9276       break;
9277
9278     case IA64_RS_INSERVICE:
9279       /* look for write of EOI (67) or read of IVR (65) */
9280       if ((idesc->operands[0] == IA64_OPND_CR3
9281            && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
9282           || (idesc->operands[1] == IA64_OPND_CR3
9283               && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
9284         {
9285           specs[count++] = tmpl;
9286         }
9287       break;
9288
9289     case IA64_RS_GR0:
9290       if (note == 1)
9291         {
9292           specs[count++] = tmpl;
9293         }
9294       else
9295         {
9296           UNHANDLED;
9297         }
9298       break;
9299
9300     case IA64_RS_CFM:
9301       if (note != 2)
9302         {
9303           specs[count++] = tmpl;
9304         }
9305       else
9306         {
9307           /* Check if any of the registers accessed are in the rotating region.
9308              mov to/from pr accesses CFM only when qp_regno is in the rotating
9309              region */
9310           for (i = 0; i < NELEMS (idesc->operands); i++)
9311             {
9312               if (idesc->operands[i] == IA64_OPND_R1
9313                   || idesc->operands[i] == IA64_OPND_R2
9314                   || idesc->operands[i] == IA64_OPND_R3)
9315                 {
9316                   int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9317                   /* Assumes that md.rot.num_regs is always valid */
9318                   if (md.rot.num_regs > 0
9319                       && num > 31
9320                       && num < 31 + md.rot.num_regs)
9321                     {
9322                       specs[count] = tmpl;
9323                       specs[count++].specific = 0;
9324                     }
9325                 }
9326               else if (idesc->operands[i] == IA64_OPND_F1
9327                        || idesc->operands[i] == IA64_OPND_F2
9328                        || idesc->operands[i] == IA64_OPND_F3
9329                        || idesc->operands[i] == IA64_OPND_F4)
9330                 {
9331                   int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9332                   if (num > 31)
9333                     {
9334                       specs[count] = tmpl;
9335                       specs[count++].specific = 0;
9336                     }
9337                 }
9338               else if (idesc->operands[i] == IA64_OPND_P1
9339                        || idesc->operands[i] == IA64_OPND_P2)
9340                 {
9341                   int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
9342                   if (num > 15)
9343                     {
9344                       specs[count] = tmpl;
9345                       specs[count++].specific = 0;
9346                     }
9347                 }
9348             }
9349           if (CURR_SLOT.qp_regno > 15)
9350             {
9351               specs[count] = tmpl;
9352               specs[count++].specific = 0;
9353             }
9354         }
9355       break;
9356
9357       /* This is the same as IA64_RS_PRr, except simplified to account for
9358          the fact that there is only one register.  */
9359     case IA64_RS_PR63:
9360       if (note == 0)
9361         {
9362           specs[count++] = tmpl;
9363         }
9364       else if (note == 7)
9365         {
9366           valueT mask = 0;
9367           if (idesc->operands[2] == IA64_OPND_IMM17)
9368             mask = CURR_SLOT.opnd[2].X_add_number;
9369           if (mask & ((valueT) 1 << 63))
9370             specs[count++] = tmpl;
9371         }
9372       else if (note == 11)
9373         {
9374           if ((idesc->operands[0] == IA64_OPND_P1
9375                && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
9376               || (idesc->operands[1] == IA64_OPND_P2
9377                   && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
9378             {
9379               specs[count++] = tmpl;
9380             }
9381         }
9382       else if (note == 12)
9383         {
9384           if (CURR_SLOT.qp_regno == 63)
9385             {
9386               specs[count++] = tmpl;
9387             }
9388         }
9389       else if (note == 1)
9390         {
9391           if (rsrc_write)
9392             {
9393               int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9394               int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9395               int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
9396               int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
9397
9398               if (p1 == 63
9399                   && (idesc->operands[0] == IA64_OPND_P1
9400                       || idesc->operands[0] == IA64_OPND_P2))
9401                 {
9402                   specs[count] = tmpl;
9403                   specs[count++].cmp_type =
9404                     (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
9405                 }
9406               if (p2 == 63
9407                   && (idesc->operands[1] == IA64_OPND_P1
9408                       || idesc->operands[1] == IA64_OPND_P2))
9409                 {
9410                   specs[count] = tmpl;
9411                   specs[count++].cmp_type =
9412                     (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9413                 }
9414             }
9415           else
9416             {
9417               if (CURR_SLOT.qp_regno == 63)
9418                 {
9419                   specs[count++] = tmpl;
9420                 }
9421             }
9422         }
9423       else
9424         {
9425           UNHANDLED;
9426         }
9427       break;
9428
9429     case IA64_RS_RSE:
9430       /* FIXME we can identify some individual RSE written resources, but RSE
9431          read resources have not yet been completely identified, so for now
9432          treat RSE as a single resource */
9433       if (strncmp (idesc->name, "mov", 3) == 0)
9434         {
9435           if (rsrc_write)
9436             {
9437               if (idesc->operands[0] == IA64_OPND_AR3
9438                   && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
9439                 {
9440                   specs[count++] = tmpl;
9441                 }
9442             }
9443           else
9444             {
9445               if (idesc->operands[0] == IA64_OPND_AR3)
9446                 {
9447                   if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
9448                       || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
9449                     {
9450                       specs[count++] = tmpl;
9451                     }
9452                 }
9453               else if (idesc->operands[1] == IA64_OPND_AR3)
9454                 {
9455                   if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
9456                       || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
9457                       || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
9458                     {
9459                       specs[count++] = tmpl;
9460                     }
9461                 }
9462             }
9463         }
9464       else
9465         {
9466           specs[count++] = tmpl;
9467         }
9468       break;
9469
9470     case IA64_RS_ANY:
9471       /* FIXME -- do any of these need to be non-specific? */
9472       specs[count++] = tmpl;
9473       break;
9474
9475     default:
9476       as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
9477       break;
9478     }
9479
9480   return count;
9481 }
9482
9483 /* Clear branch flags on marked resources.  This breaks the link between the
9484    QP of the marking instruction and a subsequent branch on the same QP.  */
9485
9486 static void
9487 clear_qp_branch_flag (mask)
9488      valueT mask;
9489 {
9490   int i;
9491   for (i = 0; i < regdepslen; i++)
9492     {
9493       valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
9494       if ((bit & mask) != 0)
9495         {
9496           regdeps[i].link_to_qp_branch = 0;
9497         }
9498     }
9499 }
9500
9501 /* MASK contains 2 and only 2 PRs which are mutually exclusive.  Remove
9502    any mutexes which contain one of the PRs and create new ones when
9503    needed.  */
9504
9505 static int
9506 update_qp_mutex (valueT mask)
9507 {
9508   int i;
9509   int add = 0;
9510
9511   i = 0;
9512   while (i < qp_mutexeslen)
9513     {
9514       if ((qp_mutexes[i].prmask & mask) != 0)
9515         {
9516           /* If it destroys and creates the same mutex, do nothing.  */
9517           if (qp_mutexes[i].prmask == mask
9518               && qp_mutexes[i].path == md.path)
9519             {
9520               i++;
9521               add = -1;
9522             }
9523           else
9524             {
9525               int keep = 0;
9526
9527               if (md.debug_dv)
9528                 {
9529                   fprintf (stderr, "  Clearing mutex relation");
9530                   print_prmask (qp_mutexes[i].prmask);
9531                   fprintf (stderr, "\n");
9532                 }
9533               
9534               /* Deal with the old mutex with more than 3+ PRs only if
9535                  the new mutex on the same execution path with it.
9536
9537                  FIXME: The 3+ mutex support is incomplete.
9538                  dot_pred_rel () may be a better place to fix it.  */
9539               if (qp_mutexes[i].path == md.path)
9540                 {
9541                   /* If it is a proper subset of the mutex, create a
9542                      new mutex.  */
9543                   if (add == 0
9544                       && (qp_mutexes[i].prmask & mask) == mask)
9545                     add = 1;
9546                   
9547                   qp_mutexes[i].prmask &= ~mask;
9548                   if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
9549                     {
9550                       /* Modify the mutex if there are more than one
9551                          PR left.  */
9552                       keep = 1;
9553                       i++;
9554                     }
9555                 }
9556               
9557               if (keep == 0)
9558                 /* Remove the mutex.  */
9559                 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9560             }
9561         }
9562       else
9563         ++i;
9564     }
9565
9566   if (add == 1)
9567     add_qp_mutex (mask);
9568
9569   return add;
9570 }
9571
9572 /* Remove any mutexes which contain any of the PRs indicated in the mask.
9573
9574    Any changes to a PR clears the mutex relations which include that PR.  */
9575
9576 static void
9577 clear_qp_mutex (mask)
9578      valueT mask;
9579 {
9580   int i;
9581
9582   i = 0;
9583   while (i < qp_mutexeslen)
9584     {
9585       if ((qp_mutexes[i].prmask & mask) != 0)
9586         {
9587           if (md.debug_dv)
9588             {
9589               fprintf (stderr, "  Clearing mutex relation");
9590               print_prmask (qp_mutexes[i].prmask);
9591               fprintf (stderr, "\n");
9592             }
9593           qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9594         }
9595       else
9596         ++i;
9597     }
9598 }
9599
9600 /* Clear implies relations which contain PRs in the given masks.
9601    P1_MASK indicates the source of the implies relation, while P2_MASK
9602    indicates the implied PR.  */
9603
9604 static void
9605 clear_qp_implies (p1_mask, p2_mask)
9606      valueT p1_mask;
9607      valueT p2_mask;
9608 {
9609   int i;
9610
9611   i = 0;
9612   while (i < qp_implieslen)
9613     {
9614       if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
9615           || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
9616         {
9617           if (md.debug_dv)
9618             fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
9619                      qp_implies[i].p1, qp_implies[i].p2);
9620           qp_implies[i] = qp_implies[--qp_implieslen];
9621         }
9622       else
9623         ++i;
9624     }
9625 }
9626
9627 /* Add the PRs specified to the list of implied relations.  */
9628
9629 static void
9630 add_qp_imply (p1, p2)
9631      int p1, p2;
9632 {
9633   valueT mask;
9634   valueT bit;
9635   int i;
9636
9637   /* p0 is not meaningful here.  */
9638   if (p1 == 0 || p2 == 0)
9639     abort ();
9640
9641   if (p1 == p2)
9642     return;
9643
9644   /* If it exists already, ignore it.  */
9645   for (i = 0; i < qp_implieslen; i++)
9646     {
9647       if (qp_implies[i].p1 == p1
9648           && qp_implies[i].p2 == p2
9649           && qp_implies[i].path == md.path
9650           && !qp_implies[i].p2_branched)
9651         return;
9652     }
9653
9654   if (qp_implieslen == qp_impliestotlen)
9655     {
9656       qp_impliestotlen += 20;
9657       qp_implies = (struct qp_imply *)
9658         xrealloc ((void *) qp_implies,
9659                   qp_impliestotlen * sizeof (struct qp_imply));
9660     }
9661   if (md.debug_dv)
9662     fprintf (stderr, "  Registering PR%d implies PR%d\n", p1, p2);
9663   qp_implies[qp_implieslen].p1 = p1;
9664   qp_implies[qp_implieslen].p2 = p2;
9665   qp_implies[qp_implieslen].path = md.path;
9666   qp_implies[qp_implieslen++].p2_branched = 0;
9667
9668   /* Add in the implied transitive relations; for everything that p2 implies,
9669      make p1 imply that, too; for everything that implies p1, make it imply p2
9670      as well.  */
9671   for (i = 0; i < qp_implieslen; i++)
9672     {
9673       if (qp_implies[i].p1 == p2)
9674         add_qp_imply (p1, qp_implies[i].p2);
9675       if (qp_implies[i].p2 == p1)
9676         add_qp_imply (qp_implies[i].p1, p2);
9677     }
9678   /* Add in mutex relations implied by this implies relation; for each mutex
9679      relation containing p2, duplicate it and replace p2 with p1.  */
9680   bit = (valueT) 1 << p1;
9681   mask = (valueT) 1 << p2;
9682   for (i = 0; i < qp_mutexeslen; i++)
9683     {
9684       if (qp_mutexes[i].prmask & mask)
9685         add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9686     }
9687 }
9688
9689 /* Add the PRs specified in the mask to the mutex list; this means that only
9690    one of the PRs can be true at any time.  PR0 should never be included in
9691    the mask.  */
9692
9693 static void
9694 add_qp_mutex (mask)
9695      valueT mask;
9696 {
9697   if (mask & 0x1)
9698     abort ();
9699
9700   if (qp_mutexeslen == qp_mutexestotlen)
9701     {
9702       qp_mutexestotlen += 20;
9703       qp_mutexes = (struct qpmutex *)
9704         xrealloc ((void *) qp_mutexes,
9705                   qp_mutexestotlen * sizeof (struct qpmutex));
9706     }
9707   if (md.debug_dv)
9708     {
9709       fprintf (stderr, "  Registering mutex on");
9710       print_prmask (mask);
9711       fprintf (stderr, "\n");
9712     }
9713   qp_mutexes[qp_mutexeslen].path = md.path;
9714   qp_mutexes[qp_mutexeslen++].prmask = mask;
9715 }
9716
9717 static int
9718 has_suffix_p (name, suffix)
9719      const char *name;
9720      const char *suffix;
9721 {
9722   size_t namelen = strlen (name);
9723   size_t sufflen = strlen (suffix);
9724
9725   if (namelen <= sufflen)
9726     return 0;
9727   return strcmp (name + namelen - sufflen, suffix) == 0;
9728 }
9729
9730 static void
9731 clear_register_values ()
9732 {
9733   int i;
9734   if (md.debug_dv)
9735     fprintf (stderr, "  Clearing register values\n");
9736   for (i = 1; i < NELEMS (gr_values); i++)
9737     gr_values[i].known = 0;
9738 }
9739
9740 /* Keep track of register values/changes which affect DV tracking.
9741
9742    optimization note: should add a flag to classes of insns where otherwise we
9743    have to examine a group of strings to identify them.  */
9744
9745 static void
9746 note_register_values (idesc)
9747      struct ia64_opcode *idesc;
9748 {
9749   valueT qp_changemask = 0;
9750   int i;
9751
9752   /* Invalidate values for registers being written to.  */
9753   for (i = 0; i < idesc->num_outputs; i++)
9754     {
9755       if (idesc->operands[i] == IA64_OPND_R1
9756           || idesc->operands[i] == IA64_OPND_R2
9757           || idesc->operands[i] == IA64_OPND_R3)
9758         {
9759           int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9760           if (regno > 0 && regno < NELEMS (gr_values))
9761             gr_values[regno].known = 0;
9762         }
9763       else if (idesc->operands[i] == IA64_OPND_R3_2)
9764         {
9765           int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9766           if (regno > 0 && regno < 4)
9767             gr_values[regno].known = 0;
9768         }
9769       else if (idesc->operands[i] == IA64_OPND_P1
9770                || idesc->operands[i] == IA64_OPND_P2)
9771         {
9772           int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9773           qp_changemask |= (valueT) 1 << regno;
9774         }
9775       else if (idesc->operands[i] == IA64_OPND_PR)
9776         {
9777           if (idesc->operands[2] & (valueT) 0x10000)
9778             qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9779           else
9780             qp_changemask = idesc->operands[2];
9781           break;
9782         }
9783       else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9784         {
9785           if (idesc->operands[1] & ((valueT) 1 << 43))
9786             qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9787           else
9788             qp_changemask = idesc->operands[1];
9789           qp_changemask &= ~(valueT) 0xFFFF;
9790           break;
9791         }
9792     }
9793
9794   /* Always clear qp branch flags on any PR change.  */
9795   /* FIXME there may be exceptions for certain compares.  */
9796   clear_qp_branch_flag (qp_changemask);
9797
9798   /* Invalidate rotating registers on insns which affect RRBs in CFM.  */
9799   if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9800     {
9801       qp_changemask |= ~(valueT) 0xFFFF;
9802       if (strcmp (idesc->name, "clrrrb.pr") != 0)
9803         {
9804           for (i = 32; i < 32 + md.rot.num_regs; i++)
9805             gr_values[i].known = 0;
9806         }
9807       clear_qp_mutex (qp_changemask);
9808       clear_qp_implies (qp_changemask, qp_changemask);
9809     }
9810   /* After a call, all register values are undefined, except those marked
9811      as "safe".  */
9812   else if (strncmp (idesc->name, "br.call", 6) == 0
9813            || strncmp (idesc->name, "brl.call", 7) == 0)
9814     {
9815       /* FIXME keep GR values which are marked as "safe_across_calls"  */
9816       clear_register_values ();
9817       clear_qp_mutex (~qp_safe_across_calls);
9818       clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9819       clear_qp_branch_flag (~qp_safe_across_calls);
9820     }
9821   else if (is_interruption_or_rfi (idesc)
9822            || is_taken_branch (idesc))
9823     {
9824       clear_register_values ();
9825       clear_qp_mutex (~(valueT) 0);
9826       clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9827     }
9828   /* Look for mutex and implies relations.  */
9829   else if ((idesc->operands[0] == IA64_OPND_P1
9830             || idesc->operands[0] == IA64_OPND_P2)
9831            && (idesc->operands[1] == IA64_OPND_P1
9832                || idesc->operands[1] == IA64_OPND_P2))
9833     {
9834       int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9835       int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9836       valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9837       valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9838
9839       /* If both PRs are PR0, we can't really do anything.  */
9840       if (p1 == 0 && p2 == 0)
9841         {
9842           if (md.debug_dv)
9843             fprintf (stderr, "  Ignoring PRs due to inclusion of p0\n");
9844         }
9845       /* In general, clear mutexes and implies which include P1 or P2,
9846          with the following exceptions.  */
9847       else if (has_suffix_p (idesc->name, ".or.andcm")
9848                || has_suffix_p (idesc->name, ".and.orcm"))
9849         {
9850           clear_qp_implies (p2mask, p1mask);
9851         }
9852       else if (has_suffix_p (idesc->name, ".andcm")
9853                || has_suffix_p (idesc->name, ".and"))
9854         {
9855           clear_qp_implies (0, p1mask | p2mask);
9856         }
9857       else if (has_suffix_p (idesc->name, ".orcm")
9858                || has_suffix_p (idesc->name, ".or"))
9859         {
9860           clear_qp_mutex (p1mask | p2mask);
9861           clear_qp_implies (p1mask | p2mask, 0);
9862         }
9863       else
9864         {
9865           int added = 0;
9866
9867           clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9868
9869           /* If one of the PRs is PR0, we call clear_qp_mutex.  */
9870           if (p1 == 0 || p2 == 0)
9871             clear_qp_mutex (p1mask | p2mask);
9872           else
9873             added = update_qp_mutex (p1mask | p2mask);
9874
9875           if (CURR_SLOT.qp_regno == 0
9876               || has_suffix_p (idesc->name, ".unc"))
9877             {
9878               if (added == 0 && p1 && p2)
9879                 add_qp_mutex (p1mask | p2mask);
9880               if (CURR_SLOT.qp_regno != 0)
9881                 {
9882                   if (p1)
9883                     add_qp_imply (p1, CURR_SLOT.qp_regno);
9884                   if (p2)
9885                     add_qp_imply (p2, CURR_SLOT.qp_regno);
9886                 }
9887             }
9888         }
9889     }
9890   /* Look for mov imm insns into GRs.  */
9891   else if (idesc->operands[0] == IA64_OPND_R1
9892            && (idesc->operands[1] == IA64_OPND_IMM22
9893                || idesc->operands[1] == IA64_OPND_IMMU64)
9894            && CURR_SLOT.opnd[1].X_op == O_constant
9895            && (strcmp (idesc->name, "mov") == 0
9896                || strcmp (idesc->name, "movl") == 0))
9897     {
9898       int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9899       if (regno > 0 && regno < NELEMS (gr_values))
9900         {
9901           gr_values[regno].known = 1;
9902           gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9903           gr_values[regno].path = md.path;
9904           if (md.debug_dv)
9905             {
9906               fprintf (stderr, "  Know gr%d = ", regno);
9907               fprintf_vma (stderr, gr_values[regno].value);
9908               fputs ("\n", stderr);
9909             }
9910         }
9911     }
9912   /* Look for dep.z imm insns.  */
9913   else if (idesc->operands[0] == IA64_OPND_R1
9914            && idesc->operands[1] == IA64_OPND_IMM8
9915            && strcmp (idesc->name, "dep.z") == 0)
9916     {
9917       int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9918       if (regno > 0 && regno < NELEMS (gr_values))
9919         {
9920           valueT value = CURR_SLOT.opnd[1].X_add_number;
9921
9922           if (CURR_SLOT.opnd[3].X_add_number < 64)
9923             value &= ((valueT)1 << CURR_SLOT.opnd[3].X_add_number) - 1;
9924           value <<= CURR_SLOT.opnd[2].X_add_number;
9925           gr_values[regno].known = 1;
9926           gr_values[regno].value = value;
9927           gr_values[regno].path = md.path;
9928           if (md.debug_dv)
9929             {
9930               fprintf (stderr, "  Know gr%d = ", regno);
9931               fprintf_vma (stderr, gr_values[regno].value);
9932               fputs ("\n", stderr);
9933             }
9934         }
9935     }
9936   else
9937     {
9938       clear_qp_mutex (qp_changemask);
9939       clear_qp_implies (qp_changemask, qp_changemask);
9940     }
9941 }
9942
9943 /* Return whether the given predicate registers are currently mutex.  */
9944
9945 static int
9946 qp_mutex (p1, p2, path)
9947      int p1;
9948      int p2;
9949      int path;
9950 {
9951   int i;
9952   valueT mask;
9953
9954   if (p1 != p2)
9955     {
9956       mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9957       for (i = 0; i < qp_mutexeslen; i++)
9958         {
9959           if (qp_mutexes[i].path >= path
9960               && (qp_mutexes[i].prmask & mask) == mask)
9961             return 1;
9962         }
9963     }
9964   return 0;
9965 }
9966
9967 /* Return whether the given resource is in the given insn's list of chks
9968    Return 1 if the conflict is absolutely determined, 2 if it's a potential
9969    conflict.  */
9970
9971 static int
9972 resources_match (rs, idesc, note, qp_regno, path)
9973      struct rsrc *rs;
9974      struct ia64_opcode *idesc;
9975      int note;
9976      int qp_regno;
9977      int path;
9978 {
9979   struct rsrc specs[MAX_SPECS];
9980   int count;
9981
9982   /* If the marked resource's qp_regno and the given qp_regno are mutex,
9983      we don't need to check.  One exception is note 11, which indicates that
9984      target predicates are written regardless of PR[qp].  */
9985   if (qp_mutex (rs->qp_regno, qp_regno, path)
9986       && note != 11)
9987     return 0;
9988
9989   count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9990   while (count-- > 0)
9991     {
9992       /* UNAT checking is a bit more specific than other resources */
9993       if (rs->dependency->specifier == IA64_RS_AR_UNAT
9994           && specs[count].mem_offset.hint
9995           && rs->mem_offset.hint)
9996         {
9997           if (rs->mem_offset.base == specs[count].mem_offset.base)
9998             {
9999               if (((rs->mem_offset.offset >> 3) & 0x3F) ==
10000                   ((specs[count].mem_offset.offset >> 3) & 0x3F))
10001                 return 1;
10002               else
10003                 continue;
10004             }
10005         }
10006
10007       /* Skip apparent PR write conflicts where both writes are an AND or both
10008          writes are an OR.  */
10009       if (rs->dependency->specifier == IA64_RS_PR
10010           || rs->dependency->specifier == IA64_RS_PRr
10011           || rs->dependency->specifier == IA64_RS_PR63)
10012         {
10013           if (specs[count].cmp_type != CMP_NONE
10014               && specs[count].cmp_type == rs->cmp_type)
10015             {
10016               if (md.debug_dv)
10017                 fprintf (stderr, "  %s on parallel compare allowed (PR%d)\n",
10018                          dv_mode[rs->dependency->mode],
10019                          rs->dependency->specifier != IA64_RS_PR63 ?
10020                          specs[count].index : 63);
10021               continue;
10022             }
10023           if (md.debug_dv)
10024             fprintf (stderr,
10025                      "  %s on parallel compare conflict %s vs %s on PR%d\n",
10026                      dv_mode[rs->dependency->mode],
10027                      dv_cmp_type[rs->cmp_type],
10028                      dv_cmp_type[specs[count].cmp_type],
10029                      rs->dependency->specifier != IA64_RS_PR63 ?
10030                      specs[count].index : 63);
10031
10032         }
10033
10034       /* If either resource is not specific, conservatively assume a conflict
10035        */
10036       if (!specs[count].specific || !rs->specific)
10037         return 2;
10038       else if (specs[count].index == rs->index)
10039         return 1;
10040     }
10041
10042   return 0;
10043 }
10044
10045 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
10046    insert a stop to create the break.  Update all resource dependencies
10047    appropriately.  If QP_REGNO is non-zero, only apply the break to resources
10048    which use the same QP_REGNO and have the link_to_qp_branch flag set.
10049    If SAVE_CURRENT is non-zero, don't affect resources marked by the current
10050    instruction.  */
10051
10052 static void
10053 insn_group_break (insert_stop, qp_regno, save_current)
10054      int insert_stop;
10055      int qp_regno;
10056      int save_current;
10057 {
10058   int i;
10059
10060   if (insert_stop && md.num_slots_in_use > 0)
10061     PREV_SLOT.end_of_insn_group = 1;
10062
10063   if (md.debug_dv)
10064     {
10065       fprintf (stderr, "  Insn group break%s",
10066                (insert_stop ? " (w/stop)" : ""));
10067       if (qp_regno != 0)
10068         fprintf (stderr, " effective for QP=%d", qp_regno);
10069       fprintf (stderr, "\n");
10070     }
10071
10072   i = 0;
10073   while (i < regdepslen)
10074     {
10075       const struct ia64_dependency *dep = regdeps[i].dependency;
10076
10077       if (qp_regno != 0
10078           && regdeps[i].qp_regno != qp_regno)
10079         {
10080           ++i;
10081           continue;
10082         }
10083
10084       if (save_current
10085           && CURR_SLOT.src_file == regdeps[i].file
10086           && CURR_SLOT.src_line == regdeps[i].line)
10087         {
10088           ++i;
10089           continue;
10090         }
10091
10092       /* clear dependencies which are automatically cleared by a stop, or
10093          those that have reached the appropriate state of insn serialization */
10094       if (dep->semantics == IA64_DVS_IMPLIED
10095           || dep->semantics == IA64_DVS_IMPLIEDF
10096           || regdeps[i].insn_srlz == STATE_SRLZ)
10097         {
10098           print_dependency ("Removing", i);
10099           regdeps[i] = regdeps[--regdepslen];
10100         }
10101       else
10102         {
10103           if (dep->semantics == IA64_DVS_DATA
10104               || dep->semantics == IA64_DVS_INSTR
10105               || dep->semantics == IA64_DVS_SPECIFIC)
10106             {
10107               if (regdeps[i].insn_srlz == STATE_NONE)
10108                 regdeps[i].insn_srlz = STATE_STOP;
10109               if (regdeps[i].data_srlz == STATE_NONE)
10110                 regdeps[i].data_srlz = STATE_STOP;
10111             }
10112           ++i;
10113         }
10114     }
10115 }
10116
10117 /* Add the given resource usage spec to the list of active dependencies.  */
10118
10119 static void
10120 mark_resource (idesc, dep, spec, depind, path)
10121      struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
10122      const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
10123      struct rsrc *spec;
10124      int depind;
10125      int path;
10126 {
10127   if (regdepslen == regdepstotlen)
10128     {
10129       regdepstotlen += 20;
10130       regdeps = (struct rsrc *)
10131         xrealloc ((void *) regdeps,
10132                   regdepstotlen * sizeof (struct rsrc));
10133     }
10134
10135   regdeps[regdepslen] = *spec;
10136   regdeps[regdepslen].depind = depind;
10137   regdeps[regdepslen].path = path;
10138   regdeps[regdepslen].file = CURR_SLOT.src_file;
10139   regdeps[regdepslen].line = CURR_SLOT.src_line;
10140
10141   print_dependency ("Adding", regdepslen);
10142
10143   ++regdepslen;
10144 }
10145
10146 static void
10147 print_dependency (action, depind)
10148      const char *action;
10149      int depind;
10150 {
10151   if (md.debug_dv)
10152     {
10153       fprintf (stderr, "  %s %s '%s'",
10154                action, dv_mode[(regdeps[depind].dependency)->mode],
10155                (regdeps[depind].dependency)->name);
10156       if (regdeps[depind].specific && regdeps[depind].index >= 0)
10157         fprintf (stderr, " (%d)", regdeps[depind].index);
10158       if (regdeps[depind].mem_offset.hint)
10159         {
10160           fputs (" ", stderr);
10161           fprintf_vma (stderr, regdeps[depind].mem_offset.base);
10162           fputs ("+", stderr);
10163           fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
10164         }
10165       fprintf (stderr, "\n");
10166     }
10167 }
10168
10169 static void
10170 instruction_serialization ()
10171 {
10172   int i;
10173   if (md.debug_dv)
10174     fprintf (stderr, "  Instruction serialization\n");
10175   for (i = 0; i < regdepslen; i++)
10176     if (regdeps[i].insn_srlz == STATE_STOP)
10177       regdeps[i].insn_srlz = STATE_SRLZ;
10178 }
10179
10180 static void
10181 data_serialization ()
10182 {
10183   int i = 0;
10184   if (md.debug_dv)
10185     fprintf (stderr, "  Data serialization\n");
10186   while (i < regdepslen)
10187     {
10188       if (regdeps[i].data_srlz == STATE_STOP
10189           /* Note: as of 991210, all "other" dependencies are cleared by a
10190              data serialization.  This might change with new tables */
10191           || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
10192         {
10193           print_dependency ("Removing", i);
10194           regdeps[i] = regdeps[--regdepslen];
10195         }
10196       else
10197         ++i;
10198     }
10199 }
10200
10201 /* Insert stops and serializations as needed to avoid DVs.  */
10202
10203 static void
10204 remove_marked_resource (rs)
10205      struct rsrc *rs;
10206 {
10207   switch (rs->dependency->semantics)
10208     {
10209     case IA64_DVS_SPECIFIC:
10210       if (md.debug_dv)
10211         fprintf (stderr, "Implementation-specific, assume worst case...\n");
10212       /* ...fall through...  */
10213     case IA64_DVS_INSTR:
10214       if (md.debug_dv)
10215         fprintf (stderr, "Inserting instr serialization\n");
10216       if (rs->insn_srlz < STATE_STOP)
10217         insn_group_break (1, 0, 0);
10218       if (rs->insn_srlz < STATE_SRLZ)
10219         {
10220           struct slot oldslot = CURR_SLOT;
10221           /* Manually jam a srlz.i insn into the stream */
10222           memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10223           CURR_SLOT.user_template = -1;
10224           CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
10225           instruction_serialization ();
10226           md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10227           if (++md.num_slots_in_use >= NUM_SLOTS)
10228             emit_one_bundle ();
10229           CURR_SLOT = oldslot;
10230         }
10231       insn_group_break (1, 0, 0);
10232       break;
10233     case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
10234                             "other" types of DV are eliminated
10235                             by a data serialization */
10236     case IA64_DVS_DATA:
10237       if (md.debug_dv)
10238         fprintf (stderr, "Inserting data serialization\n");
10239       if (rs->data_srlz < STATE_STOP)
10240         insn_group_break (1, 0, 0);
10241       {
10242         struct slot oldslot = CURR_SLOT;
10243         /* Manually jam a srlz.d insn into the stream */
10244         memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10245         CURR_SLOT.user_template = -1;
10246         CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
10247         data_serialization ();
10248         md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10249         if (++md.num_slots_in_use >= NUM_SLOTS)
10250           emit_one_bundle ();
10251         CURR_SLOT = oldslot;
10252       }
10253       break;
10254     case IA64_DVS_IMPLIED:
10255     case IA64_DVS_IMPLIEDF:
10256       if (md.debug_dv)
10257         fprintf (stderr, "Inserting stop\n");
10258       insn_group_break (1, 0, 0);
10259       break;
10260     default:
10261       break;
10262     }
10263 }
10264
10265 /* Check the resources used by the given opcode against the current dependency
10266    list.
10267
10268    The check is run once for each execution path encountered.  In this case,
10269    a unique execution path is the sequence of instructions following a code
10270    entry point, e.g. the following has three execution paths, one starting
10271    at L0, one at L1, and one at L2.
10272
10273    L0:     nop
10274    L1:     add
10275    L2:     add
10276    br.ret
10277 */
10278
10279 static void
10280 check_dependencies (idesc)
10281      struct ia64_opcode *idesc;
10282 {
10283   const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10284   int path;
10285   int i;
10286
10287   /* Note that the number of marked resources may change within the
10288      loop if in auto mode.  */
10289   i = 0;
10290   while (i < regdepslen)
10291     {
10292       struct rsrc *rs = &regdeps[i];
10293       const struct ia64_dependency *dep = rs->dependency;
10294       int chkind;
10295       int note;
10296       int start_over = 0;
10297
10298       if (dep->semantics == IA64_DVS_NONE
10299           || (chkind = depends_on (rs->depind, idesc)) == -1)
10300         {
10301           ++i;
10302           continue;
10303         }
10304
10305       note = NOTE (opdeps->chks[chkind]);
10306
10307       /* Check this resource against each execution path seen thus far.  */
10308       for (path = 0; path <= md.path; path++)
10309         {
10310           int matchtype;
10311
10312           /* If the dependency wasn't on the path being checked, ignore it.  */
10313           if (rs->path < path)
10314             continue;
10315
10316           /* If the QP for this insn implies a QP which has branched, don't
10317              bother checking.  Ed. NOTE: I don't think this check is terribly
10318              useful; what's the point of generating code which will only be
10319              reached if its QP is zero?
10320              This code was specifically inserted to handle the following code,
10321              based on notes from Intel's DV checking code, where p1 implies p2.
10322
10323                   mov r4 = 2
10324              (p2) br.cond L
10325              (p1) mov r4 = 7
10326           */
10327           if (CURR_SLOT.qp_regno != 0)
10328             {
10329               int skip = 0;
10330               int implies;
10331               for (implies = 0; implies < qp_implieslen; implies++)
10332                 {
10333                   if (qp_implies[implies].path >= path
10334                       && qp_implies[implies].p1 == CURR_SLOT.qp_regno
10335                       && qp_implies[implies].p2_branched)
10336                     {
10337                       skip = 1;
10338                       break;
10339                     }
10340                 }
10341               if (skip)
10342                 continue;
10343             }
10344
10345           if ((matchtype = resources_match (rs, idesc, note,
10346                                             CURR_SLOT.qp_regno, path)) != 0)
10347             {
10348               char msg[1024];
10349               char pathmsg[256] = "";
10350               char indexmsg[256] = "";
10351               int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
10352
10353               if (path != 0)
10354                 sprintf (pathmsg, " when entry is at label '%s'",
10355                          md.entry_labels[path - 1]);
10356               if (matchtype == 1 && rs->index >= 0)
10357                 sprintf (indexmsg, ", specific resource number is %d",
10358                          rs->index);
10359               sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
10360                        idesc->name,
10361                        (certain ? "violates" : "may violate"),
10362                        dv_mode[dep->mode], dep->name,
10363                        dv_sem[dep->semantics],
10364                        pathmsg, indexmsg);
10365
10366               if (md.explicit_mode)
10367                 {
10368                   as_warn ("%s", msg);
10369                   if (path < md.path)
10370                     as_warn (_("Only the first path encountering the conflict "
10371                                "is reported"));
10372                   as_warn_where (rs->file, rs->line,
10373                                  _("This is the location of the "
10374                                    "conflicting usage"));
10375                   /* Don't bother checking other paths, to avoid duplicating
10376                      the same warning */
10377                   break;
10378                 }
10379               else
10380                 {
10381                   if (md.debug_dv)
10382                     fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
10383
10384                   remove_marked_resource (rs);
10385
10386                   /* since the set of dependencies has changed, start over */
10387                   /* FIXME -- since we're removing dvs as we go, we
10388                      probably don't really need to start over...  */
10389                   start_over = 1;
10390                   break;
10391                 }
10392             }
10393         }
10394       if (start_over)
10395         i = 0;
10396       else
10397         ++i;
10398     }
10399 }
10400
10401 /* Register new dependencies based on the given opcode.  */
10402
10403 static void
10404 mark_resources (idesc)
10405      struct ia64_opcode *idesc;
10406 {
10407   int i;
10408   const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10409   int add_only_qp_reads = 0;
10410
10411   /* A conditional branch only uses its resources if it is taken; if it is
10412      taken, we stop following that path.  The other branch types effectively
10413      *always* write their resources.  If it's not taken, register only QP
10414      reads.  */
10415   if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
10416     {
10417       add_only_qp_reads = 1;
10418     }
10419
10420   if (md.debug_dv)
10421     fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
10422
10423   for (i = 0; i < opdeps->nregs; i++)
10424     {
10425       const struct ia64_dependency *dep;
10426       struct rsrc specs[MAX_SPECS];
10427       int note;
10428       int path;
10429       int count;
10430
10431       dep = ia64_find_dependency (opdeps->regs[i]);
10432       note = NOTE (opdeps->regs[i]);
10433
10434       if (add_only_qp_reads
10435           && !(dep->mode == IA64_DV_WAR
10436                && (dep->specifier == IA64_RS_PR
10437                    || dep->specifier == IA64_RS_PRr
10438                    || dep->specifier == IA64_RS_PR63)))
10439         continue;
10440
10441       count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
10442
10443       while (count-- > 0)
10444         {
10445           mark_resource (idesc, dep, &specs[count],
10446                          DEP (opdeps->regs[i]), md.path);
10447         }
10448
10449       /* The execution path may affect register values, which may in turn
10450          affect which indirect-access resources are accessed.  */
10451       switch (dep->specifier)
10452         {
10453         default:
10454           break;
10455         case IA64_RS_CPUID:
10456         case IA64_RS_DBR:
10457         case IA64_RS_IBR:
10458         case IA64_RS_MSR:
10459         case IA64_RS_PKR:
10460         case IA64_RS_PMC:
10461         case IA64_RS_PMD:
10462         case IA64_RS_RR:
10463           for (path = 0; path < md.path; path++)
10464             {
10465               count = specify_resource (dep, idesc, DV_REG, specs, note, path);
10466               while (count-- > 0)
10467                 mark_resource (idesc, dep, &specs[count],
10468                                DEP (opdeps->regs[i]), path);
10469             }
10470           break;
10471         }
10472     }
10473 }
10474
10475 /* Remove dependencies when they no longer apply.  */
10476
10477 static void
10478 update_dependencies (idesc)
10479      struct ia64_opcode *idesc;
10480 {
10481   int i;
10482
10483   if (strcmp (idesc->name, "srlz.i") == 0)
10484     {
10485       instruction_serialization ();
10486     }
10487   else if (strcmp (idesc->name, "srlz.d") == 0)
10488     {
10489       data_serialization ();
10490     }
10491   else if (is_interruption_or_rfi (idesc)
10492            || is_taken_branch (idesc))
10493     {
10494       /* Although technically the taken branch doesn't clear dependencies
10495          which require a srlz.[id], we don't follow the branch; the next
10496          instruction is assumed to start with a clean slate.  */
10497       regdepslen = 0;
10498       md.path = 0;
10499     }
10500   else if (is_conditional_branch (idesc)
10501            && CURR_SLOT.qp_regno != 0)
10502     {
10503       int is_call = strstr (idesc->name, ".call") != NULL;
10504
10505       for (i = 0; i < qp_implieslen; i++)
10506         {
10507           /* If the conditional branch's predicate is implied by the predicate
10508              in an existing dependency, remove that dependency.  */
10509           if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
10510             {
10511               int depind = 0;
10512               /* Note that this implied predicate takes a branch so that if
10513                  a later insn generates a DV but its predicate implies this
10514                  one, we can avoid the false DV warning.  */
10515               qp_implies[i].p2_branched = 1;
10516               while (depind < regdepslen)
10517                 {
10518                   if (regdeps[depind].qp_regno == qp_implies[i].p1)
10519                     {
10520                       print_dependency ("Removing", depind);
10521                       regdeps[depind] = regdeps[--regdepslen];
10522                     }
10523                   else
10524                     ++depind;
10525                 }
10526             }
10527         }
10528       /* Any marked resources which have this same predicate should be
10529          cleared, provided that the QP hasn't been modified between the
10530          marking instruction and the branch.  */
10531       if (is_call)
10532         {
10533           insn_group_break (0, CURR_SLOT.qp_regno, 1);
10534         }
10535       else
10536         {
10537           i = 0;
10538           while (i < regdepslen)
10539             {
10540               if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
10541                   && regdeps[i].link_to_qp_branch
10542                   && (regdeps[i].file != CURR_SLOT.src_file
10543                       || regdeps[i].line != CURR_SLOT.src_line))
10544                 {
10545                   /* Treat like a taken branch */
10546                   print_dependency ("Removing", i);
10547                   regdeps[i] = regdeps[--regdepslen];
10548                 }
10549               else
10550                 ++i;
10551             }
10552         }
10553     }
10554 }
10555
10556 /* Examine the current instruction for dependency violations.  */
10557
10558 static int
10559 check_dv (idesc)
10560      struct ia64_opcode *idesc;
10561 {
10562   if (md.debug_dv)
10563     {
10564       fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
10565                idesc->name, CURR_SLOT.src_line,
10566                idesc->dependencies->nchks,
10567                idesc->dependencies->nregs);
10568     }
10569
10570   /* Look through the list of currently marked resources; if the current
10571      instruction has the dependency in its chks list which uses that resource,
10572      check against the specific resources used.  */
10573   check_dependencies (idesc);
10574
10575   /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
10576      then add them to the list of marked resources.  */
10577   mark_resources (idesc);
10578
10579   /* There are several types of dependency semantics, and each has its own
10580      requirements for being cleared
10581
10582      Instruction serialization (insns separated by interruption, rfi, or
10583      writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
10584
10585      Data serialization (instruction serialization, or writer + srlz.d +
10586      reader, where writer and srlz.d are in separate groups) clears
10587      DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
10588      always be the case).
10589
10590      Instruction group break (groups separated by stop, taken branch,
10591      interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
10592    */
10593   update_dependencies (idesc);
10594
10595   /* Sometimes, knowing a register value allows us to avoid giving a false DV
10596      warning.  Keep track of as many as possible that are useful.  */
10597   note_register_values (idesc);
10598
10599   /* We don't need or want this anymore.  */
10600   md.mem_offset.hint = 0;
10601
10602   return 0;
10603 }
10604
10605 /* Translate one line of assembly.  Pseudo ops and labels do not show
10606    here.  */
10607 void
10608 md_assemble (str)
10609      char *str;
10610 {
10611   char *saved_input_line_pointer, *mnemonic;
10612   const struct pseudo_opcode *pdesc;
10613   struct ia64_opcode *idesc;
10614   unsigned char qp_regno;
10615   unsigned int flags;
10616   int ch;
10617
10618   saved_input_line_pointer = input_line_pointer;
10619   input_line_pointer = str;
10620
10621   /* extract the opcode (mnemonic):  */
10622
10623   mnemonic = input_line_pointer;
10624   ch = get_symbol_end ();
10625   pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
10626   if (pdesc)
10627     {
10628       *input_line_pointer = ch;
10629       (*pdesc->handler) (pdesc->arg);
10630       goto done;
10631     }
10632
10633   /* Find the instruction descriptor matching the arguments.  */
10634
10635   idesc = ia64_find_opcode (mnemonic);
10636   *input_line_pointer = ch;
10637   if (!idesc)
10638     {
10639       as_bad ("Unknown opcode `%s'", mnemonic);
10640       goto done;
10641     }
10642
10643   idesc = parse_operands (idesc);
10644   if (!idesc)
10645     goto done;
10646
10647   /* Handle the dynamic ops we can handle now:  */
10648   if (idesc->type == IA64_TYPE_DYN)
10649     {
10650       if (strcmp (idesc->name, "add") == 0)
10651         {
10652           if (CURR_SLOT.opnd[2].X_op == O_register
10653               && CURR_SLOT.opnd[2].X_add_number < 4)
10654             mnemonic = "addl";
10655           else
10656             mnemonic = "adds";
10657           ia64_free_opcode (idesc);
10658           idesc = ia64_find_opcode (mnemonic);
10659         }
10660       else if (strcmp (idesc->name, "mov") == 0)
10661         {
10662           enum ia64_opnd opnd1, opnd2;
10663           int rop;
10664
10665           opnd1 = idesc->operands[0];
10666           opnd2 = idesc->operands[1];
10667           if (opnd1 == IA64_OPND_AR3)
10668             rop = 0;
10669           else if (opnd2 == IA64_OPND_AR3)
10670             rop = 1;
10671           else
10672             abort ();
10673           if (CURR_SLOT.opnd[rop].X_op == O_register)
10674             {
10675               if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10676                 mnemonic = "mov.i";
10677               else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10678                 mnemonic = "mov.m";
10679               else
10680                 rop = -1;
10681             }
10682           else
10683             abort ();
10684           if (rop >= 0)
10685             {
10686               ia64_free_opcode (idesc);
10687               idesc = ia64_find_opcode (mnemonic);
10688               while (idesc != NULL
10689                      && (idesc->operands[0] != opnd1
10690                          || idesc->operands[1] != opnd2))
10691                 idesc = get_next_opcode (idesc);
10692             }
10693         }
10694     }
10695   else if (strcmp (idesc->name, "mov.i") == 0
10696            || strcmp (idesc->name, "mov.m") == 0)
10697     {
10698       enum ia64_opnd opnd1, opnd2;
10699       int rop;
10700       
10701       opnd1 = idesc->operands[0];
10702       opnd2 = idesc->operands[1];
10703       if (opnd1 == IA64_OPND_AR3)
10704         rop = 0;
10705       else if (opnd2 == IA64_OPND_AR3)
10706         rop = 1;
10707       else
10708         abort ();
10709       if (CURR_SLOT.opnd[rop].X_op == O_register)
10710         {
10711           char unit = 'a';
10712           if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10713             unit = 'i';
10714           else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10715             unit = 'm';
10716           if (unit != 'a' && unit != idesc->name [4])
10717             as_bad ("AR %d can only be accessed by %c-unit",
10718                     (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR),
10719                     TOUPPER (unit));
10720         }
10721     }
10722   else if (strcmp (idesc->name, "hint.b") == 0)
10723     {
10724       switch (md.hint_b)
10725         {
10726         case hint_b_ok:
10727           break;
10728         case hint_b_warning:
10729           as_warn ("hint.b may be treated as nop");
10730           break;
10731         case hint_b_error:
10732           as_bad ("hint.b shouldn't be used");
10733           break;
10734         }
10735     }
10736
10737   qp_regno = 0;
10738   if (md.qp.X_op == O_register)
10739     {
10740       qp_regno = md.qp.X_add_number - REG_P;
10741       md.qp.X_op = O_absent;
10742     }
10743
10744   flags = idesc->flags;
10745
10746   if ((flags & IA64_OPCODE_FIRST) != 0)
10747     {
10748       /* The alignment frag has to end with a stop bit only if the
10749          next instruction after the alignment directive has to be
10750          the first instruction in an instruction group.  */
10751       if (align_frag)
10752         {
10753           while (align_frag->fr_type != rs_align_code)
10754             {
10755               align_frag = align_frag->fr_next;
10756               if (!align_frag)
10757                 break;
10758             }
10759           /* align_frag can be NULL if there are directives in
10760              between.  */
10761           if (align_frag && align_frag->fr_next == frag_now)
10762             align_frag->tc_frag_data = 1;
10763         }
10764
10765       insn_group_break (1, 0, 0);
10766     }
10767   align_frag = NULL;
10768
10769   if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10770     {
10771       as_bad ("`%s' cannot be predicated", idesc->name);
10772       goto done;
10773     }
10774
10775   /* Build the instruction.  */
10776   CURR_SLOT.qp_regno = qp_regno;
10777   CURR_SLOT.idesc = idesc;
10778   as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10779   dwarf2_where (&CURR_SLOT.debug_line);
10780
10781   /* Add unwind entry, if there is one.  */
10782   if (unwind.current_entry)
10783     {
10784       CURR_SLOT.unwind_record = unwind.current_entry;
10785       unwind.current_entry = NULL;
10786     }
10787   if (unwind.proc_start && S_IS_DEFINED (unwind.proc_start))
10788     unwind.insn = 1;
10789
10790   /* Check for dependency violations.  */
10791   if (md.detect_dv)
10792     check_dv (idesc);
10793
10794   md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10795   if (++md.num_slots_in_use >= NUM_SLOTS)
10796     emit_one_bundle ();
10797
10798   if ((flags & IA64_OPCODE_LAST) != 0)
10799     insn_group_break (1, 0, 0);
10800
10801   md.last_text_seg = now_seg;
10802
10803  done:
10804   input_line_pointer = saved_input_line_pointer;
10805 }
10806
10807 /* Called when symbol NAME cannot be found in the symbol table.
10808    Should be used for dynamic valued symbols only.  */
10809
10810 symbolS *
10811 md_undefined_symbol (name)
10812      char *name ATTRIBUTE_UNUSED;
10813 {
10814   return 0;
10815 }
10816
10817 /* Called for any expression that can not be recognized.  When the
10818    function is called, `input_line_pointer' will point to the start of
10819    the expression.  */
10820
10821 void
10822 md_operand (e)
10823      expressionS *e;
10824 {
10825   switch (*input_line_pointer)
10826     {
10827     case '[':
10828       ++input_line_pointer;
10829       expression (e);
10830       if (*input_line_pointer != ']')
10831         {
10832           as_bad ("Closing bracket missing");
10833           goto err;
10834         }
10835       else
10836         {
10837           if (e->X_op != O_register)
10838             as_bad ("Register expected as index");
10839
10840           ++input_line_pointer;
10841           e->X_op = O_index;
10842         }
10843       break;
10844
10845     default:
10846       break;
10847     }
10848   return;
10849
10850  err:
10851   ignore_rest_of_line ();
10852 }
10853
10854 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10855    a section symbol plus some offset.  For relocs involving @fptr(),
10856    directives we don't want such adjustments since we need to have the
10857    original symbol's name in the reloc.  */
10858 int
10859 ia64_fix_adjustable (fix)
10860      fixS *fix;
10861 {
10862   /* Prevent all adjustments to global symbols */
10863   if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10864     return 0;
10865
10866   switch (fix->fx_r_type)
10867     {
10868     case BFD_RELOC_IA64_FPTR64I:
10869     case BFD_RELOC_IA64_FPTR32MSB:
10870     case BFD_RELOC_IA64_FPTR32LSB:
10871     case BFD_RELOC_IA64_FPTR64MSB:
10872     case BFD_RELOC_IA64_FPTR64LSB:
10873     case BFD_RELOC_IA64_LTOFF_FPTR22:
10874     case BFD_RELOC_IA64_LTOFF_FPTR64I:
10875       return 0;
10876     default:
10877       break;
10878     }
10879
10880   return 1;
10881 }
10882
10883 int
10884 ia64_force_relocation (fix)
10885      fixS *fix;
10886 {
10887   switch (fix->fx_r_type)
10888     {
10889     case BFD_RELOC_IA64_FPTR64I:
10890     case BFD_RELOC_IA64_FPTR32MSB:
10891     case BFD_RELOC_IA64_FPTR32LSB:
10892     case BFD_RELOC_IA64_FPTR64MSB:
10893     case BFD_RELOC_IA64_FPTR64LSB:
10894
10895     case BFD_RELOC_IA64_LTOFF22:
10896     case BFD_RELOC_IA64_LTOFF64I:
10897     case BFD_RELOC_IA64_LTOFF_FPTR22:
10898     case BFD_RELOC_IA64_LTOFF_FPTR64I:
10899     case BFD_RELOC_IA64_PLTOFF22:
10900     case BFD_RELOC_IA64_PLTOFF64I:
10901     case BFD_RELOC_IA64_PLTOFF64MSB:
10902     case BFD_RELOC_IA64_PLTOFF64LSB:
10903
10904     case BFD_RELOC_IA64_LTOFF22X:
10905     case BFD_RELOC_IA64_LDXMOV:
10906       return 1;
10907
10908     default:
10909       break;
10910     }
10911
10912   return generic_force_reloc (fix);
10913 }
10914
10915 /* Decide from what point a pc-relative relocation is relative to,
10916    relative to the pc-relative fixup.  Er, relatively speaking.  */
10917 long
10918 ia64_pcrel_from_section (fix, sec)
10919      fixS *fix;
10920      segT sec;
10921 {
10922   unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10923
10924   if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10925     off &= ~0xfUL;
10926
10927   return off;
10928 }
10929
10930
10931 /* Used to emit section-relative relocs for the dwarf2 debug data.  */
10932 void
10933 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10934 {
10935   expressionS expr;
10936
10937   expr.X_op = O_pseudo_fixup;
10938   expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10939   expr.X_add_number = 0;
10940   expr.X_add_symbol = symbol;
10941   emit_expr (&expr, size);
10942 }
10943
10944 /* This is called whenever some data item (not an instruction) needs a
10945    fixup.  We pick the right reloc code depending on the byteorder
10946    currently in effect.  */
10947 void
10948 ia64_cons_fix_new (f, where, nbytes, exp)
10949      fragS *f;
10950      int where;
10951      int nbytes;
10952      expressionS *exp;
10953 {
10954   bfd_reloc_code_real_type code;
10955   fixS *fix;
10956
10957   switch (nbytes)
10958     {
10959       /* There are no reloc for 8 and 16 bit quantities, but we allow
10960          them here since they will work fine as long as the expression
10961          is fully defined at the end of the pass over the source file.  */
10962     case 1: code = BFD_RELOC_8; break;
10963     case 2: code = BFD_RELOC_16; break;
10964     case 4:
10965       if (target_big_endian)
10966         code = BFD_RELOC_IA64_DIR32MSB;
10967       else
10968         code = BFD_RELOC_IA64_DIR32LSB;
10969       break;
10970
10971     case 8:
10972       /* In 32-bit mode, data8 could mean function descriptors too.  */
10973       if (exp->X_op == O_pseudo_fixup
10974           && exp->X_op_symbol
10975           && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10976           && !(md.flags & EF_IA_64_ABI64))
10977         {
10978           if (target_big_endian)
10979             code = BFD_RELOC_IA64_IPLTMSB;
10980           else
10981             code = BFD_RELOC_IA64_IPLTLSB;
10982           exp->X_op = O_symbol;
10983           break;
10984         }
10985       else
10986         {
10987           if (target_big_endian)
10988             code = BFD_RELOC_IA64_DIR64MSB;
10989           else
10990             code = BFD_RELOC_IA64_DIR64LSB;
10991           break;
10992         }
10993
10994     case 16:
10995       if (exp->X_op == O_pseudo_fixup
10996           && exp->X_op_symbol
10997           && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10998         {
10999           if (target_big_endian)
11000             code = BFD_RELOC_IA64_IPLTMSB;
11001           else
11002             code = BFD_RELOC_IA64_IPLTLSB;
11003           exp->X_op = O_symbol;
11004           break;
11005         }
11006       /* FALLTHRU */
11007
11008     default:
11009       as_bad ("Unsupported fixup size %d", nbytes);
11010       ignore_rest_of_line ();
11011       return;
11012     }
11013
11014   if (exp->X_op == O_pseudo_fixup)
11015     {
11016       exp->X_op = O_symbol;
11017       code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
11018       /* ??? If code unchanged, unsupported.  */
11019     }
11020
11021   fix = fix_new_exp (f, where, nbytes, exp, 0, code);
11022   /* We need to store the byte order in effect in case we're going
11023      to fix an 8 or 16 bit relocation (for which there no real
11024      relocs available).  See md_apply_fix3().  */
11025   fix->tc_fix_data.bigendian = target_big_endian;
11026 }
11027
11028 /* Return the actual relocation we wish to associate with the pseudo
11029    reloc described by SYM and R_TYPE.  SYM should be one of the
11030    symbols in the pseudo_func array, or NULL.  */
11031
11032 static bfd_reloc_code_real_type
11033 ia64_gen_real_reloc_type (sym, r_type)
11034      struct symbol *sym;
11035      bfd_reloc_code_real_type r_type;
11036 {
11037   bfd_reloc_code_real_type new = 0;
11038   const char *type = NULL, *suffix = "";
11039
11040   if (sym == NULL)
11041     {
11042       return r_type;
11043     }
11044
11045   switch (S_GET_VALUE (sym))
11046     {
11047     case FUNC_FPTR_RELATIVE:
11048       switch (r_type)
11049         {
11050         case BFD_RELOC_IA64_IMM64:      new = BFD_RELOC_IA64_FPTR64I; break;
11051         case BFD_RELOC_IA64_DIR32MSB:   new = BFD_RELOC_IA64_FPTR32MSB; break;
11052         case BFD_RELOC_IA64_DIR32LSB:   new = BFD_RELOC_IA64_FPTR32LSB; break;
11053         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_FPTR64MSB; break;
11054         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_FPTR64LSB; break;
11055         default:                        type = "FPTR"; break;
11056         }
11057       break;
11058
11059     case FUNC_GP_RELATIVE:
11060       switch (r_type)
11061         {
11062         case BFD_RELOC_IA64_IMM22:      new = BFD_RELOC_IA64_GPREL22; break;
11063         case BFD_RELOC_IA64_IMM64:      new = BFD_RELOC_IA64_GPREL64I; break;
11064         case BFD_RELOC_IA64_DIR32MSB:   new = BFD_RELOC_IA64_GPREL32MSB; break;
11065         case BFD_RELOC_IA64_DIR32LSB:   new = BFD_RELOC_IA64_GPREL32LSB; break;
11066         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_GPREL64MSB; break;
11067         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_GPREL64LSB; break;
11068         default:                        type = "GPREL"; break;
11069         }
11070       break;
11071
11072     case FUNC_LT_RELATIVE:
11073       switch (r_type)
11074         {
11075         case BFD_RELOC_IA64_IMM22:      new = BFD_RELOC_IA64_LTOFF22; break;
11076         case BFD_RELOC_IA64_IMM64:      new = BFD_RELOC_IA64_LTOFF64I; break;
11077         default:                        type = "LTOFF"; break;
11078         }
11079       break;
11080
11081     case FUNC_LT_RELATIVE_X:
11082       switch (r_type)
11083         {
11084         case BFD_RELOC_IA64_IMM22:      new = BFD_RELOC_IA64_LTOFF22X; break;
11085         default:                        type = "LTOFF"; suffix = "X"; break;
11086         }
11087       break;
11088
11089     case FUNC_PC_RELATIVE:
11090       switch (r_type)
11091         {
11092         case BFD_RELOC_IA64_IMM22:      new = BFD_RELOC_IA64_PCREL22; break;
11093         case BFD_RELOC_IA64_IMM64:      new = BFD_RELOC_IA64_PCREL64I; break;
11094         case BFD_RELOC_IA64_DIR32MSB:   new = BFD_RELOC_IA64_PCREL32MSB; break;
11095         case BFD_RELOC_IA64_DIR32LSB:   new = BFD_RELOC_IA64_PCREL32LSB; break;
11096         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_PCREL64MSB; break;
11097         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_PCREL64LSB; break;
11098         default:                        type = "PCREL"; break;
11099         }
11100       break;
11101
11102     case FUNC_PLT_RELATIVE:
11103       switch (r_type)
11104         {
11105         case BFD_RELOC_IA64_IMM22:      new = BFD_RELOC_IA64_PLTOFF22; break;
11106         case BFD_RELOC_IA64_IMM64:      new = BFD_RELOC_IA64_PLTOFF64I; break;
11107         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_PLTOFF64MSB;break;
11108         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_PLTOFF64LSB;break;
11109         default:                        type = "PLTOFF"; break;
11110         }
11111       break;
11112
11113     case FUNC_SEC_RELATIVE:
11114       switch (r_type)
11115         {
11116         case BFD_RELOC_IA64_DIR32MSB:   new = BFD_RELOC_IA64_SECREL32MSB;break;
11117         case BFD_RELOC_IA64_DIR32LSB:   new = BFD_RELOC_IA64_SECREL32LSB;break;
11118         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_SECREL64MSB;break;
11119         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_SECREL64LSB;break;
11120         default:                        type = "SECREL"; break;
11121         }
11122       break;
11123
11124     case FUNC_SEG_RELATIVE:
11125       switch (r_type)
11126         {
11127         case BFD_RELOC_IA64_DIR32MSB:   new = BFD_RELOC_IA64_SEGREL32MSB;break;
11128         case BFD_RELOC_IA64_DIR32LSB:   new = BFD_RELOC_IA64_SEGREL32LSB;break;
11129         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_SEGREL64MSB;break;
11130         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_SEGREL64LSB;break;
11131         default:                        type = "SEGREL"; break;
11132         }
11133       break;
11134
11135     case FUNC_LTV_RELATIVE:
11136       switch (r_type)
11137         {
11138         case BFD_RELOC_IA64_DIR32MSB:   new = BFD_RELOC_IA64_LTV32MSB; break;
11139         case BFD_RELOC_IA64_DIR32LSB:   new = BFD_RELOC_IA64_LTV32LSB; break;
11140         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_LTV64MSB; break;
11141         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_LTV64LSB; break;
11142         default:                        type = "LTV"; break;
11143         }
11144       break;
11145
11146     case FUNC_LT_FPTR_RELATIVE:
11147       switch (r_type)
11148         {
11149         case BFD_RELOC_IA64_IMM22:
11150           new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
11151         case BFD_RELOC_IA64_IMM64:
11152           new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
11153         case BFD_RELOC_IA64_DIR32MSB:
11154           new = BFD_RELOC_IA64_LTOFF_FPTR32MSB; break;
11155         case BFD_RELOC_IA64_DIR32LSB:
11156           new = BFD_RELOC_IA64_LTOFF_FPTR32LSB; break;
11157         case BFD_RELOC_IA64_DIR64MSB:
11158           new = BFD_RELOC_IA64_LTOFF_FPTR64MSB; break;
11159         case BFD_RELOC_IA64_DIR64LSB:
11160           new = BFD_RELOC_IA64_LTOFF_FPTR64LSB; break;
11161         default:
11162           type = "LTOFF_FPTR"; break;
11163         }
11164       break;
11165
11166     case FUNC_TP_RELATIVE:
11167       switch (r_type)
11168         {
11169         case BFD_RELOC_IA64_IMM14:      new = BFD_RELOC_IA64_TPREL14; break;
11170         case BFD_RELOC_IA64_IMM22:      new = BFD_RELOC_IA64_TPREL22; break;
11171         case BFD_RELOC_IA64_IMM64:      new = BFD_RELOC_IA64_TPREL64I; break;
11172         case BFD_RELOC_IA64_DIR64MSB:   new = BFD_RELOC_IA64_TPREL64MSB; break;
11173         case BFD_RELOC_IA64_DIR64LSB:   new = BFD_RELOC_IA64_TPREL64LSB; break;
11174         default:                        type = "TPREL"; break;
11175         }
11176       break;
11177
11178     case FUNC_LT_TP_RELATIVE:
11179       switch (r_type)
11180         {
11181         case BFD_RELOC_IA64_IMM22:
11182           new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
11183         default:
11184           type = "LTOFF_TPREL"; break;
11185         }
11186       break;
11187
11188     case FUNC_DTP_MODULE:
11189       switch (r_type)
11190         {
11191         case BFD_RELOC_IA64_DIR64MSB:
11192           new = BFD_RELOC_IA64_DTPMOD64MSB; break;
11193         case BFD_RELOC_IA64_DIR64LSB:
11194           new = BFD_RELOC_IA64_DTPMOD64LSB; break;
11195         default:
11196           type = "DTPMOD"; break;
11197         }
11198       break;
11199
11200     case FUNC_LT_DTP_MODULE:
11201       switch (r_type)
11202         {
11203         case BFD_RELOC_IA64_IMM22:
11204           new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
11205         default:
11206           type = "LTOFF_DTPMOD"; break;
11207         }
11208       break;
11209
11210     case FUNC_DTP_RELATIVE:
11211       switch (r_type)
11212         {
11213         case BFD_RELOC_IA64_DIR32MSB:
11214           new = BFD_RELOC_IA64_DTPREL32MSB; break;
11215         case BFD_RELOC_IA64_DIR32LSB:
11216           new = BFD_RELOC_IA64_DTPREL32LSB; break;
11217         case BFD_RELOC_IA64_DIR64MSB:
11218           new = BFD_RELOC_IA64_DTPREL64MSB; break;
11219         case BFD_RELOC_IA64_DIR64LSB:
11220           new = BFD_RELOC_IA64_DTPREL64LSB; break;
11221         case BFD_RELOC_IA64_IMM14:
11222           new = BFD_RELOC_IA64_DTPREL14; break;
11223         case BFD_RELOC_IA64_IMM22:
11224           new = BFD_RELOC_IA64_DTPREL22; break;
11225         case BFD_RELOC_IA64_IMM64:
11226           new = BFD_RELOC_IA64_DTPREL64I; break;
11227         default:
11228           type = "DTPREL"; break;
11229         }
11230       break;
11231
11232     case FUNC_LT_DTP_RELATIVE:
11233       switch (r_type)
11234         {
11235         case BFD_RELOC_IA64_IMM22:
11236           new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
11237         default:
11238           type = "LTOFF_DTPREL"; break;
11239         }
11240       break;
11241
11242     case FUNC_IPLT_RELOC:
11243       switch (r_type)
11244         {
11245         case BFD_RELOC_IA64_IPLTMSB:    return r_type;
11246         case BFD_RELOC_IA64_IPLTLSB:    return r_type;
11247         default:                        type = "IPLT"; break;
11248         }
11249       break;
11250
11251     default:
11252       abort ();
11253     }
11254
11255   if (new)
11256     return new;
11257   else
11258     {
11259       int width;
11260
11261       if (!type)
11262         abort ();
11263       switch (r_type)
11264         {
11265         case BFD_RELOC_IA64_DIR32MSB: width = 32; suffix = "MSB"; break;
11266         case BFD_RELOC_IA64_DIR32LSB: width = 32; suffix = "LSB"; break;
11267         case BFD_RELOC_IA64_DIR64MSB: width = 64; suffix = "MSB"; break;
11268         case BFD_RELOC_IA64_DIR64LSB: width = 64; suffix = "LSB"; break;
11269         case BFD_RELOC_UNUSED:        width = 13; break;
11270         case BFD_RELOC_IA64_IMM14:    width = 14; break;
11271         case BFD_RELOC_IA64_IMM22:    width = 22; break;
11272         case BFD_RELOC_IA64_IMM64:    width = 64; suffix = "I"; break;
11273         default:                      abort ();
11274         }
11275
11276       /* This should be an error, but since previously there wasn't any
11277          diagnostic here, dont't make it fail because of this for now.  */
11278       as_warn ("Cannot express %s%d%s relocation", type, width, suffix);
11279       return r_type;
11280     }
11281 }
11282
11283 /* Here is where generate the appropriate reloc for pseudo relocation
11284    functions.  */
11285 void
11286 ia64_validate_fix (fix)
11287      fixS *fix;
11288 {
11289   switch (fix->fx_r_type)
11290     {
11291     case BFD_RELOC_IA64_FPTR64I:
11292     case BFD_RELOC_IA64_FPTR32MSB:
11293     case BFD_RELOC_IA64_FPTR64LSB:
11294     case BFD_RELOC_IA64_LTOFF_FPTR22:
11295     case BFD_RELOC_IA64_LTOFF_FPTR64I:
11296       if (fix->fx_offset != 0)
11297         as_bad_where (fix->fx_file, fix->fx_line,
11298                       "No addend allowed in @fptr() relocation");
11299       break;
11300     default:
11301       break;
11302     }
11303 }
11304
11305 static void
11306 fix_insn (fix, odesc, value)
11307      fixS *fix;
11308      const struct ia64_operand *odesc;
11309      valueT value;
11310 {
11311   bfd_vma insn[3], t0, t1, control_bits;
11312   const char *err;
11313   char *fixpos;
11314   long slot;
11315
11316   slot = fix->fx_where & 0x3;
11317   fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
11318
11319   /* Bundles are always in little-endian byte order */
11320   t0 = bfd_getl64 (fixpos);
11321   t1 = bfd_getl64 (fixpos + 8);
11322   control_bits = t0 & 0x1f;
11323   insn[0] = (t0 >>  5) & 0x1ffffffffffLL;
11324   insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
11325   insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
11326
11327   err = NULL;
11328   if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
11329     {
11330       insn[1] = (value >> 22) & 0x1ffffffffffLL;
11331       insn[2] |= (((value & 0x7f) << 13)
11332                   | (((value >> 7) & 0x1ff) << 27)
11333                   | (((value >> 16) & 0x1f) << 22)
11334                   | (((value >> 21) & 0x1) << 21)
11335                   | (((value >> 63) & 0x1) << 36));
11336     }
11337   else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
11338     {
11339       if (value & ~0x3fffffffffffffffULL)
11340         err = "integer operand out of range";
11341       insn[1] = (value >> 21) & 0x1ffffffffffLL;
11342       insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
11343     }
11344   else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
11345     {
11346       value >>= 4;
11347       insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
11348       insn[2] |= ((((value >> 59) & 0x1) << 36)
11349                   | (((value >> 0) & 0xfffff) << 13));
11350     }
11351   else
11352     err = (*odesc->insert) (odesc, value, insn + slot);
11353
11354   if (err)
11355     as_bad_where (fix->fx_file, fix->fx_line, err);
11356
11357   t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
11358   t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
11359   number_to_chars_littleendian (fixpos + 0, t0, 8);
11360   number_to_chars_littleendian (fixpos + 8, t1, 8);
11361 }
11362
11363 /* Attempt to simplify or even eliminate a fixup.  The return value is
11364    ignored; perhaps it was once meaningful, but now it is historical.
11365    To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
11366
11367    If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
11368    (if possible).  */
11369
11370 void
11371 md_apply_fix3 (fix, valP, seg)
11372      fixS *fix;
11373      valueT *valP;
11374      segT seg ATTRIBUTE_UNUSED;
11375 {
11376   char *fixpos;
11377   valueT value = *valP;
11378
11379   fixpos = fix->fx_frag->fr_literal + fix->fx_where;
11380
11381   if (fix->fx_pcrel)
11382     {
11383     switch (fix->fx_r_type)
11384       {
11385       case BFD_RELOC_IA64_PCREL21B: break;
11386       case BFD_RELOC_IA64_PCREL21BI: break;
11387       case BFD_RELOC_IA64_PCREL21F: break;
11388       case BFD_RELOC_IA64_PCREL21M: break;
11389       case BFD_RELOC_IA64_PCREL60B: break;
11390       case BFD_RELOC_IA64_PCREL22: break;
11391       case BFD_RELOC_IA64_PCREL64I: break;
11392       case BFD_RELOC_IA64_PCREL32MSB: break;
11393       case BFD_RELOC_IA64_PCREL32LSB: break;
11394       case BFD_RELOC_IA64_PCREL64MSB: break;
11395       case BFD_RELOC_IA64_PCREL64LSB: break;
11396       default:
11397         fix->fx_r_type = ia64_gen_real_reloc_type (pseudo_func[FUNC_PC_RELATIVE].u.sym,
11398                                                fix->fx_r_type);
11399         break;
11400       }
11401     }
11402   if (fix->fx_addsy)
11403     {
11404       switch (fix->fx_r_type)
11405         {
11406         case BFD_RELOC_UNUSED:
11407           /* This must be a TAG13 or TAG13b operand.  There are no external
11408              relocs defined for them, so we must give an error.  */
11409           as_bad_where (fix->fx_file, fix->fx_line,
11410                         "%s must have a constant value",
11411                         elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
11412           fix->fx_done = 1;
11413           return;
11414
11415         case BFD_RELOC_IA64_TPREL14:
11416         case BFD_RELOC_IA64_TPREL22:
11417         case BFD_RELOC_IA64_TPREL64I:
11418         case BFD_RELOC_IA64_LTOFF_TPREL22:
11419         case BFD_RELOC_IA64_LTOFF_DTPMOD22:
11420         case BFD_RELOC_IA64_DTPREL14:
11421         case BFD_RELOC_IA64_DTPREL22:
11422         case BFD_RELOC_IA64_DTPREL64I:
11423         case BFD_RELOC_IA64_LTOFF_DTPREL22:
11424           S_SET_THREAD_LOCAL (fix->fx_addsy);
11425           break;
11426
11427         default:
11428           break;
11429         }
11430     }
11431   else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
11432     {
11433       if (fix->tc_fix_data.bigendian)
11434         number_to_chars_bigendian (fixpos, value, fix->fx_size);
11435       else
11436         number_to_chars_littleendian (fixpos, value, fix->fx_size);
11437       fix->fx_done = 1;
11438     }
11439   else
11440     {
11441       fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
11442       fix->fx_done = 1;
11443     }
11444 }
11445
11446 /* Generate the BFD reloc to be stuck in the object file from the
11447    fixup used internally in the assembler.  */
11448
11449 arelent *
11450 tc_gen_reloc (sec, fixp)
11451      asection *sec ATTRIBUTE_UNUSED;
11452      fixS *fixp;
11453 {
11454   arelent *reloc;
11455
11456   reloc = xmalloc (sizeof (*reloc));
11457   reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11458   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11459   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11460   reloc->addend = fixp->fx_offset;
11461   reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
11462
11463   if (!reloc->howto)
11464     {
11465       as_bad_where (fixp->fx_file, fixp->fx_line,
11466                     "Cannot represent %s relocation in object file",
11467                     bfd_get_reloc_code_name (fixp->fx_r_type));
11468     }
11469   return reloc;
11470 }
11471
11472 /* Turn a string in input_line_pointer into a floating point constant
11473    of type TYPE, and store the appropriate bytes in *LIT.  The number
11474    of LITTLENUMS emitted is stored in *SIZE.  An error message is
11475    returned, or NULL on OK.  */
11476
11477 #define MAX_LITTLENUMS 5
11478
11479 char *
11480 md_atof (type, lit, size)
11481      int type;
11482      char *lit;
11483      int *size;
11484 {
11485   LITTLENUM_TYPE words[MAX_LITTLENUMS];
11486   char *t;
11487   int prec;
11488
11489   switch (type)
11490     {
11491       /* IEEE floats */
11492     case 'f':
11493     case 'F':
11494     case 's':
11495     case 'S':
11496       prec = 2;
11497       break;
11498
11499     case 'd':
11500     case 'D':
11501     case 'r':
11502     case 'R':
11503       prec = 4;
11504       break;
11505
11506     case 'x':
11507     case 'X':
11508     case 'p':
11509     case 'P':
11510       prec = 5;
11511       break;
11512
11513     default:
11514       *size = 0;
11515       return "Bad call to MD_ATOF()";
11516     }
11517   t = atof_ieee (input_line_pointer, type, words);
11518   if (t)
11519     input_line_pointer = t;
11520
11521   (*ia64_float_to_chars) (lit, words, prec);
11522
11523   if (type == 'X')
11524     {
11525       /* It is 10 byte floating point with 6 byte padding.  */
11526       memset (&lit [10], 0, 6);
11527       *size = 8 * sizeof (LITTLENUM_TYPE);
11528     }
11529   else
11530     *size = prec * sizeof (LITTLENUM_TYPE);
11531
11532   return 0;
11533 }
11534
11535 /* Handle ia64 specific semantics of the align directive.  */
11536
11537 void
11538 ia64_md_do_align (n, fill, len, max)
11539      int n ATTRIBUTE_UNUSED;
11540      const char *fill ATTRIBUTE_UNUSED;
11541      int len ATTRIBUTE_UNUSED;
11542      int max ATTRIBUTE_UNUSED;
11543 {
11544   if (subseg_text_p (now_seg))
11545     ia64_flush_insns ();
11546 }
11547
11548 /* This is called from HANDLE_ALIGN in write.c.  Fill in the contents
11549    of an rs_align_code fragment.  */
11550
11551 void
11552 ia64_handle_align (fragp)
11553      fragS *fragp;
11554 {
11555   int bytes;
11556   char *p;
11557   const unsigned char *nop;
11558
11559   if (fragp->fr_type != rs_align_code)
11560     return;
11561
11562   /* Check if this frag has to end with a stop bit.  */
11563   nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
11564
11565   bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11566   p = fragp->fr_literal + fragp->fr_fix;
11567
11568   /* If no paddings are needed, we check if we need a stop bit.  */ 
11569   if (!bytes && fragp->tc_frag_data)
11570     {
11571       if (fragp->fr_fix < 16)
11572 #if 1
11573         /* FIXME: It won't work with
11574            .align 16
11575            alloc r32=ar.pfs,1,2,4,0
11576          */
11577         ;
11578 #else
11579         as_bad_where (fragp->fr_file, fragp->fr_line,
11580                       _("Can't add stop bit to mark end of instruction group"));
11581 #endif
11582       else
11583         /* Bundles are always in little-endian byte order. Make sure
11584            the previous bundle has the stop bit.  */
11585         *(p - 16) |= 1;
11586     }
11587
11588   /* Make sure we are on a 16-byte boundary, in case someone has been
11589      putting data into a text section.  */
11590   if (bytes & 15)
11591     {
11592       int fix = bytes & 15;
11593       memset (p, 0, fix);
11594       p += fix;
11595       bytes -= fix;
11596       fragp->fr_fix += fix;
11597     }
11598
11599   /* Instruction bundles are always little-endian.  */
11600   memcpy (p, nop, 16);
11601   fragp->fr_var = 16;
11602 }
11603
11604 static void
11605 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
11606                                int prec)
11607 {
11608   while (prec--)
11609     {
11610       number_to_chars_bigendian (lit, (long) (*words++),
11611                                  sizeof (LITTLENUM_TYPE));
11612       lit += sizeof (LITTLENUM_TYPE);
11613     }
11614 }
11615
11616 static void
11617 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
11618                                   int prec)
11619 {
11620   while (prec--)
11621     {
11622       number_to_chars_littleendian (lit, (long) (words[prec]),
11623                                     sizeof (LITTLENUM_TYPE));
11624       lit += sizeof (LITTLENUM_TYPE);
11625     }
11626 }
11627
11628 void
11629 ia64_elf_section_change_hook  (void)
11630 {
11631   if (elf_section_type (now_seg) == SHT_IA_64_UNWIND
11632       && elf_linked_to_section (now_seg) == NULL)
11633     elf_linked_to_section (now_seg) = text_section;
11634   dot_byteorder (-1);
11635 }
11636
11637 /* Check if a label should be made global.  */
11638 void
11639 ia64_check_label (symbolS *label)
11640 {
11641   if (*input_line_pointer == ':')
11642     {
11643       S_SET_EXTERNAL (label);
11644       input_line_pointer++;
11645     }
11646 }
11647
11648 /* Used to remember where .alias and .secalias directives are seen. We
11649    will rename symbol and section names when we are about to output
11650    the relocatable file.  */
11651 struct alias
11652 {
11653   char *file;           /* The file where the directive is seen.  */
11654   unsigned int line;    /* The line number the directive is at.  */
11655   const char *name;     /* The orignale name of the symbol.  */
11656 };
11657
11658 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11659    .secalias. Otherwise, it is .alias.  */
11660 static void
11661 dot_alias (int section)
11662 {
11663   char *name, *alias;
11664   char delim;
11665   char *end_name;
11666   int len;
11667   const char *error_string;
11668   struct alias *h;
11669   const char *a;
11670   struct hash_control *ahash, *nhash;
11671   const char *kind;
11672
11673   name = input_line_pointer;
11674   delim = get_symbol_end ();
11675   end_name = input_line_pointer;
11676   *end_name = delim;
11677
11678   if (name == end_name)
11679     {
11680       as_bad (_("expected symbol name"));
11681       discard_rest_of_line ();
11682       return;
11683     }
11684
11685   SKIP_WHITESPACE ();
11686
11687   if (*input_line_pointer != ',')
11688     {
11689       *end_name = 0;
11690       as_bad (_("expected comma after \"%s\""), name);
11691       *end_name = delim;
11692       ignore_rest_of_line ();
11693       return;
11694     }
11695
11696   input_line_pointer++;
11697   *end_name = 0;
11698   ia64_canonicalize_symbol_name (name);
11699
11700   /* We call demand_copy_C_string to check if alias string is valid.
11701      There should be a closing `"' and no `\0' in the string.  */
11702   alias = demand_copy_C_string (&len);
11703   if (alias == NULL)
11704     {
11705       ignore_rest_of_line ();
11706       return;
11707     }
11708
11709   /* Make a copy of name string.  */
11710   len = strlen (name) + 1;
11711   obstack_grow (&notes, name, len);
11712   name = obstack_finish (&notes);
11713
11714   if (section)
11715     {
11716       kind = "section";
11717       ahash = secalias_hash;
11718       nhash = secalias_name_hash;
11719     }
11720   else
11721     {
11722       kind = "symbol";
11723       ahash = alias_hash;
11724       nhash = alias_name_hash;
11725     }
11726
11727   /* Check if alias has been used before.  */
11728   h = (struct alias *) hash_find (ahash, alias);
11729   if (h)
11730     {
11731       if (strcmp (h->name, name))
11732         as_bad (_("`%s' is already the alias of %s `%s'"),
11733                 alias, kind, h->name);
11734       goto out;
11735     }
11736
11737   /* Check if name already has an alias.  */
11738   a = (const char *) hash_find (nhash, name);
11739   if (a)
11740     {
11741       if (strcmp (a, alias))
11742         as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11743       goto out;
11744     }
11745
11746   h = (struct alias *) xmalloc (sizeof (struct alias));
11747   as_where (&h->file, &h->line);
11748   h->name = name;
11749   
11750   error_string = hash_jam (ahash, alias, (PTR) h);
11751   if (error_string)
11752     {
11753       as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11754                 alias, kind, error_string);
11755       goto out;
11756     }
11757
11758   error_string = hash_jam (nhash, name, (PTR) alias);
11759   if (error_string)
11760     {
11761       as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11762                 alias, kind, error_string);
11763 out:
11764       obstack_free (&notes, name);
11765       obstack_free (&notes, alias);
11766     }
11767
11768   demand_empty_rest_of_line ();
11769 }
11770
11771 /* It renames the original symbol name to its alias.  */
11772 static void
11773 do_alias (const char *alias, PTR value)
11774 {
11775   struct alias *h = (struct alias *) value;
11776   symbolS *sym = symbol_find (h->name);
11777
11778   if (sym == NULL)
11779     as_warn_where (h->file, h->line,
11780                    _("symbol `%s' aliased to `%s' is not used"),
11781                    h->name, alias);
11782     else
11783       S_SET_NAME (sym, (char *) alias);
11784 }
11785
11786 /* Called from write_object_file.  */
11787 void
11788 ia64_adjust_symtab (void)
11789 {
11790   hash_traverse (alias_hash, do_alias);
11791 }
11792
11793 /* It renames the original section name to its alias.  */
11794 static void
11795 do_secalias (const char *alias, PTR value)
11796 {
11797   struct alias *h = (struct alias *) value;
11798   segT sec = bfd_get_section_by_name (stdoutput, h->name);
11799
11800   if (sec == NULL)
11801     as_warn_where (h->file, h->line,
11802                    _("section `%s' aliased to `%s' is not used"),
11803                    h->name, alias);
11804   else
11805     sec->name = alias;
11806 }
11807
11808 /* Called from write_object_file.  */
11809 void
11810 ia64_frob_file (void)
11811 {
11812   hash_traverse (secalias_hash, do_secalias);
11813 }
This page took 0.680784 seconds and 4 git commands to generate.