Patch from David Mosberger-Tang.
[binutils.git] / gas / config / tc-ia64.c
blob0dc438c2ee4142d54261d2d8a3d1070ea31564fd
1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 TODO:
25 - optional operands
26 - directives:
27 .eb
28 .estate
29 .lb
30 .popsection
31 .previous
32 .psr
33 .pushsection
34 - labels are wrong if automatic alignment is introduced
35 (e.g., checkout the second real10 definition in test-data.s)
36 - DV-related stuff:
37 <reg>.safe_across_calls and any other DV-related directives I don't
38 have documentation for.
39 verify mod-sched-brs reads/writes are checked/marked (and other
40 notes)
44 #include "as.h"
45 #include "safe-ctype.h"
46 #include "dwarf2dbg.h"
47 #include "subsegs.h"
49 #include "opcode/ia64.h"
51 #include "elf/ia64.h"
53 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
54 #define MIN(a,b) ((a) < (b) ? (a) : (b))
56 #define NUM_SLOTS 4
57 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
58 #define CURR_SLOT md.slot[md.curr_slot]
60 #define O_pseudo_fixup (O_max + 1)
62 enum special_section
64 /* IA-64 ABI section pseudo-ops. */
65 SPECIAL_SECTION_BSS = 0,
66 SPECIAL_SECTION_SBSS,
67 SPECIAL_SECTION_SDATA,
68 SPECIAL_SECTION_RODATA,
69 SPECIAL_SECTION_COMMENT,
70 SPECIAL_SECTION_UNWIND,
71 SPECIAL_SECTION_UNWIND_INFO,
72 /* HPUX specific section pseudo-ops. */
73 SPECIAL_SECTION_INIT_ARRAY,
74 SPECIAL_SECTION_FINI_ARRAY,
77 enum reloc_func
79 FUNC_DTP_MODULE,
80 FUNC_DTP_RELATIVE,
81 FUNC_FPTR_RELATIVE,
82 FUNC_GP_RELATIVE,
83 FUNC_LT_RELATIVE,
84 FUNC_LT_RELATIVE_X,
85 FUNC_PC_RELATIVE,
86 FUNC_PLT_RELATIVE,
87 FUNC_SEC_RELATIVE,
88 FUNC_SEG_RELATIVE,
89 FUNC_TP_RELATIVE,
90 FUNC_LTV_RELATIVE,
91 FUNC_LT_FPTR_RELATIVE,
92 FUNC_LT_DTP_MODULE,
93 FUNC_LT_DTP_RELATIVE,
94 FUNC_LT_TP_RELATIVE,
95 FUNC_IPLT_RELOC,
98 enum reg_symbol
100 REG_GR = 0,
101 REG_FR = (REG_GR + 128),
102 REG_AR = (REG_FR + 128),
103 REG_CR = (REG_AR + 128),
104 REG_P = (REG_CR + 128),
105 REG_BR = (REG_P + 64),
106 REG_IP = (REG_BR + 8),
107 REG_CFM,
108 REG_PR,
109 REG_PR_ROT,
110 REG_PSR,
111 REG_PSR_L,
112 REG_PSR_UM,
113 /* The following are pseudo-registers for use by gas only. */
114 IND_CPUID,
115 IND_DBR,
116 IND_DTR,
117 IND_ITR,
118 IND_IBR,
119 IND_MEM,
120 IND_MSR,
121 IND_PKR,
122 IND_PMC,
123 IND_PMD,
124 IND_RR,
125 /* The following pseudo-registers are used for unwind directives only: */
126 REG_PSP,
127 REG_PRIUNAT,
128 REG_NUM
131 enum dynreg_type
133 DYNREG_GR = 0, /* dynamic general purpose register */
134 DYNREG_FR, /* dynamic floating point register */
135 DYNREG_PR, /* dynamic predicate register */
136 DYNREG_NUM_TYPES
139 enum operand_match_result
141 OPERAND_MATCH,
142 OPERAND_OUT_OF_RANGE,
143 OPERAND_MISMATCH
146 /* On the ia64, we can't know the address of a text label until the
147 instructions are packed into a bundle. To handle this, we keep
148 track of the list of labels that appear in front of each
149 instruction. */
150 struct label_fix
152 struct label_fix *next;
153 struct symbol *sym;
156 extern int target_big_endian;
158 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
160 static void ia64_float_to_chars_bigendian
161 PARAMS ((char *, LITTLENUM_TYPE *, int));
162 static void ia64_float_to_chars_littleendian
163 PARAMS ((char *, LITTLENUM_TYPE *, int));
164 static void (*ia64_float_to_chars)
165 PARAMS ((char *, LITTLENUM_TYPE *, int));
167 static struct hash_control *alias_hash;
168 static struct hash_control *alias_name_hash;
169 static struct hash_control *secalias_hash;
170 static struct hash_control *secalias_name_hash;
172 /* Characters which always start a comment. */
173 const char comment_chars[] = "";
175 /* Characters which start a comment at the beginning of a line. */
176 const char line_comment_chars[] = "#";
178 /* Characters which may be used to separate multiple commands on a
179 single line. */
180 const char line_separator_chars[] = ";";
182 /* Characters which are used to indicate an exponent in a floating
183 point number. */
184 const char EXP_CHARS[] = "eE";
186 /* Characters which mean that a number is a floating point constant,
187 as in 0d1.0. */
188 const char FLT_CHARS[] = "rRsSfFdDxXpP";
190 /* ia64-specific option processing: */
192 const char *md_shortopts = "m:N:x::";
194 struct option md_longopts[] =
196 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
197 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
198 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
199 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
202 size_t md_longopts_size = sizeof (md_longopts);
204 static struct
206 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
207 struct hash_control *reg_hash; /* register name hash table */
208 struct hash_control *dynreg_hash; /* dynamic register hash table */
209 struct hash_control *const_hash; /* constant hash table */
210 struct hash_control *entry_hash; /* code entry hint hash table */
212 symbolS *regsym[REG_NUM];
214 /* If X_op is != O_absent, the registername for the instruction's
215 qualifying predicate. If NULL, p0 is assumed for instructions
216 that are predicatable. */
217 expressionS qp;
219 unsigned int
220 manual_bundling : 1,
221 debug_dv: 1,
222 detect_dv: 1,
223 explicit_mode : 1, /* which mode we're in */
224 default_explicit_mode : 1, /* which mode is the default */
225 mode_explicitly_set : 1, /* was the current mode explicitly set? */
226 auto_align : 1,
227 keep_pending_output : 1;
229 /* Each bundle consists of up to three instructions. We keep
230 track of four most recent instructions so we can correctly set
231 the end_of_insn_group for the last instruction in a bundle. */
232 int curr_slot;
233 int num_slots_in_use;
234 struct slot
236 unsigned int
237 end_of_insn_group : 1,
238 manual_bundling_on : 1,
239 manual_bundling_off : 1;
240 signed char user_template; /* user-selected template, if any */
241 unsigned char qp_regno; /* qualifying predicate */
242 /* This duplicates a good fraction of "struct fix" but we
243 can't use a "struct fix" instead since we can't call
244 fix_new_exp() until we know the address of the instruction. */
245 int num_fixups;
246 struct insn_fix
248 bfd_reloc_code_real_type code;
249 enum ia64_opnd opnd; /* type of operand in need of fix */
250 unsigned int is_pcrel : 1; /* is operand pc-relative? */
251 expressionS expr; /* the value to be inserted */
253 fixup[2]; /* at most two fixups per insn */
254 struct ia64_opcode *idesc;
255 struct label_fix *label_fixups;
256 struct label_fix *tag_fixups;
257 struct unw_rec_list *unwind_record; /* Unwind directive. */
258 expressionS opnd[6];
259 char *src_file;
260 unsigned int src_line;
261 struct dwarf2_line_info debug_line;
263 slot[NUM_SLOTS];
265 segT last_text_seg;
267 struct dynreg
269 struct dynreg *next; /* next dynamic register */
270 const char *name;
271 unsigned short base; /* the base register number */
272 unsigned short num_regs; /* # of registers in this set */
274 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
276 flagword flags; /* ELF-header flags */
278 struct mem_offset {
279 unsigned hint:1; /* is this hint currently valid? */
280 bfd_vma offset; /* mem.offset offset */
281 bfd_vma base; /* mem.offset base */
282 } mem_offset;
284 int path; /* number of alt. entry points seen */
285 const char **entry_labels; /* labels of all alternate paths in
286 the current DV-checking block. */
287 int maxpaths; /* size currently allocated for
288 entry_labels */
289 /* Support for hardware errata workarounds. */
291 /* Record data about the last three insn groups. */
292 struct group
294 /* B-step workaround.
295 For each predicate register, this is set if the corresponding insn
296 group conditionally sets this register with one of the affected
297 instructions. */
298 int p_reg_set[64];
299 /* B-step workaround.
300 For each general register, this is set if the corresponding insn
301 a) is conditional one one of the predicate registers for which
302 P_REG_SET is 1 in the corresponding entry of the previous group,
303 b) sets this general register with one of the affected
304 instructions. */
305 int g_reg_set_conditionally[128];
306 } last_groups[3];
307 int group_idx;
309 int pointer_size; /* size in bytes of a pointer */
310 int pointer_size_shift; /* shift size of a pointer for alignment */
314 /* application registers: */
316 #define AR_K0 0
317 #define AR_K7 7
318 #define AR_RSC 16
319 #define AR_BSP 17
320 #define AR_BSPSTORE 18
321 #define AR_RNAT 19
322 #define AR_UNAT 36
323 #define AR_FPSR 40
324 #define AR_ITC 44
325 #define AR_PFS 64
326 #define AR_LC 65
328 static const struct
330 const char *name;
331 int regnum;
333 ar[] =
335 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
336 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
337 {"ar.rsc", 16}, {"ar.bsp", 17},
338 {"ar.bspstore", 18}, {"ar.rnat", 19},
339 {"ar.fcr", 21}, {"ar.eflag", 24},
340 {"ar.csd", 25}, {"ar.ssd", 26},
341 {"ar.cflg", 27}, {"ar.fsr", 28},
342 {"ar.fir", 29}, {"ar.fdr", 30},
343 {"ar.ccv", 32}, {"ar.unat", 36},
344 {"ar.fpsr", 40}, {"ar.itc", 44},
345 {"ar.pfs", 64}, {"ar.lc", 65},
346 {"ar.ec", 66},
349 #define CR_IPSR 16
350 #define CR_ISR 17
351 #define CR_IIP 19
352 #define CR_IFA 20
353 #define CR_ITIR 21
354 #define CR_IIPA 22
355 #define CR_IFS 23
356 #define CR_IIM 24
357 #define CR_IHA 25
358 #define CR_IVR 65
359 #define CR_TPR 66
360 #define CR_EOI 67
361 #define CR_IRR0 68
362 #define CR_IRR3 71
363 #define CR_LRR0 80
364 #define CR_LRR1 81
366 /* control registers: */
367 static const struct
369 const char *name;
370 int regnum;
372 cr[] =
374 {"cr.dcr", 0},
375 {"cr.itm", 1},
376 {"cr.iva", 2},
377 {"cr.pta", 8},
378 {"cr.gpta", 9},
379 {"cr.ipsr", 16},
380 {"cr.isr", 17},
381 {"cr.iip", 19},
382 {"cr.ifa", 20},
383 {"cr.itir", 21},
384 {"cr.iipa", 22},
385 {"cr.ifs", 23},
386 {"cr.iim", 24},
387 {"cr.iha", 25},
388 {"cr.lid", 64},
389 {"cr.ivr", 65},
390 {"cr.tpr", 66},
391 {"cr.eoi", 67},
392 {"cr.irr0", 68},
393 {"cr.irr1", 69},
394 {"cr.irr2", 70},
395 {"cr.irr3", 71},
396 {"cr.itv", 72},
397 {"cr.pmv", 73},
398 {"cr.cmcv", 74},
399 {"cr.lrr0", 80},
400 {"cr.lrr1", 81}
403 #define PSR_MFL 4
404 #define PSR_IC 13
405 #define PSR_DFL 18
406 #define PSR_CPL 32
408 static const struct const_desc
410 const char *name;
411 valueT value;
413 const_bits[] =
415 /* PSR constant masks: */
417 /* 0: reserved */
418 {"psr.be", ((valueT) 1) << 1},
419 {"psr.up", ((valueT) 1) << 2},
420 {"psr.ac", ((valueT) 1) << 3},
421 {"psr.mfl", ((valueT) 1) << 4},
422 {"psr.mfh", ((valueT) 1) << 5},
423 /* 6-12: reserved */
424 {"psr.ic", ((valueT) 1) << 13},
425 {"psr.i", ((valueT) 1) << 14},
426 {"psr.pk", ((valueT) 1) << 15},
427 /* 16: reserved */
428 {"psr.dt", ((valueT) 1) << 17},
429 {"psr.dfl", ((valueT) 1) << 18},
430 {"psr.dfh", ((valueT) 1) << 19},
431 {"psr.sp", ((valueT) 1) << 20},
432 {"psr.pp", ((valueT) 1) << 21},
433 {"psr.di", ((valueT) 1) << 22},
434 {"psr.si", ((valueT) 1) << 23},
435 {"psr.db", ((valueT) 1) << 24},
436 {"psr.lp", ((valueT) 1) << 25},
437 {"psr.tb", ((valueT) 1) << 26},
438 {"psr.rt", ((valueT) 1) << 27},
439 /* 28-31: reserved */
440 /* 32-33: cpl (current privilege level) */
441 {"psr.is", ((valueT) 1) << 34},
442 {"psr.mc", ((valueT) 1) << 35},
443 {"psr.it", ((valueT) 1) << 36},
444 {"psr.id", ((valueT) 1) << 37},
445 {"psr.da", ((valueT) 1) << 38},
446 {"psr.dd", ((valueT) 1) << 39},
447 {"psr.ss", ((valueT) 1) << 40},
448 /* 41-42: ri (restart instruction) */
449 {"psr.ed", ((valueT) 1) << 43},
450 {"psr.bn", ((valueT) 1) << 44},
453 /* indirect register-sets/memory: */
455 static const struct
457 const char *name;
458 int regnum;
460 indirect_reg[] =
462 { "CPUID", IND_CPUID },
463 { "cpuid", IND_CPUID },
464 { "dbr", IND_DBR },
465 { "dtr", IND_DTR },
466 { "itr", IND_ITR },
467 { "ibr", IND_IBR },
468 { "msr", IND_MSR },
469 { "pkr", IND_PKR },
470 { "pmc", IND_PMC },
471 { "pmd", IND_PMD },
472 { "rr", IND_RR },
475 /* Pseudo functions used to indicate relocation types (these functions
476 start with an at sign (@). */
477 static struct
479 const char *name;
480 enum pseudo_type
482 PSEUDO_FUNC_NONE,
483 PSEUDO_FUNC_RELOC,
484 PSEUDO_FUNC_CONST,
485 PSEUDO_FUNC_REG,
486 PSEUDO_FUNC_FLOAT
488 type;
489 union
491 unsigned long ival;
492 symbolS *sym;
496 pseudo_func[] =
498 /* reloc pseudo functions (these must come first!): */
499 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
500 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
501 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
502 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
503 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
504 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
505 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
506 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
507 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
508 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
509 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
510 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
511 { "", 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
512 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
513 { "", 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
514 { "", 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
515 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
517 /* mbtype4 constants: */
518 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
519 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
520 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
521 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
522 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
524 /* fclass constants: */
525 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
526 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
527 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
528 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
529 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
530 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
531 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
532 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
533 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
535 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
537 /* hint constants: */
538 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
540 /* unwind-related constants: */
541 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
542 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
543 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
544 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
545 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
546 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
547 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
549 /* unwind-related registers: */
550 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
553 /* 41-bit nop opcodes (one per unit): */
554 static const bfd_vma nop[IA64_NUM_UNITS] =
556 0x0000000000LL, /* NIL => break 0 */
557 0x0008000000LL, /* I-unit nop */
558 0x0008000000LL, /* M-unit nop */
559 0x4000000000LL, /* B-unit nop */
560 0x0008000000LL, /* F-unit nop */
561 0x0008000000LL, /* L-"unit" nop */
562 0x0008000000LL, /* X-unit nop */
565 /* Can't be `const' as it's passed to input routines (which have the
566 habit of setting temporary sentinels. */
567 static char special_section_name[][20] =
569 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
570 {".IA_64.unwind"}, {".IA_64.unwind_info"},
571 {".init_array"}, {".fini_array"}
574 /* The best template for a particular sequence of up to three
575 instructions: */
576 #define N IA64_NUM_TYPES
577 static unsigned char best_template[N][N][N];
578 #undef N
580 /* Resource dependencies currently in effect */
581 static struct rsrc {
582 int depind; /* dependency index */
583 const struct ia64_dependency *dependency; /* actual dependency */
584 unsigned specific:1, /* is this a specific bit/regno? */
585 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
586 int index; /* specific regno/bit within dependency */
587 int note; /* optional qualifying note (0 if none) */
588 #define STATE_NONE 0
589 #define STATE_STOP 1
590 #define STATE_SRLZ 2
591 int insn_srlz; /* current insn serialization state */
592 int data_srlz; /* current data serialization state */
593 int qp_regno; /* qualifying predicate for this usage */
594 char *file; /* what file marked this dependency */
595 unsigned int line; /* what line marked this dependency */
596 struct mem_offset mem_offset; /* optional memory offset hint */
597 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
598 int path; /* corresponding code entry index */
599 } *regdeps = NULL;
600 static int regdepslen = 0;
601 static int regdepstotlen = 0;
602 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
603 static const char *dv_sem[] = { "none", "implied", "impliedf",
604 "data", "instr", "specific", "stop", "other" };
605 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
607 /* Current state of PR mutexation */
608 static struct qpmutex {
609 valueT prmask;
610 int path;
611 } *qp_mutexes = NULL; /* QP mutex bitmasks */
612 static int qp_mutexeslen = 0;
613 static int qp_mutexestotlen = 0;
614 static valueT qp_safe_across_calls = 0;
616 /* Current state of PR implications */
617 static struct qp_imply {
618 unsigned p1:6;
619 unsigned p2:6;
620 unsigned p2_branched:1;
621 int path;
622 } *qp_implies = NULL;
623 static int qp_implieslen = 0;
624 static int qp_impliestotlen = 0;
626 /* Keep track of static GR values so that indirect register usage can
627 sometimes be tracked. */
628 static struct gr {
629 unsigned known:1;
630 int path;
631 valueT value;
632 } gr_values[128] = {{ 1, 0, 0 }};
634 /* Remember the alignment frag. */
635 static fragS *align_frag;
637 /* These are the routines required to output the various types of
638 unwind records. */
640 /* A slot_number is a frag address plus the slot index (0-2). We use the
641 frag address here so that if there is a section switch in the middle of
642 a function, then instructions emitted to a different section are not
643 counted. Since there may be more than one frag for a function, this
644 means we also need to keep track of which frag this address belongs to
645 so we can compute inter-frag distances. This also nicely solves the
646 problem with nops emitted for align directives, which can't easily be
647 counted, but can easily be derived from frag sizes. */
649 typedef struct unw_rec_list {
650 unwind_record r;
651 unsigned long slot_number;
652 fragS *slot_frag;
653 unsigned long next_slot_number;
654 fragS *next_slot_frag;
655 struct unw_rec_list *next;
656 } unw_rec_list;
658 #define SLOT_NUM_NOT_SET (unsigned)-1
660 /* Linked list of saved prologue counts. A very poor
661 implementation of a map from label numbers to prologue counts. */
662 typedef struct label_prologue_count
664 struct label_prologue_count *next;
665 unsigned long label_number;
666 unsigned int prologue_count;
667 } label_prologue_count;
669 static struct
671 /* Maintain a list of unwind entries for the current function. */
672 unw_rec_list *list;
673 unw_rec_list *tail;
675 /* Any unwind entires that should be attached to the current slot
676 that an insn is being constructed for. */
677 unw_rec_list *current_entry;
679 /* These are used to create the unwind table entry for this function. */
680 symbolS *proc_start;
681 symbolS *proc_end;
682 symbolS *info; /* pointer to unwind info */
683 symbolS *personality_routine;
684 segT saved_text_seg;
685 subsegT saved_text_subseg;
686 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
688 /* TRUE if processing unwind directives in a prologue region. */
689 int prologue;
690 int prologue_mask;
691 unsigned int prologue_count; /* number of .prologues seen so far */
692 /* Prologue counts at previous .label_state directives. */
693 struct label_prologue_count * saved_prologue_counts;
694 } unwind;
696 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
698 /* Forward declarations: */
699 static int ar_is_in_integer_unit PARAMS ((int regnum));
700 static void set_section PARAMS ((char *name));
701 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
702 unsigned int, unsigned int));
703 static void dot_align (int);
704 static void dot_radix PARAMS ((int));
705 static void dot_special_section PARAMS ((int));
706 static void dot_proc PARAMS ((int));
707 static void dot_fframe PARAMS ((int));
708 static void dot_vframe PARAMS ((int));
709 static void dot_vframesp PARAMS ((int));
710 static void dot_vframepsp PARAMS ((int));
711 static void dot_save PARAMS ((int));
712 static void dot_restore PARAMS ((int));
713 static void dot_restorereg PARAMS ((int));
714 static void dot_restorereg_p PARAMS ((int));
715 static void dot_handlerdata PARAMS ((int));
716 static void dot_unwentry PARAMS ((int));
717 static void dot_altrp PARAMS ((int));
718 static void dot_savemem PARAMS ((int));
719 static void dot_saveg PARAMS ((int));
720 static void dot_savef PARAMS ((int));
721 static void dot_saveb PARAMS ((int));
722 static void dot_savegf PARAMS ((int));
723 static void dot_spill PARAMS ((int));
724 static void dot_spillreg PARAMS ((int));
725 static void dot_spillmem PARAMS ((int));
726 static void dot_spillreg_p PARAMS ((int));
727 static void dot_spillmem_p PARAMS ((int));
728 static void dot_label_state PARAMS ((int));
729 static void dot_copy_state PARAMS ((int));
730 static void dot_unwabi PARAMS ((int));
731 static void dot_personality PARAMS ((int));
732 static void dot_body PARAMS ((int));
733 static void dot_prologue PARAMS ((int));
734 static void dot_endp PARAMS ((int));
735 static void dot_template PARAMS ((int));
736 static void dot_regstk PARAMS ((int));
737 static void dot_rot PARAMS ((int));
738 static void dot_byteorder PARAMS ((int));
739 static void dot_psr PARAMS ((int));
740 static void dot_alias PARAMS ((int));
741 static void dot_ln PARAMS ((int));
742 static char *parse_section_name PARAMS ((void));
743 static void dot_xdata PARAMS ((int));
744 static void stmt_float_cons PARAMS ((int));
745 static void stmt_cons_ua PARAMS ((int));
746 static void dot_xfloat_cons PARAMS ((int));
747 static void dot_xstringer PARAMS ((int));
748 static void dot_xdata_ua PARAMS ((int));
749 static void dot_xfloat_cons_ua PARAMS ((int));
750 static void print_prmask PARAMS ((valueT mask));
751 static void dot_pred_rel PARAMS ((int));
752 static void dot_reg_val PARAMS ((int));
753 static void dot_serialize PARAMS ((int));
754 static void dot_dv_mode PARAMS ((int));
755 static void dot_entry PARAMS ((int));
756 static void dot_mem_offset PARAMS ((int));
757 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
758 static symbolS *declare_register PARAMS ((const char *name, int regnum));
759 static void declare_register_set PARAMS ((const char *, int, int));
760 static unsigned int operand_width PARAMS ((enum ia64_opnd));
761 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
762 int index,
763 expressionS *e));
764 static int parse_operand PARAMS ((expressionS *e));
765 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
766 static int errata_nop_necessary_p PARAMS ((struct slot *, enum ia64_unit));
767 static void build_insn PARAMS ((struct slot *, bfd_vma *));
768 static void emit_one_bundle PARAMS ((void));
769 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
770 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
771 bfd_reloc_code_real_type r_type));
772 static void insn_group_break PARAMS ((int, int, int));
773 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
774 struct rsrc *, int depind, int path));
775 static void add_qp_mutex PARAMS((valueT mask));
776 static void add_qp_imply PARAMS((int p1, int p2));
777 static void clear_qp_branch_flag PARAMS((valueT mask));
778 static void clear_qp_mutex PARAMS((valueT mask));
779 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
780 static int has_suffix_p PARAMS((const char *, const char *));
781 static void clear_register_values PARAMS ((void));
782 static void print_dependency PARAMS ((const char *action, int depind));
783 static void instruction_serialization PARAMS ((void));
784 static void data_serialization PARAMS ((void));
785 static void remove_marked_resource PARAMS ((struct rsrc *));
786 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
787 static int is_taken_branch PARAMS ((struct ia64_opcode *));
788 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
789 static int depends_on PARAMS ((int, struct ia64_opcode *));
790 static int specify_resource PARAMS ((const struct ia64_dependency *,
791 struct ia64_opcode *, int, struct rsrc [], int, int));
792 static int check_dv PARAMS((struct ia64_opcode *idesc));
793 static void check_dependencies PARAMS((struct ia64_opcode *));
794 static void mark_resources PARAMS((struct ia64_opcode *));
795 static void update_dependencies PARAMS((struct ia64_opcode *));
796 static void note_register_values PARAMS((struct ia64_opcode *));
797 static int qp_mutex PARAMS ((int, int, int));
798 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
799 static void output_vbyte_mem PARAMS ((int, char *, char *));
800 static void count_output PARAMS ((int, char *, char *));
801 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
802 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
803 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
804 static void output_P1_format PARAMS ((vbyte_func, int));
805 static void output_P2_format PARAMS ((vbyte_func, int, int));
806 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
807 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
808 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
809 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
810 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
811 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
812 static void output_P9_format PARAMS ((vbyte_func, int, int));
813 static void output_P10_format PARAMS ((vbyte_func, int, int));
814 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
815 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
816 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
817 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
818 static char format_ab_reg PARAMS ((int, int));
819 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
820 unsigned long));
821 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
822 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
823 unsigned long));
824 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
825 static unw_rec_list *output_endp PARAMS ((void));
826 static unw_rec_list *output_prologue PARAMS ((void));
827 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
828 static unw_rec_list *output_body PARAMS ((void));
829 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
830 static unw_rec_list *output_mem_stack_v PARAMS ((void));
831 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
832 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
833 static unw_rec_list *output_rp_when PARAMS ((void));
834 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
835 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
836 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
837 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
838 static unw_rec_list *output_pfs_when PARAMS ((void));
839 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
840 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
841 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
842 static unw_rec_list *output_preds_when PARAMS ((void));
843 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
844 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
845 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
846 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
847 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
848 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
849 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
850 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
851 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
852 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
853 static unw_rec_list *output_unat_when PARAMS ((void));
854 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
855 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
856 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
857 static unw_rec_list *output_lc_when PARAMS ((void));
858 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
859 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
860 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
861 static unw_rec_list *output_fpsr_when PARAMS ((void));
862 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
863 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
864 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
865 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
866 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
867 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
868 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
869 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
870 static unw_rec_list *output_bsp_when PARAMS ((void));
871 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
872 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
873 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
874 static unw_rec_list *output_bspstore_when PARAMS ((void));
875 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
876 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
877 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
878 static unw_rec_list *output_rnat_when PARAMS ((void));
879 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
880 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
881 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
882 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
883 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
884 static unw_rec_list *output_label_state PARAMS ((unsigned long));
885 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
886 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
887 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
888 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
889 unsigned int));
890 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
891 unsigned int));
892 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
893 unsigned int));
894 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
895 unsigned int, unsigned int));
896 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
897 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
898 static int calc_record_size PARAMS ((unw_rec_list *));
899 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
900 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
901 unsigned long, fragS *,
902 int));
903 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
904 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
905 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
906 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
907 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
908 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
909 static void free_saved_prologue_counts PARAMS ((void));
911 /* Determine if application register REGNUM resides in the integer
912 unit (as opposed to the memory unit). */
913 static int
914 ar_is_in_integer_unit (reg)
915 int reg;
917 reg -= REG_AR;
919 return (reg == 64 /* pfs */
920 || reg == 65 /* lc */
921 || reg == 66 /* ec */
922 /* ??? ias accepts and puts these in the integer unit. */
923 || (reg >= 112 && reg <= 127));
926 /* Switch to section NAME and create section if necessary. It's
927 rather ugly that we have to manipulate input_line_pointer but I
928 don't see any other way to accomplish the same thing without
929 changing obj-elf.c (which may be the Right Thing, in the end). */
930 static void
931 set_section (name)
932 char *name;
934 char *saved_input_line_pointer;
936 saved_input_line_pointer = input_line_pointer;
937 input_line_pointer = name;
938 obj_elf_section (0);
939 input_line_pointer = saved_input_line_pointer;
942 /* Map 's' to SHF_IA_64_SHORT. */
945 ia64_elf_section_letter (letter, ptr_msg)
946 int letter;
947 char **ptr_msg;
949 if (letter == 's')
950 return SHF_IA_64_SHORT;
951 else if (letter == 'o')
952 return SHF_LINK_ORDER;
954 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
955 return -1;
958 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
960 flagword
961 ia64_elf_section_flags (flags, attr, type)
962 flagword flags;
963 int attr, type ATTRIBUTE_UNUSED;
965 if (attr & SHF_IA_64_SHORT)
966 flags |= SEC_SMALL_DATA;
967 return flags;
971 ia64_elf_section_type (str, len)
972 const char *str;
973 size_t len;
975 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
977 if (STREQ (ELF_STRING_ia64_unwind_info))
978 return SHT_PROGBITS;
980 if (STREQ (ELF_STRING_ia64_unwind_info_once))
981 return SHT_PROGBITS;
983 if (STREQ (ELF_STRING_ia64_unwind))
984 return SHT_IA_64_UNWIND;
986 if (STREQ (ELF_STRING_ia64_unwind_once))
987 return SHT_IA_64_UNWIND;
989 if (STREQ ("unwind"))
990 return SHT_IA_64_UNWIND;
992 if (STREQ ("init_array"))
993 return SHT_INIT_ARRAY;
995 if (STREQ ("fini_array"))
996 return SHT_FINI_ARRAY;
998 return -1;
999 #undef STREQ
1002 static unsigned int
1003 set_regstack (ins, locs, outs, rots)
1004 unsigned int ins, locs, outs, rots;
1006 /* Size of frame. */
1007 unsigned int sof;
1009 sof = ins + locs + outs;
1010 if (sof > 96)
1012 as_bad ("Size of frame exceeds maximum of 96 registers");
1013 return 0;
1015 if (rots > sof)
1017 as_warn ("Size of rotating registers exceeds frame size");
1018 return 0;
1020 md.in.base = REG_GR + 32;
1021 md.loc.base = md.in.base + ins;
1022 md.out.base = md.loc.base + locs;
1024 md.in.num_regs = ins;
1025 md.loc.num_regs = locs;
1026 md.out.num_regs = outs;
1027 md.rot.num_regs = rots;
1028 return sof;
1031 void
1032 ia64_flush_insns ()
1034 struct label_fix *lfix;
1035 segT saved_seg;
1036 subsegT saved_subseg;
1037 unw_rec_list *ptr;
1039 if (!md.last_text_seg)
1040 return;
1042 saved_seg = now_seg;
1043 saved_subseg = now_subseg;
1045 subseg_set (md.last_text_seg, 0);
1047 while (md.num_slots_in_use > 0)
1048 emit_one_bundle (); /* force out queued instructions */
1050 /* In case there are labels following the last instruction, resolve
1051 those now: */
1052 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1054 S_SET_VALUE (lfix->sym, frag_now_fix ());
1055 symbol_set_frag (lfix->sym, frag_now);
1057 CURR_SLOT.label_fixups = 0;
1058 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1060 S_SET_VALUE (lfix->sym, frag_now_fix ());
1061 symbol_set_frag (lfix->sym, frag_now);
1063 CURR_SLOT.tag_fixups = 0;
1065 /* In case there are unwind directives following the last instruction,
1066 resolve those now. We only handle prologue, body, and endp directives
1067 here. Give an error for others. */
1068 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1070 switch (ptr->r.type)
1072 case prologue:
1073 case prologue_gr:
1074 case body:
1075 case endp:
1076 ptr->slot_number = (unsigned long) frag_more (0);
1077 ptr->slot_frag = frag_now;
1078 break;
1080 /* Allow any record which doesn't have a "t" field (i.e.,
1081 doesn't relate to a particular instruction). */
1082 case unwabi:
1083 case br_gr:
1084 case copy_state:
1085 case fr_mem:
1086 case frgr_mem:
1087 case gr_gr:
1088 case gr_mem:
1089 case label_state:
1090 case rp_br:
1091 case spill_base:
1092 case spill_mask:
1093 /* nothing */
1094 break;
1096 default:
1097 as_bad (_("Unwind directive not followed by an instruction."));
1098 break;
1101 unwind.current_entry = NULL;
1103 subseg_set (saved_seg, saved_subseg);
1105 if (md.qp.X_op == O_register)
1106 as_bad ("qualifying predicate not followed by instruction");
1109 static void
1110 ia64_do_align (int nbytes)
1112 char *saved_input_line_pointer = input_line_pointer;
1114 input_line_pointer = "";
1115 s_align_bytes (nbytes);
1116 input_line_pointer = saved_input_line_pointer;
1119 void
1120 ia64_cons_align (nbytes)
1121 int nbytes;
1123 if (md.auto_align)
1125 char *saved_input_line_pointer = input_line_pointer;
1126 input_line_pointer = "";
1127 s_align_bytes (nbytes);
1128 input_line_pointer = saved_input_line_pointer;
1132 /* Output COUNT bytes to a memory location. */
1133 static unsigned char *vbyte_mem_ptr = NULL;
1135 void
1136 output_vbyte_mem (count, ptr, comment)
1137 int count;
1138 char *ptr;
1139 char *comment ATTRIBUTE_UNUSED;
1141 int x;
1142 if (vbyte_mem_ptr == NULL)
1143 abort ();
1145 if (count == 0)
1146 return;
1147 for (x = 0; x < count; x++)
1148 *(vbyte_mem_ptr++) = ptr[x];
1151 /* Count the number of bytes required for records. */
1152 static int vbyte_count = 0;
1153 void
1154 count_output (count, ptr, comment)
1155 int count;
1156 char *ptr ATTRIBUTE_UNUSED;
1157 char *comment ATTRIBUTE_UNUSED;
1159 vbyte_count += count;
1162 static void
1163 output_R1_format (f, rtype, rlen)
1164 vbyte_func f;
1165 unw_record_type rtype;
1166 int rlen;
1168 int r = 0;
1169 char byte;
1170 if (rlen > 0x1f)
1172 output_R3_format (f, rtype, rlen);
1173 return;
1176 if (rtype == body)
1177 r = 1;
1178 else if (rtype != prologue)
1179 as_bad ("record type is not valid");
1181 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1182 (*f) (1, &byte, NULL);
1185 static void
1186 output_R2_format (f, mask, grsave, rlen)
1187 vbyte_func f;
1188 int mask, grsave;
1189 unsigned long rlen;
1191 char bytes[20];
1192 int count = 2;
1193 mask = (mask & 0x0f);
1194 grsave = (grsave & 0x7f);
1196 bytes[0] = (UNW_R2 | (mask >> 1));
1197 bytes[1] = (((mask & 0x01) << 7) | grsave);
1198 count += output_leb128 (bytes + 2, rlen, 0);
1199 (*f) (count, bytes, NULL);
1202 static void
1203 output_R3_format (f, rtype, rlen)
1204 vbyte_func f;
1205 unw_record_type rtype;
1206 unsigned long rlen;
1208 int r = 0, count;
1209 char bytes[20];
1210 if (rlen <= 0x1f)
1212 output_R1_format (f, rtype, rlen);
1213 return;
1216 if (rtype == body)
1217 r = 1;
1218 else if (rtype != prologue)
1219 as_bad ("record type is not valid");
1220 bytes[0] = (UNW_R3 | r);
1221 count = output_leb128 (bytes + 1, rlen, 0);
1222 (*f) (count + 1, bytes, NULL);
1225 static void
1226 output_P1_format (f, brmask)
1227 vbyte_func f;
1228 int brmask;
1230 char byte;
1231 byte = UNW_P1 | (brmask & 0x1f);
1232 (*f) (1, &byte, NULL);
1235 static void
1236 output_P2_format (f, brmask, gr)
1237 vbyte_func f;
1238 int brmask;
1239 int gr;
1241 char bytes[2];
1242 brmask = (brmask & 0x1f);
1243 bytes[0] = UNW_P2 | (brmask >> 1);
1244 bytes[1] = (((brmask & 1) << 7) | gr);
1245 (*f) (2, bytes, NULL);
1248 static void
1249 output_P3_format (f, rtype, reg)
1250 vbyte_func f;
1251 unw_record_type rtype;
1252 int reg;
1254 char bytes[2];
1255 int r = 0;
1256 reg = (reg & 0x7f);
1257 switch (rtype)
1259 case psp_gr:
1260 r = 0;
1261 break;
1262 case rp_gr:
1263 r = 1;
1264 break;
1265 case pfs_gr:
1266 r = 2;
1267 break;
1268 case preds_gr:
1269 r = 3;
1270 break;
1271 case unat_gr:
1272 r = 4;
1273 break;
1274 case lc_gr:
1275 r = 5;
1276 break;
1277 case rp_br:
1278 r = 6;
1279 break;
1280 case rnat_gr:
1281 r = 7;
1282 break;
1283 case bsp_gr:
1284 r = 8;
1285 break;
1286 case bspstore_gr:
1287 r = 9;
1288 break;
1289 case fpsr_gr:
1290 r = 10;
1291 break;
1292 case priunat_gr:
1293 r = 11;
1294 break;
1295 default:
1296 as_bad ("Invalid record type for P3 format.");
1298 bytes[0] = (UNW_P3 | (r >> 1));
1299 bytes[1] = (((r & 1) << 7) | reg);
1300 (*f) (2, bytes, NULL);
1303 static void
1304 output_P4_format (f, imask, imask_size)
1305 vbyte_func f;
1306 unsigned char *imask;
1307 unsigned long imask_size;
1309 imask[0] = UNW_P4;
1310 (*f) (imask_size, imask, NULL);
1313 static void
1314 output_P5_format (f, grmask, frmask)
1315 vbyte_func f;
1316 int grmask;
1317 unsigned long frmask;
1319 char bytes[4];
1320 grmask = (grmask & 0x0f);
1322 bytes[0] = UNW_P5;
1323 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1324 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1325 bytes[3] = (frmask & 0x000000ff);
1326 (*f) (4, bytes, NULL);
1329 static void
1330 output_P6_format (f, rtype, rmask)
1331 vbyte_func f;
1332 unw_record_type rtype;
1333 int rmask;
1335 char byte;
1336 int r = 0;
1338 if (rtype == gr_mem)
1339 r = 1;
1340 else if (rtype != fr_mem)
1341 as_bad ("Invalid record type for format P6");
1342 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1343 (*f) (1, &byte, NULL);
1346 static void
1347 output_P7_format (f, rtype, w1, w2)
1348 vbyte_func f;
1349 unw_record_type rtype;
1350 unsigned long w1;
1351 unsigned long w2;
1353 char bytes[20];
1354 int count = 1;
1355 int r = 0;
1356 count += output_leb128 (bytes + 1, w1, 0);
1357 switch (rtype)
1359 case mem_stack_f:
1360 r = 0;
1361 count += output_leb128 (bytes + count, w2 >> 4, 0);
1362 break;
1363 case mem_stack_v:
1364 r = 1;
1365 break;
1366 case spill_base:
1367 r = 2;
1368 break;
1369 case psp_sprel:
1370 r = 3;
1371 break;
1372 case rp_when:
1373 r = 4;
1374 break;
1375 case rp_psprel:
1376 r = 5;
1377 break;
1378 case pfs_when:
1379 r = 6;
1380 break;
1381 case pfs_psprel:
1382 r = 7;
1383 break;
1384 case preds_when:
1385 r = 8;
1386 break;
1387 case preds_psprel:
1388 r = 9;
1389 break;
1390 case lc_when:
1391 r = 10;
1392 break;
1393 case lc_psprel:
1394 r = 11;
1395 break;
1396 case unat_when:
1397 r = 12;
1398 break;
1399 case unat_psprel:
1400 r = 13;
1401 break;
1402 case fpsr_when:
1403 r = 14;
1404 break;
1405 case fpsr_psprel:
1406 r = 15;
1407 break;
1408 default:
1409 break;
1411 bytes[0] = (UNW_P7 | r);
1412 (*f) (count, bytes, NULL);
1415 static void
1416 output_P8_format (f, rtype, t)
1417 vbyte_func f;
1418 unw_record_type rtype;
1419 unsigned long t;
1421 char bytes[20];
1422 int r = 0;
1423 int count = 2;
1424 bytes[0] = UNW_P8;
1425 switch (rtype)
1427 case rp_sprel:
1428 r = 1;
1429 break;
1430 case pfs_sprel:
1431 r = 2;
1432 break;
1433 case preds_sprel:
1434 r = 3;
1435 break;
1436 case lc_sprel:
1437 r = 4;
1438 break;
1439 case unat_sprel:
1440 r = 5;
1441 break;
1442 case fpsr_sprel:
1443 r = 6;
1444 break;
1445 case bsp_when:
1446 r = 7;
1447 break;
1448 case bsp_psprel:
1449 r = 8;
1450 break;
1451 case bsp_sprel:
1452 r = 9;
1453 break;
1454 case bspstore_when:
1455 r = 10;
1456 break;
1457 case bspstore_psprel:
1458 r = 11;
1459 break;
1460 case bspstore_sprel:
1461 r = 12;
1462 break;
1463 case rnat_when:
1464 r = 13;
1465 break;
1466 case rnat_psprel:
1467 r = 14;
1468 break;
1469 case rnat_sprel:
1470 r = 15;
1471 break;
1472 case priunat_when_gr:
1473 r = 16;
1474 break;
1475 case priunat_psprel:
1476 r = 17;
1477 break;
1478 case priunat_sprel:
1479 r = 18;
1480 break;
1481 case priunat_when_mem:
1482 r = 19;
1483 break;
1484 default:
1485 break;
1487 bytes[1] = r;
1488 count += output_leb128 (bytes + 2, t, 0);
1489 (*f) (count, bytes, NULL);
1492 static void
1493 output_P9_format (f, grmask, gr)
1494 vbyte_func f;
1495 int grmask;
1496 int gr;
1498 char bytes[3];
1499 bytes[0] = UNW_P9;
1500 bytes[1] = (grmask & 0x0f);
1501 bytes[2] = (gr & 0x7f);
1502 (*f) (3, bytes, NULL);
1505 static void
1506 output_P10_format (f, abi, context)
1507 vbyte_func f;
1508 int abi;
1509 int context;
1511 char bytes[3];
1512 bytes[0] = UNW_P10;
1513 bytes[1] = (abi & 0xff);
1514 bytes[2] = (context & 0xff);
1515 (*f) (3, bytes, NULL);
1518 static void
1519 output_B1_format (f, rtype, label)
1520 vbyte_func f;
1521 unw_record_type rtype;
1522 unsigned long label;
1524 char byte;
1525 int r = 0;
1526 if (label > 0x1f)
1528 output_B4_format (f, rtype, label);
1529 return;
1531 if (rtype == copy_state)
1532 r = 1;
1533 else if (rtype != label_state)
1534 as_bad ("Invalid record type for format B1");
1536 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1537 (*f) (1, &byte, NULL);
1540 static void
1541 output_B2_format (f, ecount, t)
1542 vbyte_func f;
1543 unsigned long ecount;
1544 unsigned long t;
1546 char bytes[20];
1547 int count = 1;
1548 if (ecount > 0x1f)
1550 output_B3_format (f, ecount, t);
1551 return;
1553 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1554 count += output_leb128 (bytes + 1, t, 0);
1555 (*f) (count, bytes, NULL);
1558 static void
1559 output_B3_format (f, ecount, t)
1560 vbyte_func f;
1561 unsigned long ecount;
1562 unsigned long t;
1564 char bytes[20];
1565 int count = 1;
1566 if (ecount <= 0x1f)
1568 output_B2_format (f, ecount, t);
1569 return;
1571 bytes[0] = UNW_B3;
1572 count += output_leb128 (bytes + 1, t, 0);
1573 count += output_leb128 (bytes + count, ecount, 0);
1574 (*f) (count, bytes, NULL);
1577 static void
1578 output_B4_format (f, rtype, label)
1579 vbyte_func f;
1580 unw_record_type rtype;
1581 unsigned long label;
1583 char bytes[20];
1584 int r = 0;
1585 int count = 1;
1586 if (label <= 0x1f)
1588 output_B1_format (f, rtype, label);
1589 return;
1592 if (rtype == copy_state)
1593 r = 1;
1594 else if (rtype != label_state)
1595 as_bad ("Invalid record type for format B1");
1597 bytes[0] = (UNW_B4 | (r << 3));
1598 count += output_leb128 (bytes + 1, label, 0);
1599 (*f) (count, bytes, NULL);
1602 static char
1603 format_ab_reg (ab, reg)
1604 int ab;
1605 int reg;
1607 int ret;
1608 ab = (ab & 3);
1609 reg = (reg & 0x1f);
1610 ret = (ab << 5) | reg;
1611 return ret;
1614 static void
1615 output_X1_format (f, rtype, ab, reg, t, w1)
1616 vbyte_func f;
1617 unw_record_type rtype;
1618 int ab, reg;
1619 unsigned long t;
1620 unsigned long w1;
1622 char bytes[20];
1623 int r = 0;
1624 int count = 2;
1625 bytes[0] = UNW_X1;
1627 if (rtype == spill_sprel)
1628 r = 1;
1629 else if (rtype != spill_psprel)
1630 as_bad ("Invalid record type for format X1");
1631 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1632 count += output_leb128 (bytes + 2, t, 0);
1633 count += output_leb128 (bytes + count, w1, 0);
1634 (*f) (count, bytes, NULL);
1637 static void
1638 output_X2_format (f, ab, reg, x, y, treg, t)
1639 vbyte_func f;
1640 int ab, reg;
1641 int x, y, treg;
1642 unsigned long t;
1644 char bytes[20];
1645 int count = 3;
1646 bytes[0] = UNW_X2;
1647 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1648 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1649 count += output_leb128 (bytes + 3, t, 0);
1650 (*f) (count, bytes, NULL);
1653 static void
1654 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1655 vbyte_func f;
1656 unw_record_type rtype;
1657 int qp;
1658 int ab, reg;
1659 unsigned long t;
1660 unsigned long w1;
1662 char bytes[20];
1663 int r = 0;
1664 int count = 3;
1665 bytes[0] = UNW_X3;
1667 if (rtype == spill_sprel_p)
1668 r = 1;
1669 else if (rtype != spill_psprel_p)
1670 as_bad ("Invalid record type for format X3");
1671 bytes[1] = ((r << 7) | (qp & 0x3f));
1672 bytes[2] = format_ab_reg (ab, reg);
1673 count += output_leb128 (bytes + 3, t, 0);
1674 count += output_leb128 (bytes + count, w1, 0);
1675 (*f) (count, bytes, NULL);
1678 static void
1679 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1680 vbyte_func f;
1681 int qp;
1682 int ab, reg;
1683 int x, y, treg;
1684 unsigned long t;
1686 char bytes[20];
1687 int count = 4;
1688 bytes[0] = UNW_X4;
1689 bytes[1] = (qp & 0x3f);
1690 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1691 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1692 count += output_leb128 (bytes + 4, t, 0);
1693 (*f) (count, bytes, NULL);
1696 /* This function allocates a record list structure, and initializes fields. */
1698 static unw_rec_list *
1699 alloc_record (unw_record_type t)
1701 unw_rec_list *ptr;
1702 ptr = xmalloc (sizeof (*ptr));
1703 ptr->next = NULL;
1704 ptr->slot_number = SLOT_NUM_NOT_SET;
1705 ptr->r.type = t;
1706 ptr->next_slot_number = 0;
1707 ptr->next_slot_frag = 0;
1708 return ptr;
1711 /* Dummy unwind record used for calculating the length of the last prologue or
1712 body region. */
1714 static unw_rec_list *
1715 output_endp ()
1717 unw_rec_list *ptr = alloc_record (endp);
1718 return ptr;
1721 static unw_rec_list *
1722 output_prologue ()
1724 unw_rec_list *ptr = alloc_record (prologue);
1725 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1726 return ptr;
1729 static unw_rec_list *
1730 output_prologue_gr (saved_mask, reg)
1731 unsigned int saved_mask;
1732 unsigned int reg;
1734 unw_rec_list *ptr = alloc_record (prologue_gr);
1735 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1736 ptr->r.record.r.grmask = saved_mask;
1737 ptr->r.record.r.grsave = reg;
1738 return ptr;
1741 static unw_rec_list *
1742 output_body ()
1744 unw_rec_list *ptr = alloc_record (body);
1745 return ptr;
1748 static unw_rec_list *
1749 output_mem_stack_f (size)
1750 unsigned int size;
1752 unw_rec_list *ptr = alloc_record (mem_stack_f);
1753 ptr->r.record.p.size = size;
1754 return ptr;
1757 static unw_rec_list *
1758 output_mem_stack_v ()
1760 unw_rec_list *ptr = alloc_record (mem_stack_v);
1761 return ptr;
1764 static unw_rec_list *
1765 output_psp_gr (gr)
1766 unsigned int gr;
1768 unw_rec_list *ptr = alloc_record (psp_gr);
1769 ptr->r.record.p.gr = gr;
1770 return ptr;
1773 static unw_rec_list *
1774 output_psp_sprel (offset)
1775 unsigned int offset;
1777 unw_rec_list *ptr = alloc_record (psp_sprel);
1778 ptr->r.record.p.spoff = offset / 4;
1779 return ptr;
1782 static unw_rec_list *
1783 output_rp_when ()
1785 unw_rec_list *ptr = alloc_record (rp_when);
1786 return ptr;
1789 static unw_rec_list *
1790 output_rp_gr (gr)
1791 unsigned int gr;
1793 unw_rec_list *ptr = alloc_record (rp_gr);
1794 ptr->r.record.p.gr = gr;
1795 return ptr;
1798 static unw_rec_list *
1799 output_rp_br (br)
1800 unsigned int br;
1802 unw_rec_list *ptr = alloc_record (rp_br);
1803 ptr->r.record.p.br = br;
1804 return ptr;
1807 static unw_rec_list *
1808 output_rp_psprel (offset)
1809 unsigned int offset;
1811 unw_rec_list *ptr = alloc_record (rp_psprel);
1812 ptr->r.record.p.pspoff = offset / 4;
1813 return ptr;
1816 static unw_rec_list *
1817 output_rp_sprel (offset)
1818 unsigned int offset;
1820 unw_rec_list *ptr = alloc_record (rp_sprel);
1821 ptr->r.record.p.spoff = offset / 4;
1822 return ptr;
1825 static unw_rec_list *
1826 output_pfs_when ()
1828 unw_rec_list *ptr = alloc_record (pfs_when);
1829 return ptr;
1832 static unw_rec_list *
1833 output_pfs_gr (gr)
1834 unsigned int gr;
1836 unw_rec_list *ptr = alloc_record (pfs_gr);
1837 ptr->r.record.p.gr = gr;
1838 return ptr;
1841 static unw_rec_list *
1842 output_pfs_psprel (offset)
1843 unsigned int offset;
1845 unw_rec_list *ptr = alloc_record (pfs_psprel);
1846 ptr->r.record.p.pspoff = offset / 4;
1847 return ptr;
1850 static unw_rec_list *
1851 output_pfs_sprel (offset)
1852 unsigned int offset;
1854 unw_rec_list *ptr = alloc_record (pfs_sprel);
1855 ptr->r.record.p.spoff = offset / 4;
1856 return ptr;
1859 static unw_rec_list *
1860 output_preds_when ()
1862 unw_rec_list *ptr = alloc_record (preds_when);
1863 return ptr;
1866 static unw_rec_list *
1867 output_preds_gr (gr)
1868 unsigned int gr;
1870 unw_rec_list *ptr = alloc_record (preds_gr);
1871 ptr->r.record.p.gr = gr;
1872 return ptr;
1875 static unw_rec_list *
1876 output_preds_psprel (offset)
1877 unsigned int offset;
1879 unw_rec_list *ptr = alloc_record (preds_psprel);
1880 ptr->r.record.p.pspoff = offset / 4;
1881 return ptr;
1884 static unw_rec_list *
1885 output_preds_sprel (offset)
1886 unsigned int offset;
1888 unw_rec_list *ptr = alloc_record (preds_sprel);
1889 ptr->r.record.p.spoff = offset / 4;
1890 return ptr;
1893 static unw_rec_list *
1894 output_fr_mem (mask)
1895 unsigned int mask;
1897 unw_rec_list *ptr = alloc_record (fr_mem);
1898 ptr->r.record.p.rmask = mask;
1899 return ptr;
1902 static unw_rec_list *
1903 output_frgr_mem (gr_mask, fr_mask)
1904 unsigned int gr_mask;
1905 unsigned int fr_mask;
1907 unw_rec_list *ptr = alloc_record (frgr_mem);
1908 ptr->r.record.p.grmask = gr_mask;
1909 ptr->r.record.p.frmask = fr_mask;
1910 return ptr;
1913 static unw_rec_list *
1914 output_gr_gr (mask, reg)
1915 unsigned int mask;
1916 unsigned int reg;
1918 unw_rec_list *ptr = alloc_record (gr_gr);
1919 ptr->r.record.p.grmask = mask;
1920 ptr->r.record.p.gr = reg;
1921 return ptr;
1924 static unw_rec_list *
1925 output_gr_mem (mask)
1926 unsigned int mask;
1928 unw_rec_list *ptr = alloc_record (gr_mem);
1929 ptr->r.record.p.rmask = mask;
1930 return ptr;
1933 static unw_rec_list *
1934 output_br_mem (unsigned int mask)
1936 unw_rec_list *ptr = alloc_record (br_mem);
1937 ptr->r.record.p.brmask = mask;
1938 return ptr;
1941 static unw_rec_list *
1942 output_br_gr (save_mask, reg)
1943 unsigned int save_mask;
1944 unsigned int reg;
1946 unw_rec_list *ptr = alloc_record (br_gr);
1947 ptr->r.record.p.brmask = save_mask;
1948 ptr->r.record.p.gr = reg;
1949 return ptr;
1952 static unw_rec_list *
1953 output_spill_base (offset)
1954 unsigned int offset;
1956 unw_rec_list *ptr = alloc_record (spill_base);
1957 ptr->r.record.p.pspoff = offset / 4;
1958 return ptr;
1961 static unw_rec_list *
1962 output_unat_when ()
1964 unw_rec_list *ptr = alloc_record (unat_when);
1965 return ptr;
1968 static unw_rec_list *
1969 output_unat_gr (gr)
1970 unsigned int gr;
1972 unw_rec_list *ptr = alloc_record (unat_gr);
1973 ptr->r.record.p.gr = gr;
1974 return ptr;
1977 static unw_rec_list *
1978 output_unat_psprel (offset)
1979 unsigned int offset;
1981 unw_rec_list *ptr = alloc_record (unat_psprel);
1982 ptr->r.record.p.pspoff = offset / 4;
1983 return ptr;
1986 static unw_rec_list *
1987 output_unat_sprel (offset)
1988 unsigned int offset;
1990 unw_rec_list *ptr = alloc_record (unat_sprel);
1991 ptr->r.record.p.spoff = offset / 4;
1992 return ptr;
1995 static unw_rec_list *
1996 output_lc_when ()
1998 unw_rec_list *ptr = alloc_record (lc_when);
1999 return ptr;
2002 static unw_rec_list *
2003 output_lc_gr (gr)
2004 unsigned int gr;
2006 unw_rec_list *ptr = alloc_record (lc_gr);
2007 ptr->r.record.p.gr = gr;
2008 return ptr;
2011 static unw_rec_list *
2012 output_lc_psprel (offset)
2013 unsigned int offset;
2015 unw_rec_list *ptr = alloc_record (lc_psprel);
2016 ptr->r.record.p.pspoff = offset / 4;
2017 return ptr;
2020 static unw_rec_list *
2021 output_lc_sprel (offset)
2022 unsigned int offset;
2024 unw_rec_list *ptr = alloc_record (lc_sprel);
2025 ptr->r.record.p.spoff = offset / 4;
2026 return ptr;
2029 static unw_rec_list *
2030 output_fpsr_when ()
2032 unw_rec_list *ptr = alloc_record (fpsr_when);
2033 return ptr;
2036 static unw_rec_list *
2037 output_fpsr_gr (gr)
2038 unsigned int gr;
2040 unw_rec_list *ptr = alloc_record (fpsr_gr);
2041 ptr->r.record.p.gr = gr;
2042 return ptr;
2045 static unw_rec_list *
2046 output_fpsr_psprel (offset)
2047 unsigned int offset;
2049 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2050 ptr->r.record.p.pspoff = offset / 4;
2051 return ptr;
2054 static unw_rec_list *
2055 output_fpsr_sprel (offset)
2056 unsigned int offset;
2058 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2059 ptr->r.record.p.spoff = offset / 4;
2060 return ptr;
2063 static unw_rec_list *
2064 output_priunat_when_gr ()
2066 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2067 return ptr;
2070 static unw_rec_list *
2071 output_priunat_when_mem ()
2073 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2074 return ptr;
2077 static unw_rec_list *
2078 output_priunat_gr (gr)
2079 unsigned int gr;
2081 unw_rec_list *ptr = alloc_record (priunat_gr);
2082 ptr->r.record.p.gr = gr;
2083 return ptr;
2086 static unw_rec_list *
2087 output_priunat_psprel (offset)
2088 unsigned int offset;
2090 unw_rec_list *ptr = alloc_record (priunat_psprel);
2091 ptr->r.record.p.pspoff = offset / 4;
2092 return ptr;
2095 static unw_rec_list *
2096 output_priunat_sprel (offset)
2097 unsigned int offset;
2099 unw_rec_list *ptr = alloc_record (priunat_sprel);
2100 ptr->r.record.p.spoff = offset / 4;
2101 return ptr;
2104 static unw_rec_list *
2105 output_bsp_when ()
2107 unw_rec_list *ptr = alloc_record (bsp_when);
2108 return ptr;
2111 static unw_rec_list *
2112 output_bsp_gr (gr)
2113 unsigned int gr;
2115 unw_rec_list *ptr = alloc_record (bsp_gr);
2116 ptr->r.record.p.gr = gr;
2117 return ptr;
2120 static unw_rec_list *
2121 output_bsp_psprel (offset)
2122 unsigned int offset;
2124 unw_rec_list *ptr = alloc_record (bsp_psprel);
2125 ptr->r.record.p.pspoff = offset / 4;
2126 return ptr;
2129 static unw_rec_list *
2130 output_bsp_sprel (offset)
2131 unsigned int offset;
2133 unw_rec_list *ptr = alloc_record (bsp_sprel);
2134 ptr->r.record.p.spoff = offset / 4;
2135 return ptr;
2138 static unw_rec_list *
2139 output_bspstore_when ()
2141 unw_rec_list *ptr = alloc_record (bspstore_when);
2142 return ptr;
2145 static unw_rec_list *
2146 output_bspstore_gr (gr)
2147 unsigned int gr;
2149 unw_rec_list *ptr = alloc_record (bspstore_gr);
2150 ptr->r.record.p.gr = gr;
2151 return ptr;
2154 static unw_rec_list *
2155 output_bspstore_psprel (offset)
2156 unsigned int offset;
2158 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2159 ptr->r.record.p.pspoff = offset / 4;
2160 return ptr;
2163 static unw_rec_list *
2164 output_bspstore_sprel (offset)
2165 unsigned int offset;
2167 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2168 ptr->r.record.p.spoff = offset / 4;
2169 return ptr;
2172 static unw_rec_list *
2173 output_rnat_when ()
2175 unw_rec_list *ptr = alloc_record (rnat_when);
2176 return ptr;
2179 static unw_rec_list *
2180 output_rnat_gr (gr)
2181 unsigned int gr;
2183 unw_rec_list *ptr = alloc_record (rnat_gr);
2184 ptr->r.record.p.gr = gr;
2185 return ptr;
2188 static unw_rec_list *
2189 output_rnat_psprel (offset)
2190 unsigned int offset;
2192 unw_rec_list *ptr = alloc_record (rnat_psprel);
2193 ptr->r.record.p.pspoff = offset / 4;
2194 return ptr;
2197 static unw_rec_list *
2198 output_rnat_sprel (offset)
2199 unsigned int offset;
2201 unw_rec_list *ptr = alloc_record (rnat_sprel);
2202 ptr->r.record.p.spoff = offset / 4;
2203 return ptr;
2206 static unw_rec_list *
2207 output_unwabi (abi, context)
2208 unsigned long abi;
2209 unsigned long context;
2211 unw_rec_list *ptr = alloc_record (unwabi);
2212 ptr->r.record.p.abi = abi;
2213 ptr->r.record.p.context = context;
2214 return ptr;
2217 static unw_rec_list *
2218 output_epilogue (unsigned long ecount)
2220 unw_rec_list *ptr = alloc_record (epilogue);
2221 ptr->r.record.b.ecount = ecount;
2222 return ptr;
2225 static unw_rec_list *
2226 output_label_state (unsigned long label)
2228 unw_rec_list *ptr = alloc_record (label_state);
2229 ptr->r.record.b.label = label;
2230 return ptr;
2233 static unw_rec_list *
2234 output_copy_state (unsigned long label)
2236 unw_rec_list *ptr = alloc_record (copy_state);
2237 ptr->r.record.b.label = label;
2238 return ptr;
2241 static unw_rec_list *
2242 output_spill_psprel (ab, reg, offset)
2243 unsigned int ab;
2244 unsigned int reg;
2245 unsigned int offset;
2247 unw_rec_list *ptr = alloc_record (spill_psprel);
2248 ptr->r.record.x.ab = ab;
2249 ptr->r.record.x.reg = reg;
2250 ptr->r.record.x.pspoff = offset / 4;
2251 return ptr;
2254 static unw_rec_list *
2255 output_spill_sprel (ab, reg, offset)
2256 unsigned int ab;
2257 unsigned int reg;
2258 unsigned int offset;
2260 unw_rec_list *ptr = alloc_record (spill_sprel);
2261 ptr->r.record.x.ab = ab;
2262 ptr->r.record.x.reg = reg;
2263 ptr->r.record.x.spoff = offset / 4;
2264 return ptr;
2267 static unw_rec_list *
2268 output_spill_psprel_p (ab, reg, offset, predicate)
2269 unsigned int ab;
2270 unsigned int reg;
2271 unsigned int offset;
2272 unsigned int predicate;
2274 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2275 ptr->r.record.x.ab = ab;
2276 ptr->r.record.x.reg = reg;
2277 ptr->r.record.x.pspoff = offset / 4;
2278 ptr->r.record.x.qp = predicate;
2279 return ptr;
2282 static unw_rec_list *
2283 output_spill_sprel_p (ab, reg, offset, predicate)
2284 unsigned int ab;
2285 unsigned int reg;
2286 unsigned int offset;
2287 unsigned int predicate;
2289 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2290 ptr->r.record.x.ab = ab;
2291 ptr->r.record.x.reg = reg;
2292 ptr->r.record.x.spoff = offset / 4;
2293 ptr->r.record.x.qp = predicate;
2294 return ptr;
2297 static unw_rec_list *
2298 output_spill_reg (ab, reg, targ_reg, xy)
2299 unsigned int ab;
2300 unsigned int reg;
2301 unsigned int targ_reg;
2302 unsigned int xy;
2304 unw_rec_list *ptr = alloc_record (spill_reg);
2305 ptr->r.record.x.ab = ab;
2306 ptr->r.record.x.reg = reg;
2307 ptr->r.record.x.treg = targ_reg;
2308 ptr->r.record.x.xy = xy;
2309 return ptr;
2312 static unw_rec_list *
2313 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2314 unsigned int ab;
2315 unsigned int reg;
2316 unsigned int targ_reg;
2317 unsigned int xy;
2318 unsigned int predicate;
2320 unw_rec_list *ptr = alloc_record (spill_reg_p);
2321 ptr->r.record.x.ab = ab;
2322 ptr->r.record.x.reg = reg;
2323 ptr->r.record.x.treg = targ_reg;
2324 ptr->r.record.x.xy = xy;
2325 ptr->r.record.x.qp = predicate;
2326 return ptr;
2329 /* Given a unw_rec_list process the correct format with the
2330 specified function. */
2332 static void
2333 process_one_record (ptr, f)
2334 unw_rec_list *ptr;
2335 vbyte_func f;
2337 unsigned long fr_mask, gr_mask;
2339 switch (ptr->r.type)
2341 /* This is a dummy record that takes up no space in the output. */
2342 case endp:
2343 break;
2345 case gr_mem:
2346 case fr_mem:
2347 case br_mem:
2348 case frgr_mem:
2349 /* These are taken care of by prologue/prologue_gr. */
2350 break;
2352 case prologue_gr:
2353 case prologue:
2354 if (ptr->r.type == prologue_gr)
2355 output_R2_format (f, ptr->r.record.r.grmask,
2356 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2357 else
2358 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2360 /* Output descriptor(s) for union of register spills (if any). */
2361 gr_mask = ptr->r.record.r.mask.gr_mem;
2362 fr_mask = ptr->r.record.r.mask.fr_mem;
2363 if (fr_mask)
2365 if ((fr_mask & ~0xfUL) == 0)
2366 output_P6_format (f, fr_mem, fr_mask);
2367 else
2369 output_P5_format (f, gr_mask, fr_mask);
2370 gr_mask = 0;
2373 if (gr_mask)
2374 output_P6_format (f, gr_mem, gr_mask);
2375 if (ptr->r.record.r.mask.br_mem)
2376 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2378 /* output imask descriptor if necessary: */
2379 if (ptr->r.record.r.mask.i)
2380 output_P4_format (f, ptr->r.record.r.mask.i,
2381 ptr->r.record.r.imask_size);
2382 break;
2384 case body:
2385 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2386 break;
2387 case mem_stack_f:
2388 case mem_stack_v:
2389 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2390 ptr->r.record.p.size);
2391 break;
2392 case psp_gr:
2393 case rp_gr:
2394 case pfs_gr:
2395 case preds_gr:
2396 case unat_gr:
2397 case lc_gr:
2398 case fpsr_gr:
2399 case priunat_gr:
2400 case bsp_gr:
2401 case bspstore_gr:
2402 case rnat_gr:
2403 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2404 break;
2405 case rp_br:
2406 output_P3_format (f, rp_br, ptr->r.record.p.br);
2407 break;
2408 case psp_sprel:
2409 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2410 break;
2411 case rp_when:
2412 case pfs_when:
2413 case preds_when:
2414 case unat_when:
2415 case lc_when:
2416 case fpsr_when:
2417 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2418 break;
2419 case rp_psprel:
2420 case pfs_psprel:
2421 case preds_psprel:
2422 case unat_psprel:
2423 case lc_psprel:
2424 case fpsr_psprel:
2425 case spill_base:
2426 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2427 break;
2428 case rp_sprel:
2429 case pfs_sprel:
2430 case preds_sprel:
2431 case unat_sprel:
2432 case lc_sprel:
2433 case fpsr_sprel:
2434 case priunat_sprel:
2435 case bsp_sprel:
2436 case bspstore_sprel:
2437 case rnat_sprel:
2438 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2439 break;
2440 case gr_gr:
2441 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2442 break;
2443 case br_gr:
2444 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2445 break;
2446 case spill_mask:
2447 as_bad ("spill_mask record unimplemented.");
2448 break;
2449 case priunat_when_gr:
2450 case priunat_when_mem:
2451 case bsp_when:
2452 case bspstore_when:
2453 case rnat_when:
2454 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2455 break;
2456 case priunat_psprel:
2457 case bsp_psprel:
2458 case bspstore_psprel:
2459 case rnat_psprel:
2460 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2461 break;
2462 case unwabi:
2463 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2464 break;
2465 case epilogue:
2466 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2467 break;
2468 case label_state:
2469 case copy_state:
2470 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2471 break;
2472 case spill_psprel:
2473 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2474 ptr->r.record.x.reg, ptr->r.record.x.t,
2475 ptr->r.record.x.pspoff);
2476 break;
2477 case spill_sprel:
2478 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2479 ptr->r.record.x.reg, ptr->r.record.x.t,
2480 ptr->r.record.x.spoff);
2481 break;
2482 case spill_reg:
2483 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2484 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2485 ptr->r.record.x.treg, ptr->r.record.x.t);
2486 break;
2487 case spill_psprel_p:
2488 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2489 ptr->r.record.x.ab, ptr->r.record.x.reg,
2490 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2491 break;
2492 case spill_sprel_p:
2493 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2494 ptr->r.record.x.ab, ptr->r.record.x.reg,
2495 ptr->r.record.x.t, ptr->r.record.x.spoff);
2496 break;
2497 case spill_reg_p:
2498 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2499 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2500 ptr->r.record.x.xy, ptr->r.record.x.treg,
2501 ptr->r.record.x.t);
2502 break;
2503 default:
2504 as_bad ("record_type_not_valid");
2505 break;
2509 /* Given a unw_rec_list list, process all the records with
2510 the specified function. */
2511 static void
2512 process_unw_records (list, f)
2513 unw_rec_list *list;
2514 vbyte_func f;
2516 unw_rec_list *ptr;
2517 for (ptr = list; ptr; ptr = ptr->next)
2518 process_one_record (ptr, f);
2521 /* Determine the size of a record list in bytes. */
2522 static int
2523 calc_record_size (list)
2524 unw_rec_list *list;
2526 vbyte_count = 0;
2527 process_unw_records (list, count_output);
2528 return vbyte_count;
2531 /* Update IMASK bitmask to reflect the fact that one or more registers
2532 of type TYPE are saved starting at instruction with index T. If N
2533 bits are set in REGMASK, it is assumed that instructions T through
2534 T+N-1 save these registers.
2536 TYPE values:
2537 0: no save
2538 1: instruction saves next fp reg
2539 2: instruction saves next general reg
2540 3: instruction saves next branch reg */
2541 static void
2542 set_imask (region, regmask, t, type)
2543 unw_rec_list *region;
2544 unsigned long regmask;
2545 unsigned long t;
2546 unsigned int type;
2548 unsigned char *imask;
2549 unsigned long imask_size;
2550 unsigned int i;
2551 int pos;
2553 imask = region->r.record.r.mask.i;
2554 imask_size = region->r.record.r.imask_size;
2555 if (!imask)
2557 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2558 imask = xmalloc (imask_size);
2559 memset (imask, 0, imask_size);
2561 region->r.record.r.imask_size = imask_size;
2562 region->r.record.r.mask.i = imask;
2565 i = (t / 4) + 1;
2566 pos = 2 * (3 - t % 4);
2567 while (regmask)
2569 if (i >= imask_size)
2571 as_bad ("Ignoring attempt to spill beyond end of region");
2572 return;
2575 imask[i] |= (type & 0x3) << pos;
2577 regmask &= (regmask - 1);
2578 pos -= 2;
2579 if (pos < 0)
2581 pos = 0;
2582 ++i;
2587 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2588 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2589 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2590 for frag sizes. */
2592 unsigned long
2593 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2594 unsigned long slot_addr;
2595 fragS *slot_frag;
2596 unsigned long first_addr;
2597 fragS *first_frag;
2598 int before_relax;
2600 unsigned long index = 0;
2602 /* First time we are called, the initial address and frag are invalid. */
2603 if (first_addr == 0)
2604 return 0;
2606 /* If the two addresses are in different frags, then we need to add in
2607 the remaining size of this frag, and then the entire size of intermediate
2608 frags. */
2609 while (slot_frag != first_frag)
2611 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2613 if (! before_relax)
2615 /* We can get the final addresses only during and after
2616 relaxation. */
2617 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2618 index += 3 * ((first_frag->fr_next->fr_address
2619 - first_frag->fr_address
2620 - first_frag->fr_fix) >> 4);
2622 else
2623 /* We don't know what the final addresses will be. We try our
2624 best to estimate. */
2625 switch (first_frag->fr_type)
2627 default:
2628 break;
2630 case rs_space:
2631 as_fatal ("only constant space allocation is supported");
2632 break;
2634 case rs_align:
2635 case rs_align_code:
2636 case rs_align_test:
2637 /* Take alignment into account. Assume the worst case
2638 before relaxation. */
2639 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2640 break;
2642 case rs_org:
2643 if (first_frag->fr_symbol)
2645 as_fatal ("only constant offsets are supported");
2646 break;
2648 case rs_fill:
2649 index += 3 * (first_frag->fr_offset >> 4);
2650 break;
2653 /* Add in the full size of the frag converted to instruction slots. */
2654 index += 3 * (first_frag->fr_fix >> 4);
2655 /* Subtract away the initial part before first_addr. */
2656 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2657 + ((first_addr & 0x3) - (start_addr & 0x3)));
2659 /* Move to the beginning of the next frag. */
2660 first_frag = first_frag->fr_next;
2661 first_addr = (unsigned long) &first_frag->fr_literal;
2664 /* Add in the used part of the last frag. */
2665 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2666 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2667 return index;
2670 /* Optimize unwind record directives. */
2672 static unw_rec_list *
2673 optimize_unw_records (list)
2674 unw_rec_list *list;
2676 if (!list)
2677 return NULL;
2679 /* If the only unwind record is ".prologue" or ".prologue" followed
2680 by ".body", then we can optimize the unwind directives away. */
2681 if (list->r.type == prologue
2682 && (list->next->r.type == endp
2683 || (list->next->r.type == body && list->next->next->r.type == endp)))
2684 return NULL;
2686 return list;
2689 /* Given a complete record list, process any records which have
2690 unresolved fields, (ie length counts for a prologue). After
2691 this has been run, all necessary information should be available
2692 within each record to generate an image. */
2694 static void
2695 fixup_unw_records (list, before_relax)
2696 unw_rec_list *list;
2697 int before_relax;
2699 unw_rec_list *ptr, *region = 0;
2700 unsigned long first_addr = 0, rlen = 0, t;
2701 fragS *first_frag = 0;
2703 for (ptr = list; ptr; ptr = ptr->next)
2705 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2706 as_bad (" Insn slot not set in unwind record.");
2707 t = slot_index (ptr->slot_number, ptr->slot_frag,
2708 first_addr, first_frag, before_relax);
2709 switch (ptr->r.type)
2711 case prologue:
2712 case prologue_gr:
2713 case body:
2715 unw_rec_list *last;
2716 int size;
2717 unsigned long last_addr = 0;
2718 fragS *last_frag = NULL;
2720 first_addr = ptr->slot_number;
2721 first_frag = ptr->slot_frag;
2722 /* Find either the next body/prologue start, or the end of
2723 the function, and determine the size of the region. */
2724 for (last = ptr->next; last != NULL; last = last->next)
2725 if (last->r.type == prologue || last->r.type == prologue_gr
2726 || last->r.type == body || last->r.type == endp)
2728 last_addr = last->slot_number;
2729 last_frag = last->slot_frag;
2730 break;
2732 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2733 before_relax);
2734 rlen = ptr->r.record.r.rlen = size;
2735 if (ptr->r.type == body)
2736 /* End of region. */
2737 region = 0;
2738 else
2739 region = ptr;
2740 break;
2742 case epilogue:
2743 ptr->r.record.b.t = rlen - 1 - t;
2744 break;
2746 case mem_stack_f:
2747 case mem_stack_v:
2748 case rp_when:
2749 case pfs_when:
2750 case preds_when:
2751 case unat_when:
2752 case lc_when:
2753 case fpsr_when:
2754 case priunat_when_gr:
2755 case priunat_when_mem:
2756 case bsp_when:
2757 case bspstore_when:
2758 case rnat_when:
2759 ptr->r.record.p.t = t;
2760 break;
2762 case spill_reg:
2763 case spill_sprel:
2764 case spill_psprel:
2765 case spill_reg_p:
2766 case spill_sprel_p:
2767 case spill_psprel_p:
2768 ptr->r.record.x.t = t;
2769 break;
2771 case frgr_mem:
2772 if (!region)
2774 as_bad ("frgr_mem record before region record!\n");
2775 return;
2777 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2778 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2779 set_imask (region, ptr->r.record.p.frmask, t, 1);
2780 set_imask (region, ptr->r.record.p.grmask, t, 2);
2781 break;
2782 case fr_mem:
2783 if (!region)
2785 as_bad ("fr_mem record before region record!\n");
2786 return;
2788 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2789 set_imask (region, ptr->r.record.p.rmask, t, 1);
2790 break;
2791 case gr_mem:
2792 if (!region)
2794 as_bad ("gr_mem record before region record!\n");
2795 return;
2797 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2798 set_imask (region, ptr->r.record.p.rmask, t, 2);
2799 break;
2800 case br_mem:
2801 if (!region)
2803 as_bad ("br_mem record before region record!\n");
2804 return;
2806 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2807 set_imask (region, ptr->r.record.p.brmask, t, 3);
2808 break;
2810 case gr_gr:
2811 if (!region)
2813 as_bad ("gr_gr record before region record!\n");
2814 return;
2816 set_imask (region, ptr->r.record.p.grmask, t, 2);
2817 break;
2818 case br_gr:
2819 if (!region)
2821 as_bad ("br_gr record before region record!\n");
2822 return;
2824 set_imask (region, ptr->r.record.p.brmask, t, 3);
2825 break;
2827 default:
2828 break;
2833 /* Estimate the size of a frag before relaxing. We only have one type of frag
2834 to handle here, which is the unwind info frag. */
2837 ia64_estimate_size_before_relax (fragS *frag,
2838 asection *segtype ATTRIBUTE_UNUSED)
2840 unw_rec_list *list;
2841 int len, size, pad;
2843 /* ??? This code is identical to the first part of ia64_convert_frag. */
2844 list = (unw_rec_list *) frag->fr_opcode;
2845 fixup_unw_records (list, 0);
2847 len = calc_record_size (list);
2848 /* pad to pointer-size boundary. */
2849 pad = len % md.pointer_size;
2850 if (pad != 0)
2851 len += md.pointer_size - pad;
2852 /* Add 8 for the header + a pointer for the personality offset. */
2853 size = len + 8 + md.pointer_size;
2855 /* fr_var carries the max_chars that we created the fragment with.
2856 We must, of course, have allocated enough memory earlier. */
2857 assert (frag->fr_var >= size);
2859 return frag->fr_fix + size;
2862 /* This function converts a rs_machine_dependent variant frag into a
2863 normal fill frag with the unwind image from the the record list. */
2864 void
2865 ia64_convert_frag (fragS *frag)
2867 unw_rec_list *list;
2868 int len, size, pad;
2869 valueT flag_value;
2871 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2872 list = (unw_rec_list *) frag->fr_opcode;
2873 fixup_unw_records (list, 0);
2875 len = calc_record_size (list);
2876 /* pad to pointer-size boundary. */
2877 pad = len % md.pointer_size;
2878 if (pad != 0)
2879 len += md.pointer_size - pad;
2880 /* Add 8 for the header + a pointer for the personality offset. */
2881 size = len + 8 + md.pointer_size;
2883 /* fr_var carries the max_chars that we created the fragment with.
2884 We must, of course, have allocated enough memory earlier. */
2885 assert (frag->fr_var >= size);
2887 /* Initialize the header area. fr_offset is initialized with
2888 unwind.personality_routine. */
2889 if (frag->fr_offset)
2891 if (md.flags & EF_IA_64_ABI64)
2892 flag_value = (bfd_vma) 3 << 32;
2893 else
2894 /* 32-bit unwind info block. */
2895 flag_value = (bfd_vma) 0x1003 << 32;
2897 else
2898 flag_value = 0;
2900 md_number_to_chars (frag->fr_literal,
2901 (((bfd_vma) 1 << 48) /* Version. */
2902 | flag_value /* U & E handler flags. */
2903 | (len / md.pointer_size)), /* Length. */
2906 /* Skip the header. */
2907 vbyte_mem_ptr = frag->fr_literal + 8;
2908 process_unw_records (list, output_vbyte_mem);
2910 /* Fill the padding bytes with zeros. */
2911 if (pad != 0)
2912 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2913 md.pointer_size - pad);
2915 frag->fr_fix += size;
2916 frag->fr_type = rs_fill;
2917 frag->fr_var = 0;
2918 frag->fr_offset = 0;
2921 static int
2922 convert_expr_to_ab_reg (e, ab, regp)
2923 expressionS *e;
2924 unsigned int *ab;
2925 unsigned int *regp;
2927 unsigned int reg;
2929 if (e->X_op != O_register)
2930 return 0;
2932 reg = e->X_add_number;
2933 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2935 *ab = 0;
2936 *regp = reg - REG_GR;
2938 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2939 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2941 *ab = 1;
2942 *regp = reg - REG_FR;
2944 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2946 *ab = 2;
2947 *regp = reg - REG_BR;
2949 else
2951 *ab = 3;
2952 switch (reg)
2954 case REG_PR: *regp = 0; break;
2955 case REG_PSP: *regp = 1; break;
2956 case REG_PRIUNAT: *regp = 2; break;
2957 case REG_BR + 0: *regp = 3; break;
2958 case REG_AR + AR_BSP: *regp = 4; break;
2959 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2960 case REG_AR + AR_RNAT: *regp = 6; break;
2961 case REG_AR + AR_UNAT: *regp = 7; break;
2962 case REG_AR + AR_FPSR: *regp = 8; break;
2963 case REG_AR + AR_PFS: *regp = 9; break;
2964 case REG_AR + AR_LC: *regp = 10; break;
2966 default:
2967 return 0;
2970 return 1;
2973 static int
2974 convert_expr_to_xy_reg (e, xy, regp)
2975 expressionS *e;
2976 unsigned int *xy;
2977 unsigned int *regp;
2979 unsigned int reg;
2981 if (e->X_op != O_register)
2982 return 0;
2984 reg = e->X_add_number;
2986 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
2988 *xy = 0;
2989 *regp = reg - REG_GR;
2991 else if (reg >= REG_FR && reg <= (REG_FR + 127))
2993 *xy = 1;
2994 *regp = reg - REG_FR;
2996 else if (reg >= REG_BR && reg <= (REG_BR + 7))
2998 *xy = 2;
2999 *regp = reg - REG_BR;
3001 else
3002 return -1;
3003 return 1;
3006 static void
3007 dot_align (int arg)
3009 /* The current frag is an alignment frag. */
3010 align_frag = frag_now;
3011 s_align_bytes (arg);
3014 static void
3015 dot_radix (dummy)
3016 int dummy ATTRIBUTE_UNUSED;
3018 int radix;
3020 SKIP_WHITESPACE ();
3021 radix = *input_line_pointer++;
3023 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3025 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3026 ignore_rest_of_line ();
3027 return;
3031 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3032 static void
3033 dot_special_section (which)
3034 int which;
3036 set_section ((char *) special_section_name[which]);
3039 static void
3040 add_unwind_entry (ptr)
3041 unw_rec_list *ptr;
3043 if (unwind.tail)
3044 unwind.tail->next = ptr;
3045 else
3046 unwind.list = ptr;
3047 unwind.tail = ptr;
3049 /* The current entry can in fact be a chain of unwind entries. */
3050 if (unwind.current_entry == NULL)
3051 unwind.current_entry = ptr;
3054 static void
3055 dot_fframe (dummy)
3056 int dummy ATTRIBUTE_UNUSED;
3058 expressionS e;
3060 parse_operand (&e);
3062 if (e.X_op != O_constant)
3063 as_bad ("Operand to .fframe must be a constant");
3064 else
3065 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3068 static void
3069 dot_vframe (dummy)
3070 int dummy ATTRIBUTE_UNUSED;
3072 expressionS e;
3073 unsigned reg;
3075 parse_operand (&e);
3076 reg = e.X_add_number - REG_GR;
3077 if (e.X_op == O_register && reg < 128)
3079 add_unwind_entry (output_mem_stack_v ());
3080 if (! (unwind.prologue_mask & 2))
3081 add_unwind_entry (output_psp_gr (reg));
3083 else
3084 as_bad ("First operand to .vframe must be a general register");
3087 static void
3088 dot_vframesp (dummy)
3089 int dummy ATTRIBUTE_UNUSED;
3091 expressionS e;
3093 parse_operand (&e);
3094 if (e.X_op == O_constant)
3096 add_unwind_entry (output_mem_stack_v ());
3097 add_unwind_entry (output_psp_sprel (e.X_add_number));
3099 else
3100 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3103 static void
3104 dot_vframepsp (dummy)
3105 int dummy ATTRIBUTE_UNUSED;
3107 expressionS e;
3109 parse_operand (&e);
3110 if (e.X_op == O_constant)
3112 add_unwind_entry (output_mem_stack_v ());
3113 add_unwind_entry (output_psp_sprel (e.X_add_number));
3115 else
3116 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3119 static void
3120 dot_save (dummy)
3121 int dummy ATTRIBUTE_UNUSED;
3123 expressionS e1, e2;
3124 int sep;
3125 int reg1, reg2;
3127 sep = parse_operand (&e1);
3128 if (sep != ',')
3129 as_bad ("No second operand to .save");
3130 sep = parse_operand (&e2);
3132 reg1 = e1.X_add_number;
3133 reg2 = e2.X_add_number - REG_GR;
3135 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3136 if (e1.X_op == O_register)
3138 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3140 switch (reg1)
3142 case REG_AR + AR_BSP:
3143 add_unwind_entry (output_bsp_when ());
3144 add_unwind_entry (output_bsp_gr (reg2));
3145 break;
3146 case REG_AR + AR_BSPSTORE:
3147 add_unwind_entry (output_bspstore_when ());
3148 add_unwind_entry (output_bspstore_gr (reg2));
3149 break;
3150 case REG_AR + AR_RNAT:
3151 add_unwind_entry (output_rnat_when ());
3152 add_unwind_entry (output_rnat_gr (reg2));
3153 break;
3154 case REG_AR + AR_UNAT:
3155 add_unwind_entry (output_unat_when ());
3156 add_unwind_entry (output_unat_gr (reg2));
3157 break;
3158 case REG_AR + AR_FPSR:
3159 add_unwind_entry (output_fpsr_when ());
3160 add_unwind_entry (output_fpsr_gr (reg2));
3161 break;
3162 case REG_AR + AR_PFS:
3163 add_unwind_entry (output_pfs_when ());
3164 if (! (unwind.prologue_mask & 4))
3165 add_unwind_entry (output_pfs_gr (reg2));
3166 break;
3167 case REG_AR + AR_LC:
3168 add_unwind_entry (output_lc_when ());
3169 add_unwind_entry (output_lc_gr (reg2));
3170 break;
3171 case REG_BR:
3172 add_unwind_entry (output_rp_when ());
3173 if (! (unwind.prologue_mask & 8))
3174 add_unwind_entry (output_rp_gr (reg2));
3175 break;
3176 case REG_PR:
3177 add_unwind_entry (output_preds_when ());
3178 if (! (unwind.prologue_mask & 1))
3179 add_unwind_entry (output_preds_gr (reg2));
3180 break;
3181 case REG_PRIUNAT:
3182 add_unwind_entry (output_priunat_when_gr ());
3183 add_unwind_entry (output_priunat_gr (reg2));
3184 break;
3185 default:
3186 as_bad ("First operand not a valid register");
3189 else
3190 as_bad (" Second operand not a valid register");
3192 else
3193 as_bad ("First operand not a register");
3196 static void
3197 dot_restore (dummy)
3198 int dummy ATTRIBUTE_UNUSED;
3200 expressionS e1, e2;
3201 unsigned long ecount; /* # of _additional_ regions to pop */
3202 int sep;
3204 sep = parse_operand (&e1);
3205 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3207 as_bad ("First operand to .restore must be stack pointer (sp)");
3208 return;
3211 if (sep == ',')
3213 parse_operand (&e2);
3214 if (e2.X_op != O_constant || e2.X_add_number < 0)
3216 as_bad ("Second operand to .restore must be a constant >= 0");
3217 return;
3219 ecount = e2.X_add_number;
3221 else
3222 ecount = unwind.prologue_count - 1;
3224 if (ecount >= unwind.prologue_count)
3226 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3227 ecount + 1, unwind.prologue_count);
3228 return;
3231 add_unwind_entry (output_epilogue (ecount));
3233 if (ecount < unwind.prologue_count)
3234 unwind.prologue_count -= ecount + 1;
3235 else
3236 unwind.prologue_count = 0;
3239 static void
3240 dot_restorereg (dummy)
3241 int dummy ATTRIBUTE_UNUSED;
3243 unsigned int ab, reg;
3244 expressionS e;
3246 parse_operand (&e);
3248 if (!convert_expr_to_ab_reg (&e, &ab, &reg))
3250 as_bad ("First operand to .restorereg must be a preserved register");
3251 return;
3253 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3256 static void
3257 dot_restorereg_p (dummy)
3258 int dummy ATTRIBUTE_UNUSED;
3260 unsigned int qp, ab, reg;
3261 expressionS e1, e2;
3262 int sep;
3264 sep = parse_operand (&e1);
3265 if (sep != ',')
3267 as_bad ("No second operand to .restorereg.p");
3268 return;
3271 parse_operand (&e2);
3273 qp = e1.X_add_number - REG_P;
3274 if (e1.X_op != O_register || qp > 63)
3276 as_bad ("First operand to .restorereg.p must be a predicate");
3277 return;
3280 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
3282 as_bad ("Second operand to .restorereg.p must be a preserved register");
3283 return;
3285 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3288 static char *special_linkonce_name[] =
3290 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3293 static void
3294 start_unwind_section (const segT text_seg, int sec_index)
3297 Use a slightly ugly scheme to derive the unwind section names from
3298 the text section name:
3300 text sect. unwind table sect.
3301 name: name: comments:
3302 ---------- ----------------- --------------------------------
3303 .text .IA_64.unwind
3304 .text.foo .IA_64.unwind.text.foo
3305 .foo .IA_64.unwind.foo
3306 .gnu.linkonce.t.foo
3307 .gnu.linkonce.ia64unw.foo
3308 _info .IA_64.unwind_info gas issues error message (ditto)
3309 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3311 This mapping is done so that:
3313 (a) An object file with unwind info only in .text will use
3314 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3315 This follows the letter of the ABI and also ensures backwards
3316 compatibility with older toolchains.
3318 (b) An object file with unwind info in multiple text sections
3319 will use separate unwind sections for each text section.
3320 This allows us to properly set the "sh_info" and "sh_link"
3321 fields in SHT_IA_64_UNWIND as required by the ABI and also
3322 lets GNU ld support programs with multiple segments
3323 containing unwind info (as might be the case for certain
3324 embedded applications).
3326 (c) An error is issued if there would be a name clash.
3329 const char *text_name, *sec_text_name;
3330 char *sec_name;
3331 const char *prefix = special_section_name [sec_index];
3332 const char *suffix;
3333 size_t prefix_len, suffix_len, sec_name_len;
3335 sec_text_name = segment_name (text_seg);
3336 text_name = sec_text_name;
3337 if (strncmp (text_name, "_info", 5) == 0)
3339 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3340 text_name);
3341 ignore_rest_of_line ();
3342 return;
3344 if (strcmp (text_name, ".text") == 0)
3345 text_name = "";
3347 /* Build the unwind section name by appending the (possibly stripped)
3348 text section name to the unwind prefix. */
3349 suffix = text_name;
3350 if (strncmp (text_name, ".gnu.linkonce.t.",
3351 sizeof (".gnu.linkonce.t.") - 1) == 0)
3353 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3354 suffix += sizeof (".gnu.linkonce.t.") - 1;
3357 prefix_len = strlen (prefix);
3358 suffix_len = strlen (suffix);
3359 sec_name_len = prefix_len + suffix_len;
3360 sec_name = alloca (sec_name_len + 1);
3361 memcpy (sec_name, prefix, prefix_len);
3362 memcpy (sec_name + prefix_len, suffix, suffix_len);
3363 sec_name [sec_name_len] = '\0';
3365 /* Handle COMDAT group. */
3366 if (suffix == text_name && (text_seg->flags & SEC_LINK_ONCE) != 0)
3368 char *section;
3369 size_t len, group_name_len;
3370 const char *group_name = elf_group_name (text_seg);
3372 if (group_name == NULL)
3374 as_bad ("Group section `%s' has no group signature",
3375 sec_text_name);
3376 ignore_rest_of_line ();
3377 return;
3379 /* We have to construct a fake section directive. */
3380 group_name_len = strlen (group_name);
3381 len = (sec_name_len
3382 + 16 /* ,"aG",@progbits, */
3383 + group_name_len /* ,group_name */
3384 + 7); /* ,comdat */
3386 section = alloca (len + 1);
3387 memcpy (section, sec_name, sec_name_len);
3388 memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3389 memcpy (section + sec_name_len + 16, group_name, group_name_len);
3390 memcpy (section + len - 7, ",comdat", 7);
3391 section [len] = '\0';
3392 set_section (section);
3394 else
3396 set_section (sec_name);
3397 bfd_set_section_flags (stdoutput, now_seg,
3398 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3402 static void
3403 generate_unwind_image (const segT text_seg)
3405 int size, pad;
3406 unw_rec_list *list;
3408 /* Mark the end of the unwind info, so that we can compute the size of the
3409 last unwind region. */
3410 add_unwind_entry (output_endp ());
3412 /* Force out pending instructions, to make sure all unwind records have
3413 a valid slot_number field. */
3414 ia64_flush_insns ();
3416 /* Generate the unwind record. */
3417 list = optimize_unw_records (unwind.list);
3418 fixup_unw_records (list, 1);
3419 size = calc_record_size (list);
3421 if (size > 0 || unwind.force_unwind_entry)
3423 unwind.force_unwind_entry = 0;
3424 /* pad to pointer-size boundary. */
3425 pad = size % md.pointer_size;
3426 if (pad != 0)
3427 size += md.pointer_size - pad;
3428 /* Add 8 for the header + a pointer for the personality
3429 offset. */
3430 size += 8 + md.pointer_size;
3433 /* If there are unwind records, switch sections, and output the info. */
3434 if (size != 0)
3436 expressionS exp;
3437 bfd_reloc_code_real_type reloc;
3439 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO);
3441 /* Make sure the section has 4 byte alignment for ILP32 and
3442 8 byte alignment for LP64. */
3443 frag_align (md.pointer_size_shift, 0, 0);
3444 record_alignment (now_seg, md.pointer_size_shift);
3446 /* Set expression which points to start of unwind descriptor area. */
3447 unwind.info = expr_build_dot ();
3449 frag_var (rs_machine_dependent, size, size, 0, 0,
3450 (offsetT) unwind.personality_routine, (char *) list);
3452 /* Add the personality address to the image. */
3453 if (unwind.personality_routine != 0)
3455 exp.X_op = O_symbol;
3456 exp.X_add_symbol = unwind.personality_routine;
3457 exp.X_add_number = 0;
3459 if (md.flags & EF_IA_64_BE)
3461 if (md.flags & EF_IA_64_ABI64)
3462 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3463 else
3464 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3466 else
3468 if (md.flags & EF_IA_64_ABI64)
3469 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3470 else
3471 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3474 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3475 md.pointer_size, &exp, 0, reloc);
3476 unwind.personality_routine = 0;
3480 free_saved_prologue_counts ();
3481 unwind.list = unwind.tail = unwind.current_entry = NULL;
3484 static void
3485 dot_handlerdata (dummy)
3486 int dummy ATTRIBUTE_UNUSED;
3488 unwind.force_unwind_entry = 1;
3490 /* Remember which segment we're in so we can switch back after .endp */
3491 unwind.saved_text_seg = now_seg;
3492 unwind.saved_text_subseg = now_subseg;
3494 /* Generate unwind info into unwind-info section and then leave that
3495 section as the currently active one so dataXX directives go into
3496 the language specific data area of the unwind info block. */
3497 generate_unwind_image (now_seg);
3498 demand_empty_rest_of_line ();
3501 static void
3502 dot_unwentry (dummy)
3503 int dummy ATTRIBUTE_UNUSED;
3505 unwind.force_unwind_entry = 1;
3506 demand_empty_rest_of_line ();
3509 static void
3510 dot_altrp (dummy)
3511 int dummy ATTRIBUTE_UNUSED;
3513 expressionS e;
3514 unsigned reg;
3516 parse_operand (&e);
3517 reg = e.X_add_number - REG_BR;
3518 if (e.X_op == O_register && reg < 8)
3519 add_unwind_entry (output_rp_br (reg));
3520 else
3521 as_bad ("First operand not a valid branch register");
3524 static void
3525 dot_savemem (psprel)
3526 int psprel;
3528 expressionS e1, e2;
3529 int sep;
3530 int reg1, val;
3532 sep = parse_operand (&e1);
3533 if (sep != ',')
3534 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3535 sep = parse_operand (&e2);
3537 reg1 = e1.X_add_number;
3538 val = e2.X_add_number;
3540 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3541 if (e1.X_op == O_register)
3543 if (e2.X_op == O_constant)
3545 switch (reg1)
3547 case REG_AR + AR_BSP:
3548 add_unwind_entry (output_bsp_when ());
3549 add_unwind_entry ((psprel
3550 ? output_bsp_psprel
3551 : output_bsp_sprel) (val));
3552 break;
3553 case REG_AR + AR_BSPSTORE:
3554 add_unwind_entry (output_bspstore_when ());
3555 add_unwind_entry ((psprel
3556 ? output_bspstore_psprel
3557 : output_bspstore_sprel) (val));
3558 break;
3559 case REG_AR + AR_RNAT:
3560 add_unwind_entry (output_rnat_when ());
3561 add_unwind_entry ((psprel
3562 ? output_rnat_psprel
3563 : output_rnat_sprel) (val));
3564 break;
3565 case REG_AR + AR_UNAT:
3566 add_unwind_entry (output_unat_when ());
3567 add_unwind_entry ((psprel
3568 ? output_unat_psprel
3569 : output_unat_sprel) (val));
3570 break;
3571 case REG_AR + AR_FPSR:
3572 add_unwind_entry (output_fpsr_when ());
3573 add_unwind_entry ((psprel
3574 ? output_fpsr_psprel
3575 : output_fpsr_sprel) (val));
3576 break;
3577 case REG_AR + AR_PFS:
3578 add_unwind_entry (output_pfs_when ());
3579 add_unwind_entry ((psprel
3580 ? output_pfs_psprel
3581 : output_pfs_sprel) (val));
3582 break;
3583 case REG_AR + AR_LC:
3584 add_unwind_entry (output_lc_when ());
3585 add_unwind_entry ((psprel
3586 ? output_lc_psprel
3587 : output_lc_sprel) (val));
3588 break;
3589 case REG_BR:
3590 add_unwind_entry (output_rp_when ());
3591 add_unwind_entry ((psprel
3592 ? output_rp_psprel
3593 : output_rp_sprel) (val));
3594 break;
3595 case REG_PR:
3596 add_unwind_entry (output_preds_when ());
3597 add_unwind_entry ((psprel
3598 ? output_preds_psprel
3599 : output_preds_sprel) (val));
3600 break;
3601 case REG_PRIUNAT:
3602 add_unwind_entry (output_priunat_when_mem ());
3603 add_unwind_entry ((psprel
3604 ? output_priunat_psprel
3605 : output_priunat_sprel) (val));
3606 break;
3607 default:
3608 as_bad ("First operand not a valid register");
3611 else
3612 as_bad (" Second operand not a valid constant");
3614 else
3615 as_bad ("First operand not a register");
3618 static void
3619 dot_saveg (dummy)
3620 int dummy ATTRIBUTE_UNUSED;
3622 expressionS e1, e2;
3623 int sep;
3624 sep = parse_operand (&e1);
3625 if (sep == ',')
3626 parse_operand (&e2);
3628 if (e1.X_op != O_constant)
3629 as_bad ("First operand to .save.g must be a constant.");
3630 else
3632 int grmask = e1.X_add_number;
3633 if (sep != ',')
3634 add_unwind_entry (output_gr_mem (grmask));
3635 else
3637 int reg = e2.X_add_number - REG_GR;
3638 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3639 add_unwind_entry (output_gr_gr (grmask, reg));
3640 else
3641 as_bad ("Second operand is an invalid register.");
3646 static void
3647 dot_savef (dummy)
3648 int dummy ATTRIBUTE_UNUSED;
3650 expressionS e1;
3651 int sep;
3652 sep = parse_operand (&e1);
3654 if (e1.X_op != O_constant)
3655 as_bad ("Operand to .save.f must be a constant.");
3656 else
3657 add_unwind_entry (output_fr_mem (e1.X_add_number));
3660 static void
3661 dot_saveb (dummy)
3662 int dummy ATTRIBUTE_UNUSED;
3664 expressionS e1, e2;
3665 unsigned int reg;
3666 unsigned char sep;
3667 int brmask;
3669 sep = parse_operand (&e1);
3670 if (e1.X_op != O_constant)
3672 as_bad ("First operand to .save.b must be a constant.");
3673 return;
3675 brmask = e1.X_add_number;
3677 if (sep == ',')
3679 sep = parse_operand (&e2);
3680 reg = e2.X_add_number - REG_GR;
3681 if (e2.X_op != O_register || reg > 127)
3683 as_bad ("Second operand to .save.b must be a general register.");
3684 return;
3686 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3688 else
3689 add_unwind_entry (output_br_mem (brmask));
3691 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3692 demand_empty_rest_of_line ();
3695 static void
3696 dot_savegf (dummy)
3697 int dummy ATTRIBUTE_UNUSED;
3699 expressionS e1, e2;
3700 int sep;
3701 sep = parse_operand (&e1);
3702 if (sep == ',')
3703 parse_operand (&e2);
3705 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3706 as_bad ("Both operands of .save.gf must be constants.");
3707 else
3709 int grmask = e1.X_add_number;
3710 int frmask = e2.X_add_number;
3711 add_unwind_entry (output_frgr_mem (grmask, frmask));
3715 static void
3716 dot_spill (dummy)
3717 int dummy ATTRIBUTE_UNUSED;
3719 expressionS e;
3720 unsigned char sep;
3722 sep = parse_operand (&e);
3723 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3724 demand_empty_rest_of_line ();
3726 if (e.X_op != O_constant)
3727 as_bad ("Operand to .spill must be a constant");
3728 else
3729 add_unwind_entry (output_spill_base (e.X_add_number));
3732 static void
3733 dot_spillreg (dummy)
3734 int dummy ATTRIBUTE_UNUSED;
3736 int sep, ab, xy, reg, treg;
3737 expressionS e1, e2;
3739 sep = parse_operand (&e1);
3740 if (sep != ',')
3742 as_bad ("No second operand to .spillreg");
3743 return;
3746 parse_operand (&e2);
3748 if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3750 as_bad ("First operand to .spillreg must be a preserved register");
3751 return;
3754 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3756 as_bad ("Second operand to .spillreg must be a register");
3757 return;
3760 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3763 static void
3764 dot_spillmem (psprel)
3765 int psprel;
3767 expressionS e1, e2;
3768 int sep, ab, reg;
3770 sep = parse_operand (&e1);
3771 if (sep != ',')
3773 as_bad ("Second operand missing");
3774 return;
3777 parse_operand (&e2);
3779 if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3781 as_bad ("First operand to .spill%s must be a preserved register",
3782 psprel ? "psp" : "sp");
3783 return;
3786 if (e2.X_op != O_constant)
3788 as_bad ("Second operand to .spill%s must be a constant",
3789 psprel ? "psp" : "sp");
3790 return;
3793 if (psprel)
3794 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3795 else
3796 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3799 static void
3800 dot_spillreg_p (dummy)
3801 int dummy ATTRIBUTE_UNUSED;
3803 int sep, ab, xy, reg, treg;
3804 expressionS e1, e2, e3;
3805 unsigned int qp;
3807 sep = parse_operand (&e1);
3808 if (sep != ',')
3810 as_bad ("No second and third operand to .spillreg.p");
3811 return;
3814 sep = parse_operand (&e2);
3815 if (sep != ',')
3817 as_bad ("No third operand to .spillreg.p");
3818 return;
3821 parse_operand (&e3);
3823 qp = e1.X_add_number - REG_P;
3825 if (e1.X_op != O_register || qp > 63)
3827 as_bad ("First operand to .spillreg.p must be a predicate");
3828 return;
3831 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
3833 as_bad ("Second operand to .spillreg.p must be a preserved register");
3834 return;
3837 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
3839 as_bad ("Third operand to .spillreg.p must be a register");
3840 return;
3843 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
3846 static void
3847 dot_spillmem_p (psprel)
3848 int psprel;
3850 expressionS e1, e2, e3;
3851 int sep, ab, reg;
3852 unsigned int qp;
3854 sep = parse_operand (&e1);
3855 if (sep != ',')
3857 as_bad ("Second operand missing");
3858 return;
3861 parse_operand (&e2);
3862 if (sep != ',')
3864 as_bad ("Second operand missing");
3865 return;
3868 parse_operand (&e3);
3870 qp = e1.X_add_number - REG_P;
3871 if (e1.X_op != O_register || qp > 63)
3873 as_bad ("First operand to .spill%s_p must be a predicate",
3874 psprel ? "psp" : "sp");
3875 return;
3878 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
3880 as_bad ("Second operand to .spill%s_p must be a preserved register",
3881 psprel ? "psp" : "sp");
3882 return;
3885 if (e3.X_op != O_constant)
3887 as_bad ("Third operand to .spill%s_p must be a constant",
3888 psprel ? "psp" : "sp");
3889 return;
3892 if (psprel)
3893 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
3894 else
3895 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
3898 static unsigned int
3899 get_saved_prologue_count (lbl)
3900 unsigned long lbl;
3902 label_prologue_count *lpc = unwind.saved_prologue_counts;
3904 while (lpc != NULL && lpc->label_number != lbl)
3905 lpc = lpc->next;
3907 if (lpc != NULL)
3908 return lpc->prologue_count;
3910 as_bad ("Missing .label_state %ld", lbl);
3911 return 1;
3914 static void
3915 save_prologue_count (lbl, count)
3916 unsigned long lbl;
3917 unsigned int count;
3919 label_prologue_count *lpc = unwind.saved_prologue_counts;
3921 while (lpc != NULL && lpc->label_number != lbl)
3922 lpc = lpc->next;
3924 if (lpc != NULL)
3925 lpc->prologue_count = count;
3926 else
3928 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
3930 new_lpc->next = unwind.saved_prologue_counts;
3931 new_lpc->label_number = lbl;
3932 new_lpc->prologue_count = count;
3933 unwind.saved_prologue_counts = new_lpc;
3937 static void
3938 free_saved_prologue_counts ()
3940 label_prologue_count *lpc = unwind.saved_prologue_counts;
3941 label_prologue_count *next;
3943 while (lpc != NULL)
3945 next = lpc->next;
3946 free (lpc);
3947 lpc = next;
3950 unwind.saved_prologue_counts = NULL;
3953 static void
3954 dot_label_state (dummy)
3955 int dummy ATTRIBUTE_UNUSED;
3957 expressionS e;
3959 parse_operand (&e);
3960 if (e.X_op != O_constant)
3962 as_bad ("Operand to .label_state must be a constant");
3963 return;
3965 add_unwind_entry (output_label_state (e.X_add_number));
3966 save_prologue_count (e.X_add_number, unwind.prologue_count);
3969 static void
3970 dot_copy_state (dummy)
3971 int dummy ATTRIBUTE_UNUSED;
3973 expressionS e;
3975 parse_operand (&e);
3976 if (e.X_op != O_constant)
3978 as_bad ("Operand to .copy_state must be a constant");
3979 return;
3981 add_unwind_entry (output_copy_state (e.X_add_number));
3982 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
3985 static void
3986 dot_unwabi (dummy)
3987 int dummy ATTRIBUTE_UNUSED;
3989 expressionS e1, e2;
3990 unsigned char sep;
3992 sep = parse_operand (&e1);
3993 if (sep != ',')
3995 as_bad ("Second operand to .unwabi missing");
3996 return;
3998 sep = parse_operand (&e2);
3999 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4000 demand_empty_rest_of_line ();
4002 if (e1.X_op != O_constant)
4004 as_bad ("First operand to .unwabi must be a constant");
4005 return;
4008 if (e2.X_op != O_constant)
4010 as_bad ("Second operand to .unwabi must be a constant");
4011 return;
4014 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4017 static void
4018 dot_personality (dummy)
4019 int dummy ATTRIBUTE_UNUSED;
4021 char *name, *p, c;
4022 SKIP_WHITESPACE ();
4023 name = input_line_pointer;
4024 c = get_symbol_end ();
4025 p = input_line_pointer;
4026 unwind.personality_routine = symbol_find_or_make (name);
4027 unwind.force_unwind_entry = 1;
4028 *p = c;
4029 SKIP_WHITESPACE ();
4030 demand_empty_rest_of_line ();
4033 static void
4034 dot_proc (dummy)
4035 int dummy ATTRIBUTE_UNUSED;
4037 char *name, *p, c;
4038 symbolS *sym;
4040 unwind.proc_start = expr_build_dot ();
4041 /* Parse names of main and alternate entry points and mark them as
4042 function symbols: */
4043 while (1)
4045 SKIP_WHITESPACE ();
4046 name = input_line_pointer;
4047 c = get_symbol_end ();
4048 p = input_line_pointer;
4049 sym = symbol_find_or_make (name);
4050 if (unwind.proc_start == 0)
4052 unwind.proc_start = sym;
4054 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4055 *p = c;
4056 SKIP_WHITESPACE ();
4057 if (*input_line_pointer != ',')
4058 break;
4059 ++input_line_pointer;
4061 demand_empty_rest_of_line ();
4062 ia64_do_align (16);
4064 unwind.prologue_count = 0;
4065 unwind.list = unwind.tail = unwind.current_entry = NULL;
4066 unwind.personality_routine = 0;
4069 static void
4070 dot_body (dummy)
4071 int dummy ATTRIBUTE_UNUSED;
4073 unwind.prologue = 0;
4074 unwind.prologue_mask = 0;
4076 add_unwind_entry (output_body ());
4077 demand_empty_rest_of_line ();
4080 static void
4081 dot_prologue (dummy)
4082 int dummy ATTRIBUTE_UNUSED;
4084 unsigned char sep;
4085 int mask = 0, grsave = 0;
4087 if (!is_it_end_of_statement ())
4089 expressionS e1, e2;
4090 sep = parse_operand (&e1);
4091 if (sep != ',')
4092 as_bad ("No second operand to .prologue");
4093 sep = parse_operand (&e2);
4094 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4095 demand_empty_rest_of_line ();
4097 if (e1.X_op == O_constant)
4099 mask = e1.X_add_number;
4101 if (e2.X_op == O_constant)
4102 grsave = e2.X_add_number;
4103 else if (e2.X_op == O_register
4104 && (grsave = e2.X_add_number - REG_GR) < 128)
4106 else
4107 as_bad ("Second operand not a constant or general register");
4109 add_unwind_entry (output_prologue_gr (mask, grsave));
4111 else
4112 as_bad ("First operand not a constant");
4114 else
4115 add_unwind_entry (output_prologue ());
4117 unwind.prologue = 1;
4118 unwind.prologue_mask = mask;
4119 ++unwind.prologue_count;
4122 static void
4123 dot_endp (dummy)
4124 int dummy ATTRIBUTE_UNUSED;
4126 expressionS e;
4127 unsigned char *ptr;
4128 int bytes_per_address;
4129 long where;
4130 segT saved_seg;
4131 subsegT saved_subseg;
4132 char *name, *p, c;
4133 symbolS *sym;
4135 if (unwind.saved_text_seg)
4137 saved_seg = unwind.saved_text_seg;
4138 saved_subseg = unwind.saved_text_subseg;
4139 unwind.saved_text_seg = NULL;
4141 else
4143 saved_seg = now_seg;
4144 saved_subseg = now_subseg;
4147 insn_group_break (1, 0, 0);
4149 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4150 if (!unwind.info)
4151 generate_unwind_image (saved_seg);
4153 if (unwind.info || unwind.force_unwind_entry)
4155 subseg_set (md.last_text_seg, 0);
4156 unwind.proc_end = expr_build_dot ();
4158 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND);
4160 /* Make sure that section has 4 byte alignment for ILP32 and
4161 8 byte alignment for LP64. */
4162 record_alignment (now_seg, md.pointer_size_shift);
4164 /* Need space for 3 pointers for procedure start, procedure end,
4165 and unwind info. */
4166 ptr = frag_more (3 * md.pointer_size);
4167 where = frag_now_fix () - (3 * md.pointer_size);
4168 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4170 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4171 e.X_op = O_pseudo_fixup;
4172 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4173 e.X_add_number = 0;
4174 e.X_add_symbol = unwind.proc_start;
4175 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4177 e.X_op = O_pseudo_fixup;
4178 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4179 e.X_add_number = 0;
4180 e.X_add_symbol = unwind.proc_end;
4181 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4182 bytes_per_address, &e);
4184 if (unwind.info)
4186 e.X_op = O_pseudo_fixup;
4187 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4188 e.X_add_number = 0;
4189 e.X_add_symbol = unwind.info;
4190 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4191 bytes_per_address, &e);
4193 else
4194 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4195 bytes_per_address);
4198 subseg_set (saved_seg, saved_subseg);
4200 /* Parse names of main and alternate entry points and set symbol sizes. */
4201 while (1)
4203 SKIP_WHITESPACE ();
4204 name = input_line_pointer;
4205 c = get_symbol_end ();
4206 p = input_line_pointer;
4207 sym = symbol_find (name);
4208 if (sym && unwind.proc_start
4209 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4210 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4212 fragS *fr = symbol_get_frag (unwind.proc_start);
4213 fragS *frag = symbol_get_frag (sym);
4215 /* Check whether the function label is at or beyond last
4216 .proc directive. */
4217 while (fr && fr != frag)
4218 fr = fr->fr_next;
4219 if (fr)
4221 if (frag == frag_now && SEG_NORMAL (now_seg))
4222 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4223 else
4225 symbol_get_obj (sym)->size =
4226 (expressionS *) xmalloc (sizeof (expressionS));
4227 symbol_get_obj (sym)->size->X_op = O_subtract;
4228 symbol_get_obj (sym)->size->X_add_symbol
4229 = symbol_new (FAKE_LABEL_NAME, now_seg,
4230 frag_now_fix (), frag_now);
4231 symbol_get_obj (sym)->size->X_op_symbol = sym;
4232 symbol_get_obj (sym)->size->X_add_number = 0;
4236 *p = c;
4237 SKIP_WHITESPACE ();
4238 if (*input_line_pointer != ',')
4239 break;
4240 ++input_line_pointer;
4242 demand_empty_rest_of_line ();
4243 unwind.proc_start = unwind.proc_end = unwind.info = 0;
4246 static void
4247 dot_template (template)
4248 int template;
4250 CURR_SLOT.user_template = template;
4253 static void
4254 dot_regstk (dummy)
4255 int dummy ATTRIBUTE_UNUSED;
4257 int ins, locs, outs, rots;
4259 if (is_it_end_of_statement ())
4260 ins = locs = outs = rots = 0;
4261 else
4263 ins = get_absolute_expression ();
4264 if (*input_line_pointer++ != ',')
4265 goto err;
4266 locs = get_absolute_expression ();
4267 if (*input_line_pointer++ != ',')
4268 goto err;
4269 outs = get_absolute_expression ();
4270 if (*input_line_pointer++ != ',')
4271 goto err;
4272 rots = get_absolute_expression ();
4274 set_regstack (ins, locs, outs, rots);
4275 return;
4277 err:
4278 as_bad ("Comma expected");
4279 ignore_rest_of_line ();
4282 static void
4283 dot_rot (type)
4284 int type;
4286 unsigned num_regs, num_alloced = 0;
4287 struct dynreg **drpp, *dr;
4288 int ch, base_reg = 0;
4289 char *name, *start;
4290 size_t len;
4292 switch (type)
4294 case DYNREG_GR: base_reg = REG_GR + 32; break;
4295 case DYNREG_FR: base_reg = REG_FR + 32; break;
4296 case DYNREG_PR: base_reg = REG_P + 16; break;
4297 default: break;
4300 /* First, remove existing names from hash table. */
4301 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4303 hash_delete (md.dynreg_hash, dr->name);
4304 dr->num_regs = 0;
4307 drpp = &md.dynreg[type];
4308 while (1)
4310 start = input_line_pointer;
4311 ch = get_symbol_end ();
4312 *input_line_pointer = ch;
4313 len = (input_line_pointer - start);
4315 SKIP_WHITESPACE ();
4316 if (*input_line_pointer != '[')
4318 as_bad ("Expected '['");
4319 goto err;
4321 ++input_line_pointer; /* skip '[' */
4323 num_regs = get_absolute_expression ();
4325 if (*input_line_pointer++ != ']')
4327 as_bad ("Expected ']'");
4328 goto err;
4330 SKIP_WHITESPACE ();
4332 num_alloced += num_regs;
4333 switch (type)
4335 case DYNREG_GR:
4336 if (num_alloced > md.rot.num_regs)
4338 as_bad ("Used more than the declared %d rotating registers",
4339 md.rot.num_regs);
4340 goto err;
4342 break;
4343 case DYNREG_FR:
4344 if (num_alloced > 96)
4346 as_bad ("Used more than the available 96 rotating registers");
4347 goto err;
4349 break;
4350 case DYNREG_PR:
4351 if (num_alloced > 48)
4353 as_bad ("Used more than the available 48 rotating registers");
4354 goto err;
4356 break;
4358 default:
4359 break;
4362 name = obstack_alloc (&notes, len + 1);
4363 memcpy (name, start, len);
4364 name[len] = '\0';
4366 if (!*drpp)
4368 *drpp = obstack_alloc (&notes, sizeof (*dr));
4369 memset (*drpp, 0, sizeof (*dr));
4372 dr = *drpp;
4373 dr->name = name;
4374 dr->num_regs = num_regs;
4375 dr->base = base_reg;
4376 drpp = &dr->next;
4377 base_reg += num_regs;
4379 if (hash_insert (md.dynreg_hash, name, dr))
4381 as_bad ("Attempt to redefine register set `%s'", name);
4382 goto err;
4385 if (*input_line_pointer != ',')
4386 break;
4387 ++input_line_pointer; /* skip comma */
4388 SKIP_WHITESPACE ();
4390 demand_empty_rest_of_line ();
4391 return;
4393 err:
4394 ignore_rest_of_line ();
4397 static void
4398 dot_byteorder (byteorder)
4399 int byteorder;
4401 segment_info_type *seginfo = seg_info (now_seg);
4403 if (byteorder == -1)
4405 if (seginfo->tc_segment_info_data.endian == 0)
4406 seginfo->tc_segment_info_data.endian
4407 = TARGET_BYTES_BIG_ENDIAN ? 1 : 2;
4408 byteorder = seginfo->tc_segment_info_data.endian == 1;
4410 else
4411 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4413 if (target_big_endian != byteorder)
4415 target_big_endian = byteorder;
4416 if (target_big_endian)
4418 ia64_number_to_chars = number_to_chars_bigendian;
4419 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4421 else
4423 ia64_number_to_chars = number_to_chars_littleendian;
4424 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4429 static void
4430 dot_psr (dummy)
4431 int dummy ATTRIBUTE_UNUSED;
4433 char *option;
4434 int ch;
4436 while (1)
4438 option = input_line_pointer;
4439 ch = get_symbol_end ();
4440 if (strcmp (option, "lsb") == 0)
4441 md.flags &= ~EF_IA_64_BE;
4442 else if (strcmp (option, "msb") == 0)
4443 md.flags |= EF_IA_64_BE;
4444 else if (strcmp (option, "abi32") == 0)
4445 md.flags &= ~EF_IA_64_ABI64;
4446 else if (strcmp (option, "abi64") == 0)
4447 md.flags |= EF_IA_64_ABI64;
4448 else
4449 as_bad ("Unknown psr option `%s'", option);
4450 *input_line_pointer = ch;
4452 SKIP_WHITESPACE ();
4453 if (*input_line_pointer != ',')
4454 break;
4456 ++input_line_pointer;
4457 SKIP_WHITESPACE ();
4459 demand_empty_rest_of_line ();
4462 static void
4463 dot_ln (dummy)
4464 int dummy ATTRIBUTE_UNUSED;
4466 new_logical_line (0, get_absolute_expression ());
4467 demand_empty_rest_of_line ();
4470 static char *
4471 parse_section_name ()
4473 char *name;
4474 int len;
4476 SKIP_WHITESPACE ();
4477 if (*input_line_pointer != '"')
4479 as_bad ("Missing section name");
4480 ignore_rest_of_line ();
4481 return 0;
4483 name = demand_copy_C_string (&len);
4484 if (!name)
4486 ignore_rest_of_line ();
4487 return 0;
4489 SKIP_WHITESPACE ();
4490 if (*input_line_pointer != ',')
4492 as_bad ("Comma expected after section name");
4493 ignore_rest_of_line ();
4494 return 0;
4496 ++input_line_pointer; /* skip comma */
4497 return name;
4500 static void
4501 dot_xdata (size)
4502 int size;
4504 char *name = parse_section_name ();
4505 if (!name)
4506 return;
4508 md.keep_pending_output = 1;
4509 set_section (name);
4510 cons (size);
4511 obj_elf_previous (0);
4512 md.keep_pending_output = 0;
4515 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4517 static void
4518 stmt_float_cons (kind)
4519 int kind;
4521 size_t alignment;
4523 switch (kind)
4525 case 'd':
4526 alignment = 8;
4527 break;
4529 case 'x':
4530 case 'X':
4531 alignment = 16;
4532 break;
4534 case 'f':
4535 default:
4536 alignment = 4;
4537 break;
4539 ia64_do_align (alignment);
4540 float_cons (kind);
4543 static void
4544 stmt_cons_ua (size)
4545 int size;
4547 int saved_auto_align = md.auto_align;
4549 md.auto_align = 0;
4550 cons (size);
4551 md.auto_align = saved_auto_align;
4554 static void
4555 dot_xfloat_cons (kind)
4556 int kind;
4558 char *name = parse_section_name ();
4559 if (!name)
4560 return;
4562 md.keep_pending_output = 1;
4563 set_section (name);
4564 stmt_float_cons (kind);
4565 obj_elf_previous (0);
4566 md.keep_pending_output = 0;
4569 static void
4570 dot_xstringer (zero)
4571 int zero;
4573 char *name = parse_section_name ();
4574 if (!name)
4575 return;
4577 md.keep_pending_output = 1;
4578 set_section (name);
4579 stringer (zero);
4580 obj_elf_previous (0);
4581 md.keep_pending_output = 0;
4584 static void
4585 dot_xdata_ua (size)
4586 int size;
4588 int saved_auto_align = md.auto_align;
4589 char *name = parse_section_name ();
4590 if (!name)
4591 return;
4593 md.keep_pending_output = 1;
4594 set_section (name);
4595 md.auto_align = 0;
4596 cons (size);
4597 md.auto_align = saved_auto_align;
4598 obj_elf_previous (0);
4599 md.keep_pending_output = 0;
4602 static void
4603 dot_xfloat_cons_ua (kind)
4604 int kind;
4606 int saved_auto_align = md.auto_align;
4607 char *name = parse_section_name ();
4608 if (!name)
4609 return;
4611 md.keep_pending_output = 1;
4612 set_section (name);
4613 md.auto_align = 0;
4614 stmt_float_cons (kind);
4615 md.auto_align = saved_auto_align;
4616 obj_elf_previous (0);
4617 md.keep_pending_output = 0;
4620 /* .reg.val <regname>,value */
4622 static void
4623 dot_reg_val (dummy)
4624 int dummy ATTRIBUTE_UNUSED;
4626 expressionS reg;
4628 expression (&reg);
4629 if (reg.X_op != O_register)
4631 as_bad (_("Register name expected"));
4632 ignore_rest_of_line ();
4634 else if (*input_line_pointer++ != ',')
4636 as_bad (_("Comma expected"));
4637 ignore_rest_of_line ();
4639 else
4641 valueT value = get_absolute_expression ();
4642 int regno = reg.X_add_number;
4643 if (regno < REG_GR || regno > REG_GR + 128)
4644 as_warn (_("Register value annotation ignored"));
4645 else
4647 gr_values[regno - REG_GR].known = 1;
4648 gr_values[regno - REG_GR].value = value;
4649 gr_values[regno - REG_GR].path = md.path;
4652 demand_empty_rest_of_line ();
4656 .serialize.data
4657 .serialize.instruction
4659 static void
4660 dot_serialize (type)
4661 int type;
4663 insn_group_break (0, 0, 0);
4664 if (type)
4665 instruction_serialization ();
4666 else
4667 data_serialization ();
4668 insn_group_break (0, 0, 0);
4669 demand_empty_rest_of_line ();
4672 /* select dv checking mode
4673 .auto
4674 .explicit
4675 .default
4677 A stop is inserted when changing modes
4680 static void
4681 dot_dv_mode (type)
4682 int type;
4684 if (md.manual_bundling)
4685 as_warn (_("Directive invalid within a bundle"));
4687 if (type == 'E' || type == 'A')
4688 md.mode_explicitly_set = 0;
4689 else
4690 md.mode_explicitly_set = 1;
4692 md.detect_dv = 1;
4693 switch (type)
4695 case 'A':
4696 case 'a':
4697 if (md.explicit_mode)
4698 insn_group_break (1, 0, 0);
4699 md.explicit_mode = 0;
4700 break;
4701 case 'E':
4702 case 'e':
4703 if (!md.explicit_mode)
4704 insn_group_break (1, 0, 0);
4705 md.explicit_mode = 1;
4706 break;
4707 default:
4708 case 'd':
4709 if (md.explicit_mode != md.default_explicit_mode)
4710 insn_group_break (1, 0, 0);
4711 md.explicit_mode = md.default_explicit_mode;
4712 md.mode_explicitly_set = 0;
4713 break;
4717 static void
4718 print_prmask (mask)
4719 valueT mask;
4721 int regno;
4722 char *comma = "";
4723 for (regno = 0; regno < 64; regno++)
4725 if (mask & ((valueT) 1 << regno))
4727 fprintf (stderr, "%s p%d", comma, regno);
4728 comma = ",";
4734 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
4735 .pred.rel.imply p1, p2 (also .pred.rel "imply")
4736 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
4737 .pred.safe_across_calls p1 [, p2 [,...]]
4740 static void
4741 dot_pred_rel (type)
4742 int type;
4744 valueT mask = 0;
4745 int count = 0;
4746 int p1 = -1, p2 = -1;
4748 if (type == 0)
4750 if (*input_line_pointer != '"')
4752 as_bad (_("Missing predicate relation type"));
4753 ignore_rest_of_line ();
4754 return;
4756 else
4758 int len;
4759 char *form = demand_copy_C_string (&len);
4760 if (strcmp (form, "mutex") == 0)
4761 type = 'm';
4762 else if (strcmp (form, "clear") == 0)
4763 type = 'c';
4764 else if (strcmp (form, "imply") == 0)
4765 type = 'i';
4766 else
4768 as_bad (_("Unrecognized predicate relation type"));
4769 ignore_rest_of_line ();
4770 return;
4773 if (*input_line_pointer == ',')
4774 ++input_line_pointer;
4775 SKIP_WHITESPACE ();
4778 SKIP_WHITESPACE ();
4779 while (1)
4781 valueT bit = 1;
4782 int regno;
4784 if (TOUPPER (*input_line_pointer) != 'P'
4785 || (regno = atoi (++input_line_pointer)) < 0
4786 || regno > 63)
4788 as_bad (_("Predicate register expected"));
4789 ignore_rest_of_line ();
4790 return;
4792 while (ISDIGIT (*input_line_pointer))
4793 ++input_line_pointer;
4794 if (p1 == -1)
4795 p1 = regno;
4796 else if (p2 == -1)
4797 p2 = regno;
4798 bit <<= regno;
4799 if (mask & bit)
4800 as_warn (_("Duplicate predicate register ignored"));
4801 mask |= bit;
4802 count++;
4803 /* See if it's a range. */
4804 if (*input_line_pointer == '-')
4806 valueT stop = 1;
4807 ++input_line_pointer;
4809 if (TOUPPER (*input_line_pointer) != 'P'
4810 || (regno = atoi (++input_line_pointer)) < 0
4811 || regno > 63)
4813 as_bad (_("Predicate register expected"));
4814 ignore_rest_of_line ();
4815 return;
4817 while (ISDIGIT (*input_line_pointer))
4818 ++input_line_pointer;
4819 stop <<= regno;
4820 if (bit >= stop)
4822 as_bad (_("Bad register range"));
4823 ignore_rest_of_line ();
4824 return;
4826 while (bit < stop)
4828 bit <<= 1;
4829 mask |= bit;
4830 count++;
4832 SKIP_WHITESPACE ();
4834 if (*input_line_pointer != ',')
4835 break;
4836 ++input_line_pointer;
4837 SKIP_WHITESPACE ();
4840 switch (type)
4842 case 'c':
4843 if (count == 0)
4844 mask = ~(valueT) 0;
4845 clear_qp_mutex (mask);
4846 clear_qp_implies (mask, (valueT) 0);
4847 break;
4848 case 'i':
4849 if (count != 2 || p1 == -1 || p2 == -1)
4850 as_bad (_("Predicate source and target required"));
4851 else if (p1 == 0 || p2 == 0)
4852 as_bad (_("Use of p0 is not valid in this context"));
4853 else
4854 add_qp_imply (p1, p2);
4855 break;
4856 case 'm':
4857 if (count < 2)
4859 as_bad (_("At least two PR arguments expected"));
4860 break;
4862 else if (mask & 1)
4864 as_bad (_("Use of p0 is not valid in this context"));
4865 break;
4867 add_qp_mutex (mask);
4868 break;
4869 case 's':
4870 /* note that we don't override any existing relations */
4871 if (count == 0)
4873 as_bad (_("At least one PR argument expected"));
4874 break;
4876 if (md.debug_dv)
4878 fprintf (stderr, "Safe across calls: ");
4879 print_prmask (mask);
4880 fprintf (stderr, "\n");
4882 qp_safe_across_calls = mask;
4883 break;
4885 demand_empty_rest_of_line ();
4888 /* .entry label [, label [, ...]]
4889 Hint to DV code that the given labels are to be considered entry points.
4890 Otherwise, only global labels are considered entry points. */
4892 static void
4893 dot_entry (dummy)
4894 int dummy ATTRIBUTE_UNUSED;
4896 const char *err;
4897 char *name;
4898 int c;
4899 symbolS *symbolP;
4903 name = input_line_pointer;
4904 c = get_symbol_end ();
4905 symbolP = symbol_find_or_make (name);
4907 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
4908 if (err)
4909 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
4910 name, err);
4912 *input_line_pointer = c;
4913 SKIP_WHITESPACE ();
4914 c = *input_line_pointer;
4915 if (c == ',')
4917 input_line_pointer++;
4918 SKIP_WHITESPACE ();
4919 if (*input_line_pointer == '\n')
4920 c = '\n';
4923 while (c == ',');
4925 demand_empty_rest_of_line ();
4928 /* .mem.offset offset, base
4929 "base" is used to distinguish between offsets from a different base. */
4931 static void
4932 dot_mem_offset (dummy)
4933 int dummy ATTRIBUTE_UNUSED;
4935 md.mem_offset.hint = 1;
4936 md.mem_offset.offset = get_absolute_expression ();
4937 if (*input_line_pointer != ',')
4939 as_bad (_("Comma expected"));
4940 ignore_rest_of_line ();
4941 return;
4943 ++input_line_pointer;
4944 md.mem_offset.base = get_absolute_expression ();
4945 demand_empty_rest_of_line ();
4948 /* ia64-specific pseudo-ops: */
4949 const pseudo_typeS md_pseudo_table[] =
4951 { "radix", dot_radix, 0 },
4952 { "lcomm", s_lcomm_bytes, 1 },
4953 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
4954 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
4955 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
4956 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
4957 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
4958 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
4959 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
4960 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
4961 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
4962 { "proc", dot_proc, 0 },
4963 { "body", dot_body, 0 },
4964 { "prologue", dot_prologue, 0 },
4965 { "endp", dot_endp, 0 },
4967 { "fframe", dot_fframe, 0 },
4968 { "vframe", dot_vframe, 0 },
4969 { "vframesp", dot_vframesp, 0 },
4970 { "vframepsp", dot_vframepsp, 0 },
4971 { "save", dot_save, 0 },
4972 { "restore", dot_restore, 0 },
4973 { "restorereg", dot_restorereg, 0 },
4974 { "restorereg.p", dot_restorereg_p, 0 },
4975 { "handlerdata", dot_handlerdata, 0 },
4976 { "unwentry", dot_unwentry, 0 },
4977 { "altrp", dot_altrp, 0 },
4978 { "savesp", dot_savemem, 0 },
4979 { "savepsp", dot_savemem, 1 },
4980 { "save.g", dot_saveg, 0 },
4981 { "save.f", dot_savef, 0 },
4982 { "save.b", dot_saveb, 0 },
4983 { "save.gf", dot_savegf, 0 },
4984 { "spill", dot_spill, 0 },
4985 { "spillreg", dot_spillreg, 0 },
4986 { "spillsp", dot_spillmem, 0 },
4987 { "spillpsp", dot_spillmem, 1 },
4988 { "spillreg.p", dot_spillreg_p, 0 },
4989 { "spillsp.p", dot_spillmem_p, 0 },
4990 { "spillpsp.p", dot_spillmem_p, 1 },
4991 { "label_state", dot_label_state, 0 },
4992 { "copy_state", dot_copy_state, 0 },
4993 { "unwabi", dot_unwabi, 0 },
4994 { "personality", dot_personality, 0 },
4995 #if 0
4996 { "estate", dot_estate, 0 },
4997 #endif
4998 { "mii", dot_template, 0x0 },
4999 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5000 { "mlx", dot_template, 0x2 },
5001 { "mmi", dot_template, 0x4 },
5002 { "mfi", dot_template, 0x6 },
5003 { "mmf", dot_template, 0x7 },
5004 { "mib", dot_template, 0x8 },
5005 { "mbb", dot_template, 0x9 },
5006 { "bbb", dot_template, 0xb },
5007 { "mmb", dot_template, 0xc },
5008 { "mfb", dot_template, 0xe },
5009 #if 0
5010 { "lb", dot_scope, 0 },
5011 { "le", dot_scope, 1 },
5012 #endif
5013 { "align", dot_align, 0 },
5014 { "regstk", dot_regstk, 0 },
5015 { "rotr", dot_rot, DYNREG_GR },
5016 { "rotf", dot_rot, DYNREG_FR },
5017 { "rotp", dot_rot, DYNREG_PR },
5018 { "lsb", dot_byteorder, 0 },
5019 { "msb", dot_byteorder, 1 },
5020 { "psr", dot_psr, 0 },
5021 { "alias", dot_alias, 0 },
5022 { "secalias", dot_alias, 1 },
5023 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5025 { "xdata1", dot_xdata, 1 },
5026 { "xdata2", dot_xdata, 2 },
5027 { "xdata4", dot_xdata, 4 },
5028 { "xdata8", dot_xdata, 8 },
5029 { "xreal4", dot_xfloat_cons, 'f' },
5030 { "xreal8", dot_xfloat_cons, 'd' },
5031 { "xreal10", dot_xfloat_cons, 'x' },
5032 { "xreal16", dot_xfloat_cons, 'X' },
5033 { "xstring", dot_xstringer, 0 },
5034 { "xstringz", dot_xstringer, 1 },
5036 /* unaligned versions: */
5037 { "xdata2.ua", dot_xdata_ua, 2 },
5038 { "xdata4.ua", dot_xdata_ua, 4 },
5039 { "xdata8.ua", dot_xdata_ua, 8 },
5040 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5041 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5042 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5043 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5045 /* annotations/DV checking support */
5046 { "entry", dot_entry, 0 },
5047 { "mem.offset", dot_mem_offset, 0 },
5048 { "pred.rel", dot_pred_rel, 0 },
5049 { "pred.rel.clear", dot_pred_rel, 'c' },
5050 { "pred.rel.imply", dot_pred_rel, 'i' },
5051 { "pred.rel.mutex", dot_pred_rel, 'm' },
5052 { "pred.safe_across_calls", dot_pred_rel, 's' },
5053 { "reg.val", dot_reg_val, 0 },
5054 { "serialize.data", dot_serialize, 0 },
5055 { "serialize.instruction", dot_serialize, 1 },
5056 { "auto", dot_dv_mode, 'a' },
5057 { "explicit", dot_dv_mode, 'e' },
5058 { "default", dot_dv_mode, 'd' },
5060 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5061 IA-64 aligns data allocation pseudo-ops by default, so we have to
5062 tell it that these ones are supposed to be unaligned. Long term,
5063 should rewrite so that only IA-64 specific data allocation pseudo-ops
5064 are aligned by default. */
5065 {"2byte", stmt_cons_ua, 2},
5066 {"4byte", stmt_cons_ua, 4},
5067 {"8byte", stmt_cons_ua, 8},
5069 { NULL, 0, 0 }
5072 static const struct pseudo_opcode
5074 const char *name;
5075 void (*handler) (int);
5076 int arg;
5078 pseudo_opcode[] =
5080 /* these are more like pseudo-ops, but don't start with a dot */
5081 { "data1", cons, 1 },
5082 { "data2", cons, 2 },
5083 { "data4", cons, 4 },
5084 { "data8", cons, 8 },
5085 { "data16", cons, 16 },
5086 { "real4", stmt_float_cons, 'f' },
5087 { "real8", stmt_float_cons, 'd' },
5088 { "real10", stmt_float_cons, 'x' },
5089 { "real16", stmt_float_cons, 'X' },
5090 { "string", stringer, 0 },
5091 { "stringz", stringer, 1 },
5093 /* unaligned versions: */
5094 { "data2.ua", stmt_cons_ua, 2 },
5095 { "data4.ua", stmt_cons_ua, 4 },
5096 { "data8.ua", stmt_cons_ua, 8 },
5097 { "data16.ua", stmt_cons_ua, 16 },
5098 { "real4.ua", float_cons, 'f' },
5099 { "real8.ua", float_cons, 'd' },
5100 { "real10.ua", float_cons, 'x' },
5101 { "real16.ua", float_cons, 'X' },
5104 /* Declare a register by creating a symbol for it and entering it in
5105 the symbol table. */
5107 static symbolS *
5108 declare_register (name, regnum)
5109 const char *name;
5110 int regnum;
5112 const char *err;
5113 symbolS *sym;
5115 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5117 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5118 if (err)
5119 as_fatal ("Inserting \"%s\" into register table failed: %s",
5120 name, err);
5122 return sym;
5125 static void
5126 declare_register_set (prefix, num_regs, base_regnum)
5127 const char *prefix;
5128 int num_regs;
5129 int base_regnum;
5131 char name[8];
5132 int i;
5134 for (i = 0; i < num_regs; ++i)
5136 sprintf (name, "%s%u", prefix, i);
5137 declare_register (name, base_regnum + i);
5141 static unsigned int
5142 operand_width (opnd)
5143 enum ia64_opnd opnd;
5145 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5146 unsigned int bits = 0;
5147 int i;
5149 bits = 0;
5150 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5151 bits += odesc->field[i].bits;
5153 return bits;
5156 static enum operand_match_result
5157 operand_match (idesc, index, e)
5158 const struct ia64_opcode *idesc;
5159 int index;
5160 expressionS *e;
5162 enum ia64_opnd opnd = idesc->operands[index];
5163 int bits, relocatable = 0;
5164 struct insn_fix *fix;
5165 bfd_signed_vma val;
5167 switch (opnd)
5169 /* constants: */
5171 case IA64_OPND_AR_CCV:
5172 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5173 return OPERAND_MATCH;
5174 break;
5176 case IA64_OPND_AR_CSD:
5177 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5178 return OPERAND_MATCH;
5179 break;
5181 case IA64_OPND_AR_PFS:
5182 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5183 return OPERAND_MATCH;
5184 break;
5186 case IA64_OPND_GR0:
5187 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5188 return OPERAND_MATCH;
5189 break;
5191 case IA64_OPND_IP:
5192 if (e->X_op == O_register && e->X_add_number == REG_IP)
5193 return OPERAND_MATCH;
5194 break;
5196 case IA64_OPND_PR:
5197 if (e->X_op == O_register && e->X_add_number == REG_PR)
5198 return OPERAND_MATCH;
5199 break;
5201 case IA64_OPND_PR_ROT:
5202 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5203 return OPERAND_MATCH;
5204 break;
5206 case IA64_OPND_PSR:
5207 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5208 return OPERAND_MATCH;
5209 break;
5211 case IA64_OPND_PSR_L:
5212 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5213 return OPERAND_MATCH;
5214 break;
5216 case IA64_OPND_PSR_UM:
5217 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5218 return OPERAND_MATCH;
5219 break;
5221 case IA64_OPND_C1:
5222 if (e->X_op == O_constant)
5224 if (e->X_add_number == 1)
5225 return OPERAND_MATCH;
5226 else
5227 return OPERAND_OUT_OF_RANGE;
5229 break;
5231 case IA64_OPND_C8:
5232 if (e->X_op == O_constant)
5234 if (e->X_add_number == 8)
5235 return OPERAND_MATCH;
5236 else
5237 return OPERAND_OUT_OF_RANGE;
5239 break;
5241 case IA64_OPND_C16:
5242 if (e->X_op == O_constant)
5244 if (e->X_add_number == 16)
5245 return OPERAND_MATCH;
5246 else
5247 return OPERAND_OUT_OF_RANGE;
5249 break;
5251 /* register operands: */
5253 case IA64_OPND_AR3:
5254 if (e->X_op == O_register && e->X_add_number >= REG_AR
5255 && e->X_add_number < REG_AR + 128)
5256 return OPERAND_MATCH;
5257 break;
5259 case IA64_OPND_B1:
5260 case IA64_OPND_B2:
5261 if (e->X_op == O_register && e->X_add_number >= REG_BR
5262 && e->X_add_number < REG_BR + 8)
5263 return OPERAND_MATCH;
5264 break;
5266 case IA64_OPND_CR3:
5267 if (e->X_op == O_register && e->X_add_number >= REG_CR
5268 && e->X_add_number < REG_CR + 128)
5269 return OPERAND_MATCH;
5270 break;
5272 case IA64_OPND_F1:
5273 case IA64_OPND_F2:
5274 case IA64_OPND_F3:
5275 case IA64_OPND_F4:
5276 if (e->X_op == O_register && e->X_add_number >= REG_FR
5277 && e->X_add_number < REG_FR + 128)
5278 return OPERAND_MATCH;
5279 break;
5281 case IA64_OPND_P1:
5282 case IA64_OPND_P2:
5283 if (e->X_op == O_register && e->X_add_number >= REG_P
5284 && e->X_add_number < REG_P + 64)
5285 return OPERAND_MATCH;
5286 break;
5288 case IA64_OPND_R1:
5289 case IA64_OPND_R2:
5290 case IA64_OPND_R3:
5291 if (e->X_op == O_register && e->X_add_number >= REG_GR
5292 && e->X_add_number < REG_GR + 128)
5293 return OPERAND_MATCH;
5294 break;
5296 case IA64_OPND_R3_2:
5297 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5299 if (e->X_add_number < REG_GR + 4)
5300 return OPERAND_MATCH;
5301 else if (e->X_add_number < REG_GR + 128)
5302 return OPERAND_OUT_OF_RANGE;
5304 break;
5306 /* indirect operands: */
5307 case IA64_OPND_CPUID_R3:
5308 case IA64_OPND_DBR_R3:
5309 case IA64_OPND_DTR_R3:
5310 case IA64_OPND_ITR_R3:
5311 case IA64_OPND_IBR_R3:
5312 case IA64_OPND_MSR_R3:
5313 case IA64_OPND_PKR_R3:
5314 case IA64_OPND_PMC_R3:
5315 case IA64_OPND_PMD_R3:
5316 case IA64_OPND_RR_R3:
5317 if (e->X_op == O_index && e->X_op_symbol
5318 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5319 == opnd - IA64_OPND_CPUID_R3))
5320 return OPERAND_MATCH;
5321 break;
5323 case IA64_OPND_MR3:
5324 if (e->X_op == O_index && !e->X_op_symbol)
5325 return OPERAND_MATCH;
5326 break;
5328 /* immediate operands: */
5329 case IA64_OPND_CNT2a:
5330 case IA64_OPND_LEN4:
5331 case IA64_OPND_LEN6:
5332 bits = operand_width (idesc->operands[index]);
5333 if (e->X_op == O_constant)
5335 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5336 return OPERAND_MATCH;
5337 else
5338 return OPERAND_OUT_OF_RANGE;
5340 break;
5342 case IA64_OPND_CNT2b:
5343 if (e->X_op == O_constant)
5345 if ((bfd_vma) (e->X_add_number - 1) < 3)
5346 return OPERAND_MATCH;
5347 else
5348 return OPERAND_OUT_OF_RANGE;
5350 break;
5352 case IA64_OPND_CNT2c:
5353 val = e->X_add_number;
5354 if (e->X_op == O_constant)
5356 if ((val == 0 || val == 7 || val == 15 || val == 16))
5357 return OPERAND_MATCH;
5358 else
5359 return OPERAND_OUT_OF_RANGE;
5361 break;
5363 case IA64_OPND_SOR:
5364 /* SOR must be an integer multiple of 8 */
5365 if (e->X_op == O_constant && e->X_add_number & 0x7)
5366 return OPERAND_OUT_OF_RANGE;
5367 case IA64_OPND_SOF:
5368 case IA64_OPND_SOL:
5369 if (e->X_op == O_constant)
5371 if ((bfd_vma) e->X_add_number <= 96)
5372 return OPERAND_MATCH;
5373 else
5374 return OPERAND_OUT_OF_RANGE;
5376 break;
5378 case IA64_OPND_IMMU62:
5379 if (e->X_op == O_constant)
5381 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5382 return OPERAND_MATCH;
5383 else
5384 return OPERAND_OUT_OF_RANGE;
5386 else
5388 /* FIXME -- need 62-bit relocation type */
5389 as_bad (_("62-bit relocation not yet implemented"));
5391 break;
5393 case IA64_OPND_IMMU64:
5394 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5395 || e->X_op == O_subtract)
5397 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5398 fix->code = BFD_RELOC_IA64_IMM64;
5399 if (e->X_op != O_subtract)
5401 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5402 if (e->X_op == O_pseudo_fixup)
5403 e->X_op = O_symbol;
5406 fix->opnd = idesc->operands[index];
5407 fix->expr = *e;
5408 fix->is_pcrel = 0;
5409 ++CURR_SLOT.num_fixups;
5410 return OPERAND_MATCH;
5412 else if (e->X_op == O_constant)
5413 return OPERAND_MATCH;
5414 break;
5416 case IA64_OPND_CCNT5:
5417 case IA64_OPND_CNT5:
5418 case IA64_OPND_CNT6:
5419 case IA64_OPND_CPOS6a:
5420 case IA64_OPND_CPOS6b:
5421 case IA64_OPND_CPOS6c:
5422 case IA64_OPND_IMMU2:
5423 case IA64_OPND_IMMU7a:
5424 case IA64_OPND_IMMU7b:
5425 case IA64_OPND_IMMU21:
5426 case IA64_OPND_IMMU24:
5427 case IA64_OPND_MBTYPE4:
5428 case IA64_OPND_MHTYPE8:
5429 case IA64_OPND_POS6:
5430 bits = operand_width (idesc->operands[index]);
5431 if (e->X_op == O_constant)
5433 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5434 return OPERAND_MATCH;
5435 else
5436 return OPERAND_OUT_OF_RANGE;
5438 break;
5440 case IA64_OPND_IMMU9:
5441 bits = operand_width (idesc->operands[index]);
5442 if (e->X_op == O_constant)
5444 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5446 int lobits = e->X_add_number & 0x3;
5447 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5448 e->X_add_number |= (bfd_vma) 0x3;
5449 return OPERAND_MATCH;
5451 else
5452 return OPERAND_OUT_OF_RANGE;
5454 break;
5456 case IA64_OPND_IMM44:
5457 /* least 16 bits must be zero */
5458 if ((e->X_add_number & 0xffff) != 0)
5459 /* XXX technically, this is wrong: we should not be issuing warning
5460 messages until we're sure this instruction pattern is going to
5461 be used! */
5462 as_warn (_("lower 16 bits of mask ignored"));
5464 if (e->X_op == O_constant)
5466 if (((e->X_add_number >= 0
5467 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5468 || (e->X_add_number < 0
5469 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5471 /* sign-extend */
5472 if (e->X_add_number >= 0
5473 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5475 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5477 return OPERAND_MATCH;
5479 else
5480 return OPERAND_OUT_OF_RANGE;
5482 break;
5484 case IA64_OPND_IMM17:
5485 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5486 if (e->X_op == O_constant)
5488 if (((e->X_add_number >= 0
5489 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5490 || (e->X_add_number < 0
5491 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5493 /* sign-extend */
5494 if (e->X_add_number >= 0
5495 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5497 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5499 return OPERAND_MATCH;
5501 else
5502 return OPERAND_OUT_OF_RANGE;
5504 break;
5506 case IA64_OPND_IMM14:
5507 case IA64_OPND_IMM22:
5508 relocatable = 1;
5509 case IA64_OPND_IMM1:
5510 case IA64_OPND_IMM8:
5511 case IA64_OPND_IMM8U4:
5512 case IA64_OPND_IMM8M1:
5513 case IA64_OPND_IMM8M1U4:
5514 case IA64_OPND_IMM8M1U8:
5515 case IA64_OPND_IMM9a:
5516 case IA64_OPND_IMM9b:
5517 bits = operand_width (idesc->operands[index]);
5518 if (relocatable && (e->X_op == O_symbol
5519 || e->X_op == O_subtract
5520 || e->X_op == O_pseudo_fixup))
5522 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5524 if (idesc->operands[index] == IA64_OPND_IMM14)
5525 fix->code = BFD_RELOC_IA64_IMM14;
5526 else
5527 fix->code = BFD_RELOC_IA64_IMM22;
5529 if (e->X_op != O_subtract)
5531 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5532 if (e->X_op == O_pseudo_fixup)
5533 e->X_op = O_symbol;
5536 fix->opnd = idesc->operands[index];
5537 fix->expr = *e;
5538 fix->is_pcrel = 0;
5539 ++CURR_SLOT.num_fixups;
5540 return OPERAND_MATCH;
5542 else if (e->X_op != O_constant
5543 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5544 return OPERAND_MISMATCH;
5546 if (opnd == IA64_OPND_IMM8M1U4)
5548 /* Zero is not valid for unsigned compares that take an adjusted
5549 constant immediate range. */
5550 if (e->X_add_number == 0)
5551 return OPERAND_OUT_OF_RANGE;
5553 /* Sign-extend 32-bit unsigned numbers, so that the following range
5554 checks will work. */
5555 val = e->X_add_number;
5556 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5557 && ((val & ((bfd_vma) 1 << 31)) != 0))
5558 val = ((val << 32) >> 32);
5560 /* Check for 0x100000000. This is valid because
5561 0x100000000-1 is the same as ((uint32_t) -1). */
5562 if (val == ((bfd_signed_vma) 1 << 32))
5563 return OPERAND_MATCH;
5565 val = val - 1;
5567 else if (opnd == IA64_OPND_IMM8M1U8)
5569 /* Zero is not valid for unsigned compares that take an adjusted
5570 constant immediate range. */
5571 if (e->X_add_number == 0)
5572 return OPERAND_OUT_OF_RANGE;
5574 /* Check for 0x10000000000000000. */
5575 if (e->X_op == O_big)
5577 if (generic_bignum[0] == 0
5578 && generic_bignum[1] == 0
5579 && generic_bignum[2] == 0
5580 && generic_bignum[3] == 0
5581 && generic_bignum[4] == 1)
5582 return OPERAND_MATCH;
5583 else
5584 return OPERAND_OUT_OF_RANGE;
5586 else
5587 val = e->X_add_number - 1;
5589 else if (opnd == IA64_OPND_IMM8M1)
5590 val = e->X_add_number - 1;
5591 else if (opnd == IA64_OPND_IMM8U4)
5593 /* Sign-extend 32-bit unsigned numbers, so that the following range
5594 checks will work. */
5595 val = e->X_add_number;
5596 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5597 && ((val & ((bfd_vma) 1 << 31)) != 0))
5598 val = ((val << 32) >> 32);
5600 else
5601 val = e->X_add_number;
5603 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5604 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5605 return OPERAND_MATCH;
5606 else
5607 return OPERAND_OUT_OF_RANGE;
5609 case IA64_OPND_INC3:
5610 /* +/- 1, 4, 8, 16 */
5611 val = e->X_add_number;
5612 if (val < 0)
5613 val = -val;
5614 if (e->X_op == O_constant)
5616 if ((val == 1 || val == 4 || val == 8 || val == 16))
5617 return OPERAND_MATCH;
5618 else
5619 return OPERAND_OUT_OF_RANGE;
5621 break;
5623 case IA64_OPND_TGT25:
5624 case IA64_OPND_TGT25b:
5625 case IA64_OPND_TGT25c:
5626 case IA64_OPND_TGT64:
5627 if (e->X_op == O_symbol)
5629 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5630 if (opnd == IA64_OPND_TGT25)
5631 fix->code = BFD_RELOC_IA64_PCREL21F;
5632 else if (opnd == IA64_OPND_TGT25b)
5633 fix->code = BFD_RELOC_IA64_PCREL21M;
5634 else if (opnd == IA64_OPND_TGT25c)
5635 fix->code = BFD_RELOC_IA64_PCREL21B;
5636 else if (opnd == IA64_OPND_TGT64)
5637 fix->code = BFD_RELOC_IA64_PCREL60B;
5638 else
5639 abort ();
5641 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5642 fix->opnd = idesc->operands[index];
5643 fix->expr = *e;
5644 fix->is_pcrel = 1;
5645 ++CURR_SLOT.num_fixups;
5646 return OPERAND_MATCH;
5648 case IA64_OPND_TAG13:
5649 case IA64_OPND_TAG13b:
5650 switch (e->X_op)
5652 case O_constant:
5653 return OPERAND_MATCH;
5655 case O_symbol:
5656 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5657 /* There are no external relocs for TAG13/TAG13b fields, so we
5658 create a dummy reloc. This will not live past md_apply_fix3. */
5659 fix->code = BFD_RELOC_UNUSED;
5660 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5661 fix->opnd = idesc->operands[index];
5662 fix->expr = *e;
5663 fix->is_pcrel = 1;
5664 ++CURR_SLOT.num_fixups;
5665 return OPERAND_MATCH;
5667 default:
5668 break;
5670 break;
5672 case IA64_OPND_LDXMOV:
5673 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5674 fix->code = BFD_RELOC_IA64_LDXMOV;
5675 fix->opnd = idesc->operands[index];
5676 fix->expr = *e;
5677 fix->is_pcrel = 0;
5678 ++CURR_SLOT.num_fixups;
5679 return OPERAND_MATCH;
5681 default:
5682 break;
5684 return OPERAND_MISMATCH;
5687 static int
5688 parse_operand (e)
5689 expressionS *e;
5691 int sep = '\0';
5693 memset (e, 0, sizeof (*e));
5694 e->X_op = O_absent;
5695 SKIP_WHITESPACE ();
5696 if (*input_line_pointer != '}')
5697 expression (e);
5698 sep = *input_line_pointer++;
5700 if (sep == '}')
5702 if (!md.manual_bundling)
5703 as_warn ("Found '}' when manual bundling is off");
5704 else
5705 CURR_SLOT.manual_bundling_off = 1;
5706 md.manual_bundling = 0;
5707 sep = '\0';
5709 return sep;
5712 /* Returns the next entry in the opcode table that matches the one in
5713 IDESC, and frees the entry in IDESC. If no matching entry is
5714 found, NULL is returned instead. */
5716 static struct ia64_opcode *
5717 get_next_opcode (struct ia64_opcode *idesc)
5719 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
5720 ia64_free_opcode (idesc);
5721 return next;
5724 /* Parse the operands for the opcode and find the opcode variant that
5725 matches the specified operands, or NULL if no match is possible. */
5727 static struct ia64_opcode *
5728 parse_operands (idesc)
5729 struct ia64_opcode *idesc;
5731 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
5732 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
5733 enum ia64_opnd expected_operand = IA64_OPND_NIL;
5734 enum operand_match_result result;
5735 char mnemonic[129];
5736 char *first_arg = 0, *end, *saved_input_pointer;
5737 unsigned int sof;
5739 assert (strlen (idesc->name) <= 128);
5741 strcpy (mnemonic, idesc->name);
5742 if (idesc->operands[2] == IA64_OPND_SOF)
5744 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
5745 can't parse the first operand until we have parsed the
5746 remaining operands of the "alloc" instruction. */
5747 SKIP_WHITESPACE ();
5748 first_arg = input_line_pointer;
5749 end = strchr (input_line_pointer, '=');
5750 if (!end)
5752 as_bad ("Expected separator `='");
5753 return 0;
5755 input_line_pointer = end + 1;
5756 ++i;
5757 ++num_outputs;
5760 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
5762 sep = parse_operand (CURR_SLOT.opnd + i);
5763 if (CURR_SLOT.opnd[i].X_op == O_absent)
5764 break;
5766 ++num_operands;
5768 if (sep != '=' && sep != ',')
5769 break;
5771 if (sep == '=')
5773 if (num_outputs > 0)
5774 as_bad ("Duplicate equal sign (=) in instruction");
5775 else
5776 num_outputs = i + 1;
5779 if (sep != '\0')
5781 as_bad ("Illegal operand separator `%c'", sep);
5782 return 0;
5785 if (idesc->operands[2] == IA64_OPND_SOF)
5787 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
5788 know (strcmp (idesc->name, "alloc") == 0);
5789 if (num_operands == 5 /* first_arg not included in this count! */
5790 && CURR_SLOT.opnd[2].X_op == O_constant
5791 && CURR_SLOT.opnd[3].X_op == O_constant
5792 && CURR_SLOT.opnd[4].X_op == O_constant
5793 && CURR_SLOT.opnd[5].X_op == O_constant)
5795 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
5796 CURR_SLOT.opnd[3].X_add_number,
5797 CURR_SLOT.opnd[4].X_add_number,
5798 CURR_SLOT.opnd[5].X_add_number);
5800 /* now we can parse the first arg: */
5801 saved_input_pointer = input_line_pointer;
5802 input_line_pointer = first_arg;
5803 sep = parse_operand (CURR_SLOT.opnd + 0);
5804 if (sep != '=')
5805 --num_outputs; /* force error */
5806 input_line_pointer = saved_input_pointer;
5808 CURR_SLOT.opnd[2].X_add_number = sof;
5809 CURR_SLOT.opnd[3].X_add_number
5810 = sof - CURR_SLOT.opnd[4].X_add_number;
5811 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
5815 highest_unmatched_operand = 0;
5816 curr_out_of_range_pos = -1;
5817 error_pos = 0;
5818 expected_operand = idesc->operands[0];
5819 for (; idesc; idesc = get_next_opcode (idesc))
5821 if (num_outputs != idesc->num_outputs)
5822 continue; /* mismatch in # of outputs */
5824 CURR_SLOT.num_fixups = 0;
5826 /* Try to match all operands. If we see an out-of-range operand,
5827 then continue trying to match the rest of the operands, since if
5828 the rest match, then this idesc will give the best error message. */
5830 out_of_range_pos = -1;
5831 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
5833 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
5834 if (result != OPERAND_MATCH)
5836 if (result != OPERAND_OUT_OF_RANGE)
5837 break;
5838 if (out_of_range_pos < 0)
5839 /* remember position of the first out-of-range operand: */
5840 out_of_range_pos = i;
5844 /* If we did not match all operands, or if at least one operand was
5845 out-of-range, then this idesc does not match. Keep track of which
5846 idesc matched the most operands before failing. If we have two
5847 idescs that failed at the same position, and one had an out-of-range
5848 operand, then prefer the out-of-range operand. Thus if we have
5849 "add r0=0x1000000,r1" we get an error saying the constant is out
5850 of range instead of an error saying that the constant should have been
5851 a register. */
5853 if (i != num_operands || out_of_range_pos >= 0)
5855 if (i > highest_unmatched_operand
5856 || (i == highest_unmatched_operand
5857 && out_of_range_pos > curr_out_of_range_pos))
5859 highest_unmatched_operand = i;
5860 if (out_of_range_pos >= 0)
5862 expected_operand = idesc->operands[out_of_range_pos];
5863 error_pos = out_of_range_pos;
5865 else
5867 expected_operand = idesc->operands[i];
5868 error_pos = i;
5870 curr_out_of_range_pos = out_of_range_pos;
5872 continue;
5875 if (num_operands < NELEMS (idesc->operands)
5876 && idesc->operands[num_operands])
5877 continue; /* mismatch in number of arguments */
5879 break;
5881 if (!idesc)
5883 if (expected_operand)
5884 as_bad ("Operand %u of `%s' should be %s",
5885 error_pos + 1, mnemonic,
5886 elf64_ia64_operands[expected_operand].desc);
5887 else
5888 as_bad ("Operand mismatch");
5889 return 0;
5891 return idesc;
5894 /* Keep track of state necessary to determine whether a NOP is necessary
5895 to avoid an erratum in A and B step Itanium chips, and return 1 if we
5896 detect a case where additional NOPs may be necessary. */
5897 static int
5898 errata_nop_necessary_p (slot, insn_unit)
5899 struct slot *slot;
5900 enum ia64_unit insn_unit;
5902 int i;
5903 struct group *this_group = md.last_groups + md.group_idx;
5904 struct group *prev_group = md.last_groups + (md.group_idx + 2) % 3;
5905 struct ia64_opcode *idesc = slot->idesc;
5907 /* Test whether this could be the first insn in a problematic sequence. */
5908 if (insn_unit == IA64_UNIT_F)
5910 for (i = 0; i < idesc->num_outputs; i++)
5911 if (idesc->operands[i] == IA64_OPND_P1
5912 || idesc->operands[i] == IA64_OPND_P2)
5914 int regno = slot->opnd[i].X_add_number - REG_P;
5915 /* Ignore invalid operands; they generate errors elsewhere. */
5916 if (regno >= 64)
5917 return 0;
5918 this_group->p_reg_set[regno] = 1;
5922 /* Test whether this could be the second insn in a problematic sequence. */
5923 if (insn_unit == IA64_UNIT_M && slot->qp_regno > 0
5924 && prev_group->p_reg_set[slot->qp_regno])
5926 for (i = 0; i < idesc->num_outputs; i++)
5927 if (idesc->operands[i] == IA64_OPND_R1
5928 || idesc->operands[i] == IA64_OPND_R2
5929 || idesc->operands[i] == IA64_OPND_R3)
5931 int regno = slot->opnd[i].X_add_number - REG_GR;
5932 /* Ignore invalid operands; they generate errors elsewhere. */
5933 if (regno >= 128)
5934 return 0;
5935 if (strncmp (idesc->name, "add", 3) != 0
5936 && strncmp (idesc->name, "sub", 3) != 0
5937 && strncmp (idesc->name, "shladd", 6) != 0
5938 && (idesc->flags & IA64_OPCODE_POSTINC) == 0)
5939 this_group->g_reg_set_conditionally[regno] = 1;
5943 /* Test whether this could be the third insn in a problematic sequence. */
5944 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; i++)
5946 if (/* For fc, ptc, ptr, tak, thash, tpa, ttag, probe, ptr, ptc. */
5947 idesc->operands[i] == IA64_OPND_R3
5948 /* For mov indirect. */
5949 || idesc->operands[i] == IA64_OPND_RR_R3
5950 || idesc->operands[i] == IA64_OPND_DBR_R3
5951 || idesc->operands[i] == IA64_OPND_IBR_R3
5952 || idesc->operands[i] == IA64_OPND_PKR_R3
5953 || idesc->operands[i] == IA64_OPND_PMC_R3
5954 || idesc->operands[i] == IA64_OPND_PMD_R3
5955 || idesc->operands[i] == IA64_OPND_MSR_R3
5956 || idesc->operands[i] == IA64_OPND_CPUID_R3
5957 /* For itr. */
5958 || idesc->operands[i] == IA64_OPND_ITR_R3
5959 || idesc->operands[i] == IA64_OPND_DTR_R3
5960 /* Normal memory addresses (load, store, xchg, cmpxchg, etc.). */
5961 || idesc->operands[i] == IA64_OPND_MR3)
5963 int regno = slot->opnd[i].X_add_number - REG_GR;
5964 /* Ignore invalid operands; they generate errors elsewhere. */
5965 if (regno >= 128)
5966 return 0;
5967 if (idesc->operands[i] == IA64_OPND_R3)
5969 if (strcmp (idesc->name, "fc") != 0
5970 && strcmp (idesc->name, "tak") != 0
5971 && strcmp (idesc->name, "thash") != 0
5972 && strcmp (idesc->name, "tpa") != 0
5973 && strcmp (idesc->name, "ttag") != 0
5974 && strncmp (idesc->name, "ptr", 3) != 0
5975 && strncmp (idesc->name, "ptc", 3) != 0
5976 && strncmp (idesc->name, "probe", 5) != 0)
5977 return 0;
5979 if (prev_group->g_reg_set_conditionally[regno])
5980 return 1;
5983 return 0;
5986 static void
5987 build_insn (slot, insnp)
5988 struct slot *slot;
5989 bfd_vma *insnp;
5991 const struct ia64_operand *odesc, *o2desc;
5992 struct ia64_opcode *idesc = slot->idesc;
5993 bfd_signed_vma insn, val;
5994 const char *err;
5995 int i;
5997 insn = idesc->opcode | slot->qp_regno;
5999 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6001 if (slot->opnd[i].X_op == O_register
6002 || slot->opnd[i].X_op == O_constant
6003 || slot->opnd[i].X_op == O_index)
6004 val = slot->opnd[i].X_add_number;
6005 else if (slot->opnd[i].X_op == O_big)
6007 /* This must be the value 0x10000000000000000. */
6008 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6009 val = 0;
6011 else
6012 val = 0;
6014 switch (idesc->operands[i])
6016 case IA64_OPND_IMMU64:
6017 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6018 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6019 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6020 | (((val >> 63) & 0x1) << 36));
6021 continue;
6023 case IA64_OPND_IMMU62:
6024 val &= 0x3fffffffffffffffULL;
6025 if (val != slot->opnd[i].X_add_number)
6026 as_warn (_("Value truncated to 62 bits"));
6027 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6028 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6029 continue;
6031 case IA64_OPND_TGT64:
6032 val >>= 4;
6033 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6034 insn |= ((((val >> 59) & 0x1) << 36)
6035 | (((val >> 0) & 0xfffff) << 13));
6036 continue;
6038 case IA64_OPND_AR3:
6039 val -= REG_AR;
6040 break;
6042 case IA64_OPND_B1:
6043 case IA64_OPND_B2:
6044 val -= REG_BR;
6045 break;
6047 case IA64_OPND_CR3:
6048 val -= REG_CR;
6049 break;
6051 case IA64_OPND_F1:
6052 case IA64_OPND_F2:
6053 case IA64_OPND_F3:
6054 case IA64_OPND_F4:
6055 val -= REG_FR;
6056 break;
6058 case IA64_OPND_P1:
6059 case IA64_OPND_P2:
6060 val -= REG_P;
6061 break;
6063 case IA64_OPND_R1:
6064 case IA64_OPND_R2:
6065 case IA64_OPND_R3:
6066 case IA64_OPND_R3_2:
6067 case IA64_OPND_CPUID_R3:
6068 case IA64_OPND_DBR_R3:
6069 case IA64_OPND_DTR_R3:
6070 case IA64_OPND_ITR_R3:
6071 case IA64_OPND_IBR_R3:
6072 case IA64_OPND_MR3:
6073 case IA64_OPND_MSR_R3:
6074 case IA64_OPND_PKR_R3:
6075 case IA64_OPND_PMC_R3:
6076 case IA64_OPND_PMD_R3:
6077 case IA64_OPND_RR_R3:
6078 val -= REG_GR;
6079 break;
6081 default:
6082 break;
6085 odesc = elf64_ia64_operands + idesc->operands[i];
6086 err = (*odesc->insert) (odesc, val, &insn);
6087 if (err)
6088 as_bad_where (slot->src_file, slot->src_line,
6089 "Bad operand value: %s", err);
6090 if (idesc->flags & IA64_OPCODE_PSEUDO)
6092 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6093 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6095 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6096 (*o2desc->insert) (o2desc, val, &insn);
6098 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6099 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6100 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6102 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6103 (*o2desc->insert) (o2desc, 64 - val, &insn);
6107 *insnp = insn;
6110 static void
6111 emit_one_bundle ()
6113 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
6114 unsigned int manual_bundling = 0;
6115 enum ia64_unit required_unit, insn_unit = 0;
6116 enum ia64_insn_type type[3], insn_type;
6117 unsigned int template, orig_template;
6118 bfd_vma insn[3] = { -1, -1, -1 };
6119 struct ia64_opcode *idesc;
6120 int end_of_insn_group = 0, user_template = -1;
6121 int n, i, j, first, curr;
6122 unw_rec_list *ptr, *last_ptr, *end_ptr;
6123 bfd_vma t0 = 0, t1 = 0;
6124 struct label_fix *lfix;
6125 struct insn_fix *ifix;
6126 char mnemonic[16];
6127 fixS *fix;
6128 char *f;
6130 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6131 know (first >= 0 & first < NUM_SLOTS);
6132 n = MIN (3, md.num_slots_in_use);
6134 /* Determine template: user user_template if specified, best match
6135 otherwise: */
6137 if (md.slot[first].user_template >= 0)
6138 user_template = template = md.slot[first].user_template;
6139 else
6141 /* Auto select appropriate template. */
6142 memset (type, 0, sizeof (type));
6143 curr = first;
6144 for (i = 0; i < n; ++i)
6146 if (md.slot[curr].label_fixups && i != 0)
6147 break;
6148 type[i] = md.slot[curr].idesc->type;
6149 curr = (curr + 1) % NUM_SLOTS;
6151 template = best_template[type[0]][type[1]][type[2]];
6154 /* initialize instructions with appropriate nops: */
6155 for (i = 0; i < 3; ++i)
6156 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6158 f = frag_more (16);
6160 /* now fill in slots with as many insns as possible: */
6161 curr = first;
6162 idesc = md.slot[curr].idesc;
6163 end_of_insn_group = 0;
6164 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6166 /* If we have unwind records, we may need to update some now. */
6167 ptr = md.slot[curr].unwind_record;
6168 if (ptr)
6170 /* Find the last prologue/body record in the list for the current
6171 insn, and set the slot number for all records up to that point.
6172 This needs to be done now, because prologue/body records refer to
6173 the current point, not the point after the instruction has been
6174 issued. This matters because there may have been nops emitted
6175 meanwhile. Any non-prologue non-body record followed by a
6176 prologue/body record must also refer to the current point. */
6177 last_ptr = NULL;
6178 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6179 for (; ptr != end_ptr; ptr = ptr->next)
6180 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6181 || ptr->r.type == body)
6182 last_ptr = ptr;
6183 if (last_ptr)
6185 /* Make last_ptr point one after the last prologue/body
6186 record. */
6187 last_ptr = last_ptr->next;
6188 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6189 ptr = ptr->next)
6191 ptr->slot_number = (unsigned long) f + i;
6192 ptr->slot_frag = frag_now;
6194 /* Remove the initialized records, so that we won't accidentally
6195 update them again if we insert a nop and continue. */
6196 md.slot[curr].unwind_record = last_ptr;
6200 if (idesc->flags & IA64_OPCODE_SLOT2)
6202 if (manual_bundling && i != 2)
6203 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6204 "`%s' must be last in bundle", idesc->name);
6205 else
6206 i = 2;
6208 if (idesc->flags & IA64_OPCODE_LAST)
6210 int required_slot;
6211 unsigned int required_template;
6213 /* If we need a stop bit after an M slot, our only choice is
6214 template 5 (M;;MI). If we need a stop bit after a B
6215 slot, our only choice is to place it at the end of the
6216 bundle, because the only available templates are MIB,
6217 MBB, BBB, MMB, and MFB. We don't handle anything other
6218 than M and B slots because these are the only kind of
6219 instructions that can have the IA64_OPCODE_LAST bit set. */
6220 required_template = template;
6221 switch (idesc->type)
6223 case IA64_TYPE_M:
6224 required_slot = 0;
6225 required_template = 5;
6226 break;
6228 case IA64_TYPE_B:
6229 required_slot = 2;
6230 break;
6232 default:
6233 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6234 "Internal error: don't know how to force %s to end"
6235 "of instruction group", idesc->name);
6236 required_slot = i;
6237 break;
6239 if (manual_bundling && i != required_slot)
6240 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6241 "`%s' must be last in instruction group",
6242 idesc->name);
6243 if (required_slot < i)
6244 /* Can't fit this instruction. */
6245 break;
6247 i = required_slot;
6248 if (required_template != template)
6250 /* If we switch the template, we need to reset the NOPs
6251 after slot i. The slot-types of the instructions ahead
6252 of i never change, so we don't need to worry about
6253 changing NOPs in front of this slot. */
6254 for (j = i; j < 3; ++j)
6255 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6257 template = required_template;
6259 if (curr != first && md.slot[curr].label_fixups)
6261 if (manual_bundling_on)
6262 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6263 "Label must be first in a bundle");
6264 /* This insn must go into the first slot of a bundle. */
6265 break;
6268 manual_bundling_on = md.slot[curr].manual_bundling_on;
6269 manual_bundling_off = md.slot[curr].manual_bundling_off;
6271 if (manual_bundling_on)
6273 if (curr == first)
6274 manual_bundling = 1;
6275 else
6276 break; /* need to start a new bundle */
6279 if (end_of_insn_group && md.num_slots_in_use >= 1)
6281 /* We need an instruction group boundary in the middle of a
6282 bundle. See if we can switch to an other template with
6283 an appropriate boundary. */
6285 orig_template = template;
6286 if (i == 1 && (user_template == 4
6287 || (user_template < 0
6288 && (ia64_templ_desc[template].exec_unit[0]
6289 == IA64_UNIT_M))))
6291 template = 5;
6292 end_of_insn_group = 0;
6294 else if (i == 2 && (user_template == 0
6295 || (user_template < 0
6296 && (ia64_templ_desc[template].exec_unit[1]
6297 == IA64_UNIT_I)))
6298 /* This test makes sure we don't switch the template if
6299 the next instruction is one that needs to be first in
6300 an instruction group. Since all those instructions are
6301 in the M group, there is no way such an instruction can
6302 fit in this bundle even if we switch the template. The
6303 reason we have to check for this is that otherwise we
6304 may end up generating "MI;;I M.." which has the deadly
6305 effect that the second M instruction is no longer the
6306 first in the bundle! --davidm 99/12/16 */
6307 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6309 template = 1;
6310 end_of_insn_group = 0;
6312 else if (curr != first)
6313 /* can't fit this insn */
6314 break;
6316 if (template != orig_template)
6317 /* if we switch the template, we need to reset the NOPs
6318 after slot i. The slot-types of the instructions ahead
6319 of i never change, so we don't need to worry about
6320 changing NOPs in front of this slot. */
6321 for (j = i; j < 3; ++j)
6322 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6324 required_unit = ia64_templ_desc[template].exec_unit[i];
6326 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6327 if (idesc->type == IA64_TYPE_DYN)
6329 if ((strcmp (idesc->name, "nop") == 0)
6330 || (strcmp (idesc->name, "hint") == 0)
6331 || (strcmp (idesc->name, "break") == 0))
6332 insn_unit = required_unit;
6333 else if (strcmp (idesc->name, "chk.s") == 0)
6335 insn_unit = IA64_UNIT_M;
6336 if (required_unit == IA64_UNIT_I)
6337 insn_unit = IA64_UNIT_I;
6339 else
6340 as_fatal ("emit_one_bundle: unexpected dynamic op");
6342 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
6343 ia64_free_opcode (idesc);
6344 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
6345 #if 0
6346 know (!idesc->next); /* no resolved dynamic ops have collisions */
6347 #endif
6349 else
6351 insn_type = idesc->type;
6352 insn_unit = IA64_UNIT_NIL;
6353 switch (insn_type)
6355 case IA64_TYPE_A:
6356 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6357 insn_unit = required_unit;
6358 break;
6359 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6360 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6361 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6362 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6363 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6364 default: break;
6368 if (insn_unit != required_unit)
6370 if (required_unit == IA64_UNIT_L
6371 && insn_unit == IA64_UNIT_I
6372 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
6374 /* we got ourselves an MLX template but the current
6375 instruction isn't an X-unit, or an I-unit instruction
6376 that can go into the X slot of an MLX template. Duh. */
6377 if (md.num_slots_in_use >= NUM_SLOTS)
6379 as_bad_where (md.slot[curr].src_file,
6380 md.slot[curr].src_line,
6381 "`%s' can't go in X slot of "
6382 "MLX template", idesc->name);
6383 /* drop this insn so we don't livelock: */
6384 --md.num_slots_in_use;
6386 break;
6388 continue; /* try next slot */
6392 bfd_vma addr;
6394 addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6395 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6398 if (errata_nop_necessary_p (md.slot + curr, insn_unit))
6399 as_warn (_("Additional NOP may be necessary to workaround Itanium processor A/B step errata"));
6401 build_insn (md.slot + curr, insn + i);
6403 ptr = md.slot[curr].unwind_record;
6404 if (ptr)
6406 /* Set slot numbers for all remaining unwind records belonging to the
6407 current insn. There can not be any prologue/body unwind records
6408 here. */
6409 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6410 for (; ptr != end_ptr; ptr = ptr->next)
6412 ptr->slot_number = (unsigned long) f + i;
6413 ptr->slot_frag = frag_now;
6415 md.slot[curr].unwind_record = NULL;
6418 if (required_unit == IA64_UNIT_L)
6420 know (i == 1);
6421 /* skip one slot for long/X-unit instructions */
6422 ++i;
6424 --md.num_slots_in_use;
6426 /* now is a good time to fix up the labels for this insn: */
6427 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6429 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6430 symbol_set_frag (lfix->sym, frag_now);
6432 /* and fix up the tags also. */
6433 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6435 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6436 symbol_set_frag (lfix->sym, frag_now);
6439 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6441 ifix = md.slot[curr].fixup + j;
6442 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6443 &ifix->expr, ifix->is_pcrel, ifix->code);
6444 fix->tc_fix_data.opnd = ifix->opnd;
6445 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6446 fix->fx_file = md.slot[curr].src_file;
6447 fix->fx_line = md.slot[curr].src_line;
6450 end_of_insn_group = md.slot[curr].end_of_insn_group;
6452 if (end_of_insn_group)
6454 md.group_idx = (md.group_idx + 1) % 3;
6455 memset (md.last_groups + md.group_idx, 0, sizeof md.last_groups[0]);
6458 /* clear slot: */
6459 ia64_free_opcode (md.slot[curr].idesc);
6460 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6461 md.slot[curr].user_template = -1;
6463 if (manual_bundling_off)
6465 manual_bundling = 0;
6466 break;
6468 curr = (curr + 1) % NUM_SLOTS;
6469 idesc = md.slot[curr].idesc;
6471 if (manual_bundling)
6473 if (md.num_slots_in_use > 0)
6474 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6475 "`%s' does not fit into %s template",
6476 idesc->name, ia64_templ_desc[template].name);
6477 else
6478 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6479 "Missing '}' at end of file");
6481 know (md.num_slots_in_use < NUM_SLOTS);
6483 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6484 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6486 number_to_chars_littleendian (f + 0, t0, 8);
6487 number_to_chars_littleendian (f + 8, t1, 8);
6489 if (unwind.list)
6491 unwind.list->next_slot_number = (unsigned long) f + 16;
6492 unwind.list->next_slot_frag = frag_now;
6497 md_parse_option (c, arg)
6498 int c;
6499 char *arg;
6502 switch (c)
6504 /* Switches from the Intel assembler. */
6505 case 'm':
6506 if (strcmp (arg, "ilp64") == 0
6507 || strcmp (arg, "lp64") == 0
6508 || strcmp (arg, "p64") == 0)
6510 md.flags |= EF_IA_64_ABI64;
6512 else if (strcmp (arg, "ilp32") == 0)
6514 md.flags &= ~EF_IA_64_ABI64;
6516 else if (strcmp (arg, "le") == 0)
6518 md.flags &= ~EF_IA_64_BE;
6520 else if (strcmp (arg, "be") == 0)
6522 md.flags |= EF_IA_64_BE;
6524 else
6525 return 0;
6526 break;
6528 case 'N':
6529 if (strcmp (arg, "so") == 0)
6531 /* Suppress signon message. */
6533 else if (strcmp (arg, "pi") == 0)
6535 /* Reject privileged instructions. FIXME */
6537 else if (strcmp (arg, "us") == 0)
6539 /* Allow union of signed and unsigned range. FIXME */
6541 else if (strcmp (arg, "close_fcalls") == 0)
6543 /* Do not resolve global function calls. */
6545 else
6546 return 0;
6547 break;
6549 case 'C':
6550 /* temp[="prefix"] Insert temporary labels into the object file
6551 symbol table prefixed by "prefix".
6552 Default prefix is ":temp:".
6554 break;
6556 case 'a':
6557 /* indirect=<tgt> Assume unannotated indirect branches behavior
6558 according to <tgt> --
6559 exit: branch out from the current context (default)
6560 labels: all labels in context may be branch targets
6562 if (strncmp (arg, "indirect=", 9) != 0)
6563 return 0;
6564 break;
6566 case 'x':
6567 /* -X conflicts with an ignored option, use -x instead */
6568 md.detect_dv = 1;
6569 if (!arg || strcmp (arg, "explicit") == 0)
6571 /* set default mode to explicit */
6572 md.default_explicit_mode = 1;
6573 break;
6575 else if (strcmp (arg, "auto") == 0)
6577 md.default_explicit_mode = 0;
6579 else if (strcmp (arg, "debug") == 0)
6581 md.debug_dv = 1;
6583 else if (strcmp (arg, "debugx") == 0)
6585 md.default_explicit_mode = 1;
6586 md.debug_dv = 1;
6588 else
6590 as_bad (_("Unrecognized option '-x%s'"), arg);
6592 break;
6594 case 'S':
6595 /* nops Print nops statistics. */
6596 break;
6598 /* GNU specific switches for gcc. */
6599 case OPTION_MCONSTANT_GP:
6600 md.flags |= EF_IA_64_CONS_GP;
6601 break;
6603 case OPTION_MAUTO_PIC:
6604 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
6605 break;
6607 default:
6608 return 0;
6611 return 1;
6614 void
6615 md_show_usage (stream)
6616 FILE *stream;
6618 fputs (_("\
6619 IA-64 options:\n\
6620 --mconstant-gp mark output file as using the constant-GP model\n\
6621 (sets ELF header flag EF_IA_64_CONS_GP)\n\
6622 --mauto-pic mark output file as using the constant-GP model\n\
6623 without function descriptors (sets ELF header flag\n\
6624 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
6625 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
6626 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
6627 -x | -xexplicit turn on dependency violation checking (default)\n\
6628 -xauto automagically remove dependency violations\n\
6629 -xdebug debug dependency violation checker\n"),
6630 stream);
6633 void
6634 ia64_after_parse_args ()
6636 if (debug_type == DEBUG_STABS)
6637 as_fatal (_("--gstabs is not supported for ia64"));
6640 /* Return true if TYPE fits in TEMPL at SLOT. */
6642 static int
6643 match (int templ, int type, int slot)
6645 enum ia64_unit unit;
6646 int result;
6648 unit = ia64_templ_desc[templ].exec_unit[slot];
6649 switch (type)
6651 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
6652 case IA64_TYPE_A:
6653 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
6654 break;
6655 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
6656 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
6657 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
6658 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
6659 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
6660 default: result = 0; break;
6662 return result;
6665 /* Add a bit of extra goodness if a nop of type F or B would fit
6666 in TEMPL at SLOT. */
6668 static inline int
6669 extra_goodness (int templ, int slot)
6671 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
6672 return 2;
6673 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
6674 return 1;
6675 return 0;
6678 /* This function is called once, at assembler startup time. It sets
6679 up all the tables, etc. that the MD part of the assembler will need
6680 that can be determined before arguments are parsed. */
6681 void
6682 md_begin ()
6684 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
6685 const char *err;
6686 char name[8];
6688 md.auto_align = 1;
6689 md.explicit_mode = md.default_explicit_mode;
6691 bfd_set_section_alignment (stdoutput, text_section, 4);
6693 /* Make sure function pointers get initialized. */
6694 target_big_endian = -1;
6695 dot_byteorder (TARGET_BYTES_BIG_ENDIAN);
6697 alias_hash = hash_new ();
6698 alias_name_hash = hash_new ();
6699 secalias_hash = hash_new ();
6700 secalias_name_hash = hash_new ();
6702 pseudo_func[FUNC_DTP_MODULE].u.sym =
6703 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
6704 &zero_address_frag);
6706 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
6707 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
6708 &zero_address_frag);
6710 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
6711 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
6712 &zero_address_frag);
6714 pseudo_func[FUNC_GP_RELATIVE].u.sym =
6715 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
6716 &zero_address_frag);
6718 pseudo_func[FUNC_LT_RELATIVE].u.sym =
6719 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
6720 &zero_address_frag);
6722 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
6723 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
6724 &zero_address_frag);
6726 pseudo_func[FUNC_PC_RELATIVE].u.sym =
6727 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
6728 &zero_address_frag);
6730 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
6731 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
6732 &zero_address_frag);
6734 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
6735 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
6736 &zero_address_frag);
6738 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
6739 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
6740 &zero_address_frag);
6742 pseudo_func[FUNC_TP_RELATIVE].u.sym =
6743 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
6744 &zero_address_frag);
6746 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
6747 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
6748 &zero_address_frag);
6750 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
6751 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
6752 &zero_address_frag);
6754 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
6755 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
6756 &zero_address_frag);
6758 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
6759 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
6760 &zero_address_frag);
6762 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
6763 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
6764 &zero_address_frag);
6766 pseudo_func[FUNC_IPLT_RELOC].u.sym =
6767 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
6768 &zero_address_frag);
6770 /* Compute the table of best templates. We compute goodness as a
6771 base 4 value, in which each match counts for 3, each F counts
6772 for 2, each B counts for 1. This should maximize the number of
6773 F and B nops in the chosen bundles, which is good because these
6774 pipelines are least likely to be overcommitted. */
6775 for (i = 0; i < IA64_NUM_TYPES; ++i)
6776 for (j = 0; j < IA64_NUM_TYPES; ++j)
6777 for (k = 0; k < IA64_NUM_TYPES; ++k)
6779 best = 0;
6780 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
6782 goodness = 0;
6783 if (match (t, i, 0))
6785 if (match (t, j, 1))
6787 if (match (t, k, 2))
6788 goodness = 3 + 3 + 3;
6789 else
6790 goodness = 3 + 3 + extra_goodness (t, 2);
6792 else if (match (t, j, 2))
6793 goodness = 3 + 3 + extra_goodness (t, 1);
6794 else
6796 goodness = 3;
6797 goodness += extra_goodness (t, 1);
6798 goodness += extra_goodness (t, 2);
6801 else if (match (t, i, 1))
6803 if (match (t, j, 2))
6804 goodness = 3 + 3;
6805 else
6806 goodness = 3 + extra_goodness (t, 2);
6808 else if (match (t, i, 2))
6809 goodness = 3 + extra_goodness (t, 1);
6811 if (goodness > best)
6813 best = goodness;
6814 best_template[i][j][k] = t;
6819 for (i = 0; i < NUM_SLOTS; ++i)
6820 md.slot[i].user_template = -1;
6822 md.pseudo_hash = hash_new ();
6823 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
6825 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
6826 (void *) (pseudo_opcode + i));
6827 if (err)
6828 as_fatal ("ia64.md_begin: can't hash `%s': %s",
6829 pseudo_opcode[i].name, err);
6832 md.reg_hash = hash_new ();
6833 md.dynreg_hash = hash_new ();
6834 md.const_hash = hash_new ();
6835 md.entry_hash = hash_new ();
6837 /* general registers: */
6839 total = 128;
6840 for (i = 0; i < total; ++i)
6842 sprintf (name, "r%d", i - REG_GR);
6843 md.regsym[i] = declare_register (name, i);
6846 /* floating point registers: */
6847 total += 128;
6848 for (; i < total; ++i)
6850 sprintf (name, "f%d", i - REG_FR);
6851 md.regsym[i] = declare_register (name, i);
6854 /* application registers: */
6855 total += 128;
6856 ar_base = i;
6857 for (; i < total; ++i)
6859 sprintf (name, "ar%d", i - REG_AR);
6860 md.regsym[i] = declare_register (name, i);
6863 /* control registers: */
6864 total += 128;
6865 cr_base = i;
6866 for (; i < total; ++i)
6868 sprintf (name, "cr%d", i - REG_CR);
6869 md.regsym[i] = declare_register (name, i);
6872 /* predicate registers: */
6873 total += 64;
6874 for (; i < total; ++i)
6876 sprintf (name, "p%d", i - REG_P);
6877 md.regsym[i] = declare_register (name, i);
6880 /* branch registers: */
6881 total += 8;
6882 for (; i < total; ++i)
6884 sprintf (name, "b%d", i - REG_BR);
6885 md.regsym[i] = declare_register (name, i);
6888 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
6889 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
6890 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
6891 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
6892 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
6893 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
6894 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
6896 for (i = 0; i < NELEMS (indirect_reg); ++i)
6898 regnum = indirect_reg[i].regnum;
6899 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
6902 /* define synonyms for application registers: */
6903 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
6904 md.regsym[i] = declare_register (ar[i - REG_AR].name,
6905 REG_AR + ar[i - REG_AR].regnum);
6907 /* define synonyms for control registers: */
6908 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
6909 md.regsym[i] = declare_register (cr[i - REG_CR].name,
6910 REG_CR + cr[i - REG_CR].regnum);
6912 declare_register ("gp", REG_GR + 1);
6913 declare_register ("sp", REG_GR + 12);
6914 declare_register ("rp", REG_BR + 0);
6916 /* pseudo-registers used to specify unwind info: */
6917 declare_register ("psp", REG_PSP);
6919 declare_register_set ("ret", 4, REG_GR + 8);
6920 declare_register_set ("farg", 8, REG_FR + 8);
6921 declare_register_set ("fret", 8, REG_FR + 8);
6923 for (i = 0; i < NELEMS (const_bits); ++i)
6925 err = hash_insert (md.const_hash, const_bits[i].name,
6926 (PTR) (const_bits + i));
6927 if (err)
6928 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
6929 name, err);
6932 /* Set the architecture and machine depending on defaults and command line
6933 options. */
6934 if (md.flags & EF_IA_64_ABI64)
6935 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
6936 else
6937 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
6939 if (! ok)
6940 as_warn (_("Could not set architecture and machine"));
6942 /* Set the pointer size and pointer shift size depending on md.flags */
6944 if (md.flags & EF_IA_64_ABI64)
6946 md.pointer_size = 8; /* pointers are 8 bytes */
6947 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
6949 else
6951 md.pointer_size = 4; /* pointers are 4 bytes */
6952 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
6955 md.mem_offset.hint = 0;
6956 md.path = 0;
6957 md.maxpaths = 0;
6958 md.entry_labels = NULL;
6961 /* Set the elf type to 64 bit ABI by default. Cannot do this in md_begin
6962 because that is called after md_parse_option which is where we do the
6963 dynamic changing of md.flags based on -mlp64 or -milp32. Also, set the
6964 default endianness. */
6966 void
6967 ia64_init (argc, argv)
6968 int argc ATTRIBUTE_UNUSED;
6969 char **argv ATTRIBUTE_UNUSED;
6971 md.flags = MD_FLAGS_DEFAULT;
6974 /* Return a string for the target object file format. */
6976 const char *
6977 ia64_target_format ()
6979 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
6981 if (md.flags & EF_IA_64_BE)
6983 if (md.flags & EF_IA_64_ABI64)
6984 #if defined(TE_AIX50)
6985 return "elf64-ia64-aix-big";
6986 #elif defined(TE_HPUX)
6987 return "elf64-ia64-hpux-big";
6988 #else
6989 return "elf64-ia64-big";
6990 #endif
6991 else
6992 #if defined(TE_AIX50)
6993 return "elf32-ia64-aix-big";
6994 #elif defined(TE_HPUX)
6995 return "elf32-ia64-hpux-big";
6996 #else
6997 return "elf32-ia64-big";
6998 #endif
7000 else
7002 if (md.flags & EF_IA_64_ABI64)
7003 #ifdef TE_AIX50
7004 return "elf64-ia64-aix-little";
7005 #else
7006 return "elf64-ia64-little";
7007 #endif
7008 else
7009 #ifdef TE_AIX50
7010 return "elf32-ia64-aix-little";
7011 #else
7012 return "elf32-ia64-little";
7013 #endif
7016 else
7017 return "unknown-format";
7020 void
7021 ia64_end_of_source ()
7023 /* terminate insn group upon reaching end of file: */
7024 insn_group_break (1, 0, 0);
7026 /* emits slots we haven't written yet: */
7027 ia64_flush_insns ();
7029 bfd_set_private_flags (stdoutput, md.flags);
7031 md.mem_offset.hint = 0;
7034 void
7035 ia64_start_line ()
7037 if (md.qp.X_op == O_register)
7038 as_bad ("qualifying predicate not followed by instruction");
7039 md.qp.X_op = O_absent;
7041 if (ignore_input ())
7042 return;
7044 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7046 if (md.detect_dv && !md.explicit_mode)
7047 as_warn (_("Explicit stops are ignored in auto mode"));
7048 else
7049 insn_group_break (1, 0, 0);
7053 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7054 labels. */
7055 static int defining_tag = 0;
7058 ia64_unrecognized_line (ch)
7059 int ch;
7061 switch (ch)
7063 case '(':
7064 expression (&md.qp);
7065 if (*input_line_pointer++ != ')')
7067 as_bad ("Expected ')'");
7068 return 0;
7070 if (md.qp.X_op != O_register)
7072 as_bad ("Qualifying predicate expected");
7073 return 0;
7075 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7077 as_bad ("Predicate register expected");
7078 return 0;
7080 return 1;
7082 case '{':
7083 if (md.manual_bundling)
7084 as_warn ("Found '{' when manual bundling is already turned on");
7085 else
7086 CURR_SLOT.manual_bundling_on = 1;
7087 md.manual_bundling = 1;
7089 /* Bundling is only acceptable in explicit mode
7090 or when in default automatic mode. */
7091 if (md.detect_dv && !md.explicit_mode)
7093 if (!md.mode_explicitly_set
7094 && !md.default_explicit_mode)
7095 dot_dv_mode ('E');
7096 else
7097 as_warn (_("Found '{' after explicit switch to automatic mode"));
7099 return 1;
7101 case '}':
7102 if (!md.manual_bundling)
7103 as_warn ("Found '}' when manual bundling is off");
7104 else
7105 PREV_SLOT.manual_bundling_off = 1;
7106 md.manual_bundling = 0;
7108 /* switch back to automatic mode, if applicable */
7109 if (md.detect_dv
7110 && md.explicit_mode
7111 && !md.mode_explicitly_set
7112 && !md.default_explicit_mode)
7113 dot_dv_mode ('A');
7115 /* Allow '{' to follow on the same line. We also allow ";;", but that
7116 happens automatically because ';' is an end of line marker. */
7117 SKIP_WHITESPACE ();
7118 if (input_line_pointer[0] == '{')
7120 input_line_pointer++;
7121 return ia64_unrecognized_line ('{');
7124 demand_empty_rest_of_line ();
7125 return 1;
7127 case '[':
7129 char *s;
7130 char c;
7131 symbolS *tag;
7132 int temp;
7134 if (md.qp.X_op == O_register)
7136 as_bad ("Tag must come before qualifying predicate.");
7137 return 0;
7140 /* This implements just enough of read_a_source_file in read.c to
7141 recognize labels. */
7142 if (is_name_beginner (*input_line_pointer))
7144 s = input_line_pointer;
7145 c = get_symbol_end ();
7147 else if (LOCAL_LABELS_FB
7148 && ISDIGIT (*input_line_pointer))
7150 temp = 0;
7151 while (ISDIGIT (*input_line_pointer))
7152 temp = (temp * 10) + *input_line_pointer++ - '0';
7153 fb_label_instance_inc (temp);
7154 s = fb_label_name (temp, 0);
7155 c = *input_line_pointer;
7157 else
7159 s = NULL;
7160 c = '\0';
7162 if (c != ':')
7164 /* Put ':' back for error messages' sake. */
7165 *input_line_pointer++ = ':';
7166 as_bad ("Expected ':'");
7167 return 0;
7170 defining_tag = 1;
7171 tag = colon (s);
7172 defining_tag = 0;
7173 /* Put ':' back for error messages' sake. */
7174 *input_line_pointer++ = ':';
7175 if (*input_line_pointer++ != ']')
7177 as_bad ("Expected ']'");
7178 return 0;
7180 if (! tag)
7182 as_bad ("Tag name expected");
7183 return 0;
7185 return 1;
7188 default:
7189 break;
7192 /* Not a valid line. */
7193 return 0;
7196 void
7197 ia64_frob_label (sym)
7198 struct symbol *sym;
7200 struct label_fix *fix;
7202 /* Tags need special handling since they are not bundle breaks like
7203 labels. */
7204 if (defining_tag)
7206 fix = obstack_alloc (&notes, sizeof (*fix));
7207 fix->sym = sym;
7208 fix->next = CURR_SLOT.tag_fixups;
7209 CURR_SLOT.tag_fixups = fix;
7211 return;
7214 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7216 md.last_text_seg = now_seg;
7217 fix = obstack_alloc (&notes, sizeof (*fix));
7218 fix->sym = sym;
7219 fix->next = CURR_SLOT.label_fixups;
7220 CURR_SLOT.label_fixups = fix;
7222 /* Keep track of how many code entry points we've seen. */
7223 if (md.path == md.maxpaths)
7225 md.maxpaths += 20;
7226 md.entry_labels = (const char **)
7227 xrealloc ((void *) md.entry_labels,
7228 md.maxpaths * sizeof (char *));
7230 md.entry_labels[md.path++] = S_GET_NAME (sym);
7234 #ifdef TE_HPUX
7235 /* The HP-UX linker will give unresolved symbol errors for symbols
7236 that are declared but unused. This routine removes declared,
7237 unused symbols from an object. */
7239 ia64_frob_symbol (sym)
7240 struct symbol *sym;
7242 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7243 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7244 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7245 && ! S_IS_EXTERNAL (sym)))
7246 return 1;
7247 return 0;
7249 #endif
7251 void
7252 ia64_flush_pending_output ()
7254 if (!md.keep_pending_output
7255 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7257 /* ??? This causes many unnecessary stop bits to be emitted.
7258 Unfortunately, it isn't clear if it is safe to remove this. */
7259 insn_group_break (1, 0, 0);
7260 ia64_flush_insns ();
7264 /* Do ia64-specific expression optimization. All that's done here is
7265 to transform index expressions that are either due to the indexing
7266 of rotating registers or due to the indexing of indirect register
7267 sets. */
7269 ia64_optimize_expr (l, op, r)
7270 expressionS *l;
7271 operatorT op;
7272 expressionS *r;
7274 unsigned num_regs;
7276 if (op == O_index)
7278 if (l->X_op == O_register && r->X_op == O_constant)
7280 num_regs = (l->X_add_number >> 16);
7281 if ((unsigned) r->X_add_number >= num_regs)
7283 if (!num_regs)
7284 as_bad ("No current frame");
7285 else
7286 as_bad ("Index out of range 0..%u", num_regs - 1);
7287 r->X_add_number = 0;
7289 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7290 return 1;
7292 else if (l->X_op == O_register && r->X_op == O_register)
7294 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7295 || l->X_add_number == IND_MEM)
7297 as_bad ("Indirect register set name expected");
7298 l->X_add_number = IND_CPUID;
7300 l->X_op = O_index;
7301 l->X_op_symbol = md.regsym[l->X_add_number];
7302 l->X_add_number = r->X_add_number;
7303 return 1;
7306 return 0;
7310 ia64_parse_name (name, e)
7311 char *name;
7312 expressionS *e;
7314 struct const_desc *cdesc;
7315 struct dynreg *dr = 0;
7316 unsigned int regnum;
7317 struct symbol *sym;
7318 char *end;
7320 /* first see if NAME is a known register name: */
7321 sym = hash_find (md.reg_hash, name);
7322 if (sym)
7324 e->X_op = O_register;
7325 e->X_add_number = S_GET_VALUE (sym);
7326 return 1;
7329 cdesc = hash_find (md.const_hash, name);
7330 if (cdesc)
7332 e->X_op = O_constant;
7333 e->X_add_number = cdesc->value;
7334 return 1;
7337 /* check for inN, locN, or outN: */
7338 switch (name[0])
7340 case 'i':
7341 if (name[1] == 'n' && ISDIGIT (name[2]))
7343 dr = &md.in;
7344 name += 2;
7346 break;
7348 case 'l':
7349 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7351 dr = &md.loc;
7352 name += 3;
7354 break;
7356 case 'o':
7357 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7359 dr = &md.out;
7360 name += 3;
7362 break;
7364 default:
7365 break;
7368 if (dr)
7370 /* The name is inN, locN, or outN; parse the register number. */
7371 regnum = strtoul (name, &end, 10);
7372 if (end > name && *end == '\0')
7374 if ((unsigned) regnum >= dr->num_regs)
7376 if (!dr->num_regs)
7377 as_bad ("No current frame");
7378 else
7379 as_bad ("Register number out of range 0..%u",
7380 dr->num_regs - 1);
7381 regnum = 0;
7383 e->X_op = O_register;
7384 e->X_add_number = dr->base + regnum;
7385 return 1;
7389 if ((dr = hash_find (md.dynreg_hash, name)))
7391 /* We've got ourselves the name of a rotating register set.
7392 Store the base register number in the low 16 bits of
7393 X_add_number and the size of the register set in the top 16
7394 bits. */
7395 e->X_op = O_register;
7396 e->X_add_number = dr->base | (dr->num_regs << 16);
7397 return 1;
7399 return 0;
7402 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7404 char *
7405 ia64_canonicalize_symbol_name (name)
7406 char *name;
7408 size_t len = strlen (name);
7409 if (len > 1 && name[len - 1] == '#')
7410 name[len - 1] = '\0';
7411 return name;
7414 /* Return true if idesc is a conditional branch instruction. This excludes
7415 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7416 because they always read/write resources regardless of the value of the
7417 qualifying predicate. br.ia must always use p0, and hence is always
7418 taken. Thus this function returns true for branches which can fall
7419 through, and which use no resources if they do fall through. */
7421 static int
7422 is_conditional_branch (idesc)
7423 struct ia64_opcode *idesc;
7425 /* br is a conditional branch. Everything that starts with br. except
7426 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7427 Everything that starts with brl is a conditional branch. */
7428 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7429 && (idesc->name[2] == '\0'
7430 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7431 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7432 || idesc->name[2] == 'l'
7433 /* br.cond, br.call, br.clr */
7434 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
7435 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
7436 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
7439 /* Return whether the given opcode is a taken branch. If there's any doubt,
7440 returns zero. */
7442 static int
7443 is_taken_branch (idesc)
7444 struct ia64_opcode *idesc;
7446 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
7447 || strncmp (idesc->name, "br.ia", 5) == 0);
7450 /* Return whether the given opcode is an interruption or rfi. If there's any
7451 doubt, returns zero. */
7453 static int
7454 is_interruption_or_rfi (idesc)
7455 struct ia64_opcode *idesc;
7457 if (strcmp (idesc->name, "rfi") == 0)
7458 return 1;
7459 return 0;
7462 /* Returns the index of the given dependency in the opcode's list of chks, or
7463 -1 if there is no dependency. */
7465 static int
7466 depends_on (depind, idesc)
7467 int depind;
7468 struct ia64_opcode *idesc;
7470 int i;
7471 const struct ia64_opcode_dependency *dep = idesc->dependencies;
7472 for (i = 0; i < dep->nchks; i++)
7474 if (depind == DEP (dep->chks[i]))
7475 return i;
7477 return -1;
7480 /* Determine a set of specific resources used for a particular resource
7481 class. Returns the number of specific resources identified For those
7482 cases which are not determinable statically, the resource returned is
7483 marked nonspecific.
7485 Meanings of value in 'NOTE':
7486 1) only read/write when the register number is explicitly encoded in the
7487 insn.
7488 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
7489 accesses CFM when qualifying predicate is in the rotating region.
7490 3) general register value is used to specify an indirect register; not
7491 determinable statically.
7492 4) only read the given resource when bits 7:0 of the indirect index
7493 register value does not match the register number of the resource; not
7494 determinable statically.
7495 5) all rules are implementation specific.
7496 6) only when both the index specified by the reader and the index specified
7497 by the writer have the same value in bits 63:61; not determinable
7498 statically.
7499 7) only access the specified resource when the corresponding mask bit is
7501 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
7502 only read when these insns reference FR2-31
7503 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
7504 written when these insns write FR32-127
7505 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
7506 instruction
7507 11) The target predicates are written independently of PR[qp], but source
7508 registers are only read if PR[qp] is true. Since the state of PR[qp]
7509 cannot statically be determined, all source registers are marked used.
7510 12) This insn only reads the specified predicate register when that
7511 register is the PR[qp].
7512 13) This reference to ld-c only applies to teh GR whose value is loaded
7513 with data returned from memory, not the post-incremented address register.
7514 14) The RSE resource includes the implementation-specific RSE internal
7515 state resources. At least one (and possibly more) of these resources are
7516 read by each instruction listed in IC:rse-readers. At least one (and
7517 possibly more) of these resources are written by each insn listed in
7518 IC:rse-writers.
7519 15+16) Represents reserved instructions, which the assembler does not
7520 generate.
7522 Memory resources (i.e. locations in memory) are *not* marked or tracked by
7523 this code; there are no dependency violations based on memory access.
7526 #define MAX_SPECS 256
7527 #define DV_CHK 1
7528 #define DV_REG 0
7530 static int
7531 specify_resource (dep, idesc, type, specs, note, path)
7532 const struct ia64_dependency *dep;
7533 struct ia64_opcode *idesc;
7534 int type; /* is this a DV chk or a DV reg? */
7535 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
7536 int note; /* resource note for this insn's usage */
7537 int path; /* which execution path to examine */
7539 int count = 0;
7540 int i;
7541 int rsrc_write = 0;
7542 struct rsrc tmpl;
7544 if (dep->mode == IA64_DV_WAW
7545 || (dep->mode == IA64_DV_RAW && type == DV_REG)
7546 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
7547 rsrc_write = 1;
7549 /* template for any resources we identify */
7550 tmpl.dependency = dep;
7551 tmpl.note = note;
7552 tmpl.insn_srlz = tmpl.data_srlz = 0;
7553 tmpl.qp_regno = CURR_SLOT.qp_regno;
7554 tmpl.link_to_qp_branch = 1;
7555 tmpl.mem_offset.hint = 0;
7556 tmpl.specific = 1;
7557 tmpl.index = 0;
7558 tmpl.cmp_type = CMP_NONE;
7560 #define UNHANDLED \
7561 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
7562 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
7563 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
7565 /* we don't need to track these */
7566 if (dep->semantics == IA64_DVS_NONE)
7567 return 0;
7569 switch (dep->specifier)
7571 case IA64_RS_AR_K:
7572 if (note == 1)
7574 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7576 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7577 if (regno >= 0 && regno <= 7)
7579 specs[count] = tmpl;
7580 specs[count++].index = regno;
7584 else if (note == 0)
7586 for (i = 0; i < 8; i++)
7588 specs[count] = tmpl;
7589 specs[count++].index = i;
7592 else
7594 UNHANDLED;
7596 break;
7598 case IA64_RS_AR_UNAT:
7599 /* This is a mov =AR or mov AR= instruction. */
7600 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7602 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7603 if (regno == AR_UNAT)
7605 specs[count++] = tmpl;
7608 else
7610 /* This is a spill/fill, or other instruction that modifies the
7611 unat register. */
7613 /* Unless we can determine the specific bits used, mark the whole
7614 thing; bits 8:3 of the memory address indicate the bit used in
7615 UNAT. The .mem.offset hint may be used to eliminate a small
7616 subset of conflicts. */
7617 specs[count] = tmpl;
7618 if (md.mem_offset.hint)
7620 if (md.debug_dv)
7621 fprintf (stderr, " Using hint for spill/fill\n");
7622 /* The index isn't actually used, just set it to something
7623 approximating the bit index. */
7624 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
7625 specs[count].mem_offset.hint = 1;
7626 specs[count].mem_offset.offset = md.mem_offset.offset;
7627 specs[count++].mem_offset.base = md.mem_offset.base;
7629 else
7631 specs[count++].specific = 0;
7634 break;
7636 case IA64_RS_AR:
7637 if (note == 1)
7639 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7641 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7642 if ((regno >= 8 && regno <= 15)
7643 || (regno >= 20 && regno <= 23)
7644 || (regno >= 31 && regno <= 39)
7645 || (regno >= 41 && regno <= 47)
7646 || (regno >= 67 && regno <= 111))
7648 specs[count] = tmpl;
7649 specs[count++].index = regno;
7653 else
7655 UNHANDLED;
7657 break;
7659 case IA64_RS_ARb:
7660 if (note == 1)
7662 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
7664 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
7665 if ((regno >= 48 && regno <= 63)
7666 || (regno >= 112 && regno <= 127))
7668 specs[count] = tmpl;
7669 specs[count++].index = regno;
7673 else if (note == 0)
7675 for (i = 48; i < 64; i++)
7677 specs[count] = tmpl;
7678 specs[count++].index = i;
7680 for (i = 112; i < 128; i++)
7682 specs[count] = tmpl;
7683 specs[count++].index = i;
7686 else
7688 UNHANDLED;
7690 break;
7692 case IA64_RS_BR:
7693 if (note != 1)
7695 UNHANDLED;
7697 else
7699 if (rsrc_write)
7701 for (i = 0; i < idesc->num_outputs; i++)
7702 if (idesc->operands[i] == IA64_OPND_B1
7703 || idesc->operands[i] == IA64_OPND_B2)
7705 specs[count] = tmpl;
7706 specs[count++].index =
7707 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7710 else
7712 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
7713 if (idesc->operands[i] == IA64_OPND_B1
7714 || idesc->operands[i] == IA64_OPND_B2)
7716 specs[count] = tmpl;
7717 specs[count++].index =
7718 CURR_SLOT.opnd[i].X_add_number - REG_BR;
7722 break;
7724 case IA64_RS_CPUID: /* four or more registers */
7725 if (note == 3)
7727 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
7729 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7730 if (regno >= 0 && regno < NELEMS (gr_values)
7731 && KNOWN (regno))
7733 specs[count] = tmpl;
7734 specs[count++].index = gr_values[regno].value & 0xFF;
7736 else
7738 specs[count] = tmpl;
7739 specs[count++].specific = 0;
7743 else
7745 UNHANDLED;
7747 break;
7749 case IA64_RS_DBR: /* four or more registers */
7750 if (note == 3)
7752 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
7754 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7755 if (regno >= 0 && regno < NELEMS (gr_values)
7756 && KNOWN (regno))
7758 specs[count] = tmpl;
7759 specs[count++].index = gr_values[regno].value & 0xFF;
7761 else
7763 specs[count] = tmpl;
7764 specs[count++].specific = 0;
7768 else if (note == 0 && !rsrc_write)
7770 specs[count] = tmpl;
7771 specs[count++].specific = 0;
7773 else
7775 UNHANDLED;
7777 break;
7779 case IA64_RS_IBR: /* four or more registers */
7780 if (note == 3)
7782 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
7784 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7785 if (regno >= 0 && regno < NELEMS (gr_values)
7786 && KNOWN (regno))
7788 specs[count] = tmpl;
7789 specs[count++].index = gr_values[regno].value & 0xFF;
7791 else
7793 specs[count] = tmpl;
7794 specs[count++].specific = 0;
7798 else
7800 UNHANDLED;
7802 break;
7804 case IA64_RS_MSR:
7805 if (note == 5)
7807 /* These are implementation specific. Force all references to
7808 conflict with all other references. */
7809 specs[count] = tmpl;
7810 specs[count++].specific = 0;
7812 else
7814 UNHANDLED;
7816 break;
7818 case IA64_RS_PKR: /* 16 or more registers */
7819 if (note == 3 || note == 4)
7821 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
7823 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7824 if (regno >= 0 && regno < NELEMS (gr_values)
7825 && KNOWN (regno))
7827 if (note == 3)
7829 specs[count] = tmpl;
7830 specs[count++].index = gr_values[regno].value & 0xFF;
7832 else
7833 for (i = 0; i < NELEMS (gr_values); i++)
7835 /* Uses all registers *except* the one in R3. */
7836 if ((unsigned)i != (gr_values[regno].value & 0xFF))
7838 specs[count] = tmpl;
7839 specs[count++].index = i;
7843 else
7845 specs[count] = tmpl;
7846 specs[count++].specific = 0;
7850 else if (note == 0)
7852 /* probe et al. */
7853 specs[count] = tmpl;
7854 specs[count++].specific = 0;
7856 break;
7858 case IA64_RS_PMC: /* four or more registers */
7859 if (note == 3)
7861 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
7862 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
7865 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
7866 ? 1 : !rsrc_write);
7867 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
7868 if (regno >= 0 && regno < NELEMS (gr_values)
7869 && KNOWN (regno))
7871 specs[count] = tmpl;
7872 specs[count++].index = gr_values[regno].value & 0xFF;
7874 else
7876 specs[count] = tmpl;
7877 specs[count++].specific = 0;
7881 else
7883 UNHANDLED;
7885 break;
7887 case IA64_RS_PMD: /* four or more registers */
7888 if (note == 3)
7890 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
7892 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7893 if (regno >= 0 && regno < NELEMS (gr_values)
7894 && KNOWN (regno))
7896 specs[count] = tmpl;
7897 specs[count++].index = gr_values[regno].value & 0xFF;
7899 else
7901 specs[count] = tmpl;
7902 specs[count++].specific = 0;
7906 else
7908 UNHANDLED;
7910 break;
7912 case IA64_RS_RR: /* eight registers */
7913 if (note == 6)
7915 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
7917 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
7918 if (regno >= 0 && regno < NELEMS (gr_values)
7919 && KNOWN (regno))
7921 specs[count] = tmpl;
7922 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
7924 else
7926 specs[count] = tmpl;
7927 specs[count++].specific = 0;
7931 else if (note == 0 && !rsrc_write)
7933 specs[count] = tmpl;
7934 specs[count++].specific = 0;
7936 else
7938 UNHANDLED;
7940 break;
7942 case IA64_RS_CR_IRR:
7943 if (note == 0)
7945 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
7946 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
7947 if (rsrc_write
7948 && idesc->operands[1] == IA64_OPND_CR3
7949 && regno == CR_IVR)
7951 for (i = 0; i < 4; i++)
7953 specs[count] = tmpl;
7954 specs[count++].index = CR_IRR0 + i;
7958 else if (note == 1)
7960 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7961 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7962 && regno >= CR_IRR0
7963 && regno <= CR_IRR3)
7965 specs[count] = tmpl;
7966 specs[count++].index = regno;
7969 else
7971 UNHANDLED;
7973 break;
7975 case IA64_RS_CR_LRR:
7976 if (note != 1)
7978 UNHANDLED;
7980 else
7982 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
7983 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
7984 && (regno == CR_LRR0 || regno == CR_LRR1))
7986 specs[count] = tmpl;
7987 specs[count++].index = regno;
7990 break;
7992 case IA64_RS_CR:
7993 if (note == 1)
7995 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
7997 specs[count] = tmpl;
7998 specs[count++].index =
7999 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8002 else
8004 UNHANDLED;
8006 break;
8008 case IA64_RS_FR:
8009 case IA64_RS_FRb:
8010 if (note != 1)
8012 UNHANDLED;
8014 else if (rsrc_write)
8016 if (dep->specifier == IA64_RS_FRb
8017 && idesc->operands[0] == IA64_OPND_F1)
8019 specs[count] = tmpl;
8020 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8023 else
8025 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8027 if (idesc->operands[i] == IA64_OPND_F2
8028 || idesc->operands[i] == IA64_OPND_F3
8029 || idesc->operands[i] == IA64_OPND_F4)
8031 specs[count] = tmpl;
8032 specs[count++].index =
8033 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8037 break;
8039 case IA64_RS_GR:
8040 if (note == 13)
8042 /* This reference applies only to the GR whose value is loaded with
8043 data returned from memory. */
8044 specs[count] = tmpl;
8045 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8047 else if (note == 1)
8049 if (rsrc_write)
8051 for (i = 0; i < idesc->num_outputs; i++)
8052 if (idesc->operands[i] == IA64_OPND_R1
8053 || idesc->operands[i] == IA64_OPND_R2
8054 || idesc->operands[i] == IA64_OPND_R3)
8056 specs[count] = tmpl;
8057 specs[count++].index =
8058 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8060 if (idesc->flags & IA64_OPCODE_POSTINC)
8061 for (i = 0; i < NELEMS (idesc->operands); i++)
8062 if (idesc->operands[i] == IA64_OPND_MR3)
8064 specs[count] = tmpl;
8065 specs[count++].index =
8066 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8069 else
8071 /* Look for anything that reads a GR. */
8072 for (i = 0; i < NELEMS (idesc->operands); i++)
8074 if (idesc->operands[i] == IA64_OPND_MR3
8075 || idesc->operands[i] == IA64_OPND_CPUID_R3
8076 || idesc->operands[i] == IA64_OPND_DBR_R3
8077 || idesc->operands[i] == IA64_OPND_IBR_R3
8078 || idesc->operands[i] == IA64_OPND_MSR_R3
8079 || idesc->operands[i] == IA64_OPND_PKR_R3
8080 || idesc->operands[i] == IA64_OPND_PMC_R3
8081 || idesc->operands[i] == IA64_OPND_PMD_R3
8082 || idesc->operands[i] == IA64_OPND_RR_R3
8083 || ((i >= idesc->num_outputs)
8084 && (idesc->operands[i] == IA64_OPND_R1
8085 || idesc->operands[i] == IA64_OPND_R2
8086 || idesc->operands[i] == IA64_OPND_R3
8087 /* addl source register. */
8088 || idesc->operands[i] == IA64_OPND_R3_2)))
8090 specs[count] = tmpl;
8091 specs[count++].index =
8092 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8097 else
8099 UNHANDLED;
8101 break;
8103 /* This is the same as IA64_RS_PRr, except that the register range is
8104 from 1 - 15, and there are no rotating register reads/writes here. */
8105 case IA64_RS_PR:
8106 if (note == 0)
8108 for (i = 1; i < 16; i++)
8110 specs[count] = tmpl;
8111 specs[count++].index = i;
8114 else if (note == 7)
8116 valueT mask = 0;
8117 /* Mark only those registers indicated by the mask. */
8118 if (rsrc_write)
8120 mask = CURR_SLOT.opnd[2].X_add_number;
8121 for (i = 1; i < 16; i++)
8122 if (mask & ((valueT) 1 << i))
8124 specs[count] = tmpl;
8125 specs[count++].index = i;
8128 else
8130 UNHANDLED;
8133 else if (note == 11) /* note 11 implies note 1 as well */
8135 if (rsrc_write)
8137 for (i = 0; i < idesc->num_outputs; i++)
8139 if (idesc->operands[i] == IA64_OPND_P1
8140 || idesc->operands[i] == IA64_OPND_P2)
8142 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8143 if (regno >= 1 && regno < 16)
8145 specs[count] = tmpl;
8146 specs[count++].index = regno;
8151 else
8153 UNHANDLED;
8156 else if (note == 12)
8158 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8160 specs[count] = tmpl;
8161 specs[count++].index = CURR_SLOT.qp_regno;
8164 else if (note == 1)
8166 if (rsrc_write)
8168 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8169 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8170 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8171 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8173 if ((idesc->operands[0] == IA64_OPND_P1
8174 || idesc->operands[0] == IA64_OPND_P2)
8175 && p1 >= 1 && p1 < 16)
8177 specs[count] = tmpl;
8178 specs[count].cmp_type =
8179 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8180 specs[count++].index = p1;
8182 if ((idesc->operands[1] == IA64_OPND_P1
8183 || idesc->operands[1] == IA64_OPND_P2)
8184 && p2 >= 1 && p2 < 16)
8186 specs[count] = tmpl;
8187 specs[count].cmp_type =
8188 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8189 specs[count++].index = p2;
8192 else
8194 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8196 specs[count] = tmpl;
8197 specs[count++].index = CURR_SLOT.qp_regno;
8199 if (idesc->operands[1] == IA64_OPND_PR)
8201 for (i = 1; i < 16; i++)
8203 specs[count] = tmpl;
8204 specs[count++].index = i;
8209 else
8211 UNHANDLED;
8213 break;
8215 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8216 simplified cases of this. */
8217 case IA64_RS_PRr:
8218 if (note == 0)
8220 for (i = 16; i < 63; i++)
8222 specs[count] = tmpl;
8223 specs[count++].index = i;
8226 else if (note == 7)
8228 valueT mask = 0;
8229 /* Mark only those registers indicated by the mask. */
8230 if (rsrc_write
8231 && idesc->operands[0] == IA64_OPND_PR)
8233 mask = CURR_SLOT.opnd[2].X_add_number;
8234 if (mask & ((valueT) 1 << 16))
8235 for (i = 16; i < 63; i++)
8237 specs[count] = tmpl;
8238 specs[count++].index = i;
8241 else if (rsrc_write
8242 && idesc->operands[0] == IA64_OPND_PR_ROT)
8244 for (i = 16; i < 63; i++)
8246 specs[count] = tmpl;
8247 specs[count++].index = i;
8250 else
8252 UNHANDLED;
8255 else if (note == 11) /* note 11 implies note 1 as well */
8257 if (rsrc_write)
8259 for (i = 0; i < idesc->num_outputs; i++)
8261 if (idesc->operands[i] == IA64_OPND_P1
8262 || idesc->operands[i] == IA64_OPND_P2)
8264 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8265 if (regno >= 16 && regno < 63)
8267 specs[count] = tmpl;
8268 specs[count++].index = regno;
8273 else
8275 UNHANDLED;
8278 else if (note == 12)
8280 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8282 specs[count] = tmpl;
8283 specs[count++].index = CURR_SLOT.qp_regno;
8286 else if (note == 1)
8288 if (rsrc_write)
8290 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8291 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8292 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8293 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8295 if ((idesc->operands[0] == IA64_OPND_P1
8296 || idesc->operands[0] == IA64_OPND_P2)
8297 && p1 >= 16 && p1 < 63)
8299 specs[count] = tmpl;
8300 specs[count].cmp_type =
8301 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8302 specs[count++].index = p1;
8304 if ((idesc->operands[1] == IA64_OPND_P1
8305 || idesc->operands[1] == IA64_OPND_P2)
8306 && p2 >= 16 && p2 < 63)
8308 specs[count] = tmpl;
8309 specs[count].cmp_type =
8310 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8311 specs[count++].index = p2;
8314 else
8316 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8318 specs[count] = tmpl;
8319 specs[count++].index = CURR_SLOT.qp_regno;
8321 if (idesc->operands[1] == IA64_OPND_PR)
8323 for (i = 16; i < 63; i++)
8325 specs[count] = tmpl;
8326 specs[count++].index = i;
8331 else
8333 UNHANDLED;
8335 break;
8337 case IA64_RS_PSR:
8338 /* Verify that the instruction is using the PSR bit indicated in
8339 dep->regindex. */
8340 if (note == 0)
8342 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8344 if (dep->regindex < 6)
8346 specs[count++] = tmpl;
8349 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8351 if (dep->regindex < 32
8352 || dep->regindex == 35
8353 || dep->regindex == 36
8354 || (!rsrc_write && dep->regindex == PSR_CPL))
8356 specs[count++] = tmpl;
8359 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8361 if (dep->regindex < 32
8362 || dep->regindex == 35
8363 || dep->regindex == 36
8364 || (rsrc_write && dep->regindex == PSR_CPL))
8366 specs[count++] = tmpl;
8369 else
8371 /* Several PSR bits have very specific dependencies. */
8372 switch (dep->regindex)
8374 default:
8375 specs[count++] = tmpl;
8376 break;
8377 case PSR_IC:
8378 if (rsrc_write)
8380 specs[count++] = tmpl;
8382 else
8384 /* Only certain CR accesses use PSR.ic */
8385 if (idesc->operands[0] == IA64_OPND_CR3
8386 || idesc->operands[1] == IA64_OPND_CR3)
8388 int index =
8389 ((idesc->operands[0] == IA64_OPND_CR3)
8390 ? 0 : 1);
8391 int regno =
8392 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8394 switch (regno)
8396 default:
8397 break;
8398 case CR_ITIR:
8399 case CR_IFS:
8400 case CR_IIM:
8401 case CR_IIP:
8402 case CR_IPSR:
8403 case CR_ISR:
8404 case CR_IFA:
8405 case CR_IHA:
8406 case CR_IIPA:
8407 specs[count++] = tmpl;
8408 break;
8412 break;
8413 case PSR_CPL:
8414 if (rsrc_write)
8416 specs[count++] = tmpl;
8418 else
8420 /* Only some AR accesses use cpl */
8421 if (idesc->operands[0] == IA64_OPND_AR3
8422 || idesc->operands[1] == IA64_OPND_AR3)
8424 int index =
8425 ((idesc->operands[0] == IA64_OPND_AR3)
8426 ? 0 : 1);
8427 int regno =
8428 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8430 if (regno == AR_ITC
8431 || (index == 0
8432 && (regno == AR_ITC
8433 || regno == AR_RSC
8434 || (regno >= AR_K0
8435 && regno <= AR_K7))))
8437 specs[count++] = tmpl;
8440 else
8442 specs[count++] = tmpl;
8444 break;
8449 else if (note == 7)
8451 valueT mask = 0;
8452 if (idesc->operands[0] == IA64_OPND_IMMU24)
8454 mask = CURR_SLOT.opnd[0].X_add_number;
8456 else
8458 UNHANDLED;
8460 if (mask & ((valueT) 1 << dep->regindex))
8462 specs[count++] = tmpl;
8465 else if (note == 8)
8467 int min = dep->regindex == PSR_DFL ? 2 : 32;
8468 int max = dep->regindex == PSR_DFL ? 31 : 127;
8469 /* dfh is read on FR32-127; dfl is read on FR2-31 */
8470 for (i = 0; i < NELEMS (idesc->operands); i++)
8472 if (idesc->operands[i] == IA64_OPND_F1
8473 || idesc->operands[i] == IA64_OPND_F2
8474 || idesc->operands[i] == IA64_OPND_F3
8475 || idesc->operands[i] == IA64_OPND_F4)
8477 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8478 if (reg >= min && reg <= max)
8480 specs[count++] = tmpl;
8485 else if (note == 9)
8487 int min = dep->regindex == PSR_MFL ? 2 : 32;
8488 int max = dep->regindex == PSR_MFL ? 31 : 127;
8489 /* mfh is read on writes to FR32-127; mfl is read on writes to
8490 FR2-31 */
8491 for (i = 0; i < idesc->num_outputs; i++)
8493 if (idesc->operands[i] == IA64_OPND_F1)
8495 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8496 if (reg >= min && reg <= max)
8498 specs[count++] = tmpl;
8503 else if (note == 10)
8505 for (i = 0; i < NELEMS (idesc->operands); i++)
8507 if (idesc->operands[i] == IA64_OPND_R1
8508 || idesc->operands[i] == IA64_OPND_R2
8509 || idesc->operands[i] == IA64_OPND_R3)
8511 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8512 if (regno >= 16 && regno <= 31)
8514 specs[count++] = tmpl;
8519 else
8521 UNHANDLED;
8523 break;
8525 case IA64_RS_AR_FPSR:
8526 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8528 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8529 if (regno == AR_FPSR)
8531 specs[count++] = tmpl;
8534 else
8536 specs[count++] = tmpl;
8538 break;
8540 case IA64_RS_ARX:
8541 /* Handle all AR[REG] resources */
8542 if (note == 0 || note == 1)
8544 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8545 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
8546 && regno == dep->regindex)
8548 specs[count++] = tmpl;
8550 /* other AR[REG] resources may be affected by AR accesses */
8551 else if (idesc->operands[0] == IA64_OPND_AR3)
8553 /* AR[] writes */
8554 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
8555 switch (dep->regindex)
8557 default:
8558 break;
8559 case AR_BSP:
8560 case AR_RNAT:
8561 if (regno == AR_BSPSTORE)
8563 specs[count++] = tmpl;
8565 case AR_RSC:
8566 if (!rsrc_write &&
8567 (regno == AR_BSPSTORE
8568 || regno == AR_RNAT))
8570 specs[count++] = tmpl;
8572 break;
8575 else if (idesc->operands[1] == IA64_OPND_AR3)
8577 /* AR[] reads */
8578 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
8579 switch (dep->regindex)
8581 default:
8582 break;
8583 case AR_RSC:
8584 if (regno == AR_BSPSTORE || regno == AR_RNAT)
8586 specs[count++] = tmpl;
8588 break;
8591 else
8593 specs[count++] = tmpl;
8596 else
8598 UNHANDLED;
8600 break;
8602 case IA64_RS_CRX:
8603 /* Handle all CR[REG] resources */
8604 if (note == 0 || note == 1)
8606 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8608 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8609 if (regno == dep->regindex)
8611 specs[count++] = tmpl;
8613 else if (!rsrc_write)
8615 /* Reads from CR[IVR] affect other resources. */
8616 if (regno == CR_IVR)
8618 if ((dep->regindex >= CR_IRR0
8619 && dep->regindex <= CR_IRR3)
8620 || dep->regindex == CR_TPR)
8622 specs[count++] = tmpl;
8627 else
8629 specs[count++] = tmpl;
8632 else
8634 UNHANDLED;
8636 break;
8638 case IA64_RS_INSERVICE:
8639 /* look for write of EOI (67) or read of IVR (65) */
8640 if ((idesc->operands[0] == IA64_OPND_CR3
8641 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
8642 || (idesc->operands[1] == IA64_OPND_CR3
8643 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
8645 specs[count++] = tmpl;
8647 break;
8649 case IA64_RS_GR0:
8650 if (note == 1)
8652 specs[count++] = tmpl;
8654 else
8656 UNHANDLED;
8658 break;
8660 case IA64_RS_CFM:
8661 if (note != 2)
8663 specs[count++] = tmpl;
8665 else
8667 /* Check if any of the registers accessed are in the rotating region.
8668 mov to/from pr accesses CFM only when qp_regno is in the rotating
8669 region */
8670 for (i = 0; i < NELEMS (idesc->operands); i++)
8672 if (idesc->operands[i] == IA64_OPND_R1
8673 || idesc->operands[i] == IA64_OPND_R2
8674 || idesc->operands[i] == IA64_OPND_R3)
8676 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
8677 /* Assumes that md.rot.num_regs is always valid */
8678 if (md.rot.num_regs > 0
8679 && num > 31
8680 && num < 31 + md.rot.num_regs)
8682 specs[count] = tmpl;
8683 specs[count++].specific = 0;
8686 else if (idesc->operands[i] == IA64_OPND_F1
8687 || idesc->operands[i] == IA64_OPND_F2
8688 || idesc->operands[i] == IA64_OPND_F3
8689 || idesc->operands[i] == IA64_OPND_F4)
8691 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
8692 if (num > 31)
8694 specs[count] = tmpl;
8695 specs[count++].specific = 0;
8698 else if (idesc->operands[i] == IA64_OPND_P1
8699 || idesc->operands[i] == IA64_OPND_P2)
8701 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
8702 if (num > 15)
8704 specs[count] = tmpl;
8705 specs[count++].specific = 0;
8709 if (CURR_SLOT.qp_regno > 15)
8711 specs[count] = tmpl;
8712 specs[count++].specific = 0;
8715 break;
8717 /* This is the same as IA64_RS_PRr, except simplified to account for
8718 the fact that there is only one register. */
8719 case IA64_RS_PR63:
8720 if (note == 0)
8722 specs[count++] = tmpl;
8724 else if (note == 7)
8726 valueT mask = 0;
8727 if (idesc->operands[2] == IA64_OPND_IMM17)
8728 mask = CURR_SLOT.opnd[2].X_add_number;
8729 if (mask & ((valueT) 1 << 63))
8730 specs[count++] = tmpl;
8732 else if (note == 11)
8734 if ((idesc->operands[0] == IA64_OPND_P1
8735 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
8736 || (idesc->operands[1] == IA64_OPND_P2
8737 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
8739 specs[count++] = tmpl;
8742 else if (note == 12)
8744 if (CURR_SLOT.qp_regno == 63)
8746 specs[count++] = tmpl;
8749 else if (note == 1)
8751 if (rsrc_write)
8753 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8754 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8755 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8756 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8758 if (p1 == 63
8759 && (idesc->operands[0] == IA64_OPND_P1
8760 || idesc->operands[0] == IA64_OPND_P2))
8762 specs[count] = tmpl;
8763 specs[count++].cmp_type =
8764 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8766 if (p2 == 63
8767 && (idesc->operands[1] == IA64_OPND_P1
8768 || idesc->operands[1] == IA64_OPND_P2))
8770 specs[count] = tmpl;
8771 specs[count++].cmp_type =
8772 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8775 else
8777 if (CURR_SLOT.qp_regno == 63)
8779 specs[count++] = tmpl;
8783 else
8785 UNHANDLED;
8787 break;
8789 case IA64_RS_RSE:
8790 /* FIXME we can identify some individual RSE written resources, but RSE
8791 read resources have not yet been completely identified, so for now
8792 treat RSE as a single resource */
8793 if (strncmp (idesc->name, "mov", 3) == 0)
8795 if (rsrc_write)
8797 if (idesc->operands[0] == IA64_OPND_AR3
8798 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
8800 specs[count] = tmpl;
8801 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
8804 else
8806 if (idesc->operands[0] == IA64_OPND_AR3)
8808 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
8809 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
8811 specs[count++] = tmpl;
8814 else if (idesc->operands[1] == IA64_OPND_AR3)
8816 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
8817 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
8818 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
8820 specs[count++] = tmpl;
8825 else
8827 specs[count++] = tmpl;
8829 break;
8831 case IA64_RS_ANY:
8832 /* FIXME -- do any of these need to be non-specific? */
8833 specs[count++] = tmpl;
8834 break;
8836 default:
8837 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
8838 break;
8841 return count;
8844 /* Clear branch flags on marked resources. This breaks the link between the
8845 QP of the marking instruction and a subsequent branch on the same QP. */
8847 static void
8848 clear_qp_branch_flag (mask)
8849 valueT mask;
8851 int i;
8852 for (i = 0; i < regdepslen; i++)
8854 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
8855 if ((bit & mask) != 0)
8857 regdeps[i].link_to_qp_branch = 0;
8862 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
8863 any mutexes which contain one of the PRs and create new ones when
8864 needed. */
8866 static int
8867 update_qp_mutex (valueT mask)
8869 int i;
8870 int add = 0;
8872 i = 0;
8873 while (i < qp_mutexeslen)
8875 if ((qp_mutexes[i].prmask & mask) != 0)
8877 /* If it destroys and creates the same mutex, do nothing. */
8878 if (qp_mutexes[i].prmask == mask
8879 && qp_mutexes[i].path == md.path)
8881 i++;
8882 add = -1;
8884 else
8886 int keep = 0;
8888 if (md.debug_dv)
8890 fprintf (stderr, " Clearing mutex relation");
8891 print_prmask (qp_mutexes[i].prmask);
8892 fprintf (stderr, "\n");
8895 /* Deal with the old mutex with more than 3+ PRs only if
8896 the new mutex on the same execution path with it.
8898 FIXME: The 3+ mutex support is incomplete.
8899 dot_pred_rel () may be a better place to fix it. */
8900 if (qp_mutexes[i].path == md.path)
8902 /* If it is a proper subset of the mutex, create a
8903 new mutex. */
8904 if (add == 0
8905 && (qp_mutexes[i].prmask & mask) == mask)
8906 add = 1;
8908 qp_mutexes[i].prmask &= ~mask;
8909 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
8911 /* Modify the mutex if there are more than one
8912 PR left. */
8913 keep = 1;
8914 i++;
8918 if (keep == 0)
8919 /* Remove the mutex. */
8920 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8923 else
8924 ++i;
8927 if (add == 1)
8928 add_qp_mutex (mask);
8930 return add;
8933 /* Remove any mutexes which contain any of the PRs indicated in the mask.
8935 Any changes to a PR clears the mutex relations which include that PR. */
8937 static void
8938 clear_qp_mutex (mask)
8939 valueT mask;
8941 int i;
8943 i = 0;
8944 while (i < qp_mutexeslen)
8946 if ((qp_mutexes[i].prmask & mask) != 0)
8948 if (md.debug_dv)
8950 fprintf (stderr, " Clearing mutex relation");
8951 print_prmask (qp_mutexes[i].prmask);
8952 fprintf (stderr, "\n");
8954 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
8956 else
8957 ++i;
8961 /* Clear implies relations which contain PRs in the given masks.
8962 P1_MASK indicates the source of the implies relation, while P2_MASK
8963 indicates the implied PR. */
8965 static void
8966 clear_qp_implies (p1_mask, p2_mask)
8967 valueT p1_mask;
8968 valueT p2_mask;
8970 int i;
8972 i = 0;
8973 while (i < qp_implieslen)
8975 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
8976 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
8978 if (md.debug_dv)
8979 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
8980 qp_implies[i].p1, qp_implies[i].p2);
8981 qp_implies[i] = qp_implies[--qp_implieslen];
8983 else
8984 ++i;
8988 /* Add the PRs specified to the list of implied relations. */
8990 static void
8991 add_qp_imply (p1, p2)
8992 int p1, p2;
8994 valueT mask;
8995 valueT bit;
8996 int i;
8998 /* p0 is not meaningful here. */
8999 if (p1 == 0 || p2 == 0)
9000 abort ();
9002 if (p1 == p2)
9003 return;
9005 /* If it exists already, ignore it. */
9006 for (i = 0; i < qp_implieslen; i++)
9008 if (qp_implies[i].p1 == p1
9009 && qp_implies[i].p2 == p2
9010 && qp_implies[i].path == md.path
9011 && !qp_implies[i].p2_branched)
9012 return;
9015 if (qp_implieslen == qp_impliestotlen)
9017 qp_impliestotlen += 20;
9018 qp_implies = (struct qp_imply *)
9019 xrealloc ((void *) qp_implies,
9020 qp_impliestotlen * sizeof (struct qp_imply));
9022 if (md.debug_dv)
9023 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9024 qp_implies[qp_implieslen].p1 = p1;
9025 qp_implies[qp_implieslen].p2 = p2;
9026 qp_implies[qp_implieslen].path = md.path;
9027 qp_implies[qp_implieslen++].p2_branched = 0;
9029 /* Add in the implied transitive relations; for everything that p2 implies,
9030 make p1 imply that, too; for everything that implies p1, make it imply p2
9031 as well. */
9032 for (i = 0; i < qp_implieslen; i++)
9034 if (qp_implies[i].p1 == p2)
9035 add_qp_imply (p1, qp_implies[i].p2);
9036 if (qp_implies[i].p2 == p1)
9037 add_qp_imply (qp_implies[i].p1, p2);
9039 /* Add in mutex relations implied by this implies relation; for each mutex
9040 relation containing p2, duplicate it and replace p2 with p1. */
9041 bit = (valueT) 1 << p1;
9042 mask = (valueT) 1 << p2;
9043 for (i = 0; i < qp_mutexeslen; i++)
9045 if (qp_mutexes[i].prmask & mask)
9046 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9050 /* Add the PRs specified in the mask to the mutex list; this means that only
9051 one of the PRs can be true at any time. PR0 should never be included in
9052 the mask. */
9054 static void
9055 add_qp_mutex (mask)
9056 valueT mask;
9058 if (mask & 0x1)
9059 abort ();
9061 if (qp_mutexeslen == qp_mutexestotlen)
9063 qp_mutexestotlen += 20;
9064 qp_mutexes = (struct qpmutex *)
9065 xrealloc ((void *) qp_mutexes,
9066 qp_mutexestotlen * sizeof (struct qpmutex));
9068 if (md.debug_dv)
9070 fprintf (stderr, " Registering mutex on");
9071 print_prmask (mask);
9072 fprintf (stderr, "\n");
9074 qp_mutexes[qp_mutexeslen].path = md.path;
9075 qp_mutexes[qp_mutexeslen++].prmask = mask;
9078 static int
9079 has_suffix_p (name, suffix)
9080 const char *name;
9081 const char *suffix;
9083 size_t namelen = strlen (name);
9084 size_t sufflen = strlen (suffix);
9086 if (namelen <= sufflen)
9087 return 0;
9088 return strcmp (name + namelen - sufflen, suffix) == 0;
9091 static void
9092 clear_register_values ()
9094 int i;
9095 if (md.debug_dv)
9096 fprintf (stderr, " Clearing register values\n");
9097 for (i = 1; i < NELEMS (gr_values); i++)
9098 gr_values[i].known = 0;
9101 /* Keep track of register values/changes which affect DV tracking.
9103 optimization note: should add a flag to classes of insns where otherwise we
9104 have to examine a group of strings to identify them. */
9106 static void
9107 note_register_values (idesc)
9108 struct ia64_opcode *idesc;
9110 valueT qp_changemask = 0;
9111 int i;
9113 /* Invalidate values for registers being written to. */
9114 for (i = 0; i < idesc->num_outputs; i++)
9116 if (idesc->operands[i] == IA64_OPND_R1
9117 || idesc->operands[i] == IA64_OPND_R2
9118 || idesc->operands[i] == IA64_OPND_R3)
9120 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9121 if (regno > 0 && regno < NELEMS (gr_values))
9122 gr_values[regno].known = 0;
9124 else if (idesc->operands[i] == IA64_OPND_R3_2)
9126 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9127 if (regno > 0 && regno < 4)
9128 gr_values[regno].known = 0;
9130 else if (idesc->operands[i] == IA64_OPND_P1
9131 || idesc->operands[i] == IA64_OPND_P2)
9133 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9134 qp_changemask |= (valueT) 1 << regno;
9136 else if (idesc->operands[i] == IA64_OPND_PR)
9138 if (idesc->operands[2] & (valueT) 0x10000)
9139 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9140 else
9141 qp_changemask = idesc->operands[2];
9142 break;
9144 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9146 if (idesc->operands[1] & ((valueT) 1 << 43))
9147 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9148 else
9149 qp_changemask = idesc->operands[1];
9150 qp_changemask &= ~(valueT) 0xFFFF;
9151 break;
9155 /* Always clear qp branch flags on any PR change. */
9156 /* FIXME there may be exceptions for certain compares. */
9157 clear_qp_branch_flag (qp_changemask);
9159 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9160 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9162 qp_changemask |= ~(valueT) 0xFFFF;
9163 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9165 for (i = 32; i < 32 + md.rot.num_regs; i++)
9166 gr_values[i].known = 0;
9168 clear_qp_mutex (qp_changemask);
9169 clear_qp_implies (qp_changemask, qp_changemask);
9171 /* After a call, all register values are undefined, except those marked
9172 as "safe". */
9173 else if (strncmp (idesc->name, "br.call", 6) == 0
9174 || strncmp (idesc->name, "brl.call", 7) == 0)
9176 /* FIXME keep GR values which are marked as "safe_across_calls" */
9177 clear_register_values ();
9178 clear_qp_mutex (~qp_safe_across_calls);
9179 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9180 clear_qp_branch_flag (~qp_safe_across_calls);
9182 else if (is_interruption_or_rfi (idesc)
9183 || is_taken_branch (idesc))
9185 clear_register_values ();
9186 clear_qp_mutex (~(valueT) 0);
9187 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9189 /* Look for mutex and implies relations. */
9190 else if ((idesc->operands[0] == IA64_OPND_P1
9191 || idesc->operands[0] == IA64_OPND_P2)
9192 && (idesc->operands[1] == IA64_OPND_P1
9193 || idesc->operands[1] == IA64_OPND_P2))
9195 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9196 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9197 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9198 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9200 /* If both PRs are PR0, we can't really do anything. */
9201 if (p1 == 0 && p2 == 0)
9203 if (md.debug_dv)
9204 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9206 /* In general, clear mutexes and implies which include P1 or P2,
9207 with the following exceptions. */
9208 else if (has_suffix_p (idesc->name, ".or.andcm")
9209 || has_suffix_p (idesc->name, ".and.orcm"))
9211 clear_qp_implies (p2mask, p1mask);
9213 else if (has_suffix_p (idesc->name, ".andcm")
9214 || has_suffix_p (idesc->name, ".and"))
9216 clear_qp_implies (0, p1mask | p2mask);
9218 else if (has_suffix_p (idesc->name, ".orcm")
9219 || has_suffix_p (idesc->name, ".or"))
9221 clear_qp_mutex (p1mask | p2mask);
9222 clear_qp_implies (p1mask | p2mask, 0);
9224 else
9226 int added = 0;
9228 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9230 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9231 if (p1 == 0 || p2 == 0)
9232 clear_qp_mutex (p1mask | p2mask);
9233 else
9234 added = update_qp_mutex (p1mask | p2mask);
9236 if (CURR_SLOT.qp_regno == 0
9237 || has_suffix_p (idesc->name, ".unc"))
9239 if (added == 0 && p1 && p2)
9240 add_qp_mutex (p1mask | p2mask);
9241 if (CURR_SLOT.qp_regno != 0)
9243 if (p1)
9244 add_qp_imply (p1, CURR_SLOT.qp_regno);
9245 if (p2)
9246 add_qp_imply (p2, CURR_SLOT.qp_regno);
9251 /* Look for mov imm insns into GRs. */
9252 else if (idesc->operands[0] == IA64_OPND_R1
9253 && (idesc->operands[1] == IA64_OPND_IMM22
9254 || idesc->operands[1] == IA64_OPND_IMMU64)
9255 && (strcmp (idesc->name, "mov") == 0
9256 || strcmp (idesc->name, "movl") == 0))
9258 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9259 if (regno > 0 && regno < NELEMS (gr_values))
9261 gr_values[regno].known = 1;
9262 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9263 gr_values[regno].path = md.path;
9264 if (md.debug_dv)
9266 fprintf (stderr, " Know gr%d = ", regno);
9267 fprintf_vma (stderr, gr_values[regno].value);
9268 fputs ("\n", stderr);
9272 else
9274 clear_qp_mutex (qp_changemask);
9275 clear_qp_implies (qp_changemask, qp_changemask);
9279 /* Return whether the given predicate registers are currently mutex. */
9281 static int
9282 qp_mutex (p1, p2, path)
9283 int p1;
9284 int p2;
9285 int path;
9287 int i;
9288 valueT mask;
9290 if (p1 != p2)
9292 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9293 for (i = 0; i < qp_mutexeslen; i++)
9295 if (qp_mutexes[i].path >= path
9296 && (qp_mutexes[i].prmask & mask) == mask)
9297 return 1;
9300 return 0;
9303 /* Return whether the given resource is in the given insn's list of chks
9304 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9305 conflict. */
9307 static int
9308 resources_match (rs, idesc, note, qp_regno, path)
9309 struct rsrc *rs;
9310 struct ia64_opcode *idesc;
9311 int note;
9312 int qp_regno;
9313 int path;
9315 struct rsrc specs[MAX_SPECS];
9316 int count;
9318 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9319 we don't need to check. One exception is note 11, which indicates that
9320 target predicates are written regardless of PR[qp]. */
9321 if (qp_mutex (rs->qp_regno, qp_regno, path)
9322 && note != 11)
9323 return 0;
9325 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9326 while (count-- > 0)
9328 /* UNAT checking is a bit more specific than other resources */
9329 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9330 && specs[count].mem_offset.hint
9331 && rs->mem_offset.hint)
9333 if (rs->mem_offset.base == specs[count].mem_offset.base)
9335 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9336 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9337 return 1;
9338 else
9339 continue;
9343 /* Skip apparent PR write conflicts where both writes are an AND or both
9344 writes are an OR. */
9345 if (rs->dependency->specifier == IA64_RS_PR
9346 || rs->dependency->specifier == IA64_RS_PRr
9347 || rs->dependency->specifier == IA64_RS_PR63)
9349 if (specs[count].cmp_type != CMP_NONE
9350 && specs[count].cmp_type == rs->cmp_type)
9352 if (md.debug_dv)
9353 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9354 dv_mode[rs->dependency->mode],
9355 rs->dependency->specifier != IA64_RS_PR63 ?
9356 specs[count].index : 63);
9357 continue;
9359 if (md.debug_dv)
9360 fprintf (stderr,
9361 " %s on parallel compare conflict %s vs %s on PR%d\n",
9362 dv_mode[rs->dependency->mode],
9363 dv_cmp_type[rs->cmp_type],
9364 dv_cmp_type[specs[count].cmp_type],
9365 rs->dependency->specifier != IA64_RS_PR63 ?
9366 specs[count].index : 63);
9370 /* If either resource is not specific, conservatively assume a conflict
9372 if (!specs[count].specific || !rs->specific)
9373 return 2;
9374 else if (specs[count].index == rs->index)
9375 return 1;
9377 #if 0
9378 if (md.debug_dv)
9379 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
9380 #endif
9382 return 0;
9385 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9386 insert a stop to create the break. Update all resource dependencies
9387 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9388 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9389 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9390 instruction. */
9392 static void
9393 insn_group_break (insert_stop, qp_regno, save_current)
9394 int insert_stop;
9395 int qp_regno;
9396 int save_current;
9398 int i;
9400 if (insert_stop && md.num_slots_in_use > 0)
9401 PREV_SLOT.end_of_insn_group = 1;
9403 if (md.debug_dv)
9405 fprintf (stderr, " Insn group break%s",
9406 (insert_stop ? " (w/stop)" : ""));
9407 if (qp_regno != 0)
9408 fprintf (stderr, " effective for QP=%d", qp_regno);
9409 fprintf (stderr, "\n");
9412 i = 0;
9413 while (i < regdepslen)
9415 const struct ia64_dependency *dep = regdeps[i].dependency;
9417 if (qp_regno != 0
9418 && regdeps[i].qp_regno != qp_regno)
9420 ++i;
9421 continue;
9424 if (save_current
9425 && CURR_SLOT.src_file == regdeps[i].file
9426 && CURR_SLOT.src_line == regdeps[i].line)
9428 ++i;
9429 continue;
9432 /* clear dependencies which are automatically cleared by a stop, or
9433 those that have reached the appropriate state of insn serialization */
9434 if (dep->semantics == IA64_DVS_IMPLIED
9435 || dep->semantics == IA64_DVS_IMPLIEDF
9436 || regdeps[i].insn_srlz == STATE_SRLZ)
9438 print_dependency ("Removing", i);
9439 regdeps[i] = regdeps[--regdepslen];
9441 else
9443 if (dep->semantics == IA64_DVS_DATA
9444 || dep->semantics == IA64_DVS_INSTR
9445 || dep->semantics == IA64_DVS_SPECIFIC)
9447 if (regdeps[i].insn_srlz == STATE_NONE)
9448 regdeps[i].insn_srlz = STATE_STOP;
9449 if (regdeps[i].data_srlz == STATE_NONE)
9450 regdeps[i].data_srlz = STATE_STOP;
9452 ++i;
9457 /* Add the given resource usage spec to the list of active dependencies. */
9459 static void
9460 mark_resource (idesc, dep, spec, depind, path)
9461 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
9462 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
9463 struct rsrc *spec;
9464 int depind;
9465 int path;
9467 if (regdepslen == regdepstotlen)
9469 regdepstotlen += 20;
9470 regdeps = (struct rsrc *)
9471 xrealloc ((void *) regdeps,
9472 regdepstotlen * sizeof (struct rsrc));
9475 regdeps[regdepslen] = *spec;
9476 regdeps[regdepslen].depind = depind;
9477 regdeps[regdepslen].path = path;
9478 regdeps[regdepslen].file = CURR_SLOT.src_file;
9479 regdeps[regdepslen].line = CURR_SLOT.src_line;
9481 print_dependency ("Adding", regdepslen);
9483 ++regdepslen;
9486 static void
9487 print_dependency (action, depind)
9488 const char *action;
9489 int depind;
9491 if (md.debug_dv)
9493 fprintf (stderr, " %s %s '%s'",
9494 action, dv_mode[(regdeps[depind].dependency)->mode],
9495 (regdeps[depind].dependency)->name);
9496 if (regdeps[depind].specific && regdeps[depind].index != 0)
9497 fprintf (stderr, " (%d)", regdeps[depind].index);
9498 if (regdeps[depind].mem_offset.hint)
9500 fputs (" ", stderr);
9501 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
9502 fputs ("+", stderr);
9503 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
9505 fprintf (stderr, "\n");
9509 static void
9510 instruction_serialization ()
9512 int i;
9513 if (md.debug_dv)
9514 fprintf (stderr, " Instruction serialization\n");
9515 for (i = 0; i < regdepslen; i++)
9516 if (regdeps[i].insn_srlz == STATE_STOP)
9517 regdeps[i].insn_srlz = STATE_SRLZ;
9520 static void
9521 data_serialization ()
9523 int i = 0;
9524 if (md.debug_dv)
9525 fprintf (stderr, " Data serialization\n");
9526 while (i < regdepslen)
9528 if (regdeps[i].data_srlz == STATE_STOP
9529 /* Note: as of 991210, all "other" dependencies are cleared by a
9530 data serialization. This might change with new tables */
9531 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
9533 print_dependency ("Removing", i);
9534 regdeps[i] = regdeps[--regdepslen];
9536 else
9537 ++i;
9541 /* Insert stops and serializations as needed to avoid DVs. */
9543 static void
9544 remove_marked_resource (rs)
9545 struct rsrc *rs;
9547 switch (rs->dependency->semantics)
9549 case IA64_DVS_SPECIFIC:
9550 if (md.debug_dv)
9551 fprintf (stderr, "Implementation-specific, assume worst case...\n");
9552 /* ...fall through... */
9553 case IA64_DVS_INSTR:
9554 if (md.debug_dv)
9555 fprintf (stderr, "Inserting instr serialization\n");
9556 if (rs->insn_srlz < STATE_STOP)
9557 insn_group_break (1, 0, 0);
9558 if (rs->insn_srlz < STATE_SRLZ)
9560 int oldqp = CURR_SLOT.qp_regno;
9561 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9562 /* Manually jam a srlz.i insn into the stream */
9563 CURR_SLOT.qp_regno = 0;
9564 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
9565 instruction_serialization ();
9566 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9567 if (++md.num_slots_in_use >= NUM_SLOTS)
9568 emit_one_bundle ();
9569 CURR_SLOT.qp_regno = oldqp;
9570 CURR_SLOT.idesc = oldidesc;
9572 insn_group_break (1, 0, 0);
9573 break;
9574 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
9575 "other" types of DV are eliminated
9576 by a data serialization */
9577 case IA64_DVS_DATA:
9578 if (md.debug_dv)
9579 fprintf (stderr, "Inserting data serialization\n");
9580 if (rs->data_srlz < STATE_STOP)
9581 insn_group_break (1, 0, 0);
9583 int oldqp = CURR_SLOT.qp_regno;
9584 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
9585 /* Manually jam a srlz.d insn into the stream */
9586 CURR_SLOT.qp_regno = 0;
9587 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
9588 data_serialization ();
9589 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
9590 if (++md.num_slots_in_use >= NUM_SLOTS)
9591 emit_one_bundle ();
9592 CURR_SLOT.qp_regno = oldqp;
9593 CURR_SLOT.idesc = oldidesc;
9595 break;
9596 case IA64_DVS_IMPLIED:
9597 case IA64_DVS_IMPLIEDF:
9598 if (md.debug_dv)
9599 fprintf (stderr, "Inserting stop\n");
9600 insn_group_break (1, 0, 0);
9601 break;
9602 default:
9603 break;
9607 /* Check the resources used by the given opcode against the current dependency
9608 list.
9610 The check is run once for each execution path encountered. In this case,
9611 a unique execution path is the sequence of instructions following a code
9612 entry point, e.g. the following has three execution paths, one starting
9613 at L0, one at L1, and one at L2.
9615 L0: nop
9616 L1: add
9617 L2: add
9618 br.ret
9621 static void
9622 check_dependencies (idesc)
9623 struct ia64_opcode *idesc;
9625 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9626 int path;
9627 int i;
9629 /* Note that the number of marked resources may change within the
9630 loop if in auto mode. */
9631 i = 0;
9632 while (i < regdepslen)
9634 struct rsrc *rs = &regdeps[i];
9635 const struct ia64_dependency *dep = rs->dependency;
9636 int chkind;
9637 int note;
9638 int start_over = 0;
9640 if (dep->semantics == IA64_DVS_NONE
9641 || (chkind = depends_on (rs->depind, idesc)) == -1)
9643 ++i;
9644 continue;
9647 note = NOTE (opdeps->chks[chkind]);
9649 /* Check this resource against each execution path seen thus far. */
9650 for (path = 0; path <= md.path; path++)
9652 int matchtype;
9654 /* If the dependency wasn't on the path being checked, ignore it. */
9655 if (rs->path < path)
9656 continue;
9658 /* If the QP for this insn implies a QP which has branched, don't
9659 bother checking. Ed. NOTE: I don't think this check is terribly
9660 useful; what's the point of generating code which will only be
9661 reached if its QP is zero?
9662 This code was specifically inserted to handle the following code,
9663 based on notes from Intel's DV checking code, where p1 implies p2.
9665 mov r4 = 2
9666 (p2) br.cond L
9667 (p1) mov r4 = 7
9669 if (CURR_SLOT.qp_regno != 0)
9671 int skip = 0;
9672 int implies;
9673 for (implies = 0; implies < qp_implieslen; implies++)
9675 if (qp_implies[implies].path >= path
9676 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
9677 && qp_implies[implies].p2_branched)
9679 skip = 1;
9680 break;
9683 if (skip)
9684 continue;
9687 if ((matchtype = resources_match (rs, idesc, note,
9688 CURR_SLOT.qp_regno, path)) != 0)
9690 char msg[1024];
9691 char pathmsg[256] = "";
9692 char indexmsg[256] = "";
9693 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
9695 if (path != 0)
9696 sprintf (pathmsg, " when entry is at label '%s'",
9697 md.entry_labels[path - 1]);
9698 if (rs->specific && rs->index != 0)
9699 sprintf (indexmsg, ", specific resource number is %d",
9700 rs->index);
9701 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
9702 idesc->name,
9703 (certain ? "violates" : "may violate"),
9704 dv_mode[dep->mode], dep->name,
9705 dv_sem[dep->semantics],
9706 pathmsg, indexmsg);
9708 if (md.explicit_mode)
9710 as_warn ("%s", msg);
9711 if (path < md.path)
9712 as_warn (_("Only the first path encountering the conflict "
9713 "is reported"));
9714 as_warn_where (rs->file, rs->line,
9715 _("This is the location of the "
9716 "conflicting usage"));
9717 /* Don't bother checking other paths, to avoid duplicating
9718 the same warning */
9719 break;
9721 else
9723 if (md.debug_dv)
9724 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
9726 remove_marked_resource (rs);
9728 /* since the set of dependencies has changed, start over */
9729 /* FIXME -- since we're removing dvs as we go, we
9730 probably don't really need to start over... */
9731 start_over = 1;
9732 break;
9736 if (start_over)
9737 i = 0;
9738 else
9739 ++i;
9743 /* Register new dependencies based on the given opcode. */
9745 static void
9746 mark_resources (idesc)
9747 struct ia64_opcode *idesc;
9749 int i;
9750 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
9751 int add_only_qp_reads = 0;
9753 /* A conditional branch only uses its resources if it is taken; if it is
9754 taken, we stop following that path. The other branch types effectively
9755 *always* write their resources. If it's not taken, register only QP
9756 reads. */
9757 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
9759 add_only_qp_reads = 1;
9762 if (md.debug_dv)
9763 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
9765 for (i = 0; i < opdeps->nregs; i++)
9767 const struct ia64_dependency *dep;
9768 struct rsrc specs[MAX_SPECS];
9769 int note;
9770 int path;
9771 int count;
9773 dep = ia64_find_dependency (opdeps->regs[i]);
9774 note = NOTE (opdeps->regs[i]);
9776 if (add_only_qp_reads
9777 && !(dep->mode == IA64_DV_WAR
9778 && (dep->specifier == IA64_RS_PR
9779 || dep->specifier == IA64_RS_PRr
9780 || dep->specifier == IA64_RS_PR63)))
9781 continue;
9783 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
9785 #if 0
9786 if (md.debug_dv && !count)
9787 fprintf (stderr, " No %s %s usage found (path %d)\n",
9788 dv_mode[dep->mode], dep->name, md.path);
9789 #endif
9791 while (count-- > 0)
9793 mark_resource (idesc, dep, &specs[count],
9794 DEP (opdeps->regs[i]), md.path);
9797 /* The execution path may affect register values, which may in turn
9798 affect which indirect-access resources are accessed. */
9799 switch (dep->specifier)
9801 default:
9802 break;
9803 case IA64_RS_CPUID:
9804 case IA64_RS_DBR:
9805 case IA64_RS_IBR:
9806 case IA64_RS_MSR:
9807 case IA64_RS_PKR:
9808 case IA64_RS_PMC:
9809 case IA64_RS_PMD:
9810 case IA64_RS_RR:
9811 for (path = 0; path < md.path; path++)
9813 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
9814 while (count-- > 0)
9815 mark_resource (idesc, dep, &specs[count],
9816 DEP (opdeps->regs[i]), path);
9818 break;
9823 /* Remove dependencies when they no longer apply. */
9825 static void
9826 update_dependencies (idesc)
9827 struct ia64_opcode *idesc;
9829 int i;
9831 if (strcmp (idesc->name, "srlz.i") == 0)
9833 instruction_serialization ();
9835 else if (strcmp (idesc->name, "srlz.d") == 0)
9837 data_serialization ();
9839 else if (is_interruption_or_rfi (idesc)
9840 || is_taken_branch (idesc))
9842 /* Although technically the taken branch doesn't clear dependencies
9843 which require a srlz.[id], we don't follow the branch; the next
9844 instruction is assumed to start with a clean slate. */
9845 regdepslen = 0;
9846 md.path = 0;
9848 else if (is_conditional_branch (idesc)
9849 && CURR_SLOT.qp_regno != 0)
9851 int is_call = strstr (idesc->name, ".call") != NULL;
9853 for (i = 0; i < qp_implieslen; i++)
9855 /* If the conditional branch's predicate is implied by the predicate
9856 in an existing dependency, remove that dependency. */
9857 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
9859 int depind = 0;
9860 /* Note that this implied predicate takes a branch so that if
9861 a later insn generates a DV but its predicate implies this
9862 one, we can avoid the false DV warning. */
9863 qp_implies[i].p2_branched = 1;
9864 while (depind < regdepslen)
9866 if (regdeps[depind].qp_regno == qp_implies[i].p1)
9868 print_dependency ("Removing", depind);
9869 regdeps[depind] = regdeps[--regdepslen];
9871 else
9872 ++depind;
9876 /* Any marked resources which have this same predicate should be
9877 cleared, provided that the QP hasn't been modified between the
9878 marking instruction and the branch. */
9879 if (is_call)
9881 insn_group_break (0, CURR_SLOT.qp_regno, 1);
9883 else
9885 i = 0;
9886 while (i < regdepslen)
9888 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
9889 && regdeps[i].link_to_qp_branch
9890 && (regdeps[i].file != CURR_SLOT.src_file
9891 || regdeps[i].line != CURR_SLOT.src_line))
9893 /* Treat like a taken branch */
9894 print_dependency ("Removing", i);
9895 regdeps[i] = regdeps[--regdepslen];
9897 else
9898 ++i;
9904 /* Examine the current instruction for dependency violations. */
9906 static int
9907 check_dv (idesc)
9908 struct ia64_opcode *idesc;
9910 if (md.debug_dv)
9912 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
9913 idesc->name, CURR_SLOT.src_line,
9914 idesc->dependencies->nchks,
9915 idesc->dependencies->nregs);
9918 /* Look through the list of currently marked resources; if the current
9919 instruction has the dependency in its chks list which uses that resource,
9920 check against the specific resources used. */
9921 check_dependencies (idesc);
9923 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
9924 then add them to the list of marked resources. */
9925 mark_resources (idesc);
9927 /* There are several types of dependency semantics, and each has its own
9928 requirements for being cleared
9930 Instruction serialization (insns separated by interruption, rfi, or
9931 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
9933 Data serialization (instruction serialization, or writer + srlz.d +
9934 reader, where writer and srlz.d are in separate groups) clears
9935 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
9936 always be the case).
9938 Instruction group break (groups separated by stop, taken branch,
9939 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
9941 update_dependencies (idesc);
9943 /* Sometimes, knowing a register value allows us to avoid giving a false DV
9944 warning. Keep track of as many as possible that are useful. */
9945 note_register_values (idesc);
9947 /* We don't need or want this anymore. */
9948 md.mem_offset.hint = 0;
9950 return 0;
9953 /* Translate one line of assembly. Pseudo ops and labels do not show
9954 here. */
9955 void
9956 md_assemble (str)
9957 char *str;
9959 char *saved_input_line_pointer, *mnemonic;
9960 const struct pseudo_opcode *pdesc;
9961 struct ia64_opcode *idesc;
9962 unsigned char qp_regno;
9963 unsigned int flags;
9964 int ch;
9966 saved_input_line_pointer = input_line_pointer;
9967 input_line_pointer = str;
9969 /* extract the opcode (mnemonic): */
9971 mnemonic = input_line_pointer;
9972 ch = get_symbol_end ();
9973 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
9974 if (pdesc)
9976 *input_line_pointer = ch;
9977 (*pdesc->handler) (pdesc->arg);
9978 goto done;
9981 /* Find the instruction descriptor matching the arguments. */
9983 idesc = ia64_find_opcode (mnemonic);
9984 *input_line_pointer = ch;
9985 if (!idesc)
9987 as_bad ("Unknown opcode `%s'", mnemonic);
9988 goto done;
9991 idesc = parse_operands (idesc);
9992 if (!idesc)
9993 goto done;
9995 /* Handle the dynamic ops we can handle now: */
9996 if (idesc->type == IA64_TYPE_DYN)
9998 if (strcmp (idesc->name, "add") == 0)
10000 if (CURR_SLOT.opnd[2].X_op == O_register
10001 && CURR_SLOT.opnd[2].X_add_number < 4)
10002 mnemonic = "addl";
10003 else
10004 mnemonic = "adds";
10005 ia64_free_opcode (idesc);
10006 idesc = ia64_find_opcode (mnemonic);
10007 #if 0
10008 know (!idesc->next);
10009 #endif
10011 else if (strcmp (idesc->name, "mov") == 0)
10013 enum ia64_opnd opnd1, opnd2;
10014 int rop;
10016 opnd1 = idesc->operands[0];
10017 opnd2 = idesc->operands[1];
10018 if (opnd1 == IA64_OPND_AR3)
10019 rop = 0;
10020 else if (opnd2 == IA64_OPND_AR3)
10021 rop = 1;
10022 else
10023 abort ();
10024 if (CURR_SLOT.opnd[rop].X_op == O_register
10025 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10026 mnemonic = "mov.i";
10027 else
10028 mnemonic = "mov.m";
10029 ia64_free_opcode (idesc);
10030 idesc = ia64_find_opcode (mnemonic);
10031 while (idesc != NULL
10032 && (idesc->operands[0] != opnd1
10033 || idesc->operands[1] != opnd2))
10034 idesc = get_next_opcode (idesc);
10038 qp_regno = 0;
10039 if (md.qp.X_op == O_register)
10041 qp_regno = md.qp.X_add_number - REG_P;
10042 md.qp.X_op = O_absent;
10045 flags = idesc->flags;
10047 if ((flags & IA64_OPCODE_FIRST) != 0)
10049 /* The alignment frag has to end with a stop bit only if the
10050 next instruction after the alignment directive has to be
10051 the first instruction in an instruction group. */
10052 if (align_frag)
10054 while (align_frag->fr_type != rs_align_code)
10056 align_frag = align_frag->fr_next;
10057 if (!align_frag)
10058 break;
10060 /* align_frag can be NULL if there are directives in
10061 between. */
10062 if (align_frag && align_frag->fr_next == frag_now)
10063 align_frag->tc_frag_data = 1;
10066 insn_group_break (1, 0, 0);
10068 align_frag = NULL;
10070 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10072 as_bad ("`%s' cannot be predicated", idesc->name);
10073 goto done;
10076 /* Build the instruction. */
10077 CURR_SLOT.qp_regno = qp_regno;
10078 CURR_SLOT.idesc = idesc;
10079 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10080 dwarf2_where (&CURR_SLOT.debug_line);
10082 /* Add unwind entry, if there is one. */
10083 if (unwind.current_entry)
10085 CURR_SLOT.unwind_record = unwind.current_entry;
10086 unwind.current_entry = NULL;
10089 /* Check for dependency violations. */
10090 if (md.detect_dv)
10091 check_dv (idesc);
10093 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10094 if (++md.num_slots_in_use >= NUM_SLOTS)
10095 emit_one_bundle ();
10097 if ((flags & IA64_OPCODE_LAST) != 0)
10098 insn_group_break (1, 0, 0);
10100 md.last_text_seg = now_seg;
10102 done:
10103 input_line_pointer = saved_input_line_pointer;
10106 /* Called when symbol NAME cannot be found in the symbol table.
10107 Should be used for dynamic valued symbols only. */
10109 symbolS *
10110 md_undefined_symbol (name)
10111 char *name ATTRIBUTE_UNUSED;
10113 return 0;
10116 /* Called for any expression that can not be recognized. When the
10117 function is called, `input_line_pointer' will point to the start of
10118 the expression. */
10120 void
10121 md_operand (e)
10122 expressionS *e;
10124 enum pseudo_type pseudo_type;
10125 const char *name;
10126 size_t len;
10127 int ch, i;
10129 switch (*input_line_pointer)
10131 case '@':
10132 /* Find what relocation pseudo-function we're dealing with. */
10133 pseudo_type = 0;
10134 ch = *++input_line_pointer;
10135 for (i = 0; i < NELEMS (pseudo_func); ++i)
10136 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
10138 len = strlen (pseudo_func[i].name);
10139 if (strncmp (pseudo_func[i].name + 1,
10140 input_line_pointer + 1, len - 1) == 0
10141 && !is_part_of_name (input_line_pointer[len]))
10143 input_line_pointer += len;
10144 pseudo_type = pseudo_func[i].type;
10145 break;
10148 switch (pseudo_type)
10150 case PSEUDO_FUNC_RELOC:
10151 SKIP_WHITESPACE ();
10152 if (*input_line_pointer != '(')
10154 as_bad ("Expected '('");
10155 goto err;
10157 /* Skip '('. */
10158 ++input_line_pointer;
10159 expression (e);
10160 if (*input_line_pointer++ != ')')
10162 as_bad ("Missing ')'");
10163 goto err;
10165 if (e->X_op != O_symbol)
10167 if (e->X_op != O_pseudo_fixup)
10169 as_bad ("Not a symbolic expression");
10170 goto err;
10172 if (i != FUNC_LT_RELATIVE)
10174 as_bad ("Illegal combination of relocation functions");
10175 goto err;
10177 switch (S_GET_VALUE (e->X_op_symbol))
10179 case FUNC_FPTR_RELATIVE:
10180 i = FUNC_LT_FPTR_RELATIVE; break;
10181 case FUNC_DTP_MODULE:
10182 i = FUNC_LT_DTP_MODULE; break;
10183 case FUNC_DTP_RELATIVE:
10184 i = FUNC_LT_DTP_RELATIVE; break;
10185 case FUNC_TP_RELATIVE:
10186 i = FUNC_LT_TP_RELATIVE; break;
10187 default:
10188 as_bad ("Illegal combination of relocation functions");
10189 goto err;
10192 /* Make sure gas doesn't get rid of local symbols that are used
10193 in relocs. */
10194 e->X_op = O_pseudo_fixup;
10195 e->X_op_symbol = pseudo_func[i].u.sym;
10196 break;
10198 case PSEUDO_FUNC_CONST:
10199 e->X_op = O_constant;
10200 e->X_add_number = pseudo_func[i].u.ival;
10201 break;
10203 case PSEUDO_FUNC_REG:
10204 e->X_op = O_register;
10205 e->X_add_number = pseudo_func[i].u.ival;
10206 break;
10208 default:
10209 name = input_line_pointer - 1;
10210 get_symbol_end ();
10211 as_bad ("Unknown pseudo function `%s'", name);
10212 goto err;
10214 break;
10216 case '[':
10217 ++input_line_pointer;
10218 expression (e);
10219 if (*input_line_pointer != ']')
10221 as_bad ("Closing bracket misssing");
10222 goto err;
10224 else
10226 if (e->X_op != O_register)
10227 as_bad ("Register expected as index");
10229 ++input_line_pointer;
10230 e->X_op = O_index;
10232 break;
10234 default:
10235 break;
10237 return;
10239 err:
10240 ignore_rest_of_line ();
10243 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10244 a section symbol plus some offset. For relocs involving @fptr(),
10245 directives we don't want such adjustments since we need to have the
10246 original symbol's name in the reloc. */
10248 ia64_fix_adjustable (fix)
10249 fixS *fix;
10251 /* Prevent all adjustments to global symbols */
10252 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10253 return 0;
10255 switch (fix->fx_r_type)
10257 case BFD_RELOC_IA64_FPTR64I:
10258 case BFD_RELOC_IA64_FPTR32MSB:
10259 case BFD_RELOC_IA64_FPTR32LSB:
10260 case BFD_RELOC_IA64_FPTR64MSB:
10261 case BFD_RELOC_IA64_FPTR64LSB:
10262 case BFD_RELOC_IA64_LTOFF_FPTR22:
10263 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10264 return 0;
10265 default:
10266 break;
10269 return 1;
10273 ia64_force_relocation (fix)
10274 fixS *fix;
10276 switch (fix->fx_r_type)
10278 case BFD_RELOC_IA64_FPTR64I:
10279 case BFD_RELOC_IA64_FPTR32MSB:
10280 case BFD_RELOC_IA64_FPTR32LSB:
10281 case BFD_RELOC_IA64_FPTR64MSB:
10282 case BFD_RELOC_IA64_FPTR64LSB:
10284 case BFD_RELOC_IA64_LTOFF22:
10285 case BFD_RELOC_IA64_LTOFF64I:
10286 case BFD_RELOC_IA64_LTOFF_FPTR22:
10287 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10288 case BFD_RELOC_IA64_PLTOFF22:
10289 case BFD_RELOC_IA64_PLTOFF64I:
10290 case BFD_RELOC_IA64_PLTOFF64MSB:
10291 case BFD_RELOC_IA64_PLTOFF64LSB:
10293 case BFD_RELOC_IA64_LTOFF22X:
10294 case BFD_RELOC_IA64_LDXMOV:
10295 return 1;
10297 default:
10298 break;
10301 return generic_force_reloc (fix);
10304 /* Decide from what point a pc-relative relocation is relative to,
10305 relative to the pc-relative fixup. Er, relatively speaking. */
10306 long
10307 ia64_pcrel_from_section (fix, sec)
10308 fixS *fix;
10309 segT sec;
10311 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10313 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10314 off &= ~0xfUL;
10316 return off;
10320 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10321 void
10322 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10324 expressionS expr;
10326 expr.X_op = O_pseudo_fixup;
10327 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10328 expr.X_add_number = 0;
10329 expr.X_add_symbol = symbol;
10330 emit_expr (&expr, size);
10333 /* This is called whenever some data item (not an instruction) needs a
10334 fixup. We pick the right reloc code depending on the byteorder
10335 currently in effect. */
10336 void
10337 ia64_cons_fix_new (f, where, nbytes, exp)
10338 fragS *f;
10339 int where;
10340 int nbytes;
10341 expressionS *exp;
10343 bfd_reloc_code_real_type code;
10344 fixS *fix;
10346 switch (nbytes)
10348 /* There are no reloc for 8 and 16 bit quantities, but we allow
10349 them here since they will work fine as long as the expression
10350 is fully defined at the end of the pass over the source file. */
10351 case 1: code = BFD_RELOC_8; break;
10352 case 2: code = BFD_RELOC_16; break;
10353 case 4:
10354 if (target_big_endian)
10355 code = BFD_RELOC_IA64_DIR32MSB;
10356 else
10357 code = BFD_RELOC_IA64_DIR32LSB;
10358 break;
10360 case 8:
10361 /* In 32-bit mode, data8 could mean function descriptors too. */
10362 if (exp->X_op == O_pseudo_fixup
10363 && exp->X_op_symbol
10364 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10365 && !(md.flags & EF_IA_64_ABI64))
10367 if (target_big_endian)
10368 code = BFD_RELOC_IA64_IPLTMSB;
10369 else
10370 code = BFD_RELOC_IA64_IPLTLSB;
10371 exp->X_op = O_symbol;
10372 break;
10374 else
10376 if (target_big_endian)
10377 code = BFD_RELOC_IA64_DIR64MSB;
10378 else
10379 code = BFD_RELOC_IA64_DIR64LSB;
10380 break;
10383 case 16:
10384 if (exp->X_op == O_pseudo_fixup
10385 && exp->X_op_symbol
10386 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10388 if (target_big_endian)
10389 code = BFD_RELOC_IA64_IPLTMSB;
10390 else
10391 code = BFD_RELOC_IA64_IPLTLSB;
10392 exp->X_op = O_symbol;
10393 break;
10395 /* FALLTHRU */
10397 default:
10398 as_bad ("Unsupported fixup size %d", nbytes);
10399 ignore_rest_of_line ();
10400 return;
10403 if (exp->X_op == O_pseudo_fixup)
10405 exp->X_op = O_symbol;
10406 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10407 /* ??? If code unchanged, unsupported. */
10410 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10411 /* We need to store the byte order in effect in case we're going
10412 to fix an 8 or 16 bit relocation (for which there no real
10413 relocs available). See md_apply_fix3(). */
10414 fix->tc_fix_data.bigendian = target_big_endian;
10417 /* Return the actual relocation we wish to associate with the pseudo
10418 reloc described by SYM and R_TYPE. SYM should be one of the
10419 symbols in the pseudo_func array, or NULL. */
10421 static bfd_reloc_code_real_type
10422 ia64_gen_real_reloc_type (sym, r_type)
10423 struct symbol *sym;
10424 bfd_reloc_code_real_type r_type;
10426 bfd_reloc_code_real_type new = 0;
10428 if (sym == NULL)
10430 return r_type;
10433 switch (S_GET_VALUE (sym))
10435 case FUNC_FPTR_RELATIVE:
10436 switch (r_type)
10438 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10439 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10440 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10441 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10442 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10443 default: break;
10445 break;
10447 case FUNC_GP_RELATIVE:
10448 switch (r_type)
10450 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10451 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10452 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10453 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10454 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10455 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10456 default: break;
10458 break;
10460 case FUNC_LT_RELATIVE:
10461 switch (r_type)
10463 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
10464 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
10465 default: break;
10467 break;
10469 case FUNC_LT_RELATIVE_X:
10470 switch (r_type)
10472 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
10473 default: break;
10475 break;
10477 case FUNC_PC_RELATIVE:
10478 switch (r_type)
10480 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
10481 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
10482 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
10483 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
10484 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
10485 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
10486 default: break;
10488 break;
10490 case FUNC_PLT_RELATIVE:
10491 switch (r_type)
10493 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
10494 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
10495 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
10496 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
10497 default: break;
10499 break;
10501 case FUNC_SEC_RELATIVE:
10502 switch (r_type)
10504 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
10505 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
10506 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
10507 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
10508 default: break;
10510 break;
10512 case FUNC_SEG_RELATIVE:
10513 switch (r_type)
10515 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
10516 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
10517 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
10518 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
10519 default: break;
10521 break;
10523 case FUNC_LTV_RELATIVE:
10524 switch (r_type)
10526 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
10527 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
10528 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
10529 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
10530 default: break;
10532 break;
10534 case FUNC_LT_FPTR_RELATIVE:
10535 switch (r_type)
10537 case BFD_RELOC_IA64_IMM22:
10538 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
10539 case BFD_RELOC_IA64_IMM64:
10540 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
10541 default:
10542 break;
10544 break;
10546 case FUNC_TP_RELATIVE:
10547 switch (r_type)
10549 case BFD_RELOC_IA64_IMM14:
10550 new = BFD_RELOC_IA64_TPREL14; break;
10551 case BFD_RELOC_IA64_IMM22:
10552 new = BFD_RELOC_IA64_TPREL22; break;
10553 case BFD_RELOC_IA64_IMM64:
10554 new = BFD_RELOC_IA64_TPREL64I; break;
10555 default:
10556 break;
10558 break;
10560 case FUNC_LT_TP_RELATIVE:
10561 switch (r_type)
10563 case BFD_RELOC_IA64_IMM22:
10564 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
10565 default:
10566 break;
10568 break;
10570 case FUNC_LT_DTP_MODULE:
10571 switch (r_type)
10573 case BFD_RELOC_IA64_IMM22:
10574 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
10575 default:
10576 break;
10578 break;
10580 case FUNC_DTP_RELATIVE:
10581 switch (r_type)
10583 case BFD_RELOC_IA64_DIR64MSB:
10584 new = BFD_RELOC_IA64_DTPREL64MSB; break;
10585 case BFD_RELOC_IA64_DIR64LSB:
10586 new = BFD_RELOC_IA64_DTPREL64LSB; break;
10587 case BFD_RELOC_IA64_IMM14:
10588 new = BFD_RELOC_IA64_DTPREL14; break;
10589 case BFD_RELOC_IA64_IMM22:
10590 new = BFD_RELOC_IA64_DTPREL22; break;
10591 case BFD_RELOC_IA64_IMM64:
10592 new = BFD_RELOC_IA64_DTPREL64I; break;
10593 default:
10594 break;
10596 break;
10598 case FUNC_LT_DTP_RELATIVE:
10599 switch (r_type)
10601 case BFD_RELOC_IA64_IMM22:
10602 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
10603 default:
10604 break;
10606 break;
10608 case FUNC_IPLT_RELOC:
10609 break;
10611 default:
10612 abort ();
10615 /* Hmmmm. Should this ever occur? */
10616 if (new)
10617 return new;
10618 else
10619 return r_type;
10622 /* Here is where generate the appropriate reloc for pseudo relocation
10623 functions. */
10624 void
10625 ia64_validate_fix (fix)
10626 fixS *fix;
10628 switch (fix->fx_r_type)
10630 case BFD_RELOC_IA64_FPTR64I:
10631 case BFD_RELOC_IA64_FPTR32MSB:
10632 case BFD_RELOC_IA64_FPTR64LSB:
10633 case BFD_RELOC_IA64_LTOFF_FPTR22:
10634 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10635 if (fix->fx_offset != 0)
10636 as_bad_where (fix->fx_file, fix->fx_line,
10637 "No addend allowed in @fptr() relocation");
10638 break;
10639 default:
10640 break;
10644 static void
10645 fix_insn (fix, odesc, value)
10646 fixS *fix;
10647 const struct ia64_operand *odesc;
10648 valueT value;
10650 bfd_vma insn[3], t0, t1, control_bits;
10651 const char *err;
10652 char *fixpos;
10653 long slot;
10655 slot = fix->fx_where & 0x3;
10656 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
10658 /* Bundles are always in little-endian byte order */
10659 t0 = bfd_getl64 (fixpos);
10660 t1 = bfd_getl64 (fixpos + 8);
10661 control_bits = t0 & 0x1f;
10662 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
10663 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
10664 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
10666 err = NULL;
10667 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
10669 insn[1] = (value >> 22) & 0x1ffffffffffLL;
10670 insn[2] |= (((value & 0x7f) << 13)
10671 | (((value >> 7) & 0x1ff) << 27)
10672 | (((value >> 16) & 0x1f) << 22)
10673 | (((value >> 21) & 0x1) << 21)
10674 | (((value >> 63) & 0x1) << 36));
10676 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
10678 if (value & ~0x3fffffffffffffffULL)
10679 err = "integer operand out of range";
10680 insn[1] = (value >> 21) & 0x1ffffffffffLL;
10681 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
10683 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
10685 value >>= 4;
10686 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
10687 insn[2] |= ((((value >> 59) & 0x1) << 36)
10688 | (((value >> 0) & 0xfffff) << 13));
10690 else
10691 err = (*odesc->insert) (odesc, value, insn + slot);
10693 if (err)
10694 as_bad_where (fix->fx_file, fix->fx_line, err);
10696 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
10697 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
10698 number_to_chars_littleendian (fixpos + 0, t0, 8);
10699 number_to_chars_littleendian (fixpos + 8, t1, 8);
10702 /* Attempt to simplify or even eliminate a fixup. The return value is
10703 ignored; perhaps it was once meaningful, but now it is historical.
10704 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
10706 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
10707 (if possible). */
10709 void
10710 md_apply_fix3 (fix, valP, seg)
10711 fixS *fix;
10712 valueT *valP;
10713 segT seg ATTRIBUTE_UNUSED;
10715 char *fixpos;
10716 valueT value = *valP;
10718 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
10720 if (fix->fx_pcrel)
10722 switch (fix->fx_r_type)
10724 case BFD_RELOC_IA64_DIR32MSB:
10725 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
10726 break;
10728 case BFD_RELOC_IA64_DIR32LSB:
10729 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
10730 break;
10732 case BFD_RELOC_IA64_DIR64MSB:
10733 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
10734 break;
10736 case BFD_RELOC_IA64_DIR64LSB:
10737 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
10738 break;
10740 default:
10741 break;
10744 if (fix->fx_addsy)
10746 switch (fix->fx_r_type)
10748 case BFD_RELOC_UNUSED:
10749 /* This must be a TAG13 or TAG13b operand. There are no external
10750 relocs defined for them, so we must give an error. */
10751 as_bad_where (fix->fx_file, fix->fx_line,
10752 "%s must have a constant value",
10753 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
10754 fix->fx_done = 1;
10755 return;
10757 case BFD_RELOC_IA64_TPREL14:
10758 case BFD_RELOC_IA64_TPREL22:
10759 case BFD_RELOC_IA64_TPREL64I:
10760 case BFD_RELOC_IA64_LTOFF_TPREL22:
10761 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
10762 case BFD_RELOC_IA64_DTPREL14:
10763 case BFD_RELOC_IA64_DTPREL22:
10764 case BFD_RELOC_IA64_DTPREL64I:
10765 case BFD_RELOC_IA64_LTOFF_DTPREL22:
10766 S_SET_THREAD_LOCAL (fix->fx_addsy);
10767 break;
10769 default:
10770 break;
10773 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
10775 if (fix->tc_fix_data.bigendian)
10776 number_to_chars_bigendian (fixpos, value, fix->fx_size);
10777 else
10778 number_to_chars_littleendian (fixpos, value, fix->fx_size);
10779 fix->fx_done = 1;
10781 else
10783 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
10784 fix->fx_done = 1;
10788 /* Generate the BFD reloc to be stuck in the object file from the
10789 fixup used internally in the assembler. */
10791 arelent *
10792 tc_gen_reloc (sec, fixp)
10793 asection *sec ATTRIBUTE_UNUSED;
10794 fixS *fixp;
10796 arelent *reloc;
10798 reloc = xmalloc (sizeof (*reloc));
10799 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
10800 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
10801 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
10802 reloc->addend = fixp->fx_offset;
10803 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
10805 if (!reloc->howto)
10807 as_bad_where (fixp->fx_file, fixp->fx_line,
10808 "Cannot represent %s relocation in object file",
10809 bfd_get_reloc_code_name (fixp->fx_r_type));
10811 return reloc;
10814 /* Turn a string in input_line_pointer into a floating point constant
10815 of type TYPE, and store the appropriate bytes in *LIT. The number
10816 of LITTLENUMS emitted is stored in *SIZE. An error message is
10817 returned, or NULL on OK. */
10819 #define MAX_LITTLENUMS 5
10821 char *
10822 md_atof (type, lit, size)
10823 int type;
10824 char *lit;
10825 int *size;
10827 LITTLENUM_TYPE words[MAX_LITTLENUMS];
10828 char *t;
10829 int prec;
10831 switch (type)
10833 /* IEEE floats */
10834 case 'f':
10835 case 'F':
10836 case 's':
10837 case 'S':
10838 prec = 2;
10839 break;
10841 case 'd':
10842 case 'D':
10843 case 'r':
10844 case 'R':
10845 prec = 4;
10846 break;
10848 case 'x':
10849 case 'X':
10850 case 'p':
10851 case 'P':
10852 prec = 5;
10853 break;
10855 default:
10856 *size = 0;
10857 return "Bad call to MD_ATOF()";
10859 t = atof_ieee (input_line_pointer, type, words);
10860 if (t)
10861 input_line_pointer = t;
10863 (*ia64_float_to_chars) (lit, words, prec);
10865 if (type == 'X')
10867 /* It is 10 byte floating point with 6 byte padding. */
10868 memset (&lit [10], 0, 6);
10869 *size = 8 * sizeof (LITTLENUM_TYPE);
10871 else
10872 *size = prec * sizeof (LITTLENUM_TYPE);
10874 return 0;
10877 /* Handle ia64 specific semantics of the align directive. */
10879 void
10880 ia64_md_do_align (n, fill, len, max)
10881 int n ATTRIBUTE_UNUSED;
10882 const char *fill ATTRIBUTE_UNUSED;
10883 int len ATTRIBUTE_UNUSED;
10884 int max ATTRIBUTE_UNUSED;
10886 if (subseg_text_p (now_seg))
10887 ia64_flush_insns ();
10890 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
10891 of an rs_align_code fragment. */
10893 void
10894 ia64_handle_align (fragp)
10895 fragS *fragp;
10897 /* Use mfi bundle of nops with no stop bits. */
10898 static const unsigned char le_nop[]
10899 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10900 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10901 static const unsigned char le_nop_stop[]
10902 = { 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
10903 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
10905 int bytes;
10906 char *p;
10907 const unsigned char *nop;
10909 if (fragp->fr_type != rs_align_code)
10910 return;
10912 /* Check if this frag has to end with a stop bit. */
10913 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
10915 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
10916 p = fragp->fr_literal + fragp->fr_fix;
10918 /* If no paddings are needed, we check if we need a stop bit. */
10919 if (!bytes && fragp->tc_frag_data)
10921 if (fragp->fr_fix < 16)
10922 #if 1
10923 /* FIXME: It won't work with
10924 .align 16
10925 alloc r32=ar.pfs,1,2,4,0
10928 #else
10929 as_bad_where (fragp->fr_file, fragp->fr_line,
10930 _("Can't add stop bit to mark end of instruction group"));
10931 #endif
10932 else
10933 /* Bundles are always in little-endian byte order. Make sure
10934 the previous bundle has the stop bit. */
10935 *(p - 16) |= 1;
10938 /* Make sure we are on a 16-byte boundary, in case someone has been
10939 putting data into a text section. */
10940 if (bytes & 15)
10942 int fix = bytes & 15;
10943 memset (p, 0, fix);
10944 p += fix;
10945 bytes -= fix;
10946 fragp->fr_fix += fix;
10949 /* Instruction bundles are always little-endian. */
10950 memcpy (p, nop, 16);
10951 fragp->fr_var = 16;
10954 static void
10955 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
10956 int prec)
10958 while (prec--)
10960 number_to_chars_bigendian (lit, (long) (*words++),
10961 sizeof (LITTLENUM_TYPE));
10962 lit += sizeof (LITTLENUM_TYPE);
10966 static void
10967 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
10968 int prec)
10970 while (prec--)
10972 number_to_chars_littleendian (lit, (long) (words[prec]),
10973 sizeof (LITTLENUM_TYPE));
10974 lit += sizeof (LITTLENUM_TYPE);
10978 void
10979 ia64_elf_section_change_hook (void)
10981 dot_byteorder (-1);
10984 /* Check if a label should be made global. */
10985 void
10986 ia64_check_label (symbolS *label)
10988 if (*input_line_pointer == ':')
10990 S_SET_EXTERNAL (label);
10991 input_line_pointer++;
10995 /* Used to remember where .alias and .secalias directives are seen. We
10996 will rename symbol and section names when we are about to output
10997 the relocatable file. */
10998 struct alias
11000 char *file; /* The file where the directive is seen. */
11001 unsigned int line; /* The line number the directive is at. */
11002 const char *name; /* The orignale name of the symbol. */
11005 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11006 .secalias. Otherwise, it is .alias. */
11007 static void
11008 dot_alias (int section)
11010 char *name, *alias;
11011 char delim;
11012 char *end_name;
11013 int len;
11014 const char *error_string;
11015 struct alias *h;
11016 const char *a;
11017 struct hash_control *ahash, *nhash;
11018 const char *kind;
11020 name = input_line_pointer;
11021 delim = get_symbol_end ();
11022 end_name = input_line_pointer;
11023 *end_name = delim;
11025 if (name == end_name)
11027 as_bad (_("expected symbol name"));
11028 discard_rest_of_line ();
11029 return;
11032 SKIP_WHITESPACE ();
11034 if (*input_line_pointer != ',')
11036 *end_name = 0;
11037 as_bad (_("expected comma after \"%s\""), name);
11038 *end_name = delim;
11039 ignore_rest_of_line ();
11040 return;
11043 input_line_pointer++;
11044 *end_name = 0;
11046 /* We call demand_copy_C_string to check if alias string is valid.
11047 There should be a closing `"' and no `\0' in the string. */
11048 alias = demand_copy_C_string (&len);
11049 if (alias == NULL)
11051 ignore_rest_of_line ();
11052 return;
11055 /* Make a copy of name string. */
11056 len = strlen (name) + 1;
11057 obstack_grow (&notes, name, len);
11058 name = obstack_finish (&notes);
11060 if (section)
11062 kind = "section";
11063 ahash = secalias_hash;
11064 nhash = secalias_name_hash;
11066 else
11068 kind = "symbol";
11069 ahash = alias_hash;
11070 nhash = alias_name_hash;
11073 /* Check if alias has been used before. */
11074 h = (struct alias *) hash_find (ahash, alias);
11075 if (h)
11077 if (strcmp (h->name, name))
11078 as_bad (_("`%s' is already the alias of %s `%s'"),
11079 alias, kind, h->name);
11080 goto out;
11083 /* Check if name already has an alias. */
11084 a = (const char *) hash_find (nhash, name);
11085 if (a)
11087 if (strcmp (a, alias))
11088 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11089 goto out;
11092 h = (struct alias *) xmalloc (sizeof (struct alias));
11093 as_where (&h->file, &h->line);
11094 h->name = name;
11096 error_string = hash_jam (ahash, alias, (PTR) h);
11097 if (error_string)
11099 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11100 alias, kind, error_string);
11101 goto out;
11104 error_string = hash_jam (nhash, name, (PTR) alias);
11105 if (error_string)
11107 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11108 alias, kind, error_string);
11109 out:
11110 obstack_free (&notes, name);
11111 obstack_free (&notes, alias);
11114 demand_empty_rest_of_line ();
11117 /* It renames the original symbol name to its alias. */
11118 static void
11119 do_alias (const char *alias, PTR value)
11121 struct alias *h = (struct alias *) value;
11122 symbolS *sym = symbol_find (h->name);
11124 if (sym == NULL)
11125 as_warn_where (h->file, h->line,
11126 _("symbol `%s' aliased to `%s' is not used"),
11127 h->name, alias);
11128 else
11129 S_SET_NAME (sym, (char *) alias);
11132 /* Called from write_object_file. */
11133 void
11134 ia64_adjust_symtab (void)
11136 hash_traverse (alias_hash, do_alias);
11139 /* It renames the original section name to its alias. */
11140 static void
11141 do_secalias (const char *alias, PTR value)
11143 struct alias *h = (struct alias *) value;
11144 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11146 if (sec == NULL)
11147 as_warn_where (h->file, h->line,
11148 _("section `%s' aliased to `%s' is not used"),
11149 h->name, alias);
11150 else
11151 sec->name = alias;
11154 /* Called from write_object_file. */
11155 void
11156 ia64_frob_file (void)
11158 hash_traverse (secalias_hash, do_secalias);