* config/tc-mips.h (mips_flush_pending_output): Delete.
[binutils.git] / gas / config / tc-ia64.c
blobb959cdcf9197f7bd3f062bc0f73426ce51d2f71b
1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 TODO:
26 - optional operands
27 - directives:
28 .eb
29 .estate
30 .lb
31 .popsection
32 .previous
33 .psr
34 .pushsection
35 - labels are wrong if automatic alignment is introduced
36 (e.g., checkout the second real10 definition in test-data.s)
37 - DV-related stuff:
38 <reg>.safe_across_calls and any other DV-related directives I don't
39 have documentation for.
40 verify mod-sched-brs reads/writes are checked/marked (and other
41 notes)
45 #include "as.h"
46 #include "safe-ctype.h"
47 #include "dwarf2dbg.h"
48 #include "subsegs.h"
50 #include "opcode/ia64.h"
52 #include "elf/ia64.h"
54 #ifdef HAVE_LIMITS_H
55 #include <limits.h>
56 #endif
58 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
59 #define MIN(a,b) ((a) < (b) ? (a) : (b))
61 #define NUM_SLOTS 4
62 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
63 #define CURR_SLOT md.slot[md.curr_slot]
65 #define O_pseudo_fixup (O_max + 1)
67 enum special_section
69 /* IA-64 ABI section pseudo-ops. */
70 SPECIAL_SECTION_BSS = 0,
71 SPECIAL_SECTION_SBSS,
72 SPECIAL_SECTION_SDATA,
73 SPECIAL_SECTION_RODATA,
74 SPECIAL_SECTION_COMMENT,
75 SPECIAL_SECTION_UNWIND,
76 SPECIAL_SECTION_UNWIND_INFO,
77 /* HPUX specific section pseudo-ops. */
78 SPECIAL_SECTION_INIT_ARRAY,
79 SPECIAL_SECTION_FINI_ARRAY,
82 enum reloc_func
84 FUNC_DTP_MODULE,
85 FUNC_DTP_RELATIVE,
86 FUNC_FPTR_RELATIVE,
87 FUNC_GP_RELATIVE,
88 FUNC_LT_RELATIVE,
89 FUNC_LT_RELATIVE_X,
90 FUNC_PC_RELATIVE,
91 FUNC_PLT_RELATIVE,
92 FUNC_SEC_RELATIVE,
93 FUNC_SEG_RELATIVE,
94 FUNC_TP_RELATIVE,
95 FUNC_LTV_RELATIVE,
96 FUNC_LT_FPTR_RELATIVE,
97 FUNC_LT_DTP_MODULE,
98 FUNC_LT_DTP_RELATIVE,
99 FUNC_LT_TP_RELATIVE,
100 FUNC_IPLT_RELOC,
103 enum reg_symbol
105 REG_GR = 0,
106 REG_FR = (REG_GR + 128),
107 REG_AR = (REG_FR + 128),
108 REG_CR = (REG_AR + 128),
109 REG_P = (REG_CR + 128),
110 REG_BR = (REG_P + 64),
111 REG_IP = (REG_BR + 8),
112 REG_CFM,
113 REG_PR,
114 REG_PR_ROT,
115 REG_PSR,
116 REG_PSR_L,
117 REG_PSR_UM,
118 /* The following are pseudo-registers for use by gas only. */
119 IND_CPUID,
120 IND_DBR,
121 IND_DTR,
122 IND_ITR,
123 IND_IBR,
124 IND_MEM,
125 IND_MSR,
126 IND_PKR,
127 IND_PMC,
128 IND_PMD,
129 IND_RR,
130 /* The following pseudo-registers are used for unwind directives only: */
131 REG_PSP,
132 REG_PRIUNAT,
133 REG_NUM
136 enum dynreg_type
138 DYNREG_GR = 0, /* dynamic general purpose register */
139 DYNREG_FR, /* dynamic floating point register */
140 DYNREG_PR, /* dynamic predicate register */
141 DYNREG_NUM_TYPES
144 enum operand_match_result
146 OPERAND_MATCH,
147 OPERAND_OUT_OF_RANGE,
148 OPERAND_MISMATCH
151 /* On the ia64, we can't know the address of a text label until the
152 instructions are packed into a bundle. To handle this, we keep
153 track of the list of labels that appear in front of each
154 instruction. */
155 struct label_fix
157 struct label_fix *next;
158 struct symbol *sym;
161 /* This is the endianness of the current section. */
162 extern int target_big_endian;
164 /* This is the default endianness. */
165 static int default_big_endian = TARGET_BYTES_BIG_ENDIAN;
167 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
169 static void ia64_float_to_chars_bigendian
170 PARAMS ((char *, LITTLENUM_TYPE *, int));
171 static void ia64_float_to_chars_littleendian
172 PARAMS ((char *, LITTLENUM_TYPE *, int));
173 static void (*ia64_float_to_chars)
174 PARAMS ((char *, LITTLENUM_TYPE *, int));
176 static struct hash_control *alias_hash;
177 static struct hash_control *alias_name_hash;
178 static struct hash_control *secalias_hash;
179 static struct hash_control *secalias_name_hash;
181 /* List of chars besides those in app.c:symbol_chars that can start an
182 operand. Used to prevent the scrubber eating vital white-space. */
183 const char ia64_symbol_chars[] = "@?";
185 /* Characters which always start a comment. */
186 const char comment_chars[] = "";
188 /* Characters which start a comment at the beginning of a line. */
189 const char line_comment_chars[] = "#";
191 /* Characters which may be used to separate multiple commands on a
192 single line. */
193 const char line_separator_chars[] = ";";
195 /* Characters which are used to indicate an exponent in a floating
196 point number. */
197 const char EXP_CHARS[] = "eE";
199 /* Characters which mean that a number is a floating point constant,
200 as in 0d1.0. */
201 const char FLT_CHARS[] = "rRsSfFdDxXpP";
203 /* ia64-specific option processing: */
205 const char *md_shortopts = "m:N:x::";
207 struct option md_longopts[] =
209 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
210 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
211 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
212 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
215 size_t md_longopts_size = sizeof (md_longopts);
217 static struct
219 struct hash_control *pseudo_hash; /* pseudo opcode hash table */
220 struct hash_control *reg_hash; /* register name hash table */
221 struct hash_control *dynreg_hash; /* dynamic register hash table */
222 struct hash_control *const_hash; /* constant hash table */
223 struct hash_control *entry_hash; /* code entry hint hash table */
225 symbolS *regsym[REG_NUM];
227 /* If X_op is != O_absent, the registername for the instruction's
228 qualifying predicate. If NULL, p0 is assumed for instructions
229 that are predicatable. */
230 expressionS qp;
232 /* What to do when hint.b is used. */
233 enum
235 hint_b_error,
236 hint_b_warning,
237 hint_b_ok
238 } hint_b;
240 unsigned int
241 manual_bundling : 1,
242 debug_dv: 1,
243 detect_dv: 1,
244 explicit_mode : 1, /* which mode we're in */
245 default_explicit_mode : 1, /* which mode is the default */
246 mode_explicitly_set : 1, /* was the current mode explicitly set? */
247 auto_align : 1,
248 keep_pending_output : 1;
250 /* What to do when something is wrong with unwind directives. */
251 enum
253 unwind_check_warning,
254 unwind_check_error
255 } unwind_check;
257 /* Each bundle consists of up to three instructions. We keep
258 track of four most recent instructions so we can correctly set
259 the end_of_insn_group for the last instruction in a bundle. */
260 int curr_slot;
261 int num_slots_in_use;
262 struct slot
264 unsigned int
265 end_of_insn_group : 1,
266 manual_bundling_on : 1,
267 manual_bundling_off : 1,
268 loc_directive_seen : 1;
269 signed char user_template; /* user-selected template, if any */
270 unsigned char qp_regno; /* qualifying predicate */
271 /* This duplicates a good fraction of "struct fix" but we
272 can't use a "struct fix" instead since we can't call
273 fix_new_exp() until we know the address of the instruction. */
274 int num_fixups;
275 struct insn_fix
277 bfd_reloc_code_real_type code;
278 enum ia64_opnd opnd; /* type of operand in need of fix */
279 unsigned int is_pcrel : 1; /* is operand pc-relative? */
280 expressionS expr; /* the value to be inserted */
282 fixup[2]; /* at most two fixups per insn */
283 struct ia64_opcode *idesc;
284 struct label_fix *label_fixups;
285 struct label_fix *tag_fixups;
286 struct unw_rec_list *unwind_record; /* Unwind directive. */
287 expressionS opnd[6];
288 char *src_file;
289 unsigned int src_line;
290 struct dwarf2_line_info debug_line;
292 slot[NUM_SLOTS];
294 segT last_text_seg;
296 struct dynreg
298 struct dynreg *next; /* next dynamic register */
299 const char *name;
300 unsigned short base; /* the base register number */
301 unsigned short num_regs; /* # of registers in this set */
303 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
305 flagword flags; /* ELF-header flags */
307 struct mem_offset {
308 unsigned hint:1; /* is this hint currently valid? */
309 bfd_vma offset; /* mem.offset offset */
310 bfd_vma base; /* mem.offset base */
311 } mem_offset;
313 int path; /* number of alt. entry points seen */
314 const char **entry_labels; /* labels of all alternate paths in
315 the current DV-checking block. */
316 int maxpaths; /* size currently allocated for
317 entry_labels */
319 int pointer_size; /* size in bytes of a pointer */
320 int pointer_size_shift; /* shift size of a pointer for alignment */
324 /* application registers: */
326 #define AR_K0 0
327 #define AR_K7 7
328 #define AR_RSC 16
329 #define AR_BSP 17
330 #define AR_BSPSTORE 18
331 #define AR_RNAT 19
332 #define AR_UNAT 36
333 #define AR_FPSR 40
334 #define AR_ITC 44
335 #define AR_PFS 64
336 #define AR_LC 65
338 static const struct
340 const char *name;
341 int regnum;
343 ar[] =
345 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
346 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
347 {"ar.rsc", 16}, {"ar.bsp", 17},
348 {"ar.bspstore", 18}, {"ar.rnat", 19},
349 {"ar.fcr", 21}, {"ar.eflag", 24},
350 {"ar.csd", 25}, {"ar.ssd", 26},
351 {"ar.cflg", 27}, {"ar.fsr", 28},
352 {"ar.fir", 29}, {"ar.fdr", 30},
353 {"ar.ccv", 32}, {"ar.unat", 36},
354 {"ar.fpsr", 40}, {"ar.itc", 44},
355 {"ar.pfs", 64}, {"ar.lc", 65},
356 {"ar.ec", 66},
359 #define CR_IPSR 16
360 #define CR_ISR 17
361 #define CR_IIP 19
362 #define CR_IFA 20
363 #define CR_ITIR 21
364 #define CR_IIPA 22
365 #define CR_IFS 23
366 #define CR_IIM 24
367 #define CR_IHA 25
368 #define CR_IVR 65
369 #define CR_TPR 66
370 #define CR_EOI 67
371 #define CR_IRR0 68
372 #define CR_IRR3 71
373 #define CR_LRR0 80
374 #define CR_LRR1 81
376 /* control registers: */
377 static const struct
379 const char *name;
380 int regnum;
382 cr[] =
384 {"cr.dcr", 0},
385 {"cr.itm", 1},
386 {"cr.iva", 2},
387 {"cr.pta", 8},
388 {"cr.gpta", 9},
389 {"cr.ipsr", 16},
390 {"cr.isr", 17},
391 {"cr.iip", 19},
392 {"cr.ifa", 20},
393 {"cr.itir", 21},
394 {"cr.iipa", 22},
395 {"cr.ifs", 23},
396 {"cr.iim", 24},
397 {"cr.iha", 25},
398 {"cr.lid", 64},
399 {"cr.ivr", 65},
400 {"cr.tpr", 66},
401 {"cr.eoi", 67},
402 {"cr.irr0", 68},
403 {"cr.irr1", 69},
404 {"cr.irr2", 70},
405 {"cr.irr3", 71},
406 {"cr.itv", 72},
407 {"cr.pmv", 73},
408 {"cr.cmcv", 74},
409 {"cr.lrr0", 80},
410 {"cr.lrr1", 81}
413 #define PSR_MFL 4
414 #define PSR_IC 13
415 #define PSR_DFL 18
416 #define PSR_CPL 32
418 static const struct const_desc
420 const char *name;
421 valueT value;
423 const_bits[] =
425 /* PSR constant masks: */
427 /* 0: reserved */
428 {"psr.be", ((valueT) 1) << 1},
429 {"psr.up", ((valueT) 1) << 2},
430 {"psr.ac", ((valueT) 1) << 3},
431 {"psr.mfl", ((valueT) 1) << 4},
432 {"psr.mfh", ((valueT) 1) << 5},
433 /* 6-12: reserved */
434 {"psr.ic", ((valueT) 1) << 13},
435 {"psr.i", ((valueT) 1) << 14},
436 {"psr.pk", ((valueT) 1) << 15},
437 /* 16: reserved */
438 {"psr.dt", ((valueT) 1) << 17},
439 {"psr.dfl", ((valueT) 1) << 18},
440 {"psr.dfh", ((valueT) 1) << 19},
441 {"psr.sp", ((valueT) 1) << 20},
442 {"psr.pp", ((valueT) 1) << 21},
443 {"psr.di", ((valueT) 1) << 22},
444 {"psr.si", ((valueT) 1) << 23},
445 {"psr.db", ((valueT) 1) << 24},
446 {"psr.lp", ((valueT) 1) << 25},
447 {"psr.tb", ((valueT) 1) << 26},
448 {"psr.rt", ((valueT) 1) << 27},
449 /* 28-31: reserved */
450 /* 32-33: cpl (current privilege level) */
451 {"psr.is", ((valueT) 1) << 34},
452 {"psr.mc", ((valueT) 1) << 35},
453 {"psr.it", ((valueT) 1) << 36},
454 {"psr.id", ((valueT) 1) << 37},
455 {"psr.da", ((valueT) 1) << 38},
456 {"psr.dd", ((valueT) 1) << 39},
457 {"psr.ss", ((valueT) 1) << 40},
458 /* 41-42: ri (restart instruction) */
459 {"psr.ed", ((valueT) 1) << 43},
460 {"psr.bn", ((valueT) 1) << 44},
463 /* indirect register-sets/memory: */
465 static const struct
467 const char *name;
468 int regnum;
470 indirect_reg[] =
472 { "CPUID", IND_CPUID },
473 { "cpuid", IND_CPUID },
474 { "dbr", IND_DBR },
475 { "dtr", IND_DTR },
476 { "itr", IND_ITR },
477 { "ibr", IND_IBR },
478 { "msr", IND_MSR },
479 { "pkr", IND_PKR },
480 { "pmc", IND_PMC },
481 { "pmd", IND_PMD },
482 { "rr", IND_RR },
485 /* Pseudo functions used to indicate relocation types (these functions
486 start with an at sign (@). */
487 static struct
489 const char *name;
490 enum pseudo_type
492 PSEUDO_FUNC_NONE,
493 PSEUDO_FUNC_RELOC,
494 PSEUDO_FUNC_CONST,
495 PSEUDO_FUNC_REG,
496 PSEUDO_FUNC_FLOAT
498 type;
499 union
501 unsigned long ival;
502 symbolS *sym;
506 pseudo_func[] =
508 /* reloc pseudo functions (these must come first!): */
509 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
510 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
511 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
512 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
513 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
514 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
515 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
516 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
517 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
518 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
519 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
520 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
521 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
522 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
523 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
524 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
525 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
527 /* mbtype4 constants: */
528 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
529 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
530 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
531 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
532 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
534 /* fclass constants: */
535 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
536 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
537 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
538 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
539 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
540 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
541 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
542 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
543 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
545 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
547 /* hint constants: */
548 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
550 /* unwind-related constants: */
551 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
552 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
553 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
554 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
555 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
556 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
557 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
559 /* unwind-related registers: */
560 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
563 /* 41-bit nop opcodes (one per unit): */
564 static const bfd_vma nop[IA64_NUM_UNITS] =
566 0x0000000000LL, /* NIL => break 0 */
567 0x0008000000LL, /* I-unit nop */
568 0x0008000000LL, /* M-unit nop */
569 0x4000000000LL, /* B-unit nop */
570 0x0008000000LL, /* F-unit nop */
571 0x0008000000LL, /* L-"unit" nop */
572 0x0008000000LL, /* X-unit nop */
575 /* Can't be `const' as it's passed to input routines (which have the
576 habit of setting temporary sentinels. */
577 static char special_section_name[][20] =
579 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
580 {".IA_64.unwind"}, {".IA_64.unwind_info"},
581 {".init_array"}, {".fini_array"}
584 /* The best template for a particular sequence of up to three
585 instructions: */
586 #define N IA64_NUM_TYPES
587 static unsigned char best_template[N][N][N];
588 #undef N
590 /* Resource dependencies currently in effect */
591 static struct rsrc {
592 int depind; /* dependency index */
593 const struct ia64_dependency *dependency; /* actual dependency */
594 unsigned specific:1, /* is this a specific bit/regno? */
595 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
596 int index; /* specific regno/bit within dependency */
597 int note; /* optional qualifying note (0 if none) */
598 #define STATE_NONE 0
599 #define STATE_STOP 1
600 #define STATE_SRLZ 2
601 int insn_srlz; /* current insn serialization state */
602 int data_srlz; /* current data serialization state */
603 int qp_regno; /* qualifying predicate for this usage */
604 char *file; /* what file marked this dependency */
605 unsigned int line; /* what line marked this dependency */
606 struct mem_offset mem_offset; /* optional memory offset hint */
607 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
608 int path; /* corresponding code entry index */
609 } *regdeps = NULL;
610 static int regdepslen = 0;
611 static int regdepstotlen = 0;
612 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
613 static const char *dv_sem[] = { "none", "implied", "impliedf",
614 "data", "instr", "specific", "stop", "other" };
615 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
617 /* Current state of PR mutexation */
618 static struct qpmutex {
619 valueT prmask;
620 int path;
621 } *qp_mutexes = NULL; /* QP mutex bitmasks */
622 static int qp_mutexeslen = 0;
623 static int qp_mutexestotlen = 0;
624 static valueT qp_safe_across_calls = 0;
626 /* Current state of PR implications */
627 static struct qp_imply {
628 unsigned p1:6;
629 unsigned p2:6;
630 unsigned p2_branched:1;
631 int path;
632 } *qp_implies = NULL;
633 static int qp_implieslen = 0;
634 static int qp_impliestotlen = 0;
636 /* Keep track of static GR values so that indirect register usage can
637 sometimes be tracked. */
638 static struct gr {
639 unsigned known:1;
640 int path;
641 valueT value;
642 } gr_values[128] = {
645 #ifdef INT_MAX
646 INT_MAX,
647 #else
648 (((1 << (8 * sizeof(gr_values->path) - 2)) - 1) << 1) + 1,
649 #endif
654 /* Remember the alignment frag. */
655 static fragS *align_frag;
657 /* These are the routines required to output the various types of
658 unwind records. */
660 /* A slot_number is a frag address plus the slot index (0-2). We use the
661 frag address here so that if there is a section switch in the middle of
662 a function, then instructions emitted to a different section are not
663 counted. Since there may be more than one frag for a function, this
664 means we also need to keep track of which frag this address belongs to
665 so we can compute inter-frag distances. This also nicely solves the
666 problem with nops emitted for align directives, which can't easily be
667 counted, but can easily be derived from frag sizes. */
669 typedef struct unw_rec_list {
670 unwind_record r;
671 unsigned long slot_number;
672 fragS *slot_frag;
673 unsigned long next_slot_number;
674 fragS *next_slot_frag;
675 struct unw_rec_list *next;
676 } unw_rec_list;
678 #define SLOT_NUM_NOT_SET (unsigned)-1
680 /* Linked list of saved prologue counts. A very poor
681 implementation of a map from label numbers to prologue counts. */
682 typedef struct label_prologue_count
684 struct label_prologue_count *next;
685 unsigned long label_number;
686 unsigned int prologue_count;
687 } label_prologue_count;
689 static struct
691 /* Maintain a list of unwind entries for the current function. */
692 unw_rec_list *list;
693 unw_rec_list *tail;
695 /* Any unwind entires that should be attached to the current slot
696 that an insn is being constructed for. */
697 unw_rec_list *current_entry;
699 /* These are used to create the unwind table entry for this function. */
700 symbolS *proc_start;
701 symbolS *info; /* pointer to unwind info */
702 symbolS *personality_routine;
703 segT saved_text_seg;
704 subsegT saved_text_subseg;
705 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
707 /* TRUE if processing unwind directives in a prologue region. */
708 unsigned int prologue : 1;
709 unsigned int prologue_mask : 4;
710 unsigned int body : 1;
711 unsigned int insn : 1;
712 unsigned int prologue_count; /* number of .prologues seen so far */
713 /* Prologue counts at previous .label_state directives. */
714 struct label_prologue_count * saved_prologue_counts;
715 } unwind;
717 /* The input value is a negated offset from psp, and specifies an address
718 psp - offset. The encoded value is psp + 16 - (4 * offset). Thus we
719 must add 16 and divide by 4 to get the encoded value. */
721 #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4)
723 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
725 /* Forward declarations: */
726 static void set_section PARAMS ((char *name));
727 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
728 unsigned int, unsigned int));
729 static void dot_align (int);
730 static void dot_radix PARAMS ((int));
731 static void dot_special_section PARAMS ((int));
732 static void dot_proc PARAMS ((int));
733 static void dot_fframe PARAMS ((int));
734 static void dot_vframe PARAMS ((int));
735 static void dot_vframesp PARAMS ((int));
736 static void dot_vframepsp PARAMS ((int));
737 static void dot_save PARAMS ((int));
738 static void dot_restore PARAMS ((int));
739 static void dot_restorereg PARAMS ((int));
740 static void dot_restorereg_p PARAMS ((int));
741 static void dot_handlerdata PARAMS ((int));
742 static void dot_unwentry PARAMS ((int));
743 static void dot_altrp PARAMS ((int));
744 static void dot_savemem PARAMS ((int));
745 static void dot_saveg PARAMS ((int));
746 static void dot_savef PARAMS ((int));
747 static void dot_saveb PARAMS ((int));
748 static void dot_savegf PARAMS ((int));
749 static void dot_spill PARAMS ((int));
750 static void dot_spillreg PARAMS ((int));
751 static void dot_spillmem PARAMS ((int));
752 static void dot_spillreg_p PARAMS ((int));
753 static void dot_spillmem_p PARAMS ((int));
754 static void dot_label_state PARAMS ((int));
755 static void dot_copy_state PARAMS ((int));
756 static void dot_unwabi PARAMS ((int));
757 static void dot_personality PARAMS ((int));
758 static void dot_body PARAMS ((int));
759 static void dot_prologue PARAMS ((int));
760 static void dot_endp PARAMS ((int));
761 static void dot_template PARAMS ((int));
762 static void dot_regstk PARAMS ((int));
763 static void dot_rot PARAMS ((int));
764 static void dot_byteorder PARAMS ((int));
765 static void dot_psr PARAMS ((int));
766 static void dot_alias PARAMS ((int));
767 static void dot_ln PARAMS ((int));
768 static void cross_section PARAMS ((int ref, void (*cons) PARAMS((int)), int ua));
769 static void dot_xdata PARAMS ((int));
770 static void stmt_float_cons PARAMS ((int));
771 static void stmt_cons_ua PARAMS ((int));
772 static void dot_xfloat_cons PARAMS ((int));
773 static void dot_xstringer PARAMS ((int));
774 static void dot_xdata_ua PARAMS ((int));
775 static void dot_xfloat_cons_ua PARAMS ((int));
776 static void print_prmask PARAMS ((valueT mask));
777 static void dot_pred_rel PARAMS ((int));
778 static void dot_reg_val PARAMS ((int));
779 static void dot_serialize PARAMS ((int));
780 static void dot_dv_mode PARAMS ((int));
781 static void dot_entry PARAMS ((int));
782 static void dot_mem_offset PARAMS ((int));
783 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
784 static symbolS *declare_register PARAMS ((const char *name, int regnum));
785 static void declare_register_set PARAMS ((const char *, int, int));
786 static unsigned int operand_width PARAMS ((enum ia64_opnd));
787 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
788 int index,
789 expressionS *e));
790 static int parse_operand PARAMS ((expressionS *e));
791 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
792 static void build_insn PARAMS ((struct slot *, bfd_vma *));
793 static void emit_one_bundle PARAMS ((void));
794 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
795 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
796 bfd_reloc_code_real_type r_type));
797 static void insn_group_break PARAMS ((int, int, int));
798 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
799 struct rsrc *, int depind, int path));
800 static void add_qp_mutex PARAMS((valueT mask));
801 static void add_qp_imply PARAMS((int p1, int p2));
802 static void clear_qp_branch_flag PARAMS((valueT mask));
803 static void clear_qp_mutex PARAMS((valueT mask));
804 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
805 static int has_suffix_p PARAMS((const char *, const char *));
806 static void clear_register_values PARAMS ((void));
807 static void print_dependency PARAMS ((const char *action, int depind));
808 static void instruction_serialization PARAMS ((void));
809 static void data_serialization PARAMS ((void));
810 static void remove_marked_resource PARAMS ((struct rsrc *));
811 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
812 static int is_taken_branch PARAMS ((struct ia64_opcode *));
813 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
814 static int depends_on PARAMS ((int, struct ia64_opcode *));
815 static int specify_resource PARAMS ((const struct ia64_dependency *,
816 struct ia64_opcode *, int, struct rsrc [], int, int));
817 static int check_dv PARAMS((struct ia64_opcode *idesc));
818 static void check_dependencies PARAMS((struct ia64_opcode *));
819 static void mark_resources PARAMS((struct ia64_opcode *));
820 static void update_dependencies PARAMS((struct ia64_opcode *));
821 static void note_register_values PARAMS((struct ia64_opcode *));
822 static int qp_mutex PARAMS ((int, int, int));
823 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
824 static void output_vbyte_mem PARAMS ((int, char *, char *));
825 static void count_output PARAMS ((int, char *, char *));
826 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
827 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
828 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
829 static void output_P1_format PARAMS ((vbyte_func, int));
830 static void output_P2_format PARAMS ((vbyte_func, int, int));
831 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
832 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
833 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
834 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
835 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
836 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
837 static void output_P9_format PARAMS ((vbyte_func, int, int));
838 static void output_P10_format PARAMS ((vbyte_func, int, int));
839 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
840 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
841 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
842 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
843 static char format_ab_reg PARAMS ((int, int));
844 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
845 unsigned long));
846 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
847 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
848 unsigned long));
849 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
850 static unw_rec_list *output_endp PARAMS ((void));
851 static unw_rec_list *output_prologue PARAMS ((void));
852 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
853 static unw_rec_list *output_body PARAMS ((void));
854 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
855 static unw_rec_list *output_mem_stack_v PARAMS ((void));
856 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
857 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
858 static unw_rec_list *output_rp_when PARAMS ((void));
859 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
860 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
861 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
862 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
863 static unw_rec_list *output_pfs_when PARAMS ((void));
864 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
865 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
866 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
867 static unw_rec_list *output_preds_when PARAMS ((void));
868 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
869 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
870 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
871 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
872 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
873 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
874 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
875 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
876 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
877 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
878 static unw_rec_list *output_unat_when PARAMS ((void));
879 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
880 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
881 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
882 static unw_rec_list *output_lc_when PARAMS ((void));
883 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
884 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
885 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
886 static unw_rec_list *output_fpsr_when PARAMS ((void));
887 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
888 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
889 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
890 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
891 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
892 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
893 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
894 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
895 static unw_rec_list *output_bsp_when PARAMS ((void));
896 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
897 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
898 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
899 static unw_rec_list *output_bspstore_when PARAMS ((void));
900 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
901 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
902 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
903 static unw_rec_list *output_rnat_when PARAMS ((void));
904 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
905 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
906 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
907 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
908 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
909 static unw_rec_list *output_label_state PARAMS ((unsigned long));
910 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
911 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
912 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
913 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
914 unsigned int));
915 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
916 unsigned int));
917 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
918 unsigned int));
919 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
920 unsigned int, unsigned int));
921 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
922 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
923 static int calc_record_size PARAMS ((unw_rec_list *));
924 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
925 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
926 unsigned long, fragS *,
927 int));
928 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
929 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
930 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
931 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
932 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
933 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
934 static void free_saved_prologue_counts PARAMS ((void));
936 /* Determine if application register REGNUM resides only in the integer
937 unit (as opposed to the memory unit). */
938 static int
939 ar_is_only_in_integer_unit (int reg)
941 reg -= REG_AR;
942 return reg >= 64 && reg <= 111;
945 /* Determine if application register REGNUM resides only in the memory
946 unit (as opposed to the integer unit). */
947 static int
948 ar_is_only_in_memory_unit (int reg)
950 reg -= REG_AR;
951 return reg >= 0 && reg <= 47;
954 /* Switch to section NAME and create section if necessary. It's
955 rather ugly that we have to manipulate input_line_pointer but I
956 don't see any other way to accomplish the same thing without
957 changing obj-elf.c (which may be the Right Thing, in the end). */
958 static void
959 set_section (name)
960 char *name;
962 char *saved_input_line_pointer;
964 saved_input_line_pointer = input_line_pointer;
965 input_line_pointer = name;
966 obj_elf_section (0);
967 input_line_pointer = saved_input_line_pointer;
970 /* Map 's' to SHF_IA_64_SHORT. */
973 ia64_elf_section_letter (letter, ptr_msg)
974 int letter;
975 char **ptr_msg;
977 if (letter == 's')
978 return SHF_IA_64_SHORT;
979 else if (letter == 'o')
980 return SHF_LINK_ORDER;
982 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
983 return -1;
986 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
988 flagword
989 ia64_elf_section_flags (flags, attr, type)
990 flagword flags;
991 int attr, type ATTRIBUTE_UNUSED;
993 if (attr & SHF_IA_64_SHORT)
994 flags |= SEC_SMALL_DATA;
995 return flags;
999 ia64_elf_section_type (str, len)
1000 const char *str;
1001 size_t len;
1003 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
1005 if (STREQ (ELF_STRING_ia64_unwind_info))
1006 return SHT_PROGBITS;
1008 if (STREQ (ELF_STRING_ia64_unwind_info_once))
1009 return SHT_PROGBITS;
1011 if (STREQ (ELF_STRING_ia64_unwind))
1012 return SHT_IA_64_UNWIND;
1014 if (STREQ (ELF_STRING_ia64_unwind_once))
1015 return SHT_IA_64_UNWIND;
1017 if (STREQ ("unwind"))
1018 return SHT_IA_64_UNWIND;
1020 return -1;
1021 #undef STREQ
1024 static unsigned int
1025 set_regstack (ins, locs, outs, rots)
1026 unsigned int ins, locs, outs, rots;
1028 /* Size of frame. */
1029 unsigned int sof;
1031 sof = ins + locs + outs;
1032 if (sof > 96)
1034 as_bad ("Size of frame exceeds maximum of 96 registers");
1035 return 0;
1037 if (rots > sof)
1039 as_warn ("Size of rotating registers exceeds frame size");
1040 return 0;
1042 md.in.base = REG_GR + 32;
1043 md.loc.base = md.in.base + ins;
1044 md.out.base = md.loc.base + locs;
1046 md.in.num_regs = ins;
1047 md.loc.num_regs = locs;
1048 md.out.num_regs = outs;
1049 md.rot.num_regs = rots;
1050 return sof;
1053 void
1054 ia64_flush_insns ()
1056 struct label_fix *lfix;
1057 segT saved_seg;
1058 subsegT saved_subseg;
1059 unw_rec_list *ptr;
1061 if (!md.last_text_seg)
1062 return;
1064 saved_seg = now_seg;
1065 saved_subseg = now_subseg;
1067 subseg_set (md.last_text_seg, 0);
1069 while (md.num_slots_in_use > 0)
1070 emit_one_bundle (); /* force out queued instructions */
1072 /* In case there are labels following the last instruction, resolve
1073 those now: */
1074 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1076 S_SET_VALUE (lfix->sym, frag_now_fix ());
1077 symbol_set_frag (lfix->sym, frag_now);
1079 CURR_SLOT.label_fixups = 0;
1080 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1082 S_SET_VALUE (lfix->sym, frag_now_fix ());
1083 symbol_set_frag (lfix->sym, frag_now);
1085 CURR_SLOT.tag_fixups = 0;
1087 /* In case there are unwind directives following the last instruction,
1088 resolve those now. We only handle prologue, body, and endp directives
1089 here. Give an error for others. */
1090 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1092 switch (ptr->r.type)
1094 case prologue:
1095 case prologue_gr:
1096 case body:
1097 case endp:
1098 ptr->slot_number = (unsigned long) frag_more (0);
1099 ptr->slot_frag = frag_now;
1100 break;
1102 /* Allow any record which doesn't have a "t" field (i.e.,
1103 doesn't relate to a particular instruction). */
1104 case unwabi:
1105 case br_gr:
1106 case copy_state:
1107 case fr_mem:
1108 case frgr_mem:
1109 case gr_gr:
1110 case gr_mem:
1111 case label_state:
1112 case rp_br:
1113 case spill_base:
1114 case spill_mask:
1115 /* nothing */
1116 break;
1118 default:
1119 as_bad (_("Unwind directive not followed by an instruction."));
1120 break;
1123 unwind.current_entry = NULL;
1125 subseg_set (saved_seg, saved_subseg);
1127 if (md.qp.X_op == O_register)
1128 as_bad ("qualifying predicate not followed by instruction");
1131 static void
1132 ia64_do_align (int nbytes)
1134 char *saved_input_line_pointer = input_line_pointer;
1136 input_line_pointer = "";
1137 s_align_bytes (nbytes);
1138 input_line_pointer = saved_input_line_pointer;
1141 void
1142 ia64_cons_align (nbytes)
1143 int nbytes;
1145 if (md.auto_align)
1147 char *saved_input_line_pointer = input_line_pointer;
1148 input_line_pointer = "";
1149 s_align_bytes (nbytes);
1150 input_line_pointer = saved_input_line_pointer;
1154 /* Output COUNT bytes to a memory location. */
1155 static char *vbyte_mem_ptr = NULL;
1157 void
1158 output_vbyte_mem (count, ptr, comment)
1159 int count;
1160 char *ptr;
1161 char *comment ATTRIBUTE_UNUSED;
1163 int x;
1164 if (vbyte_mem_ptr == NULL)
1165 abort ();
1167 if (count == 0)
1168 return;
1169 for (x = 0; x < count; x++)
1170 *(vbyte_mem_ptr++) = ptr[x];
1173 /* Count the number of bytes required for records. */
1174 static int vbyte_count = 0;
1175 void
1176 count_output (count, ptr, comment)
1177 int count;
1178 char *ptr ATTRIBUTE_UNUSED;
1179 char *comment ATTRIBUTE_UNUSED;
1181 vbyte_count += count;
1184 static void
1185 output_R1_format (f, rtype, rlen)
1186 vbyte_func f;
1187 unw_record_type rtype;
1188 int rlen;
1190 int r = 0;
1191 char byte;
1192 if (rlen > 0x1f)
1194 output_R3_format (f, rtype, rlen);
1195 return;
1198 if (rtype == body)
1199 r = 1;
1200 else if (rtype != prologue)
1201 as_bad ("record type is not valid");
1203 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1204 (*f) (1, &byte, NULL);
1207 static void
1208 output_R2_format (f, mask, grsave, rlen)
1209 vbyte_func f;
1210 int mask, grsave;
1211 unsigned long rlen;
1213 char bytes[20];
1214 int count = 2;
1215 mask = (mask & 0x0f);
1216 grsave = (grsave & 0x7f);
1218 bytes[0] = (UNW_R2 | (mask >> 1));
1219 bytes[1] = (((mask & 0x01) << 7) | grsave);
1220 count += output_leb128 (bytes + 2, rlen, 0);
1221 (*f) (count, bytes, NULL);
1224 static void
1225 output_R3_format (f, rtype, rlen)
1226 vbyte_func f;
1227 unw_record_type rtype;
1228 unsigned long rlen;
1230 int r = 0, count;
1231 char bytes[20];
1232 if (rlen <= 0x1f)
1234 output_R1_format (f, rtype, rlen);
1235 return;
1238 if (rtype == body)
1239 r = 1;
1240 else if (rtype != prologue)
1241 as_bad ("record type is not valid");
1242 bytes[0] = (UNW_R3 | r);
1243 count = output_leb128 (bytes + 1, rlen, 0);
1244 (*f) (count + 1, bytes, NULL);
1247 static void
1248 output_P1_format (f, brmask)
1249 vbyte_func f;
1250 int brmask;
1252 char byte;
1253 byte = UNW_P1 | (brmask & 0x1f);
1254 (*f) (1, &byte, NULL);
1257 static void
1258 output_P2_format (f, brmask, gr)
1259 vbyte_func f;
1260 int brmask;
1261 int gr;
1263 char bytes[2];
1264 brmask = (brmask & 0x1f);
1265 bytes[0] = UNW_P2 | (brmask >> 1);
1266 bytes[1] = (((brmask & 1) << 7) | gr);
1267 (*f) (2, bytes, NULL);
1270 static void
1271 output_P3_format (f, rtype, reg)
1272 vbyte_func f;
1273 unw_record_type rtype;
1274 int reg;
1276 char bytes[2];
1277 int r = 0;
1278 reg = (reg & 0x7f);
1279 switch (rtype)
1281 case psp_gr:
1282 r = 0;
1283 break;
1284 case rp_gr:
1285 r = 1;
1286 break;
1287 case pfs_gr:
1288 r = 2;
1289 break;
1290 case preds_gr:
1291 r = 3;
1292 break;
1293 case unat_gr:
1294 r = 4;
1295 break;
1296 case lc_gr:
1297 r = 5;
1298 break;
1299 case rp_br:
1300 r = 6;
1301 break;
1302 case rnat_gr:
1303 r = 7;
1304 break;
1305 case bsp_gr:
1306 r = 8;
1307 break;
1308 case bspstore_gr:
1309 r = 9;
1310 break;
1311 case fpsr_gr:
1312 r = 10;
1313 break;
1314 case priunat_gr:
1315 r = 11;
1316 break;
1317 default:
1318 as_bad ("Invalid record type for P3 format.");
1320 bytes[0] = (UNW_P3 | (r >> 1));
1321 bytes[1] = (((r & 1) << 7) | reg);
1322 (*f) (2, bytes, NULL);
1325 static void
1326 output_P4_format (f, imask, imask_size)
1327 vbyte_func f;
1328 unsigned char *imask;
1329 unsigned long imask_size;
1331 imask[0] = UNW_P4;
1332 (*f) (imask_size, (char *) imask, NULL);
1335 static void
1336 output_P5_format (f, grmask, frmask)
1337 vbyte_func f;
1338 int grmask;
1339 unsigned long frmask;
1341 char bytes[4];
1342 grmask = (grmask & 0x0f);
1344 bytes[0] = UNW_P5;
1345 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1346 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1347 bytes[3] = (frmask & 0x000000ff);
1348 (*f) (4, bytes, NULL);
1351 static void
1352 output_P6_format (f, rtype, rmask)
1353 vbyte_func f;
1354 unw_record_type rtype;
1355 int rmask;
1357 char byte;
1358 int r = 0;
1360 if (rtype == gr_mem)
1361 r = 1;
1362 else if (rtype != fr_mem)
1363 as_bad ("Invalid record type for format P6");
1364 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1365 (*f) (1, &byte, NULL);
1368 static void
1369 output_P7_format (f, rtype, w1, w2)
1370 vbyte_func f;
1371 unw_record_type rtype;
1372 unsigned long w1;
1373 unsigned long w2;
1375 char bytes[20];
1376 int count = 1;
1377 int r = 0;
1378 count += output_leb128 (bytes + 1, w1, 0);
1379 switch (rtype)
1381 case mem_stack_f:
1382 r = 0;
1383 count += output_leb128 (bytes + count, w2 >> 4, 0);
1384 break;
1385 case mem_stack_v:
1386 r = 1;
1387 break;
1388 case spill_base:
1389 r = 2;
1390 break;
1391 case psp_sprel:
1392 r = 3;
1393 break;
1394 case rp_when:
1395 r = 4;
1396 break;
1397 case rp_psprel:
1398 r = 5;
1399 break;
1400 case pfs_when:
1401 r = 6;
1402 break;
1403 case pfs_psprel:
1404 r = 7;
1405 break;
1406 case preds_when:
1407 r = 8;
1408 break;
1409 case preds_psprel:
1410 r = 9;
1411 break;
1412 case lc_when:
1413 r = 10;
1414 break;
1415 case lc_psprel:
1416 r = 11;
1417 break;
1418 case unat_when:
1419 r = 12;
1420 break;
1421 case unat_psprel:
1422 r = 13;
1423 break;
1424 case fpsr_when:
1425 r = 14;
1426 break;
1427 case fpsr_psprel:
1428 r = 15;
1429 break;
1430 default:
1431 break;
1433 bytes[0] = (UNW_P7 | r);
1434 (*f) (count, bytes, NULL);
1437 static void
1438 output_P8_format (f, rtype, t)
1439 vbyte_func f;
1440 unw_record_type rtype;
1441 unsigned long t;
1443 char bytes[20];
1444 int r = 0;
1445 int count = 2;
1446 bytes[0] = UNW_P8;
1447 switch (rtype)
1449 case rp_sprel:
1450 r = 1;
1451 break;
1452 case pfs_sprel:
1453 r = 2;
1454 break;
1455 case preds_sprel:
1456 r = 3;
1457 break;
1458 case lc_sprel:
1459 r = 4;
1460 break;
1461 case unat_sprel:
1462 r = 5;
1463 break;
1464 case fpsr_sprel:
1465 r = 6;
1466 break;
1467 case bsp_when:
1468 r = 7;
1469 break;
1470 case bsp_psprel:
1471 r = 8;
1472 break;
1473 case bsp_sprel:
1474 r = 9;
1475 break;
1476 case bspstore_when:
1477 r = 10;
1478 break;
1479 case bspstore_psprel:
1480 r = 11;
1481 break;
1482 case bspstore_sprel:
1483 r = 12;
1484 break;
1485 case rnat_when:
1486 r = 13;
1487 break;
1488 case rnat_psprel:
1489 r = 14;
1490 break;
1491 case rnat_sprel:
1492 r = 15;
1493 break;
1494 case priunat_when_gr:
1495 r = 16;
1496 break;
1497 case priunat_psprel:
1498 r = 17;
1499 break;
1500 case priunat_sprel:
1501 r = 18;
1502 break;
1503 case priunat_when_mem:
1504 r = 19;
1505 break;
1506 default:
1507 break;
1509 bytes[1] = r;
1510 count += output_leb128 (bytes + 2, t, 0);
1511 (*f) (count, bytes, NULL);
1514 static void
1515 output_P9_format (f, grmask, gr)
1516 vbyte_func f;
1517 int grmask;
1518 int gr;
1520 char bytes[3];
1521 bytes[0] = UNW_P9;
1522 bytes[1] = (grmask & 0x0f);
1523 bytes[2] = (gr & 0x7f);
1524 (*f) (3, bytes, NULL);
1527 static void
1528 output_P10_format (f, abi, context)
1529 vbyte_func f;
1530 int abi;
1531 int context;
1533 char bytes[3];
1534 bytes[0] = UNW_P10;
1535 bytes[1] = (abi & 0xff);
1536 bytes[2] = (context & 0xff);
1537 (*f) (3, bytes, NULL);
1540 static void
1541 output_B1_format (f, rtype, label)
1542 vbyte_func f;
1543 unw_record_type rtype;
1544 unsigned long label;
1546 char byte;
1547 int r = 0;
1548 if (label > 0x1f)
1550 output_B4_format (f, rtype, label);
1551 return;
1553 if (rtype == copy_state)
1554 r = 1;
1555 else if (rtype != label_state)
1556 as_bad ("Invalid record type for format B1");
1558 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1559 (*f) (1, &byte, NULL);
1562 static void
1563 output_B2_format (f, ecount, t)
1564 vbyte_func f;
1565 unsigned long ecount;
1566 unsigned long t;
1568 char bytes[20];
1569 int count = 1;
1570 if (ecount > 0x1f)
1572 output_B3_format (f, ecount, t);
1573 return;
1575 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1576 count += output_leb128 (bytes + 1, t, 0);
1577 (*f) (count, bytes, NULL);
1580 static void
1581 output_B3_format (f, ecount, t)
1582 vbyte_func f;
1583 unsigned long ecount;
1584 unsigned long t;
1586 char bytes[20];
1587 int count = 1;
1588 if (ecount <= 0x1f)
1590 output_B2_format (f, ecount, t);
1591 return;
1593 bytes[0] = UNW_B3;
1594 count += output_leb128 (bytes + 1, t, 0);
1595 count += output_leb128 (bytes + count, ecount, 0);
1596 (*f) (count, bytes, NULL);
1599 static void
1600 output_B4_format (f, rtype, label)
1601 vbyte_func f;
1602 unw_record_type rtype;
1603 unsigned long label;
1605 char bytes[20];
1606 int r = 0;
1607 int count = 1;
1608 if (label <= 0x1f)
1610 output_B1_format (f, rtype, label);
1611 return;
1614 if (rtype == copy_state)
1615 r = 1;
1616 else if (rtype != label_state)
1617 as_bad ("Invalid record type for format B1");
1619 bytes[0] = (UNW_B4 | (r << 3));
1620 count += output_leb128 (bytes + 1, label, 0);
1621 (*f) (count, bytes, NULL);
1624 static char
1625 format_ab_reg (ab, reg)
1626 int ab;
1627 int reg;
1629 int ret;
1630 ab = (ab & 3);
1631 reg = (reg & 0x1f);
1632 ret = (ab << 5) | reg;
1633 return ret;
1636 static void
1637 output_X1_format (f, rtype, ab, reg, t, w1)
1638 vbyte_func f;
1639 unw_record_type rtype;
1640 int ab, reg;
1641 unsigned long t;
1642 unsigned long w1;
1644 char bytes[20];
1645 int r = 0;
1646 int count = 2;
1647 bytes[0] = UNW_X1;
1649 if (rtype == spill_sprel)
1650 r = 1;
1651 else if (rtype != spill_psprel)
1652 as_bad ("Invalid record type for format X1");
1653 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1654 count += output_leb128 (bytes + 2, t, 0);
1655 count += output_leb128 (bytes + count, w1, 0);
1656 (*f) (count, bytes, NULL);
1659 static void
1660 output_X2_format (f, ab, reg, x, y, treg, t)
1661 vbyte_func f;
1662 int ab, reg;
1663 int x, y, treg;
1664 unsigned long t;
1666 char bytes[20];
1667 int count = 3;
1668 bytes[0] = UNW_X2;
1669 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1670 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1671 count += output_leb128 (bytes + 3, t, 0);
1672 (*f) (count, bytes, NULL);
1675 static void
1676 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1677 vbyte_func f;
1678 unw_record_type rtype;
1679 int qp;
1680 int ab, reg;
1681 unsigned long t;
1682 unsigned long w1;
1684 char bytes[20];
1685 int r = 0;
1686 int count = 3;
1687 bytes[0] = UNW_X3;
1689 if (rtype == spill_sprel_p)
1690 r = 1;
1691 else if (rtype != spill_psprel_p)
1692 as_bad ("Invalid record type for format X3");
1693 bytes[1] = ((r << 7) | (qp & 0x3f));
1694 bytes[2] = format_ab_reg (ab, reg);
1695 count += output_leb128 (bytes + 3, t, 0);
1696 count += output_leb128 (bytes + count, w1, 0);
1697 (*f) (count, bytes, NULL);
1700 static void
1701 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1702 vbyte_func f;
1703 int qp;
1704 int ab, reg;
1705 int x, y, treg;
1706 unsigned long t;
1708 char bytes[20];
1709 int count = 4;
1710 bytes[0] = UNW_X4;
1711 bytes[1] = (qp & 0x3f);
1712 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1713 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1714 count += output_leb128 (bytes + 4, t, 0);
1715 (*f) (count, bytes, NULL);
1718 /* This function allocates a record list structure, and initializes fields. */
1720 static unw_rec_list *
1721 alloc_record (unw_record_type t)
1723 unw_rec_list *ptr;
1724 ptr = xmalloc (sizeof (*ptr));
1725 ptr->next = NULL;
1726 ptr->slot_number = SLOT_NUM_NOT_SET;
1727 ptr->r.type = t;
1728 ptr->next_slot_number = 0;
1729 ptr->next_slot_frag = 0;
1730 return ptr;
1733 /* Dummy unwind record used for calculating the length of the last prologue or
1734 body region. */
1736 static unw_rec_list *
1737 output_endp ()
1739 unw_rec_list *ptr = alloc_record (endp);
1740 return ptr;
1743 static unw_rec_list *
1744 output_prologue ()
1746 unw_rec_list *ptr = alloc_record (prologue);
1747 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1748 return ptr;
1751 static unw_rec_list *
1752 output_prologue_gr (saved_mask, reg)
1753 unsigned int saved_mask;
1754 unsigned int reg;
1756 unw_rec_list *ptr = alloc_record (prologue_gr);
1757 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1758 ptr->r.record.r.grmask = saved_mask;
1759 ptr->r.record.r.grsave = reg;
1760 return ptr;
1763 static unw_rec_list *
1764 output_body ()
1766 unw_rec_list *ptr = alloc_record (body);
1767 return ptr;
1770 static unw_rec_list *
1771 output_mem_stack_f (size)
1772 unsigned int size;
1774 unw_rec_list *ptr = alloc_record (mem_stack_f);
1775 ptr->r.record.p.size = size;
1776 return ptr;
1779 static unw_rec_list *
1780 output_mem_stack_v ()
1782 unw_rec_list *ptr = alloc_record (mem_stack_v);
1783 return ptr;
1786 static unw_rec_list *
1787 output_psp_gr (gr)
1788 unsigned int gr;
1790 unw_rec_list *ptr = alloc_record (psp_gr);
1791 ptr->r.record.p.gr = gr;
1792 return ptr;
1795 static unw_rec_list *
1796 output_psp_sprel (offset)
1797 unsigned int offset;
1799 unw_rec_list *ptr = alloc_record (psp_sprel);
1800 ptr->r.record.p.spoff = offset / 4;
1801 return ptr;
1804 static unw_rec_list *
1805 output_rp_when ()
1807 unw_rec_list *ptr = alloc_record (rp_when);
1808 return ptr;
1811 static unw_rec_list *
1812 output_rp_gr (gr)
1813 unsigned int gr;
1815 unw_rec_list *ptr = alloc_record (rp_gr);
1816 ptr->r.record.p.gr = gr;
1817 return ptr;
1820 static unw_rec_list *
1821 output_rp_br (br)
1822 unsigned int br;
1824 unw_rec_list *ptr = alloc_record (rp_br);
1825 ptr->r.record.p.br = br;
1826 return ptr;
1829 static unw_rec_list *
1830 output_rp_psprel (offset)
1831 unsigned int offset;
1833 unw_rec_list *ptr = alloc_record (rp_psprel);
1834 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1835 return ptr;
1838 static unw_rec_list *
1839 output_rp_sprel (offset)
1840 unsigned int offset;
1842 unw_rec_list *ptr = alloc_record (rp_sprel);
1843 ptr->r.record.p.spoff = offset / 4;
1844 return ptr;
1847 static unw_rec_list *
1848 output_pfs_when ()
1850 unw_rec_list *ptr = alloc_record (pfs_when);
1851 return ptr;
1854 static unw_rec_list *
1855 output_pfs_gr (gr)
1856 unsigned int gr;
1858 unw_rec_list *ptr = alloc_record (pfs_gr);
1859 ptr->r.record.p.gr = gr;
1860 return ptr;
1863 static unw_rec_list *
1864 output_pfs_psprel (offset)
1865 unsigned int offset;
1867 unw_rec_list *ptr = alloc_record (pfs_psprel);
1868 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1869 return ptr;
1872 static unw_rec_list *
1873 output_pfs_sprel (offset)
1874 unsigned int offset;
1876 unw_rec_list *ptr = alloc_record (pfs_sprel);
1877 ptr->r.record.p.spoff = offset / 4;
1878 return ptr;
1881 static unw_rec_list *
1882 output_preds_when ()
1884 unw_rec_list *ptr = alloc_record (preds_when);
1885 return ptr;
1888 static unw_rec_list *
1889 output_preds_gr (gr)
1890 unsigned int gr;
1892 unw_rec_list *ptr = alloc_record (preds_gr);
1893 ptr->r.record.p.gr = gr;
1894 return ptr;
1897 static unw_rec_list *
1898 output_preds_psprel (offset)
1899 unsigned int offset;
1901 unw_rec_list *ptr = alloc_record (preds_psprel);
1902 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1903 return ptr;
1906 static unw_rec_list *
1907 output_preds_sprel (offset)
1908 unsigned int offset;
1910 unw_rec_list *ptr = alloc_record (preds_sprel);
1911 ptr->r.record.p.spoff = offset / 4;
1912 return ptr;
1915 static unw_rec_list *
1916 output_fr_mem (mask)
1917 unsigned int mask;
1919 unw_rec_list *ptr = alloc_record (fr_mem);
1920 ptr->r.record.p.rmask = mask;
1921 return ptr;
1924 static unw_rec_list *
1925 output_frgr_mem (gr_mask, fr_mask)
1926 unsigned int gr_mask;
1927 unsigned int fr_mask;
1929 unw_rec_list *ptr = alloc_record (frgr_mem);
1930 ptr->r.record.p.grmask = gr_mask;
1931 ptr->r.record.p.frmask = fr_mask;
1932 return ptr;
1935 static unw_rec_list *
1936 output_gr_gr (mask, reg)
1937 unsigned int mask;
1938 unsigned int reg;
1940 unw_rec_list *ptr = alloc_record (gr_gr);
1941 ptr->r.record.p.grmask = mask;
1942 ptr->r.record.p.gr = reg;
1943 return ptr;
1946 static unw_rec_list *
1947 output_gr_mem (mask)
1948 unsigned int mask;
1950 unw_rec_list *ptr = alloc_record (gr_mem);
1951 ptr->r.record.p.rmask = mask;
1952 return ptr;
1955 static unw_rec_list *
1956 output_br_mem (unsigned int mask)
1958 unw_rec_list *ptr = alloc_record (br_mem);
1959 ptr->r.record.p.brmask = mask;
1960 return ptr;
1963 static unw_rec_list *
1964 output_br_gr (save_mask, reg)
1965 unsigned int save_mask;
1966 unsigned int reg;
1968 unw_rec_list *ptr = alloc_record (br_gr);
1969 ptr->r.record.p.brmask = save_mask;
1970 ptr->r.record.p.gr = reg;
1971 return ptr;
1974 static unw_rec_list *
1975 output_spill_base (offset)
1976 unsigned int offset;
1978 unw_rec_list *ptr = alloc_record (spill_base);
1979 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1980 return ptr;
1983 static unw_rec_list *
1984 output_unat_when ()
1986 unw_rec_list *ptr = alloc_record (unat_when);
1987 return ptr;
1990 static unw_rec_list *
1991 output_unat_gr (gr)
1992 unsigned int gr;
1994 unw_rec_list *ptr = alloc_record (unat_gr);
1995 ptr->r.record.p.gr = gr;
1996 return ptr;
1999 static unw_rec_list *
2000 output_unat_psprel (offset)
2001 unsigned int offset;
2003 unw_rec_list *ptr = alloc_record (unat_psprel);
2004 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2005 return ptr;
2008 static unw_rec_list *
2009 output_unat_sprel (offset)
2010 unsigned int offset;
2012 unw_rec_list *ptr = alloc_record (unat_sprel);
2013 ptr->r.record.p.spoff = offset / 4;
2014 return ptr;
2017 static unw_rec_list *
2018 output_lc_when ()
2020 unw_rec_list *ptr = alloc_record (lc_when);
2021 return ptr;
2024 static unw_rec_list *
2025 output_lc_gr (gr)
2026 unsigned int gr;
2028 unw_rec_list *ptr = alloc_record (lc_gr);
2029 ptr->r.record.p.gr = gr;
2030 return ptr;
2033 static unw_rec_list *
2034 output_lc_psprel (offset)
2035 unsigned int offset;
2037 unw_rec_list *ptr = alloc_record (lc_psprel);
2038 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2039 return ptr;
2042 static unw_rec_list *
2043 output_lc_sprel (offset)
2044 unsigned int offset;
2046 unw_rec_list *ptr = alloc_record (lc_sprel);
2047 ptr->r.record.p.spoff = offset / 4;
2048 return ptr;
2051 static unw_rec_list *
2052 output_fpsr_when ()
2054 unw_rec_list *ptr = alloc_record (fpsr_when);
2055 return ptr;
2058 static unw_rec_list *
2059 output_fpsr_gr (gr)
2060 unsigned int gr;
2062 unw_rec_list *ptr = alloc_record (fpsr_gr);
2063 ptr->r.record.p.gr = gr;
2064 return ptr;
2067 static unw_rec_list *
2068 output_fpsr_psprel (offset)
2069 unsigned int offset;
2071 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2072 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2073 return ptr;
2076 static unw_rec_list *
2077 output_fpsr_sprel (offset)
2078 unsigned int offset;
2080 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2081 ptr->r.record.p.spoff = offset / 4;
2082 return ptr;
2085 static unw_rec_list *
2086 output_priunat_when_gr ()
2088 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2089 return ptr;
2092 static unw_rec_list *
2093 output_priunat_when_mem ()
2095 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2096 return ptr;
2099 static unw_rec_list *
2100 output_priunat_gr (gr)
2101 unsigned int gr;
2103 unw_rec_list *ptr = alloc_record (priunat_gr);
2104 ptr->r.record.p.gr = gr;
2105 return ptr;
2108 static unw_rec_list *
2109 output_priunat_psprel (offset)
2110 unsigned int offset;
2112 unw_rec_list *ptr = alloc_record (priunat_psprel);
2113 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2114 return ptr;
2117 static unw_rec_list *
2118 output_priunat_sprel (offset)
2119 unsigned int offset;
2121 unw_rec_list *ptr = alloc_record (priunat_sprel);
2122 ptr->r.record.p.spoff = offset / 4;
2123 return ptr;
2126 static unw_rec_list *
2127 output_bsp_when ()
2129 unw_rec_list *ptr = alloc_record (bsp_when);
2130 return ptr;
2133 static unw_rec_list *
2134 output_bsp_gr (gr)
2135 unsigned int gr;
2137 unw_rec_list *ptr = alloc_record (bsp_gr);
2138 ptr->r.record.p.gr = gr;
2139 return ptr;
2142 static unw_rec_list *
2143 output_bsp_psprel (offset)
2144 unsigned int offset;
2146 unw_rec_list *ptr = alloc_record (bsp_psprel);
2147 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2148 return ptr;
2151 static unw_rec_list *
2152 output_bsp_sprel (offset)
2153 unsigned int offset;
2155 unw_rec_list *ptr = alloc_record (bsp_sprel);
2156 ptr->r.record.p.spoff = offset / 4;
2157 return ptr;
2160 static unw_rec_list *
2161 output_bspstore_when ()
2163 unw_rec_list *ptr = alloc_record (bspstore_when);
2164 return ptr;
2167 static unw_rec_list *
2168 output_bspstore_gr (gr)
2169 unsigned int gr;
2171 unw_rec_list *ptr = alloc_record (bspstore_gr);
2172 ptr->r.record.p.gr = gr;
2173 return ptr;
2176 static unw_rec_list *
2177 output_bspstore_psprel (offset)
2178 unsigned int offset;
2180 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2181 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2182 return ptr;
2185 static unw_rec_list *
2186 output_bspstore_sprel (offset)
2187 unsigned int offset;
2189 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2190 ptr->r.record.p.spoff = offset / 4;
2191 return ptr;
2194 static unw_rec_list *
2195 output_rnat_when ()
2197 unw_rec_list *ptr = alloc_record (rnat_when);
2198 return ptr;
2201 static unw_rec_list *
2202 output_rnat_gr (gr)
2203 unsigned int gr;
2205 unw_rec_list *ptr = alloc_record (rnat_gr);
2206 ptr->r.record.p.gr = gr;
2207 return ptr;
2210 static unw_rec_list *
2211 output_rnat_psprel (offset)
2212 unsigned int offset;
2214 unw_rec_list *ptr = alloc_record (rnat_psprel);
2215 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2216 return ptr;
2219 static unw_rec_list *
2220 output_rnat_sprel (offset)
2221 unsigned int offset;
2223 unw_rec_list *ptr = alloc_record (rnat_sprel);
2224 ptr->r.record.p.spoff = offset / 4;
2225 return ptr;
2228 static unw_rec_list *
2229 output_unwabi (abi, context)
2230 unsigned long abi;
2231 unsigned long context;
2233 unw_rec_list *ptr = alloc_record (unwabi);
2234 ptr->r.record.p.abi = abi;
2235 ptr->r.record.p.context = context;
2236 return ptr;
2239 static unw_rec_list *
2240 output_epilogue (unsigned long ecount)
2242 unw_rec_list *ptr = alloc_record (epilogue);
2243 ptr->r.record.b.ecount = ecount;
2244 return ptr;
2247 static unw_rec_list *
2248 output_label_state (unsigned long label)
2250 unw_rec_list *ptr = alloc_record (label_state);
2251 ptr->r.record.b.label = label;
2252 return ptr;
2255 static unw_rec_list *
2256 output_copy_state (unsigned long label)
2258 unw_rec_list *ptr = alloc_record (copy_state);
2259 ptr->r.record.b.label = label;
2260 return ptr;
2263 static unw_rec_list *
2264 output_spill_psprel (ab, reg, offset)
2265 unsigned int ab;
2266 unsigned int reg;
2267 unsigned int offset;
2269 unw_rec_list *ptr = alloc_record (spill_psprel);
2270 ptr->r.record.x.ab = ab;
2271 ptr->r.record.x.reg = reg;
2272 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2273 return ptr;
2276 static unw_rec_list *
2277 output_spill_sprel (ab, reg, offset)
2278 unsigned int ab;
2279 unsigned int reg;
2280 unsigned int offset;
2282 unw_rec_list *ptr = alloc_record (spill_sprel);
2283 ptr->r.record.x.ab = ab;
2284 ptr->r.record.x.reg = reg;
2285 ptr->r.record.x.spoff = offset / 4;
2286 return ptr;
2289 static unw_rec_list *
2290 output_spill_psprel_p (ab, reg, offset, predicate)
2291 unsigned int ab;
2292 unsigned int reg;
2293 unsigned int offset;
2294 unsigned int predicate;
2296 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2297 ptr->r.record.x.ab = ab;
2298 ptr->r.record.x.reg = reg;
2299 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2300 ptr->r.record.x.qp = predicate;
2301 return ptr;
2304 static unw_rec_list *
2305 output_spill_sprel_p (ab, reg, offset, predicate)
2306 unsigned int ab;
2307 unsigned int reg;
2308 unsigned int offset;
2309 unsigned int predicate;
2311 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2312 ptr->r.record.x.ab = ab;
2313 ptr->r.record.x.reg = reg;
2314 ptr->r.record.x.spoff = offset / 4;
2315 ptr->r.record.x.qp = predicate;
2316 return ptr;
2319 static unw_rec_list *
2320 output_spill_reg (ab, reg, targ_reg, xy)
2321 unsigned int ab;
2322 unsigned int reg;
2323 unsigned int targ_reg;
2324 unsigned int xy;
2326 unw_rec_list *ptr = alloc_record (spill_reg);
2327 ptr->r.record.x.ab = ab;
2328 ptr->r.record.x.reg = reg;
2329 ptr->r.record.x.treg = targ_reg;
2330 ptr->r.record.x.xy = xy;
2331 return ptr;
2334 static unw_rec_list *
2335 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2336 unsigned int ab;
2337 unsigned int reg;
2338 unsigned int targ_reg;
2339 unsigned int xy;
2340 unsigned int predicate;
2342 unw_rec_list *ptr = alloc_record (spill_reg_p);
2343 ptr->r.record.x.ab = ab;
2344 ptr->r.record.x.reg = reg;
2345 ptr->r.record.x.treg = targ_reg;
2346 ptr->r.record.x.xy = xy;
2347 ptr->r.record.x.qp = predicate;
2348 return ptr;
2351 /* Given a unw_rec_list process the correct format with the
2352 specified function. */
2354 static void
2355 process_one_record (ptr, f)
2356 unw_rec_list *ptr;
2357 vbyte_func f;
2359 unsigned long fr_mask, gr_mask;
2361 switch (ptr->r.type)
2363 /* This is a dummy record that takes up no space in the output. */
2364 case endp:
2365 break;
2367 case gr_mem:
2368 case fr_mem:
2369 case br_mem:
2370 case frgr_mem:
2371 /* These are taken care of by prologue/prologue_gr. */
2372 break;
2374 case prologue_gr:
2375 case prologue:
2376 if (ptr->r.type == prologue_gr)
2377 output_R2_format (f, ptr->r.record.r.grmask,
2378 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2379 else
2380 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2382 /* Output descriptor(s) for union of register spills (if any). */
2383 gr_mask = ptr->r.record.r.mask.gr_mem;
2384 fr_mask = ptr->r.record.r.mask.fr_mem;
2385 if (fr_mask)
2387 if ((fr_mask & ~0xfUL) == 0)
2388 output_P6_format (f, fr_mem, fr_mask);
2389 else
2391 output_P5_format (f, gr_mask, fr_mask);
2392 gr_mask = 0;
2395 if (gr_mask)
2396 output_P6_format (f, gr_mem, gr_mask);
2397 if (ptr->r.record.r.mask.br_mem)
2398 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2400 /* output imask descriptor if necessary: */
2401 if (ptr->r.record.r.mask.i)
2402 output_P4_format (f, ptr->r.record.r.mask.i,
2403 ptr->r.record.r.imask_size);
2404 break;
2406 case body:
2407 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2408 break;
2409 case mem_stack_f:
2410 case mem_stack_v:
2411 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2412 ptr->r.record.p.size);
2413 break;
2414 case psp_gr:
2415 case rp_gr:
2416 case pfs_gr:
2417 case preds_gr:
2418 case unat_gr:
2419 case lc_gr:
2420 case fpsr_gr:
2421 case priunat_gr:
2422 case bsp_gr:
2423 case bspstore_gr:
2424 case rnat_gr:
2425 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2426 break;
2427 case rp_br:
2428 output_P3_format (f, rp_br, ptr->r.record.p.br);
2429 break;
2430 case psp_sprel:
2431 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2432 break;
2433 case rp_when:
2434 case pfs_when:
2435 case preds_when:
2436 case unat_when:
2437 case lc_when:
2438 case fpsr_when:
2439 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2440 break;
2441 case rp_psprel:
2442 case pfs_psprel:
2443 case preds_psprel:
2444 case unat_psprel:
2445 case lc_psprel:
2446 case fpsr_psprel:
2447 case spill_base:
2448 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2449 break;
2450 case rp_sprel:
2451 case pfs_sprel:
2452 case preds_sprel:
2453 case unat_sprel:
2454 case lc_sprel:
2455 case fpsr_sprel:
2456 case priunat_sprel:
2457 case bsp_sprel:
2458 case bspstore_sprel:
2459 case rnat_sprel:
2460 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2461 break;
2462 case gr_gr:
2463 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2464 break;
2465 case br_gr:
2466 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2467 break;
2468 case spill_mask:
2469 as_bad ("spill_mask record unimplemented.");
2470 break;
2471 case priunat_when_gr:
2472 case priunat_when_mem:
2473 case bsp_when:
2474 case bspstore_when:
2475 case rnat_when:
2476 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2477 break;
2478 case priunat_psprel:
2479 case bsp_psprel:
2480 case bspstore_psprel:
2481 case rnat_psprel:
2482 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2483 break;
2484 case unwabi:
2485 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2486 break;
2487 case epilogue:
2488 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2489 break;
2490 case label_state:
2491 case copy_state:
2492 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2493 break;
2494 case spill_psprel:
2495 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2496 ptr->r.record.x.reg, ptr->r.record.x.t,
2497 ptr->r.record.x.pspoff);
2498 break;
2499 case spill_sprel:
2500 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2501 ptr->r.record.x.reg, ptr->r.record.x.t,
2502 ptr->r.record.x.spoff);
2503 break;
2504 case spill_reg:
2505 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2506 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2507 ptr->r.record.x.treg, ptr->r.record.x.t);
2508 break;
2509 case spill_psprel_p:
2510 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2511 ptr->r.record.x.ab, ptr->r.record.x.reg,
2512 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2513 break;
2514 case spill_sprel_p:
2515 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2516 ptr->r.record.x.ab, ptr->r.record.x.reg,
2517 ptr->r.record.x.t, ptr->r.record.x.spoff);
2518 break;
2519 case spill_reg_p:
2520 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2521 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2522 ptr->r.record.x.xy, ptr->r.record.x.treg,
2523 ptr->r.record.x.t);
2524 break;
2525 default:
2526 as_bad ("record_type_not_valid");
2527 break;
2531 /* Given a unw_rec_list list, process all the records with
2532 the specified function. */
2533 static void
2534 process_unw_records (list, f)
2535 unw_rec_list *list;
2536 vbyte_func f;
2538 unw_rec_list *ptr;
2539 for (ptr = list; ptr; ptr = ptr->next)
2540 process_one_record (ptr, f);
2543 /* Determine the size of a record list in bytes. */
2544 static int
2545 calc_record_size (list)
2546 unw_rec_list *list;
2548 vbyte_count = 0;
2549 process_unw_records (list, count_output);
2550 return vbyte_count;
2553 /* Update IMASK bitmask to reflect the fact that one or more registers
2554 of type TYPE are saved starting at instruction with index T. If N
2555 bits are set in REGMASK, it is assumed that instructions T through
2556 T+N-1 save these registers.
2558 TYPE values:
2559 0: no save
2560 1: instruction saves next fp reg
2561 2: instruction saves next general reg
2562 3: instruction saves next branch reg */
2563 static void
2564 set_imask (region, regmask, t, type)
2565 unw_rec_list *region;
2566 unsigned long regmask;
2567 unsigned long t;
2568 unsigned int type;
2570 unsigned char *imask;
2571 unsigned long imask_size;
2572 unsigned int i;
2573 int pos;
2575 imask = region->r.record.r.mask.i;
2576 imask_size = region->r.record.r.imask_size;
2577 if (!imask)
2579 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2580 imask = xmalloc (imask_size);
2581 memset (imask, 0, imask_size);
2583 region->r.record.r.imask_size = imask_size;
2584 region->r.record.r.mask.i = imask;
2587 i = (t / 4) + 1;
2588 pos = 2 * (3 - t % 4);
2589 while (regmask)
2591 if (i >= imask_size)
2593 as_bad ("Ignoring attempt to spill beyond end of region");
2594 return;
2597 imask[i] |= (type & 0x3) << pos;
2599 regmask &= (regmask - 1);
2600 pos -= 2;
2601 if (pos < 0)
2603 pos = 0;
2604 ++i;
2609 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2610 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2611 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2612 for frag sizes. */
2614 unsigned long
2615 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2616 unsigned long slot_addr;
2617 fragS *slot_frag;
2618 unsigned long first_addr;
2619 fragS *first_frag;
2620 int before_relax;
2622 unsigned long index = 0;
2624 /* First time we are called, the initial address and frag are invalid. */
2625 if (first_addr == 0)
2626 return 0;
2628 /* If the two addresses are in different frags, then we need to add in
2629 the remaining size of this frag, and then the entire size of intermediate
2630 frags. */
2631 while (slot_frag != first_frag)
2633 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2635 if (! before_relax)
2637 /* We can get the final addresses only during and after
2638 relaxation. */
2639 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2640 index += 3 * ((first_frag->fr_next->fr_address
2641 - first_frag->fr_address
2642 - first_frag->fr_fix) >> 4);
2644 else
2645 /* We don't know what the final addresses will be. We try our
2646 best to estimate. */
2647 switch (first_frag->fr_type)
2649 default:
2650 break;
2652 case rs_space:
2653 as_fatal ("only constant space allocation is supported");
2654 break;
2656 case rs_align:
2657 case rs_align_code:
2658 case rs_align_test:
2659 /* Take alignment into account. Assume the worst case
2660 before relaxation. */
2661 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2662 break;
2664 case rs_org:
2665 if (first_frag->fr_symbol)
2667 as_fatal ("only constant offsets are supported");
2668 break;
2670 case rs_fill:
2671 index += 3 * (first_frag->fr_offset >> 4);
2672 break;
2675 /* Add in the full size of the frag converted to instruction slots. */
2676 index += 3 * (first_frag->fr_fix >> 4);
2677 /* Subtract away the initial part before first_addr. */
2678 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2679 + ((first_addr & 0x3) - (start_addr & 0x3)));
2681 /* Move to the beginning of the next frag. */
2682 first_frag = first_frag->fr_next;
2683 first_addr = (unsigned long) &first_frag->fr_literal;
2686 /* Add in the used part of the last frag. */
2687 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2688 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2689 return index;
2692 /* Optimize unwind record directives. */
2694 static unw_rec_list *
2695 optimize_unw_records (list)
2696 unw_rec_list *list;
2698 if (!list)
2699 return NULL;
2701 /* If the only unwind record is ".prologue" or ".prologue" followed
2702 by ".body", then we can optimize the unwind directives away. */
2703 if (list->r.type == prologue
2704 && (list->next->r.type == endp
2705 || (list->next->r.type == body && list->next->next->r.type == endp)))
2706 return NULL;
2708 return list;
2711 /* Given a complete record list, process any records which have
2712 unresolved fields, (ie length counts for a prologue). After
2713 this has been run, all necessary information should be available
2714 within each record to generate an image. */
2716 static void
2717 fixup_unw_records (list, before_relax)
2718 unw_rec_list *list;
2719 int before_relax;
2721 unw_rec_list *ptr, *region = 0;
2722 unsigned long first_addr = 0, rlen = 0, t;
2723 fragS *first_frag = 0;
2725 for (ptr = list; ptr; ptr = ptr->next)
2727 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2728 as_bad (" Insn slot not set in unwind record.");
2729 t = slot_index (ptr->slot_number, ptr->slot_frag,
2730 first_addr, first_frag, before_relax);
2731 switch (ptr->r.type)
2733 case prologue:
2734 case prologue_gr:
2735 case body:
2737 unw_rec_list *last;
2738 int size;
2739 unsigned long last_addr = 0;
2740 fragS *last_frag = NULL;
2742 first_addr = ptr->slot_number;
2743 first_frag = ptr->slot_frag;
2744 /* Find either the next body/prologue start, or the end of
2745 the function, and determine the size of the region. */
2746 for (last = ptr->next; last != NULL; last = last->next)
2747 if (last->r.type == prologue || last->r.type == prologue_gr
2748 || last->r.type == body || last->r.type == endp)
2750 last_addr = last->slot_number;
2751 last_frag = last->slot_frag;
2752 break;
2754 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2755 before_relax);
2756 rlen = ptr->r.record.r.rlen = size;
2757 if (ptr->r.type == body)
2758 /* End of region. */
2759 region = 0;
2760 else
2761 region = ptr;
2762 break;
2764 case epilogue:
2765 if (t < rlen)
2766 ptr->r.record.b.t = rlen - 1 - t;
2767 else
2768 /* This happens when a memory-stack-less procedure uses a
2769 ".restore sp" directive at the end of a region to pop
2770 the frame state. */
2771 ptr->r.record.b.t = 0;
2772 break;
2774 case mem_stack_f:
2775 case mem_stack_v:
2776 case rp_when:
2777 case pfs_when:
2778 case preds_when:
2779 case unat_when:
2780 case lc_when:
2781 case fpsr_when:
2782 case priunat_when_gr:
2783 case priunat_when_mem:
2784 case bsp_when:
2785 case bspstore_when:
2786 case rnat_when:
2787 ptr->r.record.p.t = t;
2788 break;
2790 case spill_reg:
2791 case spill_sprel:
2792 case spill_psprel:
2793 case spill_reg_p:
2794 case spill_sprel_p:
2795 case spill_psprel_p:
2796 ptr->r.record.x.t = t;
2797 break;
2799 case frgr_mem:
2800 if (!region)
2802 as_bad ("frgr_mem record before region record!");
2803 return;
2805 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2806 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2807 set_imask (region, ptr->r.record.p.frmask, t, 1);
2808 set_imask (region, ptr->r.record.p.grmask, t, 2);
2809 break;
2810 case fr_mem:
2811 if (!region)
2813 as_bad ("fr_mem record before region record!");
2814 return;
2816 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2817 set_imask (region, ptr->r.record.p.rmask, t, 1);
2818 break;
2819 case gr_mem:
2820 if (!region)
2822 as_bad ("gr_mem record before region record!");
2823 return;
2825 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2826 set_imask (region, ptr->r.record.p.rmask, t, 2);
2827 break;
2828 case br_mem:
2829 if (!region)
2831 as_bad ("br_mem record before region record!");
2832 return;
2834 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2835 set_imask (region, ptr->r.record.p.brmask, t, 3);
2836 break;
2838 case gr_gr:
2839 if (!region)
2841 as_bad ("gr_gr record before region record!");
2842 return;
2844 set_imask (region, ptr->r.record.p.grmask, t, 2);
2845 break;
2846 case br_gr:
2847 if (!region)
2849 as_bad ("br_gr record before region record!");
2850 return;
2852 set_imask (region, ptr->r.record.p.brmask, t, 3);
2853 break;
2855 default:
2856 break;
2861 /* Estimate the size of a frag before relaxing. We only have one type of frag
2862 to handle here, which is the unwind info frag. */
2865 ia64_estimate_size_before_relax (fragS *frag,
2866 asection *segtype ATTRIBUTE_UNUSED)
2868 unw_rec_list *list;
2869 int len, size, pad;
2871 /* ??? This code is identical to the first part of ia64_convert_frag. */
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. */
2881 size = len + 8;
2882 /* Add a pointer for the personality offset. */
2883 if (frag->fr_offset)
2884 size += md.pointer_size;
2886 /* fr_var carries the max_chars that we created the fragment with.
2887 We must, of course, have allocated enough memory earlier. */
2888 assert (frag->fr_var >= size);
2890 return frag->fr_fix + size;
2893 /* This function converts a rs_machine_dependent variant frag into a
2894 normal fill frag with the unwind image from the the record list. */
2895 void
2896 ia64_convert_frag (fragS *frag)
2898 unw_rec_list *list;
2899 int len, size, pad;
2900 valueT flag_value;
2902 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2903 list = (unw_rec_list *) frag->fr_opcode;
2904 fixup_unw_records (list, 0);
2906 len = calc_record_size (list);
2907 /* pad to pointer-size boundary. */
2908 pad = len % md.pointer_size;
2909 if (pad != 0)
2910 len += md.pointer_size - pad;
2911 /* Add 8 for the header. */
2912 size = len + 8;
2913 /* Add a pointer for the personality offset. */
2914 if (frag->fr_offset)
2915 size += md.pointer_size;
2917 /* fr_var carries the max_chars that we created the fragment with.
2918 We must, of course, have allocated enough memory earlier. */
2919 assert (frag->fr_var >= size);
2921 /* Initialize the header area. fr_offset is initialized with
2922 unwind.personality_routine. */
2923 if (frag->fr_offset)
2925 if (md.flags & EF_IA_64_ABI64)
2926 flag_value = (bfd_vma) 3 << 32;
2927 else
2928 /* 32-bit unwind info block. */
2929 flag_value = (bfd_vma) 0x1003 << 32;
2931 else
2932 flag_value = 0;
2934 md_number_to_chars (frag->fr_literal,
2935 (((bfd_vma) 1 << 48) /* Version. */
2936 | flag_value /* U & E handler flags. */
2937 | (len / md.pointer_size)), /* Length. */
2940 /* Skip the header. */
2941 vbyte_mem_ptr = frag->fr_literal + 8;
2942 process_unw_records (list, output_vbyte_mem);
2944 /* Fill the padding bytes with zeros. */
2945 if (pad != 0)
2946 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2947 md.pointer_size - pad);
2949 frag->fr_fix += size;
2950 frag->fr_type = rs_fill;
2951 frag->fr_var = 0;
2952 frag->fr_offset = 0;
2955 static int
2956 convert_expr_to_ab_reg (e, ab, regp)
2957 expressionS *e;
2958 unsigned int *ab;
2959 unsigned int *regp;
2961 unsigned int reg;
2963 if (e->X_op != O_register)
2964 return 0;
2966 reg = e->X_add_number;
2967 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2969 *ab = 0;
2970 *regp = reg - REG_GR;
2972 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2973 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2975 *ab = 1;
2976 *regp = reg - REG_FR;
2978 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
2980 *ab = 2;
2981 *regp = reg - REG_BR;
2983 else
2985 *ab = 3;
2986 switch (reg)
2988 case REG_PR: *regp = 0; break;
2989 case REG_PSP: *regp = 1; break;
2990 case REG_PRIUNAT: *regp = 2; break;
2991 case REG_BR + 0: *regp = 3; break;
2992 case REG_AR + AR_BSP: *regp = 4; break;
2993 case REG_AR + AR_BSPSTORE: *regp = 5; break;
2994 case REG_AR + AR_RNAT: *regp = 6; break;
2995 case REG_AR + AR_UNAT: *regp = 7; break;
2996 case REG_AR + AR_FPSR: *regp = 8; break;
2997 case REG_AR + AR_PFS: *regp = 9; break;
2998 case REG_AR + AR_LC: *regp = 10; break;
3000 default:
3001 return 0;
3004 return 1;
3007 static int
3008 convert_expr_to_xy_reg (e, xy, regp)
3009 expressionS *e;
3010 unsigned int *xy;
3011 unsigned int *regp;
3013 unsigned int reg;
3015 if (e->X_op != O_register)
3016 return 0;
3018 reg = e->X_add_number;
3020 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
3022 *xy = 0;
3023 *regp = reg - REG_GR;
3025 else if (reg >= REG_FR && reg <= (REG_FR + 127))
3027 *xy = 1;
3028 *regp = reg - REG_FR;
3030 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3032 *xy = 2;
3033 *regp = reg - REG_BR;
3035 else
3036 return -1;
3037 return 1;
3040 static void
3041 dot_align (int arg)
3043 /* The current frag is an alignment frag. */
3044 align_frag = frag_now;
3045 s_align_bytes (arg);
3048 static void
3049 dot_radix (dummy)
3050 int dummy ATTRIBUTE_UNUSED;
3052 int radix;
3054 SKIP_WHITESPACE ();
3055 radix = *input_line_pointer++;
3057 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3059 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3060 ignore_rest_of_line ();
3061 return;
3065 /* Helper function for .loc directives. If the assembler is not generating
3066 line number info, then we need to remember which instructions have a .loc
3067 directive, and only call dwarf2_gen_line_info for those instructions. */
3069 static void
3070 dot_loc (int x)
3072 CURR_SLOT.loc_directive_seen = 1;
3073 dwarf2_directive_loc (x);
3076 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3077 static void
3078 dot_special_section (which)
3079 int which;
3081 set_section ((char *) special_section_name[which]);
3084 /* Return -1 for warning and 0 for error. */
3086 static int
3087 unwind_diagnostic (const char * region, const char *directive)
3089 if (md.unwind_check == unwind_check_warning)
3091 as_warn (".%s outside of %s", directive, region);
3092 return -1;
3094 else
3096 as_bad (".%s outside of %s", directive, region);
3097 ignore_rest_of_line ();
3098 return 0;
3102 /* Return 1 if a directive is in a procedure, -1 if a directive isn't in
3103 a procedure but the unwind directive check is set to warning, 0 if
3104 a directive isn't in a procedure and the unwind directive check is set
3105 to error. */
3107 static int
3108 in_procedure (const char *directive)
3110 if (unwind.proc_start
3111 && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0))
3112 return 1;
3113 return unwind_diagnostic ("procedure", directive);
3116 /* Return 1 if a directive is in a prologue, -1 if a directive isn't in
3117 a prologue but the unwind directive check is set to warning, 0 if
3118 a directive isn't in a prologue and the unwind directive check is set
3119 to error. */
3121 static int
3122 in_prologue (const char *directive)
3124 int in = in_procedure (directive);
3125 if (in)
3127 /* We are in a procedure. Check if we are in a prologue. */
3128 if (unwind.prologue)
3129 return 1;
3130 /* We only want to issue one message. */
3131 if (in == 1)
3132 return unwind_diagnostic ("prologue", directive);
3133 else
3134 return -1;
3136 return 0;
3139 /* Return 1 if a directive is in a body, -1 if a directive isn't in
3140 a body but the unwind directive check is set to warning, 0 if
3141 a directive isn't in a body and the unwind directive check is set
3142 to error. */
3144 static int
3145 in_body (const char *directive)
3147 int in = in_procedure (directive);
3148 if (in)
3150 /* We are in a procedure. Check if we are in a body. */
3151 if (unwind.body)
3152 return 1;
3153 /* We only want to issue one message. */
3154 if (in == 1)
3155 return unwind_diagnostic ("body region", directive);
3156 else
3157 return -1;
3159 return 0;
3162 static void
3163 add_unwind_entry (ptr)
3164 unw_rec_list *ptr;
3166 if (unwind.tail)
3167 unwind.tail->next = ptr;
3168 else
3169 unwind.list = ptr;
3170 unwind.tail = ptr;
3172 /* The current entry can in fact be a chain of unwind entries. */
3173 if (unwind.current_entry == NULL)
3174 unwind.current_entry = ptr;
3177 static void
3178 dot_fframe (dummy)
3179 int dummy ATTRIBUTE_UNUSED;
3181 expressionS e;
3183 if (!in_prologue ("fframe"))
3184 return;
3186 parse_operand (&e);
3188 if (e.X_op != O_constant)
3189 as_bad ("Operand to .fframe must be a constant");
3190 else
3191 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3194 static void
3195 dot_vframe (dummy)
3196 int dummy ATTRIBUTE_UNUSED;
3198 expressionS e;
3199 unsigned reg;
3201 if (!in_prologue ("vframe"))
3202 return;
3204 parse_operand (&e);
3205 reg = e.X_add_number - REG_GR;
3206 if (e.X_op == O_register && reg < 128)
3208 add_unwind_entry (output_mem_stack_v ());
3209 if (! (unwind.prologue_mask & 2))
3210 add_unwind_entry (output_psp_gr (reg));
3212 else
3213 as_bad ("First operand to .vframe must be a general register");
3216 static void
3217 dot_vframesp (dummy)
3218 int dummy ATTRIBUTE_UNUSED;
3220 expressionS e;
3222 if (!in_prologue ("vframesp"))
3223 return;
3225 parse_operand (&e);
3226 if (e.X_op == O_constant)
3228 add_unwind_entry (output_mem_stack_v ());
3229 add_unwind_entry (output_psp_sprel (e.X_add_number));
3231 else
3232 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3235 static void
3236 dot_vframepsp (dummy)
3237 int dummy ATTRIBUTE_UNUSED;
3239 expressionS e;
3241 if (!in_prologue ("vframepsp"))
3242 return;
3244 parse_operand (&e);
3245 if (e.X_op == O_constant)
3247 add_unwind_entry (output_mem_stack_v ());
3248 add_unwind_entry (output_psp_sprel (e.X_add_number));
3250 else
3251 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3254 static void
3255 dot_save (dummy)
3256 int dummy ATTRIBUTE_UNUSED;
3258 expressionS e1, e2;
3259 int sep;
3260 int reg1, reg2;
3262 if (!in_prologue ("save"))
3263 return;
3265 sep = parse_operand (&e1);
3266 if (sep != ',')
3267 as_bad ("No second operand to .save");
3268 sep = parse_operand (&e2);
3270 reg1 = e1.X_add_number;
3271 reg2 = e2.X_add_number - REG_GR;
3273 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3274 if (e1.X_op == O_register)
3276 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3278 switch (reg1)
3280 case REG_AR + AR_BSP:
3281 add_unwind_entry (output_bsp_when ());
3282 add_unwind_entry (output_bsp_gr (reg2));
3283 break;
3284 case REG_AR + AR_BSPSTORE:
3285 add_unwind_entry (output_bspstore_when ());
3286 add_unwind_entry (output_bspstore_gr (reg2));
3287 break;
3288 case REG_AR + AR_RNAT:
3289 add_unwind_entry (output_rnat_when ());
3290 add_unwind_entry (output_rnat_gr (reg2));
3291 break;
3292 case REG_AR + AR_UNAT:
3293 add_unwind_entry (output_unat_when ());
3294 add_unwind_entry (output_unat_gr (reg2));
3295 break;
3296 case REG_AR + AR_FPSR:
3297 add_unwind_entry (output_fpsr_when ());
3298 add_unwind_entry (output_fpsr_gr (reg2));
3299 break;
3300 case REG_AR + AR_PFS:
3301 add_unwind_entry (output_pfs_when ());
3302 if (! (unwind.prologue_mask & 4))
3303 add_unwind_entry (output_pfs_gr (reg2));
3304 break;
3305 case REG_AR + AR_LC:
3306 add_unwind_entry (output_lc_when ());
3307 add_unwind_entry (output_lc_gr (reg2));
3308 break;
3309 case REG_BR:
3310 add_unwind_entry (output_rp_when ());
3311 if (! (unwind.prologue_mask & 8))
3312 add_unwind_entry (output_rp_gr (reg2));
3313 break;
3314 case REG_PR:
3315 add_unwind_entry (output_preds_when ());
3316 if (! (unwind.prologue_mask & 1))
3317 add_unwind_entry (output_preds_gr (reg2));
3318 break;
3319 case REG_PRIUNAT:
3320 add_unwind_entry (output_priunat_when_gr ());
3321 add_unwind_entry (output_priunat_gr (reg2));
3322 break;
3323 default:
3324 as_bad ("First operand not a valid register");
3327 else
3328 as_bad (" Second operand not a valid register");
3330 else
3331 as_bad ("First operand not a register");
3334 static void
3335 dot_restore (dummy)
3336 int dummy ATTRIBUTE_UNUSED;
3338 expressionS e1, e2;
3339 unsigned long ecount; /* # of _additional_ regions to pop */
3340 int sep;
3342 if (!in_body ("restore"))
3343 return;
3345 sep = parse_operand (&e1);
3346 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3348 as_bad ("First operand to .restore must be stack pointer (sp)");
3349 return;
3352 if (sep == ',')
3354 parse_operand (&e2);
3355 if (e2.X_op != O_constant || e2.X_add_number < 0)
3357 as_bad ("Second operand to .restore must be a constant >= 0");
3358 return;
3360 ecount = e2.X_add_number;
3362 else
3363 ecount = unwind.prologue_count - 1;
3365 if (ecount >= unwind.prologue_count)
3367 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3368 ecount + 1, unwind.prologue_count);
3369 return;
3372 add_unwind_entry (output_epilogue (ecount));
3374 if (ecount < unwind.prologue_count)
3375 unwind.prologue_count -= ecount + 1;
3376 else
3377 unwind.prologue_count = 0;
3380 static void
3381 dot_restorereg (dummy)
3382 int dummy ATTRIBUTE_UNUSED;
3384 unsigned int ab, reg;
3385 expressionS e;
3387 if (!in_procedure ("restorereg"))
3388 return;
3390 parse_operand (&e);
3392 if (!convert_expr_to_ab_reg (&e, &ab, &reg))
3394 as_bad ("First operand to .restorereg must be a preserved register");
3395 return;
3397 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3400 static void
3401 dot_restorereg_p (dummy)
3402 int dummy ATTRIBUTE_UNUSED;
3404 unsigned int qp, ab, reg;
3405 expressionS e1, e2;
3406 int sep;
3408 if (!in_procedure ("restorereg.p"))
3409 return;
3411 sep = parse_operand (&e1);
3412 if (sep != ',')
3414 as_bad ("No second operand to .restorereg.p");
3415 return;
3418 parse_operand (&e2);
3420 qp = e1.X_add_number - REG_P;
3421 if (e1.X_op != O_register || qp > 63)
3423 as_bad ("First operand to .restorereg.p must be a predicate");
3424 return;
3427 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
3429 as_bad ("Second operand to .restorereg.p must be a preserved register");
3430 return;
3432 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3435 static char *special_linkonce_name[] =
3437 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3440 static void
3441 start_unwind_section (const segT text_seg, int sec_index, int linkonce_empty)
3444 Use a slightly ugly scheme to derive the unwind section names from
3445 the text section name:
3447 text sect. unwind table sect.
3448 name: name: comments:
3449 ---------- ----------------- --------------------------------
3450 .text .IA_64.unwind
3451 .text.foo .IA_64.unwind.text.foo
3452 .foo .IA_64.unwind.foo
3453 .gnu.linkonce.t.foo
3454 .gnu.linkonce.ia64unw.foo
3455 _info .IA_64.unwind_info gas issues error message (ditto)
3456 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3458 This mapping is done so that:
3460 (a) An object file with unwind info only in .text will use
3461 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3462 This follows the letter of the ABI and also ensures backwards
3463 compatibility with older toolchains.
3465 (b) An object file with unwind info in multiple text sections
3466 will use separate unwind sections for each text section.
3467 This allows us to properly set the "sh_info" and "sh_link"
3468 fields in SHT_IA_64_UNWIND as required by the ABI and also
3469 lets GNU ld support programs with multiple segments
3470 containing unwind info (as might be the case for certain
3471 embedded applications).
3473 (c) An error is issued if there would be a name clash.
3476 const char *text_name, *sec_text_name;
3477 char *sec_name;
3478 const char *prefix = special_section_name [sec_index];
3479 const char *suffix;
3480 size_t prefix_len, suffix_len, sec_name_len;
3482 sec_text_name = segment_name (text_seg);
3483 text_name = sec_text_name;
3484 if (strncmp (text_name, "_info", 5) == 0)
3486 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3487 text_name);
3488 ignore_rest_of_line ();
3489 return;
3491 if (strcmp (text_name, ".text") == 0)
3492 text_name = "";
3494 /* Build the unwind section name by appending the (possibly stripped)
3495 text section name to the unwind prefix. */
3496 suffix = text_name;
3497 if (strncmp (text_name, ".gnu.linkonce.t.",
3498 sizeof (".gnu.linkonce.t.") - 1) == 0)
3500 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3501 suffix += sizeof (".gnu.linkonce.t.") - 1;
3503 else if (linkonce_empty)
3504 return;
3506 prefix_len = strlen (prefix);
3507 suffix_len = strlen (suffix);
3508 sec_name_len = prefix_len + suffix_len;
3509 sec_name = alloca (sec_name_len + 1);
3510 memcpy (sec_name, prefix, prefix_len);
3511 memcpy (sec_name + prefix_len, suffix, suffix_len);
3512 sec_name [sec_name_len] = '\0';
3514 /* Handle COMDAT group. */
3515 if (suffix == text_name && (text_seg->flags & SEC_LINK_ONCE) != 0)
3517 char *section;
3518 size_t len, group_name_len;
3519 const char *group_name = elf_group_name (text_seg);
3521 if (group_name == NULL)
3523 as_bad ("Group section `%s' has no group signature",
3524 sec_text_name);
3525 ignore_rest_of_line ();
3526 return;
3528 /* We have to construct a fake section directive. */
3529 group_name_len = strlen (group_name);
3530 len = (sec_name_len
3531 + 16 /* ,"aG",@progbits, */
3532 + group_name_len /* ,group_name */
3533 + 7); /* ,comdat */
3535 section = alloca (len + 1);
3536 memcpy (section, sec_name, sec_name_len);
3537 memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3538 memcpy (section + sec_name_len + 16, group_name, group_name_len);
3539 memcpy (section + len - 7, ",comdat", 7);
3540 section [len] = '\0';
3541 set_section (section);
3543 else
3545 set_section (sec_name);
3546 bfd_set_section_flags (stdoutput, now_seg,
3547 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3550 elf_linked_to_section (now_seg) = text_seg;
3553 static void
3554 generate_unwind_image (const segT text_seg)
3556 int size, pad;
3557 unw_rec_list *list;
3559 /* Mark the end of the unwind info, so that we can compute the size of the
3560 last unwind region. */
3561 add_unwind_entry (output_endp ());
3563 /* Force out pending instructions, to make sure all unwind records have
3564 a valid slot_number field. */
3565 ia64_flush_insns ();
3567 /* Generate the unwind record. */
3568 list = optimize_unw_records (unwind.list);
3569 fixup_unw_records (list, 1);
3570 size = calc_record_size (list);
3572 if (size > 0 || unwind.force_unwind_entry)
3574 unwind.force_unwind_entry = 0;
3575 /* pad to pointer-size boundary. */
3576 pad = size % md.pointer_size;
3577 if (pad != 0)
3578 size += md.pointer_size - pad;
3579 /* Add 8 for the header. */
3580 size += 8;
3581 /* Add a pointer for the personality offset. */
3582 if (unwind.personality_routine)
3583 size += md.pointer_size;
3586 /* If there are unwind records, switch sections, and output the info. */
3587 if (size != 0)
3589 expressionS exp;
3590 bfd_reloc_code_real_type reloc;
3592 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 0);
3594 /* Make sure the section has 4 byte alignment for ILP32 and
3595 8 byte alignment for LP64. */
3596 frag_align (md.pointer_size_shift, 0, 0);
3597 record_alignment (now_seg, md.pointer_size_shift);
3599 /* Set expression which points to start of unwind descriptor area. */
3600 unwind.info = expr_build_dot ();
3602 frag_var (rs_machine_dependent, size, size, 0, 0,
3603 (offsetT) (long) unwind.personality_routine,
3604 (char *) list);
3606 /* Add the personality address to the image. */
3607 if (unwind.personality_routine != 0)
3609 exp.X_op = O_symbol;
3610 exp.X_add_symbol = unwind.personality_routine;
3611 exp.X_add_number = 0;
3613 if (md.flags & EF_IA_64_BE)
3615 if (md.flags & EF_IA_64_ABI64)
3616 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3617 else
3618 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3620 else
3622 if (md.flags & EF_IA_64_ABI64)
3623 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3624 else
3625 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3628 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3629 md.pointer_size, &exp, 0, reloc);
3630 unwind.personality_routine = 0;
3633 else
3634 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO, 1);
3636 free_saved_prologue_counts ();
3637 unwind.list = unwind.tail = unwind.current_entry = NULL;
3640 static void
3641 dot_handlerdata (dummy)
3642 int dummy ATTRIBUTE_UNUSED;
3644 if (!in_procedure ("handlerdata"))
3645 return;
3646 unwind.force_unwind_entry = 1;
3648 /* Remember which segment we're in so we can switch back after .endp */
3649 unwind.saved_text_seg = now_seg;
3650 unwind.saved_text_subseg = now_subseg;
3652 /* Generate unwind info into unwind-info section and then leave that
3653 section as the currently active one so dataXX directives go into
3654 the language specific data area of the unwind info block. */
3655 generate_unwind_image (now_seg);
3656 demand_empty_rest_of_line ();
3659 static void
3660 dot_unwentry (dummy)
3661 int dummy ATTRIBUTE_UNUSED;
3663 if (!in_procedure ("unwentry"))
3664 return;
3665 unwind.force_unwind_entry = 1;
3666 demand_empty_rest_of_line ();
3669 static void
3670 dot_altrp (dummy)
3671 int dummy ATTRIBUTE_UNUSED;
3673 expressionS e;
3674 unsigned reg;
3676 if (!in_prologue ("altrp"))
3677 return;
3679 parse_operand (&e);
3680 reg = e.X_add_number - REG_BR;
3681 if (e.X_op == O_register && reg < 8)
3682 add_unwind_entry (output_rp_br (reg));
3683 else
3684 as_bad ("First operand not a valid branch register");
3687 static void
3688 dot_savemem (psprel)
3689 int psprel;
3691 expressionS e1, e2;
3692 int sep;
3693 int reg1, val;
3695 if (!in_prologue (psprel ? "savepsp" : "savesp"))
3696 return;
3698 sep = parse_operand (&e1);
3699 if (sep != ',')
3700 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3701 sep = parse_operand (&e2);
3703 reg1 = e1.X_add_number;
3704 val = e2.X_add_number;
3706 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3707 if (e1.X_op == O_register)
3709 if (e2.X_op == O_constant)
3711 switch (reg1)
3713 case REG_AR + AR_BSP:
3714 add_unwind_entry (output_bsp_when ());
3715 add_unwind_entry ((psprel
3716 ? output_bsp_psprel
3717 : output_bsp_sprel) (val));
3718 break;
3719 case REG_AR + AR_BSPSTORE:
3720 add_unwind_entry (output_bspstore_when ());
3721 add_unwind_entry ((psprel
3722 ? output_bspstore_psprel
3723 : output_bspstore_sprel) (val));
3724 break;
3725 case REG_AR + AR_RNAT:
3726 add_unwind_entry (output_rnat_when ());
3727 add_unwind_entry ((psprel
3728 ? output_rnat_psprel
3729 : output_rnat_sprel) (val));
3730 break;
3731 case REG_AR + AR_UNAT:
3732 add_unwind_entry (output_unat_when ());
3733 add_unwind_entry ((psprel
3734 ? output_unat_psprel
3735 : output_unat_sprel) (val));
3736 break;
3737 case REG_AR + AR_FPSR:
3738 add_unwind_entry (output_fpsr_when ());
3739 add_unwind_entry ((psprel
3740 ? output_fpsr_psprel
3741 : output_fpsr_sprel) (val));
3742 break;
3743 case REG_AR + AR_PFS:
3744 add_unwind_entry (output_pfs_when ());
3745 add_unwind_entry ((psprel
3746 ? output_pfs_psprel
3747 : output_pfs_sprel) (val));
3748 break;
3749 case REG_AR + AR_LC:
3750 add_unwind_entry (output_lc_when ());
3751 add_unwind_entry ((psprel
3752 ? output_lc_psprel
3753 : output_lc_sprel) (val));
3754 break;
3755 case REG_BR:
3756 add_unwind_entry (output_rp_when ());
3757 add_unwind_entry ((psprel
3758 ? output_rp_psprel
3759 : output_rp_sprel) (val));
3760 break;
3761 case REG_PR:
3762 add_unwind_entry (output_preds_when ());
3763 add_unwind_entry ((psprel
3764 ? output_preds_psprel
3765 : output_preds_sprel) (val));
3766 break;
3767 case REG_PRIUNAT:
3768 add_unwind_entry (output_priunat_when_mem ());
3769 add_unwind_entry ((psprel
3770 ? output_priunat_psprel
3771 : output_priunat_sprel) (val));
3772 break;
3773 default:
3774 as_bad ("First operand not a valid register");
3777 else
3778 as_bad (" Second operand not a valid constant");
3780 else
3781 as_bad ("First operand not a register");
3784 static void
3785 dot_saveg (dummy)
3786 int dummy ATTRIBUTE_UNUSED;
3788 expressionS e1, e2;
3789 int sep;
3791 if (!in_prologue ("save.g"))
3792 return;
3794 sep = parse_operand (&e1);
3795 if (sep == ',')
3796 parse_operand (&e2);
3798 if (e1.X_op != O_constant)
3799 as_bad ("First operand to .save.g must be a constant.");
3800 else
3802 int grmask = e1.X_add_number;
3803 if (sep != ',')
3804 add_unwind_entry (output_gr_mem (grmask));
3805 else
3807 int reg = e2.X_add_number - REG_GR;
3808 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3809 add_unwind_entry (output_gr_gr (grmask, reg));
3810 else
3811 as_bad ("Second operand is an invalid register.");
3816 static void
3817 dot_savef (dummy)
3818 int dummy ATTRIBUTE_UNUSED;
3820 expressionS e1;
3821 int sep;
3823 if (!in_prologue ("save.f"))
3824 return;
3826 sep = parse_operand (&e1);
3828 if (e1.X_op != O_constant)
3829 as_bad ("Operand to .save.f must be a constant.");
3830 else
3831 add_unwind_entry (output_fr_mem (e1.X_add_number));
3834 static void
3835 dot_saveb (dummy)
3836 int dummy ATTRIBUTE_UNUSED;
3838 expressionS e1, e2;
3839 unsigned int reg;
3840 unsigned char sep;
3841 int brmask;
3843 if (!in_prologue ("save.b"))
3844 return;
3846 sep = parse_operand (&e1);
3847 if (e1.X_op != O_constant)
3849 as_bad ("First operand to .save.b must be a constant.");
3850 return;
3852 brmask = e1.X_add_number;
3854 if (sep == ',')
3856 sep = parse_operand (&e2);
3857 reg = e2.X_add_number - REG_GR;
3858 if (e2.X_op != O_register || reg > 127)
3860 as_bad ("Second operand to .save.b must be a general register.");
3861 return;
3863 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3865 else
3866 add_unwind_entry (output_br_mem (brmask));
3868 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3869 demand_empty_rest_of_line ();
3872 static void
3873 dot_savegf (dummy)
3874 int dummy ATTRIBUTE_UNUSED;
3876 expressionS e1, e2;
3877 int sep;
3879 if (!in_prologue ("save.gf"))
3880 return;
3882 sep = parse_operand (&e1);
3883 if (sep == ',')
3884 parse_operand (&e2);
3886 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3887 as_bad ("Both operands of .save.gf must be constants.");
3888 else
3890 int grmask = e1.X_add_number;
3891 int frmask = e2.X_add_number;
3892 add_unwind_entry (output_frgr_mem (grmask, frmask));
3896 static void
3897 dot_spill (dummy)
3898 int dummy ATTRIBUTE_UNUSED;
3900 expressionS e;
3901 unsigned char sep;
3903 if (!in_prologue ("spill"))
3904 return;
3906 sep = parse_operand (&e);
3907 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3908 demand_empty_rest_of_line ();
3910 if (e.X_op != O_constant)
3911 as_bad ("Operand to .spill must be a constant");
3912 else
3913 add_unwind_entry (output_spill_base (e.X_add_number));
3916 static void
3917 dot_spillreg (dummy)
3918 int dummy ATTRIBUTE_UNUSED;
3920 int sep;
3921 unsigned int ab, xy, reg, treg;
3922 expressionS e1, e2;
3924 if (!in_procedure ("spillreg"))
3925 return;
3927 sep = parse_operand (&e1);
3928 if (sep != ',')
3930 as_bad ("No second operand to .spillreg");
3931 return;
3934 parse_operand (&e2);
3936 if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3938 as_bad ("First operand to .spillreg must be a preserved register");
3939 return;
3942 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3944 as_bad ("Second operand to .spillreg must be a register");
3945 return;
3948 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3951 static void
3952 dot_spillmem (psprel)
3953 int psprel;
3955 expressionS e1, e2;
3956 int sep;
3957 unsigned int ab, reg;
3959 if (!in_procedure ("spillmem"))
3960 return;
3962 sep = parse_operand (&e1);
3963 if (sep != ',')
3965 as_bad ("Second operand missing");
3966 return;
3969 parse_operand (&e2);
3971 if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3973 as_bad ("First operand to .spill%s must be a preserved register",
3974 psprel ? "psp" : "sp");
3975 return;
3978 if (e2.X_op != O_constant)
3980 as_bad ("Second operand to .spill%s must be a constant",
3981 psprel ? "psp" : "sp");
3982 return;
3985 if (psprel)
3986 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
3987 else
3988 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
3991 static void
3992 dot_spillreg_p (dummy)
3993 int dummy ATTRIBUTE_UNUSED;
3995 int sep;
3996 unsigned int ab, xy, reg, treg;
3997 expressionS e1, e2, e3;
3998 unsigned int qp;
4000 if (!in_procedure ("spillreg.p"))
4001 return;
4003 sep = parse_operand (&e1);
4004 if (sep != ',')
4006 as_bad ("No second and third operand to .spillreg.p");
4007 return;
4010 sep = parse_operand (&e2);
4011 if (sep != ',')
4013 as_bad ("No third operand to .spillreg.p");
4014 return;
4017 parse_operand (&e3);
4019 qp = e1.X_add_number - REG_P;
4021 if (e1.X_op != O_register || qp > 63)
4023 as_bad ("First operand to .spillreg.p must be a predicate");
4024 return;
4027 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
4029 as_bad ("Second operand to .spillreg.p must be a preserved register");
4030 return;
4033 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
4035 as_bad ("Third operand to .spillreg.p must be a register");
4036 return;
4039 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
4042 static void
4043 dot_spillmem_p (psprel)
4044 int psprel;
4046 expressionS e1, e2, e3;
4047 int sep;
4048 unsigned int ab, reg;
4049 unsigned int qp;
4051 if (!in_procedure ("spillmem.p"))
4052 return;
4054 sep = parse_operand (&e1);
4055 if (sep != ',')
4057 as_bad ("Second operand missing");
4058 return;
4061 parse_operand (&e2);
4062 if (sep != ',')
4064 as_bad ("Second operand missing");
4065 return;
4068 parse_operand (&e3);
4070 qp = e1.X_add_number - REG_P;
4071 if (e1.X_op != O_register || qp > 63)
4073 as_bad ("First operand to .spill%s_p must be a predicate",
4074 psprel ? "psp" : "sp");
4075 return;
4078 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
4080 as_bad ("Second operand to .spill%s_p must be a preserved register",
4081 psprel ? "psp" : "sp");
4082 return;
4085 if (e3.X_op != O_constant)
4087 as_bad ("Third operand to .spill%s_p must be a constant",
4088 psprel ? "psp" : "sp");
4089 return;
4092 if (psprel)
4093 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
4094 else
4095 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
4098 static unsigned int
4099 get_saved_prologue_count (lbl)
4100 unsigned long lbl;
4102 label_prologue_count *lpc = unwind.saved_prologue_counts;
4104 while (lpc != NULL && lpc->label_number != lbl)
4105 lpc = lpc->next;
4107 if (lpc != NULL)
4108 return lpc->prologue_count;
4110 as_bad ("Missing .label_state %ld", lbl);
4111 return 1;
4114 static void
4115 save_prologue_count (lbl, count)
4116 unsigned long lbl;
4117 unsigned int count;
4119 label_prologue_count *lpc = unwind.saved_prologue_counts;
4121 while (lpc != NULL && lpc->label_number != lbl)
4122 lpc = lpc->next;
4124 if (lpc != NULL)
4125 lpc->prologue_count = count;
4126 else
4128 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
4130 new_lpc->next = unwind.saved_prologue_counts;
4131 new_lpc->label_number = lbl;
4132 new_lpc->prologue_count = count;
4133 unwind.saved_prologue_counts = new_lpc;
4137 static void
4138 free_saved_prologue_counts ()
4140 label_prologue_count *lpc = unwind.saved_prologue_counts;
4141 label_prologue_count *next;
4143 while (lpc != NULL)
4145 next = lpc->next;
4146 free (lpc);
4147 lpc = next;
4150 unwind.saved_prologue_counts = NULL;
4153 static void
4154 dot_label_state (dummy)
4155 int dummy ATTRIBUTE_UNUSED;
4157 expressionS e;
4159 if (!in_body ("label_state"))
4160 return;
4162 parse_operand (&e);
4163 if (e.X_op != O_constant)
4165 as_bad ("Operand to .label_state must be a constant");
4166 return;
4168 add_unwind_entry (output_label_state (e.X_add_number));
4169 save_prologue_count (e.X_add_number, unwind.prologue_count);
4172 static void
4173 dot_copy_state (dummy)
4174 int dummy ATTRIBUTE_UNUSED;
4176 expressionS e;
4178 if (!in_body ("copy_state"))
4179 return;
4181 parse_operand (&e);
4182 if (e.X_op != O_constant)
4184 as_bad ("Operand to .copy_state must be a constant");
4185 return;
4187 add_unwind_entry (output_copy_state (e.X_add_number));
4188 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
4191 static void
4192 dot_unwabi (dummy)
4193 int dummy ATTRIBUTE_UNUSED;
4195 expressionS e1, e2;
4196 unsigned char sep;
4198 if (!in_procedure ("unwabi"))
4199 return;
4201 sep = parse_operand (&e1);
4202 if (sep != ',')
4204 as_bad ("Second operand to .unwabi missing");
4205 return;
4207 sep = parse_operand (&e2);
4208 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4209 demand_empty_rest_of_line ();
4211 if (e1.X_op != O_constant)
4213 as_bad ("First operand to .unwabi must be a constant");
4214 return;
4217 if (e2.X_op != O_constant)
4219 as_bad ("Second operand to .unwabi must be a constant");
4220 return;
4223 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4226 static void
4227 dot_personality (dummy)
4228 int dummy ATTRIBUTE_UNUSED;
4230 char *name, *p, c;
4231 if (!in_procedure ("personality"))
4232 return;
4233 SKIP_WHITESPACE ();
4234 name = input_line_pointer;
4235 c = get_symbol_end ();
4236 p = input_line_pointer;
4237 unwind.personality_routine = symbol_find_or_make (name);
4238 unwind.force_unwind_entry = 1;
4239 *p = c;
4240 SKIP_WHITESPACE ();
4241 demand_empty_rest_of_line ();
4244 static void
4245 dot_proc (dummy)
4246 int dummy ATTRIBUTE_UNUSED;
4248 char *name, *p, c;
4249 symbolS *sym;
4251 unwind.proc_start = 0;
4252 /* Parse names of main and alternate entry points and mark them as
4253 function symbols: */
4254 while (1)
4256 SKIP_WHITESPACE ();
4257 name = input_line_pointer;
4258 c = get_symbol_end ();
4259 p = input_line_pointer;
4260 if (!*name)
4261 as_bad ("Empty argument of .proc");
4262 else
4264 sym = symbol_find_or_make (name);
4265 if (S_IS_DEFINED (sym))
4266 as_bad ("`%s' was already defined", name);
4267 else if (unwind.proc_start == 0)
4269 unwind.proc_start = sym;
4271 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4273 *p = c;
4274 SKIP_WHITESPACE ();
4275 if (*input_line_pointer != ',')
4276 break;
4277 ++input_line_pointer;
4279 if (unwind.proc_start == 0)
4280 unwind.proc_start = expr_build_dot ();
4281 demand_empty_rest_of_line ();
4282 ia64_do_align (16);
4284 unwind.prologue = 0;
4285 unwind.prologue_count = 0;
4286 unwind.body = 0;
4287 unwind.insn = 0;
4288 unwind.list = unwind.tail = unwind.current_entry = NULL;
4289 unwind.personality_routine = 0;
4292 static void
4293 dot_body (dummy)
4294 int dummy ATTRIBUTE_UNUSED;
4296 if (!in_procedure ("body"))
4297 return;
4298 if (!unwind.prologue && !unwind.body && unwind.insn)
4299 as_warn ("Initial .body should precede any instructions");
4301 unwind.prologue = 0;
4302 unwind.prologue_mask = 0;
4303 unwind.body = 1;
4305 add_unwind_entry (output_body ());
4306 demand_empty_rest_of_line ();
4309 static void
4310 dot_prologue (dummy)
4311 int dummy ATTRIBUTE_UNUSED;
4313 unsigned char sep;
4314 int mask = 0, grsave = 0;
4316 if (!in_procedure ("prologue"))
4317 return;
4318 if (unwind.prologue)
4320 as_bad (".prologue within prologue");
4321 ignore_rest_of_line ();
4322 return;
4324 if (!unwind.body && unwind.insn)
4325 as_warn ("Initial .prologue should precede any instructions");
4327 if (!is_it_end_of_statement ())
4329 expressionS e1, e2;
4330 sep = parse_operand (&e1);
4331 if (sep != ',')
4332 as_bad ("No second operand to .prologue");
4333 sep = parse_operand (&e2);
4334 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4335 demand_empty_rest_of_line ();
4337 if (e1.X_op == O_constant)
4339 mask = e1.X_add_number;
4341 if (e2.X_op == O_constant)
4342 grsave = e2.X_add_number;
4343 else if (e2.X_op == O_register
4344 && (grsave = e2.X_add_number - REG_GR) < 128)
4346 else
4347 as_bad ("Second operand not a constant or general register");
4349 add_unwind_entry (output_prologue_gr (mask, grsave));
4351 else
4352 as_bad ("First operand not a constant");
4354 else
4355 add_unwind_entry (output_prologue ());
4357 unwind.prologue = 1;
4358 unwind.prologue_mask = mask;
4359 unwind.body = 0;
4360 ++unwind.prologue_count;
4363 static void
4364 dot_endp (dummy)
4365 int dummy ATTRIBUTE_UNUSED;
4367 expressionS e;
4368 char *ptr;
4369 int bytes_per_address;
4370 long where;
4371 segT saved_seg;
4372 subsegT saved_subseg;
4373 char *name, *default_name, *p, c;
4374 symbolS *sym;
4375 int unwind_check = md.unwind_check;
4377 md.unwind_check = unwind_check_error;
4378 if (!in_procedure ("endp"))
4379 return;
4380 md.unwind_check = unwind_check;
4382 if (unwind.saved_text_seg)
4384 saved_seg = unwind.saved_text_seg;
4385 saved_subseg = unwind.saved_text_subseg;
4386 unwind.saved_text_seg = NULL;
4388 else
4390 saved_seg = now_seg;
4391 saved_subseg = now_subseg;
4394 insn_group_break (1, 0, 0);
4396 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4397 if (!unwind.info)
4398 generate_unwind_image (saved_seg);
4400 if (unwind.info || unwind.force_unwind_entry)
4402 symbolS *proc_end;
4404 subseg_set (md.last_text_seg, 0);
4405 proc_end = expr_build_dot ();
4407 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 0);
4409 /* Make sure that section has 4 byte alignment for ILP32 and
4410 8 byte alignment for LP64. */
4411 record_alignment (now_seg, md.pointer_size_shift);
4413 /* Need space for 3 pointers for procedure start, procedure end,
4414 and unwind info. */
4415 ptr = frag_more (3 * md.pointer_size);
4416 where = frag_now_fix () - (3 * md.pointer_size);
4417 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4419 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4420 e.X_op = O_pseudo_fixup;
4421 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4422 e.X_add_number = 0;
4423 e.X_add_symbol = unwind.proc_start;
4424 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4426 e.X_op = O_pseudo_fixup;
4427 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4428 e.X_add_number = 0;
4429 e.X_add_symbol = proc_end;
4430 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4431 bytes_per_address, &e);
4433 if (unwind.info)
4435 e.X_op = O_pseudo_fixup;
4436 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4437 e.X_add_number = 0;
4438 e.X_add_symbol = unwind.info;
4439 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4440 bytes_per_address, &e);
4442 else
4443 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4444 bytes_per_address);
4447 else
4448 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND, 1);
4450 subseg_set (saved_seg, saved_subseg);
4452 if (unwind.proc_start)
4453 default_name = (char *) S_GET_NAME (unwind.proc_start);
4454 else
4455 default_name = NULL;
4457 /* Parse names of main and alternate entry points and set symbol sizes. */
4458 while (1)
4460 SKIP_WHITESPACE ();
4461 name = input_line_pointer;
4462 c = get_symbol_end ();
4463 p = input_line_pointer;
4464 if (!*name)
4466 if (md.unwind_check == unwind_check_warning)
4468 if (default_name)
4470 as_warn ("Empty argument of .endp. Use the default name `%s'",
4471 default_name);
4472 name = default_name;
4474 else
4475 as_warn ("Empty argument of .endp");
4477 else
4478 as_bad ("Empty argument of .endp");
4480 if (*name)
4482 sym = symbol_find (name);
4483 if (!sym
4484 && md.unwind_check == unwind_check_warning
4485 && default_name
4486 && default_name != name)
4488 /* We have a bad name. Try the default one if needed. */
4489 as_warn ("`%s' was not defined within procedure. Use the default name `%s'",
4490 name, default_name);
4491 name = default_name;
4492 sym = symbol_find (name);
4494 if (!sym || !S_IS_DEFINED (sym))
4495 as_bad ("`%s' was not defined within procedure", name);
4496 else if (unwind.proc_start
4497 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4498 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4500 fragS *fr = symbol_get_frag (unwind.proc_start);
4501 fragS *frag = symbol_get_frag (sym);
4503 /* Check whether the function label is at or beyond last
4504 .proc directive. */
4505 while (fr && fr != frag)
4506 fr = fr->fr_next;
4507 if (fr)
4509 if (frag == frag_now && SEG_NORMAL (now_seg))
4510 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4511 else
4513 symbol_get_obj (sym)->size =
4514 (expressionS *) xmalloc (sizeof (expressionS));
4515 symbol_get_obj (sym)->size->X_op = O_subtract;
4516 symbol_get_obj (sym)->size->X_add_symbol
4517 = symbol_new (FAKE_LABEL_NAME, now_seg,
4518 frag_now_fix (), frag_now);
4519 symbol_get_obj (sym)->size->X_op_symbol = sym;
4520 symbol_get_obj (sym)->size->X_add_number = 0;
4525 *p = c;
4526 SKIP_WHITESPACE ();
4527 if (*input_line_pointer != ',')
4528 break;
4529 ++input_line_pointer;
4531 demand_empty_rest_of_line ();
4532 unwind.proc_start = unwind.info = 0;
4535 static void
4536 dot_template (template)
4537 int template;
4539 CURR_SLOT.user_template = template;
4542 static void
4543 dot_regstk (dummy)
4544 int dummy ATTRIBUTE_UNUSED;
4546 int ins, locs, outs, rots;
4548 if (is_it_end_of_statement ())
4549 ins = locs = outs = rots = 0;
4550 else
4552 ins = get_absolute_expression ();
4553 if (*input_line_pointer++ != ',')
4554 goto err;
4555 locs = get_absolute_expression ();
4556 if (*input_line_pointer++ != ',')
4557 goto err;
4558 outs = get_absolute_expression ();
4559 if (*input_line_pointer++ != ',')
4560 goto err;
4561 rots = get_absolute_expression ();
4563 set_regstack (ins, locs, outs, rots);
4564 return;
4566 err:
4567 as_bad ("Comma expected");
4568 ignore_rest_of_line ();
4571 static void
4572 dot_rot (type)
4573 int type;
4575 unsigned num_regs, num_alloced = 0;
4576 struct dynreg **drpp, *dr;
4577 int ch, base_reg = 0;
4578 char *name, *start;
4579 size_t len;
4581 switch (type)
4583 case DYNREG_GR: base_reg = REG_GR + 32; break;
4584 case DYNREG_FR: base_reg = REG_FR + 32; break;
4585 case DYNREG_PR: base_reg = REG_P + 16; break;
4586 default: break;
4589 /* First, remove existing names from hash table. */
4590 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4592 hash_delete (md.dynreg_hash, dr->name);
4593 /* FIXME: Free dr->name. */
4594 dr->num_regs = 0;
4597 drpp = &md.dynreg[type];
4598 while (1)
4600 start = input_line_pointer;
4601 ch = get_symbol_end ();
4602 len = strlen (ia64_canonicalize_symbol_name (start));
4603 *input_line_pointer = ch;
4605 SKIP_WHITESPACE ();
4606 if (*input_line_pointer != '[')
4608 as_bad ("Expected '['");
4609 goto err;
4611 ++input_line_pointer; /* skip '[' */
4613 num_regs = get_absolute_expression ();
4615 if (*input_line_pointer++ != ']')
4617 as_bad ("Expected ']'");
4618 goto err;
4620 SKIP_WHITESPACE ();
4622 num_alloced += num_regs;
4623 switch (type)
4625 case DYNREG_GR:
4626 if (num_alloced > md.rot.num_regs)
4628 as_bad ("Used more than the declared %d rotating registers",
4629 md.rot.num_regs);
4630 goto err;
4632 break;
4633 case DYNREG_FR:
4634 if (num_alloced > 96)
4636 as_bad ("Used more than the available 96 rotating registers");
4637 goto err;
4639 break;
4640 case DYNREG_PR:
4641 if (num_alloced > 48)
4643 as_bad ("Used more than the available 48 rotating registers");
4644 goto err;
4646 break;
4648 default:
4649 break;
4652 if (!*drpp)
4654 *drpp = obstack_alloc (&notes, sizeof (*dr));
4655 memset (*drpp, 0, sizeof (*dr));
4658 name = obstack_alloc (&notes, len + 1);
4659 memcpy (name, start, len);
4660 name[len] = '\0';
4662 dr = *drpp;
4663 dr->name = name;
4664 dr->num_regs = num_regs;
4665 dr->base = base_reg;
4666 drpp = &dr->next;
4667 base_reg += num_regs;
4669 if (hash_insert (md.dynreg_hash, name, dr))
4671 as_bad ("Attempt to redefine register set `%s'", name);
4672 obstack_free (&notes, name);
4673 goto err;
4676 if (*input_line_pointer != ',')
4677 break;
4678 ++input_line_pointer; /* skip comma */
4679 SKIP_WHITESPACE ();
4681 demand_empty_rest_of_line ();
4682 return;
4684 err:
4685 ignore_rest_of_line ();
4688 static void
4689 dot_byteorder (byteorder)
4690 int byteorder;
4692 segment_info_type *seginfo = seg_info (now_seg);
4694 if (byteorder == -1)
4696 if (seginfo->tc_segment_info_data.endian == 0)
4697 seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2;
4698 byteorder = seginfo->tc_segment_info_data.endian == 1;
4700 else
4701 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4703 if (target_big_endian != byteorder)
4705 target_big_endian = byteorder;
4706 if (target_big_endian)
4708 ia64_number_to_chars = number_to_chars_bigendian;
4709 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4711 else
4713 ia64_number_to_chars = number_to_chars_littleendian;
4714 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4719 static void
4720 dot_psr (dummy)
4721 int dummy ATTRIBUTE_UNUSED;
4723 char *option;
4724 int ch;
4726 while (1)
4728 option = input_line_pointer;
4729 ch = get_symbol_end ();
4730 if (strcmp (option, "lsb") == 0)
4731 md.flags &= ~EF_IA_64_BE;
4732 else if (strcmp (option, "msb") == 0)
4733 md.flags |= EF_IA_64_BE;
4734 else if (strcmp (option, "abi32") == 0)
4735 md.flags &= ~EF_IA_64_ABI64;
4736 else if (strcmp (option, "abi64") == 0)
4737 md.flags |= EF_IA_64_ABI64;
4738 else
4739 as_bad ("Unknown psr option `%s'", option);
4740 *input_line_pointer = ch;
4742 SKIP_WHITESPACE ();
4743 if (*input_line_pointer != ',')
4744 break;
4746 ++input_line_pointer;
4747 SKIP_WHITESPACE ();
4749 demand_empty_rest_of_line ();
4752 static void
4753 dot_ln (dummy)
4754 int dummy ATTRIBUTE_UNUSED;
4756 new_logical_line (0, get_absolute_expression ());
4757 demand_empty_rest_of_line ();
4760 static void
4761 cross_section (ref, cons, ua)
4762 int ref;
4763 void (*cons) PARAMS((int));
4764 int ua;
4766 char *start, *end;
4767 int saved_auto_align;
4768 unsigned int section_count;
4770 SKIP_WHITESPACE ();
4771 start = input_line_pointer;
4772 if (*start == '"')
4774 int len;
4775 char *name;
4777 name = demand_copy_C_string (&len);
4778 obstack_free(&notes, name);
4779 if (!name)
4781 ignore_rest_of_line ();
4782 return;
4785 else
4787 char c = get_symbol_end ();
4789 if (input_line_pointer == start)
4791 as_bad ("Missing section name");
4792 ignore_rest_of_line ();
4793 return;
4795 *input_line_pointer = c;
4797 end = input_line_pointer;
4798 SKIP_WHITESPACE ();
4799 if (*input_line_pointer != ',')
4801 as_bad ("Comma expected after section name");
4802 ignore_rest_of_line ();
4803 return;
4805 *end = '\0';
4806 end = input_line_pointer + 1; /* skip comma */
4807 input_line_pointer = start;
4808 md.keep_pending_output = 1;
4809 section_count = bfd_count_sections(stdoutput);
4810 obj_elf_section (0);
4811 if (section_count != bfd_count_sections(stdoutput))
4812 as_warn ("Creating sections with .xdataN/.xrealN/.xstringZ is deprecated.");
4813 input_line_pointer = end;
4814 saved_auto_align = md.auto_align;
4815 if (ua)
4816 md.auto_align = 0;
4817 (*cons) (ref);
4818 if (ua)
4819 md.auto_align = saved_auto_align;
4820 obj_elf_previous (0);
4821 md.keep_pending_output = 0;
4824 static void
4825 dot_xdata (size)
4826 int size;
4828 cross_section (size, cons, 0);
4831 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4833 static void
4834 stmt_float_cons (kind)
4835 int kind;
4837 size_t alignment;
4839 switch (kind)
4841 case 'd':
4842 alignment = 8;
4843 break;
4845 case 'x':
4846 case 'X':
4847 alignment = 16;
4848 break;
4850 case 'f':
4851 default:
4852 alignment = 4;
4853 break;
4855 ia64_do_align (alignment);
4856 float_cons (kind);
4859 static void
4860 stmt_cons_ua (size)
4861 int size;
4863 int saved_auto_align = md.auto_align;
4865 md.auto_align = 0;
4866 cons (size);
4867 md.auto_align = saved_auto_align;
4870 static void
4871 dot_xfloat_cons (kind)
4872 int kind;
4874 cross_section (kind, stmt_float_cons, 0);
4877 static void
4878 dot_xstringer (zero)
4879 int zero;
4881 cross_section (zero, stringer, 0);
4884 static void
4885 dot_xdata_ua (size)
4886 int size;
4888 cross_section (size, cons, 1);
4891 static void
4892 dot_xfloat_cons_ua (kind)
4893 int kind;
4895 cross_section (kind, float_cons, 1);
4898 /* .reg.val <regname>,value */
4900 static void
4901 dot_reg_val (dummy)
4902 int dummy ATTRIBUTE_UNUSED;
4904 expressionS reg;
4906 expression (&reg);
4907 if (reg.X_op != O_register)
4909 as_bad (_("Register name expected"));
4910 ignore_rest_of_line ();
4912 else if (*input_line_pointer++ != ',')
4914 as_bad (_("Comma expected"));
4915 ignore_rest_of_line ();
4917 else
4919 valueT value = get_absolute_expression ();
4920 int regno = reg.X_add_number;
4921 if (regno <= REG_GR || regno > REG_GR + 127)
4922 as_warn (_("Register value annotation ignored"));
4923 else
4925 gr_values[regno - REG_GR].known = 1;
4926 gr_values[regno - REG_GR].value = value;
4927 gr_values[regno - REG_GR].path = md.path;
4930 demand_empty_rest_of_line ();
4934 .serialize.data
4935 .serialize.instruction
4937 static void
4938 dot_serialize (type)
4939 int type;
4941 insn_group_break (0, 0, 0);
4942 if (type)
4943 instruction_serialization ();
4944 else
4945 data_serialization ();
4946 insn_group_break (0, 0, 0);
4947 demand_empty_rest_of_line ();
4950 /* select dv checking mode
4951 .auto
4952 .explicit
4953 .default
4955 A stop is inserted when changing modes
4958 static void
4959 dot_dv_mode (type)
4960 int type;
4962 if (md.manual_bundling)
4963 as_warn (_("Directive invalid within a bundle"));
4965 if (type == 'E' || type == 'A')
4966 md.mode_explicitly_set = 0;
4967 else
4968 md.mode_explicitly_set = 1;
4970 md.detect_dv = 1;
4971 switch (type)
4973 case 'A':
4974 case 'a':
4975 if (md.explicit_mode)
4976 insn_group_break (1, 0, 0);
4977 md.explicit_mode = 0;
4978 break;
4979 case 'E':
4980 case 'e':
4981 if (!md.explicit_mode)
4982 insn_group_break (1, 0, 0);
4983 md.explicit_mode = 1;
4984 break;
4985 default:
4986 case 'd':
4987 if (md.explicit_mode != md.default_explicit_mode)
4988 insn_group_break (1, 0, 0);
4989 md.explicit_mode = md.default_explicit_mode;
4990 md.mode_explicitly_set = 0;
4991 break;
4995 static void
4996 print_prmask (mask)
4997 valueT mask;
4999 int regno;
5000 char *comma = "";
5001 for (regno = 0; regno < 64; regno++)
5003 if (mask & ((valueT) 1 << regno))
5005 fprintf (stderr, "%s p%d", comma, regno);
5006 comma = ",";
5012 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear)
5013 .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply)
5014 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex)
5015 .pred.safe_across_calls p1 [, p2 [,...]]
5018 static void
5019 dot_pred_rel (type)
5020 int type;
5022 valueT mask = 0;
5023 int count = 0;
5024 int p1 = -1, p2 = -1;
5026 if (type == 0)
5028 if (*input_line_pointer == '"')
5030 int len;
5031 char *form = demand_copy_C_string (&len);
5033 if (strcmp (form, "mutex") == 0)
5034 type = 'm';
5035 else if (strcmp (form, "clear") == 0)
5036 type = 'c';
5037 else if (strcmp (form, "imply") == 0)
5038 type = 'i';
5039 obstack_free (&notes, form);
5041 else if (*input_line_pointer == '@')
5043 char *form = ++input_line_pointer;
5044 char c = get_symbol_end();
5046 if (strcmp (form, "mutex") == 0)
5047 type = 'm';
5048 else if (strcmp (form, "clear") == 0)
5049 type = 'c';
5050 else if (strcmp (form, "imply") == 0)
5051 type = 'i';
5052 *input_line_pointer = c;
5054 else
5056 as_bad (_("Missing predicate relation type"));
5057 ignore_rest_of_line ();
5058 return;
5060 if (type == 0)
5062 as_bad (_("Unrecognized predicate relation type"));
5063 ignore_rest_of_line ();
5064 return;
5066 if (*input_line_pointer == ',')
5067 ++input_line_pointer;
5068 SKIP_WHITESPACE ();
5071 SKIP_WHITESPACE ();
5072 while (1)
5074 valueT bits = 1;
5075 int regno;
5076 expressionS pr, *pr1, *pr2;
5078 expression (&pr);
5079 if (pr.X_op == O_register
5080 && pr.X_add_number >= REG_P
5081 && pr.X_add_number <= REG_P + 63)
5083 regno = pr.X_add_number - REG_P;
5084 bits <<= regno;
5085 count++;
5086 if (p1 == -1)
5087 p1 = regno;
5088 else if (p2 == -1)
5089 p2 = regno;
5091 else if (type != 'i'
5092 && pr.X_op == O_subtract
5093 && (pr1 = symbol_get_value_expression (pr.X_add_symbol))
5094 && pr1->X_op == O_register
5095 && pr1->X_add_number >= REG_P
5096 && pr1->X_add_number <= REG_P + 63
5097 && (pr2 = symbol_get_value_expression (pr.X_op_symbol))
5098 && pr2->X_op == O_register
5099 && pr2->X_add_number >= REG_P
5100 && pr2->X_add_number <= REG_P + 63)
5102 /* It's a range. */
5103 int stop;
5105 regno = pr1->X_add_number - REG_P;
5106 stop = pr2->X_add_number - REG_P;
5107 if (regno >= stop)
5109 as_bad (_("Bad register range"));
5110 ignore_rest_of_line ();
5111 return;
5113 bits = ((bits << stop) << 1) - (bits << regno);
5114 count += stop - regno + 1;
5116 else
5118 as_bad (_("Predicate register expected"));
5119 ignore_rest_of_line ();
5120 return;
5122 if (mask & bits)
5123 as_warn (_("Duplicate predicate register ignored"));
5124 mask |= bits;
5125 if (*input_line_pointer != ',')
5126 break;
5127 ++input_line_pointer;
5128 SKIP_WHITESPACE ();
5131 switch (type)
5133 case 'c':
5134 if (count == 0)
5135 mask = ~(valueT) 0;
5136 clear_qp_mutex (mask);
5137 clear_qp_implies (mask, (valueT) 0);
5138 break;
5139 case 'i':
5140 if (count != 2 || p1 == -1 || p2 == -1)
5141 as_bad (_("Predicate source and target required"));
5142 else if (p1 == 0 || p2 == 0)
5143 as_bad (_("Use of p0 is not valid in this context"));
5144 else
5145 add_qp_imply (p1, p2);
5146 break;
5147 case 'm':
5148 if (count < 2)
5150 as_bad (_("At least two PR arguments expected"));
5151 break;
5153 else if (mask & 1)
5155 as_bad (_("Use of p0 is not valid in this context"));
5156 break;
5158 add_qp_mutex (mask);
5159 break;
5160 case 's':
5161 /* note that we don't override any existing relations */
5162 if (count == 0)
5164 as_bad (_("At least one PR argument expected"));
5165 break;
5167 if (md.debug_dv)
5169 fprintf (stderr, "Safe across calls: ");
5170 print_prmask (mask);
5171 fprintf (stderr, "\n");
5173 qp_safe_across_calls = mask;
5174 break;
5176 demand_empty_rest_of_line ();
5179 /* .entry label [, label [, ...]]
5180 Hint to DV code that the given labels are to be considered entry points.
5181 Otherwise, only global labels are considered entry points. */
5183 static void
5184 dot_entry (dummy)
5185 int dummy ATTRIBUTE_UNUSED;
5187 const char *err;
5188 char *name;
5189 int c;
5190 symbolS *symbolP;
5194 name = input_line_pointer;
5195 c = get_symbol_end ();
5196 symbolP = symbol_find_or_make (name);
5198 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
5199 if (err)
5200 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
5201 name, err);
5203 *input_line_pointer = c;
5204 SKIP_WHITESPACE ();
5205 c = *input_line_pointer;
5206 if (c == ',')
5208 input_line_pointer++;
5209 SKIP_WHITESPACE ();
5210 if (*input_line_pointer == '\n')
5211 c = '\n';
5214 while (c == ',');
5216 demand_empty_rest_of_line ();
5219 /* .mem.offset offset, base
5220 "base" is used to distinguish between offsets from a different base. */
5222 static void
5223 dot_mem_offset (dummy)
5224 int dummy ATTRIBUTE_UNUSED;
5226 md.mem_offset.hint = 1;
5227 md.mem_offset.offset = get_absolute_expression ();
5228 if (*input_line_pointer != ',')
5230 as_bad (_("Comma expected"));
5231 ignore_rest_of_line ();
5232 return;
5234 ++input_line_pointer;
5235 md.mem_offset.base = get_absolute_expression ();
5236 demand_empty_rest_of_line ();
5239 /* ia64-specific pseudo-ops: */
5240 const pseudo_typeS md_pseudo_table[] =
5242 { "radix", dot_radix, 0 },
5243 { "lcomm", s_lcomm_bytes, 1 },
5244 { "loc", dot_loc, 0 },
5245 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
5246 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
5247 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
5248 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
5249 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
5250 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
5251 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
5252 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
5253 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
5254 { "proc", dot_proc, 0 },
5255 { "body", dot_body, 0 },
5256 { "prologue", dot_prologue, 0 },
5257 { "endp", dot_endp, 0 },
5259 { "fframe", dot_fframe, 0 },
5260 { "vframe", dot_vframe, 0 },
5261 { "vframesp", dot_vframesp, 0 },
5262 { "vframepsp", dot_vframepsp, 0 },
5263 { "save", dot_save, 0 },
5264 { "restore", dot_restore, 0 },
5265 { "restorereg", dot_restorereg, 0 },
5266 { "restorereg.p", dot_restorereg_p, 0 },
5267 { "handlerdata", dot_handlerdata, 0 },
5268 { "unwentry", dot_unwentry, 0 },
5269 { "altrp", dot_altrp, 0 },
5270 { "savesp", dot_savemem, 0 },
5271 { "savepsp", dot_savemem, 1 },
5272 { "save.g", dot_saveg, 0 },
5273 { "save.f", dot_savef, 0 },
5274 { "save.b", dot_saveb, 0 },
5275 { "save.gf", dot_savegf, 0 },
5276 { "spill", dot_spill, 0 },
5277 { "spillreg", dot_spillreg, 0 },
5278 { "spillsp", dot_spillmem, 0 },
5279 { "spillpsp", dot_spillmem, 1 },
5280 { "spillreg.p", dot_spillreg_p, 0 },
5281 { "spillsp.p", dot_spillmem_p, 0 },
5282 { "spillpsp.p", dot_spillmem_p, 1 },
5283 { "label_state", dot_label_state, 0 },
5284 { "copy_state", dot_copy_state, 0 },
5285 { "unwabi", dot_unwabi, 0 },
5286 { "personality", dot_personality, 0 },
5287 { "mii", dot_template, 0x0 },
5288 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5289 { "mlx", dot_template, 0x2 },
5290 { "mmi", dot_template, 0x4 },
5291 { "mfi", dot_template, 0x6 },
5292 { "mmf", dot_template, 0x7 },
5293 { "mib", dot_template, 0x8 },
5294 { "mbb", dot_template, 0x9 },
5295 { "bbb", dot_template, 0xb },
5296 { "mmb", dot_template, 0xc },
5297 { "mfb", dot_template, 0xe },
5298 { "align", dot_align, 0 },
5299 { "regstk", dot_regstk, 0 },
5300 { "rotr", dot_rot, DYNREG_GR },
5301 { "rotf", dot_rot, DYNREG_FR },
5302 { "rotp", dot_rot, DYNREG_PR },
5303 { "lsb", dot_byteorder, 0 },
5304 { "msb", dot_byteorder, 1 },
5305 { "psr", dot_psr, 0 },
5306 { "alias", dot_alias, 0 },
5307 { "secalias", dot_alias, 1 },
5308 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5310 { "xdata1", dot_xdata, 1 },
5311 { "xdata2", dot_xdata, 2 },
5312 { "xdata4", dot_xdata, 4 },
5313 { "xdata8", dot_xdata, 8 },
5314 { "xdata16", dot_xdata, 16 },
5315 { "xreal4", dot_xfloat_cons, 'f' },
5316 { "xreal8", dot_xfloat_cons, 'd' },
5317 { "xreal10", dot_xfloat_cons, 'x' },
5318 { "xreal16", dot_xfloat_cons, 'X' },
5319 { "xstring", dot_xstringer, 0 },
5320 { "xstringz", dot_xstringer, 1 },
5322 /* unaligned versions: */
5323 { "xdata2.ua", dot_xdata_ua, 2 },
5324 { "xdata4.ua", dot_xdata_ua, 4 },
5325 { "xdata8.ua", dot_xdata_ua, 8 },
5326 { "xdata16.ua", dot_xdata_ua, 16 },
5327 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5328 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5329 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5330 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5332 /* annotations/DV checking support */
5333 { "entry", dot_entry, 0 },
5334 { "mem.offset", dot_mem_offset, 0 },
5335 { "pred.rel", dot_pred_rel, 0 },
5336 { "pred.rel.clear", dot_pred_rel, 'c' },
5337 { "pred.rel.imply", dot_pred_rel, 'i' },
5338 { "pred.rel.mutex", dot_pred_rel, 'm' },
5339 { "pred.safe_across_calls", dot_pred_rel, 's' },
5340 { "reg.val", dot_reg_val, 0 },
5341 { "serialize.data", dot_serialize, 0 },
5342 { "serialize.instruction", dot_serialize, 1 },
5343 { "auto", dot_dv_mode, 'a' },
5344 { "explicit", dot_dv_mode, 'e' },
5345 { "default", dot_dv_mode, 'd' },
5347 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5348 IA-64 aligns data allocation pseudo-ops by default, so we have to
5349 tell it that these ones are supposed to be unaligned. Long term,
5350 should rewrite so that only IA-64 specific data allocation pseudo-ops
5351 are aligned by default. */
5352 {"2byte", stmt_cons_ua, 2},
5353 {"4byte", stmt_cons_ua, 4},
5354 {"8byte", stmt_cons_ua, 8},
5356 { NULL, 0, 0 }
5359 static const struct pseudo_opcode
5361 const char *name;
5362 void (*handler) (int);
5363 int arg;
5365 pseudo_opcode[] =
5367 /* these are more like pseudo-ops, but don't start with a dot */
5368 { "data1", cons, 1 },
5369 { "data2", cons, 2 },
5370 { "data4", cons, 4 },
5371 { "data8", cons, 8 },
5372 { "data16", cons, 16 },
5373 { "real4", stmt_float_cons, 'f' },
5374 { "real8", stmt_float_cons, 'd' },
5375 { "real10", stmt_float_cons, 'x' },
5376 { "real16", stmt_float_cons, 'X' },
5377 { "string", stringer, 0 },
5378 { "stringz", stringer, 1 },
5380 /* unaligned versions: */
5381 { "data2.ua", stmt_cons_ua, 2 },
5382 { "data4.ua", stmt_cons_ua, 4 },
5383 { "data8.ua", stmt_cons_ua, 8 },
5384 { "data16.ua", stmt_cons_ua, 16 },
5385 { "real4.ua", float_cons, 'f' },
5386 { "real8.ua", float_cons, 'd' },
5387 { "real10.ua", float_cons, 'x' },
5388 { "real16.ua", float_cons, 'X' },
5391 /* Declare a register by creating a symbol for it and entering it in
5392 the symbol table. */
5394 static symbolS *
5395 declare_register (name, regnum)
5396 const char *name;
5397 int regnum;
5399 const char *err;
5400 symbolS *sym;
5402 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5404 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5405 if (err)
5406 as_fatal ("Inserting \"%s\" into register table failed: %s",
5407 name, err);
5409 return sym;
5412 static void
5413 declare_register_set (prefix, num_regs, base_regnum)
5414 const char *prefix;
5415 int num_regs;
5416 int base_regnum;
5418 char name[8];
5419 int i;
5421 for (i = 0; i < num_regs; ++i)
5423 sprintf (name, "%s%u", prefix, i);
5424 declare_register (name, base_regnum + i);
5428 static unsigned int
5429 operand_width (opnd)
5430 enum ia64_opnd opnd;
5432 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5433 unsigned int bits = 0;
5434 int i;
5436 bits = 0;
5437 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5438 bits += odesc->field[i].bits;
5440 return bits;
5443 static enum operand_match_result
5444 operand_match (idesc, index, e)
5445 const struct ia64_opcode *idesc;
5446 int index;
5447 expressionS *e;
5449 enum ia64_opnd opnd = idesc->operands[index];
5450 int bits, relocatable = 0;
5451 struct insn_fix *fix;
5452 bfd_signed_vma val;
5454 switch (opnd)
5456 /* constants: */
5458 case IA64_OPND_AR_CCV:
5459 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5460 return OPERAND_MATCH;
5461 break;
5463 case IA64_OPND_AR_CSD:
5464 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5465 return OPERAND_MATCH;
5466 break;
5468 case IA64_OPND_AR_PFS:
5469 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5470 return OPERAND_MATCH;
5471 break;
5473 case IA64_OPND_GR0:
5474 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5475 return OPERAND_MATCH;
5476 break;
5478 case IA64_OPND_IP:
5479 if (e->X_op == O_register && e->X_add_number == REG_IP)
5480 return OPERAND_MATCH;
5481 break;
5483 case IA64_OPND_PR:
5484 if (e->X_op == O_register && e->X_add_number == REG_PR)
5485 return OPERAND_MATCH;
5486 break;
5488 case IA64_OPND_PR_ROT:
5489 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5490 return OPERAND_MATCH;
5491 break;
5493 case IA64_OPND_PSR:
5494 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5495 return OPERAND_MATCH;
5496 break;
5498 case IA64_OPND_PSR_L:
5499 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5500 return OPERAND_MATCH;
5501 break;
5503 case IA64_OPND_PSR_UM:
5504 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5505 return OPERAND_MATCH;
5506 break;
5508 case IA64_OPND_C1:
5509 if (e->X_op == O_constant)
5511 if (e->X_add_number == 1)
5512 return OPERAND_MATCH;
5513 else
5514 return OPERAND_OUT_OF_RANGE;
5516 break;
5518 case IA64_OPND_C8:
5519 if (e->X_op == O_constant)
5521 if (e->X_add_number == 8)
5522 return OPERAND_MATCH;
5523 else
5524 return OPERAND_OUT_OF_RANGE;
5526 break;
5528 case IA64_OPND_C16:
5529 if (e->X_op == O_constant)
5531 if (e->X_add_number == 16)
5532 return OPERAND_MATCH;
5533 else
5534 return OPERAND_OUT_OF_RANGE;
5536 break;
5538 /* register operands: */
5540 case IA64_OPND_AR3:
5541 if (e->X_op == O_register && e->X_add_number >= REG_AR
5542 && e->X_add_number < REG_AR + 128)
5543 return OPERAND_MATCH;
5544 break;
5546 case IA64_OPND_B1:
5547 case IA64_OPND_B2:
5548 if (e->X_op == O_register && e->X_add_number >= REG_BR
5549 && e->X_add_number < REG_BR + 8)
5550 return OPERAND_MATCH;
5551 break;
5553 case IA64_OPND_CR3:
5554 if (e->X_op == O_register && e->X_add_number >= REG_CR
5555 && e->X_add_number < REG_CR + 128)
5556 return OPERAND_MATCH;
5557 break;
5559 case IA64_OPND_F1:
5560 case IA64_OPND_F2:
5561 case IA64_OPND_F3:
5562 case IA64_OPND_F4:
5563 if (e->X_op == O_register && e->X_add_number >= REG_FR
5564 && e->X_add_number < REG_FR + 128)
5565 return OPERAND_MATCH;
5566 break;
5568 case IA64_OPND_P1:
5569 case IA64_OPND_P2:
5570 if (e->X_op == O_register && e->X_add_number >= REG_P
5571 && e->X_add_number < REG_P + 64)
5572 return OPERAND_MATCH;
5573 break;
5575 case IA64_OPND_R1:
5576 case IA64_OPND_R2:
5577 case IA64_OPND_R3:
5578 if (e->X_op == O_register && e->X_add_number >= REG_GR
5579 && e->X_add_number < REG_GR + 128)
5580 return OPERAND_MATCH;
5581 break;
5583 case IA64_OPND_R3_2:
5584 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5586 if (e->X_add_number < REG_GR + 4)
5587 return OPERAND_MATCH;
5588 else if (e->X_add_number < REG_GR + 128)
5589 return OPERAND_OUT_OF_RANGE;
5591 break;
5593 /* indirect operands: */
5594 case IA64_OPND_CPUID_R3:
5595 case IA64_OPND_DBR_R3:
5596 case IA64_OPND_DTR_R3:
5597 case IA64_OPND_ITR_R3:
5598 case IA64_OPND_IBR_R3:
5599 case IA64_OPND_MSR_R3:
5600 case IA64_OPND_PKR_R3:
5601 case IA64_OPND_PMC_R3:
5602 case IA64_OPND_PMD_R3:
5603 case IA64_OPND_RR_R3:
5604 if (e->X_op == O_index && e->X_op_symbol
5605 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5606 == opnd - IA64_OPND_CPUID_R3))
5607 return OPERAND_MATCH;
5608 break;
5610 case IA64_OPND_MR3:
5611 if (e->X_op == O_index && !e->X_op_symbol)
5612 return OPERAND_MATCH;
5613 break;
5615 /* immediate operands: */
5616 case IA64_OPND_CNT2a:
5617 case IA64_OPND_LEN4:
5618 case IA64_OPND_LEN6:
5619 bits = operand_width (idesc->operands[index]);
5620 if (e->X_op == O_constant)
5622 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5623 return OPERAND_MATCH;
5624 else
5625 return OPERAND_OUT_OF_RANGE;
5627 break;
5629 case IA64_OPND_CNT2b:
5630 if (e->X_op == O_constant)
5632 if ((bfd_vma) (e->X_add_number - 1) < 3)
5633 return OPERAND_MATCH;
5634 else
5635 return OPERAND_OUT_OF_RANGE;
5637 break;
5639 case IA64_OPND_CNT2c:
5640 val = e->X_add_number;
5641 if (e->X_op == O_constant)
5643 if ((val == 0 || val == 7 || val == 15 || val == 16))
5644 return OPERAND_MATCH;
5645 else
5646 return OPERAND_OUT_OF_RANGE;
5648 break;
5650 case IA64_OPND_SOR:
5651 /* SOR must be an integer multiple of 8 */
5652 if (e->X_op == O_constant && e->X_add_number & 0x7)
5653 return OPERAND_OUT_OF_RANGE;
5654 case IA64_OPND_SOF:
5655 case IA64_OPND_SOL:
5656 if (e->X_op == O_constant)
5658 if ((bfd_vma) e->X_add_number <= 96)
5659 return OPERAND_MATCH;
5660 else
5661 return OPERAND_OUT_OF_RANGE;
5663 break;
5665 case IA64_OPND_IMMU62:
5666 if (e->X_op == O_constant)
5668 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5669 return OPERAND_MATCH;
5670 else
5671 return OPERAND_OUT_OF_RANGE;
5673 else
5675 /* FIXME -- need 62-bit relocation type */
5676 as_bad (_("62-bit relocation not yet implemented"));
5678 break;
5680 case IA64_OPND_IMMU64:
5681 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5682 || e->X_op == O_subtract)
5684 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5685 fix->code = BFD_RELOC_IA64_IMM64;
5686 if (e->X_op != O_subtract)
5688 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5689 if (e->X_op == O_pseudo_fixup)
5690 e->X_op = O_symbol;
5693 fix->opnd = idesc->operands[index];
5694 fix->expr = *e;
5695 fix->is_pcrel = 0;
5696 ++CURR_SLOT.num_fixups;
5697 return OPERAND_MATCH;
5699 else if (e->X_op == O_constant)
5700 return OPERAND_MATCH;
5701 break;
5703 case IA64_OPND_CCNT5:
5704 case IA64_OPND_CNT5:
5705 case IA64_OPND_CNT6:
5706 case IA64_OPND_CPOS6a:
5707 case IA64_OPND_CPOS6b:
5708 case IA64_OPND_CPOS6c:
5709 case IA64_OPND_IMMU2:
5710 case IA64_OPND_IMMU7a:
5711 case IA64_OPND_IMMU7b:
5712 case IA64_OPND_IMMU21:
5713 case IA64_OPND_IMMU24:
5714 case IA64_OPND_MBTYPE4:
5715 case IA64_OPND_MHTYPE8:
5716 case IA64_OPND_POS6:
5717 bits = operand_width (idesc->operands[index]);
5718 if (e->X_op == O_constant)
5720 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5721 return OPERAND_MATCH;
5722 else
5723 return OPERAND_OUT_OF_RANGE;
5725 break;
5727 case IA64_OPND_IMMU9:
5728 bits = operand_width (idesc->operands[index]);
5729 if (e->X_op == O_constant)
5731 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5733 int lobits = e->X_add_number & 0x3;
5734 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5735 e->X_add_number |= (bfd_vma) 0x3;
5736 return OPERAND_MATCH;
5738 else
5739 return OPERAND_OUT_OF_RANGE;
5741 break;
5743 case IA64_OPND_IMM44:
5744 /* least 16 bits must be zero */
5745 if ((e->X_add_number & 0xffff) != 0)
5746 /* XXX technically, this is wrong: we should not be issuing warning
5747 messages until we're sure this instruction pattern is going to
5748 be used! */
5749 as_warn (_("lower 16 bits of mask ignored"));
5751 if (e->X_op == O_constant)
5753 if (((e->X_add_number >= 0
5754 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5755 || (e->X_add_number < 0
5756 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5758 /* sign-extend */
5759 if (e->X_add_number >= 0
5760 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5762 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5764 return OPERAND_MATCH;
5766 else
5767 return OPERAND_OUT_OF_RANGE;
5769 break;
5771 case IA64_OPND_IMM17:
5772 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5773 if (e->X_op == O_constant)
5775 if (((e->X_add_number >= 0
5776 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5777 || (e->X_add_number < 0
5778 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5780 /* sign-extend */
5781 if (e->X_add_number >= 0
5782 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5784 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5786 return OPERAND_MATCH;
5788 else
5789 return OPERAND_OUT_OF_RANGE;
5791 break;
5793 case IA64_OPND_IMM14:
5794 case IA64_OPND_IMM22:
5795 relocatable = 1;
5796 case IA64_OPND_IMM1:
5797 case IA64_OPND_IMM8:
5798 case IA64_OPND_IMM8U4:
5799 case IA64_OPND_IMM8M1:
5800 case IA64_OPND_IMM8M1U4:
5801 case IA64_OPND_IMM8M1U8:
5802 case IA64_OPND_IMM9a:
5803 case IA64_OPND_IMM9b:
5804 bits = operand_width (idesc->operands[index]);
5805 if (relocatable && (e->X_op == O_symbol
5806 || e->X_op == O_subtract
5807 || e->X_op == O_pseudo_fixup))
5809 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5811 if (idesc->operands[index] == IA64_OPND_IMM14)
5812 fix->code = BFD_RELOC_IA64_IMM14;
5813 else
5814 fix->code = BFD_RELOC_IA64_IMM22;
5816 if (e->X_op != O_subtract)
5818 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5819 if (e->X_op == O_pseudo_fixup)
5820 e->X_op = O_symbol;
5823 fix->opnd = idesc->operands[index];
5824 fix->expr = *e;
5825 fix->is_pcrel = 0;
5826 ++CURR_SLOT.num_fixups;
5827 return OPERAND_MATCH;
5829 else if (e->X_op != O_constant
5830 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5831 return OPERAND_MISMATCH;
5833 if (opnd == IA64_OPND_IMM8M1U4)
5835 /* Zero is not valid for unsigned compares that take an adjusted
5836 constant immediate range. */
5837 if (e->X_add_number == 0)
5838 return OPERAND_OUT_OF_RANGE;
5840 /* Sign-extend 32-bit unsigned numbers, so that the following range
5841 checks will work. */
5842 val = e->X_add_number;
5843 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5844 && ((val & ((bfd_vma) 1 << 31)) != 0))
5845 val = ((val << 32) >> 32);
5847 /* Check for 0x100000000. This is valid because
5848 0x100000000-1 is the same as ((uint32_t) -1). */
5849 if (val == ((bfd_signed_vma) 1 << 32))
5850 return OPERAND_MATCH;
5852 val = val - 1;
5854 else if (opnd == IA64_OPND_IMM8M1U8)
5856 /* Zero is not valid for unsigned compares that take an adjusted
5857 constant immediate range. */
5858 if (e->X_add_number == 0)
5859 return OPERAND_OUT_OF_RANGE;
5861 /* Check for 0x10000000000000000. */
5862 if (e->X_op == O_big)
5864 if (generic_bignum[0] == 0
5865 && generic_bignum[1] == 0
5866 && generic_bignum[2] == 0
5867 && generic_bignum[3] == 0
5868 && generic_bignum[4] == 1)
5869 return OPERAND_MATCH;
5870 else
5871 return OPERAND_OUT_OF_RANGE;
5873 else
5874 val = e->X_add_number - 1;
5876 else if (opnd == IA64_OPND_IMM8M1)
5877 val = e->X_add_number - 1;
5878 else if (opnd == IA64_OPND_IMM8U4)
5880 /* Sign-extend 32-bit unsigned numbers, so that the following range
5881 checks will work. */
5882 val = e->X_add_number;
5883 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5884 && ((val & ((bfd_vma) 1 << 31)) != 0))
5885 val = ((val << 32) >> 32);
5887 else
5888 val = e->X_add_number;
5890 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5891 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5892 return OPERAND_MATCH;
5893 else
5894 return OPERAND_OUT_OF_RANGE;
5896 case IA64_OPND_INC3:
5897 /* +/- 1, 4, 8, 16 */
5898 val = e->X_add_number;
5899 if (val < 0)
5900 val = -val;
5901 if (e->X_op == O_constant)
5903 if ((val == 1 || val == 4 || val == 8 || val == 16))
5904 return OPERAND_MATCH;
5905 else
5906 return OPERAND_OUT_OF_RANGE;
5908 break;
5910 case IA64_OPND_TGT25:
5911 case IA64_OPND_TGT25b:
5912 case IA64_OPND_TGT25c:
5913 case IA64_OPND_TGT64:
5914 if (e->X_op == O_symbol)
5916 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5917 if (opnd == IA64_OPND_TGT25)
5918 fix->code = BFD_RELOC_IA64_PCREL21F;
5919 else if (opnd == IA64_OPND_TGT25b)
5920 fix->code = BFD_RELOC_IA64_PCREL21M;
5921 else if (opnd == IA64_OPND_TGT25c)
5922 fix->code = BFD_RELOC_IA64_PCREL21B;
5923 else if (opnd == IA64_OPND_TGT64)
5924 fix->code = BFD_RELOC_IA64_PCREL60B;
5925 else
5926 abort ();
5928 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5929 fix->opnd = idesc->operands[index];
5930 fix->expr = *e;
5931 fix->is_pcrel = 1;
5932 ++CURR_SLOT.num_fixups;
5933 return OPERAND_MATCH;
5935 case IA64_OPND_TAG13:
5936 case IA64_OPND_TAG13b:
5937 switch (e->X_op)
5939 case O_constant:
5940 return OPERAND_MATCH;
5942 case O_symbol:
5943 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5944 /* There are no external relocs for TAG13/TAG13b fields, so we
5945 create a dummy reloc. This will not live past md_apply_fix3. */
5946 fix->code = BFD_RELOC_UNUSED;
5947 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5948 fix->opnd = idesc->operands[index];
5949 fix->expr = *e;
5950 fix->is_pcrel = 1;
5951 ++CURR_SLOT.num_fixups;
5952 return OPERAND_MATCH;
5954 default:
5955 break;
5957 break;
5959 case IA64_OPND_LDXMOV:
5960 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5961 fix->code = BFD_RELOC_IA64_LDXMOV;
5962 fix->opnd = idesc->operands[index];
5963 fix->expr = *e;
5964 fix->is_pcrel = 0;
5965 ++CURR_SLOT.num_fixups;
5966 return OPERAND_MATCH;
5968 default:
5969 break;
5971 return OPERAND_MISMATCH;
5974 static int
5975 parse_operand (e)
5976 expressionS *e;
5978 int sep = '\0';
5980 memset (e, 0, sizeof (*e));
5981 e->X_op = O_absent;
5982 SKIP_WHITESPACE ();
5983 if (*input_line_pointer != '}')
5984 expression (e);
5985 sep = *input_line_pointer++;
5987 if (sep == '}')
5989 if (!md.manual_bundling)
5990 as_warn ("Found '}' when manual bundling is off");
5991 else
5992 CURR_SLOT.manual_bundling_off = 1;
5993 md.manual_bundling = 0;
5994 sep = '\0';
5996 return sep;
5999 /* Returns the next entry in the opcode table that matches the one in
6000 IDESC, and frees the entry in IDESC. If no matching entry is
6001 found, NULL is returned instead. */
6003 static struct ia64_opcode *
6004 get_next_opcode (struct ia64_opcode *idesc)
6006 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
6007 ia64_free_opcode (idesc);
6008 return next;
6011 /* Parse the operands for the opcode and find the opcode variant that
6012 matches the specified operands, or NULL if no match is possible. */
6014 static struct ia64_opcode *
6015 parse_operands (idesc)
6016 struct ia64_opcode *idesc;
6018 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
6019 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
6020 int reg1, reg2;
6021 char reg_class;
6022 enum ia64_opnd expected_operand = IA64_OPND_NIL;
6023 enum operand_match_result result;
6024 char mnemonic[129];
6025 char *first_arg = 0, *end, *saved_input_pointer;
6026 unsigned int sof;
6028 assert (strlen (idesc->name) <= 128);
6030 strcpy (mnemonic, idesc->name);
6031 if (idesc->operands[2] == IA64_OPND_SOF
6032 || idesc->operands[1] == IA64_OPND_SOF)
6034 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
6035 can't parse the first operand until we have parsed the
6036 remaining operands of the "alloc" instruction. */
6037 SKIP_WHITESPACE ();
6038 first_arg = input_line_pointer;
6039 end = strchr (input_line_pointer, '=');
6040 if (!end)
6042 as_bad ("Expected separator `='");
6043 return 0;
6045 input_line_pointer = end + 1;
6046 ++i;
6047 ++num_outputs;
6050 for (; ; ++i)
6052 if (i < NELEMS (CURR_SLOT.opnd))
6054 sep = parse_operand (CURR_SLOT.opnd + i);
6055 if (CURR_SLOT.opnd[i].X_op == O_absent)
6056 break;
6058 else
6060 expressionS dummy;
6062 sep = parse_operand (&dummy);
6063 if (dummy.X_op == O_absent)
6064 break;
6067 ++num_operands;
6069 if (sep != '=' && sep != ',')
6070 break;
6072 if (sep == '=')
6074 if (num_outputs > 0)
6075 as_bad ("Duplicate equal sign (=) in instruction");
6076 else
6077 num_outputs = i + 1;
6080 if (sep != '\0')
6082 as_bad ("Illegal operand separator `%c'", sep);
6083 return 0;
6086 if (idesc->operands[2] == IA64_OPND_SOF
6087 || idesc->operands[1] == IA64_OPND_SOF)
6089 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
6090 know (strcmp (idesc->name, "alloc") == 0);
6091 i = (CURR_SLOT.opnd[1].X_op == O_register
6092 && CURR_SLOT.opnd[1].X_add_number == REG_AR + AR_PFS) ? 2 : 1;
6093 if (num_operands == i + 3 /* first_arg not included in this count! */
6094 && CURR_SLOT.opnd[i].X_op == O_constant
6095 && CURR_SLOT.opnd[i + 1].X_op == O_constant
6096 && CURR_SLOT.opnd[i + 2].X_op == O_constant
6097 && CURR_SLOT.opnd[i + 3].X_op == O_constant)
6099 sof = set_regstack (CURR_SLOT.opnd[i].X_add_number,
6100 CURR_SLOT.opnd[i + 1].X_add_number,
6101 CURR_SLOT.opnd[i + 2].X_add_number,
6102 CURR_SLOT.opnd[i + 3].X_add_number);
6104 /* now we can parse the first arg: */
6105 saved_input_pointer = input_line_pointer;
6106 input_line_pointer = first_arg;
6107 sep = parse_operand (CURR_SLOT.opnd + 0);
6108 if (sep != '=')
6109 --num_outputs; /* force error */
6110 input_line_pointer = saved_input_pointer;
6112 CURR_SLOT.opnd[i].X_add_number = sof;
6113 CURR_SLOT.opnd[i + 1].X_add_number
6114 = sof - CURR_SLOT.opnd[i + 2].X_add_number;
6115 CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3];
6119 highest_unmatched_operand = -4;
6120 curr_out_of_range_pos = -1;
6121 error_pos = 0;
6122 for (; idesc; idesc = get_next_opcode (idesc))
6124 if (num_outputs != idesc->num_outputs)
6125 continue; /* mismatch in # of outputs */
6126 if (highest_unmatched_operand < 0)
6127 highest_unmatched_operand |= 1;
6128 if (num_operands > NELEMS (idesc->operands)
6129 || (num_operands < NELEMS (idesc->operands)
6130 && idesc->operands[num_operands])
6131 || (num_operands > 0 && !idesc->operands[num_operands - 1]))
6132 continue; /* mismatch in number of arguments */
6133 if (highest_unmatched_operand < 0)
6134 highest_unmatched_operand |= 2;
6136 CURR_SLOT.num_fixups = 0;
6138 /* Try to match all operands. If we see an out-of-range operand,
6139 then continue trying to match the rest of the operands, since if
6140 the rest match, then this idesc will give the best error message. */
6142 out_of_range_pos = -1;
6143 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
6145 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
6146 if (result != OPERAND_MATCH)
6148 if (result != OPERAND_OUT_OF_RANGE)
6149 break;
6150 if (out_of_range_pos < 0)
6151 /* remember position of the first out-of-range operand: */
6152 out_of_range_pos = i;
6156 /* If we did not match all operands, or if at least one operand was
6157 out-of-range, then this idesc does not match. Keep track of which
6158 idesc matched the most operands before failing. If we have two
6159 idescs that failed at the same position, and one had an out-of-range
6160 operand, then prefer the out-of-range operand. Thus if we have
6161 "add r0=0x1000000,r1" we get an error saying the constant is out
6162 of range instead of an error saying that the constant should have been
6163 a register. */
6165 if (i != num_operands || out_of_range_pos >= 0)
6167 if (i > highest_unmatched_operand
6168 || (i == highest_unmatched_operand
6169 && out_of_range_pos > curr_out_of_range_pos))
6171 highest_unmatched_operand = i;
6172 if (out_of_range_pos >= 0)
6174 expected_operand = idesc->operands[out_of_range_pos];
6175 error_pos = out_of_range_pos;
6177 else
6179 expected_operand = idesc->operands[i];
6180 error_pos = i;
6182 curr_out_of_range_pos = out_of_range_pos;
6184 continue;
6187 break;
6189 if (!idesc)
6191 if (expected_operand)
6192 as_bad ("Operand %u of `%s' should be %s",
6193 error_pos + 1, mnemonic,
6194 elf64_ia64_operands[expected_operand].desc);
6195 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1))
6196 as_bad ("Wrong number of output operands");
6197 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2))
6198 as_bad ("Wrong number of input operands");
6199 else
6200 as_bad ("Operand mismatch");
6201 return 0;
6204 /* Check that the instruction doesn't use
6205 - r0, f0, or f1 as output operands
6206 - the same predicate twice as output operands
6207 - r0 as address of a base update load or store
6208 - the same GR as output and address of a base update load
6209 - two even- or two odd-numbered FRs as output operands of a floating
6210 point parallel load.
6211 At most two (conflicting) output (or output-like) operands can exist,
6212 (floating point parallel loads have three outputs, but the base register,
6213 if updated, cannot conflict with the actual outputs). */
6214 reg2 = reg1 = -1;
6215 for (i = 0; i < num_operands; ++i)
6217 int regno = 0;
6219 reg_class = 0;
6220 switch (idesc->operands[i])
6222 case IA64_OPND_R1:
6223 case IA64_OPND_R2:
6224 case IA64_OPND_R3:
6225 if (i < num_outputs)
6227 if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6228 reg_class = 'r';
6229 else if (reg1 < 0)
6230 reg1 = CURR_SLOT.opnd[i].X_add_number;
6231 else if (reg2 < 0)
6232 reg2 = CURR_SLOT.opnd[i].X_add_number;
6234 break;
6235 case IA64_OPND_P1:
6236 case IA64_OPND_P2:
6237 if (i < num_outputs)
6239 if (reg1 < 0)
6240 reg1 = CURR_SLOT.opnd[i].X_add_number;
6241 else if (reg2 < 0)
6242 reg2 = CURR_SLOT.opnd[i].X_add_number;
6244 break;
6245 case IA64_OPND_F1:
6246 case IA64_OPND_F2:
6247 case IA64_OPND_F3:
6248 case IA64_OPND_F4:
6249 if (i < num_outputs)
6251 if (CURR_SLOT.opnd[i].X_add_number >= REG_FR
6252 && CURR_SLOT.opnd[i].X_add_number <= REG_FR + 1)
6254 reg_class = 'f';
6255 regno = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6257 else if (reg1 < 0)
6258 reg1 = CURR_SLOT.opnd[i].X_add_number;
6259 else if (reg2 < 0)
6260 reg2 = CURR_SLOT.opnd[i].X_add_number;
6262 break;
6263 case IA64_OPND_MR3:
6264 if (idesc->flags & IA64_OPCODE_POSTINC)
6266 if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6267 reg_class = 'm';
6268 else if (reg1 < 0)
6269 reg1 = CURR_SLOT.opnd[i].X_add_number;
6270 else if (reg2 < 0)
6271 reg2 = CURR_SLOT.opnd[i].X_add_number;
6273 break;
6274 default:
6275 break;
6277 switch (reg_class)
6279 case 0:
6280 break;
6281 default:
6282 as_warn ("Invalid use of `%c%d' as output operand", reg_class, regno);
6283 break;
6284 case 'm':
6285 as_warn ("Invalid use of `r%d' as base update address operand", regno);
6286 break;
6289 if (reg1 == reg2)
6291 if (reg1 >= REG_GR && reg1 <= REG_GR + 127)
6293 reg1 -= REG_GR;
6294 reg_class = 'r';
6296 else if (reg1 >= REG_P && reg1 <= REG_P + 63)
6298 reg1 -= REG_P;
6299 reg_class = 'p';
6301 else if (reg1 >= REG_FR && reg1 <= REG_FR + 127)
6303 reg1 -= REG_FR;
6304 reg_class = 'f';
6306 else
6307 reg_class = 0;
6308 if (reg_class)
6309 as_warn ("Invalid duplicate use of `%c%d'", reg_class, reg1);
6311 else if (((reg1 >= REG_FR && reg1 <= REG_FR + 31
6312 && reg2 >= REG_FR && reg2 <= REG_FR + 31)
6313 || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6314 && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127))
6315 && ! ((reg1 ^ reg2) & 1))
6316 as_warn ("Invalid simultaneous use of `f%d' and `f%d'",
6317 reg1 - REG_FR, reg2 - REG_FR);
6318 else if ((reg1 >= REG_FR && reg1 <= REG_FR + 31
6319 && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127)
6320 || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6321 && reg2 >= REG_FR && reg2 <= REG_FR + 31))
6322 as_warn ("Dangerous simultaneous use of `f%d' and `f%d'",
6323 reg1 - REG_FR, reg2 - REG_FR);
6324 return idesc;
6327 static void
6328 build_insn (slot, insnp)
6329 struct slot *slot;
6330 bfd_vma *insnp;
6332 const struct ia64_operand *odesc, *o2desc;
6333 struct ia64_opcode *idesc = slot->idesc;
6334 bfd_vma insn;
6335 bfd_signed_vma val;
6336 const char *err;
6337 int i;
6339 insn = idesc->opcode | slot->qp_regno;
6341 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6343 if (slot->opnd[i].X_op == O_register
6344 || slot->opnd[i].X_op == O_constant
6345 || slot->opnd[i].X_op == O_index)
6346 val = slot->opnd[i].X_add_number;
6347 else if (slot->opnd[i].X_op == O_big)
6349 /* This must be the value 0x10000000000000000. */
6350 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6351 val = 0;
6353 else
6354 val = 0;
6356 switch (idesc->operands[i])
6358 case IA64_OPND_IMMU64:
6359 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6360 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6361 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6362 | (((val >> 63) & 0x1) << 36));
6363 continue;
6365 case IA64_OPND_IMMU62:
6366 val &= 0x3fffffffffffffffULL;
6367 if (val != slot->opnd[i].X_add_number)
6368 as_warn (_("Value truncated to 62 bits"));
6369 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6370 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6371 continue;
6373 case IA64_OPND_TGT64:
6374 val >>= 4;
6375 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6376 insn |= ((((val >> 59) & 0x1) << 36)
6377 | (((val >> 0) & 0xfffff) << 13));
6378 continue;
6380 case IA64_OPND_AR3:
6381 val -= REG_AR;
6382 break;
6384 case IA64_OPND_B1:
6385 case IA64_OPND_B2:
6386 val -= REG_BR;
6387 break;
6389 case IA64_OPND_CR3:
6390 val -= REG_CR;
6391 break;
6393 case IA64_OPND_F1:
6394 case IA64_OPND_F2:
6395 case IA64_OPND_F3:
6396 case IA64_OPND_F4:
6397 val -= REG_FR;
6398 break;
6400 case IA64_OPND_P1:
6401 case IA64_OPND_P2:
6402 val -= REG_P;
6403 break;
6405 case IA64_OPND_R1:
6406 case IA64_OPND_R2:
6407 case IA64_OPND_R3:
6408 case IA64_OPND_R3_2:
6409 case IA64_OPND_CPUID_R3:
6410 case IA64_OPND_DBR_R3:
6411 case IA64_OPND_DTR_R3:
6412 case IA64_OPND_ITR_R3:
6413 case IA64_OPND_IBR_R3:
6414 case IA64_OPND_MR3:
6415 case IA64_OPND_MSR_R3:
6416 case IA64_OPND_PKR_R3:
6417 case IA64_OPND_PMC_R3:
6418 case IA64_OPND_PMD_R3:
6419 case IA64_OPND_RR_R3:
6420 val -= REG_GR;
6421 break;
6423 default:
6424 break;
6427 odesc = elf64_ia64_operands + idesc->operands[i];
6428 err = (*odesc->insert) (odesc, val, &insn);
6429 if (err)
6430 as_bad_where (slot->src_file, slot->src_line,
6431 "Bad operand value: %s", err);
6432 if (idesc->flags & IA64_OPCODE_PSEUDO)
6434 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6435 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6437 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6438 (*o2desc->insert) (o2desc, val, &insn);
6440 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6441 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6442 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6444 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6445 (*o2desc->insert) (o2desc, 64 - val, &insn);
6449 *insnp = insn;
6452 static void
6453 emit_one_bundle ()
6455 int manual_bundling_off = 0, manual_bundling = 0;
6456 enum ia64_unit required_unit, insn_unit = 0;
6457 enum ia64_insn_type type[3], insn_type;
6458 unsigned int template, orig_template;
6459 bfd_vma insn[3] = { -1, -1, -1 };
6460 struct ia64_opcode *idesc;
6461 int end_of_insn_group = 0, user_template = -1;
6462 int n, i, j, first, curr, last_slot;
6463 unw_rec_list *ptr, *last_ptr, *end_ptr;
6464 bfd_vma t0 = 0, t1 = 0;
6465 struct label_fix *lfix;
6466 struct insn_fix *ifix;
6467 char mnemonic[16];
6468 fixS *fix;
6469 char *f;
6470 int addr_mod;
6472 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6473 know (first >= 0 & first < NUM_SLOTS);
6474 n = MIN (3, md.num_slots_in_use);
6476 /* Determine template: user user_template if specified, best match
6477 otherwise: */
6479 if (md.slot[first].user_template >= 0)
6480 user_template = template = md.slot[first].user_template;
6481 else
6483 /* Auto select appropriate template. */
6484 memset (type, 0, sizeof (type));
6485 curr = first;
6486 for (i = 0; i < n; ++i)
6488 if (md.slot[curr].label_fixups && i != 0)
6489 break;
6490 type[i] = md.slot[curr].idesc->type;
6491 curr = (curr + 1) % NUM_SLOTS;
6493 template = best_template[type[0]][type[1]][type[2]];
6496 /* initialize instructions with appropriate nops: */
6497 for (i = 0; i < 3; ++i)
6498 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6500 f = frag_more (16);
6502 /* Check to see if this bundle is at an offset that is a multiple of 16-bytes
6503 from the start of the frag. */
6504 addr_mod = frag_now_fix () & 15;
6505 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
6506 as_bad (_("instruction address is not a multiple of 16"));
6507 frag_now->insn_addr = addr_mod;
6508 frag_now->has_code = 1;
6510 /* now fill in slots with as many insns as possible: */
6511 curr = first;
6512 idesc = md.slot[curr].idesc;
6513 end_of_insn_group = 0;
6514 last_slot = -1;
6515 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6517 /* If we have unwind records, we may need to update some now. */
6518 ptr = md.slot[curr].unwind_record;
6519 if (ptr)
6521 /* Find the last prologue/body record in the list for the current
6522 insn, and set the slot number for all records up to that point.
6523 This needs to be done now, because prologue/body records refer to
6524 the current point, not the point after the instruction has been
6525 issued. This matters because there may have been nops emitted
6526 meanwhile. Any non-prologue non-body record followed by a
6527 prologue/body record must also refer to the current point. */
6528 last_ptr = NULL;
6529 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6530 for (; ptr != end_ptr; ptr = ptr->next)
6531 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6532 || ptr->r.type == body)
6533 last_ptr = ptr;
6534 if (last_ptr)
6536 /* Make last_ptr point one after the last prologue/body
6537 record. */
6538 last_ptr = last_ptr->next;
6539 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6540 ptr = ptr->next)
6542 ptr->slot_number = (unsigned long) f + i;
6543 ptr->slot_frag = frag_now;
6545 /* Remove the initialized records, so that we won't accidentally
6546 update them again if we insert a nop and continue. */
6547 md.slot[curr].unwind_record = last_ptr;
6551 manual_bundling_off = md.slot[curr].manual_bundling_off;
6552 if (md.slot[curr].manual_bundling_on)
6554 if (curr == first)
6555 manual_bundling = 1;
6556 else
6557 break; /* Need to start a new bundle. */
6560 /* If this instruction specifies a template, then it must be the first
6561 instruction of a bundle. */
6562 if (curr != first && md.slot[curr].user_template >= 0)
6563 break;
6565 if (idesc->flags & IA64_OPCODE_SLOT2)
6567 if (manual_bundling && !manual_bundling_off)
6569 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6570 "`%s' must be last in bundle", idesc->name);
6571 if (i < 2)
6572 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6574 i = 2;
6576 if (idesc->flags & IA64_OPCODE_LAST)
6578 int required_slot;
6579 unsigned int required_template;
6581 /* If we need a stop bit after an M slot, our only choice is
6582 template 5 (M;;MI). If we need a stop bit after a B
6583 slot, our only choice is to place it at the end of the
6584 bundle, because the only available templates are MIB,
6585 MBB, BBB, MMB, and MFB. We don't handle anything other
6586 than M and B slots because these are the only kind of
6587 instructions that can have the IA64_OPCODE_LAST bit set. */
6588 required_template = template;
6589 switch (idesc->type)
6591 case IA64_TYPE_M:
6592 required_slot = 0;
6593 required_template = 5;
6594 break;
6596 case IA64_TYPE_B:
6597 required_slot = 2;
6598 break;
6600 default:
6601 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6602 "Internal error: don't know how to force %s to end"
6603 "of instruction group", idesc->name);
6604 required_slot = i;
6605 break;
6607 if (manual_bundling
6608 && (i > required_slot
6609 || (required_slot == 2 && !manual_bundling_off)
6610 || (user_template >= 0
6611 /* Changing from MMI to M;MI is OK. */
6612 && (template ^ required_template) > 1)))
6614 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6615 "`%s' must be last in instruction group",
6616 idesc->name);
6617 if (i < 2 && required_slot == 2 && !manual_bundling_off)
6618 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6620 if (required_slot < i)
6621 /* Can't fit this instruction. */
6622 break;
6624 i = required_slot;
6625 if (required_template != template)
6627 /* If we switch the template, we need to reset the NOPs
6628 after slot i. The slot-types of the instructions ahead
6629 of i never change, so we don't need to worry about
6630 changing NOPs in front of this slot. */
6631 for (j = i; j < 3; ++j)
6632 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6634 template = required_template;
6636 if (curr != first && md.slot[curr].label_fixups)
6638 if (manual_bundling)
6640 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6641 "Label must be first in a bundle");
6642 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6644 /* This insn must go into the first slot of a bundle. */
6645 break;
6648 if (end_of_insn_group && md.num_slots_in_use >= 1)
6650 /* We need an instruction group boundary in the middle of a
6651 bundle. See if we can switch to an other template with
6652 an appropriate boundary. */
6654 orig_template = template;
6655 if (i == 1 && (user_template == 4
6656 || (user_template < 0
6657 && (ia64_templ_desc[template].exec_unit[0]
6658 == IA64_UNIT_M))))
6660 template = 5;
6661 end_of_insn_group = 0;
6663 else if (i == 2 && (user_template == 0
6664 || (user_template < 0
6665 && (ia64_templ_desc[template].exec_unit[1]
6666 == IA64_UNIT_I)))
6667 /* This test makes sure we don't switch the template if
6668 the next instruction is one that needs to be first in
6669 an instruction group. Since all those instructions are
6670 in the M group, there is no way such an instruction can
6671 fit in this bundle even if we switch the template. The
6672 reason we have to check for this is that otherwise we
6673 may end up generating "MI;;I M.." which has the deadly
6674 effect that the second M instruction is no longer the
6675 first in the group! --davidm 99/12/16 */
6676 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6678 template = 1;
6679 end_of_insn_group = 0;
6681 else if (i == 1
6682 && user_template == 0
6683 && !(idesc->flags & IA64_OPCODE_FIRST))
6684 /* Use the next slot. */
6685 continue;
6686 else if (curr != first)
6687 /* can't fit this insn */
6688 break;
6690 if (template != orig_template)
6691 /* if we switch the template, we need to reset the NOPs
6692 after slot i. The slot-types of the instructions ahead
6693 of i never change, so we don't need to worry about
6694 changing NOPs in front of this slot. */
6695 for (j = i; j < 3; ++j)
6696 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6698 required_unit = ia64_templ_desc[template].exec_unit[i];
6700 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6701 if (idesc->type == IA64_TYPE_DYN)
6703 enum ia64_opnd opnd1, opnd2;
6705 if ((strcmp (idesc->name, "nop") == 0)
6706 || (strcmp (idesc->name, "break") == 0))
6707 insn_unit = required_unit;
6708 else if (strcmp (idesc->name, "hint") == 0)
6710 insn_unit = required_unit;
6711 if (required_unit == IA64_UNIT_B)
6713 switch (md.hint_b)
6715 case hint_b_ok:
6716 break;
6717 case hint_b_warning:
6718 as_warn ("hint in B unit may be treated as nop");
6719 break;
6720 case hint_b_error:
6721 /* When manual bundling is off and there is no
6722 user template, we choose a different unit so
6723 that hint won't go into the current slot. We
6724 will fill the current bundle with nops and
6725 try to put hint into the next bundle. */
6726 if (!manual_bundling && user_template < 0)
6727 insn_unit = IA64_UNIT_I;
6728 else
6729 as_bad ("hint in B unit can't be used");
6730 break;
6734 else if (strcmp (idesc->name, "chk.s") == 0
6735 || strcmp (idesc->name, "mov") == 0)
6737 insn_unit = IA64_UNIT_M;
6738 if (required_unit == IA64_UNIT_I
6739 || (required_unit == IA64_UNIT_F && template == 6))
6740 insn_unit = IA64_UNIT_I;
6742 else
6743 as_fatal ("emit_one_bundle: unexpected dynamic op");
6745 sprintf (mnemonic, "%s.%c", idesc->name, "?imbfxx"[insn_unit]);
6746 opnd1 = idesc->operands[0];
6747 opnd2 = idesc->operands[1];
6748 ia64_free_opcode (idesc);
6749 idesc = ia64_find_opcode (mnemonic);
6750 /* moves to/from ARs have collisions */
6751 if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3)
6753 while (idesc != NULL
6754 && (idesc->operands[0] != opnd1
6755 || idesc->operands[1] != opnd2))
6756 idesc = get_next_opcode (idesc);
6758 md.slot[curr].idesc = idesc;
6760 else
6762 insn_type = idesc->type;
6763 insn_unit = IA64_UNIT_NIL;
6764 switch (insn_type)
6766 case IA64_TYPE_A:
6767 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6768 insn_unit = required_unit;
6769 break;
6770 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6771 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6772 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6773 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6774 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6775 default: break;
6779 if (insn_unit != required_unit)
6780 continue; /* Try next slot. */
6782 if (debug_type == DEBUG_DWARF2 || md.slot[curr].loc_directive_seen)
6784 bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6786 md.slot[curr].loc_directive_seen = 0;
6787 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6790 build_insn (md.slot + curr, insn + i);
6792 ptr = md.slot[curr].unwind_record;
6793 if (ptr)
6795 /* Set slot numbers for all remaining unwind records belonging to the
6796 current insn. There can not be any prologue/body unwind records
6797 here. */
6798 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6799 for (; ptr != end_ptr; ptr = ptr->next)
6801 ptr->slot_number = (unsigned long) f + i;
6802 ptr->slot_frag = frag_now;
6804 md.slot[curr].unwind_record = NULL;
6807 if (required_unit == IA64_UNIT_L)
6809 know (i == 1);
6810 /* skip one slot for long/X-unit instructions */
6811 ++i;
6813 --md.num_slots_in_use;
6814 last_slot = i;
6816 /* now is a good time to fix up the labels for this insn: */
6817 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6819 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6820 symbol_set_frag (lfix->sym, frag_now);
6822 /* and fix up the tags also. */
6823 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6825 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6826 symbol_set_frag (lfix->sym, frag_now);
6829 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6831 ifix = md.slot[curr].fixup + j;
6832 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6833 &ifix->expr, ifix->is_pcrel, ifix->code);
6834 fix->tc_fix_data.opnd = ifix->opnd;
6835 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6836 fix->fx_file = md.slot[curr].src_file;
6837 fix->fx_line = md.slot[curr].src_line;
6840 end_of_insn_group = md.slot[curr].end_of_insn_group;
6842 /* clear slot: */
6843 ia64_free_opcode (md.slot[curr].idesc);
6844 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6845 md.slot[curr].user_template = -1;
6847 if (manual_bundling_off)
6849 manual_bundling = 0;
6850 break;
6852 curr = (curr + 1) % NUM_SLOTS;
6853 idesc = md.slot[curr].idesc;
6855 if (manual_bundling > 0)
6857 if (md.num_slots_in_use > 0)
6859 if (last_slot >= 2)
6860 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6861 "`%s' does not fit into bundle", idesc->name);
6862 else if (last_slot < 0)
6864 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6865 "`%s' does not fit into %s template",
6866 idesc->name, ia64_templ_desc[template].name);
6867 /* Drop first insn so we don't livelock. */
6868 --md.num_slots_in_use;
6869 know (curr == first);
6870 ia64_free_opcode (md.slot[curr].idesc);
6871 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6872 md.slot[curr].user_template = -1;
6874 else
6876 const char *where;
6878 if (template == 2)
6879 where = "X slot";
6880 else if (last_slot == 0)
6881 where = "slots 2 or 3";
6882 else
6883 where = "slot 3";
6884 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6885 "`%s' can't go in %s of %s template",
6886 idesc->name, where, ia64_templ_desc[template].name);
6889 else
6890 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6891 "Missing '}' at end of file");
6893 know (md.num_slots_in_use < NUM_SLOTS);
6895 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6896 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6898 number_to_chars_littleendian (f + 0, t0, 8);
6899 number_to_chars_littleendian (f + 8, t1, 8);
6901 if (unwind.list)
6903 unwind.list->next_slot_number = (unsigned long) f + 16;
6904 unwind.list->next_slot_frag = frag_now;
6909 md_parse_option (c, arg)
6910 int c;
6911 char *arg;
6914 switch (c)
6916 /* Switches from the Intel assembler. */
6917 case 'm':
6918 if (strcmp (arg, "ilp64") == 0
6919 || strcmp (arg, "lp64") == 0
6920 || strcmp (arg, "p64") == 0)
6922 md.flags |= EF_IA_64_ABI64;
6924 else if (strcmp (arg, "ilp32") == 0)
6926 md.flags &= ~EF_IA_64_ABI64;
6928 else if (strcmp (arg, "le") == 0)
6930 md.flags &= ~EF_IA_64_BE;
6931 default_big_endian = 0;
6933 else if (strcmp (arg, "be") == 0)
6935 md.flags |= EF_IA_64_BE;
6936 default_big_endian = 1;
6938 else if (strncmp (arg, "unwind-check=", 13) == 0)
6940 arg += 13;
6941 if (strcmp (arg, "warning") == 0)
6942 md.unwind_check = unwind_check_warning;
6943 else if (strcmp (arg, "error") == 0)
6944 md.unwind_check = unwind_check_error;
6945 else
6946 return 0;
6948 else if (strncmp (arg, "hint.b=", 7) == 0)
6950 arg += 7;
6951 if (strcmp (arg, "ok") == 0)
6952 md.hint_b = hint_b_ok;
6953 else if (strcmp (arg, "warning") == 0)
6954 md.hint_b = hint_b_warning;
6955 else if (strcmp (arg, "error") == 0)
6956 md.hint_b = hint_b_error;
6957 else
6958 return 0;
6960 else
6961 return 0;
6962 break;
6964 case 'N':
6965 if (strcmp (arg, "so") == 0)
6967 /* Suppress signon message. */
6969 else if (strcmp (arg, "pi") == 0)
6971 /* Reject privileged instructions. FIXME */
6973 else if (strcmp (arg, "us") == 0)
6975 /* Allow union of signed and unsigned range. FIXME */
6977 else if (strcmp (arg, "close_fcalls") == 0)
6979 /* Do not resolve global function calls. */
6981 else
6982 return 0;
6983 break;
6985 case 'C':
6986 /* temp[="prefix"] Insert temporary labels into the object file
6987 symbol table prefixed by "prefix".
6988 Default prefix is ":temp:".
6990 break;
6992 case 'a':
6993 /* indirect=<tgt> Assume unannotated indirect branches behavior
6994 according to <tgt> --
6995 exit: branch out from the current context (default)
6996 labels: all labels in context may be branch targets
6998 if (strncmp (arg, "indirect=", 9) != 0)
6999 return 0;
7000 break;
7002 case 'x':
7003 /* -X conflicts with an ignored option, use -x instead */
7004 md.detect_dv = 1;
7005 if (!arg || strcmp (arg, "explicit") == 0)
7007 /* set default mode to explicit */
7008 md.default_explicit_mode = 1;
7009 break;
7011 else if (strcmp (arg, "auto") == 0)
7013 md.default_explicit_mode = 0;
7015 else if (strcmp (arg, "none") == 0)
7017 md.detect_dv = 0;
7019 else if (strcmp (arg, "debug") == 0)
7021 md.debug_dv = 1;
7023 else if (strcmp (arg, "debugx") == 0)
7025 md.default_explicit_mode = 1;
7026 md.debug_dv = 1;
7028 else if (strcmp (arg, "debugn") == 0)
7030 md.debug_dv = 1;
7031 md.detect_dv = 0;
7033 else
7035 as_bad (_("Unrecognized option '-x%s'"), arg);
7037 break;
7039 case 'S':
7040 /* nops Print nops statistics. */
7041 break;
7043 /* GNU specific switches for gcc. */
7044 case OPTION_MCONSTANT_GP:
7045 md.flags |= EF_IA_64_CONS_GP;
7046 break;
7048 case OPTION_MAUTO_PIC:
7049 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
7050 break;
7052 default:
7053 return 0;
7056 return 1;
7059 void
7060 md_show_usage (stream)
7061 FILE *stream;
7063 fputs (_("\
7064 IA-64 options:\n\
7065 --mconstant-gp mark output file as using the constant-GP model\n\
7066 (sets ELF header flag EF_IA_64_CONS_GP)\n\
7067 --mauto-pic mark output file as using the constant-GP model\n\
7068 without function descriptors (sets ELF header flag\n\
7069 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
7070 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
7071 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
7072 -munwind-check=[warning|error]\n\
7073 unwind directive check (default -munwind-check=warning)\n\
7074 -mhint.b=[ok|warning|error]\n\
7075 hint.b check (default -mhint.b=error)\n\
7076 -x | -xexplicit turn on dependency violation checking\n\
7077 -xauto automagically remove dependency violations (default)\n\
7078 -xnone turn off dependency violation checking\n\
7079 -xdebug debug dependency violation checker\n\
7080 -xdebugn debug dependency violation checker but turn off\n\
7081 dependency violation checking\n\
7082 -xdebugx debug dependency violation checker and turn on\n\
7083 dependency violation checking\n"),
7084 stream);
7087 void
7088 ia64_after_parse_args ()
7090 if (debug_type == DEBUG_STABS)
7091 as_fatal (_("--gstabs is not supported for ia64"));
7094 /* Return true if TYPE fits in TEMPL at SLOT. */
7096 static int
7097 match (int templ, int type, int slot)
7099 enum ia64_unit unit;
7100 int result;
7102 unit = ia64_templ_desc[templ].exec_unit[slot];
7103 switch (type)
7105 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
7106 case IA64_TYPE_A:
7107 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
7108 break;
7109 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
7110 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
7111 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
7112 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
7113 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
7114 default: result = 0; break;
7116 return result;
7119 /* Add a bit of extra goodness if a nop of type F or B would fit
7120 in TEMPL at SLOT. */
7122 static inline int
7123 extra_goodness (int templ, int slot)
7125 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
7126 return 2;
7127 if (slot == 2 && match (templ, IA64_TYPE_B, slot))
7128 return 1;
7129 return 0;
7132 /* This function is called once, at assembler startup time. It sets
7133 up all the tables, etc. that the MD part of the assembler will need
7134 that can be determined before arguments are parsed. */
7135 void
7136 md_begin ()
7138 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
7139 const char *err;
7140 char name[8];
7142 md.auto_align = 1;
7143 md.explicit_mode = md.default_explicit_mode;
7145 bfd_set_section_alignment (stdoutput, text_section, 4);
7147 /* Make sure function pointers get initialized. */
7148 target_big_endian = -1;
7149 dot_byteorder (default_big_endian);
7151 alias_hash = hash_new ();
7152 alias_name_hash = hash_new ();
7153 secalias_hash = hash_new ();
7154 secalias_name_hash = hash_new ();
7156 pseudo_func[FUNC_DTP_MODULE].u.sym =
7157 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
7158 &zero_address_frag);
7160 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
7161 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
7162 &zero_address_frag);
7164 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
7165 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
7166 &zero_address_frag);
7168 pseudo_func[FUNC_GP_RELATIVE].u.sym =
7169 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
7170 &zero_address_frag);
7172 pseudo_func[FUNC_LT_RELATIVE].u.sym =
7173 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
7174 &zero_address_frag);
7176 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
7177 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
7178 &zero_address_frag);
7180 pseudo_func[FUNC_PC_RELATIVE].u.sym =
7181 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
7182 &zero_address_frag);
7184 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
7185 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
7186 &zero_address_frag);
7188 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
7189 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
7190 &zero_address_frag);
7192 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
7193 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
7194 &zero_address_frag);
7196 pseudo_func[FUNC_TP_RELATIVE].u.sym =
7197 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
7198 &zero_address_frag);
7200 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
7201 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
7202 &zero_address_frag);
7204 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
7205 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
7206 &zero_address_frag);
7208 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
7209 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
7210 &zero_address_frag);
7212 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
7213 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
7214 &zero_address_frag);
7216 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
7217 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
7218 &zero_address_frag);
7220 pseudo_func[FUNC_IPLT_RELOC].u.sym =
7221 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
7222 &zero_address_frag);
7224 /* Compute the table of best templates. We compute goodness as a
7225 base 4 value, in which each match counts for 3, each F counts
7226 for 2, each B counts for 1. This should maximize the number of
7227 F and B nops in the chosen bundles, which is good because these
7228 pipelines are least likely to be overcommitted. */
7229 for (i = 0; i < IA64_NUM_TYPES; ++i)
7230 for (j = 0; j < IA64_NUM_TYPES; ++j)
7231 for (k = 0; k < IA64_NUM_TYPES; ++k)
7233 best = 0;
7234 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
7236 goodness = 0;
7237 if (match (t, i, 0))
7239 if (match (t, j, 1))
7241 if (match (t, k, 2))
7242 goodness = 3 + 3 + 3;
7243 else
7244 goodness = 3 + 3 + extra_goodness (t, 2);
7246 else if (match (t, j, 2))
7247 goodness = 3 + 3 + extra_goodness (t, 1);
7248 else
7250 goodness = 3;
7251 goodness += extra_goodness (t, 1);
7252 goodness += extra_goodness (t, 2);
7255 else if (match (t, i, 1))
7257 if (match (t, j, 2))
7258 goodness = 3 + 3;
7259 else
7260 goodness = 3 + extra_goodness (t, 2);
7262 else if (match (t, i, 2))
7263 goodness = 3 + extra_goodness (t, 1);
7265 if (goodness > best)
7267 best = goodness;
7268 best_template[i][j][k] = t;
7273 for (i = 0; i < NUM_SLOTS; ++i)
7274 md.slot[i].user_template = -1;
7276 md.pseudo_hash = hash_new ();
7277 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
7279 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
7280 (void *) (pseudo_opcode + i));
7281 if (err)
7282 as_fatal ("ia64.md_begin: can't hash `%s': %s",
7283 pseudo_opcode[i].name, err);
7286 md.reg_hash = hash_new ();
7287 md.dynreg_hash = hash_new ();
7288 md.const_hash = hash_new ();
7289 md.entry_hash = hash_new ();
7291 /* general registers: */
7293 total = 128;
7294 for (i = 0; i < total; ++i)
7296 sprintf (name, "r%d", i - REG_GR);
7297 md.regsym[i] = declare_register (name, i);
7300 /* floating point registers: */
7301 total += 128;
7302 for (; i < total; ++i)
7304 sprintf (name, "f%d", i - REG_FR);
7305 md.regsym[i] = declare_register (name, i);
7308 /* application registers: */
7309 total += 128;
7310 ar_base = i;
7311 for (; i < total; ++i)
7313 sprintf (name, "ar%d", i - REG_AR);
7314 md.regsym[i] = declare_register (name, i);
7317 /* control registers: */
7318 total += 128;
7319 cr_base = i;
7320 for (; i < total; ++i)
7322 sprintf (name, "cr%d", i - REG_CR);
7323 md.regsym[i] = declare_register (name, i);
7326 /* predicate registers: */
7327 total += 64;
7328 for (; i < total; ++i)
7330 sprintf (name, "p%d", i - REG_P);
7331 md.regsym[i] = declare_register (name, i);
7334 /* branch registers: */
7335 total += 8;
7336 for (; i < total; ++i)
7338 sprintf (name, "b%d", i - REG_BR);
7339 md.regsym[i] = declare_register (name, i);
7342 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
7343 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
7344 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
7345 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
7346 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
7347 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
7348 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
7350 for (i = 0; i < NELEMS (indirect_reg); ++i)
7352 regnum = indirect_reg[i].regnum;
7353 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
7356 /* define synonyms for application registers: */
7357 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
7358 md.regsym[i] = declare_register (ar[i - REG_AR].name,
7359 REG_AR + ar[i - REG_AR].regnum);
7361 /* define synonyms for control registers: */
7362 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
7363 md.regsym[i] = declare_register (cr[i - REG_CR].name,
7364 REG_CR + cr[i - REG_CR].regnum);
7366 declare_register ("gp", REG_GR + 1);
7367 declare_register ("sp", REG_GR + 12);
7368 declare_register ("rp", REG_BR + 0);
7370 /* pseudo-registers used to specify unwind info: */
7371 declare_register ("psp", REG_PSP);
7373 declare_register_set ("ret", 4, REG_GR + 8);
7374 declare_register_set ("farg", 8, REG_FR + 8);
7375 declare_register_set ("fret", 8, REG_FR + 8);
7377 for (i = 0; i < NELEMS (const_bits); ++i)
7379 err = hash_insert (md.const_hash, const_bits[i].name,
7380 (PTR) (const_bits + i));
7381 if (err)
7382 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
7383 name, err);
7386 /* Set the architecture and machine depending on defaults and command line
7387 options. */
7388 if (md.flags & EF_IA_64_ABI64)
7389 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
7390 else
7391 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
7393 if (! ok)
7394 as_warn (_("Could not set architecture and machine"));
7396 /* Set the pointer size and pointer shift size depending on md.flags */
7398 if (md.flags & EF_IA_64_ABI64)
7400 md.pointer_size = 8; /* pointers are 8 bytes */
7401 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
7403 else
7405 md.pointer_size = 4; /* pointers are 4 bytes */
7406 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
7409 md.mem_offset.hint = 0;
7410 md.path = 0;
7411 md.maxpaths = 0;
7412 md.entry_labels = NULL;
7415 /* Set the default options in md. Cannot do this in md_begin because
7416 that is called after md_parse_option which is where we set the
7417 options in md based on command line options. */
7419 void
7420 ia64_init (argc, argv)
7421 int argc ATTRIBUTE_UNUSED;
7422 char **argv ATTRIBUTE_UNUSED;
7424 md.flags = MD_FLAGS_DEFAULT;
7425 md.detect_dv = 1;
7426 /* FIXME: We should change it to unwind_check_error someday. */
7427 md.unwind_check = unwind_check_warning;
7428 md.hint_b = hint_b_error;
7431 /* Return a string for the target object file format. */
7433 const char *
7434 ia64_target_format ()
7436 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7438 if (md.flags & EF_IA_64_BE)
7440 if (md.flags & EF_IA_64_ABI64)
7441 #if defined(TE_AIX50)
7442 return "elf64-ia64-aix-big";
7443 #elif defined(TE_HPUX)
7444 return "elf64-ia64-hpux-big";
7445 #else
7446 return "elf64-ia64-big";
7447 #endif
7448 else
7449 #if defined(TE_AIX50)
7450 return "elf32-ia64-aix-big";
7451 #elif defined(TE_HPUX)
7452 return "elf32-ia64-hpux-big";
7453 #else
7454 return "elf32-ia64-big";
7455 #endif
7457 else
7459 if (md.flags & EF_IA_64_ABI64)
7460 #ifdef TE_AIX50
7461 return "elf64-ia64-aix-little";
7462 #else
7463 return "elf64-ia64-little";
7464 #endif
7465 else
7466 #ifdef TE_AIX50
7467 return "elf32-ia64-aix-little";
7468 #else
7469 return "elf32-ia64-little";
7470 #endif
7473 else
7474 return "unknown-format";
7477 void
7478 ia64_end_of_source ()
7480 /* terminate insn group upon reaching end of file: */
7481 insn_group_break (1, 0, 0);
7483 /* emits slots we haven't written yet: */
7484 ia64_flush_insns ();
7486 bfd_set_private_flags (stdoutput, md.flags);
7488 md.mem_offset.hint = 0;
7491 void
7492 ia64_start_line ()
7494 if (md.qp.X_op == O_register)
7495 as_bad ("qualifying predicate not followed by instruction");
7496 md.qp.X_op = O_absent;
7498 if (ignore_input ())
7499 return;
7501 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7503 if (md.detect_dv && !md.explicit_mode)
7505 static int warned;
7507 if (!warned)
7509 warned = 1;
7510 as_warn (_("Explicit stops are ignored in auto mode"));
7513 else
7514 insn_group_break (1, 0, 0);
7518 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7519 labels. */
7520 static int defining_tag = 0;
7523 ia64_unrecognized_line (ch)
7524 int ch;
7526 switch (ch)
7528 case '(':
7529 expression (&md.qp);
7530 if (*input_line_pointer++ != ')')
7532 as_bad ("Expected ')'");
7533 return 0;
7535 if (md.qp.X_op != O_register)
7537 as_bad ("Qualifying predicate expected");
7538 return 0;
7540 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7542 as_bad ("Predicate register expected");
7543 return 0;
7545 return 1;
7547 case '{':
7548 if (md.manual_bundling)
7549 as_warn ("Found '{' when manual bundling is already turned on");
7550 else
7551 CURR_SLOT.manual_bundling_on = 1;
7552 md.manual_bundling = 1;
7554 /* Bundling is only acceptable in explicit mode
7555 or when in default automatic mode. */
7556 if (md.detect_dv && !md.explicit_mode)
7558 if (!md.mode_explicitly_set
7559 && !md.default_explicit_mode)
7560 dot_dv_mode ('E');
7561 else
7562 as_warn (_("Found '{' after explicit switch to automatic mode"));
7564 return 1;
7566 case '}':
7567 if (!md.manual_bundling)
7568 as_warn ("Found '}' when manual bundling is off");
7569 else
7570 PREV_SLOT.manual_bundling_off = 1;
7571 md.manual_bundling = 0;
7573 /* switch back to automatic mode, if applicable */
7574 if (md.detect_dv
7575 && md.explicit_mode
7576 && !md.mode_explicitly_set
7577 && !md.default_explicit_mode)
7578 dot_dv_mode ('A');
7580 /* Allow '{' to follow on the same line. We also allow ";;", but that
7581 happens automatically because ';' is an end of line marker. */
7582 SKIP_WHITESPACE ();
7583 if (input_line_pointer[0] == '{')
7585 input_line_pointer++;
7586 return ia64_unrecognized_line ('{');
7589 demand_empty_rest_of_line ();
7590 return 1;
7592 case '[':
7594 char *s;
7595 char c;
7596 symbolS *tag;
7597 int temp;
7599 if (md.qp.X_op == O_register)
7601 as_bad ("Tag must come before qualifying predicate.");
7602 return 0;
7605 /* This implements just enough of read_a_source_file in read.c to
7606 recognize labels. */
7607 if (is_name_beginner (*input_line_pointer))
7609 s = input_line_pointer;
7610 c = get_symbol_end ();
7612 else if (LOCAL_LABELS_FB
7613 && ISDIGIT (*input_line_pointer))
7615 temp = 0;
7616 while (ISDIGIT (*input_line_pointer))
7617 temp = (temp * 10) + *input_line_pointer++ - '0';
7618 fb_label_instance_inc (temp);
7619 s = fb_label_name (temp, 0);
7620 c = *input_line_pointer;
7622 else
7624 s = NULL;
7625 c = '\0';
7627 if (c != ':')
7629 /* Put ':' back for error messages' sake. */
7630 *input_line_pointer++ = ':';
7631 as_bad ("Expected ':'");
7632 return 0;
7635 defining_tag = 1;
7636 tag = colon (s);
7637 defining_tag = 0;
7638 /* Put ':' back for error messages' sake. */
7639 *input_line_pointer++ = ':';
7640 if (*input_line_pointer++ != ']')
7642 as_bad ("Expected ']'");
7643 return 0;
7645 if (! tag)
7647 as_bad ("Tag name expected");
7648 return 0;
7650 return 1;
7653 default:
7654 break;
7657 /* Not a valid line. */
7658 return 0;
7661 void
7662 ia64_frob_label (sym)
7663 struct symbol *sym;
7665 struct label_fix *fix;
7667 /* Tags need special handling since they are not bundle breaks like
7668 labels. */
7669 if (defining_tag)
7671 fix = obstack_alloc (&notes, sizeof (*fix));
7672 fix->sym = sym;
7673 fix->next = CURR_SLOT.tag_fixups;
7674 CURR_SLOT.tag_fixups = fix;
7676 return;
7679 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7681 md.last_text_seg = now_seg;
7682 fix = obstack_alloc (&notes, sizeof (*fix));
7683 fix->sym = sym;
7684 fix->next = CURR_SLOT.label_fixups;
7685 CURR_SLOT.label_fixups = fix;
7687 /* Keep track of how many code entry points we've seen. */
7688 if (md.path == md.maxpaths)
7690 md.maxpaths += 20;
7691 md.entry_labels = (const char **)
7692 xrealloc ((void *) md.entry_labels,
7693 md.maxpaths * sizeof (char *));
7695 md.entry_labels[md.path++] = S_GET_NAME (sym);
7699 #ifdef TE_HPUX
7700 /* The HP-UX linker will give unresolved symbol errors for symbols
7701 that are declared but unused. This routine removes declared,
7702 unused symbols from an object. */
7704 ia64_frob_symbol (sym)
7705 struct symbol *sym;
7707 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7708 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7709 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7710 && ! S_IS_EXTERNAL (sym)))
7711 return 1;
7712 return 0;
7714 #endif
7716 void
7717 ia64_flush_pending_output ()
7719 if (!md.keep_pending_output
7720 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7722 /* ??? This causes many unnecessary stop bits to be emitted.
7723 Unfortunately, it isn't clear if it is safe to remove this. */
7724 insn_group_break (1, 0, 0);
7725 ia64_flush_insns ();
7729 /* Do ia64-specific expression optimization. All that's done here is
7730 to transform index expressions that are either due to the indexing
7731 of rotating registers or due to the indexing of indirect register
7732 sets. */
7734 ia64_optimize_expr (l, op, r)
7735 expressionS *l;
7736 operatorT op;
7737 expressionS *r;
7739 unsigned num_regs;
7741 if (op == O_index)
7743 if (l->X_op == O_register && r->X_op == O_constant)
7745 num_regs = (l->X_add_number >> 16);
7746 if ((unsigned) r->X_add_number >= num_regs)
7748 if (!num_regs)
7749 as_bad ("No current frame");
7750 else
7751 as_bad ("Index out of range 0..%u", num_regs - 1);
7752 r->X_add_number = 0;
7754 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7755 return 1;
7757 else if (l->X_op == O_register && r->X_op == O_register)
7759 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7760 || l->X_add_number == IND_MEM)
7762 as_bad ("Indirect register set name expected");
7763 l->X_add_number = IND_CPUID;
7765 l->X_op = O_index;
7766 l->X_op_symbol = md.regsym[l->X_add_number];
7767 l->X_add_number = r->X_add_number;
7768 return 1;
7771 return 0;
7775 ia64_parse_name (name, e, nextcharP)
7776 char *name;
7777 expressionS *e;
7778 char *nextcharP;
7780 struct const_desc *cdesc;
7781 struct dynreg *dr = 0;
7782 unsigned int idx;
7783 struct symbol *sym;
7784 char *end;
7786 if (*name == '@')
7788 enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE;
7790 /* Find what relocation pseudo-function we're dealing with. */
7791 for (idx = 0; idx < NELEMS (pseudo_func); ++idx)
7792 if (pseudo_func[idx].name
7793 && pseudo_func[idx].name[0] == name[1]
7794 && strcmp (pseudo_func[idx].name + 1, name + 2) == 0)
7796 pseudo_type = pseudo_func[idx].type;
7797 break;
7799 switch (pseudo_type)
7801 case PSEUDO_FUNC_RELOC:
7802 end = input_line_pointer;
7803 if (*nextcharP != '(')
7805 as_bad ("Expected '('");
7806 break;
7808 /* Skip '('. */
7809 ++input_line_pointer;
7810 expression (e);
7811 if (*input_line_pointer != ')')
7813 as_bad ("Missing ')'");
7814 goto done;
7816 /* Skip ')'. */
7817 ++input_line_pointer;
7818 if (e->X_op != O_symbol)
7820 if (e->X_op != O_pseudo_fixup)
7822 as_bad ("Not a symbolic expression");
7823 goto done;
7825 if (idx != FUNC_LT_RELATIVE)
7827 as_bad ("Illegal combination of relocation functions");
7828 goto done;
7830 switch (S_GET_VALUE (e->X_op_symbol))
7832 case FUNC_FPTR_RELATIVE:
7833 idx = FUNC_LT_FPTR_RELATIVE; break;
7834 case FUNC_DTP_MODULE:
7835 idx = FUNC_LT_DTP_MODULE; break;
7836 case FUNC_DTP_RELATIVE:
7837 idx = FUNC_LT_DTP_RELATIVE; break;
7838 case FUNC_TP_RELATIVE:
7839 idx = FUNC_LT_TP_RELATIVE; break;
7840 default:
7841 as_bad ("Illegal combination of relocation functions");
7842 goto done;
7845 /* Make sure gas doesn't get rid of local symbols that are used
7846 in relocs. */
7847 e->X_op = O_pseudo_fixup;
7848 e->X_op_symbol = pseudo_func[idx].u.sym;
7849 done:
7850 *nextcharP = *input_line_pointer;
7851 break;
7853 case PSEUDO_FUNC_CONST:
7854 e->X_op = O_constant;
7855 e->X_add_number = pseudo_func[idx].u.ival;
7856 break;
7858 case PSEUDO_FUNC_REG:
7859 e->X_op = O_register;
7860 e->X_add_number = pseudo_func[idx].u.ival;
7861 break;
7863 default:
7864 return 0;
7866 return 1;
7869 /* first see if NAME is a known register name: */
7870 sym = hash_find (md.reg_hash, name);
7871 if (sym)
7873 e->X_op = O_register;
7874 e->X_add_number = S_GET_VALUE (sym);
7875 return 1;
7878 cdesc = hash_find (md.const_hash, name);
7879 if (cdesc)
7881 e->X_op = O_constant;
7882 e->X_add_number = cdesc->value;
7883 return 1;
7886 /* check for inN, locN, or outN: */
7887 idx = 0;
7888 switch (name[0])
7890 case 'i':
7891 if (name[1] == 'n' && ISDIGIT (name[2]))
7893 dr = &md.in;
7894 idx = 2;
7896 break;
7898 case 'l':
7899 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7901 dr = &md.loc;
7902 idx = 3;
7904 break;
7906 case 'o':
7907 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7909 dr = &md.out;
7910 idx = 3;
7912 break;
7914 default:
7915 break;
7918 /* Ignore register numbers with leading zeroes, except zero itself. */
7919 if (dr && (name[idx] != '0' || name[idx + 1] == '\0'))
7921 unsigned long regnum;
7923 /* The name is inN, locN, or outN; parse the register number. */
7924 regnum = strtoul (name + idx, &end, 10);
7925 if (end > name + idx && *end == '\0' && regnum < 96)
7927 if (regnum >= dr->num_regs)
7929 if (!dr->num_regs)
7930 as_bad ("No current frame");
7931 else
7932 as_bad ("Register number out of range 0..%u",
7933 dr->num_regs - 1);
7934 regnum = 0;
7936 e->X_op = O_register;
7937 e->X_add_number = dr->base + regnum;
7938 return 1;
7942 end = alloca (strlen (name) + 1);
7943 strcpy (end, name);
7944 name = ia64_canonicalize_symbol_name (end);
7945 if ((dr = hash_find (md.dynreg_hash, name)))
7947 /* We've got ourselves the name of a rotating register set.
7948 Store the base register number in the low 16 bits of
7949 X_add_number and the size of the register set in the top 16
7950 bits. */
7951 e->X_op = O_register;
7952 e->X_add_number = dr->base | (dr->num_regs << 16);
7953 return 1;
7955 return 0;
7958 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
7960 char *
7961 ia64_canonicalize_symbol_name (name)
7962 char *name;
7964 size_t len = strlen (name), full = len;
7966 while (len > 0 && name[len - 1] == '#')
7967 --len;
7968 if (len <= 0)
7970 if (full > 0)
7971 as_bad ("Standalone `#' is illegal");
7972 else
7973 as_bad ("Zero-length symbol is illegal");
7975 else if (len < full - 1)
7976 as_warn ("Redundant `#' suffix operators");
7977 name[len] = '\0';
7978 return name;
7981 /* Return true if idesc is a conditional branch instruction. This excludes
7982 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
7983 because they always read/write resources regardless of the value of the
7984 qualifying predicate. br.ia must always use p0, and hence is always
7985 taken. Thus this function returns true for branches which can fall
7986 through, and which use no resources if they do fall through. */
7988 static int
7989 is_conditional_branch (idesc)
7990 struct ia64_opcode *idesc;
7992 /* br is a conditional branch. Everything that starts with br. except
7993 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
7994 Everything that starts with brl is a conditional branch. */
7995 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
7996 && (idesc->name[2] == '\0'
7997 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
7998 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
7999 || idesc->name[2] == 'l'
8000 /* br.cond, br.call, br.clr */
8001 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
8002 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
8003 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
8006 /* Return whether the given opcode is a taken branch. If there's any doubt,
8007 returns zero. */
8009 static int
8010 is_taken_branch (idesc)
8011 struct ia64_opcode *idesc;
8013 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
8014 || strncmp (idesc->name, "br.ia", 5) == 0);
8017 /* Return whether the given opcode is an interruption or rfi. If there's any
8018 doubt, returns zero. */
8020 static int
8021 is_interruption_or_rfi (idesc)
8022 struct ia64_opcode *idesc;
8024 if (strcmp (idesc->name, "rfi") == 0)
8025 return 1;
8026 return 0;
8029 /* Returns the index of the given dependency in the opcode's list of chks, or
8030 -1 if there is no dependency. */
8032 static int
8033 depends_on (depind, idesc)
8034 int depind;
8035 struct ia64_opcode *idesc;
8037 int i;
8038 const struct ia64_opcode_dependency *dep = idesc->dependencies;
8039 for (i = 0; i < dep->nchks; i++)
8041 if (depind == DEP (dep->chks[i]))
8042 return i;
8044 return -1;
8047 /* Determine a set of specific resources used for a particular resource
8048 class. Returns the number of specific resources identified For those
8049 cases which are not determinable statically, the resource returned is
8050 marked nonspecific.
8052 Meanings of value in 'NOTE':
8053 1) only read/write when the register number is explicitly encoded in the
8054 insn.
8055 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
8056 accesses CFM when qualifying predicate is in the rotating region.
8057 3) general register value is used to specify an indirect register; not
8058 determinable statically.
8059 4) only read the given resource when bits 7:0 of the indirect index
8060 register value does not match the register number of the resource; not
8061 determinable statically.
8062 5) all rules are implementation specific.
8063 6) only when both the index specified by the reader and the index specified
8064 by the writer have the same value in bits 63:61; not determinable
8065 statically.
8066 7) only access the specified resource when the corresponding mask bit is
8068 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
8069 only read when these insns reference FR2-31
8070 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
8071 written when these insns write FR32-127
8072 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
8073 instruction
8074 11) The target predicates are written independently of PR[qp], but source
8075 registers are only read if PR[qp] is true. Since the state of PR[qp]
8076 cannot statically be determined, all source registers are marked used.
8077 12) This insn only reads the specified predicate register when that
8078 register is the PR[qp].
8079 13) This reference to ld-c only applies to teh GR whose value is loaded
8080 with data returned from memory, not the post-incremented address register.
8081 14) The RSE resource includes the implementation-specific RSE internal
8082 state resources. At least one (and possibly more) of these resources are
8083 read by each instruction listed in IC:rse-readers. At least one (and
8084 possibly more) of these resources are written by each insn listed in
8085 IC:rse-writers.
8086 15+16) Represents reserved instructions, which the assembler does not
8087 generate.
8089 Memory resources (i.e. locations in memory) are *not* marked or tracked by
8090 this code; there are no dependency violations based on memory access.
8093 #define MAX_SPECS 256
8094 #define DV_CHK 1
8095 #define DV_REG 0
8097 static int
8098 specify_resource (dep, idesc, type, specs, note, path)
8099 const struct ia64_dependency *dep;
8100 struct ia64_opcode *idesc;
8101 int type; /* is this a DV chk or a DV reg? */
8102 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
8103 int note; /* resource note for this insn's usage */
8104 int path; /* which execution path to examine */
8106 int count = 0;
8107 int i;
8108 int rsrc_write = 0;
8109 struct rsrc tmpl;
8111 if (dep->mode == IA64_DV_WAW
8112 || (dep->mode == IA64_DV_RAW && type == DV_REG)
8113 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
8114 rsrc_write = 1;
8116 /* template for any resources we identify */
8117 tmpl.dependency = dep;
8118 tmpl.note = note;
8119 tmpl.insn_srlz = tmpl.data_srlz = 0;
8120 tmpl.qp_regno = CURR_SLOT.qp_regno;
8121 tmpl.link_to_qp_branch = 1;
8122 tmpl.mem_offset.hint = 0;
8123 tmpl.specific = 1;
8124 tmpl.index = -1;
8125 tmpl.cmp_type = CMP_NONE;
8127 #define UNHANDLED \
8128 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
8129 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
8130 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
8132 /* we don't need to track these */
8133 if (dep->semantics == IA64_DVS_NONE)
8134 return 0;
8136 switch (dep->specifier)
8138 case IA64_RS_AR_K:
8139 if (note == 1)
8141 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8143 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8144 if (regno >= 0 && regno <= 7)
8146 specs[count] = tmpl;
8147 specs[count++].index = regno;
8151 else if (note == 0)
8153 for (i = 0; i < 8; i++)
8155 specs[count] = tmpl;
8156 specs[count++].index = i;
8159 else
8161 UNHANDLED;
8163 break;
8165 case IA64_RS_AR_UNAT:
8166 /* This is a mov =AR or mov AR= instruction. */
8167 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8169 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8170 if (regno == AR_UNAT)
8172 specs[count++] = tmpl;
8175 else
8177 /* This is a spill/fill, or other instruction that modifies the
8178 unat register. */
8180 /* Unless we can determine the specific bits used, mark the whole
8181 thing; bits 8:3 of the memory address indicate the bit used in
8182 UNAT. The .mem.offset hint may be used to eliminate a small
8183 subset of conflicts. */
8184 specs[count] = tmpl;
8185 if (md.mem_offset.hint)
8187 if (md.debug_dv)
8188 fprintf (stderr, " Using hint for spill/fill\n");
8189 /* The index isn't actually used, just set it to something
8190 approximating the bit index. */
8191 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
8192 specs[count].mem_offset.hint = 1;
8193 specs[count].mem_offset.offset = md.mem_offset.offset;
8194 specs[count++].mem_offset.base = md.mem_offset.base;
8196 else
8198 specs[count++].specific = 0;
8201 break;
8203 case IA64_RS_AR:
8204 if (note == 1)
8206 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8208 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8209 if ((regno >= 8 && regno <= 15)
8210 || (regno >= 20 && regno <= 23)
8211 || (regno >= 31 && regno <= 39)
8212 || (regno >= 41 && regno <= 47)
8213 || (regno >= 67 && regno <= 111))
8215 specs[count] = tmpl;
8216 specs[count++].index = regno;
8220 else
8222 UNHANDLED;
8224 break;
8226 case IA64_RS_ARb:
8227 if (note == 1)
8229 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8231 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8232 if ((regno >= 48 && regno <= 63)
8233 || (regno >= 112 && regno <= 127))
8235 specs[count] = tmpl;
8236 specs[count++].index = regno;
8240 else if (note == 0)
8242 for (i = 48; i < 64; i++)
8244 specs[count] = tmpl;
8245 specs[count++].index = i;
8247 for (i = 112; i < 128; i++)
8249 specs[count] = tmpl;
8250 specs[count++].index = i;
8253 else
8255 UNHANDLED;
8257 break;
8259 case IA64_RS_BR:
8260 if (note != 1)
8262 UNHANDLED;
8264 else
8266 if (rsrc_write)
8268 for (i = 0; i < idesc->num_outputs; i++)
8269 if (idesc->operands[i] == IA64_OPND_B1
8270 || idesc->operands[i] == IA64_OPND_B2)
8272 specs[count] = tmpl;
8273 specs[count++].index =
8274 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8277 else
8279 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8280 if (idesc->operands[i] == IA64_OPND_B1
8281 || idesc->operands[i] == IA64_OPND_B2)
8283 specs[count] = tmpl;
8284 specs[count++].index =
8285 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8289 break;
8291 case IA64_RS_CPUID: /* four or more registers */
8292 if (note == 3)
8294 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
8296 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8297 if (regno >= 0 && regno < NELEMS (gr_values)
8298 && KNOWN (regno))
8300 specs[count] = tmpl;
8301 specs[count++].index = gr_values[regno].value & 0xFF;
8303 else
8305 specs[count] = tmpl;
8306 specs[count++].specific = 0;
8310 else
8312 UNHANDLED;
8314 break;
8316 case IA64_RS_DBR: /* four or more registers */
8317 if (note == 3)
8319 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
8321 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8322 if (regno >= 0 && regno < NELEMS (gr_values)
8323 && KNOWN (regno))
8325 specs[count] = tmpl;
8326 specs[count++].index = gr_values[regno].value & 0xFF;
8328 else
8330 specs[count] = tmpl;
8331 specs[count++].specific = 0;
8335 else if (note == 0 && !rsrc_write)
8337 specs[count] = tmpl;
8338 specs[count++].specific = 0;
8340 else
8342 UNHANDLED;
8344 break;
8346 case IA64_RS_IBR: /* four or more registers */
8347 if (note == 3)
8349 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
8351 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8352 if (regno >= 0 && regno < NELEMS (gr_values)
8353 && KNOWN (regno))
8355 specs[count] = tmpl;
8356 specs[count++].index = gr_values[regno].value & 0xFF;
8358 else
8360 specs[count] = tmpl;
8361 specs[count++].specific = 0;
8365 else
8367 UNHANDLED;
8369 break;
8371 case IA64_RS_MSR:
8372 if (note == 5)
8374 /* These are implementation specific. Force all references to
8375 conflict with all other references. */
8376 specs[count] = tmpl;
8377 specs[count++].specific = 0;
8379 else
8381 UNHANDLED;
8383 break;
8385 case IA64_RS_PKR: /* 16 or more registers */
8386 if (note == 3 || note == 4)
8388 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
8390 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8391 if (regno >= 0 && regno < NELEMS (gr_values)
8392 && KNOWN (regno))
8394 if (note == 3)
8396 specs[count] = tmpl;
8397 specs[count++].index = gr_values[regno].value & 0xFF;
8399 else
8400 for (i = 0; i < NELEMS (gr_values); i++)
8402 /* Uses all registers *except* the one in R3. */
8403 if ((unsigned)i != (gr_values[regno].value & 0xFF))
8405 specs[count] = tmpl;
8406 specs[count++].index = i;
8410 else
8412 specs[count] = tmpl;
8413 specs[count++].specific = 0;
8417 else if (note == 0)
8419 /* probe et al. */
8420 specs[count] = tmpl;
8421 specs[count++].specific = 0;
8423 break;
8425 case IA64_RS_PMC: /* four or more registers */
8426 if (note == 3)
8428 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
8429 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
8432 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
8433 ? 1 : !rsrc_write);
8434 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
8435 if (regno >= 0 && regno < NELEMS (gr_values)
8436 && KNOWN (regno))
8438 specs[count] = tmpl;
8439 specs[count++].index = gr_values[regno].value & 0xFF;
8441 else
8443 specs[count] = tmpl;
8444 specs[count++].specific = 0;
8448 else
8450 UNHANDLED;
8452 break;
8454 case IA64_RS_PMD: /* four or more registers */
8455 if (note == 3)
8457 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
8459 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8460 if (regno >= 0 && regno < NELEMS (gr_values)
8461 && KNOWN (regno))
8463 specs[count] = tmpl;
8464 specs[count++].index = gr_values[regno].value & 0xFF;
8466 else
8468 specs[count] = tmpl;
8469 specs[count++].specific = 0;
8473 else
8475 UNHANDLED;
8477 break;
8479 case IA64_RS_RR: /* eight registers */
8480 if (note == 6)
8482 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
8484 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8485 if (regno >= 0 && regno < NELEMS (gr_values)
8486 && KNOWN (regno))
8488 specs[count] = tmpl;
8489 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
8491 else
8493 specs[count] = tmpl;
8494 specs[count++].specific = 0;
8498 else if (note == 0 && !rsrc_write)
8500 specs[count] = tmpl;
8501 specs[count++].specific = 0;
8503 else
8505 UNHANDLED;
8507 break;
8509 case IA64_RS_CR_IRR:
8510 if (note == 0)
8512 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
8513 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
8514 if (rsrc_write
8515 && idesc->operands[1] == IA64_OPND_CR3
8516 && regno == CR_IVR)
8518 for (i = 0; i < 4; i++)
8520 specs[count] = tmpl;
8521 specs[count++].index = CR_IRR0 + i;
8525 else if (note == 1)
8527 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8528 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8529 && regno >= CR_IRR0
8530 && regno <= CR_IRR3)
8532 specs[count] = tmpl;
8533 specs[count++].index = regno;
8536 else
8538 UNHANDLED;
8540 break;
8542 case IA64_RS_CR_LRR:
8543 if (note != 1)
8545 UNHANDLED;
8547 else
8549 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8550 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8551 && (regno == CR_LRR0 || regno == CR_LRR1))
8553 specs[count] = tmpl;
8554 specs[count++].index = regno;
8557 break;
8559 case IA64_RS_CR:
8560 if (note == 1)
8562 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8564 specs[count] = tmpl;
8565 specs[count++].index =
8566 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8569 else
8571 UNHANDLED;
8573 break;
8575 case IA64_RS_FR:
8576 case IA64_RS_FRb:
8577 if (note != 1)
8579 UNHANDLED;
8581 else if (rsrc_write)
8583 if (dep->specifier == IA64_RS_FRb
8584 && idesc->operands[0] == IA64_OPND_F1)
8586 specs[count] = tmpl;
8587 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8590 else
8592 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8594 if (idesc->operands[i] == IA64_OPND_F2
8595 || idesc->operands[i] == IA64_OPND_F3
8596 || idesc->operands[i] == IA64_OPND_F4)
8598 specs[count] = tmpl;
8599 specs[count++].index =
8600 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8604 break;
8606 case IA64_RS_GR:
8607 if (note == 13)
8609 /* This reference applies only to the GR whose value is loaded with
8610 data returned from memory. */
8611 specs[count] = tmpl;
8612 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8614 else if (note == 1)
8616 if (rsrc_write)
8618 for (i = 0; i < idesc->num_outputs; i++)
8619 if (idesc->operands[i] == IA64_OPND_R1
8620 || idesc->operands[i] == IA64_OPND_R2
8621 || idesc->operands[i] == IA64_OPND_R3)
8623 specs[count] = tmpl;
8624 specs[count++].index =
8625 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8627 if (idesc->flags & IA64_OPCODE_POSTINC)
8628 for (i = 0; i < NELEMS (idesc->operands); i++)
8629 if (idesc->operands[i] == IA64_OPND_MR3)
8631 specs[count] = tmpl;
8632 specs[count++].index =
8633 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8636 else
8638 /* Look for anything that reads a GR. */
8639 for (i = 0; i < NELEMS (idesc->operands); i++)
8641 if (idesc->operands[i] == IA64_OPND_MR3
8642 || idesc->operands[i] == IA64_OPND_CPUID_R3
8643 || idesc->operands[i] == IA64_OPND_DBR_R3
8644 || idesc->operands[i] == IA64_OPND_IBR_R3
8645 || idesc->operands[i] == IA64_OPND_MSR_R3
8646 || idesc->operands[i] == IA64_OPND_PKR_R3
8647 || idesc->operands[i] == IA64_OPND_PMC_R3
8648 || idesc->operands[i] == IA64_OPND_PMD_R3
8649 || idesc->operands[i] == IA64_OPND_RR_R3
8650 || ((i >= idesc->num_outputs)
8651 && (idesc->operands[i] == IA64_OPND_R1
8652 || idesc->operands[i] == IA64_OPND_R2
8653 || idesc->operands[i] == IA64_OPND_R3
8654 /* addl source register. */
8655 || idesc->operands[i] == IA64_OPND_R3_2)))
8657 specs[count] = tmpl;
8658 specs[count++].index =
8659 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8664 else
8666 UNHANDLED;
8668 break;
8670 /* This is the same as IA64_RS_PRr, except that the register range is
8671 from 1 - 15, and there are no rotating register reads/writes here. */
8672 case IA64_RS_PR:
8673 if (note == 0)
8675 for (i = 1; i < 16; i++)
8677 specs[count] = tmpl;
8678 specs[count++].index = i;
8681 else if (note == 7)
8683 valueT mask = 0;
8684 /* Mark only those registers indicated by the mask. */
8685 if (rsrc_write)
8687 mask = CURR_SLOT.opnd[2].X_add_number;
8688 for (i = 1; i < 16; i++)
8689 if (mask & ((valueT) 1 << i))
8691 specs[count] = tmpl;
8692 specs[count++].index = i;
8695 else
8697 UNHANDLED;
8700 else if (note == 11) /* note 11 implies note 1 as well */
8702 if (rsrc_write)
8704 for (i = 0; i < idesc->num_outputs; i++)
8706 if (idesc->operands[i] == IA64_OPND_P1
8707 || idesc->operands[i] == IA64_OPND_P2)
8709 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8710 if (regno >= 1 && regno < 16)
8712 specs[count] = tmpl;
8713 specs[count++].index = regno;
8718 else
8720 UNHANDLED;
8723 else if (note == 12)
8725 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8727 specs[count] = tmpl;
8728 specs[count++].index = CURR_SLOT.qp_regno;
8731 else if (note == 1)
8733 if (rsrc_write)
8735 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8736 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8737 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8738 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8740 if ((idesc->operands[0] == IA64_OPND_P1
8741 || idesc->operands[0] == IA64_OPND_P2)
8742 && p1 >= 1 && p1 < 16)
8744 specs[count] = tmpl;
8745 specs[count].cmp_type =
8746 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8747 specs[count++].index = p1;
8749 if ((idesc->operands[1] == IA64_OPND_P1
8750 || idesc->operands[1] == IA64_OPND_P2)
8751 && p2 >= 1 && p2 < 16)
8753 specs[count] = tmpl;
8754 specs[count].cmp_type =
8755 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8756 specs[count++].index = p2;
8759 else
8761 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8763 specs[count] = tmpl;
8764 specs[count++].index = CURR_SLOT.qp_regno;
8766 if (idesc->operands[1] == IA64_OPND_PR)
8768 for (i = 1; i < 16; i++)
8770 specs[count] = tmpl;
8771 specs[count++].index = i;
8776 else
8778 UNHANDLED;
8780 break;
8782 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8783 simplified cases of this. */
8784 case IA64_RS_PRr:
8785 if (note == 0)
8787 for (i = 16; i < 63; i++)
8789 specs[count] = tmpl;
8790 specs[count++].index = i;
8793 else if (note == 7)
8795 valueT mask = 0;
8796 /* Mark only those registers indicated by the mask. */
8797 if (rsrc_write
8798 && idesc->operands[0] == IA64_OPND_PR)
8800 mask = CURR_SLOT.opnd[2].X_add_number;
8801 if (mask & ((valueT) 1 << 16))
8802 for (i = 16; i < 63; i++)
8804 specs[count] = tmpl;
8805 specs[count++].index = i;
8808 else if (rsrc_write
8809 && idesc->operands[0] == IA64_OPND_PR_ROT)
8811 for (i = 16; i < 63; i++)
8813 specs[count] = tmpl;
8814 specs[count++].index = i;
8817 else
8819 UNHANDLED;
8822 else if (note == 11) /* note 11 implies note 1 as well */
8824 if (rsrc_write)
8826 for (i = 0; i < idesc->num_outputs; i++)
8828 if (idesc->operands[i] == IA64_OPND_P1
8829 || idesc->operands[i] == IA64_OPND_P2)
8831 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8832 if (regno >= 16 && regno < 63)
8834 specs[count] = tmpl;
8835 specs[count++].index = regno;
8840 else
8842 UNHANDLED;
8845 else if (note == 12)
8847 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8849 specs[count] = tmpl;
8850 specs[count++].index = CURR_SLOT.qp_regno;
8853 else if (note == 1)
8855 if (rsrc_write)
8857 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8858 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8859 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8860 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8862 if ((idesc->operands[0] == IA64_OPND_P1
8863 || idesc->operands[0] == IA64_OPND_P2)
8864 && p1 >= 16 && p1 < 63)
8866 specs[count] = tmpl;
8867 specs[count].cmp_type =
8868 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8869 specs[count++].index = p1;
8871 if ((idesc->operands[1] == IA64_OPND_P1
8872 || idesc->operands[1] == IA64_OPND_P2)
8873 && p2 >= 16 && p2 < 63)
8875 specs[count] = tmpl;
8876 specs[count].cmp_type =
8877 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8878 specs[count++].index = p2;
8881 else
8883 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8885 specs[count] = tmpl;
8886 specs[count++].index = CURR_SLOT.qp_regno;
8888 if (idesc->operands[1] == IA64_OPND_PR)
8890 for (i = 16; i < 63; i++)
8892 specs[count] = tmpl;
8893 specs[count++].index = i;
8898 else
8900 UNHANDLED;
8902 break;
8904 case IA64_RS_PSR:
8905 /* Verify that the instruction is using the PSR bit indicated in
8906 dep->regindex. */
8907 if (note == 0)
8909 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8911 if (dep->regindex < 6)
8913 specs[count++] = tmpl;
8916 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8918 if (dep->regindex < 32
8919 || dep->regindex == 35
8920 || dep->regindex == 36
8921 || (!rsrc_write && dep->regindex == PSR_CPL))
8923 specs[count++] = tmpl;
8926 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8928 if (dep->regindex < 32
8929 || dep->regindex == 35
8930 || dep->regindex == 36
8931 || (rsrc_write && dep->regindex == PSR_CPL))
8933 specs[count++] = tmpl;
8936 else
8938 /* Several PSR bits have very specific dependencies. */
8939 switch (dep->regindex)
8941 default:
8942 specs[count++] = tmpl;
8943 break;
8944 case PSR_IC:
8945 if (rsrc_write)
8947 specs[count++] = tmpl;
8949 else
8951 /* Only certain CR accesses use PSR.ic */
8952 if (idesc->operands[0] == IA64_OPND_CR3
8953 || idesc->operands[1] == IA64_OPND_CR3)
8955 int index =
8956 ((idesc->operands[0] == IA64_OPND_CR3)
8957 ? 0 : 1);
8958 int regno =
8959 CURR_SLOT.opnd[index].X_add_number - REG_CR;
8961 switch (regno)
8963 default:
8964 break;
8965 case CR_ITIR:
8966 case CR_IFS:
8967 case CR_IIM:
8968 case CR_IIP:
8969 case CR_IPSR:
8970 case CR_ISR:
8971 case CR_IFA:
8972 case CR_IHA:
8973 case CR_IIPA:
8974 specs[count++] = tmpl;
8975 break;
8979 break;
8980 case PSR_CPL:
8981 if (rsrc_write)
8983 specs[count++] = tmpl;
8985 else
8987 /* Only some AR accesses use cpl */
8988 if (idesc->operands[0] == IA64_OPND_AR3
8989 || idesc->operands[1] == IA64_OPND_AR3)
8991 int index =
8992 ((idesc->operands[0] == IA64_OPND_AR3)
8993 ? 0 : 1);
8994 int regno =
8995 CURR_SLOT.opnd[index].X_add_number - REG_AR;
8997 if (regno == AR_ITC
8998 || (index == 0
8999 && (regno == AR_ITC
9000 || regno == AR_RSC
9001 || (regno >= AR_K0
9002 && regno <= AR_K7))))
9004 specs[count++] = tmpl;
9007 else
9009 specs[count++] = tmpl;
9011 break;
9016 else if (note == 7)
9018 valueT mask = 0;
9019 if (idesc->operands[0] == IA64_OPND_IMMU24)
9021 mask = CURR_SLOT.opnd[0].X_add_number;
9023 else
9025 UNHANDLED;
9027 if (mask & ((valueT) 1 << dep->regindex))
9029 specs[count++] = tmpl;
9032 else if (note == 8)
9034 int min = dep->regindex == PSR_DFL ? 2 : 32;
9035 int max = dep->regindex == PSR_DFL ? 31 : 127;
9036 /* dfh is read on FR32-127; dfl is read on FR2-31 */
9037 for (i = 0; i < NELEMS (idesc->operands); i++)
9039 if (idesc->operands[i] == IA64_OPND_F1
9040 || idesc->operands[i] == IA64_OPND_F2
9041 || idesc->operands[i] == IA64_OPND_F3
9042 || idesc->operands[i] == IA64_OPND_F4)
9044 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9045 if (reg >= min && reg <= max)
9047 specs[count++] = tmpl;
9052 else if (note == 9)
9054 int min = dep->regindex == PSR_MFL ? 2 : 32;
9055 int max = dep->regindex == PSR_MFL ? 31 : 127;
9056 /* mfh is read on writes to FR32-127; mfl is read on writes to
9057 FR2-31 */
9058 for (i = 0; i < idesc->num_outputs; i++)
9060 if (idesc->operands[i] == IA64_OPND_F1)
9062 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9063 if (reg >= min && reg <= max)
9065 specs[count++] = tmpl;
9070 else if (note == 10)
9072 for (i = 0; i < NELEMS (idesc->operands); i++)
9074 if (idesc->operands[i] == IA64_OPND_R1
9075 || idesc->operands[i] == IA64_OPND_R2
9076 || idesc->operands[i] == IA64_OPND_R3)
9078 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9079 if (regno >= 16 && regno <= 31)
9081 specs[count++] = tmpl;
9086 else
9088 UNHANDLED;
9090 break;
9092 case IA64_RS_AR_FPSR:
9093 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
9095 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9096 if (regno == AR_FPSR)
9098 specs[count++] = tmpl;
9101 else
9103 specs[count++] = tmpl;
9105 break;
9107 case IA64_RS_ARX:
9108 /* Handle all AR[REG] resources */
9109 if (note == 0 || note == 1)
9111 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9112 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
9113 && regno == dep->regindex)
9115 specs[count++] = tmpl;
9117 /* other AR[REG] resources may be affected by AR accesses */
9118 else if (idesc->operands[0] == IA64_OPND_AR3)
9120 /* AR[] writes */
9121 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
9122 switch (dep->regindex)
9124 default:
9125 break;
9126 case AR_BSP:
9127 case AR_RNAT:
9128 if (regno == AR_BSPSTORE)
9130 specs[count++] = tmpl;
9132 case AR_RSC:
9133 if (!rsrc_write &&
9134 (regno == AR_BSPSTORE
9135 || regno == AR_RNAT))
9137 specs[count++] = tmpl;
9139 break;
9142 else if (idesc->operands[1] == IA64_OPND_AR3)
9144 /* AR[] reads */
9145 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
9146 switch (dep->regindex)
9148 default:
9149 break;
9150 case AR_RSC:
9151 if (regno == AR_BSPSTORE || regno == AR_RNAT)
9153 specs[count++] = tmpl;
9155 break;
9158 else
9160 specs[count++] = tmpl;
9163 else
9165 UNHANDLED;
9167 break;
9169 case IA64_RS_CRX:
9170 /* Handle all CR[REG] resources */
9171 if (note == 0 || note == 1)
9173 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
9175 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
9176 if (regno == dep->regindex)
9178 specs[count++] = tmpl;
9180 else if (!rsrc_write)
9182 /* Reads from CR[IVR] affect other resources. */
9183 if (regno == CR_IVR)
9185 if ((dep->regindex >= CR_IRR0
9186 && dep->regindex <= CR_IRR3)
9187 || dep->regindex == CR_TPR)
9189 specs[count++] = tmpl;
9194 else
9196 specs[count++] = tmpl;
9199 else
9201 UNHANDLED;
9203 break;
9205 case IA64_RS_INSERVICE:
9206 /* look for write of EOI (67) or read of IVR (65) */
9207 if ((idesc->operands[0] == IA64_OPND_CR3
9208 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
9209 || (idesc->operands[1] == IA64_OPND_CR3
9210 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
9212 specs[count++] = tmpl;
9214 break;
9216 case IA64_RS_GR0:
9217 if (note == 1)
9219 specs[count++] = tmpl;
9221 else
9223 UNHANDLED;
9225 break;
9227 case IA64_RS_CFM:
9228 if (note != 2)
9230 specs[count++] = tmpl;
9232 else
9234 /* Check if any of the registers accessed are in the rotating region.
9235 mov to/from pr accesses CFM only when qp_regno is in the rotating
9236 region */
9237 for (i = 0; i < NELEMS (idesc->operands); i++)
9239 if (idesc->operands[i] == IA64_OPND_R1
9240 || idesc->operands[i] == IA64_OPND_R2
9241 || idesc->operands[i] == IA64_OPND_R3)
9243 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9244 /* Assumes that md.rot.num_regs is always valid */
9245 if (md.rot.num_regs > 0
9246 && num > 31
9247 && num < 31 + md.rot.num_regs)
9249 specs[count] = tmpl;
9250 specs[count++].specific = 0;
9253 else if (idesc->operands[i] == IA64_OPND_F1
9254 || idesc->operands[i] == IA64_OPND_F2
9255 || idesc->operands[i] == IA64_OPND_F3
9256 || idesc->operands[i] == IA64_OPND_F4)
9258 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9259 if (num > 31)
9261 specs[count] = tmpl;
9262 specs[count++].specific = 0;
9265 else if (idesc->operands[i] == IA64_OPND_P1
9266 || idesc->operands[i] == IA64_OPND_P2)
9268 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
9269 if (num > 15)
9271 specs[count] = tmpl;
9272 specs[count++].specific = 0;
9276 if (CURR_SLOT.qp_regno > 15)
9278 specs[count] = tmpl;
9279 specs[count++].specific = 0;
9282 break;
9284 /* This is the same as IA64_RS_PRr, except simplified to account for
9285 the fact that there is only one register. */
9286 case IA64_RS_PR63:
9287 if (note == 0)
9289 specs[count++] = tmpl;
9291 else if (note == 7)
9293 valueT mask = 0;
9294 if (idesc->operands[2] == IA64_OPND_IMM17)
9295 mask = CURR_SLOT.opnd[2].X_add_number;
9296 if (mask & ((valueT) 1 << 63))
9297 specs[count++] = tmpl;
9299 else if (note == 11)
9301 if ((idesc->operands[0] == IA64_OPND_P1
9302 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
9303 || (idesc->operands[1] == IA64_OPND_P2
9304 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
9306 specs[count++] = tmpl;
9309 else if (note == 12)
9311 if (CURR_SLOT.qp_regno == 63)
9313 specs[count++] = tmpl;
9316 else if (note == 1)
9318 if (rsrc_write)
9320 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9321 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9322 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
9323 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
9325 if (p1 == 63
9326 && (idesc->operands[0] == IA64_OPND_P1
9327 || idesc->operands[0] == IA64_OPND_P2))
9329 specs[count] = tmpl;
9330 specs[count++].cmp_type =
9331 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
9333 if (p2 == 63
9334 && (idesc->operands[1] == IA64_OPND_P1
9335 || idesc->operands[1] == IA64_OPND_P2))
9337 specs[count] = tmpl;
9338 specs[count++].cmp_type =
9339 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9342 else
9344 if (CURR_SLOT.qp_regno == 63)
9346 specs[count++] = tmpl;
9350 else
9352 UNHANDLED;
9354 break;
9356 case IA64_RS_RSE:
9357 /* FIXME we can identify some individual RSE written resources, but RSE
9358 read resources have not yet been completely identified, so for now
9359 treat RSE as a single resource */
9360 if (strncmp (idesc->name, "mov", 3) == 0)
9362 if (rsrc_write)
9364 if (idesc->operands[0] == IA64_OPND_AR3
9365 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
9367 specs[count++] = tmpl;
9370 else
9372 if (idesc->operands[0] == IA64_OPND_AR3)
9374 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
9375 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
9377 specs[count++] = tmpl;
9380 else if (idesc->operands[1] == IA64_OPND_AR3)
9382 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
9383 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
9384 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
9386 specs[count++] = tmpl;
9391 else
9393 specs[count++] = tmpl;
9395 break;
9397 case IA64_RS_ANY:
9398 /* FIXME -- do any of these need to be non-specific? */
9399 specs[count++] = tmpl;
9400 break;
9402 default:
9403 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
9404 break;
9407 return count;
9410 /* Clear branch flags on marked resources. This breaks the link between the
9411 QP of the marking instruction and a subsequent branch on the same QP. */
9413 static void
9414 clear_qp_branch_flag (mask)
9415 valueT mask;
9417 int i;
9418 for (i = 0; i < regdepslen; i++)
9420 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
9421 if ((bit & mask) != 0)
9423 regdeps[i].link_to_qp_branch = 0;
9428 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
9429 any mutexes which contain one of the PRs and create new ones when
9430 needed. */
9432 static int
9433 update_qp_mutex (valueT mask)
9435 int i;
9436 int add = 0;
9438 i = 0;
9439 while (i < qp_mutexeslen)
9441 if ((qp_mutexes[i].prmask & mask) != 0)
9443 /* If it destroys and creates the same mutex, do nothing. */
9444 if (qp_mutexes[i].prmask == mask
9445 && qp_mutexes[i].path == md.path)
9447 i++;
9448 add = -1;
9450 else
9452 int keep = 0;
9454 if (md.debug_dv)
9456 fprintf (stderr, " Clearing mutex relation");
9457 print_prmask (qp_mutexes[i].prmask);
9458 fprintf (stderr, "\n");
9461 /* Deal with the old mutex with more than 3+ PRs only if
9462 the new mutex on the same execution path with it.
9464 FIXME: The 3+ mutex support is incomplete.
9465 dot_pred_rel () may be a better place to fix it. */
9466 if (qp_mutexes[i].path == md.path)
9468 /* If it is a proper subset of the mutex, create a
9469 new mutex. */
9470 if (add == 0
9471 && (qp_mutexes[i].prmask & mask) == mask)
9472 add = 1;
9474 qp_mutexes[i].prmask &= ~mask;
9475 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
9477 /* Modify the mutex if there are more than one
9478 PR left. */
9479 keep = 1;
9480 i++;
9484 if (keep == 0)
9485 /* Remove the mutex. */
9486 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9489 else
9490 ++i;
9493 if (add == 1)
9494 add_qp_mutex (mask);
9496 return add;
9499 /* Remove any mutexes which contain any of the PRs indicated in the mask.
9501 Any changes to a PR clears the mutex relations which include that PR. */
9503 static void
9504 clear_qp_mutex (mask)
9505 valueT mask;
9507 int i;
9509 i = 0;
9510 while (i < qp_mutexeslen)
9512 if ((qp_mutexes[i].prmask & mask) != 0)
9514 if (md.debug_dv)
9516 fprintf (stderr, " Clearing mutex relation");
9517 print_prmask (qp_mutexes[i].prmask);
9518 fprintf (stderr, "\n");
9520 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9522 else
9523 ++i;
9527 /* Clear implies relations which contain PRs in the given masks.
9528 P1_MASK indicates the source of the implies relation, while P2_MASK
9529 indicates the implied PR. */
9531 static void
9532 clear_qp_implies (p1_mask, p2_mask)
9533 valueT p1_mask;
9534 valueT p2_mask;
9536 int i;
9538 i = 0;
9539 while (i < qp_implieslen)
9541 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
9542 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
9544 if (md.debug_dv)
9545 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
9546 qp_implies[i].p1, qp_implies[i].p2);
9547 qp_implies[i] = qp_implies[--qp_implieslen];
9549 else
9550 ++i;
9554 /* Add the PRs specified to the list of implied relations. */
9556 static void
9557 add_qp_imply (p1, p2)
9558 int p1, p2;
9560 valueT mask;
9561 valueT bit;
9562 int i;
9564 /* p0 is not meaningful here. */
9565 if (p1 == 0 || p2 == 0)
9566 abort ();
9568 if (p1 == p2)
9569 return;
9571 /* If it exists already, ignore it. */
9572 for (i = 0; i < qp_implieslen; i++)
9574 if (qp_implies[i].p1 == p1
9575 && qp_implies[i].p2 == p2
9576 && qp_implies[i].path == md.path
9577 && !qp_implies[i].p2_branched)
9578 return;
9581 if (qp_implieslen == qp_impliestotlen)
9583 qp_impliestotlen += 20;
9584 qp_implies = (struct qp_imply *)
9585 xrealloc ((void *) qp_implies,
9586 qp_impliestotlen * sizeof (struct qp_imply));
9588 if (md.debug_dv)
9589 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9590 qp_implies[qp_implieslen].p1 = p1;
9591 qp_implies[qp_implieslen].p2 = p2;
9592 qp_implies[qp_implieslen].path = md.path;
9593 qp_implies[qp_implieslen++].p2_branched = 0;
9595 /* Add in the implied transitive relations; for everything that p2 implies,
9596 make p1 imply that, too; for everything that implies p1, make it imply p2
9597 as well. */
9598 for (i = 0; i < qp_implieslen; i++)
9600 if (qp_implies[i].p1 == p2)
9601 add_qp_imply (p1, qp_implies[i].p2);
9602 if (qp_implies[i].p2 == p1)
9603 add_qp_imply (qp_implies[i].p1, p2);
9605 /* Add in mutex relations implied by this implies relation; for each mutex
9606 relation containing p2, duplicate it and replace p2 with p1. */
9607 bit = (valueT) 1 << p1;
9608 mask = (valueT) 1 << p2;
9609 for (i = 0; i < qp_mutexeslen; i++)
9611 if (qp_mutexes[i].prmask & mask)
9612 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9616 /* Add the PRs specified in the mask to the mutex list; this means that only
9617 one of the PRs can be true at any time. PR0 should never be included in
9618 the mask. */
9620 static void
9621 add_qp_mutex (mask)
9622 valueT mask;
9624 if (mask & 0x1)
9625 abort ();
9627 if (qp_mutexeslen == qp_mutexestotlen)
9629 qp_mutexestotlen += 20;
9630 qp_mutexes = (struct qpmutex *)
9631 xrealloc ((void *) qp_mutexes,
9632 qp_mutexestotlen * sizeof (struct qpmutex));
9634 if (md.debug_dv)
9636 fprintf (stderr, " Registering mutex on");
9637 print_prmask (mask);
9638 fprintf (stderr, "\n");
9640 qp_mutexes[qp_mutexeslen].path = md.path;
9641 qp_mutexes[qp_mutexeslen++].prmask = mask;
9644 static int
9645 has_suffix_p (name, suffix)
9646 const char *name;
9647 const char *suffix;
9649 size_t namelen = strlen (name);
9650 size_t sufflen = strlen (suffix);
9652 if (namelen <= sufflen)
9653 return 0;
9654 return strcmp (name + namelen - sufflen, suffix) == 0;
9657 static void
9658 clear_register_values ()
9660 int i;
9661 if (md.debug_dv)
9662 fprintf (stderr, " Clearing register values\n");
9663 for (i = 1; i < NELEMS (gr_values); i++)
9664 gr_values[i].known = 0;
9667 /* Keep track of register values/changes which affect DV tracking.
9669 optimization note: should add a flag to classes of insns where otherwise we
9670 have to examine a group of strings to identify them. */
9672 static void
9673 note_register_values (idesc)
9674 struct ia64_opcode *idesc;
9676 valueT qp_changemask = 0;
9677 int i;
9679 /* Invalidate values for registers being written to. */
9680 for (i = 0; i < idesc->num_outputs; i++)
9682 if (idesc->operands[i] == IA64_OPND_R1
9683 || idesc->operands[i] == IA64_OPND_R2
9684 || idesc->operands[i] == IA64_OPND_R3)
9686 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9687 if (regno > 0 && regno < NELEMS (gr_values))
9688 gr_values[regno].known = 0;
9690 else if (idesc->operands[i] == IA64_OPND_R3_2)
9692 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9693 if (regno > 0 && regno < 4)
9694 gr_values[regno].known = 0;
9696 else if (idesc->operands[i] == IA64_OPND_P1
9697 || idesc->operands[i] == IA64_OPND_P2)
9699 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9700 qp_changemask |= (valueT) 1 << regno;
9702 else if (idesc->operands[i] == IA64_OPND_PR)
9704 if (idesc->operands[2] & (valueT) 0x10000)
9705 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9706 else
9707 qp_changemask = idesc->operands[2];
9708 break;
9710 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9712 if (idesc->operands[1] & ((valueT) 1 << 43))
9713 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9714 else
9715 qp_changemask = idesc->operands[1];
9716 qp_changemask &= ~(valueT) 0xFFFF;
9717 break;
9721 /* Always clear qp branch flags on any PR change. */
9722 /* FIXME there may be exceptions for certain compares. */
9723 clear_qp_branch_flag (qp_changemask);
9725 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9726 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9728 qp_changemask |= ~(valueT) 0xFFFF;
9729 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9731 for (i = 32; i < 32 + md.rot.num_regs; i++)
9732 gr_values[i].known = 0;
9734 clear_qp_mutex (qp_changemask);
9735 clear_qp_implies (qp_changemask, qp_changemask);
9737 /* After a call, all register values are undefined, except those marked
9738 as "safe". */
9739 else if (strncmp (idesc->name, "br.call", 6) == 0
9740 || strncmp (idesc->name, "brl.call", 7) == 0)
9742 /* FIXME keep GR values which are marked as "safe_across_calls" */
9743 clear_register_values ();
9744 clear_qp_mutex (~qp_safe_across_calls);
9745 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9746 clear_qp_branch_flag (~qp_safe_across_calls);
9748 else if (is_interruption_or_rfi (idesc)
9749 || is_taken_branch (idesc))
9751 clear_register_values ();
9752 clear_qp_mutex (~(valueT) 0);
9753 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9755 /* Look for mutex and implies relations. */
9756 else if ((idesc->operands[0] == IA64_OPND_P1
9757 || idesc->operands[0] == IA64_OPND_P2)
9758 && (idesc->operands[1] == IA64_OPND_P1
9759 || idesc->operands[1] == IA64_OPND_P2))
9761 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9762 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9763 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9764 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9766 /* If both PRs are PR0, we can't really do anything. */
9767 if (p1 == 0 && p2 == 0)
9769 if (md.debug_dv)
9770 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9772 /* In general, clear mutexes and implies which include P1 or P2,
9773 with the following exceptions. */
9774 else if (has_suffix_p (idesc->name, ".or.andcm")
9775 || has_suffix_p (idesc->name, ".and.orcm"))
9777 clear_qp_implies (p2mask, p1mask);
9779 else if (has_suffix_p (idesc->name, ".andcm")
9780 || has_suffix_p (idesc->name, ".and"))
9782 clear_qp_implies (0, p1mask | p2mask);
9784 else if (has_suffix_p (idesc->name, ".orcm")
9785 || has_suffix_p (idesc->name, ".or"))
9787 clear_qp_mutex (p1mask | p2mask);
9788 clear_qp_implies (p1mask | p2mask, 0);
9790 else
9792 int added = 0;
9794 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9796 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9797 if (p1 == 0 || p2 == 0)
9798 clear_qp_mutex (p1mask | p2mask);
9799 else
9800 added = update_qp_mutex (p1mask | p2mask);
9802 if (CURR_SLOT.qp_regno == 0
9803 || has_suffix_p (idesc->name, ".unc"))
9805 if (added == 0 && p1 && p2)
9806 add_qp_mutex (p1mask | p2mask);
9807 if (CURR_SLOT.qp_regno != 0)
9809 if (p1)
9810 add_qp_imply (p1, CURR_SLOT.qp_regno);
9811 if (p2)
9812 add_qp_imply (p2, CURR_SLOT.qp_regno);
9817 /* Look for mov imm insns into GRs. */
9818 else if (idesc->operands[0] == IA64_OPND_R1
9819 && (idesc->operands[1] == IA64_OPND_IMM22
9820 || idesc->operands[1] == IA64_OPND_IMMU64)
9821 && CURR_SLOT.opnd[1].X_op == O_constant
9822 && (strcmp (idesc->name, "mov") == 0
9823 || strcmp (idesc->name, "movl") == 0))
9825 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9826 if (regno > 0 && regno < NELEMS (gr_values))
9828 gr_values[regno].known = 1;
9829 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9830 gr_values[regno].path = md.path;
9831 if (md.debug_dv)
9833 fprintf (stderr, " Know gr%d = ", regno);
9834 fprintf_vma (stderr, gr_values[regno].value);
9835 fputs ("\n", stderr);
9839 /* Look for dep.z imm insns. */
9840 else if (idesc->operands[0] == IA64_OPND_R1
9841 && idesc->operands[1] == IA64_OPND_IMM8
9842 && strcmp (idesc->name, "dep.z") == 0)
9844 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9845 if (regno > 0 && regno < NELEMS (gr_values))
9847 valueT value = CURR_SLOT.opnd[1].X_add_number;
9849 if (CURR_SLOT.opnd[3].X_add_number < 64)
9850 value &= ((valueT)1 << CURR_SLOT.opnd[3].X_add_number) - 1;
9851 value <<= CURR_SLOT.opnd[2].X_add_number;
9852 gr_values[regno].known = 1;
9853 gr_values[regno].value = value;
9854 gr_values[regno].path = md.path;
9855 if (md.debug_dv)
9857 fprintf (stderr, " Know gr%d = ", regno);
9858 fprintf_vma (stderr, gr_values[regno].value);
9859 fputs ("\n", stderr);
9863 else
9865 clear_qp_mutex (qp_changemask);
9866 clear_qp_implies (qp_changemask, qp_changemask);
9870 /* Return whether the given predicate registers are currently mutex. */
9872 static int
9873 qp_mutex (p1, p2, path)
9874 int p1;
9875 int p2;
9876 int path;
9878 int i;
9879 valueT mask;
9881 if (p1 != p2)
9883 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9884 for (i = 0; i < qp_mutexeslen; i++)
9886 if (qp_mutexes[i].path >= path
9887 && (qp_mutexes[i].prmask & mask) == mask)
9888 return 1;
9891 return 0;
9894 /* Return whether the given resource is in the given insn's list of chks
9895 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9896 conflict. */
9898 static int
9899 resources_match (rs, idesc, note, qp_regno, path)
9900 struct rsrc *rs;
9901 struct ia64_opcode *idesc;
9902 int note;
9903 int qp_regno;
9904 int path;
9906 struct rsrc specs[MAX_SPECS];
9907 int count;
9909 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9910 we don't need to check. One exception is note 11, which indicates that
9911 target predicates are written regardless of PR[qp]. */
9912 if (qp_mutex (rs->qp_regno, qp_regno, path)
9913 && note != 11)
9914 return 0;
9916 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9917 while (count-- > 0)
9919 /* UNAT checking is a bit more specific than other resources */
9920 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9921 && specs[count].mem_offset.hint
9922 && rs->mem_offset.hint)
9924 if (rs->mem_offset.base == specs[count].mem_offset.base)
9926 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9927 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9928 return 1;
9929 else
9930 continue;
9934 /* Skip apparent PR write conflicts where both writes are an AND or both
9935 writes are an OR. */
9936 if (rs->dependency->specifier == IA64_RS_PR
9937 || rs->dependency->specifier == IA64_RS_PRr
9938 || rs->dependency->specifier == IA64_RS_PR63)
9940 if (specs[count].cmp_type != CMP_NONE
9941 && specs[count].cmp_type == rs->cmp_type)
9943 if (md.debug_dv)
9944 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
9945 dv_mode[rs->dependency->mode],
9946 rs->dependency->specifier != IA64_RS_PR63 ?
9947 specs[count].index : 63);
9948 continue;
9950 if (md.debug_dv)
9951 fprintf (stderr,
9952 " %s on parallel compare conflict %s vs %s on PR%d\n",
9953 dv_mode[rs->dependency->mode],
9954 dv_cmp_type[rs->cmp_type],
9955 dv_cmp_type[specs[count].cmp_type],
9956 rs->dependency->specifier != IA64_RS_PR63 ?
9957 specs[count].index : 63);
9961 /* If either resource is not specific, conservatively assume a conflict
9963 if (!specs[count].specific || !rs->specific)
9964 return 2;
9965 else if (specs[count].index == rs->index)
9966 return 1;
9969 return 0;
9972 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
9973 insert a stop to create the break. Update all resource dependencies
9974 appropriately. If QP_REGNO is non-zero, only apply the break to resources
9975 which use the same QP_REGNO and have the link_to_qp_branch flag set.
9976 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
9977 instruction. */
9979 static void
9980 insn_group_break (insert_stop, qp_regno, save_current)
9981 int insert_stop;
9982 int qp_regno;
9983 int save_current;
9985 int i;
9987 if (insert_stop && md.num_slots_in_use > 0)
9988 PREV_SLOT.end_of_insn_group = 1;
9990 if (md.debug_dv)
9992 fprintf (stderr, " Insn group break%s",
9993 (insert_stop ? " (w/stop)" : ""));
9994 if (qp_regno != 0)
9995 fprintf (stderr, " effective for QP=%d", qp_regno);
9996 fprintf (stderr, "\n");
9999 i = 0;
10000 while (i < regdepslen)
10002 const struct ia64_dependency *dep = regdeps[i].dependency;
10004 if (qp_regno != 0
10005 && regdeps[i].qp_regno != qp_regno)
10007 ++i;
10008 continue;
10011 if (save_current
10012 && CURR_SLOT.src_file == regdeps[i].file
10013 && CURR_SLOT.src_line == regdeps[i].line)
10015 ++i;
10016 continue;
10019 /* clear dependencies which are automatically cleared by a stop, or
10020 those that have reached the appropriate state of insn serialization */
10021 if (dep->semantics == IA64_DVS_IMPLIED
10022 || dep->semantics == IA64_DVS_IMPLIEDF
10023 || regdeps[i].insn_srlz == STATE_SRLZ)
10025 print_dependency ("Removing", i);
10026 regdeps[i] = regdeps[--regdepslen];
10028 else
10030 if (dep->semantics == IA64_DVS_DATA
10031 || dep->semantics == IA64_DVS_INSTR
10032 || dep->semantics == IA64_DVS_SPECIFIC)
10034 if (regdeps[i].insn_srlz == STATE_NONE)
10035 regdeps[i].insn_srlz = STATE_STOP;
10036 if (regdeps[i].data_srlz == STATE_NONE)
10037 regdeps[i].data_srlz = STATE_STOP;
10039 ++i;
10044 /* Add the given resource usage spec to the list of active dependencies. */
10046 static void
10047 mark_resource (idesc, dep, spec, depind, path)
10048 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
10049 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
10050 struct rsrc *spec;
10051 int depind;
10052 int path;
10054 if (regdepslen == regdepstotlen)
10056 regdepstotlen += 20;
10057 regdeps = (struct rsrc *)
10058 xrealloc ((void *) regdeps,
10059 regdepstotlen * sizeof (struct rsrc));
10062 regdeps[regdepslen] = *spec;
10063 regdeps[regdepslen].depind = depind;
10064 regdeps[regdepslen].path = path;
10065 regdeps[regdepslen].file = CURR_SLOT.src_file;
10066 regdeps[regdepslen].line = CURR_SLOT.src_line;
10068 print_dependency ("Adding", regdepslen);
10070 ++regdepslen;
10073 static void
10074 print_dependency (action, depind)
10075 const char *action;
10076 int depind;
10078 if (md.debug_dv)
10080 fprintf (stderr, " %s %s '%s'",
10081 action, dv_mode[(regdeps[depind].dependency)->mode],
10082 (regdeps[depind].dependency)->name);
10083 if (regdeps[depind].specific && regdeps[depind].index >= 0)
10084 fprintf (stderr, " (%d)", regdeps[depind].index);
10085 if (regdeps[depind].mem_offset.hint)
10087 fputs (" ", stderr);
10088 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
10089 fputs ("+", stderr);
10090 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
10092 fprintf (stderr, "\n");
10096 static void
10097 instruction_serialization ()
10099 int i;
10100 if (md.debug_dv)
10101 fprintf (stderr, " Instruction serialization\n");
10102 for (i = 0; i < regdepslen; i++)
10103 if (regdeps[i].insn_srlz == STATE_STOP)
10104 regdeps[i].insn_srlz = STATE_SRLZ;
10107 static void
10108 data_serialization ()
10110 int i = 0;
10111 if (md.debug_dv)
10112 fprintf (stderr, " Data serialization\n");
10113 while (i < regdepslen)
10115 if (regdeps[i].data_srlz == STATE_STOP
10116 /* Note: as of 991210, all "other" dependencies are cleared by a
10117 data serialization. This might change with new tables */
10118 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
10120 print_dependency ("Removing", i);
10121 regdeps[i] = regdeps[--regdepslen];
10123 else
10124 ++i;
10128 /* Insert stops and serializations as needed to avoid DVs. */
10130 static void
10131 remove_marked_resource (rs)
10132 struct rsrc *rs;
10134 switch (rs->dependency->semantics)
10136 case IA64_DVS_SPECIFIC:
10137 if (md.debug_dv)
10138 fprintf (stderr, "Implementation-specific, assume worst case...\n");
10139 /* ...fall through... */
10140 case IA64_DVS_INSTR:
10141 if (md.debug_dv)
10142 fprintf (stderr, "Inserting instr serialization\n");
10143 if (rs->insn_srlz < STATE_STOP)
10144 insn_group_break (1, 0, 0);
10145 if (rs->insn_srlz < STATE_SRLZ)
10147 struct slot oldslot = CURR_SLOT;
10148 /* Manually jam a srlz.i insn into the stream */
10149 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10150 CURR_SLOT.user_template = -1;
10151 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
10152 instruction_serialization ();
10153 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10154 if (++md.num_slots_in_use >= NUM_SLOTS)
10155 emit_one_bundle ();
10156 CURR_SLOT = oldslot;
10158 insn_group_break (1, 0, 0);
10159 break;
10160 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
10161 "other" types of DV are eliminated
10162 by a data serialization */
10163 case IA64_DVS_DATA:
10164 if (md.debug_dv)
10165 fprintf (stderr, "Inserting data serialization\n");
10166 if (rs->data_srlz < STATE_STOP)
10167 insn_group_break (1, 0, 0);
10169 struct slot oldslot = CURR_SLOT;
10170 /* Manually jam a srlz.d insn into the stream */
10171 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10172 CURR_SLOT.user_template = -1;
10173 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
10174 data_serialization ();
10175 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10176 if (++md.num_slots_in_use >= NUM_SLOTS)
10177 emit_one_bundle ();
10178 CURR_SLOT = oldslot;
10180 break;
10181 case IA64_DVS_IMPLIED:
10182 case IA64_DVS_IMPLIEDF:
10183 if (md.debug_dv)
10184 fprintf (stderr, "Inserting stop\n");
10185 insn_group_break (1, 0, 0);
10186 break;
10187 default:
10188 break;
10192 /* Check the resources used by the given opcode against the current dependency
10193 list.
10195 The check is run once for each execution path encountered. In this case,
10196 a unique execution path is the sequence of instructions following a code
10197 entry point, e.g. the following has three execution paths, one starting
10198 at L0, one at L1, and one at L2.
10200 L0: nop
10201 L1: add
10202 L2: add
10203 br.ret
10206 static void
10207 check_dependencies (idesc)
10208 struct ia64_opcode *idesc;
10210 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10211 int path;
10212 int i;
10214 /* Note that the number of marked resources may change within the
10215 loop if in auto mode. */
10216 i = 0;
10217 while (i < regdepslen)
10219 struct rsrc *rs = &regdeps[i];
10220 const struct ia64_dependency *dep = rs->dependency;
10221 int chkind;
10222 int note;
10223 int start_over = 0;
10225 if (dep->semantics == IA64_DVS_NONE
10226 || (chkind = depends_on (rs->depind, idesc)) == -1)
10228 ++i;
10229 continue;
10232 note = NOTE (opdeps->chks[chkind]);
10234 /* Check this resource against each execution path seen thus far. */
10235 for (path = 0; path <= md.path; path++)
10237 int matchtype;
10239 /* If the dependency wasn't on the path being checked, ignore it. */
10240 if (rs->path < path)
10241 continue;
10243 /* If the QP for this insn implies a QP which has branched, don't
10244 bother checking. Ed. NOTE: I don't think this check is terribly
10245 useful; what's the point of generating code which will only be
10246 reached if its QP is zero?
10247 This code was specifically inserted to handle the following code,
10248 based on notes from Intel's DV checking code, where p1 implies p2.
10250 mov r4 = 2
10251 (p2) br.cond L
10252 (p1) mov r4 = 7
10254 if (CURR_SLOT.qp_regno != 0)
10256 int skip = 0;
10257 int implies;
10258 for (implies = 0; implies < qp_implieslen; implies++)
10260 if (qp_implies[implies].path >= path
10261 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
10262 && qp_implies[implies].p2_branched)
10264 skip = 1;
10265 break;
10268 if (skip)
10269 continue;
10272 if ((matchtype = resources_match (rs, idesc, note,
10273 CURR_SLOT.qp_regno, path)) != 0)
10275 char msg[1024];
10276 char pathmsg[256] = "";
10277 char indexmsg[256] = "";
10278 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
10280 if (path != 0)
10281 sprintf (pathmsg, " when entry is at label '%s'",
10282 md.entry_labels[path - 1]);
10283 if (matchtype == 1 && rs->index >= 0)
10284 sprintf (indexmsg, ", specific resource number is %d",
10285 rs->index);
10286 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
10287 idesc->name,
10288 (certain ? "violates" : "may violate"),
10289 dv_mode[dep->mode], dep->name,
10290 dv_sem[dep->semantics],
10291 pathmsg, indexmsg);
10293 if (md.explicit_mode)
10295 as_warn ("%s", msg);
10296 if (path < md.path)
10297 as_warn (_("Only the first path encountering the conflict "
10298 "is reported"));
10299 as_warn_where (rs->file, rs->line,
10300 _("This is the location of the "
10301 "conflicting usage"));
10302 /* Don't bother checking other paths, to avoid duplicating
10303 the same warning */
10304 break;
10306 else
10308 if (md.debug_dv)
10309 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
10311 remove_marked_resource (rs);
10313 /* since the set of dependencies has changed, start over */
10314 /* FIXME -- since we're removing dvs as we go, we
10315 probably don't really need to start over... */
10316 start_over = 1;
10317 break;
10321 if (start_over)
10322 i = 0;
10323 else
10324 ++i;
10328 /* Register new dependencies based on the given opcode. */
10330 static void
10331 mark_resources (idesc)
10332 struct ia64_opcode *idesc;
10334 int i;
10335 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10336 int add_only_qp_reads = 0;
10338 /* A conditional branch only uses its resources if it is taken; if it is
10339 taken, we stop following that path. The other branch types effectively
10340 *always* write their resources. If it's not taken, register only QP
10341 reads. */
10342 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
10344 add_only_qp_reads = 1;
10347 if (md.debug_dv)
10348 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
10350 for (i = 0; i < opdeps->nregs; i++)
10352 const struct ia64_dependency *dep;
10353 struct rsrc specs[MAX_SPECS];
10354 int note;
10355 int path;
10356 int count;
10358 dep = ia64_find_dependency (opdeps->regs[i]);
10359 note = NOTE (opdeps->regs[i]);
10361 if (add_only_qp_reads
10362 && !(dep->mode == IA64_DV_WAR
10363 && (dep->specifier == IA64_RS_PR
10364 || dep->specifier == IA64_RS_PRr
10365 || dep->specifier == IA64_RS_PR63)))
10366 continue;
10368 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
10370 while (count-- > 0)
10372 mark_resource (idesc, dep, &specs[count],
10373 DEP (opdeps->regs[i]), md.path);
10376 /* The execution path may affect register values, which may in turn
10377 affect which indirect-access resources are accessed. */
10378 switch (dep->specifier)
10380 default:
10381 break;
10382 case IA64_RS_CPUID:
10383 case IA64_RS_DBR:
10384 case IA64_RS_IBR:
10385 case IA64_RS_MSR:
10386 case IA64_RS_PKR:
10387 case IA64_RS_PMC:
10388 case IA64_RS_PMD:
10389 case IA64_RS_RR:
10390 for (path = 0; path < md.path; path++)
10392 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
10393 while (count-- > 0)
10394 mark_resource (idesc, dep, &specs[count],
10395 DEP (opdeps->regs[i]), path);
10397 break;
10402 /* Remove dependencies when they no longer apply. */
10404 static void
10405 update_dependencies (idesc)
10406 struct ia64_opcode *idesc;
10408 int i;
10410 if (strcmp (idesc->name, "srlz.i") == 0)
10412 instruction_serialization ();
10414 else if (strcmp (idesc->name, "srlz.d") == 0)
10416 data_serialization ();
10418 else if (is_interruption_or_rfi (idesc)
10419 || is_taken_branch (idesc))
10421 /* Although technically the taken branch doesn't clear dependencies
10422 which require a srlz.[id], we don't follow the branch; the next
10423 instruction is assumed to start with a clean slate. */
10424 regdepslen = 0;
10425 md.path = 0;
10427 else if (is_conditional_branch (idesc)
10428 && CURR_SLOT.qp_regno != 0)
10430 int is_call = strstr (idesc->name, ".call") != NULL;
10432 for (i = 0; i < qp_implieslen; i++)
10434 /* If the conditional branch's predicate is implied by the predicate
10435 in an existing dependency, remove that dependency. */
10436 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
10438 int depind = 0;
10439 /* Note that this implied predicate takes a branch so that if
10440 a later insn generates a DV but its predicate implies this
10441 one, we can avoid the false DV warning. */
10442 qp_implies[i].p2_branched = 1;
10443 while (depind < regdepslen)
10445 if (regdeps[depind].qp_regno == qp_implies[i].p1)
10447 print_dependency ("Removing", depind);
10448 regdeps[depind] = regdeps[--regdepslen];
10450 else
10451 ++depind;
10455 /* Any marked resources which have this same predicate should be
10456 cleared, provided that the QP hasn't been modified between the
10457 marking instruction and the branch. */
10458 if (is_call)
10460 insn_group_break (0, CURR_SLOT.qp_regno, 1);
10462 else
10464 i = 0;
10465 while (i < regdepslen)
10467 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
10468 && regdeps[i].link_to_qp_branch
10469 && (regdeps[i].file != CURR_SLOT.src_file
10470 || regdeps[i].line != CURR_SLOT.src_line))
10472 /* Treat like a taken branch */
10473 print_dependency ("Removing", i);
10474 regdeps[i] = regdeps[--regdepslen];
10476 else
10477 ++i;
10483 /* Examine the current instruction for dependency violations. */
10485 static int
10486 check_dv (idesc)
10487 struct ia64_opcode *idesc;
10489 if (md.debug_dv)
10491 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
10492 idesc->name, CURR_SLOT.src_line,
10493 idesc->dependencies->nchks,
10494 idesc->dependencies->nregs);
10497 /* Look through the list of currently marked resources; if the current
10498 instruction has the dependency in its chks list which uses that resource,
10499 check against the specific resources used. */
10500 check_dependencies (idesc);
10502 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
10503 then add them to the list of marked resources. */
10504 mark_resources (idesc);
10506 /* There are several types of dependency semantics, and each has its own
10507 requirements for being cleared
10509 Instruction serialization (insns separated by interruption, rfi, or
10510 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
10512 Data serialization (instruction serialization, or writer + srlz.d +
10513 reader, where writer and srlz.d are in separate groups) clears
10514 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
10515 always be the case).
10517 Instruction group break (groups separated by stop, taken branch,
10518 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
10520 update_dependencies (idesc);
10522 /* Sometimes, knowing a register value allows us to avoid giving a false DV
10523 warning. Keep track of as many as possible that are useful. */
10524 note_register_values (idesc);
10526 /* We don't need or want this anymore. */
10527 md.mem_offset.hint = 0;
10529 return 0;
10532 /* Translate one line of assembly. Pseudo ops and labels do not show
10533 here. */
10534 void
10535 md_assemble (str)
10536 char *str;
10538 char *saved_input_line_pointer, *mnemonic;
10539 const struct pseudo_opcode *pdesc;
10540 struct ia64_opcode *idesc;
10541 unsigned char qp_regno;
10542 unsigned int flags;
10543 int ch;
10545 saved_input_line_pointer = input_line_pointer;
10546 input_line_pointer = str;
10548 /* extract the opcode (mnemonic): */
10550 mnemonic = input_line_pointer;
10551 ch = get_symbol_end ();
10552 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
10553 if (pdesc)
10555 *input_line_pointer = ch;
10556 (*pdesc->handler) (pdesc->arg);
10557 goto done;
10560 /* Find the instruction descriptor matching the arguments. */
10562 idesc = ia64_find_opcode (mnemonic);
10563 *input_line_pointer = ch;
10564 if (!idesc)
10566 as_bad ("Unknown opcode `%s'", mnemonic);
10567 goto done;
10570 idesc = parse_operands (idesc);
10571 if (!idesc)
10572 goto done;
10574 /* Handle the dynamic ops we can handle now: */
10575 if (idesc->type == IA64_TYPE_DYN)
10577 if (strcmp (idesc->name, "add") == 0)
10579 if (CURR_SLOT.opnd[2].X_op == O_register
10580 && CURR_SLOT.opnd[2].X_add_number < 4)
10581 mnemonic = "addl";
10582 else
10583 mnemonic = "adds";
10584 ia64_free_opcode (idesc);
10585 idesc = ia64_find_opcode (mnemonic);
10587 else if (strcmp (idesc->name, "mov") == 0)
10589 enum ia64_opnd opnd1, opnd2;
10590 int rop;
10592 opnd1 = idesc->operands[0];
10593 opnd2 = idesc->operands[1];
10594 if (opnd1 == IA64_OPND_AR3)
10595 rop = 0;
10596 else if (opnd2 == IA64_OPND_AR3)
10597 rop = 1;
10598 else
10599 abort ();
10600 if (CURR_SLOT.opnd[rop].X_op == O_register)
10602 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10603 mnemonic = "mov.i";
10604 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10605 mnemonic = "mov.m";
10606 else
10607 rop = -1;
10609 else
10610 abort ();
10611 if (rop >= 0)
10613 ia64_free_opcode (idesc);
10614 idesc = ia64_find_opcode (mnemonic);
10615 while (idesc != NULL
10616 && (idesc->operands[0] != opnd1
10617 || idesc->operands[1] != opnd2))
10618 idesc = get_next_opcode (idesc);
10622 else if (strcmp (idesc->name, "mov.i") == 0
10623 || strcmp (idesc->name, "mov.m") == 0)
10625 enum ia64_opnd opnd1, opnd2;
10626 int rop;
10628 opnd1 = idesc->operands[0];
10629 opnd2 = idesc->operands[1];
10630 if (opnd1 == IA64_OPND_AR3)
10631 rop = 0;
10632 else if (opnd2 == IA64_OPND_AR3)
10633 rop = 1;
10634 else
10635 abort ();
10636 if (CURR_SLOT.opnd[rop].X_op == O_register)
10638 char unit = 'a';
10639 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10640 unit = 'i';
10641 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10642 unit = 'm';
10643 if (unit != 'a' && unit != idesc->name [4])
10644 as_bad ("AR %d cannot be accessed by %c-unit",
10645 (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR),
10646 TOUPPER (unit));
10649 else if (strcmp (idesc->name, "hint.b") == 0)
10651 switch (md.hint_b)
10653 case hint_b_ok:
10654 break;
10655 case hint_b_warning:
10656 as_warn ("hint.b may be treated as nop");
10657 break;
10658 case hint_b_error:
10659 as_bad ("hint.b shouldn't be used");
10660 break;
10664 qp_regno = 0;
10665 if (md.qp.X_op == O_register)
10667 qp_regno = md.qp.X_add_number - REG_P;
10668 md.qp.X_op = O_absent;
10671 flags = idesc->flags;
10673 if ((flags & IA64_OPCODE_FIRST) != 0)
10675 /* The alignment frag has to end with a stop bit only if the
10676 next instruction after the alignment directive has to be
10677 the first instruction in an instruction group. */
10678 if (align_frag)
10680 while (align_frag->fr_type != rs_align_code)
10682 align_frag = align_frag->fr_next;
10683 if (!align_frag)
10684 break;
10686 /* align_frag can be NULL if there are directives in
10687 between. */
10688 if (align_frag && align_frag->fr_next == frag_now)
10689 align_frag->tc_frag_data = 1;
10692 insn_group_break (1, 0, 0);
10694 align_frag = NULL;
10696 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10698 as_bad ("`%s' cannot be predicated", idesc->name);
10699 goto done;
10702 /* Build the instruction. */
10703 CURR_SLOT.qp_regno = qp_regno;
10704 CURR_SLOT.idesc = idesc;
10705 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10706 dwarf2_where (&CURR_SLOT.debug_line);
10708 /* Add unwind entry, if there is one. */
10709 if (unwind.current_entry)
10711 CURR_SLOT.unwind_record = unwind.current_entry;
10712 unwind.current_entry = NULL;
10714 if (unwind.proc_start && S_IS_DEFINED (unwind.proc_start))
10715 unwind.insn = 1;
10717 /* Check for dependency violations. */
10718 if (md.detect_dv)
10719 check_dv (idesc);
10721 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10722 if (++md.num_slots_in_use >= NUM_SLOTS)
10723 emit_one_bundle ();
10725 if ((flags & IA64_OPCODE_LAST) != 0)
10726 insn_group_break (1, 0, 0);
10728 md.last_text_seg = now_seg;
10730 done:
10731 input_line_pointer = saved_input_line_pointer;
10734 /* Called when symbol NAME cannot be found in the symbol table.
10735 Should be used for dynamic valued symbols only. */
10737 symbolS *
10738 md_undefined_symbol (name)
10739 char *name ATTRIBUTE_UNUSED;
10741 return 0;
10744 /* Called for any expression that can not be recognized. When the
10745 function is called, `input_line_pointer' will point to the start of
10746 the expression. */
10748 void
10749 md_operand (e)
10750 expressionS *e;
10752 switch (*input_line_pointer)
10754 case '[':
10755 ++input_line_pointer;
10756 expression (e);
10757 if (*input_line_pointer != ']')
10759 as_bad ("Closing bracket missing");
10760 goto err;
10762 else
10764 if (e->X_op != O_register)
10765 as_bad ("Register expected as index");
10767 ++input_line_pointer;
10768 e->X_op = O_index;
10770 break;
10772 default:
10773 break;
10775 return;
10777 err:
10778 ignore_rest_of_line ();
10781 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10782 a section symbol plus some offset. For relocs involving @fptr(),
10783 directives we don't want such adjustments since we need to have the
10784 original symbol's name in the reloc. */
10786 ia64_fix_adjustable (fix)
10787 fixS *fix;
10789 /* Prevent all adjustments to global symbols */
10790 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10791 return 0;
10793 switch (fix->fx_r_type)
10795 case BFD_RELOC_IA64_FPTR64I:
10796 case BFD_RELOC_IA64_FPTR32MSB:
10797 case BFD_RELOC_IA64_FPTR32LSB:
10798 case BFD_RELOC_IA64_FPTR64MSB:
10799 case BFD_RELOC_IA64_FPTR64LSB:
10800 case BFD_RELOC_IA64_LTOFF_FPTR22:
10801 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10802 return 0;
10803 default:
10804 break;
10807 return 1;
10811 ia64_force_relocation (fix)
10812 fixS *fix;
10814 switch (fix->fx_r_type)
10816 case BFD_RELOC_IA64_FPTR64I:
10817 case BFD_RELOC_IA64_FPTR32MSB:
10818 case BFD_RELOC_IA64_FPTR32LSB:
10819 case BFD_RELOC_IA64_FPTR64MSB:
10820 case BFD_RELOC_IA64_FPTR64LSB:
10822 case BFD_RELOC_IA64_LTOFF22:
10823 case BFD_RELOC_IA64_LTOFF64I:
10824 case BFD_RELOC_IA64_LTOFF_FPTR22:
10825 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10826 case BFD_RELOC_IA64_PLTOFF22:
10827 case BFD_RELOC_IA64_PLTOFF64I:
10828 case BFD_RELOC_IA64_PLTOFF64MSB:
10829 case BFD_RELOC_IA64_PLTOFF64LSB:
10831 case BFD_RELOC_IA64_LTOFF22X:
10832 case BFD_RELOC_IA64_LDXMOV:
10833 return 1;
10835 default:
10836 break;
10839 return generic_force_reloc (fix);
10842 /* Decide from what point a pc-relative relocation is relative to,
10843 relative to the pc-relative fixup. Er, relatively speaking. */
10844 long
10845 ia64_pcrel_from_section (fix, sec)
10846 fixS *fix;
10847 segT sec;
10849 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10851 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10852 off &= ~0xfUL;
10854 return off;
10858 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10859 void
10860 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10862 expressionS expr;
10864 expr.X_op = O_pseudo_fixup;
10865 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10866 expr.X_add_number = 0;
10867 expr.X_add_symbol = symbol;
10868 emit_expr (&expr, size);
10871 /* This is called whenever some data item (not an instruction) needs a
10872 fixup. We pick the right reloc code depending on the byteorder
10873 currently in effect. */
10874 void
10875 ia64_cons_fix_new (f, where, nbytes, exp)
10876 fragS *f;
10877 int where;
10878 int nbytes;
10879 expressionS *exp;
10881 bfd_reloc_code_real_type code;
10882 fixS *fix;
10884 switch (nbytes)
10886 /* There are no reloc for 8 and 16 bit quantities, but we allow
10887 them here since they will work fine as long as the expression
10888 is fully defined at the end of the pass over the source file. */
10889 case 1: code = BFD_RELOC_8; break;
10890 case 2: code = BFD_RELOC_16; break;
10891 case 4:
10892 if (target_big_endian)
10893 code = BFD_RELOC_IA64_DIR32MSB;
10894 else
10895 code = BFD_RELOC_IA64_DIR32LSB;
10896 break;
10898 case 8:
10899 /* In 32-bit mode, data8 could mean function descriptors too. */
10900 if (exp->X_op == O_pseudo_fixup
10901 && exp->X_op_symbol
10902 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10903 && !(md.flags & EF_IA_64_ABI64))
10905 if (target_big_endian)
10906 code = BFD_RELOC_IA64_IPLTMSB;
10907 else
10908 code = BFD_RELOC_IA64_IPLTLSB;
10909 exp->X_op = O_symbol;
10910 break;
10912 else
10914 if (target_big_endian)
10915 code = BFD_RELOC_IA64_DIR64MSB;
10916 else
10917 code = BFD_RELOC_IA64_DIR64LSB;
10918 break;
10921 case 16:
10922 if (exp->X_op == O_pseudo_fixup
10923 && exp->X_op_symbol
10924 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10926 if (target_big_endian)
10927 code = BFD_RELOC_IA64_IPLTMSB;
10928 else
10929 code = BFD_RELOC_IA64_IPLTLSB;
10930 exp->X_op = O_symbol;
10931 break;
10933 /* FALLTHRU */
10935 default:
10936 as_bad ("Unsupported fixup size %d", nbytes);
10937 ignore_rest_of_line ();
10938 return;
10941 if (exp->X_op == O_pseudo_fixup)
10943 exp->X_op = O_symbol;
10944 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
10945 /* ??? If code unchanged, unsupported. */
10948 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
10949 /* We need to store the byte order in effect in case we're going
10950 to fix an 8 or 16 bit relocation (for which there no real
10951 relocs available). See md_apply_fix3(). */
10952 fix->tc_fix_data.bigendian = target_big_endian;
10955 /* Return the actual relocation we wish to associate with the pseudo
10956 reloc described by SYM and R_TYPE. SYM should be one of the
10957 symbols in the pseudo_func array, or NULL. */
10959 static bfd_reloc_code_real_type
10960 ia64_gen_real_reloc_type (sym, r_type)
10961 struct symbol *sym;
10962 bfd_reloc_code_real_type r_type;
10964 bfd_reloc_code_real_type new = 0;
10965 const char *type = NULL, *suffix = "";
10967 if (sym == NULL)
10969 return r_type;
10972 switch (S_GET_VALUE (sym))
10974 case FUNC_FPTR_RELATIVE:
10975 switch (r_type)
10977 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
10978 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
10979 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
10980 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
10981 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
10982 default: type = "FPTR"; break;
10984 break;
10986 case FUNC_GP_RELATIVE:
10987 switch (r_type)
10989 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
10990 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
10991 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
10992 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
10993 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
10994 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
10995 default: type = "GPREL"; break;
10997 break;
10999 case FUNC_LT_RELATIVE:
11000 switch (r_type)
11002 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
11003 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
11004 default: type = "LTOFF"; break;
11006 break;
11008 case FUNC_LT_RELATIVE_X:
11009 switch (r_type)
11011 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
11012 default: type = "LTOFF"; suffix = "X"; break;
11014 break;
11016 case FUNC_PC_RELATIVE:
11017 switch (r_type)
11019 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
11020 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
11021 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
11022 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
11023 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
11024 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
11025 default: type = "PCREL"; break;
11027 break;
11029 case FUNC_PLT_RELATIVE:
11030 switch (r_type)
11032 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
11033 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
11034 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
11035 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
11036 default: type = "PLTOFF"; break;
11038 break;
11040 case FUNC_SEC_RELATIVE:
11041 switch (r_type)
11043 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
11044 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
11045 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
11046 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
11047 default: type = "SECREL"; break;
11049 break;
11051 case FUNC_SEG_RELATIVE:
11052 switch (r_type)
11054 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
11055 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
11056 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
11057 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
11058 default: type = "SEGREL"; break;
11060 break;
11062 case FUNC_LTV_RELATIVE:
11063 switch (r_type)
11065 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
11066 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
11067 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
11068 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
11069 default: type = "LTV"; break;
11071 break;
11073 case FUNC_LT_FPTR_RELATIVE:
11074 switch (r_type)
11076 case BFD_RELOC_IA64_IMM22:
11077 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
11078 case BFD_RELOC_IA64_IMM64:
11079 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
11080 case BFD_RELOC_IA64_DIR32MSB:
11081 new = BFD_RELOC_IA64_LTOFF_FPTR32MSB; break;
11082 case BFD_RELOC_IA64_DIR32LSB:
11083 new = BFD_RELOC_IA64_LTOFF_FPTR32LSB; break;
11084 case BFD_RELOC_IA64_DIR64MSB:
11085 new = BFD_RELOC_IA64_LTOFF_FPTR64MSB; break;
11086 case BFD_RELOC_IA64_DIR64LSB:
11087 new = BFD_RELOC_IA64_LTOFF_FPTR64LSB; break;
11088 default:
11089 type = "LTOFF_FPTR"; break;
11091 break;
11093 case FUNC_TP_RELATIVE:
11094 switch (r_type)
11096 case BFD_RELOC_IA64_IMM14: new = BFD_RELOC_IA64_TPREL14; break;
11097 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_TPREL22; break;
11098 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_TPREL64I; break;
11099 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_TPREL64MSB; break;
11100 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_TPREL64LSB; break;
11101 default: type = "TPREL"; break;
11103 break;
11105 case FUNC_LT_TP_RELATIVE:
11106 switch (r_type)
11108 case BFD_RELOC_IA64_IMM22:
11109 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
11110 default:
11111 type = "LTOFF_TPREL"; break;
11113 break;
11115 case FUNC_DTP_MODULE:
11116 switch (r_type)
11118 case BFD_RELOC_IA64_DIR64MSB:
11119 new = BFD_RELOC_IA64_DTPMOD64MSB; break;
11120 case BFD_RELOC_IA64_DIR64LSB:
11121 new = BFD_RELOC_IA64_DTPMOD64LSB; break;
11122 default:
11123 type = "DTPMOD"; break;
11125 break;
11127 case FUNC_LT_DTP_MODULE:
11128 switch (r_type)
11130 case BFD_RELOC_IA64_IMM22:
11131 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
11132 default:
11133 type = "LTOFF_DTPMOD"; break;
11135 break;
11137 case FUNC_DTP_RELATIVE:
11138 switch (r_type)
11140 case BFD_RELOC_IA64_DIR32MSB:
11141 new = BFD_RELOC_IA64_DTPREL32MSB; break;
11142 case BFD_RELOC_IA64_DIR32LSB:
11143 new = BFD_RELOC_IA64_DTPREL32LSB; break;
11144 case BFD_RELOC_IA64_DIR64MSB:
11145 new = BFD_RELOC_IA64_DTPREL64MSB; break;
11146 case BFD_RELOC_IA64_DIR64LSB:
11147 new = BFD_RELOC_IA64_DTPREL64LSB; break;
11148 case BFD_RELOC_IA64_IMM14:
11149 new = BFD_RELOC_IA64_DTPREL14; break;
11150 case BFD_RELOC_IA64_IMM22:
11151 new = BFD_RELOC_IA64_DTPREL22; break;
11152 case BFD_RELOC_IA64_IMM64:
11153 new = BFD_RELOC_IA64_DTPREL64I; break;
11154 default:
11155 type = "DTPREL"; break;
11157 break;
11159 case FUNC_LT_DTP_RELATIVE:
11160 switch (r_type)
11162 case BFD_RELOC_IA64_IMM22:
11163 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
11164 default:
11165 type = "LTOFF_DTPREL"; break;
11167 break;
11169 case FUNC_IPLT_RELOC:
11170 switch (r_type)
11172 case BFD_RELOC_IA64_IPLTMSB: return r_type;
11173 case BFD_RELOC_IA64_IPLTLSB: return r_type;
11174 default: type = "IPLT"; break;
11176 break;
11178 default:
11179 abort ();
11182 if (new)
11183 return new;
11184 else
11186 int width;
11188 if (!type)
11189 abort ();
11190 switch (r_type)
11192 case BFD_RELOC_IA64_DIR32MSB: width = 32; suffix = "MSB"; break;
11193 case BFD_RELOC_IA64_DIR32LSB: width = 32; suffix = "LSB"; break;
11194 case BFD_RELOC_IA64_DIR64MSB: width = 64; suffix = "MSB"; break;
11195 case BFD_RELOC_IA64_DIR64LSB: width = 64; suffix = "LSB"; break;
11196 case BFD_RELOC_IA64_IMM14: width = 14; break;
11197 case BFD_RELOC_IA64_IMM22: width = 22; break;
11198 case BFD_RELOC_IA64_IMM64: width = 64; suffix = "I"; break;
11199 default: abort ();
11202 /* This should be an error, but since previously there wasn't any
11203 diagnostic here, dont't make it fail because of this for now. */
11204 as_warn ("Cannot express %s%d%s relocation", type, width, suffix);
11205 return r_type;
11209 /* Here is where generate the appropriate reloc for pseudo relocation
11210 functions. */
11211 void
11212 ia64_validate_fix (fix)
11213 fixS *fix;
11215 switch (fix->fx_r_type)
11217 case BFD_RELOC_IA64_FPTR64I:
11218 case BFD_RELOC_IA64_FPTR32MSB:
11219 case BFD_RELOC_IA64_FPTR64LSB:
11220 case BFD_RELOC_IA64_LTOFF_FPTR22:
11221 case BFD_RELOC_IA64_LTOFF_FPTR64I:
11222 if (fix->fx_offset != 0)
11223 as_bad_where (fix->fx_file, fix->fx_line,
11224 "No addend allowed in @fptr() relocation");
11225 break;
11226 default:
11227 break;
11231 static void
11232 fix_insn (fix, odesc, value)
11233 fixS *fix;
11234 const struct ia64_operand *odesc;
11235 valueT value;
11237 bfd_vma insn[3], t0, t1, control_bits;
11238 const char *err;
11239 char *fixpos;
11240 long slot;
11242 slot = fix->fx_where & 0x3;
11243 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
11245 /* Bundles are always in little-endian byte order */
11246 t0 = bfd_getl64 (fixpos);
11247 t1 = bfd_getl64 (fixpos + 8);
11248 control_bits = t0 & 0x1f;
11249 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
11250 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
11251 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
11253 err = NULL;
11254 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
11256 insn[1] = (value >> 22) & 0x1ffffffffffLL;
11257 insn[2] |= (((value & 0x7f) << 13)
11258 | (((value >> 7) & 0x1ff) << 27)
11259 | (((value >> 16) & 0x1f) << 22)
11260 | (((value >> 21) & 0x1) << 21)
11261 | (((value >> 63) & 0x1) << 36));
11263 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
11265 if (value & ~0x3fffffffffffffffULL)
11266 err = "integer operand out of range";
11267 insn[1] = (value >> 21) & 0x1ffffffffffLL;
11268 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
11270 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
11272 value >>= 4;
11273 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
11274 insn[2] |= ((((value >> 59) & 0x1) << 36)
11275 | (((value >> 0) & 0xfffff) << 13));
11277 else
11278 err = (*odesc->insert) (odesc, value, insn + slot);
11280 if (err)
11281 as_bad_where (fix->fx_file, fix->fx_line, err);
11283 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
11284 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
11285 number_to_chars_littleendian (fixpos + 0, t0, 8);
11286 number_to_chars_littleendian (fixpos + 8, t1, 8);
11289 /* Attempt to simplify or even eliminate a fixup. The return value is
11290 ignored; perhaps it was once meaningful, but now it is historical.
11291 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
11293 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
11294 (if possible). */
11296 void
11297 md_apply_fix3 (fix, valP, seg)
11298 fixS *fix;
11299 valueT *valP;
11300 segT seg ATTRIBUTE_UNUSED;
11302 char *fixpos;
11303 valueT value = *valP;
11305 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
11307 if (fix->fx_pcrel)
11309 switch (fix->fx_r_type)
11311 case BFD_RELOC_IA64_PCREL21B: break;
11312 case BFD_RELOC_IA64_PCREL21BI: break;
11313 case BFD_RELOC_IA64_PCREL21F: break;
11314 case BFD_RELOC_IA64_PCREL21M: break;
11315 case BFD_RELOC_IA64_PCREL60B: break;
11316 case BFD_RELOC_IA64_PCREL22: break;
11317 case BFD_RELOC_IA64_PCREL64I: break;
11318 case BFD_RELOC_IA64_PCREL32MSB: break;
11319 case BFD_RELOC_IA64_PCREL32LSB: break;
11320 case BFD_RELOC_IA64_PCREL64MSB: break;
11321 case BFD_RELOC_IA64_PCREL64LSB: break;
11322 default:
11323 fix->fx_r_type = ia64_gen_real_reloc_type (pseudo_func[FUNC_PC_RELATIVE].u.sym,
11324 fix->fx_r_type);
11325 break;
11328 if (fix->fx_addsy)
11330 switch (fix->fx_r_type)
11332 case BFD_RELOC_UNUSED:
11333 /* This must be a TAG13 or TAG13b operand. There are no external
11334 relocs defined for them, so we must give an error. */
11335 as_bad_where (fix->fx_file, fix->fx_line,
11336 "%s must have a constant value",
11337 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
11338 fix->fx_done = 1;
11339 return;
11341 case BFD_RELOC_IA64_TPREL14:
11342 case BFD_RELOC_IA64_TPREL22:
11343 case BFD_RELOC_IA64_TPREL64I:
11344 case BFD_RELOC_IA64_LTOFF_TPREL22:
11345 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
11346 case BFD_RELOC_IA64_DTPREL14:
11347 case BFD_RELOC_IA64_DTPREL22:
11348 case BFD_RELOC_IA64_DTPREL64I:
11349 case BFD_RELOC_IA64_LTOFF_DTPREL22:
11350 S_SET_THREAD_LOCAL (fix->fx_addsy);
11351 break;
11353 default:
11354 break;
11357 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
11359 if (fix->tc_fix_data.bigendian)
11360 number_to_chars_bigendian (fixpos, value, fix->fx_size);
11361 else
11362 number_to_chars_littleendian (fixpos, value, fix->fx_size);
11363 fix->fx_done = 1;
11365 else
11367 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
11368 fix->fx_done = 1;
11372 /* Generate the BFD reloc to be stuck in the object file from the
11373 fixup used internally in the assembler. */
11375 arelent *
11376 tc_gen_reloc (sec, fixp)
11377 asection *sec ATTRIBUTE_UNUSED;
11378 fixS *fixp;
11380 arelent *reloc;
11382 reloc = xmalloc (sizeof (*reloc));
11383 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11384 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11385 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11386 reloc->addend = fixp->fx_offset;
11387 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
11389 if (!reloc->howto)
11391 as_bad_where (fixp->fx_file, fixp->fx_line,
11392 "Cannot represent %s relocation in object file",
11393 bfd_get_reloc_code_name (fixp->fx_r_type));
11395 return reloc;
11398 /* Turn a string in input_line_pointer into a floating point constant
11399 of type TYPE, and store the appropriate bytes in *LIT. The number
11400 of LITTLENUMS emitted is stored in *SIZE. An error message is
11401 returned, or NULL on OK. */
11403 #define MAX_LITTLENUMS 5
11405 char *
11406 md_atof (type, lit, size)
11407 int type;
11408 char *lit;
11409 int *size;
11411 LITTLENUM_TYPE words[MAX_LITTLENUMS];
11412 char *t;
11413 int prec;
11415 switch (type)
11417 /* IEEE floats */
11418 case 'f':
11419 case 'F':
11420 case 's':
11421 case 'S':
11422 prec = 2;
11423 break;
11425 case 'd':
11426 case 'D':
11427 case 'r':
11428 case 'R':
11429 prec = 4;
11430 break;
11432 case 'x':
11433 case 'X':
11434 case 'p':
11435 case 'P':
11436 prec = 5;
11437 break;
11439 default:
11440 *size = 0;
11441 return "Bad call to MD_ATOF()";
11443 t = atof_ieee (input_line_pointer, type, words);
11444 if (t)
11445 input_line_pointer = t;
11447 (*ia64_float_to_chars) (lit, words, prec);
11449 if (type == 'X')
11451 /* It is 10 byte floating point with 6 byte padding. */
11452 memset (&lit [10], 0, 6);
11453 *size = 8 * sizeof (LITTLENUM_TYPE);
11455 else
11456 *size = prec * sizeof (LITTLENUM_TYPE);
11458 return 0;
11461 /* Handle ia64 specific semantics of the align directive. */
11463 void
11464 ia64_md_do_align (n, fill, len, max)
11465 int n ATTRIBUTE_UNUSED;
11466 const char *fill ATTRIBUTE_UNUSED;
11467 int len ATTRIBUTE_UNUSED;
11468 int max ATTRIBUTE_UNUSED;
11470 if (subseg_text_p (now_seg))
11471 ia64_flush_insns ();
11474 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
11475 of an rs_align_code fragment. */
11477 void
11478 ia64_handle_align (fragp)
11479 fragS *fragp;
11481 /* Use mfi bundle of nops with no stop bits. */
11482 static const unsigned char le_nop[]
11483 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
11484 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
11485 static const unsigned char le_nop_stop[]
11486 = { 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
11487 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
11489 int bytes;
11490 char *p;
11491 const unsigned char *nop;
11493 if (fragp->fr_type != rs_align_code)
11494 return;
11496 /* Check if this frag has to end with a stop bit. */
11497 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
11499 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11500 p = fragp->fr_literal + fragp->fr_fix;
11502 /* If no paddings are needed, we check if we need a stop bit. */
11503 if (!bytes && fragp->tc_frag_data)
11505 if (fragp->fr_fix < 16)
11506 #if 1
11507 /* FIXME: It won't work with
11508 .align 16
11509 alloc r32=ar.pfs,1,2,4,0
11512 #else
11513 as_bad_where (fragp->fr_file, fragp->fr_line,
11514 _("Can't add stop bit to mark end of instruction group"));
11515 #endif
11516 else
11517 /* Bundles are always in little-endian byte order. Make sure
11518 the previous bundle has the stop bit. */
11519 *(p - 16) |= 1;
11522 /* Make sure we are on a 16-byte boundary, in case someone has been
11523 putting data into a text section. */
11524 if (bytes & 15)
11526 int fix = bytes & 15;
11527 memset (p, 0, fix);
11528 p += fix;
11529 bytes -= fix;
11530 fragp->fr_fix += fix;
11533 /* Instruction bundles are always little-endian. */
11534 memcpy (p, nop, 16);
11535 fragp->fr_var = 16;
11538 static void
11539 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
11540 int prec)
11542 while (prec--)
11544 number_to_chars_bigendian (lit, (long) (*words++),
11545 sizeof (LITTLENUM_TYPE));
11546 lit += sizeof (LITTLENUM_TYPE);
11550 static void
11551 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
11552 int prec)
11554 while (prec--)
11556 number_to_chars_littleendian (lit, (long) (words[prec]),
11557 sizeof (LITTLENUM_TYPE));
11558 lit += sizeof (LITTLENUM_TYPE);
11562 void
11563 ia64_elf_section_change_hook (void)
11565 if (elf_section_type (now_seg) == SHT_IA_64_UNWIND
11566 && elf_linked_to_section (now_seg) == NULL)
11567 elf_linked_to_section (now_seg) = text_section;
11568 dot_byteorder (-1);
11571 /* Check if a label should be made global. */
11572 void
11573 ia64_check_label (symbolS *label)
11575 if (*input_line_pointer == ':')
11577 S_SET_EXTERNAL (label);
11578 input_line_pointer++;
11582 /* Used to remember where .alias and .secalias directives are seen. We
11583 will rename symbol and section names when we are about to output
11584 the relocatable file. */
11585 struct alias
11587 char *file; /* The file where the directive is seen. */
11588 unsigned int line; /* The line number the directive is at. */
11589 const char *name; /* The orignale name of the symbol. */
11592 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11593 .secalias. Otherwise, it is .alias. */
11594 static void
11595 dot_alias (int section)
11597 char *name, *alias;
11598 char delim;
11599 char *end_name;
11600 int len;
11601 const char *error_string;
11602 struct alias *h;
11603 const char *a;
11604 struct hash_control *ahash, *nhash;
11605 const char *kind;
11607 name = input_line_pointer;
11608 delim = get_symbol_end ();
11609 end_name = input_line_pointer;
11610 *end_name = delim;
11612 if (name == end_name)
11614 as_bad (_("expected symbol name"));
11615 discard_rest_of_line ();
11616 return;
11619 SKIP_WHITESPACE ();
11621 if (*input_line_pointer != ',')
11623 *end_name = 0;
11624 as_bad (_("expected comma after \"%s\""), name);
11625 *end_name = delim;
11626 ignore_rest_of_line ();
11627 return;
11630 input_line_pointer++;
11631 *end_name = 0;
11632 ia64_canonicalize_symbol_name (name);
11634 /* We call demand_copy_C_string to check if alias string is valid.
11635 There should be a closing `"' and no `\0' in the string. */
11636 alias = demand_copy_C_string (&len);
11637 if (alias == NULL)
11639 ignore_rest_of_line ();
11640 return;
11643 /* Make a copy of name string. */
11644 len = strlen (name) + 1;
11645 obstack_grow (&notes, name, len);
11646 name = obstack_finish (&notes);
11648 if (section)
11650 kind = "section";
11651 ahash = secalias_hash;
11652 nhash = secalias_name_hash;
11654 else
11656 kind = "symbol";
11657 ahash = alias_hash;
11658 nhash = alias_name_hash;
11661 /* Check if alias has been used before. */
11662 h = (struct alias *) hash_find (ahash, alias);
11663 if (h)
11665 if (strcmp (h->name, name))
11666 as_bad (_("`%s' is already the alias of %s `%s'"),
11667 alias, kind, h->name);
11668 goto out;
11671 /* Check if name already has an alias. */
11672 a = (const char *) hash_find (nhash, name);
11673 if (a)
11675 if (strcmp (a, alias))
11676 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11677 goto out;
11680 h = (struct alias *) xmalloc (sizeof (struct alias));
11681 as_where (&h->file, &h->line);
11682 h->name = name;
11684 error_string = hash_jam (ahash, alias, (PTR) h);
11685 if (error_string)
11687 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11688 alias, kind, error_string);
11689 goto out;
11692 error_string = hash_jam (nhash, name, (PTR) alias);
11693 if (error_string)
11695 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11696 alias, kind, error_string);
11697 out:
11698 obstack_free (&notes, name);
11699 obstack_free (&notes, alias);
11702 demand_empty_rest_of_line ();
11705 /* It renames the original symbol name to its alias. */
11706 static void
11707 do_alias (const char *alias, PTR value)
11709 struct alias *h = (struct alias *) value;
11710 symbolS *sym = symbol_find (h->name);
11712 if (sym == NULL)
11713 as_warn_where (h->file, h->line,
11714 _("symbol `%s' aliased to `%s' is not used"),
11715 h->name, alias);
11716 else
11717 S_SET_NAME (sym, (char *) alias);
11720 /* Called from write_object_file. */
11721 void
11722 ia64_adjust_symtab (void)
11724 hash_traverse (alias_hash, do_alias);
11727 /* It renames the original section name to its alias. */
11728 static void
11729 do_secalias (const char *alias, PTR value)
11731 struct alias *h = (struct alias *) value;
11732 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11734 if (sec == NULL)
11735 as_warn_where (h->file, h->line,
11736 _("section `%s' aliased to `%s' is not used"),
11737 h->name, alias);
11738 else
11739 sec->name = alias;
11742 /* Called from write_object_file. */
11743 void
11744 ia64_frob_file (void)
11746 hash_traverse (secalias_hash, do_secalias);